diff --git a/docs/.gitbook/assets/Capture d#U2019#U00e9cran 2023-06-08 #U00e0 17.59.46.png b/docs/.gitbook/assets/Capture d#U2019#U00e9cran 2023-06-08 #U00e0 17.59.46.png new file mode 100644 index 000000000..713f9f0df Binary files /dev/null and b/docs/.gitbook/assets/Capture d#U2019#U00e9cran 2023-06-08 #U00e0 17.59.46.png differ diff --git a/docs/.gitbook/assets/Capture d#U2019e#U0301cran 2023-06-08 a#U0300 17.59.46.png b/docs/.gitbook/assets/Capture d#U2019e#U0301cran 2023-06-08 a#U0300 17.59.46.png new file mode 100644 index 000000000..713f9f0df Binary files /dev/null and b/docs/.gitbook/assets/Capture d#U2019e#U0301cran 2023-06-08 a#U0300 17.59.46.png differ diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index eba6bc647..16aa93858 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -133,6 +133,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.dynamic_quantize_linear`](tensor.dynamic\_quantize\_linear.md) | Computes the Scale, Zero Point and FP32->8Bit conversion of FP32 Input data. | | [`tensor.scatter_nd`](tensor.scatter\_nd.md) | The output of the operation is produced by creating a copy of the input data, and then updating its value to values specified by updates at specific index positions specified by indices. Its output shape is the same as the shape of data | | [`tensor.label_encoder`](tensor.label\_encoder.md) | Maps each element in the input tensor to another value. | +| [`tensor.eye_like`](tensor.eye\_like.md) | Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the same as the input tensor. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.eye_like.md b/docs/framework/operators/tensor/tensor.eye_like.md new file mode 100644 index 000000000..6d5ce38e4 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.eye_like.md @@ -0,0 +1,44 @@ +# TensorTrait::eye_like + +```rust + fn eye_like(self: @Tensor, k: Option) -> Tensor; +``` + +Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the same as the input tensor. By default, the main diagonal is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. + +## Args + +* `self`(`@Tensor`) - 2D input tensor to copy shape, and optionally, type information from. +* `k`(Option) - (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. + +## Returns + +* Output tensor, same shape as input tensor. + +## Examples + +```rust +use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::numbers::{FixedTrait, FP8x23}; + + +fn example() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + let tensor1 = TensorTrait::new(shape.span(), data.span()); + + return tensor1.eye_like(Option::Some(0)); +} +>>> [1, 0, 0, 1] +``` diff --git a/nodegen/node/eye_like.py b/nodegen/node/eye_like.py new file mode 100644 index 000000000..4c6b36501 --- /dev/null +++ b/nodegen/node/eye_like.py @@ -0,0 +1,89 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait, get_data_statement + +def eye_like(data, k=None) -> np.ndarray: # type: ignore + if data is None: + _dtype = np.float32 + else: + _dtype = data.dtype + shape = data.shape + if len(shape) == 1: + sh = (shape[0], shape[0]) + elif len(shape) == 2: + sh = shape + else: + raise RuntimeError(f"EyeLike only accept 1D or 2D tensors not {shape!r}.") + return np.eye(*sh, k=k, dtype=_dtype) # type: ignore + +class Eye_like(RunAll): + + @staticmethod + # We test here with fp8x23 implementation. + def fp8x23(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + k = 0 + y = eye_like(x, k) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "eye_like_fp8x23" + make_test([x], y, f"input_0.eye_like(Option::Some({k}))", name) + + @staticmethod + # We test here with fp16x16 implementation. + def fp16x16(): + x = np.random.randint(-3, 3, (4, 7)).astype(np.float64) + k = 3 + y = eye_like(x, k) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "eye_like_fp16x16" + make_test([x], y, f"input_0.eye_like(Option::Some({k}))", name) + + @staticmethod + # We test here with i8 implementation. + def i8(): + x = np.random.randint(0, 6, (5, 3)).astype(np.int8) + k = -2 + y = eye_like(x, k) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "eye_like_i8" + make_test([x], y, f"input_0.eye_like(Option::Some({k}))", name) + + @staticmethod + # We test here with i32 implementation. + def i32(): + x = np.random.randint(0, 6, (5, 8)).astype(np.int32) + k = 9 + y = eye_like(x, k) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "eye_like_i32" + make_test([x], y, f"input_0.eye_like(Option::Some({k}))", name) + + @staticmethod + # We test here with u32 implementation. + def u32(): + x = np.random.randint(0, 6, (1, 2)).astype(np.uint32) + k = -7 + y = eye_like(x, k) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "eye_like_u32" + make_test([x], y, f"input_0.eye_like(Option::Some({k}))", name) + \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 7fbecd10c..f02ad07db 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -137,8 +137,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -6090,6 +6089,52 @@ trait TensorTrait { values: Option>, values_tensor: Option> ) -> Tensor; + /// # TensorTrait::eye_like + /// + /// ```rust + /// fn eye_like(self: @Tensor, k: Option) -> Tensor; + /// ``` + /// + /// Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D tensors are supported, i.e. input T1 must be of rank 2. The shape of the output tensor is the same as the input tensor. By default, the main diagonal is populated with ones, but attribute 'k' can be used to populate upper or lower diagonals. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - 2D input tensor to copy shape, and optionally, type information from. + /// * `k`(Option) - (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. + /// + /// ## Returns + /// + /// * Output tensor, same shape as input tensor. + /// + /// ## Examples + /// + /// ```rust + /// use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; + /// use core::array::{ArrayTrait, SpanTrait}; + /// use orion::operators::tensor::{TensorTrait, Tensor}; + /// use orion::utils::{assert_eq, assert_seq_eq}; + /// use orion::operators::tensor::FP8x23TensorPartialEq; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// + /// fn example() -> Tensor { + /// let mut shape = ArrayTrait::::new(); + /// shape.append(2); + /// shape.append(2); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(FP8x23 { mag: 16777216, sign: true }); + /// data.append(FP8x23 { mag: 16777216, sign: false }); + /// data.append(FP8x23 { mag: 16777216, sign: true }); + /// data.append(FP8x23 { mag: 16777216, sign: false }); + /// let tensor1 = TensorTrait::new(shape.span(), data.span()); + /// + /// return tensor1.eye_like(Option::Some(0)); + /// } + /// >>> [1, 0, 0, 1] + /// ``` + /// + fn eye_like(self: @Tensor, k: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d1a79459b..ae9db301e 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -580,6 +580,10 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_complex64.cairo b/src/operators/tensor/implementations/tensor_complex64.cairo index b087508f4..6f3365613 100644 --- a/src/operators/tensor/implementations/tensor_complex64.cairo +++ b/src/operators/tensor/implementations/tensor_complex64.cairo @@ -623,6 +623,10 @@ impl Complex64Tensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index f3d74e1b3..1def7faee 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -691,6 +691,10 @@ impl FP16x16Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 e809f3658..149ac9478 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -632,6 +632,10 @@ impl FP16x16WTensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 87b0e80bc..8c9a04870 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -687,6 +687,10 @@ impl FP32x32Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 d186dc286..f9dc77c08 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -687,6 +687,10 @@ impl FP64x64Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 50ff34775..483b34da7 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -683,6 +683,10 @@ impl FP8x23Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 132d4fdd0..1ee38295f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -609,6 +609,10 @@ impl FP8x23WTensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 cef00cadc..b8b17d088 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -651,6 +651,10 @@ impl I32Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 282670ca7..79eaaf34f 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -654,6 +654,10 @@ impl I8Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// 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 a796350cb..a54477995 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -579,6 +579,10 @@ impl U32Tensor of TensorTrait { self, default_list, default_tensor, keys, keys_tensor, values, values_tensor ) } + + fn eye_like(self: @Tensor, k: Option) -> Tensor { + math::eye_like::eye_like(self, k) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index b73f6d102..3bd31745e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -68,3 +68,4 @@ mod hann_window; mod hamming_window; mod blackman_window; mod scatter_nd; +mod eye_like; diff --git a/src/operators/tensor/math/eye_like.cairo b/src/operators/tensor/math/eye_like.cairo new file mode 100644 index 000000000..012fd2ce4 --- /dev/null +++ b/src/operators/tensor/math/eye_like.cairo @@ -0,0 +1,61 @@ +use orion::numbers::fixed_point::core::FixedTrait; +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; + +fn eye_like< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TAdd: Add, + impl TSub: Sub, + impl TMul: Mul, + impl TDiv: Div, + impl TTensorAdd: Add>, + impl TPartialOrd: PartialOrd, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, +>( + self: @Tensor, k: Option +) -> Tensor { + assert((*self.shape).len() == 2 || (*self.shape).len() == 1, 'Unexpected shape.'); + let mut shape = *self.shape; + if (*self.shape).len()==1 { + shape = (array![*(*self.shape).at(0), *(*self.shape).at(0)]).span(); + }; + let M = *shape.at(1); + let K = match k { + Option::Some(val) => val, + Option::None => 0, + }; + let len = *(shape.at(0)) * (*(shape.at(1))); + let mut i: usize = 0; + let mut arr: Array = array![]; + while i != len { + arr.append(NumberTrait::zero()); + i += 1; + }; + if (K >= M.try_into().unwrap()) { + return TensorTrait::::new(shape, arr.span()); + }; + let mut j: usize = 0; + if (K < 0){ + j = (-(K)).try_into().unwrap() * M; + } else { + j = K.try_into().unwrap(); + }; + let end: usize = (M.try_into().unwrap() - K).try_into().unwrap() * M; + i = 0; + arr = array![]; + while i != len { + if (i == j && j < end) { + arr.append(NumberTrait::one()); + j += (M + 1); + } else { + arr.append(NumberTrait::zero()); + }; + i += 1; + }; + return TensorTrait::::new(shape, arr.span()); +} \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 64d07a9f1..08efc0821 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -955,6 +955,11 @@ mod label_encoder_fp8x23_default; mod label_encoder_i8_default; mod label_encoder_i32_default; mod label_encoder_u32_default; +mod eye_like_fp8x23; +mod eye_like_fp16x16; +mod eye_like_i32; +mod eye_like_i8; +mod eye_like_u32; mod conv_interger_with_padding; mod conv_interger_no_padding; mod qlinear_conv; diff --git a/tests/nodes/eye_like_fp16x16.cairo b/tests/nodes/eye_like_fp16x16.cairo new file mode 100644 index 000000000..e6308ebdb --- /dev/null +++ b/tests/nodes/eye_like_fp16x16.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; + +#[test] +#[available_gas(2000000000)] +fn test_eye_like_fp16x16() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.eye_like(Option::Some(3)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/eye_like_fp16x16/input_0.cairo b/tests/nodes/eye_like_fp16x16/input_0.cairo new file mode 100644 index 000000000..f836579aa --- /dev/null +++ b/tests/nodes/eye_like_fp16x16/input_0.cairo @@ -0,0 +1,41 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorAdd}; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(4); + shape.append(7); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_fp16x16/output_0.cairo b/tests/nodes/eye_like_fp16x16/output_0.cairo new file mode 100644 index 000000000..0c7816343 --- /dev/null +++ b/tests/nodes/eye_like_fp16x16/output_0.cairo @@ -0,0 +1,41 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorAdd}; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(4); + shape.append(7); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_fp8x23.cairo b/tests/nodes/eye_like_fp8x23.cairo new file mode 100644 index 000000000..5b27f9c19 --- /dev/null +++ b/tests/nodes/eye_like_fp8x23.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; +use orion::operators::tensor::{TensorTrait, Tensor}; + +#[test] +#[available_gas(2000000000)] +fn test_eye_like_fp8x23() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.eye_like(Option::Some(0)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/eye_like_fp8x23/input_0.cairo b/tests/nodes/eye_like_fp8x23/input_0.cairo new file mode 100644 index 000000000..f6d72b464 --- /dev/null +++ b/tests/nodes/eye_like_fp8x23/input_0.cairo @@ -0,0 +1,17 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; +use orion::numbers::{FixedTrait, 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: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_fp8x23/output_0.cairo b/tests/nodes/eye_like_fp8x23/output_0.cairo new file mode 100644 index 000000000..b34779fa2 --- /dev/null +++ b/tests/nodes/eye_like_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; +use orion::numbers::{FixedTrait, 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: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_i32.cairo b/tests/nodes/eye_like_i32.cairo new file mode 100644 index 000000000..dc9b9e4db --- /dev/null +++ b/tests/nodes/eye_like_i32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{I32Tensor, I32TensorAdd}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_eye_like_i32() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.eye_like(Option::Some(9)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/eye_like_i32/input_0.cairo b/tests/nodes/eye_like_i32/input_0.cairo new file mode 100644 index 000000000..52dcd9d16 --- /dev/null +++ b/tests/nodes/eye_like_i32/input_0.cairo @@ -0,0 +1,53 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{I32Tensor, I32TensorAdd}; +use orion::numbers::NumberTrait; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(5); + shape.append(8); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(4); + data.append(4); + data.append(4); + data.append(3); + data.append(0); + data.append(1); + data.append(5); + data.append(0); + data.append(5); + data.append(3); + data.append(4); + data.append(5); + data.append(4); + data.append(0); + data.append(1); + data.append(5); + data.append(4); + data.append(3); + data.append(3); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(5); + data.append(5); + data.append(4); + data.append(3); + data.append(5); + data.append(4); + data.append(4); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_i32/output_0.cairo b/tests/nodes/eye_like_i32/output_0.cairo new file mode 100644 index 000000000..df6b89e08 --- /dev/null +++ b/tests/nodes/eye_like_i32/output_0.cairo @@ -0,0 +1,53 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{I32Tensor, I32TensorAdd}; +use orion::numbers::NumberTrait; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(5); + shape.append(8); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_i8.cairo b/tests/nodes/eye_like_i8.cairo new file mode 100644 index 000000000..e6077dc0d --- /dev/null +++ b/tests/nodes/eye_like_i8.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{I8Tensor, I8TensorAdd}; + +#[test] +#[available_gas(2000000000)] +fn test_eye_like_i8() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.eye_like(Option::Some(-2)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/eye_like_i8/input_0.cairo b/tests/nodes/eye_like_i8/input_0.cairo new file mode 100644 index 000000000..b3a862444 --- /dev/null +++ b/tests/nodes/eye_like_i8/input_0.cairo @@ -0,0 +1,28 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{I8Tensor, I8TensorAdd}; +use orion::numbers::NumberTrait; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(5); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(4); + data.append(5); + data.append(5); + data.append(1); + data.append(1); + data.append(4); + data.append(1); + data.append(5); + data.append(0); + data.append(2); + data.append(4); + data.append(0); + data.append(0); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_i8/output_0.cairo b/tests/nodes/eye_like_i8/output_0.cairo new file mode 100644 index 000000000..2da514c89 --- /dev/null +++ b/tests/nodes/eye_like_i8/output_0.cairo @@ -0,0 +1,28 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{I8Tensor, I8TensorAdd}; +use orion::numbers::NumberTrait; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(5); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_u32.cairo b/tests/nodes/eye_like_u32.cairo new file mode 100644 index 000000000..a45b0f4e1 --- /dev/null +++ b/tests/nodes/eye_like_u32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_eye_like_u32() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.eye_like(Option::Some(-7)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/eye_like_u32/input_0.cairo b/tests/nodes/eye_like_u32/input_0.cairo new file mode 100644 index 000000000..de9e68f35 --- /dev/null +++ b/tests/nodes/eye_like_u32/input_0.cairo @@ -0,0 +1,15 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/eye_like_u32/output_0.cairo b/tests/nodes/eye_like_u32/output_0.cairo new file mode 100644 index 000000000..dc8ee52be --- /dev/null +++ b/tests/nodes/eye_like_u32/output_0.cairo @@ -0,0 +1,15 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +}