# Gemm#

## Gemm - 13#

Version

• name: Gemm (GitHub)

• 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

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3

A’ = transpose(A) if transA else A

B’ = transpose(B) if transB else B

Compute Y = alpha * A’ * B’ + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports unidirectional broadcasting (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX. This operator has optional inputs/outputs. See ONNX for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument’s name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C. Default value is `1.0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

Between 2 and 3 inputs.

• A (heterogeneous) - T: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.

• B (heterogeneous) - T: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.

• C (optional, heterogeneous) - T: Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N).

Outputs

• Y (heterogeneous) - T: Output tensor of shape (M, N).

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_zero_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y']
)
a = np.random.ranf([3, 5]).astype(np.float32)
b = np.random.ranf([5, 4]).astype(np.float32)
c = np.zeros([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_default_zero_bias')
```

_default_no_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b'],
outputs=['y']
)
a = np.random.ranf([2, 10]).astype(np.float32)
b = np.random.ranf([10, 3]).astype(np.float32)
y = gemm_reference_implementation(a, b)
expect(node, inputs=[a, b], outputs=[y],
name='test_gemm_default_no_bias')
```

_default_scalar_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y']
)
a = np.random.ranf([2, 3]).astype(np.float32)
b = np.random.ranf([3, 4]).astype(np.float32)
c = np.array(3.14).astype(np.float32)
y = gemm_reference_implementation(a, b, c)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_default_scalar_bias')
```

_default_single_elem_vector_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y']
)
a = np.random.ranf([3, 7]).astype(np.float32)
b = np.random.ranf([7, 3]).astype(np.float32)
c = np.random.ranf().astype(np.float32)
y = gemm_reference_implementation(a, b, c)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_default_single_elem_vector_bias')
```

_default_vector_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y']
)
a = np.random.ranf([2, 7]).astype(np.float32)
b = np.random.ranf([7, 4]).astype(np.float32)
c = np.random.ranf([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_default_vector_bias')
```

_default_matrix_bias

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y']
)
a = np.random.ranf([3, 6]).astype(np.float32)
b = np.random.ranf([6, 4]).astype(np.float32)
c = np.random.ranf([3, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_default_matrix_bias')
```

_transposeA

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y'],
transA=1
)
a = np.random.ranf([6, 3]).astype(np.float32)
b = np.random.ranf([6, 4]).astype(np.float32)
c = np.zeros([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c, transA=1)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_transposeA')
```

_transposeB

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y'],
transB=1
)
a = np.random.ranf([3, 6]).astype(np.float32)
b = np.random.ranf([4, 6]).astype(np.float32)
c = np.zeros([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c, transB=1)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_transposeB')
```

_alpha

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y'],
alpha=0.5
)
a = np.random.ranf([3, 5]).astype(np.float32)
b = np.random.ranf([5, 4]).astype(np.float32)
c = np.zeros([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c, alpha=0.5)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_alpha')
```

_beta

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y'],
beta=0.5
)
a = np.random.ranf([2, 7]).astype(np.float32)
b = np.random.ranf([7, 4]).astype(np.float32)
c = np.random.ranf([1, 4]).astype(np.float32)
y = gemm_reference_implementation(a, b, c, beta=0.5)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_beta')
```

_all_attributes

```node = onnx.helper.make_node(
'Gemm',
inputs=['a', 'b', 'c'],
outputs=['y'],
alpha=0.25,
beta=0.35,
transA=1,
transB=1
)
a = np.random.ranf([4, 3]).astype(np.float32)
b = np.random.ranf([5, 4]).astype(np.float32)
c = np.random.ranf([1, 5]).astype(np.float32)
y = gemm_reference_implementation(a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35)
expect(node, inputs=[a, b, c], outputs=[y],
name='test_gemm_all_attributes')
```

Differences

 `0` `0` `General Matrix multiplication:` `General Matrix multiplication:` `1` `1` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `2` `2` `3` `3` `A' = transpose(A) if transA else A` `A' = transpose(A) if transA else A` `4` `4` `5` `5` `B' = transpose(B) if transB else B` `B' = transpose(B) if transB else B` `6` `6` `7` `7` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `8` `8` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `9` `9` `and output tensor Y has shape (M, N). A will be transposed before doing the` `and output tensor Y has shape (M, N). A will be transposed before doing the` `10` `10` `computation if attribute transA is non-zero, same for B and transB.` `computation if attribute transA is non-zero, same for B and transB.` `11` `11` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `12` `12` `This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.` `This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.` `13` `13` `14` `14` `**Attributes**` `**Attributes**` `15` `15` `16` `16` `* **alpha**:` `* **alpha**:` `17` `17` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` `18` `18` `* **beta**:` `* **beta**:` `19` `19` ` Scalar multiplier for input tensor C. Default value is 1.0.` ` Scalar multiplier for input tensor C. Default value is 1.0.` `20` `20` `* **transA**:` `* **transA**:` `21` `21` ` Whether A should be transposed Default value is 0.` ` Whether A should be transposed Default value is 0.` `22` `22` `* **transB**:` `* **transB**:` `23` `23` ` Whether B should be transposed Default value is 0.` ` Whether B should be transposed Default value is 0.` `24` `24` `25` `25` `**Inputs**` `**Inputs**` `26` `26` `27` `27` `Between 2 and 3 inputs.` `Between 2 and 3 inputs.` `28` `28` `29` `29` `* **A** (heterogeneous) - **T**:` `* **A** (heterogeneous) - **T**:` `30` `30` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` `31` `31` ` (K, M) if transA is non-zero.` ` (K, M) if transA is non-zero.` `32` `32` `* **B** (heterogeneous) - **T**:` `* **B** (heterogeneous) - **T**:` `33` `33` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` `34` `34` ` (N, K) if transB is non-zero.` ` (N, K) if transB is non-zero.` `35` `35` `* **C** (optional, heterogeneous) - **T**:` `* **C** (optional, heterogeneous) - **T**:` `36` `36` ` Optional input tensor C. If not specified, the computation is done` ` Optional input tensor C. If not specified, the computation is done` `37` `37` ` as if C is a scalar 0. The shape of C should be unidirectional` ` as if C is a scalar 0. The shape of C should be unidirectional` `38` `38` ` broadcastable to (M, N).` ` broadcastable to (M, N).` `39` `39` `40` `40` `**Outputs**` `**Outputs**` `41` `41` `42` `42` `* **Y** (heterogeneous) - **T**:` `* **Y** (heterogeneous) - **T**:` `43` `43` ` Output tensor of shape (M, N).` ` Output tensor of shape (M, N).` `44` `44` `45` `45` `**Type Constraints**` `**Type Constraints**` `46` `46` `47` `47` `* **T** in (` `* **T** in (` `48` ` tensor(bfloat16),` `48` `49` ` tensor(double),` ` tensor(double),` `49` `50` ` tensor(float),` ` tensor(float),` `50` `51` ` tensor(float16),` ` tensor(float16),` `51` `52` ` tensor(int32),` ` tensor(int32),` `52` `53` ` tensor(int64),` ` tensor(int64),` `53` `54` ` tensor(uint32),` ` tensor(uint32),` `54` `55` ` tensor(uint64)` ` tensor(uint64)` `55` `56` ` ):` ` ):` `56` `57` ` Constrain input and output types to float/int tensors.` ` Constrain input and output types to float/int tensors.`

## Gemm - 11#

Version

• name: Gemm (GitHub)

• domain: main

• since_version: 11

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 11.

Summary

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3

A’ = transpose(A) if transA else A

B’ = transpose(B) if transB else B

Compute Y = alpha * A’ * B’ + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports unidirectional broadcasting (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX. This operator has optional inputs/outputs. See ONNX for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument’s name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C. Default value is `1.0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

Between 2 and 3 inputs.

• A (heterogeneous) - T: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.

• B (heterogeneous) - T: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.

• C (optional, heterogeneous) - T: Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N).

Outputs

• Y (heterogeneous) - T: Output tensor of shape (M, N).

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.

Differences

 `0` `0` `General Matrix multiplication:` `General Matrix multiplication:` `1` `1` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `2` `2` `3` `3` `A' = transpose(A) if transA else A` `A' = transpose(A) if transA else A` `4` `4` `5` `5` `B' = transpose(B) if transB else B` `B' = transpose(B) if transB else B` `6` `6` `7` `7` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `8` `8` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `9` `9` `and output tensor Y has shape (M, N). A will be transposed before doing the` `and output tensor Y has shape (M, N). A will be transposed before doing the` `10` `10` `computation if attribute transA is non-zero, same for B and transB.` `computation if attribute transA is non-zero, same for B and transB.` `11` `11` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `12` `This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.` `12` `13` `13` `14` `**Attributes**` `**Attributes**` `14` `15` `15` `16` `* **alpha**:` `* **alpha**:` `16` `17` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` `17` `18` `* **beta**:` `* **beta**:` `18` `19` ` Scalar multiplier for input tensor C. Default value is 1.0.` ` Scalar multiplier for input tensor C. Default value is 1.0.` `19` `20` `* **transA**:` `* **transA**:` `20` `21` ` Whether A should be transposed Default value is 0.` ` Whether A should be transposed Default value is 0.` `21` `22` `* **transB**:` `* **transB**:` `22` `23` ` Whether B should be transposed Default value is 0.` ` Whether B should be transposed Default value is 0.` `23` `24` `24` `25` `**Inputs**` `**Inputs**` `25` `26` `27` `Between 2 and 3 inputs.` `28` `26` `29` `* **A** (heterogeneous) - **T**:` `* **A** (heterogeneous) - **T**:` `27` `30` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` `28` `31` ` (K, M) if transA is non-zero.` ` (K, M) if transA is non-zero.` `29` `32` `* **B** (heterogeneous) - **T**:` `* **B** (heterogeneous) - **T**:` `30` `33` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` `31` `34` ` (N, K) if transB is non-zero.` ` (N, K) if transB is non-zero.` `35` `* **C** (optional, heterogeneous) - **T**:` `32` `36` `* **C** (heterogeneous) - **T**:` ` Optional input tensor C. If not specified, the computation is done` `33` `37` ` Input tensor C. The shape of C should be unidirectional` ` as if C is a scalar 0. The shape of C should be unidirectional` `34` `38` ` broadcastable to (M, N).` ` broadcastable to (M, N).` `35` `39` `36` `40` `**Outputs**` `**Outputs**` `37` `41` `38` `42` `* **Y** (heterogeneous) - **T**:` `* **Y** (heterogeneous) - **T**:` `39` `43` ` Output tensor of shape (M, N).` ` Output tensor of shape (M, N).` `40` `44` `41` `45` `**Type Constraints**` `**Type Constraints**` `42` `46` `43` `47` `* **T** in (` `* **T** in (` `44` `48` ` tensor(double),` ` tensor(double),` `45` `49` ` tensor(float),` ` tensor(float),` `46` `50` ` tensor(float16),` ` tensor(float16),` `47` `51` ` tensor(int32),` ` tensor(int32),` `48` `52` ` tensor(int64),` ` tensor(int64),` `49` `53` ` tensor(uint32),` ` tensor(uint32),` `50` `54` ` tensor(uint64)` ` tensor(uint64)` `51` `55` ` ):` ` ):` `52` `56` ` Constrain input and output types to float/int tensors.` ` Constrain input and output types to float/int tensors.`

## Gemm - 9#

Version

• name: Gemm (GitHub)

• 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

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3

A’ = transpose(A) if transA else A

B’ = transpose(B) if transB else B

Compute Y = alpha * A’ * B’ + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports unidirectional broadcasting (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C. Default value is `1.0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

• A (heterogeneous) - T: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.

• B (heterogeneous) - T: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.

• C (heterogeneous) - T: Input tensor C. The shape of C should be unidirectional broadcastable to (M, N).

Outputs

• Y (heterogeneous) - T: Output tensor of shape (M, N).

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.

Differences

 `0` `0` `General Matrix multiplication:` `General Matrix multiplication:` `1` `1` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `2` `2` `3` `3` `A' = transpose(A) if transA else A` `A' = transpose(A) if transA else A` `4` `4` `5` `5` `B' = transpose(B) if transB else B` `B' = transpose(B) if transB else B` `6` `6` `7` `7` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `8` `8` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `9` `9` `and output tensor Y has shape (M, N). A will be transposed before doing the` `and output tensor Y has shape (M, N). A will be transposed before doing the` `10` `10` `computation if attribute transA is non-zero, same for B and transB.` `computation if attribute transA is non-zero, same for B and transB.` `11` `11` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `12` `12` `13` `13` `**Attributes**` `**Attributes**` `14` `14` `15` `15` `* **alpha**:` `* **alpha**:` `16` `16` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` `17` `17` `* **beta**:` `* **beta**:` `18` `18` ` Scalar multiplier for input tensor C. Default value is 1.0.` ` Scalar multiplier for input tensor C. Default value is 1.0.` `19` `19` `* **transA**:` `* **transA**:` `20` `20` ` Whether A should be transposed Default value is 0.` ` Whether A should be transposed Default value is 0.` `21` `21` `* **transB**:` `* **transB**:` `22` `22` ` Whether B should be transposed Default value is 0.` ` Whether B should be transposed Default value is 0.` `23` `23` `24` `24` `**Inputs**` `**Inputs**` `25` `25` `26` `26` `* **A** (heterogeneous) - **T**:` `* **A** (heterogeneous) - **T**:` `27` `27` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` `28` `28` ` (K, M) if transA is non-zero.` ` (K, M) if transA is non-zero.` `29` `29` `* **B** (heterogeneous) - **T**:` `* **B** (heterogeneous) - **T**:` `30` `30` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` `31` `31` ` (N, K) if transB is non-zero.` ` (N, K) if transB is non-zero.` `32` `32` `* **C** (heterogeneous) - **T**:` `* **C** (heterogeneous) - **T**:` `33` `33` ` Input tensor C. The shape of C should be unidirectional` ` Input tensor C. The shape of C should be unidirectional` `34` `34` ` broadcastable to (M, N).` ` broadcastable to (M, N).` `35` `35` `36` `36` `**Outputs**` `**Outputs**` `37` `37` `38` `38` `* **Y** (heterogeneous) - **T**:` `* **Y** (heterogeneous) - **T**:` `39` `39` ` Output tensor of shape (M, N).` ` Output tensor of shape (M, N).` `40` `40` `41` `41` `**Type Constraints**` `**Type Constraints**` `42` `42` `43` `43` `* **T** in (` `* **T** in (` `44` `44` ` tensor(double),` ` tensor(double),` `45` `45` ` tensor(float),` ` tensor(float),` `46` `46` ` tensor(float16)` ` tensor(float16),` `47` ` tensor(int32),` `48` ` tensor(int64),` `49` ` tensor(uint32),` `50` ` tensor(uint64)` `47` `51` ` ):` ` ):` `48` `52` ` Constrain input and output types to float tensors.` ` Constrain input and output types to float/int tensors.`

## Gemm - 7#

Version

• name: Gemm (GitHub)

• domain: main

• since_version: 7

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 7.

Summary

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3

A’ = transpose(A) if transA else A

B’ = transpose(B) if transB else B

Compute Y = alpha * A’ * B’ + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports unidirectional broadcasting (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C. Default value is `1.0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

• A (heterogeneous) - T: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero.

• B (heterogeneous) - T: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero.

• C (heterogeneous) - T: Input tensor C. The shape of C should be unidirectional broadcastable to (M, N).

Outputs

• Y (heterogeneous) - T: Output tensor of shape (M, N).

Type Constraints

• T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.

Differences

 `0` `0` `General Matrix multiplication:` `General Matrix multiplication:` `1` `1` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `2` `3` `A' = transpose(A) if transA else A` `4` `5` `B' = transpose(B) if transB else B` `6` `2` `7` `Compute Y = alpha * A * B + beta * C, where input tensor A has` `Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),` `3` `dimension (M X K), input tensor B has dimension (K X N), input tensor C and` `4` `8` `output tensor Y have dimension (M X N).` `input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),` `9` `and output tensor Y has shape (M, N). A will be transposed before doing the` `5` `10` `If attribute broadcast is non-zero, input tensor C will be broadcasted to match` `computation if attribute transA is non-zero, same for B and transB.` `6` `11` `the dimension requirement. A will be transposed before doing the computation` `This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.` `7` `if attribute transA is non-zero, same for B and transB.` `8` `12` `9` `13` `**Attributes**` `**Attributes**` `10` `14` `11` `15` `* **alpha**:` `* **alpha**:` `12` `16` ` Scalar multiplier for the product of input tensors A * B, the` ` Scalar multiplier for the product of input tensors A * B. Default value is 1.0.` `13` ` default value is 1.0. Default value is 1.0.` `14` `17` `* **beta**:` `* **beta**:` `15` `18` ` Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0.` ` Scalar multiplier for input tensor C. Default value is 1.0.` `16` `* **broadcast**:` `17` ` Whether C should be broadcasted Default value is 0.` `18` `19` `* **transA**:` `* **transA**:` `19` `20` ` Whether A should be transposed Default value is 0.` ` Whether A should be transposed Default value is 0.` `20` `21` `* **transB**:` `* **transB**:` `21` `22` ` Whether B should be transposed Default value is 0.` ` Whether B should be transposed Default value is 0.` `22` `23` `23` `24` `**Inputs**` `**Inputs**` `24` `25` `25` `26` `* **A** (heterogeneous) - **T**:` `* **A** (heterogeneous) - **T**:` `26` `27` ` Input tensor A` ` Input tensor A. The shape of A should be (M, K) if transA is 0, or` `28` ` (K, M) if transA is non-zero.` `27` `29` `* **B** (heterogeneous) - **T**:` `* **B** (heterogeneous) - **T**:` `28` `30` ` Input tensor B` ` Input tensor B. The shape of B should be (K, N) if transB is 0, or` `31` ` (N, K) if transB is non-zero.` `29` `32` `* **C** (heterogeneous) - **T**:` `* **C** (heterogeneous) - **T**:` `30` `33` ` Input tensor C` ` Input tensor C. The shape of C should be unidirectional` `34` ` broadcastable to (M, N).` `31` `35` `32` `36` `**Outputs**` `**Outputs**` `33` `37` `34` `38` `* **Y** (heterogeneous) - **T**:` `* **Y** (heterogeneous) - **T**:` `35` `39` ` Output tensor.` ` Output tensor of shape (M, N).` `36` `40` `37` `41` `**Type Constraints**` `**Type Constraints**` `38` `42` `39` `43` `* **T** in (` `* **T** in (` `40` `44` ` tensor(double),` ` tensor(double),` `41` `45` ` tensor(float),` ` tensor(float),` `42` `46` ` tensor(float16)` ` tensor(float16)` `43` `47` ` ):` ` ):` `44` `48` ` Constrain input and output types to float tensors.` ` Constrain input and output types to float tensors.`

## Gemm - 6#

Version

• name: Gemm (GitHub)

• domain: main

• since_version: 6

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 6.

Summary

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B, the default value is 1.0. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C, the default value is 1.0. Default value is `1.0`.

• broadcast: Whether C should be broadcasted Default value is `0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

• A (heterogeneous) - T: Input tensor A

• B (heterogeneous) - T: Input tensor B

• C (heterogeneous) - T: Input tensor C

Outputs

• Y (heterogeneous) - T: Output tensor.

Type Constraints

• T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.

Differences

 `0` `0` `General Matrix multiplication:` `General Matrix multiplication:` `1` `1` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3` `2` `2` `Compute Y = alpha * A * B + beta * C, where input tensor A has` `Compute Y = alpha * A * B + beta * C, where input tensor A has` `3` `3` `dimension (M X K), input tensor B has dimension (K X N), input tensor C and` `dimension (M X K), input tensor B has dimension (K X N), input tensor C and` `4` `4` `output tensor Y have dimension (M X N).` `output tensor Y have dimension (M X N).` `5` `5` `If attribute broadcast is non-zero, input tensor C will be broadcasted to match` `If attribute broadcast is non-zero, input tensor C will be broadcasted to match` `6` `6` `the dimension requirement. A will be transposed before doing the computation` `the dimension requirement. A will be transposed before doing the computation` `7` `7` `if attribute transA is non-zero, same for B and transB.` `if attribute transA is non-zero, same for B and transB.` `8` `8` `9` `9` `**Attributes**` `**Attributes**` `10` `10` `11` `11` `* **alpha**:` `* **alpha**:` `12` `12` ` Scalar multiplier for the product of input tensors A * B, the` ` Scalar multiplier for the product of input tensors A * B, the` `13` `13` ` default value is 1.0. Default value is 1.0.` ` default value is 1.0. Default value is 1.0.` `14` `14` `* **beta**:` `* **beta**:` `15` `15` ` Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0.` ` Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0.` `16` `16` `* **broadcast**:` `* **broadcast**:` `17` `17` ` Whether C should be broadcasted Default value is 0.` ` Whether C should be broadcasted Default value is 0.` `18` `18` `* **transA**:` `* **transA**:` `19` `19` ` Whether A should be transposed Default value is 0.` ` Whether A should be transposed Default value is 0.` `20` `20` `* **transB**:` `* **transB**:` `21` `21` ` Whether B should be transposed Default value is 0.` ` Whether B should be transposed Default value is 0.` `22` `22` `23` `23` `**Inputs**` `**Inputs**` `24` `24` `25` `25` `* **A** (heterogeneous) - **T**:` `* **A** (heterogeneous) - **T**:` `26` `26` ` Input tensor A` ` Input tensor A` `27` `27` `* **B** (heterogeneous) - **T**:` `* **B** (heterogeneous) - **T**:` `28` `28` ` Input tensor B` ` Input tensor B` `29` `29` `* **C** (heterogeneous) - **T**:` `* **C** (heterogeneous) - **T**:` `30` `30` ` Input tensor C, can be inplace.` ` Input tensor C` `31` `31` `32` `32` `**Outputs**` `**Outputs**` `33` `33` `34` `34` `* **Y** (heterogeneous) - **T**:` `* **Y** (heterogeneous) - **T**:` `35` `35` ` Output tensor.` ` Output tensor.` `36` `36` `37` `37` `**Type Constraints**` `**Type Constraints**` `38` `38` `39` `39` `* **T** in (` `* **T** in (` `40` `40` ` tensor(double),` ` tensor(double),` `41` `41` ` tensor(float),` ` tensor(float),` `42` `42` ` tensor(float16)` ` tensor(float16)` `43` `43` ` ):` ` ):` `44` `44` ` Constrain input and output types to float tensors.` ` Constrain input and output types to float tensors.`

## Gemm - 1#

Version

• name: Gemm (GitHub)

• domain: main

• since_version: 1

• function: False

• support_level: SupportType.COMMON

• shape inference: False

This version of the operator has been available since version 1.

Summary

General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB.

Attributes

• alpha: Scalar multiplier for the product of input tensors A * B, the default value is 1.0. Default value is `1.0`.

• beta: Scalar multiplier for input tensor C, the default value is 1.0. Default value is `1.0`.

• broadcast: Whether C should be broadcasted Default value is `0`.

• transA: Whether A should be transposed Default value is `0`.

• transB: Whether B should be transposed Default value is `0`.

Inputs

• A (heterogeneous) - T: Input tensor A

• B (heterogeneous) - T: Input tensor B

• C (heterogeneous) - T: Input tensor C, can be inplace.

Outputs

• Y (heterogeneous) - T: Output tensor.

Type Constraints

• T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.