From 094353038fc30ac2aeefc7042aff7682ddd4dccc Mon Sep 17 00:00:00 2001 From: 0xd3bs Date: Mon, 23 Oct 2023 16:34:13 -0300 Subject: [PATCH] feat: add identity --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.identity.md | 33 +++++++ nodegen/node/identity.py | 86 +++++++++++++++++++ src/operators/tensor/core.cairo | 44 ++++++++++ .../implementations/tensor_fp16x16.cairo | 5 ++ .../implementations/tensor_fp16x16wide.cairo | 5 ++ .../implementations/tensor_fp32x32.cairo | 5 ++ .../implementations/tensor_fp64x64.cairo | 5 ++ .../implementations/tensor_fp8x23.cairo | 5 ++ .../implementations/tensor_fp8x23wide.cairo | 5 ++ .../tensor/implementations/tensor_i32.cairo | 5 ++ .../tensor/implementations/tensor_i8.cairo | 5 ++ .../tensor/implementations/tensor_u32.cairo | 5 ++ tests/src/nodes.cairo | 5 ++ tests/src/nodes/identity_fP16x16.cairo | 19 ++++ .../src/nodes/identity_fP16x16/input_0.cairo | 18 ++++ .../src/nodes/identity_fP16x16/output_0.cairo | 18 ++++ tests/src/nodes/identity_fP8x23.cairo | 20 +++++ tests/src/nodes/identity_fP8x23/input_0.cairo | 18 ++++ .../src/nodes/identity_fP8x23/output_0.cairo | 18 ++++ tests/src/nodes/identity_i32.cairo | 20 +++++ tests/src/nodes/identity_i32/input_0.cairo | 17 ++++ tests/src/nodes/identity_i32/output_0.cairo | 17 ++++ tests/src/nodes/identity_i8.cairo | 20 +++++ tests/src/nodes/identity_i8/input_0.cairo | 17 ++++ tests/src/nodes/identity_i8/output_0.cairo | 17 ++++ tests/src/nodes/identity_u32.cairo | 20 +++++ tests/src/nodes/identity_u32/input_0.cairo | 16 ++++ tests/src/nodes/identity_u32/output_0.cairo | 16 ++++ 31 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.identity.md create mode 100644 nodegen/node/identity.py create mode 100644 tests/src/nodes/identity_fP16x16.cairo create mode 100644 tests/src/nodes/identity_fP16x16/input_0.cairo create mode 100644 tests/src/nodes/identity_fP16x16/output_0.cairo create mode 100644 tests/src/nodes/identity_fP8x23.cairo create mode 100644 tests/src/nodes/identity_fP8x23/input_0.cairo create mode 100644 tests/src/nodes/identity_fP8x23/output_0.cairo create mode 100644 tests/src/nodes/identity_i32.cairo create mode 100644 tests/src/nodes/identity_i32/input_0.cairo create mode 100644 tests/src/nodes/identity_i32/output_0.cairo create mode 100644 tests/src/nodes/identity_i8.cairo create mode 100644 tests/src/nodes/identity_i8/input_0.cairo create mode 100644 tests/src/nodes/identity_i8/output_0.cairo create mode 100644 tests/src/nodes/identity_u32.cairo create mode 100644 tests/src/nodes/identity_u32/input_0.cairo create mode 100644 tests/src/nodes/identity_u32/output_0.cairo diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 07de3f249..b5d966102 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -86,6 +86,7 @@ * [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) * [tensor.sign](framework/operators/tensor/tensor.sign.md) * [tensor.clip](framework/operators/tensor/tensor.clip.md) + * [tensor.identity](framework/operators/tensor/tensor.identity.md) * [Neural Network](framework/operators/neural-network/README.md) * [nn.relu](framework/operators/neural-network/nn.relu.md) * [nn.leaky\_relu](framework/operators/neural-network/nn.leaky\_relu.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index a7b415cc6..a18efebf5 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -57,5 +57,6 @@ You can see below the list of current supported ONNX Operators: | [Unsqueeze](operators/tensor/tensor.unsqueeze.md) | :white\_check\_mark: | | [Sign](operators/tensor/tensor.sign.md) | :white\_check\_mark: | | [Clip](operators/tensor/tensor.clip.md) | :white\_check\_mark: | +| [Identity](operators/tensor/tensor.identity.md) | :white\_check\_mark: | -Current Operators support: **50/156 (32%)** +Current Operators support: **51/156 (33%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index b33f330c7..a7261616e 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -82,6 +82,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.unsqueeze`](tensor.unsqueeze.md) | Inserts single-dimensional entries to the shape of an input tensor. | | [`tensor.sign`](tensor.sign.md) | Calculates the sign of the given input tensor element-wise. | | [`tensor.clip`](tensor.clip.md) | Clip operator limits the given input within an interval. | +| [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.identity.md b/docs/framework/operators/tensor/tensor.identity.md new file mode 100644 index 000000000..902972c84 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.identity.md @@ -0,0 +1,33 @@ +# tensor.identity + +```rust + fn identity(self: @Tensor) -> Tensor; +``` + +Return a Tensor with the same shape and contents as input. + +## Args + +* `self`(`@Tensor`) - Input tensor. + +## Returns + +A new `Tensor` to copy input into. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; + +fn identity_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2].span(), + data: array![1, 2, 3, 4].span(), + ); + let t_identity = tensor.identity(); + t_identity +} +>>> [[1 2] [3 4]] // A Tensor with the same shape and contents as input +``` diff --git a/nodegen/node/identity.py b/nodegen/node/identity.py new file mode 100644 index 000000000..eb46b93e9 --- /dev/null +++ b/nodegen/node/identity.py @@ -0,0 +1,86 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Identity(RunAll): + + @staticmethod + def identity_fP8x23(): + def identity(): + x = np.array([[1, 2], [3, 4]]) + y = x + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "identity_fP8x23" + make_node([x], [y], name) + + make_test( + [x], y, "input_0.identity()", name) + identity() + + @staticmethod + def identity_fP16x16(): + def identity(): + x = np.array([[1, 2], [3, 4]]) + y = x + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "identity_fP16x16" + make_node([x], [y], name) + + make_test( + [x], y, "input_0.identity()", name) + identity() + + @staticmethod + def identity_i8(): + def identity(): + x = np.array([[1, 2], [3, 4]]) + y = x + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "identity_i8" + make_node([x], [y], name) + + make_test( + [x], y, "input_0.identity()", name) + identity() + + @staticmethod + def identity_i32(): + def identity(): + x = np.array([[1, 2], [3, 4]]) + y = x + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "identity_i32" + make_node([x], [y], name) + + make_test( + [x], y, "input_0.identity()", name) + identity() + + @staticmethod + def identity_u32(): + def identity(): + x = np.array([[1, 2], [3, 4]]) + y = x + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "identity_u32" + make_node([x], [y], name) + + make_test( + [x], y, "input_0.identity()", name) + identity() \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 535ed699c..7d5300a00 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -78,6 +78,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new @@ -2669,6 +2670,41 @@ trait TensorTrait { /// ``` /// fn sign(self: @Tensor) -> Tensor; + /// # tensor.identity + /// + /// ```rust + /// fn identity(self: @Tensor) -> Tensor; + /// ``` + /// + /// Return a Tensor with the same shape and contents as input. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - Input tensor. + /// + /// ## Returns + /// + /// A new `Tensor` to copy input into. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; + /// + /// fn identity_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![1, 2, 3, 4].span(), + /// ); + /// let t_identity = tensor.identity(); + /// t_identity + /// } + /// >>> [[1 2] [3 4]] // A Tensor with the same shape and contents as input + /// ``` + /// + fn identity(self: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring @@ -3243,3 +3279,11 @@ fn clip< return Tensor:: { shape: *self.shape, data: return_data.span() }; } + +/// Cf: TensorTrait::identity docstring +fn identity +( + self: @Tensor +) -> Tensor { + Tensor:: { shape: *self.shape, data: *self.data } +} \ No newline at end of file diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index ac803904e..8833f3a0c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -229,6 +229,11 @@ impl FP16x16Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 0a89fe72d..2d402df8a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -237,6 +237,11 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 19557eba1..c0a60cf91 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -230,6 +230,11 @@ impl FP32x32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 686d319b1..80d80277b 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -230,6 +230,11 @@ impl FP64x64Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index f46e96fb5..6ec80ad50 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -229,6 +229,11 @@ impl FP8x23Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 91ca9338d..67b117019 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -229,6 +229,11 @@ impl FP8x23WTensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index dd6ae6f59..e66f14701 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -228,6 +228,11 @@ impl I32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index a4518cefb..6673caddb 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -227,6 +227,11 @@ impl I8Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 4d26a8634..4c8fad8a8 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -221,6 +221,11 @@ impl U32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/tests/src/nodes.cairo b/tests/src/nodes.cairo index 398edc4bf..18a877f8b 100644 --- a/tests/src/nodes.cairo +++ b/tests/src/nodes.cairo @@ -433,3 +433,8 @@ mod clip_i8_2d; mod clip_i8_3d; mod clip_u32_2d; mod clip_u32_3d; +mod identity_fP16x16; +mod identity_fP8x23; +mod identity_i32; +mod identity_i8; +mod identity_u32; diff --git a/tests/src/nodes/identity_fP16x16.cairo b/tests/src/nodes/identity_fP16x16.cairo new file mode 100644 index 000000000..5a3fa9893 --- /dev/null +++ b/tests/src/nodes/identity_fP16x16.cairo @@ -0,0 +1,19 @@ +mod input_0; +mod output_0; + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_identity_fP16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.identity(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/identity_fP16x16/input_0.cairo b/tests/src/nodes/identity_fP16x16/input_0.cairo new file mode 100644 index 000000000..621d26f75 --- /dev/null +++ b/tests/src/nodes/identity_fP16x16/input_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1, sign: false }); + data.append(FP16x16 { mag: 2, sign: false }); + data.append(FP16x16 { mag: 3, sign: false }); + data.append(FP16x16 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_fP16x16/output_0.cairo b/tests/src/nodes/identity_fP16x16/output_0.cairo new file mode 100644 index 000000000..c43d35cc6 --- /dev/null +++ b/tests/src/nodes/identity_fP16x16/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1, sign: false }); + data.append(FP16x16 { mag: 2, sign: false }); + data.append(FP16x16 { mag: 3, sign: false }); + data.append(FP16x16 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_fP8x23.cairo b/tests/src/nodes/identity_fP8x23.cairo new file mode 100644 index 000000000..0d525dd66 --- /dev/null +++ b/tests/src/nodes/identity_fP8x23.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_identity_fP8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.identity(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/identity_fP8x23/input_0.cairo b/tests/src/nodes/identity_fP8x23/input_0.cairo new file mode 100644 index 000000000..788d470dc --- /dev/null +++ b/tests/src/nodes/identity_fP8x23/input_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + data.append(FP8x23 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_fP8x23/output_0.cairo b/tests/src/nodes/identity_fP8x23/output_0.cairo new file mode 100644 index 000000000..91c661c60 --- /dev/null +++ b/tests/src/nodes/identity_fP8x23/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + data.append(FP8x23 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i32.cairo b/tests/src/nodes/identity_i32.cairo new file mode 100644 index 000000000..a9071a4d5 --- /dev/null +++ b/tests/src/nodes/identity_i32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_identity_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.identity(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i32/input_0.cairo b/tests/src/nodes/identity_i32/input_0.cairo new file mode 100644 index 000000000..235eb099e --- /dev/null +++ b/tests/src/nodes/identity_i32/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i32/output_0.cairo b/tests/src/nodes/identity_i32/output_0.cairo new file mode 100644 index 000000000..a9b5e2a13 --- /dev/null +++ b/tests/src/nodes/identity_i32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i8.cairo b/tests/src/nodes/identity_i8.cairo new file mode 100644 index 000000000..29af4b5ea --- /dev/null +++ b/tests/src/nodes/identity_i8.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_identity_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.identity(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i8/input_0.cairo b/tests/src/nodes/identity_i8/input_0.cairo new file mode 100644 index 000000000..93b08b452 --- /dev/null +++ b/tests/src/nodes/identity_i8/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_i8/output_0.cairo b/tests/src/nodes/identity_i8/output_0.cairo new file mode 100644 index 000000000..1aac8f583 --- /dev/null +++ b/tests/src/nodes/identity_i8/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_u32.cairo b/tests/src/nodes/identity_u32.cairo new file mode 100644 index 000000000..548b41804 --- /dev/null +++ b/tests/src/nodes/identity_u32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_identity_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.identity(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/identity_u32/input_0.cairo b/tests/src/nodes/identity_u32/input_0.cairo new file mode 100644 index 000000000..9594bde53 --- /dev/null +++ b/tests/src/nodes/identity_u32/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/identity_u32/output_0.cairo b/tests/src/nodes/identity_u32/output_0.cairo new file mode 100644 index 000000000..c760602db --- /dev/null +++ b/tests/src/nodes/identity_u32/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file