Spaces:
Running
Running
File size: 1,900 Bytes
dc2106c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import onnx
from onnx.backend.test.case.base import Base
from onnx.backend.test.case.node import expect
class ConstantOfShape(Base):
@staticmethod
def export_float_ones() -> None:
x = np.array([4, 3, 2]).astype(np.int64)
tensor_value = onnx.helper.make_tensor(
"value", onnx.TensorProto.FLOAT, [1], [1]
)
node = onnx.helper.make_node(
"ConstantOfShape",
inputs=["x"],
outputs=["y"],
value=tensor_value,
)
y = np.ones(x, dtype=np.float32)
expect(node, inputs=[x], outputs=[y], name="test_constantofshape_float_ones")
@staticmethod
def export_int32_zeros() -> None:
x = np.array([10, 6]).astype(np.int64)
tensor_value = onnx.helper.make_tensor(
"value", onnx.TensorProto.INT32, [1], [0]
)
node = onnx.helper.make_node(
"ConstantOfShape",
inputs=["x"],
outputs=["y"],
value=tensor_value,
)
y = np.zeros(x, dtype=np.int32)
expect(node, inputs=[x], outputs=[y], name="test_constantofshape_int_zeros")
@staticmethod
def export_int32_shape_zero() -> None:
x = np.array(
[
0,
]
).astype(np.int64)
tensor_value = onnx.helper.make_tensor(
"value", onnx.TensorProto.INT32, [1], [0]
)
node = onnx.helper.make_node(
"ConstantOfShape",
inputs=["x"],
outputs=["y"],
value=tensor_value,
)
y = np.zeros(x, dtype=np.int32)
expect(
node, inputs=[x], outputs=[y], name="test_constantofshape_int_shape_zero"
)
|