EyeLike#
EyeLike - 9#
Version
name: EyeLike (GitHub)
domain: main
since_version: 9
function:
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 9.
Summary
Attributes
dtype - INT : (Optional) The data type for the elements of the output tensor. If not specified,the data type of the input tensor T1 is used. If input tensor T1 is also notspecified, then type defaults to ‘float’.
k - INT : (Optional) Index of the diagonal to be populated with ones. Default is 0. If T2 is the output, this op sets T2[i, i+k] = 1. k = 0 populates the main diagonal, k > 0 populates an upper diagonal, and k < 0 populates a lower diagonal.
Inputs
input (heterogeneous) - T1:
Outputs
output (heterogeneous) - T2:
Type Constraints
T1 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain input types. Strings and complex are not supported.
T2 in ( tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8) ): Constrain output types. Strings and complex are not supported.
Examples
_without_dtype
import numpy as np
import onnx
shape = (4, 4)
node = onnx.helper.make_node(
"EyeLike",
inputs=["x"],
outputs=["y"],
)
x = np.random.randint(0, 100, size=shape, dtype=np.int32)
y = np.eye(shape[0], shape[1], dtype=np.int32)
expect(node, inputs=[x], outputs=[y], name="test_eyelike_without_dtype")
_with_dtype
import numpy as np
import onnx
shape = (3, 4)
node = onnx.helper.make_node(
"EyeLike",
inputs=["x"],
outputs=["y"],
dtype=onnx.TensorProto.DOUBLE,
)
x = np.random.randint(0, 100, size=shape, dtype=np.int32)
y = np.eye(shape[0], shape[1], dtype=np.float64)
expect(node, inputs=[x], outputs=[y], name="test_eyelike_with_dtype")
_populate_off_main_diagonal
import numpy as np
import onnx
shape = (4, 5)
off_diagonal_offset = 1
node = onnx.helper.make_node(
"EyeLike",
inputs=["x"],
outputs=["y"],
k=off_diagonal_offset,
dtype=onnx.TensorProto.FLOAT,
)
x = np.random.randint(0, 100, size=shape, dtype=np.int32)
y = np.eye(shape[0], shape[1], k=off_diagonal_offset, dtype=np.float32)
expect(
node,
inputs=[x],
outputs=[y],
name="test_eyelike_populate_off_main_diagonal",
)