Einsum#
Einsum - 12#
Version
name: Einsum (GitHub)
domain: main
since_version: 12
function:
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 12.
Summary
Attributes
equation - STRING (required) : Einsum expression string.
Inputs
Between 1 and 2147483647 inputs.
Inputs (variadic, heterogeneous) - T:
Outputs
Output (heterogeneous) - T:
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input and output types to all numerical tensor types.
Examples
_einsum_transpose
import numpy as np
import onnx
Eqn = "ij->ji"
node = onnx.helper.make_node(
"Einsum", inputs=["x"], outputs=["y"], equation=Eqn
)
X = np.random.randn(3, 4)
Y = einsum_reference_implementation(Eqn, (X,))
expect(node, inputs=[X], outputs=[Y], name="test_einsum_transpose")
_einsum_sum
import numpy as np
import onnx
Eqn = "ij->i"
node = onnx.helper.make_node(
"Einsum", inputs=["x"], outputs=["y"], equation=Eqn
)
X = np.random.randn(3, 4)
Z = einsum_reference_implementation(Eqn, (X,))
expect(node, inputs=[X], outputs=[Z], name="test_einsum_sum")
_einsum_batch_diagonal
import numpy as np
import onnx
Eqn = "...ii ->...i"
node = onnx.helper.make_node(
"Einsum", inputs=["x"], outputs=["y"], equation=Eqn
)
X = np.random.randn(3, 5, 5)
Z = einsum_reference_implementation(Eqn, (X,))
expect(node, inputs=[X], outputs=[Z], name="test_einsum_batch_diagonal")
_einsum_inner_prod
import numpy as np
import onnx
Eqn = "i,i"
node = onnx.helper.make_node(
"Einsum", inputs=["x", "y"], outputs=["z"], equation=Eqn
)
X = np.random.randn(5)
Y = np.random.randn(5)
Z = einsum_reference_implementation(Eqn, (X, Y))
expect(node, inputs=[X, Y], outputs=[Z], name="test_einsum_inner_prod")
_einsum_batch_matmul
import numpy as np
import onnx
Eqn = "bij, bjk -> bik"
node = onnx.helper.make_node(
"Einsum", inputs=["x", "y"], outputs=["z"], equation=Eqn
)
X = np.random.randn(5, 2, 3)
Y = np.random.randn(5, 3, 4)
Z = einsum_reference_implementation(Eqn, (X, Y))
expect(node, inputs=[X, Y], outputs=[Z], name="test_einsum_batch_matmul")