(l-onnx-doc-MatMul)= # MatMul (l-onnx-op-matmul-13)= ## MatMul - 13 ### Version - **name**: [MatMul (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#MatMul) - **domain**: `main` - **since_version**: `13` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 13**. ### Summary Matrix product that behaves like [numpy.matmul](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html). ### Inputs - **A** (heterogeneous) - **T**: N-dimensional matrix A - **B** (heterogeneous) - **T**: N-dimensional matrix B ### Outputs - **Y** (heterogeneous) - **T**: Matrix multiply results from A * B ### Type Constraints * **T** in ( `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` ): Constrain input and output types to float/int tensors. ### Examples #### default ```python import numpy as np import onnx node = onnx.helper.make_node( "MatMul", inputs=["a", "b"], outputs=["c"], ) # 2d a = np.random.randn(3, 4).astype(np.float32) b = np.random.randn(4, 3).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_2d") # 3d a = np.random.randn(2, 3, 4).astype(np.float32) b = np.random.randn(2, 4, 3).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_3d") # 4d a = np.random.randn(1, 2, 3, 4).astype(np.float32) b = np.random.randn(1, 2, 4, 3).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_4d") # broadcasting a = np.random.randn(3, 1, 3, 4).astype(np.float32) b = np.random.randn(1, 2, 4, 2).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_bcast") # 1d + 3d a = np.random.randn(4).astype(np.float32) b = np.random.randn(2, 4, 1).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_1d_3d") # 3d + 1d a = np.random.randn(1, 2, 4, 3).astype(np.float32) b = np.random.randn(3).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_4d_1d") # 1d + 1d a = np.random.randn(3).astype(np.float32) b = np.random.randn(3).astype(np.float32) c = np.matmul(a, b) expect(node, inputs=[a, b], outputs=[c], name="test_matmul_1d_1d") ``` ```{toctree} text_diff_MatMul_9_13 ``` (l-onnx-op-matmul-9)= ## MatMul - 9 ### Version - **name**: [MatMul (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#MatMul) - **domain**: `main` - **since_version**: `9` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 9**. ### Summary Matrix product that behaves like [numpy.matmul](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html). ### Inputs - **A** (heterogeneous) - **T**: N-dimensional matrix A - **B** (heterogeneous) - **T**: N-dimensional matrix B ### Outputs - **Y** (heterogeneous) - **T**: Matrix multiply results from A * B ### Type Constraints * **T** in ( `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` ): Constrain input and output types to float/int tensors. ```{toctree} text_diff_MatMul_1_13 text_diff_MatMul_1_9 ``` (l-onnx-op-matmul-1)= ## MatMul - 1 ### Version - **name**: [MatMul (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#MatMul) - **domain**: `main` - **since_version**: `1` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 1**. ### Summary Matrix product that behaves like [numpy.matmul](https://numpy.org/doc/stable/reference/generated/numpy.matmul.html). ### Inputs - **A** (heterogeneous) - **T**: N-dimensional matrix A - **B** (heterogeneous) - **T**: N-dimensional matrix B ### Outputs - **Y** (heterogeneous) - **T**: Matrix multiply results from A * B ### Type Constraints * **T** in ( `tensor(double)`, `tensor(float)`, `tensor(float16)` ): Constrain input and output types to float tensors.