From 1f73e545862e1806e7eb08cc2502df821bb6d9e5 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Thu, 26 Oct 2023 17:28:43 +0100 Subject: [PATCH 001/127] "feat: implement type bool tensor" --- .../tensor/implementations/tensor_bool.cairo | 335 ++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 src/operators/tensor/implementations/tensor_bool.cairo diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo new file mode 100644 index 000000000..e9d830947 --- /dev/null +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -0,0 +1,335 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; +use traits::{TryInto, Into}; + +use orion::numbers::fixed_point::core::FixedTrait; +use orion::operators::tensor::core::{ + new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, +}; +use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::numbers::{bool, i32, NumberTrait}; +use orion::operators::tensor::implementations::tensor_u32::U32Tensor; + +impl BoolTensor of TensorTrait { + fn new(shape: Span, data: Span) -> Tensor { + new_tensor(shape, data) + } + + fn at(self: @Tensor, indices: Span) -> bool { + *at_tensor(self, indices) + } + + fn min(self: @Tensor) -> bool { + math::min::min_in_tensor::(*self.data) + } + + fn max(self: @Tensor) -> bool { + math::max::max_in_tensor(*self.data) + } + + fn stride(self: @Tensor) -> Span { + stride(*self.shape) + } + + fn ravel_index(self: @Tensor, indices: Span) -> usize { + ravel_index(*self.shape, indices) + } + + fn unravel_index(self: @Tensor, index: usize) -> Span { + unravel_index(index, *self.shape) + } + + fn reshape(self: @Tensor, target_shape: Span) -> Tensor { + reshape(self, target_shape) + } + + fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum::reduce_sum(self, axis, keepdims) + } + + fn argmax( + self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option + ) -> Tensor { + math::argmax::argmax(self, axis, keepdims, select_last_index) + } + + fn argmin( + self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option + ) -> Tensor { + math::argmin::argmin(self, axis, keepdims, select_last_index) + } + + fn transpose(self: @Tensor, axes: Span) -> Tensor { + linalg::transpose::transpose(self, axes) + } + + fn matmul(self: @Tensor, other: @Tensor) -> Tensor { + linalg::matmul::matmul(self, other) + } + + fn exp(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn log(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn equal(self: @Tensor, other: @Tensor) -> Tensor { + math::equal::equal(self, other) + } + + fn greater(self: @Tensor, other: @Tensor) -> Tensor { + math::greater::greater(self, other) + } + + fn greater_equal(self: @Tensor, other: @Tensor) -> Tensor { + math::greater_equal::greater_equal(self, other) + } + + fn less(self: @Tensor, other: @Tensor) -> Tensor { + math::less::less(self, other) + } + + fn less_equal(self: @Tensor, other: @Tensor) -> Tensor { + math::less_equal::less_equal(self, other) + } + + fn abs(self: @Tensor) -> Tensor { + math::abs::abs(*self) + } + + fn ceil(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn sin(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn cos(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn asin(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn cumsum( + self: @Tensor, axis: usize, exclusive: Option, reverse: Option + ) -> Tensor { + panic(array!['not supported!']) + } + + fn flatten(self: @Tensor, axis: usize) -> Tensor { + math::flatten::flatten(self, axis) + } + + fn sinh(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn tanh(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn cosh(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn acosh(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn asinh(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn atan(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn xor(self: @Tensor, other: @Tensor) -> Tensor { + math::xor::xor(self, other) + } + + fn or(self: @Tensor, other: @Tensor) -> Tensor { + math::or::or(self, other) + } + + fn acos(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn onehot( + self: @Tensor, depth: usize, axis: Option, values: Span + ) -> Tensor { + panic(array!['not supported!']) + } + + fn sqrt(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn concat(tensors: Span>, axis: usize,) -> Tensor { + panic(array!['not supported!']) + } + + fn quantize_linear( + self: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor + ) -> Tensor:: { + quantization::quantize_linear::quantize_linear( + self, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + + fn dequantize_linear( + self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor + ) -> Tensor:: { + quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) + } + + fn slice( + self: @Tensor, + starts: Span, + ends: Span, + axes: Option>, + steps: Option> + ) -> Tensor { + core::slice::(self, starts, ends, axes, steps) + } + + fn gather(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + math::gather::gather(self, indices, axis) + } + + fn nonzero(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn squeeze(self: @Tensor, axes: Option>) -> Tensor { + panic(array!['not supported!']) + } + + fn unsqueeze(self: @Tensor, axes: Span) -> Tensor { + panic(array!['not supported!']) + } + + fn sign(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { + panic(array!['not supported!']) + } +} + +/// Implements addition for `Tensor` using the `Add` trait. +impl boolTensorAdd of Add> { + /// Adds two `Tensor` instances element-wise. + /// + /// # Arguments + /// * `lhs` - The first tensor. + /// * `rhs` - The second tensor. + /// + /// # Returns + /// * A `Tensor` instance representing the result of the element-wise addition. + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } +} + +/// Implements subtraction for `Tensor` using the `Sub` trait. +impl boolTensorSub of Sub> { + /// Subtracts two `Tensor` instances element-wise. + /// + /// # Arguments + /// * `lhs` - The first tensor. + /// * `rhs` - The second tensor. + /// + /// # Returns + /// * A `Tensor` instance representing the result of the element-wise subtraction. + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } +} + +/// Implements multiplication for `Tensor` using the `Mul` trait. +impl boolTensorMul of Mul> { + /// Multiplies two `Tensor` instances element-wise. + /// + /// # Arguments + /// * `lhs` - The first tensor. + /// * `rhs` - The second tensor. + /// + /// # Returns + /// * A `Tensor` instance representing the result of the element-wise multiplication. + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } +} + +/// Implements division for `Tensor` using the `Div` trait. +impl boolTensorDiv of Div> { + /// Divides two `Tensor` instances element-wise. + /// + /// # Arguments + /// * `lhs` - The first tensor. + /// * `rhs` - The second tensor. + /// + /// # Returns + /// * A `Tensor` instance representing the result of the element-wise division. + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } +} + +/// Implements partial equal for two `Tensor` using the `PartialEq` trait. +impl boolTensorPartialEq of PartialEq> { + fn eq(lhs: @Tensor, rhs: @Tensor) -> bool { + tensor_eq(*lhs, *rhs) + } + + fn ne(lhs: @Tensor, rhs: @Tensor) -> bool { + !tensor_eq(*lhs, *rhs) + } +} + +impl boolTryIntobool of TryInto { + fn try_into(self: bool) -> Option { + Option::Some(self) + } +} + +// Internals + +fn tensor_eq(mut lhs: Tensor, mut rhs: Tensor,) -> bool { + let mut is_eq = true; + + loop { + if lhs.shape.len() == 0 || !is_eq { + break; + } + + is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); + }; + + if !is_eq { + return false; + } + + loop { + if lhs.data.len() == 0 || !is_eq { + break; + } + + is_eq = lhs.data.pop_front().unwrap() == rhs.data.pop_front().unwrap(); + }; + + return is_eq; +} From 121776f5c4de561aca6e76cbb67ff223288056e9 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Fri, 27 Oct 2023 11:24:04 +0100 Subject: [PATCH 002/127] "feat: test for bool tensor type" --- tests/src/tensor_core/at.cairo | 1 + tests/src/tensor_core/at/at_bool_test.cairo | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/src/tensor_core/at/at_bool_test.cairo diff --git a/tests/src/tensor_core/at.cairo b/tests/src/tensor_core/at.cairo index b5cb3376c..da455d08a 100644 --- a/tests/src/tensor_core/at.cairo +++ b/tests/src/tensor_core/at.cairo @@ -1,3 +1,4 @@ mod at_u32_test; mod at_i32_test; mod at_fp_test; +mod at_bool_test; diff --git a/tests/src/tensor_core/at/at_bool_test.cairo b/tests/src/tensor_core/at/at_bool_test.cairo new file mode 100644 index 000000000..78c7c10f9 --- /dev/null +++ b/tests/src/tensor_core/at/at_bool_test.cairo @@ -0,0 +1,31 @@ +// ===== 1D ===== // + +#[cfg(test)] +mod tensor_1D { + use array::ArrayTrait; + use orion::operators::tensor::BoolTensor; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(true); + data.append(false); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + + let mut indices = ArrayTrait::new(); + indices.append(1); + + let result = tensor.at(indices.span()).mag; + + assert(result == true, 'result[2] = true'); + } +} \ No newline at end of file From b6fba4045b1b09d0b1328c83d042dfc4547d0a17 Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Mon, 30 Oct 2023 18:46:38 +0300 Subject: [PATCH 003/127] feat: fixed point bitwise and methods added --- .../fixed_point/implementations/fp16x16/math/comp.cairo | 4 ++++ .../fixed_point/implementations/fp16x16wide/math/comp.cairo | 4 ++++ src/numbers/fixed_point/implementations/fp32x32/comp.cairo | 4 ++++ src/numbers/fixed_point/implementations/fp64x64/comp.cairo | 4 ++++ .../fixed_point/implementations/fp8x23/math/comp.cairo | 4 ++++ .../fixed_point/implementations/fp8x23wide/math/comp.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp16x16.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp16x16wide.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp32x32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp64x64.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp8x23.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp8x23wide.cairo | 4 ++++ 12 files changed, 48 insertions(+) diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 74f1dbf2f..45275b9fd 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -52,6 +52,10 @@ fn where(a: FP16x16, b: FP16x16, c: FP16x16) -> FP16x16 { } } +fn bitwise_and(a: FP16x16, b: FP16x16) -> FP16x16 { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 453969599..ae0d41432 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -52,6 +52,10 @@ fn where(a: FP16x16W, b: FP16x16W, c: FP16x16W) -> FP16x16W { } } +fn bitwise_and(a: FP16x16W, b: FP16x16W) -> FP16x16W { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo index c4821ba50..ed1fa7d92 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo @@ -34,3 +34,7 @@ fn where(a: FP32x32, b: FP32x32, c: FP32x32) -> FP32x32 { return b; } } + +fn bitwise_and(a: FP32x32, b: FP32x32) -> FP32x32 { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} diff --git a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo index a55f9a5ca..98528a00c 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo @@ -34,3 +34,7 @@ fn where(a: FP64x64, b: FP64x64, c: FP64x64) -> FP64x64 { return b; } } + +fn bitwise_and(a: FP64x64, b: FP64x64) -> FP64x64 { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index a8bd83ef4..1ad7b6012 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -52,6 +52,10 @@ fn where(a: FP8x23, b: FP8x23, c: FP8x23) -> FP8x23 { } } +fn bitwise_and(a: FP8x23, b: FP8x23) -> FP8x23 { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index fbefd313f..197b6b1a7 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -52,6 +52,10 @@ fn where(a: FP8x23W, b: FP8x23W, c: FP8x23W) -> FP8x23W { } } +fn bitwise_and(a: FP8x23W, b: FP8x23W) -> FP8x23W { + return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index f726c8d1e..fad9cbd0a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -245,6 +245,10 @@ impl FP16x16Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 c4f2de169..8d4607b7b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -255,6 +255,10 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 5f78a86f6..aa98a823e 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -246,6 +246,10 @@ impl FP32x32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 d9e540293..5933bd659 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -246,6 +246,10 @@ impl FP64x64Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 153f179ef..a1797c761 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -245,6 +245,10 @@ impl FP8x23Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 f594eec4d..2432be167 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -245,6 +245,10 @@ impl FP8x23WTensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. From d3434a5a0838601c5d552e08820c0662e0aa721b Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Mon, 30 Oct 2023 18:51:46 +0300 Subject: [PATCH 004/127] feat: bitwise and added for signed int --- src/numbers/signed_integer/i128.cairo | 4 ++++ src/numbers/signed_integer/i16.cairo | 4 ++++ src/numbers/signed_integer/i32.cairo | 4 ++++ src/numbers/signed_integer/i64.cairo | 4 ++++ src/numbers/signed_integer/i8.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i8.cairo | 4 ++++ src/operators/tensor/implementations/tensor_u32.cairo | 4 ++++ 8 files changed, 32 insertions(+) diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index 1c100ddc5..93608fe24 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -469,3 +469,7 @@ fn i128_sign(a: i128) -> i128 { IntegerTrait::::new(1, a.sign) } } + +fn i128_bitwise_and(a: i128, b: i128) -> i128 { + IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) +} diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index 5d6b04ffa..c51c803bd 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -469,3 +469,7 @@ fn i16_sign(a: i16) -> i16 { IntegerTrait::::new(1, a.sign) } } + +fn i16_bitwise_and(a: i16, b: i16) -> i16 { + IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) +} diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index 0147ff0c3..ee44c73b1 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -501,3 +501,7 @@ fn i32_sign(a: i32) -> i32 { IntegerTrait::::new(1, a.sign) } } + +fn i32_bitwise_and(a: i32, b: i32) -> i32 { + IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) +} diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index 8bde7c0ee..99dddd68c 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -469,3 +469,7 @@ fn i64_sign(a: i64) -> i64 { IntegerTrait::::new(1, a.sign) } } + +fn i64_bitwise_and(a: i64, b: i64) -> i64 { + IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) +} \ No newline at end of file diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 1acc60ecd..72e92e911 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -546,3 +546,7 @@ fn i8_sign(a: i8) -> i8 { IntegerTrait::::new(1, a.sign) } } + +fn i8_bitwise_and(a: i8, b: i8) -> i8 { + return IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign); +} diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 057fb6853..7058e2783 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -244,6 +244,10 @@ impl I32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 ae2662f0d..1f7a3d2e6 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -243,6 +243,10 @@ impl I8Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// 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 fc83d35c3..e5a33b0d6 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -237,6 +237,10 @@ impl U32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_and::bitwise_and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. From 78280167be60c05c47fe8802009f09c470110fed Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Mon, 30 Oct 2023 18:54:47 +0300 Subject: [PATCH 005/127] feat: bitwise and path added --- src/numbers.cairo | 49 +++++++++++++++++++++++ src/operators/tensor/core.cairo | 70 +++++++++++++++++++++++++++++++++ src/operators/tensor/math.cairo | 1 + 3 files changed, 120 insertions(+) diff --git a/src/numbers.cairo b/src/numbers.cairo index d81cefa33..6c6a06c86 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -49,6 +49,7 @@ trait NumberTrait { fn sign(self: T) -> T; fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; + fn bitwise_and(lhs: T, rhs: T) -> T; } use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; @@ -226,6 +227,10 @@ impl FP8x23Number of NumberTrait { fn where(self: FP8x23, x: FP8x23, y: FP8x23) -> FP8x23 { comp_fp8x23::where(self, x, y) } + + fn bitwise_and(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + comp_fp8x23::bitwise_and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; @@ -403,6 +408,10 @@ impl FP8x23WNumber of NumberTrait { fn where(self: FP8x23W, x: FP8x23W, y: FP8x23W) -> FP8x23W { comp_fp8x23wide::where(self, x, y) } + + fn bitwise_and(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + comp_fp8x23wide::bitwise_and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -580,6 +589,10 @@ impl FP16x16Number of NumberTrait { fn where(self: FP16x16, x: FP16x16, y: FP16x16) -> FP16x16 { comp_fp16x16::where(self, x, y) } + + fn bitwise_and(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + comp_fp16x16::bitwise_and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; @@ -757,6 +770,10 @@ impl FP16x16WNumber of NumberTrait { fn where(self: FP16x16W, x: FP16x16W, y: FP16x16W) -> FP16x16W { comp_fp16x16wide::where(self, x, y) } + + fn bitwise_and(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + comp_fp16x16wide::bitwise_and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; @@ -935,6 +952,10 @@ impl FP64x64Number of NumberTrait { fn where(self: FP64x64, x: FP64x64, y: FP64x64) -> FP64x64 { comp_fp64x64::where(self, x, y) } + + fn bitwise_and(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + comp_fp64x64::bitwise_and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; @@ -1113,6 +1134,10 @@ impl FP32x32Number of NumberTrait { fn where(self: FP32x32, x: FP32x32, y: FP32x32) -> FP32x32 { comp_fp32x32::where(self, x, y) } + + fn bitwise_and(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + comp_fp32x32::bitwise_and(lhs, rhs) + } } use orion::numbers::signed_integer::i8 as i8_core; @@ -1305,6 +1330,10 @@ impl I8Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: i8, rhs: i8) -> i8 { + i8_core::i8_bitwise_and(lhs, rhs) + } } use orion::numbers::signed_integer::i16 as i16_core; @@ -1497,6 +1526,10 @@ impl i16Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: i16, rhs: i16) -> i16 { + i16_core::i16_bitwise_and(lhs, rhs) + } } use orion::numbers::signed_integer::i32 as i32_core; @@ -1689,6 +1722,10 @@ impl i32Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: i32, rhs: i32) -> i32 { + i32_core::i32_bitwise_and(lhs, rhs) + } } use orion::numbers::signed_integer::i64 as i64_core; @@ -1881,6 +1918,10 @@ impl i64Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: i64, rhs: i64) -> i64 { + i64_core::i64_bitwise_and(lhs, rhs) + } } use orion::numbers::signed_integer::i128 as i128_core; @@ -2074,6 +2115,10 @@ impl i128Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: i128, rhs: i128) -> i128 { + i128_core::i128_bitwise_and(lhs, rhs) + } } impl u32Number of NumberTrait { @@ -2272,4 +2317,8 @@ impl u32Number of NumberTrait { return x; } } + + fn bitwise_and(lhs: u32, rhs: u32) -> u32 { + lhs & rhs + } } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 94a9baac7..ba2ae157d 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -82,6 +82,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new @@ -2868,6 +2869,75 @@ trait TensorTrait { /// ``` /// fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor; + /// #tensor.and + /// + /// ```rust + /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the logical AND of two tensors element-wise. + /// The input tensors must have either: + /// * Exactly the same shape + /// * The same number of dimensions and the length of each dimension is either a common length or 1. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be compared + /// * `other`(`@Tensor`) - The second tensor to be compared + /// + /// ## Panics + /// + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Returns + /// + /// A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. + /// + /// ## Examples + /// + /// Case 1: Compare tensors with same shape + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn and_example() -> Tensor { + /// let tensor_1 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + /// ); + /// + /// let tensor_2 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 0, 1, 2, 0, 1, 2].span(), + /// ); + /// + /// return tensor_1.and(@tensor_2); + /// } + /// >>> [0,1,1,0,1,1,0,1,1] + /// ``` + /// + /// Case 2: Compare tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn and_example() -> Tensor { + /// let tensor_1 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + /// ); + /// + /// let tensor_2 = TensorTrait::::new( + /// shape: array![1, 3].span(), data: array![0, 1, 2].span(), + /// ); + /// + /// return tensor_1.and(@tensor_2); + /// } + /// >>> [0,1,1,0,1,1,0,1,1] + /// ``` + /// + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index d8c5a56f4..3fb97dae2 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -35,3 +35,4 @@ mod sign; mod and; mod neg; mod where; +mod bitwise_and; From 33bd8a6b868222d94f6b50f712486b36e0d719a9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Mon, 30 Oct 2023 18:35:40 +0200 Subject: [PATCH 006/127] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b69dbeef7..eaf6a0e61 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ target __pycache__ neural_network/.venv + +./Scarb.lock \ No newline at end of file From 86ba4b1ca903f0c096d9f70c9b3cdd6395249858 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 31 Oct 2023 12:07:41 +0200 Subject: [PATCH 007/127] git commit -m "Stop tracking Scarb.lock" --- .gitignore | 2 +- Scarb.lock | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 Scarb.lock diff --git a/.gitignore b/.gitignore index eaf6a0e61..5a0c79267 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ __pycache__ neural_network/.venv -./Scarb.lock \ No newline at end of file +Scarb.lock \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock deleted file mode 100644 index 85e5484e6..000000000 --- a/Scarb.lock +++ /dev/null @@ -1,20 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "alexandria_data_structures" -version = "0.1.0" -source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=f37d73d#f37d73d8a8248e4d8dc65de3949333e30bda022f" - -[[package]] -name = "cubit" -version = "1.2.0" -source = "git+https://github.com/raphaelDkhn/cubit.git#e6331ebf98c5d5f442a0e5edefe0b367c8e270d9" - -[[package]] -name = "orion" -version = "0.1.2" -dependencies = [ - "alexandria_data_structures", - "cubit", -] From 1bd61ec9225e2a3f917e1248b728c20dcdd2e938 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 31 Oct 2023 12:13:17 +0200 Subject: [PATCH 008/127] fix imports --- src/operators/tensor.cairo | 4 ++++ src/operators/tensor/implementations.cairo | 1 + 2 files changed, 5 insertions(+) diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 976102b52..dbc7ed664 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -30,3 +30,7 @@ use orion::operators::tensor::implementations::tensor_u32::{ U32Tensor, U32TensorAdd, U32TensorSub, U32TensorMul, U32TensorDiv, U32TensorPartialEq }; +use orion::operators::tensor::implementations::tensor_bool::{ + BoolTensor, BoolTensorPartialEq +}; + diff --git a/src/operators/tensor/implementations.cairo b/src/operators/tensor/implementations.cairo index 61dd41674..f463805ee 100644 --- a/src/operators/tensor/implementations.cairo +++ b/src/operators/tensor/implementations.cairo @@ -7,3 +7,4 @@ mod tensor_fp64x64; mod tensor_fp32x32; mod tensor_fp16x16wide; mod tensor_fp8x23wide; +mod tensor_bool; \ No newline at end of file From 1da34c64669d0a42ba02d63bd502331e63f37207 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 31 Oct 2023 12:20:42 +0200 Subject: [PATCH 009/127] fixed compilation errors --- .../tensor/implementations/tensor_bool.cairo | 76 +++++++++++-------- tests/lib.cairo | 12 +-- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index e9d830947..24d4a8e89 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -8,7 +8,7 @@ use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; -use orion::numbers::{bool, i32, NumberTrait}; +use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; impl BoolTensor of TensorTrait { @@ -21,11 +21,11 @@ impl BoolTensor of TensorTrait { } fn min(self: @Tensor) -> bool { - math::min::min_in_tensor::(*self.data) + panic(array!['not supported!']) } fn max(self: @Tensor) -> bool { - math::max::max_in_tensor(*self.data) + panic(array!['not supported!']) } fn stride(self: @Tensor) -> Span { @@ -45,19 +45,19 @@ impl BoolTensor of TensorTrait { } fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + panic(array!['not supported!']) } fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { - math::argmax::argmax(self, axis, keepdims, select_last_index) + panic(array!['not supported!']) } fn argmin( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { - math::argmin::argmin(self, axis, keepdims, select_last_index) + panic(array!['not supported!']) } fn transpose(self: @Tensor, axes: Span) -> Tensor { @@ -65,7 +65,7 @@ impl BoolTensor of TensorTrait { } fn matmul(self: @Tensor, other: @Tensor) -> Tensor { - linalg::matmul::matmul(self, other) + panic(array!['not supported!']) } fn exp(self: @Tensor) -> Tensor { @@ -81,23 +81,27 @@ impl BoolTensor of TensorTrait { } fn greater(self: @Tensor, other: @Tensor) -> Tensor { - math::greater::greater(self, other) + panic(array!['not supported!']) } fn greater_equal(self: @Tensor, other: @Tensor) -> Tensor { - math::greater_equal::greater_equal(self, other) + panic(array!['not supported!']) } fn less(self: @Tensor, other: @Tensor) -> Tensor { - math::less::less(self, other) + panic(array!['not supported!']) } fn less_equal(self: @Tensor, other: @Tensor) -> Tensor { - math::less_equal::less_equal(self, other) + panic(array!['not supported!']) } fn abs(self: @Tensor) -> Tensor { - math::abs::abs(*self) + panic(array!['not supported!']) + } + + fn neg(self: @Tensor) -> Tensor { + panic(array!['not supported!']) } fn ceil(self: @Tensor) -> Tensor { @@ -119,7 +123,7 @@ impl BoolTensor of TensorTrait { fn cumsum( self: @Tensor, axis: usize, exclusive: Option, reverse: Option ) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } fn flatten(self: @Tensor, axis: usize) -> Tensor { @@ -151,11 +155,11 @@ impl BoolTensor of TensorTrait { } fn xor(self: @Tensor, other: @Tensor) -> Tensor { - math::xor::xor(self, other) + panic(array!['not supported!']) } fn or(self: @Tensor, other: @Tensor) -> Tensor { - math::or::or(self, other) + panic(array!['not supported!']) } fn acos(self: @Tensor) -> Tensor { @@ -178,20 +182,14 @@ impl BoolTensor of TensorTrait { fn quantize_linear( self: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor - ) -> Tensor:: { - quantization::quantize_linear::quantize_linear( - self, - y_scale, - y_zero_point, - NumberTrait::new_unscaled(128, true), - NumberTrait::new_unscaled(127, false) - ) + ) -> Tensor:: { + panic(array!['not supported!']) } fn dequantize_linear( - self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor + self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor ) -> Tensor:: { - quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) + panic(array!['not supported!']) } fn slice( @@ -221,16 +219,28 @@ impl BoolTensor of TensorTrait { } fn sign(self: @Tensor) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { panic(array!['not supported!']) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn identity(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. -impl boolTensorAdd of Add> { +impl BoolTensorAdd of Add> { /// Adds two `Tensor` instances element-wise. /// /// # Arguments @@ -240,12 +250,12 @@ impl boolTensorAdd of Add> { /// # Returns /// * A `Tensor` instance representing the result of the element-wise addition. fn add(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } } /// Implements subtraction for `Tensor` using the `Sub` trait. -impl boolTensorSub of Sub> { +impl BoolTensorSub of Sub> { /// Subtracts two `Tensor` instances element-wise. /// /// # Arguments @@ -260,7 +270,7 @@ impl boolTensorSub of Sub> { } /// Implements multiplication for `Tensor` using the `Mul` trait. -impl boolTensorMul of Mul> { +impl BoolTensorMul of Mul> { /// Multiplies two `Tensor` instances element-wise. /// /// # Arguments @@ -275,7 +285,7 @@ impl boolTensorMul of Mul> { } /// Implements division for `Tensor` using the `Div` trait. -impl boolTensorDiv of Div> { +impl BoolTensorDiv of Div> { /// Divides two `Tensor` instances element-wise. /// /// # Arguments @@ -285,12 +295,12 @@ impl boolTensorDiv of Div> { /// # Returns /// * A `Tensor` instance representing the result of the element-wise division. fn div(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. -impl boolTensorPartialEq of PartialEq> { +impl BoolTensorPartialEq of PartialEq> { fn eq(lhs: @Tensor, rhs: @Tensor) -> bool { tensor_eq(*lhs, *rhs) } diff --git a/tests/lib.cairo b/tests/lib.cairo index b8f3c9b96..226597d2f 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -1,6 +1,6 @@ -mod numbers; -mod performance; -mod tensor_core; -mod nodes; -mod ml; -mod operators; +// mod numbers; +// mod performance; +// mod tensor_core; +// mod nodes; +// mod ml; +// mod operators; From 9931d981796ed4df015027e19cbe3409edb286e8 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 31 Oct 2023 12:22:30 +0200 Subject: [PATCH 010/127] fix tests --- tests/lib.cairo | 12 +- tests/nodes.cairo | 952 ++++++++++++------------ tests/tensor_core/at/at_bool_test.cairo | 2 +- 3 files changed, 483 insertions(+), 483 deletions(-) diff --git a/tests/lib.cairo b/tests/lib.cairo index 226597d2f..b8f3c9b96 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -1,6 +1,6 @@ -// mod numbers; -// mod performance; -// mod tensor_core; -// mod nodes; -// mod ml; -// mod operators; +mod numbers; +mod performance; +mod tensor_core; +mod nodes; +mod ml; +mod operators; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index d867b2277..e39890c5d 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,477 +1,477 @@ -mod abs_fp16x16; -mod abs_fp8x23; -mod abs_i32; -mod abs_i8; -mod acos_fp16x16; -mod acos_fp8x23; -mod acosh_fp16x16; -mod acosh_fp8x23; -mod add_fp16x16; -mod add_fp16x16_broadcast; -mod add_fp8x23; -mod add_fp8x23_broadcast; -mod add_i32; -mod add_i32_broadcast; -mod add_i8; -mod add_i8_broadcast; -mod add_u32; -mod add_u32_broadcast; -mod argmax_fp16x16_1D_default; -mod argmax_fp16x16_1D_keepdims_false; -mod argmax_fp16x16_1D_last_index; -mod argmax_fp16x16_2D_default; -mod argmax_fp16x16_2D_keepdims_false; -mod argmax_fp16x16_2D_last_index; -mod argmax_fp16x16_3D_default; -mod argmax_fp16x16_3D_keepdims_false; -mod argmax_fp16x16_3D_last_index; -mod argmax_fp8x23_1D_default; -mod argmax_fp8x23_1D_keepdims_false; -mod argmax_fp8x23_1D_last_index; -mod argmax_fp8x23_2D_default; -mod argmax_fp8x23_2D_keepdims_false; -mod argmax_fp8x23_2D_last_index; -mod argmax_fp8x23_3D_default; -mod argmax_fp8x23_3D_keepdims_false; -mod argmax_fp8x23_3D_last_index; -mod argmax_i32_1D_default; -mod argmax_i32_1D_keepdims_false; -mod argmax_i32_1D_last_index; -mod argmax_i32_2D_default; -mod argmax_i32_2D_keepdims_false; -mod argmax_i32_2D_last_index; -mod argmax_i32_3D_default; -mod argmax_i32_3D_keepdims_false; -mod argmax_i32_3D_last_index; -mod argmax_i8_1D_default; -mod argmax_i8_1D_keepdims_false; -mod argmax_i8_1D_last_index; -mod argmax_i8_2D_default; -mod argmax_i8_2D_keepdims_false; -mod argmax_i8_2D_last_index; -mod argmax_i8_3D_default; -mod argmax_i8_3D_keepdims_false; -mod argmax_i8_3D_last_index; -mod argmax_u32_1D_default; -mod argmax_u32_1D_keepdims_false; -mod argmax_u32_1D_last_index; -mod argmax_u32_2D_default; -mod argmax_u32_2D_keepdims_false; -mod argmax_u32_2D_last_index; -mod argmax_u32_3D_default; -mod argmax_u32_3D_keepdims_false; -mod argmax_u32_3D_last_index; -mod argmin_fp16x16_1D_default; -mod argmin_fp16x16_1D_keepdims_false; -mod argmin_fp16x16_1D_last_index; -mod argmin_fp16x16_2D_default; -mod argmin_fp16x16_2D_keepdims_false; -mod argmin_fp16x16_2D_last_index; -mod argmin_fp16x16_3D_default; -mod argmin_fp16x16_3D_keepdims_false; -mod argmin_fp16x16_3D_last_index; -mod argmin_fp8x23_1D_default; -mod argmin_fp8x23_1D_keepdims_false; -mod argmin_fp8x23_1D_last_index; -mod argmin_fp8x23_2D_default; -mod argmin_fp8x23_2D_keepdims_false; -mod argmin_fp8x23_2D_last_index; -mod argmin_fp8x23_3D_default; -mod argmin_fp8x23_3D_keepdims_false; -mod argmin_fp8x23_3D_last_index; -mod argmin_i32_1D_default; -mod argmin_i32_1D_keepdims_false; -mod argmin_i32_1D_last_index; -mod argmin_i32_2D_default; -mod argmin_i32_2D_keepdims_false; -mod argmin_i32_2D_last_index; -mod argmin_i32_3D_default; -mod argmin_i32_3D_keepdims_false; -mod argmin_i32_3D_last_index; -mod argmin_i8_1D_default; -mod argmin_i8_1D_keepdims_false; -mod argmin_i8_1D_last_index; -mod argmin_i8_2D_default; -mod argmin_i8_2D_keepdims_false; -mod argmin_i8_2D_last_index; -mod argmin_i8_3D_default; -mod argmin_i8_3D_keepdims_false; -mod argmin_i8_3D_last_index; -mod argmin_u32_1D_default; -mod argmin_u32_1D_keepdims_false; -mod argmin_u32_1D_last_index; -mod argmin_u32_2D_default; -mod argmin_u32_2D_keepdims_false; -mod argmin_u32_2D_last_index; -mod argmin_u32_3D_default; -mod argmin_u32_3D_keepdims_false; -mod argmin_u32_3D_last_index; -mod asin_fp16x16; -mod asin_fp8x23; -mod asinh_fp16x16; -mod asinh_fp8x23; -mod atan_fp16x16; -mod atan_fp8x23; -mod ceil_fp16x16; -mod ceil_fp8x23; -mod concat_fp16x16_1d; -mod concat_fp16x16_2d; -mod concat_fp16x16_3d_default; -mod concat_fp16x16_3d_axis_1; -mod concat_fp16x16_3d_axis_2; -mod concat_fp16x16_3d_three_tensors_axis_1; -mod concat_fp16x16_3d_three_tensors_axis_2; -mod concat_fp8x23_1d; -mod concat_fp8x23_2d; -mod concat_fp8x23_3d_default; -mod concat_fp8x23_3d_axis_1; -mod concat_fp8x23_3d_axis_2; -mod concat_fp8x23_3d_three_tensors_axis_1; -mod concat_fp8x23_3d_three_tensors_axis_2; -mod concat_i32_1d; -mod concat_i32_2d; -mod concat_i32_3d_default; -mod concat_i32_3d_axis_1; -mod concat_i32_3d_axis_2; -mod concat_i32_3d_three_tensors_axis_1; -mod concat_i32_3d_three_tensors_axis_2; -mod concat_i8_1d; -mod concat_i8_2d; -mod concat_i8_3d_default; -mod concat_i8_3d_axis_1; -mod concat_i8_3d_axis_2; -mod concat_i8_3d_three_tensors_axis_1; -mod concat_i8_3d_three_tensors_axis_2; -mod concat_u32_1d; -mod concat_u32_2d; -mod concat_u32_3d_default; -mod concat_u32_3d_axis_1; -mod concat_u32_3d_axis_2; -mod concat_u32_3d_three_tensors_axis_1; -mod concat_u32_3d_three_tensors_axis_2; -mod cos_fp16x16; -mod cos_fp8x23; -mod cosh_fp16x16; -mod cosh_fp8x23; -mod cumsum_fp16x16_1d_default; -mod cumsum_fp16x16_1d_exclusive; -mod cumsum_fp16x16_1d_reverse; -mod cumsum_fp16x16_1d_reverse_exclusive; -mod cumsum_fp16x16_2d_axis_0; -mod cumsum_fp16x16_2d_axis_1; -mod cumsum_fp8x23_1d_default; -mod cumsum_fp8x23_1d_exclusive; -mod cumsum_fp8x23_1d_reverse; -mod cumsum_fp8x23_1d_reverse_exclusive; -mod cumsum_fp8x23_2d_axis_0; -mod cumsum_fp8x23_2d_axis_1; -mod cumsum_i32_1d_default; -mod cumsum_i32_1d_exclusive; -mod cumsum_i32_1d_reverse; -mod cumsum_i32_1d_reverse_exclusive; -mod cumsum_i32_2d_axis_0; -mod cumsum_i32_2d_axis_1; -mod cumsum_i8_1d_default; -mod cumsum_i8_1d_exclusive; -mod cumsum_i8_1d_reverse; -mod cumsum_i8_1d_reverse_exclusive; -mod cumsum_i8_2d_axis_0; -mod cumsum_i8_2d_axis_1; -mod cumsum_u32_1d_default; -mod cumsum_u32_1d_exclusive; -mod cumsum_u32_1d_reverse; -mod cumsum_u32_1d_reverse_exclusive; -mod cumsum_u32_2d_axis_0; -mod cumsum_u32_2d_axis_1; -mod div_fp16x16; -mod div_fp16x16_broadcast; -mod div_fp8x23; -mod div_fp8x23_broadcast; -mod div_i32; -mod div_i32_broadcast; -mod div_i8; -mod div_i8_broadcast; -mod div_u32; -mod div_u32_broadcast; -mod equal_fp16x16; -mod equal_fp16x16_broadcast; -mod equal_fp8x23; -mod equal_fp8x23_broadcast; -mod equal_i32; -mod equal_i32_broadcast; -mod equal_i8; -mod equal_i8_broadcast; -mod equal_u32; -mod equal_u32_broadcast; -mod exp_fp16x16; -mod exp_fp8x23; -mod less_equal_fp16x16; -mod less_equal_fp16x16_broadcast; -mod less_equal_fp8x23; -mod less_equal_fp8x23_broadcast; -mod less_equal_i32; -mod less_equal_i32_broadcast; -mod less_equal_i8; -mod less_equal_i8_broadcast; -mod less_equal_u32; -mod less_equal_u32_broadcast; -mod greater_fp16x16; -mod greater_fp16x16_broadcast; -mod greater_fp8x23; -mod greater_fp8x23_broadcast; -mod greater_i32; -mod greater_i32_broadcast; -mod greater_i8; -mod greater_i8_broadcast; -mod greater_u32; -mod greater_u32_broadcast; -mod leaky_relu_fp16x16; -mod leaky_relu_fp8x23; -mod linear_fp16x16; -mod linear_fp8x23; -mod linear_i32; -mod linear_i8; -mod linear_u32; -mod log_fp16x16; -mod log_fp8x23; -mod logsoftmax_fp16x16_axis_0; -mod logsoftmax_fp16x16_axis_1; -mod logsoftmax_fp8x23_axis_0; -mod logsoftmax_fp8x23_axis_1; -mod matmul_fp16x16_1d; -mod matmul_fp16x16_2x2; -mod matmul_fp16x16_2x1; -mod matmul_fp16x16_1x2; -mod matmul_fp8x23_1d; -mod matmul_fp8x23_2x2; -mod matmul_fp8x23_2x1; -mod matmul_fp8x23_1x2; -mod matmul_i32_1d; -mod matmul_i32_2x2; -mod matmul_i32_2x1; -mod matmul_i32_1x2; -mod matmul_i8_1d; -mod matmul_i8_2x2; -mod matmul_i8_2x1; -mod matmul_i8_1x2; -mod matmul_u32_1d; -mod matmul_u32_2x2; -mod matmul_u32_2x1; -mod matmul_u32_1x2; -mod mul_fp16x16; -mod mul_fp16x16_broadcast; -mod mul_fp8x23; -mod mul_fp8x23_broadcast; -mod mul_i32; -mod mul_i32_broadcast; -mod mul_i8; -mod mul_i8_broadcast; -mod mul_u32; -mod mul_u32_broadcast; -mod or_fp16x16; -mod or_fp16x16_broadcast; -mod or_fp8x23; -mod or_fp8x23_broadcast; -mod or_i32; -mod or_i32_broadcast; -mod or_i8; -mod or_i8_broadcast; -mod or_u32; -mod or_u32_broadcast; -mod reduce_sum_fp16x16_1D; -mod reduce_sum_fp16x16_2D_default; -mod reduce_sum_fp16x16_2D_keepdims; -mod reduce_sum_fp16x16_2D_axis_1; -mod reduce_sum_fp8x23_1D; -mod reduce_sum_fp8x23_2D_default; -mod reduce_sum_fp8x23_2D_keepdims; -mod reduce_sum_fp8x23_2D_axis_1; -mod reduce_sum_i32_1D; -mod reduce_sum_i32_2D_default; -mod reduce_sum_i32_2D_keepdims; -mod reduce_sum_i32_2D_axis_1; -mod reduce_sum_i8_1D; -mod reduce_sum_i8_2D_default; -mod reduce_sum_i8_2D_keepdims; -mod reduce_sum_i8_2D_axis_1; -mod reduce_sum_u32_1D; -mod reduce_sum_u32_2D_default; -mod reduce_sum_u32_2D_keepdims; -mod reduce_sum_u32_2D_axis_1; -mod relu_fp16x16; -mod relu_fp8x23; -mod relu_i32; -mod relu_i8; -mod sigmoid_fp16x16; -mod sigmoid_fp8x23; -mod sin_fp16x16; -mod sin_fp8x23; -mod sinh_fp16x16; -mod sinh_fp8x23; -mod softmax_fp16x16; -mod softmax_fp8x23; -mod softplus_fp8x23; -mod softplus_fp16x16; -mod softsign_fp8x23; -mod softsign_fp16x16; -mod sqrt_fp16x16; -mod sqrt_fp8x23; -mod sub_fp16x16; -mod sub_fp16x16_broadcast; -mod sub_fp8x23; -mod sub_fp8x23_broadcast; -mod sub_i32; -mod sub_i32_broadcast; -mod sub_i8; -mod sub_i8_broadcast; -mod sub_u32; -mod sub_u32_broadcast; -mod tanh_fp16x16; -mod tanh_fp8x23; -mod transpose_fp16x16_2d; -mod transpose_fp16x16_3d; -mod transpose_fp8x23_2d; -mod transpose_fp8x23_3d; -mod transpose_i32_2d; -mod transpose_i32_3d; -mod transpose_i8_2d; -mod transpose_i8_3d; -mod transpose_u32_2d; -mod transpose_u32_3d; -mod xor_fp16x16; -mod xor_fp16x16_broadcast; -mod xor_fp8x23; -mod xor_fp8x23_broadcast; -mod xor_i32; -mod xor_i32_broadcast; -mod xor_i8; -mod xor_i8_broadcast; -mod xor_u32; -mod xor_u32_broadcast; -mod less_fp16x16; -mod less_fp16x16_broadcast; -mod less_fp8x23; -mod less_fp8x23_broadcast; -mod less_i32; -mod less_i32_broadcast; -mod less_i8; -mod less_i8_broadcast; -mod less_u32; -mod less_u32_broadcast; -mod greater_equal_fp16x16; -mod greater_equal_fp16x16_broadcast; -mod greater_equal_fp8x23; -mod greater_equal_fp8x23_broadcast; -mod greater_equal_i32; -mod greater_equal_i32_broadcast; -mod greater_equal_i8; -mod greater_equal_i8_broadcast; -mod greater_equal_u32; -mod greater_equal_u32_broadcast; -mod slice_fp16x16_2d; -mod slice_fp16x16_3d; -mod slice_fp8x23_2d; -mod slice_fp8x23_3d; -mod slice_i32_2d; -mod slice_i32_3d; -mod slice_i8_2d; -mod slice_i8_3d; -mod slice_u32_2d; -mod slice_u32_3d; -mod gather_fp8x23_3d_default; -mod gather_fp8x23_3d_axis1; -mod gather_fp8x23_3d_axis2; -mod gather_fp16x16_3d_default; -mod gather_fp16x16_3d_axis1; -mod gather_fp16x16_3d_axis2; -mod gather_i8_3d_default; -mod gather_i8_3d_axis1; -mod gather_i8_3d_axis2; -mod gather_i32_3d_default; -mod gather_i32_3d_axis1; -mod gather_i32_3d_axis2; -mod gather_u32_3d_default; -mod gather_u32_3d_axis1; -mod gather_u32_3d_axis2; -mod nonzero_fp16x16_2d; -mod nonzero_fp16x16_3d; -mod nonzero_fp8x23_2d; -mod nonzero_fp8x23_3d; -mod nonzero_i32_2d; -mod nonzero_i32_3d; -mod nonzero_i8_2d; -mod nonzero_i8_3d; -mod nonzero_u32_2d; -mod nonzero_u32_3d; -mod squeeze_fP16x16; -mod squeeze_fP8x23; -mod squeeze_i32; -mod squeeze_i8; -mod squeeze_u32; -mod unsqueeze_fp16x16_2d; -mod unsqueeze_fp16x16_3d; -mod unsqueeze_fp8x23_2d; -mod unsqueeze_fp8x23_3d; -mod unsqueeze_i32_2d; -mod unsqueeze_i32_3d; -mod unsqueeze_i8_2d; -mod unsqueeze_i8_3d; -mod unsqueeze_u32_2d; -mod unsqueeze_u32_3d; -mod sign_fP16x16; -mod sign_fP8x23; -mod sign_fail; -mod sign_i32; -mod sign_i8; -mod clip_fp16x16_2d; -mod clip_fp16x16_3d; -mod clip_fp8x23_2d; -mod clip_fp8x23_3d; -mod clip_i32_2d; -mod clip_i32_3d; -mod clip_i8_2d; -mod clip_i8_3d; -mod clip_u32_2d; -mod clip_u32_3d; -mod and_fp16x16; -mod and_fp16x16_broadcast; -mod and_fp8x23; -mod and_fp8x23_broadcast; -mod and_i32; -mod and_i32_broadcast; -mod and_i8; -mod and_i8_broadcast; -mod and_u32; -mod and_u32_broadcast; -mod identity_fP16x16; -mod identity_fP8x23; -mod identity_i32; -mod identity_i8; -mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod where_fp16x16; -mod where_fp16x16_broadcast; -mod where_fp8x23; -mod where_fp8x23_broadcast; -mod where_i32; -mod where_i32_broadcast; -mod where_i8; -mod where_i8_broadcast; -mod where_u32; -mod where_u32_broadcast; +// mod abs_fp16x16; +// mod abs_fp8x23; +// mod abs_i32; +// mod abs_i8; +// mod acos_fp16x16; +// mod acos_fp8x23; +// mod acosh_fp16x16; +// mod acosh_fp8x23; +// mod add_fp16x16; +// mod add_fp16x16_broadcast; +// mod add_fp8x23; +// mod add_fp8x23_broadcast; +// mod add_i32; +// mod add_i32_broadcast; +// mod add_i8; +// mod add_i8_broadcast; +// mod add_u32; +// mod add_u32_broadcast; +// mod argmax_fp16x16_1D_default; +// mod argmax_fp16x16_1D_keepdims_false; +// mod argmax_fp16x16_1D_last_index; +// mod argmax_fp16x16_2D_default; +// mod argmax_fp16x16_2D_keepdims_false; +// mod argmax_fp16x16_2D_last_index; +// mod argmax_fp16x16_3D_default; +// mod argmax_fp16x16_3D_keepdims_false; +// mod argmax_fp16x16_3D_last_index; +// mod argmax_fp8x23_1D_default; +// mod argmax_fp8x23_1D_keepdims_false; +// mod argmax_fp8x23_1D_last_index; +// mod argmax_fp8x23_2D_default; +// mod argmax_fp8x23_2D_keepdims_false; +// mod argmax_fp8x23_2D_last_index; +// mod argmax_fp8x23_3D_default; +// mod argmax_fp8x23_3D_keepdims_false; +// mod argmax_fp8x23_3D_last_index; +// mod argmax_i32_1D_default; +// mod argmax_i32_1D_keepdims_false; +// mod argmax_i32_1D_last_index; +// mod argmax_i32_2D_default; +// mod argmax_i32_2D_keepdims_false; +// mod argmax_i32_2D_last_index; +// mod argmax_i32_3D_default; +// mod argmax_i32_3D_keepdims_false; +// mod argmax_i32_3D_last_index; +// mod argmax_i8_1D_default; +// mod argmax_i8_1D_keepdims_false; +// mod argmax_i8_1D_last_index; +// mod argmax_i8_2D_default; +// mod argmax_i8_2D_keepdims_false; +// mod argmax_i8_2D_last_index; +// mod argmax_i8_3D_default; +// mod argmax_i8_3D_keepdims_false; +// mod argmax_i8_3D_last_index; +// mod argmax_u32_1D_default; +// mod argmax_u32_1D_keepdims_false; +// mod argmax_u32_1D_last_index; +// mod argmax_u32_2D_default; +// mod argmax_u32_2D_keepdims_false; +// mod argmax_u32_2D_last_index; +// mod argmax_u32_3D_default; +// mod argmax_u32_3D_keepdims_false; +// mod argmax_u32_3D_last_index; +// mod argmin_fp16x16_1D_default; +// mod argmin_fp16x16_1D_keepdims_false; +// mod argmin_fp16x16_1D_last_index; +// mod argmin_fp16x16_2D_default; +// mod argmin_fp16x16_2D_keepdims_false; +// mod argmin_fp16x16_2D_last_index; +// mod argmin_fp16x16_3D_default; +// mod argmin_fp16x16_3D_keepdims_false; +// mod argmin_fp16x16_3D_last_index; +// mod argmin_fp8x23_1D_default; +// mod argmin_fp8x23_1D_keepdims_false; +// mod argmin_fp8x23_1D_last_index; +// mod argmin_fp8x23_2D_default; +// mod argmin_fp8x23_2D_keepdims_false; +// mod argmin_fp8x23_2D_last_index; +// mod argmin_fp8x23_3D_default; +// mod argmin_fp8x23_3D_keepdims_false; +// mod argmin_fp8x23_3D_last_index; +// mod argmin_i32_1D_default; +// mod argmin_i32_1D_keepdims_false; +// mod argmin_i32_1D_last_index; +// mod argmin_i32_2D_default; +// mod argmin_i32_2D_keepdims_false; +// mod argmin_i32_2D_last_index; +// mod argmin_i32_3D_default; +// mod argmin_i32_3D_keepdims_false; +// mod argmin_i32_3D_last_index; +// mod argmin_i8_1D_default; +// mod argmin_i8_1D_keepdims_false; +// mod argmin_i8_1D_last_index; +// mod argmin_i8_2D_default; +// mod argmin_i8_2D_keepdims_false; +// mod argmin_i8_2D_last_index; +// mod argmin_i8_3D_default; +// mod argmin_i8_3D_keepdims_false; +// mod argmin_i8_3D_last_index; +// mod argmin_u32_1D_default; +// mod argmin_u32_1D_keepdims_false; +// mod argmin_u32_1D_last_index; +// mod argmin_u32_2D_default; +// mod argmin_u32_2D_keepdims_false; +// mod argmin_u32_2D_last_index; +// mod argmin_u32_3D_default; +// mod argmin_u32_3D_keepdims_false; +// mod argmin_u32_3D_last_index; +// mod asin_fp16x16; +// mod asin_fp8x23; +// mod asinh_fp16x16; +// mod asinh_fp8x23; +// mod atan_fp16x16; +// mod atan_fp8x23; +// mod ceil_fp16x16; +// mod ceil_fp8x23; +// mod concat_fp16x16_1d; +// mod concat_fp16x16_2d; +// mod concat_fp16x16_3d_default; +// mod concat_fp16x16_3d_axis_1; +// mod concat_fp16x16_3d_axis_2; +// mod concat_fp16x16_3d_three_tensors_axis_1; +// mod concat_fp16x16_3d_three_tensors_axis_2; +// mod concat_fp8x23_1d; +// mod concat_fp8x23_2d; +// mod concat_fp8x23_3d_default; +// mod concat_fp8x23_3d_axis_1; +// mod concat_fp8x23_3d_axis_2; +// mod concat_fp8x23_3d_three_tensors_axis_1; +// mod concat_fp8x23_3d_three_tensors_axis_2; +// mod concat_i32_1d; +// mod concat_i32_2d; +// mod concat_i32_3d_default; +// mod concat_i32_3d_axis_1; +// mod concat_i32_3d_axis_2; +// mod concat_i32_3d_three_tensors_axis_1; +// mod concat_i32_3d_three_tensors_axis_2; +// mod concat_i8_1d; +// mod concat_i8_2d; +// mod concat_i8_3d_default; +// mod concat_i8_3d_axis_1; +// mod concat_i8_3d_axis_2; +// mod concat_i8_3d_three_tensors_axis_1; +// mod concat_i8_3d_three_tensors_axis_2; +// mod concat_u32_1d; +// mod concat_u32_2d; +// mod concat_u32_3d_default; +// mod concat_u32_3d_axis_1; +// mod concat_u32_3d_axis_2; +// mod concat_u32_3d_three_tensors_axis_1; +// mod concat_u32_3d_three_tensors_axis_2; +// mod cos_fp16x16; +// mod cos_fp8x23; +// mod cosh_fp16x16; +// mod cosh_fp8x23; +// mod cumsum_fp16x16_1d_default; +// mod cumsum_fp16x16_1d_exclusive; +// mod cumsum_fp16x16_1d_reverse; +// mod cumsum_fp16x16_1d_reverse_exclusive; +// mod cumsum_fp16x16_2d_axis_0; +// mod cumsum_fp16x16_2d_axis_1; +// mod cumsum_fp8x23_1d_default; +// mod cumsum_fp8x23_1d_exclusive; +// mod cumsum_fp8x23_1d_reverse; +// mod cumsum_fp8x23_1d_reverse_exclusive; +// mod cumsum_fp8x23_2d_axis_0; +// mod cumsum_fp8x23_2d_axis_1; +// mod cumsum_i32_1d_default; +// mod cumsum_i32_1d_exclusive; +// mod cumsum_i32_1d_reverse; +// mod cumsum_i32_1d_reverse_exclusive; +// mod cumsum_i32_2d_axis_0; +// mod cumsum_i32_2d_axis_1; +// mod cumsum_i8_1d_default; +// mod cumsum_i8_1d_exclusive; +// mod cumsum_i8_1d_reverse; +// mod cumsum_i8_1d_reverse_exclusive; +// mod cumsum_i8_2d_axis_0; +// mod cumsum_i8_2d_axis_1; +// mod cumsum_u32_1d_default; +// mod cumsum_u32_1d_exclusive; +// mod cumsum_u32_1d_reverse; +// mod cumsum_u32_1d_reverse_exclusive; +// mod cumsum_u32_2d_axis_0; +// mod cumsum_u32_2d_axis_1; +// mod div_fp16x16; +// mod div_fp16x16_broadcast; +// mod div_fp8x23; +// mod div_fp8x23_broadcast; +// mod div_i32; +// mod div_i32_broadcast; +// mod div_i8; +// mod div_i8_broadcast; +// mod div_u32; +// mod div_u32_broadcast; +// mod equal_fp16x16; +// mod equal_fp16x16_broadcast; +// mod equal_fp8x23; +// mod equal_fp8x23_broadcast; +// mod equal_i32; +// mod equal_i32_broadcast; +// mod equal_i8; +// mod equal_i8_broadcast; +// mod equal_u32; +// mod equal_u32_broadcast; +// mod exp_fp16x16; +// mod exp_fp8x23; +// mod less_equal_fp16x16; +// mod less_equal_fp16x16_broadcast; +// mod less_equal_fp8x23; +// mod less_equal_fp8x23_broadcast; +// mod less_equal_i32; +// mod less_equal_i32_broadcast; +// mod less_equal_i8; +// mod less_equal_i8_broadcast; +// mod less_equal_u32; +// mod less_equal_u32_broadcast; +// mod greater_fp16x16; +// mod greater_fp16x16_broadcast; +// mod greater_fp8x23; +// mod greater_fp8x23_broadcast; +// mod greater_i32; +// mod greater_i32_broadcast; +// mod greater_i8; +// mod greater_i8_broadcast; +// mod greater_u32; +// mod greater_u32_broadcast; +// mod leaky_relu_fp16x16; +// mod leaky_relu_fp8x23; +// mod linear_fp16x16; +// mod linear_fp8x23; +// mod linear_i32; +// mod linear_i8; +// mod linear_u32; +// mod log_fp16x16; +// mod log_fp8x23; +// mod logsoftmax_fp16x16_axis_0; +// mod logsoftmax_fp16x16_axis_1; +// mod logsoftmax_fp8x23_axis_0; +// mod logsoftmax_fp8x23_axis_1; +// mod matmul_fp16x16_1d; +// mod matmul_fp16x16_2x2; +// mod matmul_fp16x16_2x1; +// mod matmul_fp16x16_1x2; +// mod matmul_fp8x23_1d; +// mod matmul_fp8x23_2x2; +// mod matmul_fp8x23_2x1; +// mod matmul_fp8x23_1x2; +// mod matmul_i32_1d; +// mod matmul_i32_2x2; +// mod matmul_i32_2x1; +// mod matmul_i32_1x2; +// mod matmul_i8_1d; +// mod matmul_i8_2x2; +// mod matmul_i8_2x1; +// mod matmul_i8_1x2; +// mod matmul_u32_1d; +// mod matmul_u32_2x2; +// mod matmul_u32_2x1; +// mod matmul_u32_1x2; +// mod mul_fp16x16; +// mod mul_fp16x16_broadcast; +// mod mul_fp8x23; +// mod mul_fp8x23_broadcast; +// mod mul_i32; +// mod mul_i32_broadcast; +// mod mul_i8; +// mod mul_i8_broadcast; +// mod mul_u32; +// mod mul_u32_broadcast; +// mod or_fp16x16; +// mod or_fp16x16_broadcast; +// mod or_fp8x23; +// mod or_fp8x23_broadcast; +// mod or_i32; +// mod or_i32_broadcast; +// mod or_i8; +// mod or_i8_broadcast; +// mod or_u32; +// mod or_u32_broadcast; +// mod reduce_sum_fp16x16_1D; +// mod reduce_sum_fp16x16_2D_default; +// mod reduce_sum_fp16x16_2D_keepdims; +// mod reduce_sum_fp16x16_2D_axis_1; +// mod reduce_sum_fp8x23_1D; +// mod reduce_sum_fp8x23_2D_default; +// mod reduce_sum_fp8x23_2D_keepdims; +// mod reduce_sum_fp8x23_2D_axis_1; +// mod reduce_sum_i32_1D; +// mod reduce_sum_i32_2D_default; +// mod reduce_sum_i32_2D_keepdims; +// mod reduce_sum_i32_2D_axis_1; +// mod reduce_sum_i8_1D; +// mod reduce_sum_i8_2D_default; +// mod reduce_sum_i8_2D_keepdims; +// mod reduce_sum_i8_2D_axis_1; +// mod reduce_sum_u32_1D; +// mod reduce_sum_u32_2D_default; +// mod reduce_sum_u32_2D_keepdims; +// mod reduce_sum_u32_2D_axis_1; +// mod relu_fp16x16; +// mod relu_fp8x23; +// mod relu_i32; +// mod relu_i8; +// mod sigmoid_fp16x16; +// mod sigmoid_fp8x23; +// mod sin_fp16x16; +// mod sin_fp8x23; +// mod sinh_fp16x16; +// mod sinh_fp8x23; +// mod softmax_fp16x16; +// mod softmax_fp8x23; +// mod softplus_fp8x23; +// mod softplus_fp16x16; +// mod softsign_fp8x23; +// mod softsign_fp16x16; +// mod sqrt_fp16x16; +// mod sqrt_fp8x23; +// mod sub_fp16x16; +// mod sub_fp16x16_broadcast; +// mod sub_fp8x23; +// mod sub_fp8x23_broadcast; +// mod sub_i32; +// mod sub_i32_broadcast; +// mod sub_i8; +// mod sub_i8_broadcast; +// mod sub_u32; +// mod sub_u32_broadcast; +// mod tanh_fp16x16; +// mod tanh_fp8x23; +// mod transpose_fp16x16_2d; +// mod transpose_fp16x16_3d; +// mod transpose_fp8x23_2d; +// mod transpose_fp8x23_3d; +// mod transpose_i32_2d; +// mod transpose_i32_3d; +// mod transpose_i8_2d; +// mod transpose_i8_3d; +// mod transpose_u32_2d; +// mod transpose_u32_3d; +// mod xor_fp16x16; +// mod xor_fp16x16_broadcast; +// mod xor_fp8x23; +// mod xor_fp8x23_broadcast; +// mod xor_i32; +// mod xor_i32_broadcast; +// mod xor_i8; +// mod xor_i8_broadcast; +// mod xor_u32; +// mod xor_u32_broadcast; +// mod less_fp16x16; +// mod less_fp16x16_broadcast; +// mod less_fp8x23; +// mod less_fp8x23_broadcast; +// mod less_i32; +// mod less_i32_broadcast; +// mod less_i8; +// mod less_i8_broadcast; +// mod less_u32; +// mod less_u32_broadcast; +// mod greater_equal_fp16x16; +// mod greater_equal_fp16x16_broadcast; +// mod greater_equal_fp8x23; +// mod greater_equal_fp8x23_broadcast; +// mod greater_equal_i32; +// mod greater_equal_i32_broadcast; +// mod greater_equal_i8; +// mod greater_equal_i8_broadcast; +// mod greater_equal_u32; +// mod greater_equal_u32_broadcast; +// mod slice_fp16x16_2d; +// mod slice_fp16x16_3d; +// mod slice_fp8x23_2d; +// mod slice_fp8x23_3d; +// mod slice_i32_2d; +// mod slice_i32_3d; +// mod slice_i8_2d; +// mod slice_i8_3d; +// mod slice_u32_2d; +// mod slice_u32_3d; +// mod gather_fp8x23_3d_default; +// mod gather_fp8x23_3d_axis1; +// mod gather_fp8x23_3d_axis2; +// mod gather_fp16x16_3d_default; +// mod gather_fp16x16_3d_axis1; +// mod gather_fp16x16_3d_axis2; +// mod gather_i8_3d_default; +// mod gather_i8_3d_axis1; +// mod gather_i8_3d_axis2; +// mod gather_i32_3d_default; +// mod gather_i32_3d_axis1; +// mod gather_i32_3d_axis2; +// mod gather_u32_3d_default; +// mod gather_u32_3d_axis1; +// mod gather_u32_3d_axis2; +// mod nonzero_fp16x16_2d; +// mod nonzero_fp16x16_3d; +// mod nonzero_fp8x23_2d; +// mod nonzero_fp8x23_3d; +// mod nonzero_i32_2d; +// mod nonzero_i32_3d; +// mod nonzero_i8_2d; +// mod nonzero_i8_3d; +// mod nonzero_u32_2d; +// mod nonzero_u32_3d; +// mod squeeze_fP16x16; +// mod squeeze_fP8x23; +// mod squeeze_i32; +// mod squeeze_i8; +// mod squeeze_u32; +// mod unsqueeze_fp16x16_2d; +// mod unsqueeze_fp16x16_3d; +// mod unsqueeze_fp8x23_2d; +// mod unsqueeze_fp8x23_3d; +// mod unsqueeze_i32_2d; +// mod unsqueeze_i32_3d; +// mod unsqueeze_i8_2d; +// mod unsqueeze_i8_3d; +// mod unsqueeze_u32_2d; +// mod unsqueeze_u32_3d; +// mod sign_fP16x16; +// mod sign_fP8x23; +// mod sign_fail; +// mod sign_i32; +// mod sign_i8; +// mod clip_fp16x16_2d; +// mod clip_fp16x16_3d; +// mod clip_fp8x23_2d; +// mod clip_fp8x23_3d; +// mod clip_i32_2d; +// mod clip_i32_3d; +// mod clip_i8_2d; +// mod clip_i8_3d; +// mod clip_u32_2d; +// mod clip_u32_3d; +// mod and_fp16x16; +// mod and_fp16x16_broadcast; +// mod and_fp8x23; +// mod and_fp8x23_broadcast; +// mod and_i32; +// mod and_i32_broadcast; +// mod and_i8; +// mod and_i8_broadcast; +// mod and_u32; +// mod and_u32_broadcast; +// mod identity_fP16x16; +// mod identity_fP8x23; +// mod identity_i32; +// mod identity_i8; +// mod identity_u32; +// mod thresholded_relu_fp16x16; +// mod thresholded_relu_fp8x23; +// mod hard_sigmoid_fp8x23; +// mod hard_sigmoid_fp16x16; +// mod neg_fp16x16; +// mod neg_fp8x23; +// mod neg_i32; +// mod neg_i8; +// mod gemm_all_attributes; +// mod gemm_alpha; +// mod gemm_beta; +// mod gemm_default_matrix_bias; +// mod gemm_default_vector_bias; +// mod gemm_default_no_bias; +// mod gemm_transposeA; +// mod gemm_transposeB; +// mod where_fp16x16; +// mod where_fp16x16_broadcast; +// mod where_fp8x23; +// mod where_fp8x23_broadcast; +// mod where_i32; +// mod where_i32_broadcast; +// mod where_i8; +// mod where_i8_broadcast; +// mod where_u32; +// mod where_u32_broadcast; diff --git a/tests/tensor_core/at/at_bool_test.cairo b/tests/tensor_core/at/at_bool_test.cairo index 78c7c10f9..0abad5d49 100644 --- a/tests/tensor_core/at/at_bool_test.cairo +++ b/tests/tensor_core/at/at_bool_test.cairo @@ -24,7 +24,7 @@ mod tensor_1D { let mut indices = ArrayTrait::new(); indices.append(1); - let result = tensor.at(indices.span()).mag; + let result = tensor.at(indices.span()); assert(result == true, 'result[2] = true'); } From 31280c366c494d7a3f83503cb30d921e48add51b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 31 Oct 2023 12:22:45 +0200 Subject: [PATCH 011/127] uncomment nodes --- tests/nodes.cairo | 952 +++++++++++++++++++++++----------------------- 1 file changed, 476 insertions(+), 476 deletions(-) diff --git a/tests/nodes.cairo b/tests/nodes.cairo index e39890c5d..d867b2277 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,477 +1,477 @@ -// mod abs_fp16x16; -// mod abs_fp8x23; -// mod abs_i32; -// mod abs_i8; -// mod acos_fp16x16; -// mod acos_fp8x23; -// mod acosh_fp16x16; -// mod acosh_fp8x23; -// mod add_fp16x16; -// mod add_fp16x16_broadcast; -// mod add_fp8x23; -// mod add_fp8x23_broadcast; -// mod add_i32; -// mod add_i32_broadcast; -// mod add_i8; -// mod add_i8_broadcast; -// mod add_u32; -// mod add_u32_broadcast; -// mod argmax_fp16x16_1D_default; -// mod argmax_fp16x16_1D_keepdims_false; -// mod argmax_fp16x16_1D_last_index; -// mod argmax_fp16x16_2D_default; -// mod argmax_fp16x16_2D_keepdims_false; -// mod argmax_fp16x16_2D_last_index; -// mod argmax_fp16x16_3D_default; -// mod argmax_fp16x16_3D_keepdims_false; -// mod argmax_fp16x16_3D_last_index; -// mod argmax_fp8x23_1D_default; -// mod argmax_fp8x23_1D_keepdims_false; -// mod argmax_fp8x23_1D_last_index; -// mod argmax_fp8x23_2D_default; -// mod argmax_fp8x23_2D_keepdims_false; -// mod argmax_fp8x23_2D_last_index; -// mod argmax_fp8x23_3D_default; -// mod argmax_fp8x23_3D_keepdims_false; -// mod argmax_fp8x23_3D_last_index; -// mod argmax_i32_1D_default; -// mod argmax_i32_1D_keepdims_false; -// mod argmax_i32_1D_last_index; -// mod argmax_i32_2D_default; -// mod argmax_i32_2D_keepdims_false; -// mod argmax_i32_2D_last_index; -// mod argmax_i32_3D_default; -// mod argmax_i32_3D_keepdims_false; -// mod argmax_i32_3D_last_index; -// mod argmax_i8_1D_default; -// mod argmax_i8_1D_keepdims_false; -// mod argmax_i8_1D_last_index; -// mod argmax_i8_2D_default; -// mod argmax_i8_2D_keepdims_false; -// mod argmax_i8_2D_last_index; -// mod argmax_i8_3D_default; -// mod argmax_i8_3D_keepdims_false; -// mod argmax_i8_3D_last_index; -// mod argmax_u32_1D_default; -// mod argmax_u32_1D_keepdims_false; -// mod argmax_u32_1D_last_index; -// mod argmax_u32_2D_default; -// mod argmax_u32_2D_keepdims_false; -// mod argmax_u32_2D_last_index; -// mod argmax_u32_3D_default; -// mod argmax_u32_3D_keepdims_false; -// mod argmax_u32_3D_last_index; -// mod argmin_fp16x16_1D_default; -// mod argmin_fp16x16_1D_keepdims_false; -// mod argmin_fp16x16_1D_last_index; -// mod argmin_fp16x16_2D_default; -// mod argmin_fp16x16_2D_keepdims_false; -// mod argmin_fp16x16_2D_last_index; -// mod argmin_fp16x16_3D_default; -// mod argmin_fp16x16_3D_keepdims_false; -// mod argmin_fp16x16_3D_last_index; -// mod argmin_fp8x23_1D_default; -// mod argmin_fp8x23_1D_keepdims_false; -// mod argmin_fp8x23_1D_last_index; -// mod argmin_fp8x23_2D_default; -// mod argmin_fp8x23_2D_keepdims_false; -// mod argmin_fp8x23_2D_last_index; -// mod argmin_fp8x23_3D_default; -// mod argmin_fp8x23_3D_keepdims_false; -// mod argmin_fp8x23_3D_last_index; -// mod argmin_i32_1D_default; -// mod argmin_i32_1D_keepdims_false; -// mod argmin_i32_1D_last_index; -// mod argmin_i32_2D_default; -// mod argmin_i32_2D_keepdims_false; -// mod argmin_i32_2D_last_index; -// mod argmin_i32_3D_default; -// mod argmin_i32_3D_keepdims_false; -// mod argmin_i32_3D_last_index; -// mod argmin_i8_1D_default; -// mod argmin_i8_1D_keepdims_false; -// mod argmin_i8_1D_last_index; -// mod argmin_i8_2D_default; -// mod argmin_i8_2D_keepdims_false; -// mod argmin_i8_2D_last_index; -// mod argmin_i8_3D_default; -// mod argmin_i8_3D_keepdims_false; -// mod argmin_i8_3D_last_index; -// mod argmin_u32_1D_default; -// mod argmin_u32_1D_keepdims_false; -// mod argmin_u32_1D_last_index; -// mod argmin_u32_2D_default; -// mod argmin_u32_2D_keepdims_false; -// mod argmin_u32_2D_last_index; -// mod argmin_u32_3D_default; -// mod argmin_u32_3D_keepdims_false; -// mod argmin_u32_3D_last_index; -// mod asin_fp16x16; -// mod asin_fp8x23; -// mod asinh_fp16x16; -// mod asinh_fp8x23; -// mod atan_fp16x16; -// mod atan_fp8x23; -// mod ceil_fp16x16; -// mod ceil_fp8x23; -// mod concat_fp16x16_1d; -// mod concat_fp16x16_2d; -// mod concat_fp16x16_3d_default; -// mod concat_fp16x16_3d_axis_1; -// mod concat_fp16x16_3d_axis_2; -// mod concat_fp16x16_3d_three_tensors_axis_1; -// mod concat_fp16x16_3d_three_tensors_axis_2; -// mod concat_fp8x23_1d; -// mod concat_fp8x23_2d; -// mod concat_fp8x23_3d_default; -// mod concat_fp8x23_3d_axis_1; -// mod concat_fp8x23_3d_axis_2; -// mod concat_fp8x23_3d_three_tensors_axis_1; -// mod concat_fp8x23_3d_three_tensors_axis_2; -// mod concat_i32_1d; -// mod concat_i32_2d; -// mod concat_i32_3d_default; -// mod concat_i32_3d_axis_1; -// mod concat_i32_3d_axis_2; -// mod concat_i32_3d_three_tensors_axis_1; -// mod concat_i32_3d_three_tensors_axis_2; -// mod concat_i8_1d; -// mod concat_i8_2d; -// mod concat_i8_3d_default; -// mod concat_i8_3d_axis_1; -// mod concat_i8_3d_axis_2; -// mod concat_i8_3d_three_tensors_axis_1; -// mod concat_i8_3d_three_tensors_axis_2; -// mod concat_u32_1d; -// mod concat_u32_2d; -// mod concat_u32_3d_default; -// mod concat_u32_3d_axis_1; -// mod concat_u32_3d_axis_2; -// mod concat_u32_3d_three_tensors_axis_1; -// mod concat_u32_3d_three_tensors_axis_2; -// mod cos_fp16x16; -// mod cos_fp8x23; -// mod cosh_fp16x16; -// mod cosh_fp8x23; -// mod cumsum_fp16x16_1d_default; -// mod cumsum_fp16x16_1d_exclusive; -// mod cumsum_fp16x16_1d_reverse; -// mod cumsum_fp16x16_1d_reverse_exclusive; -// mod cumsum_fp16x16_2d_axis_0; -// mod cumsum_fp16x16_2d_axis_1; -// mod cumsum_fp8x23_1d_default; -// mod cumsum_fp8x23_1d_exclusive; -// mod cumsum_fp8x23_1d_reverse; -// mod cumsum_fp8x23_1d_reverse_exclusive; -// mod cumsum_fp8x23_2d_axis_0; -// mod cumsum_fp8x23_2d_axis_1; -// mod cumsum_i32_1d_default; -// mod cumsum_i32_1d_exclusive; -// mod cumsum_i32_1d_reverse; -// mod cumsum_i32_1d_reverse_exclusive; -// mod cumsum_i32_2d_axis_0; -// mod cumsum_i32_2d_axis_1; -// mod cumsum_i8_1d_default; -// mod cumsum_i8_1d_exclusive; -// mod cumsum_i8_1d_reverse; -// mod cumsum_i8_1d_reverse_exclusive; -// mod cumsum_i8_2d_axis_0; -// mod cumsum_i8_2d_axis_1; -// mod cumsum_u32_1d_default; -// mod cumsum_u32_1d_exclusive; -// mod cumsum_u32_1d_reverse; -// mod cumsum_u32_1d_reverse_exclusive; -// mod cumsum_u32_2d_axis_0; -// mod cumsum_u32_2d_axis_1; -// mod div_fp16x16; -// mod div_fp16x16_broadcast; -// mod div_fp8x23; -// mod div_fp8x23_broadcast; -// mod div_i32; -// mod div_i32_broadcast; -// mod div_i8; -// mod div_i8_broadcast; -// mod div_u32; -// mod div_u32_broadcast; -// mod equal_fp16x16; -// mod equal_fp16x16_broadcast; -// mod equal_fp8x23; -// mod equal_fp8x23_broadcast; -// mod equal_i32; -// mod equal_i32_broadcast; -// mod equal_i8; -// mod equal_i8_broadcast; -// mod equal_u32; -// mod equal_u32_broadcast; -// mod exp_fp16x16; -// mod exp_fp8x23; -// mod less_equal_fp16x16; -// mod less_equal_fp16x16_broadcast; -// mod less_equal_fp8x23; -// mod less_equal_fp8x23_broadcast; -// mod less_equal_i32; -// mod less_equal_i32_broadcast; -// mod less_equal_i8; -// mod less_equal_i8_broadcast; -// mod less_equal_u32; -// mod less_equal_u32_broadcast; -// mod greater_fp16x16; -// mod greater_fp16x16_broadcast; -// mod greater_fp8x23; -// mod greater_fp8x23_broadcast; -// mod greater_i32; -// mod greater_i32_broadcast; -// mod greater_i8; -// mod greater_i8_broadcast; -// mod greater_u32; -// mod greater_u32_broadcast; -// mod leaky_relu_fp16x16; -// mod leaky_relu_fp8x23; -// mod linear_fp16x16; -// mod linear_fp8x23; -// mod linear_i32; -// mod linear_i8; -// mod linear_u32; -// mod log_fp16x16; -// mod log_fp8x23; -// mod logsoftmax_fp16x16_axis_0; -// mod logsoftmax_fp16x16_axis_1; -// mod logsoftmax_fp8x23_axis_0; -// mod logsoftmax_fp8x23_axis_1; -// mod matmul_fp16x16_1d; -// mod matmul_fp16x16_2x2; -// mod matmul_fp16x16_2x1; -// mod matmul_fp16x16_1x2; -// mod matmul_fp8x23_1d; -// mod matmul_fp8x23_2x2; -// mod matmul_fp8x23_2x1; -// mod matmul_fp8x23_1x2; -// mod matmul_i32_1d; -// mod matmul_i32_2x2; -// mod matmul_i32_2x1; -// mod matmul_i32_1x2; -// mod matmul_i8_1d; -// mod matmul_i8_2x2; -// mod matmul_i8_2x1; -// mod matmul_i8_1x2; -// mod matmul_u32_1d; -// mod matmul_u32_2x2; -// mod matmul_u32_2x1; -// mod matmul_u32_1x2; -// mod mul_fp16x16; -// mod mul_fp16x16_broadcast; -// mod mul_fp8x23; -// mod mul_fp8x23_broadcast; -// mod mul_i32; -// mod mul_i32_broadcast; -// mod mul_i8; -// mod mul_i8_broadcast; -// mod mul_u32; -// mod mul_u32_broadcast; -// mod or_fp16x16; -// mod or_fp16x16_broadcast; -// mod or_fp8x23; -// mod or_fp8x23_broadcast; -// mod or_i32; -// mod or_i32_broadcast; -// mod or_i8; -// mod or_i8_broadcast; -// mod or_u32; -// mod or_u32_broadcast; -// mod reduce_sum_fp16x16_1D; -// mod reduce_sum_fp16x16_2D_default; -// mod reduce_sum_fp16x16_2D_keepdims; -// mod reduce_sum_fp16x16_2D_axis_1; -// mod reduce_sum_fp8x23_1D; -// mod reduce_sum_fp8x23_2D_default; -// mod reduce_sum_fp8x23_2D_keepdims; -// mod reduce_sum_fp8x23_2D_axis_1; -// mod reduce_sum_i32_1D; -// mod reduce_sum_i32_2D_default; -// mod reduce_sum_i32_2D_keepdims; -// mod reduce_sum_i32_2D_axis_1; -// mod reduce_sum_i8_1D; -// mod reduce_sum_i8_2D_default; -// mod reduce_sum_i8_2D_keepdims; -// mod reduce_sum_i8_2D_axis_1; -// mod reduce_sum_u32_1D; -// mod reduce_sum_u32_2D_default; -// mod reduce_sum_u32_2D_keepdims; -// mod reduce_sum_u32_2D_axis_1; -// mod relu_fp16x16; -// mod relu_fp8x23; -// mod relu_i32; -// mod relu_i8; -// mod sigmoid_fp16x16; -// mod sigmoid_fp8x23; -// mod sin_fp16x16; -// mod sin_fp8x23; -// mod sinh_fp16x16; -// mod sinh_fp8x23; -// mod softmax_fp16x16; -// mod softmax_fp8x23; -// mod softplus_fp8x23; -// mod softplus_fp16x16; -// mod softsign_fp8x23; -// mod softsign_fp16x16; -// mod sqrt_fp16x16; -// mod sqrt_fp8x23; -// mod sub_fp16x16; -// mod sub_fp16x16_broadcast; -// mod sub_fp8x23; -// mod sub_fp8x23_broadcast; -// mod sub_i32; -// mod sub_i32_broadcast; -// mod sub_i8; -// mod sub_i8_broadcast; -// mod sub_u32; -// mod sub_u32_broadcast; -// mod tanh_fp16x16; -// mod tanh_fp8x23; -// mod transpose_fp16x16_2d; -// mod transpose_fp16x16_3d; -// mod transpose_fp8x23_2d; -// mod transpose_fp8x23_3d; -// mod transpose_i32_2d; -// mod transpose_i32_3d; -// mod transpose_i8_2d; -// mod transpose_i8_3d; -// mod transpose_u32_2d; -// mod transpose_u32_3d; -// mod xor_fp16x16; -// mod xor_fp16x16_broadcast; -// mod xor_fp8x23; -// mod xor_fp8x23_broadcast; -// mod xor_i32; -// mod xor_i32_broadcast; -// mod xor_i8; -// mod xor_i8_broadcast; -// mod xor_u32; -// mod xor_u32_broadcast; -// mod less_fp16x16; -// mod less_fp16x16_broadcast; -// mod less_fp8x23; -// mod less_fp8x23_broadcast; -// mod less_i32; -// mod less_i32_broadcast; -// mod less_i8; -// mod less_i8_broadcast; -// mod less_u32; -// mod less_u32_broadcast; -// mod greater_equal_fp16x16; -// mod greater_equal_fp16x16_broadcast; -// mod greater_equal_fp8x23; -// mod greater_equal_fp8x23_broadcast; -// mod greater_equal_i32; -// mod greater_equal_i32_broadcast; -// mod greater_equal_i8; -// mod greater_equal_i8_broadcast; -// mod greater_equal_u32; -// mod greater_equal_u32_broadcast; -// mod slice_fp16x16_2d; -// mod slice_fp16x16_3d; -// mod slice_fp8x23_2d; -// mod slice_fp8x23_3d; -// mod slice_i32_2d; -// mod slice_i32_3d; -// mod slice_i8_2d; -// mod slice_i8_3d; -// mod slice_u32_2d; -// mod slice_u32_3d; -// mod gather_fp8x23_3d_default; -// mod gather_fp8x23_3d_axis1; -// mod gather_fp8x23_3d_axis2; -// mod gather_fp16x16_3d_default; -// mod gather_fp16x16_3d_axis1; -// mod gather_fp16x16_3d_axis2; -// mod gather_i8_3d_default; -// mod gather_i8_3d_axis1; -// mod gather_i8_3d_axis2; -// mod gather_i32_3d_default; -// mod gather_i32_3d_axis1; -// mod gather_i32_3d_axis2; -// mod gather_u32_3d_default; -// mod gather_u32_3d_axis1; -// mod gather_u32_3d_axis2; -// mod nonzero_fp16x16_2d; -// mod nonzero_fp16x16_3d; -// mod nonzero_fp8x23_2d; -// mod nonzero_fp8x23_3d; -// mod nonzero_i32_2d; -// mod nonzero_i32_3d; -// mod nonzero_i8_2d; -// mod nonzero_i8_3d; -// mod nonzero_u32_2d; -// mod nonzero_u32_3d; -// mod squeeze_fP16x16; -// mod squeeze_fP8x23; -// mod squeeze_i32; -// mod squeeze_i8; -// mod squeeze_u32; -// mod unsqueeze_fp16x16_2d; -// mod unsqueeze_fp16x16_3d; -// mod unsqueeze_fp8x23_2d; -// mod unsqueeze_fp8x23_3d; -// mod unsqueeze_i32_2d; -// mod unsqueeze_i32_3d; -// mod unsqueeze_i8_2d; -// mod unsqueeze_i8_3d; -// mod unsqueeze_u32_2d; -// mod unsqueeze_u32_3d; -// mod sign_fP16x16; -// mod sign_fP8x23; -// mod sign_fail; -// mod sign_i32; -// mod sign_i8; -// mod clip_fp16x16_2d; -// mod clip_fp16x16_3d; -// mod clip_fp8x23_2d; -// mod clip_fp8x23_3d; -// mod clip_i32_2d; -// mod clip_i32_3d; -// mod clip_i8_2d; -// mod clip_i8_3d; -// mod clip_u32_2d; -// mod clip_u32_3d; -// mod and_fp16x16; -// mod and_fp16x16_broadcast; -// mod and_fp8x23; -// mod and_fp8x23_broadcast; -// mod and_i32; -// mod and_i32_broadcast; -// mod and_i8; -// mod and_i8_broadcast; -// mod and_u32; -// mod and_u32_broadcast; -// mod identity_fP16x16; -// mod identity_fP8x23; -// mod identity_i32; -// mod identity_i8; -// mod identity_u32; -// mod thresholded_relu_fp16x16; -// mod thresholded_relu_fp8x23; -// mod hard_sigmoid_fp8x23; -// mod hard_sigmoid_fp16x16; -// mod neg_fp16x16; -// mod neg_fp8x23; -// mod neg_i32; -// mod neg_i8; -// mod gemm_all_attributes; -// mod gemm_alpha; -// mod gemm_beta; -// mod gemm_default_matrix_bias; -// mod gemm_default_vector_bias; -// mod gemm_default_no_bias; -// mod gemm_transposeA; -// mod gemm_transposeB; -// mod where_fp16x16; -// mod where_fp16x16_broadcast; -// mod where_fp8x23; -// mod where_fp8x23_broadcast; -// mod where_i32; -// mod where_i32_broadcast; -// mod where_i8; -// mod where_i8_broadcast; -// mod where_u32; -// mod where_u32_broadcast; +mod abs_fp16x16; +mod abs_fp8x23; +mod abs_i32; +mod abs_i8; +mod acos_fp16x16; +mod acos_fp8x23; +mod acosh_fp16x16; +mod acosh_fp8x23; +mod add_fp16x16; +mod add_fp16x16_broadcast; +mod add_fp8x23; +mod add_fp8x23_broadcast; +mod add_i32; +mod add_i32_broadcast; +mod add_i8; +mod add_i8_broadcast; +mod add_u32; +mod add_u32_broadcast; +mod argmax_fp16x16_1D_default; +mod argmax_fp16x16_1D_keepdims_false; +mod argmax_fp16x16_1D_last_index; +mod argmax_fp16x16_2D_default; +mod argmax_fp16x16_2D_keepdims_false; +mod argmax_fp16x16_2D_last_index; +mod argmax_fp16x16_3D_default; +mod argmax_fp16x16_3D_keepdims_false; +mod argmax_fp16x16_3D_last_index; +mod argmax_fp8x23_1D_default; +mod argmax_fp8x23_1D_keepdims_false; +mod argmax_fp8x23_1D_last_index; +mod argmax_fp8x23_2D_default; +mod argmax_fp8x23_2D_keepdims_false; +mod argmax_fp8x23_2D_last_index; +mod argmax_fp8x23_3D_default; +mod argmax_fp8x23_3D_keepdims_false; +mod argmax_fp8x23_3D_last_index; +mod argmax_i32_1D_default; +mod argmax_i32_1D_keepdims_false; +mod argmax_i32_1D_last_index; +mod argmax_i32_2D_default; +mod argmax_i32_2D_keepdims_false; +mod argmax_i32_2D_last_index; +mod argmax_i32_3D_default; +mod argmax_i32_3D_keepdims_false; +mod argmax_i32_3D_last_index; +mod argmax_i8_1D_default; +mod argmax_i8_1D_keepdims_false; +mod argmax_i8_1D_last_index; +mod argmax_i8_2D_default; +mod argmax_i8_2D_keepdims_false; +mod argmax_i8_2D_last_index; +mod argmax_i8_3D_default; +mod argmax_i8_3D_keepdims_false; +mod argmax_i8_3D_last_index; +mod argmax_u32_1D_default; +mod argmax_u32_1D_keepdims_false; +mod argmax_u32_1D_last_index; +mod argmax_u32_2D_default; +mod argmax_u32_2D_keepdims_false; +mod argmax_u32_2D_last_index; +mod argmax_u32_3D_default; +mod argmax_u32_3D_keepdims_false; +mod argmax_u32_3D_last_index; +mod argmin_fp16x16_1D_default; +mod argmin_fp16x16_1D_keepdims_false; +mod argmin_fp16x16_1D_last_index; +mod argmin_fp16x16_2D_default; +mod argmin_fp16x16_2D_keepdims_false; +mod argmin_fp16x16_2D_last_index; +mod argmin_fp16x16_3D_default; +mod argmin_fp16x16_3D_keepdims_false; +mod argmin_fp16x16_3D_last_index; +mod argmin_fp8x23_1D_default; +mod argmin_fp8x23_1D_keepdims_false; +mod argmin_fp8x23_1D_last_index; +mod argmin_fp8x23_2D_default; +mod argmin_fp8x23_2D_keepdims_false; +mod argmin_fp8x23_2D_last_index; +mod argmin_fp8x23_3D_default; +mod argmin_fp8x23_3D_keepdims_false; +mod argmin_fp8x23_3D_last_index; +mod argmin_i32_1D_default; +mod argmin_i32_1D_keepdims_false; +mod argmin_i32_1D_last_index; +mod argmin_i32_2D_default; +mod argmin_i32_2D_keepdims_false; +mod argmin_i32_2D_last_index; +mod argmin_i32_3D_default; +mod argmin_i32_3D_keepdims_false; +mod argmin_i32_3D_last_index; +mod argmin_i8_1D_default; +mod argmin_i8_1D_keepdims_false; +mod argmin_i8_1D_last_index; +mod argmin_i8_2D_default; +mod argmin_i8_2D_keepdims_false; +mod argmin_i8_2D_last_index; +mod argmin_i8_3D_default; +mod argmin_i8_3D_keepdims_false; +mod argmin_i8_3D_last_index; +mod argmin_u32_1D_default; +mod argmin_u32_1D_keepdims_false; +mod argmin_u32_1D_last_index; +mod argmin_u32_2D_default; +mod argmin_u32_2D_keepdims_false; +mod argmin_u32_2D_last_index; +mod argmin_u32_3D_default; +mod argmin_u32_3D_keepdims_false; +mod argmin_u32_3D_last_index; +mod asin_fp16x16; +mod asin_fp8x23; +mod asinh_fp16x16; +mod asinh_fp8x23; +mod atan_fp16x16; +mod atan_fp8x23; +mod ceil_fp16x16; +mod ceil_fp8x23; +mod concat_fp16x16_1d; +mod concat_fp16x16_2d; +mod concat_fp16x16_3d_default; +mod concat_fp16x16_3d_axis_1; +mod concat_fp16x16_3d_axis_2; +mod concat_fp16x16_3d_three_tensors_axis_1; +mod concat_fp16x16_3d_three_tensors_axis_2; +mod concat_fp8x23_1d; +mod concat_fp8x23_2d; +mod concat_fp8x23_3d_default; +mod concat_fp8x23_3d_axis_1; +mod concat_fp8x23_3d_axis_2; +mod concat_fp8x23_3d_three_tensors_axis_1; +mod concat_fp8x23_3d_three_tensors_axis_2; +mod concat_i32_1d; +mod concat_i32_2d; +mod concat_i32_3d_default; +mod concat_i32_3d_axis_1; +mod concat_i32_3d_axis_2; +mod concat_i32_3d_three_tensors_axis_1; +mod concat_i32_3d_three_tensors_axis_2; +mod concat_i8_1d; +mod concat_i8_2d; +mod concat_i8_3d_default; +mod concat_i8_3d_axis_1; +mod concat_i8_3d_axis_2; +mod concat_i8_3d_three_tensors_axis_1; +mod concat_i8_3d_three_tensors_axis_2; +mod concat_u32_1d; +mod concat_u32_2d; +mod concat_u32_3d_default; +mod concat_u32_3d_axis_1; +mod concat_u32_3d_axis_2; +mod concat_u32_3d_three_tensors_axis_1; +mod concat_u32_3d_three_tensors_axis_2; +mod cos_fp16x16; +mod cos_fp8x23; +mod cosh_fp16x16; +mod cosh_fp8x23; +mod cumsum_fp16x16_1d_default; +mod cumsum_fp16x16_1d_exclusive; +mod cumsum_fp16x16_1d_reverse; +mod cumsum_fp16x16_1d_reverse_exclusive; +mod cumsum_fp16x16_2d_axis_0; +mod cumsum_fp16x16_2d_axis_1; +mod cumsum_fp8x23_1d_default; +mod cumsum_fp8x23_1d_exclusive; +mod cumsum_fp8x23_1d_reverse; +mod cumsum_fp8x23_1d_reverse_exclusive; +mod cumsum_fp8x23_2d_axis_0; +mod cumsum_fp8x23_2d_axis_1; +mod cumsum_i32_1d_default; +mod cumsum_i32_1d_exclusive; +mod cumsum_i32_1d_reverse; +mod cumsum_i32_1d_reverse_exclusive; +mod cumsum_i32_2d_axis_0; +mod cumsum_i32_2d_axis_1; +mod cumsum_i8_1d_default; +mod cumsum_i8_1d_exclusive; +mod cumsum_i8_1d_reverse; +mod cumsum_i8_1d_reverse_exclusive; +mod cumsum_i8_2d_axis_0; +mod cumsum_i8_2d_axis_1; +mod cumsum_u32_1d_default; +mod cumsum_u32_1d_exclusive; +mod cumsum_u32_1d_reverse; +mod cumsum_u32_1d_reverse_exclusive; +mod cumsum_u32_2d_axis_0; +mod cumsum_u32_2d_axis_1; +mod div_fp16x16; +mod div_fp16x16_broadcast; +mod div_fp8x23; +mod div_fp8x23_broadcast; +mod div_i32; +mod div_i32_broadcast; +mod div_i8; +mod div_i8_broadcast; +mod div_u32; +mod div_u32_broadcast; +mod equal_fp16x16; +mod equal_fp16x16_broadcast; +mod equal_fp8x23; +mod equal_fp8x23_broadcast; +mod equal_i32; +mod equal_i32_broadcast; +mod equal_i8; +mod equal_i8_broadcast; +mod equal_u32; +mod equal_u32_broadcast; +mod exp_fp16x16; +mod exp_fp8x23; +mod less_equal_fp16x16; +mod less_equal_fp16x16_broadcast; +mod less_equal_fp8x23; +mod less_equal_fp8x23_broadcast; +mod less_equal_i32; +mod less_equal_i32_broadcast; +mod less_equal_i8; +mod less_equal_i8_broadcast; +mod less_equal_u32; +mod less_equal_u32_broadcast; +mod greater_fp16x16; +mod greater_fp16x16_broadcast; +mod greater_fp8x23; +mod greater_fp8x23_broadcast; +mod greater_i32; +mod greater_i32_broadcast; +mod greater_i8; +mod greater_i8_broadcast; +mod greater_u32; +mod greater_u32_broadcast; +mod leaky_relu_fp16x16; +mod leaky_relu_fp8x23; +mod linear_fp16x16; +mod linear_fp8x23; +mod linear_i32; +mod linear_i8; +mod linear_u32; +mod log_fp16x16; +mod log_fp8x23; +mod logsoftmax_fp16x16_axis_0; +mod logsoftmax_fp16x16_axis_1; +mod logsoftmax_fp8x23_axis_0; +mod logsoftmax_fp8x23_axis_1; +mod matmul_fp16x16_1d; +mod matmul_fp16x16_2x2; +mod matmul_fp16x16_2x1; +mod matmul_fp16x16_1x2; +mod matmul_fp8x23_1d; +mod matmul_fp8x23_2x2; +mod matmul_fp8x23_2x1; +mod matmul_fp8x23_1x2; +mod matmul_i32_1d; +mod matmul_i32_2x2; +mod matmul_i32_2x1; +mod matmul_i32_1x2; +mod matmul_i8_1d; +mod matmul_i8_2x2; +mod matmul_i8_2x1; +mod matmul_i8_1x2; +mod matmul_u32_1d; +mod matmul_u32_2x2; +mod matmul_u32_2x1; +mod matmul_u32_1x2; +mod mul_fp16x16; +mod mul_fp16x16_broadcast; +mod mul_fp8x23; +mod mul_fp8x23_broadcast; +mod mul_i32; +mod mul_i32_broadcast; +mod mul_i8; +mod mul_i8_broadcast; +mod mul_u32; +mod mul_u32_broadcast; +mod or_fp16x16; +mod or_fp16x16_broadcast; +mod or_fp8x23; +mod or_fp8x23_broadcast; +mod or_i32; +mod or_i32_broadcast; +mod or_i8; +mod or_i8_broadcast; +mod or_u32; +mod or_u32_broadcast; +mod reduce_sum_fp16x16_1D; +mod reduce_sum_fp16x16_2D_default; +mod reduce_sum_fp16x16_2D_keepdims; +mod reduce_sum_fp16x16_2D_axis_1; +mod reduce_sum_fp8x23_1D; +mod reduce_sum_fp8x23_2D_default; +mod reduce_sum_fp8x23_2D_keepdims; +mod reduce_sum_fp8x23_2D_axis_1; +mod reduce_sum_i32_1D; +mod reduce_sum_i32_2D_default; +mod reduce_sum_i32_2D_keepdims; +mod reduce_sum_i32_2D_axis_1; +mod reduce_sum_i8_1D; +mod reduce_sum_i8_2D_default; +mod reduce_sum_i8_2D_keepdims; +mod reduce_sum_i8_2D_axis_1; +mod reduce_sum_u32_1D; +mod reduce_sum_u32_2D_default; +mod reduce_sum_u32_2D_keepdims; +mod reduce_sum_u32_2D_axis_1; +mod relu_fp16x16; +mod relu_fp8x23; +mod relu_i32; +mod relu_i8; +mod sigmoid_fp16x16; +mod sigmoid_fp8x23; +mod sin_fp16x16; +mod sin_fp8x23; +mod sinh_fp16x16; +mod sinh_fp8x23; +mod softmax_fp16x16; +mod softmax_fp8x23; +mod softplus_fp8x23; +mod softplus_fp16x16; +mod softsign_fp8x23; +mod softsign_fp16x16; +mod sqrt_fp16x16; +mod sqrt_fp8x23; +mod sub_fp16x16; +mod sub_fp16x16_broadcast; +mod sub_fp8x23; +mod sub_fp8x23_broadcast; +mod sub_i32; +mod sub_i32_broadcast; +mod sub_i8; +mod sub_i8_broadcast; +mod sub_u32; +mod sub_u32_broadcast; +mod tanh_fp16x16; +mod tanh_fp8x23; +mod transpose_fp16x16_2d; +mod transpose_fp16x16_3d; +mod transpose_fp8x23_2d; +mod transpose_fp8x23_3d; +mod transpose_i32_2d; +mod transpose_i32_3d; +mod transpose_i8_2d; +mod transpose_i8_3d; +mod transpose_u32_2d; +mod transpose_u32_3d; +mod xor_fp16x16; +mod xor_fp16x16_broadcast; +mod xor_fp8x23; +mod xor_fp8x23_broadcast; +mod xor_i32; +mod xor_i32_broadcast; +mod xor_i8; +mod xor_i8_broadcast; +mod xor_u32; +mod xor_u32_broadcast; +mod less_fp16x16; +mod less_fp16x16_broadcast; +mod less_fp8x23; +mod less_fp8x23_broadcast; +mod less_i32; +mod less_i32_broadcast; +mod less_i8; +mod less_i8_broadcast; +mod less_u32; +mod less_u32_broadcast; +mod greater_equal_fp16x16; +mod greater_equal_fp16x16_broadcast; +mod greater_equal_fp8x23; +mod greater_equal_fp8x23_broadcast; +mod greater_equal_i32; +mod greater_equal_i32_broadcast; +mod greater_equal_i8; +mod greater_equal_i8_broadcast; +mod greater_equal_u32; +mod greater_equal_u32_broadcast; +mod slice_fp16x16_2d; +mod slice_fp16x16_3d; +mod slice_fp8x23_2d; +mod slice_fp8x23_3d; +mod slice_i32_2d; +mod slice_i32_3d; +mod slice_i8_2d; +mod slice_i8_3d; +mod slice_u32_2d; +mod slice_u32_3d; +mod gather_fp8x23_3d_default; +mod gather_fp8x23_3d_axis1; +mod gather_fp8x23_3d_axis2; +mod gather_fp16x16_3d_default; +mod gather_fp16x16_3d_axis1; +mod gather_fp16x16_3d_axis2; +mod gather_i8_3d_default; +mod gather_i8_3d_axis1; +mod gather_i8_3d_axis2; +mod gather_i32_3d_default; +mod gather_i32_3d_axis1; +mod gather_i32_3d_axis2; +mod gather_u32_3d_default; +mod gather_u32_3d_axis1; +mod gather_u32_3d_axis2; +mod nonzero_fp16x16_2d; +mod nonzero_fp16x16_3d; +mod nonzero_fp8x23_2d; +mod nonzero_fp8x23_3d; +mod nonzero_i32_2d; +mod nonzero_i32_3d; +mod nonzero_i8_2d; +mod nonzero_i8_3d; +mod nonzero_u32_2d; +mod nonzero_u32_3d; +mod squeeze_fP16x16; +mod squeeze_fP8x23; +mod squeeze_i32; +mod squeeze_i8; +mod squeeze_u32; +mod unsqueeze_fp16x16_2d; +mod unsqueeze_fp16x16_3d; +mod unsqueeze_fp8x23_2d; +mod unsqueeze_fp8x23_3d; +mod unsqueeze_i32_2d; +mod unsqueeze_i32_3d; +mod unsqueeze_i8_2d; +mod unsqueeze_i8_3d; +mod unsqueeze_u32_2d; +mod unsqueeze_u32_3d; +mod sign_fP16x16; +mod sign_fP8x23; +mod sign_fail; +mod sign_i32; +mod sign_i8; +mod clip_fp16x16_2d; +mod clip_fp16x16_3d; +mod clip_fp8x23_2d; +mod clip_fp8x23_3d; +mod clip_i32_2d; +mod clip_i32_3d; +mod clip_i8_2d; +mod clip_i8_3d; +mod clip_u32_2d; +mod clip_u32_3d; +mod and_fp16x16; +mod and_fp16x16_broadcast; +mod and_fp8x23; +mod and_fp8x23_broadcast; +mod and_i32; +mod and_i32_broadcast; +mod and_i8; +mod and_i8_broadcast; +mod and_u32; +mod and_u32_broadcast; +mod identity_fP16x16; +mod identity_fP8x23; +mod identity_i32; +mod identity_i8; +mod identity_u32; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod where_fp16x16; +mod where_fp16x16_broadcast; +mod where_fp8x23; +mod where_fp8x23_broadcast; +mod where_i32; +mod where_i32_broadcast; +mod where_i8; +mod where_i8_broadcast; +mod where_u32; +mod where_u32_broadcast; From 062a5757f7bad6e8b6f9688b053f94a1c9fd1c90 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 09:09:51 +0200 Subject: [PATCH 012/127] set TreeEnsemble --- src/numbers/fixed_point/core.cairo | 1 + src/operators/ml.cairo | 1 + src/operators/ml/tree_ensemble.cairo | 1 + src/operators/ml/tree_ensemble/core.cairo | 57 ++ tests/nodes.cairo | 1036 ++++++++++----------- 5 files changed, 578 insertions(+), 518 deletions(-) create mode 100644 src/operators/ml/tree_ensemble.cairo create mode 100644 src/operators/ml/tree_ensemble/core.cairo diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 6581b018f..5490fc0de 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1102,4 +1102,5 @@ trait FixedTrait { fn ZERO() -> T; fn ONE() -> T; fn MAX() -> T; + // fn NaN() -> T; } diff --git a/src/operators/ml.cairo b/src/operators/ml.cairo index 96c1859dd..721751fdd 100644 --- a/src/operators/ml.cairo +++ b/src/operators/ml.cairo @@ -1,6 +1,7 @@ mod tree_regressor; mod tree_classifier; mod xgboost_regressor; +mod tree_ensemble; use orion::operators::ml::tree_regressor::core::{TreeRegressorTrait, TreeRegressor}; use orion::operators::ml::tree_regressor::implementations::tree_regressor_fp16x16::FP16x16TreeRegressor; diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo new file mode 100644 index 000000000..ef33ab296 --- /dev/null +++ b/src/operators/ml/tree_ensemble.cairo @@ -0,0 +1 @@ +mod core; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo new file mode 100644 index 000000000..63f0306e5 --- /dev/null +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -0,0 +1,57 @@ +use core::array::SpanTrait; +use core::dict::Felt252DictTrait; +use core::Felt252Dict; + +impl UsizeDictCopy of Copy>; +impl UsizeDictDrop of Drop>; + +#[derive(Copy, Drop)] +struct TreeEnsembleAttributes { + nodes_modes: Span, // Change to modes + nodes_featureids: Span, + nodes_missing_value_tracks_true: Span, + nodes_values: Span, + nodes_truenodeids: Span, + nodes_falsenodeids: Span, +} + +#[derive(Copy, Drop)] +struct TreeEnsemble { + atts: TreeEnsembleAttributes, + tree_ids: Span, + root_index: Felt252Dict, + node_index: Felt252Dict, // index is pedersen hash of tree_id and nid. +} + +#[derive(Copy, Drop)] +enum NODE_MODES { + BRANCH_LEQ, + BRANCH_LT, + BRANCH_GTE, + BRANCH_GT, + BRANCH_EQ, + BRANCH_NEQ, + LEAF +} + + +fn leaf_index_tree, +Copy>( + ref ensemble: TreeEnsemble, x: Span, tree_id: usize +) -> usize { + let mut index = ensemble.root_index.get(tree_id.into()); + + loop { + match *ensemble.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => { continue; }, + NODE_MODES::BRANCH_LT => { continue; }, + NODE_MODES::BRANCH_GTE => { continue; }, + NODE_MODES::BRANCH_GT => { continue; }, + NODE_MODES::BRANCH_EQ => { continue; }, + NODE_MODES::BRANCH_NEQ => { continue; }, + NODE_MODES::LEAF => { break; }, + }; + }; + + 1 +} + diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 4a6d7c8cb..4e34baff1 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,518 +1,518 @@ -mod abs_fp16x16; -mod abs_fp8x23; -mod abs_i32; -mod abs_i8; -mod acos_fp16x16; -mod acos_fp8x23; -mod acosh_fp16x16; -mod acosh_fp8x23; -mod add_fp16x16; -mod add_fp16x16_broadcast; -mod add_fp8x23; -mod add_fp8x23_broadcast; -mod add_i32; -mod add_i32_broadcast; -mod add_i8; -mod add_i8_broadcast; -mod add_u32; -mod add_u32_broadcast; -mod argmax_fp16x16_1D_default; -mod argmax_fp16x16_1D_keepdims_false; -mod argmax_fp16x16_1D_last_index; -mod argmax_fp16x16_2D_default; -mod argmax_fp16x16_2D_keepdims_false; -mod argmax_fp16x16_2D_last_index; -mod argmax_fp16x16_3D_default; -mod argmax_fp16x16_3D_keepdims_false; -mod argmax_fp16x16_3D_last_index; -mod argmax_fp8x23_1D_default; -mod argmax_fp8x23_1D_keepdims_false; -mod argmax_fp8x23_1D_last_index; -mod argmax_fp8x23_2D_default; -mod argmax_fp8x23_2D_keepdims_false; -mod argmax_fp8x23_2D_last_index; -mod argmax_fp8x23_3D_default; -mod argmax_fp8x23_3D_keepdims_false; -mod argmax_fp8x23_3D_last_index; -mod argmax_i32_1D_default; -mod argmax_i32_1D_keepdims_false; -mod argmax_i32_1D_last_index; -mod argmax_i32_2D_default; -mod argmax_i32_2D_keepdims_false; -mod argmax_i32_2D_last_index; -mod argmax_i32_3D_default; -mod argmax_i32_3D_keepdims_false; -mod argmax_i32_3D_last_index; -mod argmax_i8_1D_default; -mod argmax_i8_1D_keepdims_false; -mod argmax_i8_1D_last_index; -mod argmax_i8_2D_default; -mod argmax_i8_2D_keepdims_false; -mod argmax_i8_2D_last_index; -mod argmax_i8_3D_default; -mod argmax_i8_3D_keepdims_false; -mod argmax_i8_3D_last_index; -mod argmax_u32_1D_default; -mod argmax_u32_1D_keepdims_false; -mod argmax_u32_1D_last_index; -mod argmax_u32_2D_default; -mod argmax_u32_2D_keepdims_false; -mod argmax_u32_2D_last_index; -mod argmax_u32_3D_default; -mod argmax_u32_3D_keepdims_false; -mod argmax_u32_3D_last_index; -mod argmin_fp16x16_1D_default; -mod argmin_fp16x16_1D_keepdims_false; -mod argmin_fp16x16_1D_last_index; -mod argmin_fp16x16_2D_default; -mod argmin_fp16x16_2D_keepdims_false; -mod argmin_fp16x16_2D_last_index; -mod argmin_fp16x16_3D_default; -mod argmin_fp16x16_3D_keepdims_false; -mod argmin_fp16x16_3D_last_index; -mod argmin_fp8x23_1D_default; -mod argmin_fp8x23_1D_keepdims_false; -mod argmin_fp8x23_1D_last_index; -mod argmin_fp8x23_2D_default; -mod argmin_fp8x23_2D_keepdims_false; -mod argmin_fp8x23_2D_last_index; -mod argmin_fp8x23_3D_default; -mod argmin_fp8x23_3D_keepdims_false; -mod argmin_fp8x23_3D_last_index; -mod argmin_i32_1D_default; -mod argmin_i32_1D_keepdims_false; -mod argmin_i32_1D_last_index; -mod argmin_i32_2D_default; -mod argmin_i32_2D_keepdims_false; -mod argmin_i32_2D_last_index; -mod argmin_i32_3D_default; -mod argmin_i32_3D_keepdims_false; -mod argmin_i32_3D_last_index; -mod argmin_i8_1D_default; -mod argmin_i8_1D_keepdims_false; -mod argmin_i8_1D_last_index; -mod argmin_i8_2D_default; -mod argmin_i8_2D_keepdims_false; -mod argmin_i8_2D_last_index; -mod argmin_i8_3D_default; -mod argmin_i8_3D_keepdims_false; -mod argmin_i8_3D_last_index; -mod argmin_u32_1D_default; -mod argmin_u32_1D_keepdims_false; -mod argmin_u32_1D_last_index; -mod argmin_u32_2D_default; -mod argmin_u32_2D_keepdims_false; -mod argmin_u32_2D_last_index; -mod argmin_u32_3D_default; -mod argmin_u32_3D_keepdims_false; -mod argmin_u32_3D_last_index; -mod asin_fp16x16; -mod asin_fp8x23; -mod asinh_fp16x16; -mod asinh_fp8x23; -mod atan_fp16x16; -mod atan_fp8x23; -mod ceil_fp16x16; -mod ceil_fp8x23; -mod concat_fp16x16_1d; -mod concat_fp16x16_2d; -mod concat_fp16x16_3d_default; -mod concat_fp16x16_3d_axis_1; -mod concat_fp16x16_3d_axis_2; -mod concat_fp16x16_3d_three_tensors_axis_1; -mod concat_fp16x16_3d_three_tensors_axis_2; -mod concat_fp8x23_1d; -mod concat_fp8x23_2d; -mod concat_fp8x23_3d_default; -mod concat_fp8x23_3d_axis_1; -mod concat_fp8x23_3d_axis_2; -mod concat_fp8x23_3d_three_tensors_axis_1; -mod concat_fp8x23_3d_three_tensors_axis_2; -mod concat_i32_1d; -mod concat_i32_2d; -mod concat_i32_3d_default; -mod concat_i32_3d_axis_1; -mod concat_i32_3d_axis_2; -mod concat_i32_3d_three_tensors_axis_1; -mod concat_i32_3d_three_tensors_axis_2; -mod concat_i8_1d; -mod concat_i8_2d; -mod concat_i8_3d_default; -mod concat_i8_3d_axis_1; -mod concat_i8_3d_axis_2; -mod concat_i8_3d_three_tensors_axis_1; -mod concat_i8_3d_three_tensors_axis_2; -mod concat_u32_1d; -mod concat_u32_2d; -mod concat_u32_3d_default; -mod concat_u32_3d_axis_1; -mod concat_u32_3d_axis_2; -mod concat_u32_3d_three_tensors_axis_1; -mod concat_u32_3d_three_tensors_axis_2; -mod cos_fp16x16; -mod cos_fp8x23; -mod cosh_fp16x16; -mod cosh_fp8x23; -mod cumsum_fp16x16_1d_default; -mod cumsum_fp16x16_1d_exclusive; -mod cumsum_fp16x16_1d_reverse; -mod cumsum_fp16x16_1d_reverse_exclusive; -mod cumsum_fp16x16_2d_axis_0; -mod cumsum_fp16x16_2d_axis_1; -mod cumsum_fp8x23_1d_default; -mod cumsum_fp8x23_1d_exclusive; -mod cumsum_fp8x23_1d_reverse; -mod cumsum_fp8x23_1d_reverse_exclusive; -mod cumsum_fp8x23_2d_axis_0; -mod cumsum_fp8x23_2d_axis_1; -mod cumsum_i32_1d_default; -mod cumsum_i32_1d_exclusive; -mod cumsum_i32_1d_reverse; -mod cumsum_i32_1d_reverse_exclusive; -mod cumsum_i32_2d_axis_0; -mod cumsum_i32_2d_axis_1; -mod cumsum_i8_1d_default; -mod cumsum_i8_1d_exclusive; -mod cumsum_i8_1d_reverse; -mod cumsum_i8_1d_reverse_exclusive; -mod cumsum_i8_2d_axis_0; -mod cumsum_i8_2d_axis_1; -mod cumsum_u32_1d_default; -mod cumsum_u32_1d_exclusive; -mod cumsum_u32_1d_reverse; -mod cumsum_u32_1d_reverse_exclusive; -mod cumsum_u32_2d_axis_0; -mod cumsum_u32_2d_axis_1; -mod div_fp16x16; -mod div_fp16x16_broadcast; -mod div_fp8x23; -mod div_fp8x23_broadcast; -mod div_i32; -mod div_i32_broadcast; -mod div_i8; -mod div_i8_broadcast; -mod div_u32; -mod div_u32_broadcast; -mod equal_fp16x16; -mod equal_fp16x16_broadcast; -mod equal_fp8x23; -mod equal_fp8x23_broadcast; -mod equal_i32; -mod equal_i32_broadcast; -mod equal_i8; -mod equal_i8_broadcast; -mod equal_u32; -mod equal_u32_broadcast; -mod exp_fp16x16; -mod exp_fp8x23; -mod less_equal_fp16x16; -mod less_equal_fp16x16_broadcast; -mod less_equal_fp8x23; -mod less_equal_fp8x23_broadcast; -mod less_equal_i32; -mod less_equal_i32_broadcast; -mod less_equal_i8; -mod less_equal_i8_broadcast; -mod less_equal_u32; -mod less_equal_u32_broadcast; -mod greater_fp16x16; -mod greater_fp16x16_broadcast; -mod greater_fp8x23; -mod greater_fp8x23_broadcast; -mod greater_i32; -mod greater_i32_broadcast; -mod greater_i8; -mod greater_i8_broadcast; -mod greater_u32; -mod greater_u32_broadcast; -mod leaky_relu_fp16x16; -mod leaky_relu_fp8x23; -mod linear_fp16x16; -mod linear_fp8x23; -mod linear_i32; -mod linear_i8; -mod linear_u32; -mod log_fp16x16; -mod log_fp8x23; -mod logsoftmax_fp16x16_axis_0; -mod logsoftmax_fp16x16_axis_1; -mod logsoftmax_fp8x23_axis_0; -mod logsoftmax_fp8x23_axis_1; -mod matmul_fp16x16_1d; -mod matmul_fp16x16_2x2; -mod matmul_fp16x16_2x1; -mod matmul_fp16x16_1x2; -mod matmul_fp8x23_1d; -mod matmul_fp8x23_2x2; -mod matmul_fp8x23_2x1; -mod matmul_fp8x23_1x2; -mod matmul_i32_1d; -mod matmul_i32_2x2; -mod matmul_i32_2x1; -mod matmul_i32_1x2; -mod matmul_i8_1d; -mod matmul_i8_2x2; -mod matmul_i8_2x1; -mod matmul_i8_1x2; -mod matmul_u32_1d; -mod matmul_u32_2x2; -mod matmul_u32_2x1; -mod matmul_u32_1x2; -mod mul_fp16x16; -mod mul_fp16x16_broadcast; -mod mul_fp8x23; -mod mul_fp8x23_broadcast; -mod mul_i32; -mod mul_i32_broadcast; -mod mul_i8; -mod mul_i8_broadcast; -mod mul_u32; -mod mul_u32_broadcast; -mod or_fp16x16; -mod or_fp16x16_broadcast; -mod or_fp8x23; -mod or_fp8x23_broadcast; -mod or_i32; -mod or_i32_broadcast; -mod or_i8; -mod or_i8_broadcast; -mod or_u32; -mod or_u32_broadcast; -mod reduce_sum_fp16x16_1D; -mod reduce_sum_fp16x16_2D_default; -mod reduce_sum_fp16x16_2D_keepdims; -mod reduce_sum_fp16x16_2D_axis_1; -mod reduce_sum_fp8x23_1D; -mod reduce_sum_fp8x23_2D_default; -mod reduce_sum_fp8x23_2D_keepdims; -mod reduce_sum_fp8x23_2D_axis_1; -mod reduce_sum_i32_1D; -mod reduce_sum_i32_2D_default; -mod reduce_sum_i32_2D_keepdims; -mod reduce_sum_i32_2D_axis_1; -mod reduce_sum_i8_1D; -mod reduce_sum_i8_2D_default; -mod reduce_sum_i8_2D_keepdims; -mod reduce_sum_i8_2D_axis_1; -mod reduce_sum_u32_1D; -mod reduce_sum_u32_2D_default; -mod reduce_sum_u32_2D_keepdims; -mod reduce_sum_u32_2D_axis_1; -mod relu_fp16x16; -mod relu_fp8x23; -mod relu_i32; -mod relu_i8; -mod sigmoid_fp16x16; -mod sigmoid_fp8x23; -mod sin_fp16x16; -mod sin_fp8x23; -mod sinh_fp16x16; -mod sinh_fp8x23; -mod softmax_fp16x16; -mod softmax_fp8x23; -mod softplus_fp8x23; -mod softplus_fp16x16; -mod softsign_fp8x23; -mod softsign_fp16x16; -mod sqrt_fp16x16; -mod sqrt_fp8x23; -mod sub_fp16x16; -mod sub_fp16x16_broadcast; -mod sub_fp8x23; -mod sub_fp8x23_broadcast; -mod sub_i32; -mod sub_i32_broadcast; -mod sub_i8; -mod sub_i8_broadcast; -mod sub_u32; -mod sub_u32_broadcast; -mod tanh_fp16x16; -mod tanh_fp8x23; -mod transpose_fp16x16_2d; -mod transpose_fp16x16_3d; -mod transpose_fp8x23_2d; -mod transpose_fp8x23_3d; -mod transpose_i32_2d; -mod transpose_i32_3d; -mod transpose_i8_2d; -mod transpose_i8_3d; -mod transpose_u32_2d; -mod transpose_u32_3d; -mod xor_fp16x16; -mod xor_fp16x16_broadcast; -mod xor_fp8x23; -mod xor_fp8x23_broadcast; -mod xor_i32; -mod xor_i32_broadcast; -mod xor_i8; -mod xor_i8_broadcast; -mod xor_u32; -mod xor_u32_broadcast; -mod less_fp16x16; -mod less_fp16x16_broadcast; -mod less_fp8x23; -mod less_fp8x23_broadcast; -mod less_i32; -mod less_i32_broadcast; -mod less_i8; -mod less_i8_broadcast; -mod less_u32; -mod less_u32_broadcast; -mod greater_equal_fp16x16; -mod greater_equal_fp16x16_broadcast; -mod greater_equal_fp8x23; -mod greater_equal_fp8x23_broadcast; -mod greater_equal_i32; -mod greater_equal_i32_broadcast; -mod greater_equal_i8; -mod greater_equal_i8_broadcast; -mod greater_equal_u32; -mod greater_equal_u32_broadcast; -mod slice_fp16x16_2d; -mod slice_fp16x16_3d; -mod slice_fp8x23_2d; -mod slice_fp8x23_3d; -mod slice_i32_2d; -mod slice_i32_3d; -mod slice_i8_2d; -mod slice_i8_3d; -mod slice_u32_2d; -mod slice_u32_3d; -mod gather_fp8x23_3d_default; -mod gather_fp8x23_3d_axis1; -mod gather_fp8x23_3d_axis2; -mod gather_fp16x16_3d_default; -mod gather_fp16x16_3d_axis1; -mod gather_fp16x16_3d_axis2; -mod gather_i8_3d_default; -mod gather_i8_3d_axis1; -mod gather_i8_3d_axis2; -mod gather_i32_3d_default; -mod gather_i32_3d_axis1; -mod gather_i32_3d_axis2; -mod gather_u32_3d_default; -mod gather_u32_3d_axis1; -mod gather_u32_3d_axis2; -mod nonzero_fp16x16_2d; -mod nonzero_fp16x16_3d; -mod nonzero_fp8x23_2d; -mod nonzero_fp8x23_3d; -mod nonzero_i32_2d; -mod nonzero_i32_3d; -mod nonzero_i8_2d; -mod nonzero_i8_3d; -mod nonzero_u32_2d; -mod nonzero_u32_3d; -mod squeeze_fP16x16; -mod squeeze_fP8x23; -mod squeeze_i32; -mod squeeze_i8; -mod squeeze_u32; -mod unsqueeze_fp16x16_2d; -mod unsqueeze_fp16x16_3d; -mod unsqueeze_fp8x23_2d; -mod unsqueeze_fp8x23_3d; -mod unsqueeze_i32_2d; -mod unsqueeze_i32_3d; -mod unsqueeze_i8_2d; -mod unsqueeze_i8_3d; -mod unsqueeze_u32_2d; -mod unsqueeze_u32_3d; -mod sign_fP16x16; -mod sign_fP8x23; -mod sign_fail; -mod sign_i32; -mod sign_i8; -mod clip_fp16x16_2d; -mod clip_fp16x16_3d; -mod clip_fp8x23_2d; -mod clip_fp8x23_3d; -mod clip_i32_2d; -mod clip_i32_3d; -mod clip_i8_2d; -mod clip_i8_3d; -mod clip_u32_2d; -mod clip_u32_3d; -mod and_fp16x16; -mod and_fp16x16_broadcast; -mod and_fp8x23; -mod and_fp8x23_broadcast; -mod and_i32; -mod and_i32_broadcast; -mod and_i8; -mod and_i8_broadcast; -mod and_u32; -mod and_u32_broadcast; -mod identity_fP16x16; -mod identity_fP8x23; -mod identity_i32; -mod identity_i8; -mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; -mod where_fp16x16; -mod where_fp16x16_broadcast; -mod where_fp8x23; -mod where_fp8x23_broadcast; -mod where_i32; -mod where_i32_broadcast; -mod where_i8; -mod where_i8_broadcast; -mod where_u32; -mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; +// mod abs_fp16x16; +// mod abs_fp8x23; +// mod abs_i32; +// mod abs_i8; +// mod acos_fp16x16; +// mod acos_fp8x23; +// mod acosh_fp16x16; +// mod acosh_fp8x23; +// mod add_fp16x16; +// mod add_fp16x16_broadcast; +// mod add_fp8x23; +// mod add_fp8x23_broadcast; +// mod add_i32; +// mod add_i32_broadcast; +// mod add_i8; +// mod add_i8_broadcast; +// mod add_u32; +// mod add_u32_broadcast; +// mod argmax_fp16x16_1D_default; +// mod argmax_fp16x16_1D_keepdims_false; +// mod argmax_fp16x16_1D_last_index; +// mod argmax_fp16x16_2D_default; +// mod argmax_fp16x16_2D_keepdims_false; +// mod argmax_fp16x16_2D_last_index; +// mod argmax_fp16x16_3D_default; +// mod argmax_fp16x16_3D_keepdims_false; +// mod argmax_fp16x16_3D_last_index; +// mod argmax_fp8x23_1D_default; +// mod argmax_fp8x23_1D_keepdims_false; +// mod argmax_fp8x23_1D_last_index; +// mod argmax_fp8x23_2D_default; +// mod argmax_fp8x23_2D_keepdims_false; +// mod argmax_fp8x23_2D_last_index; +// mod argmax_fp8x23_3D_default; +// mod argmax_fp8x23_3D_keepdims_false; +// mod argmax_fp8x23_3D_last_index; +// mod argmax_i32_1D_default; +// mod argmax_i32_1D_keepdims_false; +// mod argmax_i32_1D_last_index; +// mod argmax_i32_2D_default; +// mod argmax_i32_2D_keepdims_false; +// mod argmax_i32_2D_last_index; +// mod argmax_i32_3D_default; +// mod argmax_i32_3D_keepdims_false; +// mod argmax_i32_3D_last_index; +// mod argmax_i8_1D_default; +// mod argmax_i8_1D_keepdims_false; +// mod argmax_i8_1D_last_index; +// mod argmax_i8_2D_default; +// mod argmax_i8_2D_keepdims_false; +// mod argmax_i8_2D_last_index; +// mod argmax_i8_3D_default; +// mod argmax_i8_3D_keepdims_false; +// mod argmax_i8_3D_last_index; +// mod argmax_u32_1D_default; +// mod argmax_u32_1D_keepdims_false; +// mod argmax_u32_1D_last_index; +// mod argmax_u32_2D_default; +// mod argmax_u32_2D_keepdims_false; +// mod argmax_u32_2D_last_index; +// mod argmax_u32_3D_default; +// mod argmax_u32_3D_keepdims_false; +// mod argmax_u32_3D_last_index; +// mod argmin_fp16x16_1D_default; +// mod argmin_fp16x16_1D_keepdims_false; +// mod argmin_fp16x16_1D_last_index; +// mod argmin_fp16x16_2D_default; +// mod argmin_fp16x16_2D_keepdims_false; +// mod argmin_fp16x16_2D_last_index; +// mod argmin_fp16x16_3D_default; +// mod argmin_fp16x16_3D_keepdims_false; +// mod argmin_fp16x16_3D_last_index; +// mod argmin_fp8x23_1D_default; +// mod argmin_fp8x23_1D_keepdims_false; +// mod argmin_fp8x23_1D_last_index; +// mod argmin_fp8x23_2D_default; +// mod argmin_fp8x23_2D_keepdims_false; +// mod argmin_fp8x23_2D_last_index; +// mod argmin_fp8x23_3D_default; +// mod argmin_fp8x23_3D_keepdims_false; +// mod argmin_fp8x23_3D_last_index; +// mod argmin_i32_1D_default; +// mod argmin_i32_1D_keepdims_false; +// mod argmin_i32_1D_last_index; +// mod argmin_i32_2D_default; +// mod argmin_i32_2D_keepdims_false; +// mod argmin_i32_2D_last_index; +// mod argmin_i32_3D_default; +// mod argmin_i32_3D_keepdims_false; +// mod argmin_i32_3D_last_index; +// mod argmin_i8_1D_default; +// mod argmin_i8_1D_keepdims_false; +// mod argmin_i8_1D_last_index; +// mod argmin_i8_2D_default; +// mod argmin_i8_2D_keepdims_false; +// mod argmin_i8_2D_last_index; +// mod argmin_i8_3D_default; +// mod argmin_i8_3D_keepdims_false; +// mod argmin_i8_3D_last_index; +// mod argmin_u32_1D_default; +// mod argmin_u32_1D_keepdims_false; +// mod argmin_u32_1D_last_index; +// mod argmin_u32_2D_default; +// mod argmin_u32_2D_keepdims_false; +// mod argmin_u32_2D_last_index; +// mod argmin_u32_3D_default; +// mod argmin_u32_3D_keepdims_false; +// mod argmin_u32_3D_last_index; +// mod asin_fp16x16; +// mod asin_fp8x23; +// mod asinh_fp16x16; +// mod asinh_fp8x23; +// mod atan_fp16x16; +// mod atan_fp8x23; +// mod ceil_fp16x16; +// mod ceil_fp8x23; +// mod concat_fp16x16_1d; +// mod concat_fp16x16_2d; +// mod concat_fp16x16_3d_default; +// mod concat_fp16x16_3d_axis_1; +// mod concat_fp16x16_3d_axis_2; +// mod concat_fp16x16_3d_three_tensors_axis_1; +// mod concat_fp16x16_3d_three_tensors_axis_2; +// mod concat_fp8x23_1d; +// mod concat_fp8x23_2d; +// mod concat_fp8x23_3d_default; +// mod concat_fp8x23_3d_axis_1; +// mod concat_fp8x23_3d_axis_2; +// mod concat_fp8x23_3d_three_tensors_axis_1; +// mod concat_fp8x23_3d_three_tensors_axis_2; +// mod concat_i32_1d; +// mod concat_i32_2d; +// mod concat_i32_3d_default; +// mod concat_i32_3d_axis_1; +// mod concat_i32_3d_axis_2; +// mod concat_i32_3d_three_tensors_axis_1; +// mod concat_i32_3d_three_tensors_axis_2; +// mod concat_i8_1d; +// mod concat_i8_2d; +// mod concat_i8_3d_default; +// mod concat_i8_3d_axis_1; +// mod concat_i8_3d_axis_2; +// mod concat_i8_3d_three_tensors_axis_1; +// mod concat_i8_3d_three_tensors_axis_2; +// mod concat_u32_1d; +// mod concat_u32_2d; +// mod concat_u32_3d_default; +// mod concat_u32_3d_axis_1; +// mod concat_u32_3d_axis_2; +// mod concat_u32_3d_three_tensors_axis_1; +// mod concat_u32_3d_three_tensors_axis_2; +// mod cos_fp16x16; +// mod cos_fp8x23; +// mod cosh_fp16x16; +// mod cosh_fp8x23; +// mod cumsum_fp16x16_1d_default; +// mod cumsum_fp16x16_1d_exclusive; +// mod cumsum_fp16x16_1d_reverse; +// mod cumsum_fp16x16_1d_reverse_exclusive; +// mod cumsum_fp16x16_2d_axis_0; +// mod cumsum_fp16x16_2d_axis_1; +// mod cumsum_fp8x23_1d_default; +// mod cumsum_fp8x23_1d_exclusive; +// mod cumsum_fp8x23_1d_reverse; +// mod cumsum_fp8x23_1d_reverse_exclusive; +// mod cumsum_fp8x23_2d_axis_0; +// mod cumsum_fp8x23_2d_axis_1; +// mod cumsum_i32_1d_default; +// mod cumsum_i32_1d_exclusive; +// mod cumsum_i32_1d_reverse; +// mod cumsum_i32_1d_reverse_exclusive; +// mod cumsum_i32_2d_axis_0; +// mod cumsum_i32_2d_axis_1; +// mod cumsum_i8_1d_default; +// mod cumsum_i8_1d_exclusive; +// mod cumsum_i8_1d_reverse; +// mod cumsum_i8_1d_reverse_exclusive; +// mod cumsum_i8_2d_axis_0; +// mod cumsum_i8_2d_axis_1; +// mod cumsum_u32_1d_default; +// mod cumsum_u32_1d_exclusive; +// mod cumsum_u32_1d_reverse; +// mod cumsum_u32_1d_reverse_exclusive; +// mod cumsum_u32_2d_axis_0; +// mod cumsum_u32_2d_axis_1; +// mod div_fp16x16; +// mod div_fp16x16_broadcast; +// mod div_fp8x23; +// mod div_fp8x23_broadcast; +// mod div_i32; +// mod div_i32_broadcast; +// mod div_i8; +// mod div_i8_broadcast; +// mod div_u32; +// mod div_u32_broadcast; +// mod equal_fp16x16; +// mod equal_fp16x16_broadcast; +// mod equal_fp8x23; +// mod equal_fp8x23_broadcast; +// mod equal_i32; +// mod equal_i32_broadcast; +// mod equal_i8; +// mod equal_i8_broadcast; +// mod equal_u32; +// mod equal_u32_broadcast; +// mod exp_fp16x16; +// mod exp_fp8x23; +// mod less_equal_fp16x16; +// mod less_equal_fp16x16_broadcast; +// mod less_equal_fp8x23; +// mod less_equal_fp8x23_broadcast; +// mod less_equal_i32; +// mod less_equal_i32_broadcast; +// mod less_equal_i8; +// mod less_equal_i8_broadcast; +// mod less_equal_u32; +// mod less_equal_u32_broadcast; +// mod greater_fp16x16; +// mod greater_fp16x16_broadcast; +// mod greater_fp8x23; +// mod greater_fp8x23_broadcast; +// mod greater_i32; +// mod greater_i32_broadcast; +// mod greater_i8; +// mod greater_i8_broadcast; +// mod greater_u32; +// mod greater_u32_broadcast; +// mod leaky_relu_fp16x16; +// mod leaky_relu_fp8x23; +// mod linear_fp16x16; +// mod linear_fp8x23; +// mod linear_i32; +// mod linear_i8; +// mod linear_u32; +// mod log_fp16x16; +// mod log_fp8x23; +// mod logsoftmax_fp16x16_axis_0; +// mod logsoftmax_fp16x16_axis_1; +// mod logsoftmax_fp8x23_axis_0; +// mod logsoftmax_fp8x23_axis_1; +// mod matmul_fp16x16_1d; +// mod matmul_fp16x16_2x2; +// mod matmul_fp16x16_2x1; +// mod matmul_fp16x16_1x2; +// mod matmul_fp8x23_1d; +// mod matmul_fp8x23_2x2; +// mod matmul_fp8x23_2x1; +// mod matmul_fp8x23_1x2; +// mod matmul_i32_1d; +// mod matmul_i32_2x2; +// mod matmul_i32_2x1; +// mod matmul_i32_1x2; +// mod matmul_i8_1d; +// mod matmul_i8_2x2; +// mod matmul_i8_2x1; +// mod matmul_i8_1x2; +// mod matmul_u32_1d; +// mod matmul_u32_2x2; +// mod matmul_u32_2x1; +// mod matmul_u32_1x2; +// mod mul_fp16x16; +// mod mul_fp16x16_broadcast; +// mod mul_fp8x23; +// mod mul_fp8x23_broadcast; +// mod mul_i32; +// mod mul_i32_broadcast; +// mod mul_i8; +// mod mul_i8_broadcast; +// mod mul_u32; +// mod mul_u32_broadcast; +// mod or_fp16x16; +// mod or_fp16x16_broadcast; +// mod or_fp8x23; +// mod or_fp8x23_broadcast; +// mod or_i32; +// mod or_i32_broadcast; +// mod or_i8; +// mod or_i8_broadcast; +// mod or_u32; +// mod or_u32_broadcast; +// mod reduce_sum_fp16x16_1D; +// mod reduce_sum_fp16x16_2D_default; +// mod reduce_sum_fp16x16_2D_keepdims; +// mod reduce_sum_fp16x16_2D_axis_1; +// mod reduce_sum_fp8x23_1D; +// mod reduce_sum_fp8x23_2D_default; +// mod reduce_sum_fp8x23_2D_keepdims; +// mod reduce_sum_fp8x23_2D_axis_1; +// mod reduce_sum_i32_1D; +// mod reduce_sum_i32_2D_default; +// mod reduce_sum_i32_2D_keepdims; +// mod reduce_sum_i32_2D_axis_1; +// mod reduce_sum_i8_1D; +// mod reduce_sum_i8_2D_default; +// mod reduce_sum_i8_2D_keepdims; +// mod reduce_sum_i8_2D_axis_1; +// mod reduce_sum_u32_1D; +// mod reduce_sum_u32_2D_default; +// mod reduce_sum_u32_2D_keepdims; +// mod reduce_sum_u32_2D_axis_1; +// mod relu_fp16x16; +// mod relu_fp8x23; +// mod relu_i32; +// mod relu_i8; +// mod sigmoid_fp16x16; +// mod sigmoid_fp8x23; +// mod sin_fp16x16; +// mod sin_fp8x23; +// mod sinh_fp16x16; +// mod sinh_fp8x23; +// mod softmax_fp16x16; +// mod softmax_fp8x23; +// mod softplus_fp8x23; +// mod softplus_fp16x16; +// mod softsign_fp8x23; +// mod softsign_fp16x16; +// mod sqrt_fp16x16; +// mod sqrt_fp8x23; +// mod sub_fp16x16; +// mod sub_fp16x16_broadcast; +// mod sub_fp8x23; +// mod sub_fp8x23_broadcast; +// mod sub_i32; +// mod sub_i32_broadcast; +// mod sub_i8; +// mod sub_i8_broadcast; +// mod sub_u32; +// mod sub_u32_broadcast; +// mod tanh_fp16x16; +// mod tanh_fp8x23; +// mod transpose_fp16x16_2d; +// mod transpose_fp16x16_3d; +// mod transpose_fp8x23_2d; +// mod transpose_fp8x23_3d; +// mod transpose_i32_2d; +// mod transpose_i32_3d; +// mod transpose_i8_2d; +// mod transpose_i8_3d; +// mod transpose_u32_2d; +// mod transpose_u32_3d; +// mod xor_fp16x16; +// mod xor_fp16x16_broadcast; +// mod xor_fp8x23; +// mod xor_fp8x23_broadcast; +// mod xor_i32; +// mod xor_i32_broadcast; +// mod xor_i8; +// mod xor_i8_broadcast; +// mod xor_u32; +// mod xor_u32_broadcast; +// mod less_fp16x16; +// mod less_fp16x16_broadcast; +// mod less_fp8x23; +// mod less_fp8x23_broadcast; +// mod less_i32; +// mod less_i32_broadcast; +// mod less_i8; +// mod less_i8_broadcast; +// mod less_u32; +// mod less_u32_broadcast; +// mod greater_equal_fp16x16; +// mod greater_equal_fp16x16_broadcast; +// mod greater_equal_fp8x23; +// mod greater_equal_fp8x23_broadcast; +// mod greater_equal_i32; +// mod greater_equal_i32_broadcast; +// mod greater_equal_i8; +// mod greater_equal_i8_broadcast; +// mod greater_equal_u32; +// mod greater_equal_u32_broadcast; +// mod slice_fp16x16_2d; +// mod slice_fp16x16_3d; +// mod slice_fp8x23_2d; +// mod slice_fp8x23_3d; +// mod slice_i32_2d; +// mod slice_i32_3d; +// mod slice_i8_2d; +// mod slice_i8_3d; +// mod slice_u32_2d; +// mod slice_u32_3d; +// mod gather_fp8x23_3d_default; +// mod gather_fp8x23_3d_axis1; +// mod gather_fp8x23_3d_axis2; +// mod gather_fp16x16_3d_default; +// mod gather_fp16x16_3d_axis1; +// mod gather_fp16x16_3d_axis2; +// mod gather_i8_3d_default; +// mod gather_i8_3d_axis1; +// mod gather_i8_3d_axis2; +// mod gather_i32_3d_default; +// mod gather_i32_3d_axis1; +// mod gather_i32_3d_axis2; +// mod gather_u32_3d_default; +// mod gather_u32_3d_axis1; +// mod gather_u32_3d_axis2; +// mod nonzero_fp16x16_2d; +// mod nonzero_fp16x16_3d; +// mod nonzero_fp8x23_2d; +// mod nonzero_fp8x23_3d; +// mod nonzero_i32_2d; +// mod nonzero_i32_3d; +// mod nonzero_i8_2d; +// mod nonzero_i8_3d; +// mod nonzero_u32_2d; +// mod nonzero_u32_3d; +// mod squeeze_fP16x16; +// mod squeeze_fP8x23; +// mod squeeze_i32; +// mod squeeze_i8; +// mod squeeze_u32; +// mod unsqueeze_fp16x16_2d; +// mod unsqueeze_fp16x16_3d; +// mod unsqueeze_fp8x23_2d; +// mod unsqueeze_fp8x23_3d; +// mod unsqueeze_i32_2d; +// mod unsqueeze_i32_3d; +// mod unsqueeze_i8_2d; +// mod unsqueeze_i8_3d; +// mod unsqueeze_u32_2d; +// mod unsqueeze_u32_3d; +// mod sign_fP16x16; +// mod sign_fP8x23; +// mod sign_fail; +// mod sign_i32; +// mod sign_i8; +// mod clip_fp16x16_2d; +// mod clip_fp16x16_3d; +// mod clip_fp8x23_2d; +// mod clip_fp8x23_3d; +// mod clip_i32_2d; +// mod clip_i32_3d; +// mod clip_i8_2d; +// mod clip_i8_3d; +// mod clip_u32_2d; +// mod clip_u32_3d; +// mod and_fp16x16; +// mod and_fp16x16_broadcast; +// mod and_fp8x23; +// mod and_fp8x23_broadcast; +// mod and_i32; +// mod and_i32_broadcast; +// mod and_i8; +// mod and_i8_broadcast; +// mod and_u32; +// mod and_u32_broadcast; +// mod identity_fP16x16; +// mod identity_fP8x23; +// mod identity_i32; +// mod identity_i8; +// mod identity_u32; +// mod thresholded_relu_fp16x16; +// mod thresholded_relu_fp8x23; +// mod hard_sigmoid_fp8x23; +// mod hard_sigmoid_fp16x16; +// mod neg_fp16x16; +// mod neg_fp8x23; +// mod neg_i32; +// mod neg_i8; +// mod gemm_all_attributes; +// mod gemm_alpha; +// mod gemm_beta; +// mod gemm_default_matrix_bias; +// mod gemm_default_vector_bias; +// mod gemm_default_no_bias; +// mod gemm_transposeA; +// mod gemm_transposeB; +// mod min_fp16x16_three_tensors; +// mod min_fp16x16_broadcast_three_tensors; +// mod min_fp16x16_two_tensors; +// mod min_fp16x16_broadcast_two_tensors; +// mod min_fp8x23_three_tensors; +// mod min_fp8x23_broadcast_three_tensors; +// mod min_fp8x23_two_tensors; +// mod min_fp8x23_broadcast_two_tensors; +// mod min_i32_three_tensors; +// mod min_i32_broadcast_three_tensors; +// mod min_i32_two_tensors; +// mod min_i32_broadcast_two_tensors; +// mod min_i8_three_tensors; +// mod min_i8_broadcast_three_tensors; +// mod min_i8_two_tensors; +// mod min_i8_broadcast_two_tensors; +// mod min_u32_three_tensors; +// mod min_u32_broadcast_three_tensors; +// mod min_u32_two_tensors; +// mod min_u32_broadcast_two_tensors; +// mod where_fp16x16; +// mod where_fp16x16_broadcast; +// mod where_fp8x23; +// mod where_fp8x23_broadcast; +// mod where_i32; +// mod where_i32_broadcast; +// mod where_i8; +// mod where_i8_broadcast; +// mod where_u32; +// mod where_u32_broadcast; +// mod round_fp16x16; +// mod round_fp8x23; +// mod max_fp16x16_three_tensors; +// mod max_fp16x16_broadcast_three_tensors; +// mod max_fp16x16_two_tensors; +// mod max_fp16x16_broadcast_two_tensors; +// mod max_fp8x23_three_tensors; +// mod max_fp8x23_broadcast_three_tensors; +// mod max_fp8x23_two_tensors; +// mod max_fp8x23_broadcast_two_tensors; +// mod max_i32_three_tensors; +// mod max_i32_broadcast_three_tensors; +// mod max_i32_two_tensors; +// mod max_i32_broadcast_two_tensors; +// mod max_i8_three_tensors; +// mod max_i8_broadcast_three_tensors; +// mod max_i8_two_tensors; +// mod max_i8_broadcast_two_tensors; +// mod max_u32_three_tensors; +// mod max_u32_broadcast_three_tensors; +// mod max_u32_two_tensors; +// mod max_u32_broadcast_two_tensors; From 05bc3deaed89b0a751bba57bbd2f61b98262144b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 09:30:58 +0200 Subject: [PATCH 013/127] implement NaN --- src/numbers.cairo | 99 +++++++++++++++++++ src/numbers/fixed_point/core.cairo | 3 +- .../implementations/fp16x16/core.cairo | 8 ++ .../implementations/fp16x16wide/core.cairo | 8 ++ .../implementations/fp32x32/core.cairo | 30 +++--- .../implementations/fp64x64/core.cairo | 30 +++--- .../implementations/fp8x23/core.cairo | 8 ++ .../implementations/fp8x23wide/core.cairo | 8 ++ src/numbers/signed_integer/i128.cairo | 8 ++ src/numbers/signed_integer/i16.cairo | 8 ++ src/numbers/signed_integer/i32.cairo | 8 ++ src/numbers/signed_integer/i64.cairo | 8 ++ src/numbers/signed_integer/i8.cairo | 8 ++ .../signed_integer/integer_trait.cairo | 3 + 14 files changed, 214 insertions(+), 23 deletions(-) diff --git a/src/numbers.cairo b/src/numbers.cairo index d81cefa33..5e27a4ed0 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -49,6 +49,8 @@ trait NumberTrait { fn sign(self: T) -> T; fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; + fn NaN() -> T; + fn is_nan(self: T) -> bool; } use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; @@ -226,6 +228,14 @@ impl FP8x23Number of NumberTrait { fn where(self: FP8x23, x: FP8x23, y: FP8x23) -> FP8x23 { comp_fp8x23::where(self, x, y) } + + fn NaN() -> FP8x23 { + FP8x23Impl::NaN() + } + + fn is_nan(self: FP8x23) -> bool { + FP8x23Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; @@ -403,6 +413,14 @@ impl FP8x23WNumber of NumberTrait { fn where(self: FP8x23W, x: FP8x23W, y: FP8x23W) -> FP8x23W { comp_fp8x23wide::where(self, x, y) } + + fn NaN() -> FP8x23W { + FP8x23WImpl::NaN() + } + + fn is_nan(self: FP8x23W) -> bool { + FP8x23WImpl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -580,6 +598,14 @@ impl FP16x16Number of NumberTrait { fn where(self: FP16x16, x: FP16x16, y: FP16x16) -> FP16x16 { comp_fp16x16::where(self, x, y) } + + fn NaN() -> FP16x16 { + FP16x16Impl::NaN() + } + + fn is_nan(self: FP16x16) -> bool { + FP16x16Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; @@ -757,6 +783,14 @@ impl FP16x16WNumber of NumberTrait { fn where(self: FP16x16W, x: FP16x16W, y: FP16x16W) -> FP16x16W { comp_fp16x16wide::where(self, x, y) } + + fn NaN() -> FP16x16W { + FP16x16WImpl::NaN() + } + + fn is_nan(self: FP16x16W) -> bool { + FP16x16WImpl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; @@ -935,6 +969,14 @@ impl FP64x64Number of NumberTrait { fn where(self: FP64x64, x: FP64x64, y: FP64x64) -> FP64x64 { comp_fp64x64::where(self, x, y) } + + fn NaN() -> FP64x64 { + FP64x64Impl::NaN() + } + + fn is_nan(self: FP64x64) -> bool { + FP64x64Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; @@ -1113,6 +1155,14 @@ impl FP32x32Number of NumberTrait { fn where(self: FP32x32, x: FP32x32, y: FP32x32) -> FP32x32 { comp_fp32x32::where(self, x, y) } + + fn NaN() -> FP32x32 { + FP32x32Impl::NaN() + } + + fn is_nan(self: FP32x32) -> bool { + FP32x32Impl::is_nan(self) + } } use orion::numbers::signed_integer::i8 as i8_core; @@ -1305,6 +1355,14 @@ impl I8Number of NumberTrait { return x; } } + + fn NaN() -> i8 { + IntegerTrait::NaN() + } + + fn is_nan(self: i8) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i16 as i16_core; @@ -1497,6 +1555,14 @@ impl i16Number of NumberTrait { return x; } } + + fn NaN() -> i16 { + IntegerTrait::NaN() + } + + fn is_nan(self: i16) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i32 as i32_core; @@ -1689,6 +1755,14 @@ impl i32Number of NumberTrait { return x; } } + + fn NaN() -> i32 { + IntegerTrait::NaN() + } + + fn is_nan(self: i32) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i64 as i64_core; @@ -1881,6 +1955,14 @@ impl i64Number of NumberTrait { return x; } } + + fn NaN() -> i64 { + IntegerTrait::NaN() + } + + fn is_nan(self: i64) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i128 as i128_core; @@ -2074,6 +2156,15 @@ impl i128Number of NumberTrait { return x; } } + + + fn NaN() -> i128 { + IntegerTrait::NaN() + } + + fn is_nan(self: i128) -> bool { + IntegerTrait::is_nan(self) + } } impl u32Number of NumberTrait { @@ -2272,4 +2363,12 @@ impl u32Number of NumberTrait { return x; } } + + fn NaN() -> u32 { + 4242424242 + } + + fn is_nan(self: u32) -> bool { + self == 4242424242 + } } diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 5490fc0de..9daa862d2 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1102,5 +1102,6 @@ trait FixedTrait { fn ZERO() -> T; fn ONE() -> T; fn MAX() -> T; - // fn NaN() -> T; + fn NaN() -> T; + fn is_nan(self: T) -> bool; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index 10aed6e09..2ab47090f 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -182,6 +182,14 @@ impl FP16x16Impl of FixedTrait { fn sign(self: FP16x16) -> FP16x16 { return core::sign(self); } + + fn NaN() -> FP16x16 { + return FP16x16 { mag: 0, sign: true }; + } + + fn is_nan(self: FP16x16) -> bool { + self == FP16x16 { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index f04f4e690..98d45bda3 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -182,6 +182,14 @@ impl FP16x16WImpl of FixedTrait { fn sign(self: FP16x16W) -> FP16x16W { return core::sign(self); } + + fn NaN() -> FP16x16W { + return FP16x16W { mag: 0, sign: true }; + } + + fn is_nan(self: FP16x16W) -> bool { + self == FP16x16W { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index a84373883..f2ffe2012 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -173,6 +173,14 @@ impl FP32x32Impl of FixedTrait { fn sign(self: FP32x32) -> FP32x32 { panic(array!['not supported!']) } + + fn NaN() -> FP32x32 { + return FP32x32 { mag: 0, sign: true }; + } + + fn is_nan(self: FP32x32) -> bool { + self == FP32x32 { mag: 0, sign: true } + } } @@ -246,17 +254,17 @@ impl FP32x32TryIntoI8 of TryInto { } } -impl FP32x32PartialEq of PartialEq { - #[inline(always)] - fn eq(lhs: @FP32x32, rhs: @FP32x32) -> bool { - return fp32x32::core::eq(lhs, rhs); - } - - #[inline(always)] - fn ne(lhs: @FP32x32, rhs: @FP32x32) -> bool { - return fp32x32::core::ne(lhs, rhs); - } -} +// impl FP32x32PartialEq of PartialEq { +// #[inline(always)] +// fn eq(lhs: @FP32x32, rhs: @FP32x32) -> bool { +// return fp32x32::core::eq(lhs, rhs); +// } + +// #[inline(always)] +// fn ne(lhs: @FP32x32, rhs: @FP32x32) -> bool { +// return fp32x32::core::ne(lhs, rhs); +// } +// } impl FP32x32Add of Add { fn add(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index 706fe21a6..7d07211b8 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -171,6 +171,14 @@ impl FP64x64Impl of FixedTrait { fn sign(self: FP64x64) -> FP64x64 { panic(array!['not supported!']) } + + fn NaN() -> FP64x64 { + return FP64x64 { mag: 0, sign: true }; + } + + fn is_nan(self: FP64x64) -> bool { + self == FP64x64 { mag: 0, sign: true } + } } @@ -244,17 +252,17 @@ impl FP64x64TryIntoI8 of TryInto { } } -impl FP64x64PartialEq of PartialEq { - #[inline(always)] - fn eq(lhs: @FP64x64, rhs: @FP64x64) -> bool { - return fp64x64::core::eq(lhs, rhs); - } - - #[inline(always)] - fn ne(lhs: @FP64x64, rhs: @FP64x64) -> bool { - return fp64x64::core::ne(lhs, rhs); - } -} +// impl FP64x64PartialEq of PartialEq { +// #[inline(always)] +// fn eq(lhs: @FP64x64, rhs: @FP64x64) -> bool { +// return fp64x64::core::eq(lhs, rhs); +// } + +// #[inline(always)] +// fn ne(lhs: @FP64x64, rhs: @FP64x64) -> bool { +// return fp64x64::core::ne(lhs, rhs); +// } +// } impl FP64x64Add of Add { fn add(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 12ef49e24..b6cae31dd 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -182,6 +182,14 @@ impl FP8x23Impl of FixedTrait { fn sign(self: FP8x23) -> FP8x23 { return core::sign(self); } + + fn NaN() -> FP8x23 { + return FP8x23 { mag: 0, sign: true }; + } + + fn is_nan(self: FP8x23) -> bool { + self == FP8x23 { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 0243b56fc..76ebf6ed4 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -182,6 +182,14 @@ impl FP8x23WImpl of FixedTrait { fn sign(self: FP8x23W) -> FP8x23W { return core::sign(self); } + + fn NaN() -> FP8x23W { + return FP8x23W { mag: 0, sign: true }; + } + + fn is_nan(self: FP8x23W) -> bool { + self == FP8x23W { mag: 0, sign: true } + } } diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index 1c100ddc5..55d3a142d 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -37,6 +37,14 @@ impl i128Impl of IntegerTrait { fn sign(self: i128) -> i128 { i128_sign(self) } + + fn NaN() -> i128 { + return i128 { mag: 0, sign: true }; + } + + fn is_nan(self: i128) -> bool { + self == i128 { mag: 0, sign: true } + } } // Implements the Into trait for i128. diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index 5d6b04ffa..14f5269b9 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -37,6 +37,14 @@ impl i16Impl of IntegerTrait { fn sign(self: i16) -> i16 { i16_sign(self) } + + fn NaN() -> i16 { + return i16 { mag: 0, sign: true }; + } + + fn is_nan(self: i16) -> bool { + self == i16 { mag: 0, sign: true } + } } // Implements the Into trait for i16. diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index 0147ff0c3..b512d21a4 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -40,6 +40,14 @@ impl i32Impl of IntegerTrait { fn sign(self: i32) -> i32 { i32_sign(self) } + + fn NaN() -> i32 { + return i32 { mag: 0, sign: true }; + } + + fn is_nan(self: i32) -> bool { + self == i32 { mag: 0, sign: true } + } } // Implements the Into trait for i32. diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index 8bde7c0ee..d4f1853a3 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -37,6 +37,14 @@ impl i64Impl of IntegerTrait { fn sign(self: i64) -> i64 { i64_sign(self) } + + fn NaN() -> i64 { + return i64 { mag: 0, sign: true }; + } + + fn is_nan(self: i64) -> bool { + self == i64 { mag: 0, sign: true } + } } // Implements the Into trait for i64. diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 1acc60ecd..19f3eb918 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -43,6 +43,14 @@ impl i8Impl of IntegerTrait { fn sign(self: i8) -> i8 { i8_sign(self) } + + fn NaN() -> i8 { + return i8 { mag: 0, sign: true }; + } + + fn is_nan(self: i8) -> bool { + self == i8 { mag: 0, sign: true } + } } // Implements the Into trait for i8. diff --git a/src/numbers/signed_integer/integer_trait.cairo b/src/numbers/signed_integer/integer_trait.cairo index 85f7037d4..23aca9f8c 100644 --- a/src/numbers/signed_integer/integer_trait.cairo +++ b/src/numbers/signed_integer/integer_trait.cairo @@ -209,5 +209,8 @@ trait IntegerTrait { /// ``` /// fn sign(self: T) -> T; + + fn NaN() -> T; + fn is_nan(self: T) -> bool; } From ed2296966a78dcf78ec25c2110f0f8c6f0fc8e0f Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 11:56:59 +0200 Subject: [PATCH 014/127] implement TreeEnsembleImpl --- Scarb.toml | 2 +- src/operators/ml/tree_ensemble/core.cairo | 105 +++++++++++++++++----- src/utils.cairo | 12 +++ 3 files changed, 98 insertions(+), 21 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index 502513ba4..2b495e0bf 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -11,4 +11,4 @@ cubit = { git = "https://github.com/raphaelDkhn/cubit.git" } [scripts] sierra = "cairo-compile . -r" docgen = "cd docgen && cargo run" -nodegen = "python3 nodegen/node/__init__.py" \ No newline at end of file +nodegen = "python3 nodegen/node/__init__.py" diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 63f0306e5..ef33c5cbe 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -1,13 +1,17 @@ -use core::array::SpanTrait; -use core::dict::Felt252DictTrait; -use core::Felt252Dict; +use orion::numbers::NumberTrait; +use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::ArrayTraitExt; impl UsizeDictCopy of Copy>; impl UsizeDictDrop of Drop>; + #[derive(Copy, Drop)] struct TreeEnsembleAttributes { - nodes_modes: Span, // Change to modes + nodes_modes: Span, nodes_featureids: Span, nodes_missing_value_tracks_true: Span, nodes_values: Span, @@ -34,24 +38,85 @@ enum NODE_MODES { LEAF } +#[generate_trait] +impl TreeEnsembleImpl< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq +> of TreeEnsembleTrait { + fn leaf_index_tree(ref self: TreeEnsemble, x: Span, tree_id: usize) -> usize { + let mut index: usize = self.root_index.get(tree_id.into()); + + loop { + let x_value = *x.at(*(self.atts.nodes_missing_value_tracks_true).at(index)); + let r = if x_value.is_nan() { + *self.atts.nodes_missing_value_tracks_true.at(index) >= 1 + } else { + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => x_value <= *self.atts.nodes_values[index], + NODE_MODES::BRANCH_LT => x_value < *self.atts.nodes_values[index], + NODE_MODES::BRANCH_GTE => x_value >= *self.atts.nodes_values[index], + NODE_MODES::BRANCH_GT => x_value > *self.atts.nodes_values[index], + NODE_MODES::BRANCH_EQ => x_value == *self.atts.nodes_values[index], + NODE_MODES::BRANCH_NEQ => x_value != *self.atts.nodes_values[index], + NODE_MODES::LEAF => { + panic(array!['Unexpected rule for node index ', index.into()]) + }, + } + }; + + let nid = if r { + *self.atts.nodes_truenodeids[index] + } else { + *self.atts.nodes_falsenodeids[index] + }; + + // key of TreeEnsemble.node_index is pedersen hash of tree_id and nid. + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tree_id.into(), nid.into()); + + index = self.node_index.get(key); + + // Loop breaker + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => { continue; }, + NODE_MODES::BRANCH_LT => { continue; }, + NODE_MODES::BRANCH_GTE => { continue; }, + NODE_MODES::BRANCH_GT => { continue; }, + NODE_MODES::BRANCH_EQ => { continue; }, + NODE_MODES::BRANCH_NEQ => { continue; }, + NODE_MODES::LEAF => { break; }, + }; + }; + + index + } + fn leave_index_tree(ref self: TreeEnsemble, x: Tensor) -> Tensor { + let mut outputs = ArrayTrait::new(); + + let mut i: usize = 0; + let breaker: usize = *x.shape[0]; + loop { + if i == breaker { + break; + } -fn leaf_index_tree, +Copy>( - ref ensemble: TreeEnsemble, x: Span, tree_id: usize -) -> usize { - let mut index = ensemble.root_index.get(tree_id.into()); - - loop { - match *ensemble.atts.nodes_modes.at(index) { - NODE_MODES::BRANCH_LEQ => { continue; }, - NODE_MODES::BRANCH_LT => { continue; }, - NODE_MODES::BRANCH_GTE => { continue; }, - NODE_MODES::BRANCH_GT => { continue; }, - NODE_MODES::BRANCH_EQ => { continue; }, - NODE_MODES::BRANCH_NEQ => { continue; }, - NODE_MODES::LEAF => { break; }, + let row_data: Span = get_row(x, i); + let mut outs = ArrayTrait::new(); + let mut tree_ids = self.tree_ids; + loop { + match tree_ids.pop_front() { + Option::Some(tree_id) => { + outs + .append( + TreeEnsembleImpl::::leaf_index_tree(ref self, row_data, *tree_id) + ) + }, + Option::None(_) => { break; } + }; + }; + outputs.append_all(ref outs); }; - }; - 1 + TensorTrait::new(array![*x.shape[0], self.tree_ids.len()].span(), outputs.span()) + } } diff --git a/src/utils.cairo b/src/utils.cairo index b8062f733..dc2c35b0b 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -3,6 +3,8 @@ use option::OptionTrait; use array::ArrayTrait; use array::SpanTrait; +use orion::operators::tensor::{Tensor, TensorTrait}; + fn u32_max(a: u32, b: u32) -> u32 { if a > b { a @@ -28,3 +30,13 @@ fn assert_eq, impl TCopy: Copy, impl TDrop: ) { assert(lhs == rhs, 'should be equal'); } + +fn get_row, +Copy>(self: Tensor, row: usize) -> Span { + assert(self.shape.len() == 2, 'Expected a 2D tensor'); + + let row_length = *self.shape[1]; + let start = row * row_length; + let end = start + row_length; + + self.data.slice(start, end) +} From b3805308c729da92209b9ddb67b5a84f662a6cae Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 12:03:16 +0200 Subject: [PATCH 015/127] add missing loop incrementer --- src/operators/ml/tree_ensemble/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index ef33c5cbe..c07b31bba 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -114,6 +114,7 @@ impl TreeEnsembleImpl< }; }; outputs.append_all(ref outs); + i += 1; }; TensorTrait::new(array![*x.shape[0], self.tree_ids.len()].span(), outputs.span()) From 8783d5f72a8b2cccc1e2457c558ba523216a5351 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 12:05:00 +0200 Subject: [PATCH 016/127] Update core.cairo --- src/operators/ml/tree_ensemble/core.cairo | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index c07b31bba..31508ab55 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -46,6 +46,17 @@ impl TreeEnsembleImpl< let mut index: usize = self.root_index.get(tree_id.into()); loop { + // Loop breaker + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => {}, + NODE_MODES::BRANCH_LT => {}, + NODE_MODES::BRANCH_GTE => {}, + NODE_MODES::BRANCH_GT => {}, + NODE_MODES::BRANCH_EQ => {}, + NODE_MODES::BRANCH_NEQ => {}, + NODE_MODES::LEAF => { break; }, + }; + let x_value = *x.at(*(self.atts.nodes_missing_value_tracks_true).at(index)); let r = if x_value.is_nan() { *self.atts.nodes_missing_value_tracks_true.at(index) >= 1 @@ -74,17 +85,6 @@ impl TreeEnsembleImpl< let key: felt252 = key.hash(tree_id.into(), nid.into()); index = self.node_index.get(key); - - // Loop breaker - match *self.atts.nodes_modes.at(index) { - NODE_MODES::BRANCH_LEQ => { continue; }, - NODE_MODES::BRANCH_LT => { continue; }, - NODE_MODES::BRANCH_GTE => { continue; }, - NODE_MODES::BRANCH_GT => { continue; }, - NODE_MODES::BRANCH_EQ => { continue; }, - NODE_MODES::BRANCH_NEQ => { continue; }, - NODE_MODES::LEAF => { break; }, - }; }; index From 21b77d1b227cfc37bfda4ee7d904f22618dd7b59 Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Wed, 1 Nov 2023 16:58:01 +0300 Subject: [PATCH 017/127] feat: bitwise_and operation added --- src/operators/tensor/core.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 2 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- src/operators/tensor/math/bitwise_and.cairo | 51 +++++++++++++++++++ 11 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 src/operators/tensor/math/bitwise_and.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index ba2ae157d..a91ad0dfc 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -2937,7 +2937,7 @@ trait TensorTrait { /// >>> [0,1,1,0,1,1,0,1,1] /// ``` /// - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index fad9cbd0a..0bc8d1ff5 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -246,7 +246,7 @@ impl FP16x16Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 8d4607b7b..55f644100 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -256,7 +256,7 @@ impl FP16x16WTensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index aa98a823e..83686033c 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -247,7 +247,7 @@ impl FP32x32Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 5933bd659..c05ab7fa2 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -247,7 +247,7 @@ impl FP64x64Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index a1797c761..1b7659eae 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -246,7 +246,7 @@ impl FP8x23Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 2432be167..3a6228250 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -246,7 +246,7 @@ impl FP8x23WTensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 7058e2783..fa74cc38d 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -245,7 +245,7 @@ impl I32Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 1f7a3d2e6..d06d5bec7 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -244,7 +244,7 @@ impl I8Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index e5a33b0d6..36e313f4b 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -238,7 +238,7 @@ impl U32Tensor of TensorTrait { math::where::where(self, x, y) } - fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } } diff --git a/src/operators/tensor/math/bitwise_and.cairo b/src/operators/tensor/math/bitwise_and.cairo new file mode 100644 index 000000000..6dd3f88ba --- /dev/null +++ b/src/operators/tensor/math/bitwise_and.cairo @@ -0,0 +1,51 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::helpers::{ + broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility +}; + +/// Cf: TensorTrait::and docstring +fn bitwise_and< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + y: @Tensor, z: @Tensor +) -> Tensor { + 'check_compatibility'.print(); + let broadcasted_shape = broadcast_shape(*y.shape, *z.shape); + let mut result: Array = ArrayTrait::::new(); + + let num_elements = len_from_shape(broadcasted_shape); + 'checked'.print(); + + let mut n: usize = 0; + loop { + let indices_broadcasted = unravel_index(n, broadcasted_shape); + + let indices_self = broadcast_index_mapping(*y.shape, indices_broadcasted); + let indices_other = broadcast_index_mapping(*z.shape, indices_broadcasted); + + let lhs = *(*y.data)[indices_self]; + let rhs = *(*z.data)[indices_other]; + + result.append(NumberTrait::bitwise_and(lhs, rhs)); + // let res = *(*y.data).at(n) ^ *(*z.data).at(n) + // result.append(res); + + n += 1; + if n == num_elements { + break (); + }; + }; + + return TensorTrait::::new(broadcasted_shape, result.span()); +} \ No newline at end of file From e4932b0d87efc5f4c6d78a28b8e9c2e7ada50bb7 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Thu, 2 Nov 2023 04:06:55 +0100 Subject: [PATCH 018/127] not ongoing --- src/operators/tensor/math/not.cairo | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/operators/tensor/math/not.cairo diff --git a/src/operators/tensor/math/not.cairo b/src/operators/tensor/math/not.cairo new file mode 100644 index 000000000..a727de4e5 --- /dev/null +++ b/src/operators/tensor/math/not.cairo @@ -0,0 +1,35 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; + + +// Cf TensorTrait::not docstring + +fn not < + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +> (mut z: Tensor) -> Tensor { + let mut data_result = ArrayTrait::::new(); + + loop { + match z.data.pop_front() { + Option::Some(item) => { + data_result.append(!*item); + + }, + Option::None(_) => { + break; + } + }; + }; + + return TensorTrait::new(z.shape, data_result.span()); +} \ No newline at end of file From 3e186315ae70b81923a55f9b82d0e0f7164580c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Thu, 2 Nov 2023 10:11:13 +0000 Subject: [PATCH 019/127] feat: bitwise_and tests for fp reoresentation --- .../implementations/fp16x16/math/comp.cairo | 11 ++++++++++- .../implementations/fp16x16wide/math/comp.cairo | 11 ++++++++++- .../implementations/fp8x23/math/comp.cairo | 10 +++++++++- .../implementations/fp8x23wide/math/comp.cairo | 10 +++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 45275b9fd..59067e17d 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -60,7 +60,7 @@ fn bitwise_and(a: FP16x16, b: FP16x16) -> FP16x16 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min}; + use super::{FixedTrait, max, min, bitwise_and}; #[test] @@ -100,4 +100,13 @@ mod tests { assert(min(c, b) == c, 'min(c, b)'); assert(min(c, c) == c, 'min(c, c)'); } + + #[test] + fn test_bitwise_and() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(94208, false); // 1.4375 + + assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index ae0d41432..04e9fe3d4 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -60,7 +60,7 @@ fn bitwise_and(a: FP16x16W, b: FP16x16W) -> FP16x16W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min}; + use super::{FixedTrait, max, min, bitwise_and}; #[test] @@ -100,4 +100,13 @@ mod tests { assert(min(c, b) == c, 'min(c, b)'); assert(min(c, c) == c, 'min(c, c)'); } + + #[test] + fn test_bitwise_and() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(94208, false); // 1.4375 + + assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index 1ad7b6012..5ca6233f4 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -60,7 +60,7 @@ fn bitwise_and(a: FP8x23, b: FP8x23) -> FP8x23 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min}; + use super::{FixedTrait, max, min, bitwise_and}; #[test] fn test_max() { @@ -99,4 +99,12 @@ mod tests { assert(min(c, b) == c, 'min(c, b)'); assert(min(c, c) == c, 'min(c, c)'); } + #[test] + fn test_bitwise_and() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + + assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') + } + } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index 197b6b1a7..3c583f60c 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -60,7 +60,7 @@ fn bitwise_and(a: FP8x23W, b: FP8x23W) -> FP8x23W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min}; + use super::{FixedTrait, max, min, bitwise_and}; #[test] @@ -100,4 +100,12 @@ mod tests { assert(min(c, b) == c, 'min(c, b)'); assert(min(c, c) == c, 'min(c, c)'); } + + #[test] + fn test_bitwise_and() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + + assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') + } } From 8fea9521c9fba2b557b3d689306e6443fbc1f5c1 Mon Sep 17 00:00:00 2001 From: 0x73e <132935850+0x73e@users.noreply.github.com> Date: Thu, 2 Nov 2023 20:57:28 -0400 Subject: [PATCH 020/127] feat trilu --- docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + docs/framework/operators/tensor/tensor.min.md | 2 +- .../operators/tensor/tensor.trilu.md | 39 + .../operators/tensor/tensor.where.md | 2 +- nodegen/helpers.py | 14 +- nodegen/node/trilu.py | 1249 +++++++++++++++++ src/operators/tensor/core.cairo | 44 +- .../implementations/tensor_fp16x16.cairo | 3 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 6 +- .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 7 +- .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 6 +- .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/linalg.cairo | 1 + src/operators/tensor/linalg/trilu.cairo | 77 + src/operators/tensor/math.cairo | 2 +- src/operators/tensor/math/max.cairo | 11 +- src/operators/tensor/math/min.cairo | 11 +- src/operators/tensor/math/min_in_tensor.cairo | 4 +- tests/nodes.cairo | 207 ++- .../max_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp16x16_three_tensors.cairo | 10 +- .../max_fp16x16_three_tensors/input_0.cairo | 2 +- .../max_fp16x16_three_tensors/input_1.cairo | 2 +- .../max_fp16x16_three_tensors/input_2.cairo | 2 +- .../max_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp16x16_two_tensors.cairo | 8 +- .../max_fp16x16_two_tensors/input_0.cairo | 2 +- .../max_fp16x16_two_tensors/input_1.cairo | 2 +- .../max_fp16x16_two_tensors/output_0.cairo | 2 +- .../max_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp8x23_three_tensors.cairo | 10 +- .../max_fp8x23_three_tensors/input_0.cairo | 2 +- .../max_fp8x23_three_tensors/input_1.cairo | 2 +- .../max_fp8x23_three_tensors/input_2.cairo | 2 +- .../max_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp8x23_two_tensors.cairo | 8 +- .../max_fp8x23_two_tensors/input_0.cairo | 2 +- .../max_fp8x23_two_tensors/input_1.cairo | 2 +- .../max_fp8x23_two_tensors/output_0.cairo | 2 +- .../max_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i32_three_tensors.cairo | 10 +- .../nodes/max_i32_three_tensors/input_0.cairo | 2 +- .../nodes/max_i32_three_tensors/input_1.cairo | 2 +- .../nodes/max_i32_three_tensors/input_2.cairo | 2 +- .../max_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i32_two_tensors.cairo | 8 +- tests/nodes/max_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i32_two_tensors/input_1.cairo | 2 +- .../nodes/max_i32_two_tensors/output_0.cairo | 2 +- .../max_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i8_three_tensors.cairo | 10 +- .../nodes/max_i8_three_tensors/input_0.cairo | 2 +- .../nodes/max_i8_three_tensors/input_1.cairo | 2 +- .../nodes/max_i8_three_tensors/input_2.cairo | 2 +- .../nodes/max_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i8_two_tensors.cairo | 8 +- tests/nodes/max_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/max_i8_two_tensors/output_0.cairo | 2 +- .../max_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_u32_three_tensors.cairo | 10 +- .../nodes/max_u32_three_tensors/input_0.cairo | 2 +- .../nodes/max_u32_three_tensors/input_1.cairo | 2 +- .../nodes/max_u32_three_tensors/input_2.cairo | 2 +- .../max_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_u32_two_tensors.cairo | 8 +- tests/nodes/max_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_u32_two_tensors/input_1.cairo | 2 +- .../nodes/max_u32_two_tensors/output_0.cairo | 2 +- .../min_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp16x16_three_tensors.cairo | 10 +- .../min_fp16x16_three_tensors/input_0.cairo | 2 +- .../min_fp16x16_three_tensors/input_1.cairo | 2 +- .../min_fp16x16_three_tensors/input_2.cairo | 2 +- .../min_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp16x16_two_tensors.cairo | 8 +- .../min_fp16x16_two_tensors/input_0.cairo | 2 +- .../min_fp16x16_two_tensors/input_1.cairo | 2 +- .../min_fp16x16_two_tensors/output_0.cairo | 2 +- .../min_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp8x23_three_tensors.cairo | 10 +- .../min_fp8x23_three_tensors/input_0.cairo | 2 +- .../min_fp8x23_three_tensors/input_1.cairo | 2 +- .../min_fp8x23_three_tensors/input_2.cairo | 2 +- .../min_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp8x23_two_tensors.cairo | 8 +- .../min_fp8x23_two_tensors/input_0.cairo | 2 +- .../min_fp8x23_two_tensors/input_1.cairo | 2 +- .../min_fp8x23_two_tensors/output_0.cairo | 2 +- .../min_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i32_three_tensors.cairo | 10 +- .../nodes/min_i32_three_tensors/input_0.cairo | 2 +- .../nodes/min_i32_three_tensors/input_1.cairo | 2 +- .../nodes/min_i32_three_tensors/input_2.cairo | 2 +- .../min_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i32_two_tensors.cairo | 8 +- tests/nodes/min_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i32_two_tensors/input_1.cairo | 2 +- .../nodes/min_i32_two_tensors/output_0.cairo | 2 +- .../min_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i8_three_tensors.cairo | 10 +- .../nodes/min_i8_three_tensors/input_0.cairo | 2 +- .../nodes/min_i8_three_tensors/input_1.cairo | 2 +- .../nodes/min_i8_three_tensors/input_2.cairo | 2 +- .../nodes/min_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i8_two_tensors.cairo | 8 +- tests/nodes/min_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/min_i8_two_tensors/output_0.cairo | 2 +- .../min_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_u32_three_tensors.cairo | 10 +- .../nodes/min_u32_three_tensors/input_0.cairo | 2 +- .../nodes/min_u32_three_tensors/input_1.cairo | 2 +- .../nodes/min_u32_three_tensors/input_2.cairo | 2 +- .../min_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_u32_two_tensors.cairo | 8 +- tests/nodes/min_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_u32_two_tensors/input_1.cairo | 2 +- .../nodes/min_u32_two_tensors/output_0.cairo | 2 +- tests/nodes/round_fp16x16.cairo | 6 +- tests/nodes/round_fp16x16/input_0.cairo | 2 +- tests/nodes/round_fp16x16/output_0.cairo | 2 +- tests/nodes/round_fp8x23.cairo | 6 +- tests/nodes/round_fp8x23/input_0.cairo | 2 +- tests/nodes/round_fp8x23/output_0.cairo | 2 +- tests/nodes/tril_fp16x16.cairo | 20 + tests/nodes/tril_fp16x16/input_0.cairo | 34 + tests/nodes/tril_fp16x16/output_0.cairo | 34 + tests/nodes/tril_fp16x16_neg.cairo | 20 + tests/nodes/tril_fp16x16_neg/input_0.cairo | 34 + tests/nodes/tril_fp16x16_neg/output_0.cairo | 34 + tests/nodes/tril_fp16x16_one_row.cairo | 20 + .../nodes/tril_fp16x16_one_row/input_0.cairo | 30 + .../nodes/tril_fp16x16_one_row/output_0.cairo | 30 + tests/nodes/tril_fp16x16_out_neg.cairo | 20 + .../nodes/tril_fp16x16_out_neg/input_0.cairo | 34 + .../nodes/tril_fp16x16_out_neg/output_0.cairo | 34 + tests/nodes/tril_fp16x16_out_pos.cairo | 20 + .../nodes/tril_fp16x16_out_pos/input_0.cairo | 34 + .../nodes/tril_fp16x16_out_pos/output_0.cairo | 34 + tests/nodes/tril_fp16x16_pos.cairo | 20 + tests/nodes/tril_fp16x16_pos/input_0.cairo | 34 + tests/nodes/tril_fp16x16_pos/output_0.cairo | 34 + tests/nodes/tril_fp16x16_square.cairo | 20 + tests/nodes/tril_fp16x16_square/input_0.cairo | 33 + .../nodes/tril_fp16x16_square/output_0.cairo | 33 + tests/nodes/tril_fp16x16_square_neg.cairo | 20 + .../tril_fp16x16_square_neg/input_0.cairo | 33 + .../tril_fp16x16_square_neg/output_0.cairo | 33 + tests/nodes/tril_fp16x16_zero.cairo | 20 + tests/nodes/tril_fp16x16_zero/input_0.cairo | 15 + tests/nodes/tril_fp16x16_zero/output_0.cairo | 15 + tests/nodes/tril_fp8x23.cairo | 20 + tests/nodes/tril_fp8x23/input_0.cairo | 34 + tests/nodes/tril_fp8x23/output_0.cairo | 34 + tests/nodes/tril_fp8x23_neg.cairo | 20 + tests/nodes/tril_fp8x23_neg/input_0.cairo | 34 + tests/nodes/tril_fp8x23_neg/output_0.cairo | 34 + tests/nodes/tril_fp8x23_one_row.cairo | 20 + tests/nodes/tril_fp8x23_one_row/input_0.cairo | 30 + .../nodes/tril_fp8x23_one_row/output_0.cairo | 30 + tests/nodes/tril_fp8x23_out_neg.cairo | 20 + tests/nodes/tril_fp8x23_out_neg/input_0.cairo | 34 + .../nodes/tril_fp8x23_out_neg/output_0.cairo | 34 + tests/nodes/tril_fp8x23_out_pos.cairo | 20 + tests/nodes/tril_fp8x23_out_pos/input_0.cairo | 34 + .../nodes/tril_fp8x23_out_pos/output_0.cairo | 34 + tests/nodes/tril_fp8x23_pos.cairo | 20 + tests/nodes/tril_fp8x23_pos/input_0.cairo | 34 + tests/nodes/tril_fp8x23_pos/output_0.cairo | 34 + tests/nodes/tril_fp8x23_square.cairo | 20 + tests/nodes/tril_fp8x23_square/input_0.cairo | 33 + tests/nodes/tril_fp8x23_square/output_0.cairo | 33 + tests/nodes/tril_fp8x23_square_neg.cairo | 20 + .../tril_fp8x23_square_neg/input_0.cairo | 33 + .../tril_fp8x23_square_neg/output_0.cairo | 33 + tests/nodes/tril_fp8x23_zero.cairo | 20 + tests/nodes/tril_fp8x23_zero/input_0.cairo | 15 + tests/nodes/tril_fp8x23_zero/output_0.cairo | 15 + tests/nodes/tril_i32.cairo | 20 + tests/nodes/tril_i32/input_0.cairo | 33 + tests/nodes/tril_i32/output_0.cairo | 33 + tests/nodes/tril_i32_one_row.cairo | 20 + tests/nodes/tril_i32_one_row/input_0.cairo | 29 + tests/nodes/tril_i32_one_row/output_0.cairo | 29 + tests/nodes/tril_i32_out_neg.cairo | 20 + tests/nodes/tril_i32_out_neg/input_0.cairo | 33 + tests/nodes/tril_i32_out_neg/output_0.cairo | 33 + tests/nodes/tril_i32_out_pos.cairo | 20 + tests/nodes/tril_i32_out_pos/input_0.cairo | 33 + tests/nodes/tril_i32_out_pos/output_0.cairo | 33 + tests/nodes/tril_i32_pos.cairo | 20 + tests/nodes/tril_i32_pos/input_0.cairo | 33 + tests/nodes/tril_i32_pos/output_0.cairo | 33 + tests/nodes/tril_i32_square.cairo | 20 + tests/nodes/tril_i32_square/input_0.cairo | 32 + tests/nodes/tril_i32_square/output_0.cairo | 32 + tests/nodes/tril_i32_square_neg.cairo | 20 + tests/nodes/tril_i32_square_neg/input_0.cairo | 32 + .../nodes/tril_i32_square_neg/output_0.cairo | 32 + tests/nodes/tril_i32_zero.cairo | 20 + tests/nodes/tril_i32_zero/input_0.cairo | 14 + tests/nodes/tril_i32_zero/output_0.cairo | 14 + tests/nodes/tril_i8.cairo | 20 + tests/nodes/tril_i8/input_0.cairo | 33 + tests/nodes/tril_i8/output_0.cairo | 33 + tests/nodes/tril_i8_neg.cairo | 20 + tests/nodes/tril_i8_neg/input_0.cairo | 33 + tests/nodes/tril_i8_neg/output_0.cairo | 33 + tests/nodes/tril_i8_one_row.cairo | 20 + tests/nodes/tril_i8_one_row/input_0.cairo | 29 + tests/nodes/tril_i8_one_row/output_0.cairo | 29 + tests/nodes/tril_i8_out_neg.cairo | 20 + tests/nodes/tril_i8_out_neg/input_0.cairo | 33 + tests/nodes/tril_i8_out_neg/output_0.cairo | 33 + tests/nodes/tril_i8_out_pos.cairo | 20 + tests/nodes/tril_i8_out_pos/input_0.cairo | 33 + tests/nodes/tril_i8_out_pos/output_0.cairo | 33 + tests/nodes/tril_i8_pos.cairo | 20 + tests/nodes/tril_i8_pos/input_0.cairo | 33 + tests/nodes/tril_i8_pos/output_0.cairo | 33 + tests/nodes/tril_i8_square.cairo | 20 + tests/nodes/tril_i8_square/input_0.cairo | 32 + tests/nodes/tril_i8_square/output_0.cairo | 32 + tests/nodes/tril_i8_square_neg.cairo | 20 + tests/nodes/tril_i8_square_neg/input_0.cairo | 32 + tests/nodes/tril_i8_square_neg/output_0.cairo | 32 + tests/nodes/tril_i8_zero.cairo | 20 + tests/nodes/tril_i8_zero/input_0.cairo | 14 + tests/nodes/tril_i8_zero/output_0.cairo | 14 + tests/nodes/tril_neg_i32.cairo | 20 + tests/nodes/tril_neg_i32/input_0.cairo | 33 + tests/nodes/tril_neg_i32/output_0.cairo | 33 + tests/nodes/tril_u32.cairo | 20 + tests/nodes/tril_u32/input_0.cairo | 32 + tests/nodes/tril_u32/output_0.cairo | 32 + tests/nodes/tril_u32_neg.cairo | 20 + tests/nodes/tril_u32_neg/input_0.cairo | 32 + tests/nodes/tril_u32_neg/output_0.cairo | 32 + tests/nodes/tril_u32_one_row.cairo | 20 + tests/nodes/tril_u32_one_row/input_0.cairo | 28 + tests/nodes/tril_u32_one_row/output_0.cairo | 28 + tests/nodes/tril_u32_out_neg.cairo | 20 + tests/nodes/tril_u32_out_neg/input_0.cairo | 32 + tests/nodes/tril_u32_out_neg/output_0.cairo | 32 + tests/nodes/tril_u32_out_pos.cairo | 20 + tests/nodes/tril_u32_out_pos/input_0.cairo | 32 + tests/nodes/tril_u32_out_pos/output_0.cairo | 32 + tests/nodes/tril_u32_pos.cairo | 20 + tests/nodes/tril_u32_pos/input_0.cairo | 32 + tests/nodes/tril_u32_pos/output_0.cairo | 32 + tests/nodes/tril_u32_square.cairo | 20 + tests/nodes/tril_u32_square/input_0.cairo | 31 + tests/nodes/tril_u32_square/output_0.cairo | 31 + tests/nodes/tril_u32_square_neg.cairo | 20 + tests/nodes/tril_u32_square_neg/input_0.cairo | 31 + .../nodes/tril_u32_square_neg/output_0.cairo | 31 + tests/nodes/tril_u32_zero.cairo | 20 + tests/nodes/tril_u32_zero/input_0.cairo | 13 + tests/nodes/tril_u32_zero/output_0.cairo | 13 + tests/nodes/triu_fp16x16.cairo | 20 + tests/nodes/triu_fp16x16/input_0.cairo | 34 + tests/nodes/triu_fp16x16/output_0.cairo | 34 + tests/nodes/triu_fp16x16_neg.cairo | 20 + tests/nodes/triu_fp16x16_neg/input_0.cairo | 34 + tests/nodes/triu_fp16x16_neg/output_0.cairo | 34 + tests/nodes/triu_fp16x16_one_row.cairo | 20 + .../nodes/triu_fp16x16_one_row/input_0.cairo | 30 + .../nodes/triu_fp16x16_one_row/output_0.cairo | 30 + tests/nodes/triu_fp16x16_out_neg.cairo | 20 + .../nodes/triu_fp16x16_out_neg/input_0.cairo | 34 + .../nodes/triu_fp16x16_out_neg/output_0.cairo | 34 + tests/nodes/triu_fp16x16_out_pos.cairo | 20 + .../nodes/triu_fp16x16_out_pos/input_0.cairo | 34 + .../nodes/triu_fp16x16_out_pos/output_0.cairo | 34 + tests/nodes/triu_fp16x16_pos.cairo | 20 + tests/nodes/triu_fp16x16_pos/input_0.cairo | 34 + tests/nodes/triu_fp16x16_pos/output_0.cairo | 34 + tests/nodes/triu_fp16x16_square.cairo | 20 + tests/nodes/triu_fp16x16_square/input_0.cairo | 33 + .../nodes/triu_fp16x16_square/output_0.cairo | 33 + tests/nodes/triu_fp16x16_square_neg.cairo | 20 + .../triu_fp16x16_square_neg/input_0.cairo | 33 + .../triu_fp16x16_square_neg/output_0.cairo | 33 + tests/nodes/triu_fp16x16_zero.cairo | 20 + tests/nodes/triu_fp16x16_zero/input_0.cairo | 15 + tests/nodes/triu_fp16x16_zero/output_0.cairo | 15 + tests/nodes/triu_fp8x23.cairo | 20 + tests/nodes/triu_fp8x23/input_0.cairo | 34 + tests/nodes/triu_fp8x23/output_0.cairo | 34 + tests/nodes/triu_fp8x23_neg.cairo | 20 + tests/nodes/triu_fp8x23_neg/input_0.cairo | 34 + tests/nodes/triu_fp8x23_neg/output_0.cairo | 34 + tests/nodes/triu_fp8x23_one_row.cairo | 20 + tests/nodes/triu_fp8x23_one_row/input_0.cairo | 30 + .../nodes/triu_fp8x23_one_row/output_0.cairo | 30 + tests/nodes/triu_fp8x23_out_neg.cairo | 20 + tests/nodes/triu_fp8x23_out_neg/input_0.cairo | 34 + .../nodes/triu_fp8x23_out_neg/output_0.cairo | 34 + tests/nodes/triu_fp8x23_out_pos.cairo | 20 + tests/nodes/triu_fp8x23_out_pos/input_0.cairo | 34 + .../nodes/triu_fp8x23_out_pos/output_0.cairo | 34 + tests/nodes/triu_fp8x23_pos.cairo | 20 + tests/nodes/triu_fp8x23_pos/input_0.cairo | 34 + tests/nodes/triu_fp8x23_pos/output_0.cairo | 34 + tests/nodes/triu_fp8x23_square.cairo | 20 + tests/nodes/triu_fp8x23_square/input_0.cairo | 33 + tests/nodes/triu_fp8x23_square/output_0.cairo | 33 + tests/nodes/triu_fp8x23_square_neg.cairo | 20 + .../triu_fp8x23_square_neg/input_0.cairo | 33 + .../triu_fp8x23_square_neg/output_0.cairo | 33 + tests/nodes/triu_fp8x23_zero.cairo | 20 + tests/nodes/triu_fp8x23_zero/input_0.cairo | 15 + tests/nodes/triu_fp8x23_zero/output_0.cairo | 15 + tests/nodes/triu_i32.cairo | 20 + tests/nodes/triu_i32/input_0.cairo | 33 + tests/nodes/triu_i32/output_0.cairo | 33 + tests/nodes/triu_i32_neg.cairo | 20 + tests/nodes/triu_i32_neg/input_0.cairo | 33 + tests/nodes/triu_i32_neg/output_0.cairo | 33 + tests/nodes/triu_i32_one_row.cairo | 20 + tests/nodes/triu_i32_one_row/input_0.cairo | 29 + tests/nodes/triu_i32_one_row/output_0.cairo | 29 + tests/nodes/triu_i32_out_neg.cairo | 20 + tests/nodes/triu_i32_out_neg/input_0.cairo | 33 + tests/nodes/triu_i32_out_neg/output_0.cairo | 33 + tests/nodes/triu_i32_out_pos.cairo | 20 + tests/nodes/triu_i32_out_pos/input_0.cairo | 33 + tests/nodes/triu_i32_out_pos/output_0.cairo | 33 + tests/nodes/triu_i32_pos.cairo | 20 + tests/nodes/triu_i32_pos/input_0.cairo | 33 + tests/nodes/triu_i32_pos/output_0.cairo | 33 + tests/nodes/triu_i32_square.cairo | 20 + tests/nodes/triu_i32_square/input_0.cairo | 32 + tests/nodes/triu_i32_square/output_0.cairo | 32 + tests/nodes/triu_i32_square_neg.cairo | 20 + tests/nodes/triu_i32_square_neg/input_0.cairo | 32 + .../nodes/triu_i32_square_neg/output_0.cairo | 32 + tests/nodes/triu_i32_zero.cairo | 20 + tests/nodes/triu_i32_zero/input_0.cairo | 14 + tests/nodes/triu_i32_zero/output_0.cairo | 14 + tests/nodes/triu_i8.cairo | 20 + tests/nodes/triu_i8/input_0.cairo | 33 + tests/nodes/triu_i8/output_0.cairo | 33 + tests/nodes/triu_i8_neg.cairo | 20 + tests/nodes/triu_i8_neg/input_0.cairo | 33 + tests/nodes/triu_i8_neg/output_0.cairo | 33 + tests/nodes/triu_i8_one_row.cairo | 20 + tests/nodes/triu_i8_one_row/input_0.cairo | 29 + tests/nodes/triu_i8_one_row/output_0.cairo | 29 + tests/nodes/triu_i8_out_neg.cairo | 20 + tests/nodes/triu_i8_out_neg/input_0.cairo | 33 + tests/nodes/triu_i8_out_neg/output_0.cairo | 33 + tests/nodes/triu_i8_out_pos.cairo | 20 + tests/nodes/triu_i8_out_pos/input_0.cairo | 33 + tests/nodes/triu_i8_out_pos/output_0.cairo | 33 + tests/nodes/triu_i8_pos.cairo | 20 + tests/nodes/triu_i8_pos/input_0.cairo | 33 + tests/nodes/triu_i8_pos/output_0.cairo | 33 + tests/nodes/triu_i8_square.cairo | 20 + tests/nodes/triu_i8_square/input_0.cairo | 32 + tests/nodes/triu_i8_square/output_0.cairo | 32 + tests/nodes/triu_i8_square_neg.cairo | 20 + tests/nodes/triu_i8_square_neg/input_0.cairo | 32 + tests/nodes/triu_i8_square_neg/output_0.cairo | 32 + tests/nodes/triu_i8_zero.cairo | 20 + tests/nodes/triu_i8_zero/input_0.cairo | 14 + tests/nodes/triu_i8_zero/output_0.cairo | 14 + tests/nodes/triu_u32.cairo | 20 + tests/nodes/triu_u32/input_0.cairo | 32 + tests/nodes/triu_u32/output_0.cairo | 32 + tests/nodes/triu_u32_neg.cairo | 20 + tests/nodes/triu_u32_neg/input_0.cairo | 32 + tests/nodes/triu_u32_neg/output_0.cairo | 32 + tests/nodes/triu_u32_one_row.cairo | 20 + tests/nodes/triu_u32_one_row/input_0.cairo | 28 + tests/nodes/triu_u32_one_row/output_0.cairo | 28 + tests/nodes/triu_u32_out_neg.cairo | 20 + tests/nodes/triu_u32_out_neg/input_0.cairo | 32 + tests/nodes/triu_u32_out_neg/output_0.cairo | 32 + tests/nodes/triu_u32_out_pos.cairo | 20 + tests/nodes/triu_u32_out_pos/input_0.cairo | 32 + tests/nodes/triu_u32_out_pos/output_0.cairo | 32 + tests/nodes/triu_u32_pos.cairo | 20 + tests/nodes/triu_u32_pos/input_0.cairo | 32 + tests/nodes/triu_u32_pos/output_0.cairo | 32 + tests/nodes/triu_u32_square.cairo | 20 + tests/nodes/triu_u32_square/input_0.cairo | 31 + tests/nodes/triu_u32_square/output_0.cairo | 31 + tests/nodes/triu_u32_square_neg.cairo | 20 + tests/nodes/triu_u32_square_neg/input_0.cairo | 31 + .../nodes/triu_u32_square_neg/output_0.cairo | 31 + tests/nodes/triu_u32_zero.cairo | 20 + tests/nodes/triu_u32_zero/input_0.cairo | 13 + tests/nodes/triu_u32_zero/output_0.cairo | 13 + 480 files changed, 9229 insertions(+), 414 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.trilu.md create mode 100644 nodegen/node/trilu.py create mode 100644 src/operators/tensor/linalg/trilu.cairo create mode 100644 tests/nodes/tril_fp16x16.cairo create mode 100644 tests/nodes/tril_fp16x16/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_neg.cairo create mode 100644 tests/nodes/tril_fp16x16_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_one_row.cairo create mode 100644 tests/nodes/tril_fp16x16_one_row/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_one_row/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_out_neg.cairo create mode 100644 tests/nodes/tril_fp16x16_out_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_out_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_out_pos.cairo create mode 100644 tests/nodes/tril_fp16x16_out_pos/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_out_pos/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_pos.cairo create mode 100644 tests/nodes/tril_fp16x16_pos/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_pos/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_square.cairo create mode 100644 tests/nodes/tril_fp16x16_square/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_square/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_square_neg.cairo create mode 100644 tests/nodes/tril_fp16x16_square_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_square_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp16x16_zero.cairo create mode 100644 tests/nodes/tril_fp16x16_zero/input_0.cairo create mode 100644 tests/nodes/tril_fp16x16_zero/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23.cairo create mode 100644 tests/nodes/tril_fp8x23/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_neg.cairo create mode 100644 tests/nodes/tril_fp8x23_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_one_row.cairo create mode 100644 tests/nodes/tril_fp8x23_one_row/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_one_row/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_out_neg.cairo create mode 100644 tests/nodes/tril_fp8x23_out_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_out_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_out_pos.cairo create mode 100644 tests/nodes/tril_fp8x23_out_pos/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_out_pos/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_pos.cairo create mode 100644 tests/nodes/tril_fp8x23_pos/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_pos/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_square.cairo create mode 100644 tests/nodes/tril_fp8x23_square/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_square/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_square_neg.cairo create mode 100644 tests/nodes/tril_fp8x23_square_neg/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_square_neg/output_0.cairo create mode 100644 tests/nodes/tril_fp8x23_zero.cairo create mode 100644 tests/nodes/tril_fp8x23_zero/input_0.cairo create mode 100644 tests/nodes/tril_fp8x23_zero/output_0.cairo create mode 100644 tests/nodes/tril_i32.cairo create mode 100644 tests/nodes/tril_i32/input_0.cairo create mode 100644 tests/nodes/tril_i32/output_0.cairo create mode 100644 tests/nodes/tril_i32_one_row.cairo create mode 100644 tests/nodes/tril_i32_one_row/input_0.cairo create mode 100644 tests/nodes/tril_i32_one_row/output_0.cairo create mode 100644 tests/nodes/tril_i32_out_neg.cairo create mode 100644 tests/nodes/tril_i32_out_neg/input_0.cairo create mode 100644 tests/nodes/tril_i32_out_neg/output_0.cairo create mode 100644 tests/nodes/tril_i32_out_pos.cairo create mode 100644 tests/nodes/tril_i32_out_pos/input_0.cairo create mode 100644 tests/nodes/tril_i32_out_pos/output_0.cairo create mode 100644 tests/nodes/tril_i32_pos.cairo create mode 100644 tests/nodes/tril_i32_pos/input_0.cairo create mode 100644 tests/nodes/tril_i32_pos/output_0.cairo create mode 100644 tests/nodes/tril_i32_square.cairo create mode 100644 tests/nodes/tril_i32_square/input_0.cairo create mode 100644 tests/nodes/tril_i32_square/output_0.cairo create mode 100644 tests/nodes/tril_i32_square_neg.cairo create mode 100644 tests/nodes/tril_i32_square_neg/input_0.cairo create mode 100644 tests/nodes/tril_i32_square_neg/output_0.cairo create mode 100644 tests/nodes/tril_i32_zero.cairo create mode 100644 tests/nodes/tril_i32_zero/input_0.cairo create mode 100644 tests/nodes/tril_i32_zero/output_0.cairo create mode 100644 tests/nodes/tril_i8.cairo create mode 100644 tests/nodes/tril_i8/input_0.cairo create mode 100644 tests/nodes/tril_i8/output_0.cairo create mode 100644 tests/nodes/tril_i8_neg.cairo create mode 100644 tests/nodes/tril_i8_neg/input_0.cairo create mode 100644 tests/nodes/tril_i8_neg/output_0.cairo create mode 100644 tests/nodes/tril_i8_one_row.cairo create mode 100644 tests/nodes/tril_i8_one_row/input_0.cairo create mode 100644 tests/nodes/tril_i8_one_row/output_0.cairo create mode 100644 tests/nodes/tril_i8_out_neg.cairo create mode 100644 tests/nodes/tril_i8_out_neg/input_0.cairo create mode 100644 tests/nodes/tril_i8_out_neg/output_0.cairo create mode 100644 tests/nodes/tril_i8_out_pos.cairo create mode 100644 tests/nodes/tril_i8_out_pos/input_0.cairo create mode 100644 tests/nodes/tril_i8_out_pos/output_0.cairo create mode 100644 tests/nodes/tril_i8_pos.cairo create mode 100644 tests/nodes/tril_i8_pos/input_0.cairo create mode 100644 tests/nodes/tril_i8_pos/output_0.cairo create mode 100644 tests/nodes/tril_i8_square.cairo create mode 100644 tests/nodes/tril_i8_square/input_0.cairo create mode 100644 tests/nodes/tril_i8_square/output_0.cairo create mode 100644 tests/nodes/tril_i8_square_neg.cairo create mode 100644 tests/nodes/tril_i8_square_neg/input_0.cairo create mode 100644 tests/nodes/tril_i8_square_neg/output_0.cairo create mode 100644 tests/nodes/tril_i8_zero.cairo create mode 100644 tests/nodes/tril_i8_zero/input_0.cairo create mode 100644 tests/nodes/tril_i8_zero/output_0.cairo create mode 100644 tests/nodes/tril_neg_i32.cairo create mode 100644 tests/nodes/tril_neg_i32/input_0.cairo create mode 100644 tests/nodes/tril_neg_i32/output_0.cairo create mode 100644 tests/nodes/tril_u32.cairo create mode 100644 tests/nodes/tril_u32/input_0.cairo create mode 100644 tests/nodes/tril_u32/output_0.cairo create mode 100644 tests/nodes/tril_u32_neg.cairo create mode 100644 tests/nodes/tril_u32_neg/input_0.cairo create mode 100644 tests/nodes/tril_u32_neg/output_0.cairo create mode 100644 tests/nodes/tril_u32_one_row.cairo create mode 100644 tests/nodes/tril_u32_one_row/input_0.cairo create mode 100644 tests/nodes/tril_u32_one_row/output_0.cairo create mode 100644 tests/nodes/tril_u32_out_neg.cairo create mode 100644 tests/nodes/tril_u32_out_neg/input_0.cairo create mode 100644 tests/nodes/tril_u32_out_neg/output_0.cairo create mode 100644 tests/nodes/tril_u32_out_pos.cairo create mode 100644 tests/nodes/tril_u32_out_pos/input_0.cairo create mode 100644 tests/nodes/tril_u32_out_pos/output_0.cairo create mode 100644 tests/nodes/tril_u32_pos.cairo create mode 100644 tests/nodes/tril_u32_pos/input_0.cairo create mode 100644 tests/nodes/tril_u32_pos/output_0.cairo create mode 100644 tests/nodes/tril_u32_square.cairo create mode 100644 tests/nodes/tril_u32_square/input_0.cairo create mode 100644 tests/nodes/tril_u32_square/output_0.cairo create mode 100644 tests/nodes/tril_u32_square_neg.cairo create mode 100644 tests/nodes/tril_u32_square_neg/input_0.cairo create mode 100644 tests/nodes/tril_u32_square_neg/output_0.cairo create mode 100644 tests/nodes/tril_u32_zero.cairo create mode 100644 tests/nodes/tril_u32_zero/input_0.cairo create mode 100644 tests/nodes/tril_u32_zero/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16.cairo create mode 100644 tests/nodes/triu_fp16x16/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_neg.cairo create mode 100644 tests/nodes/triu_fp16x16_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_one_row.cairo create mode 100644 tests/nodes/triu_fp16x16_one_row/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_one_row/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_out_neg.cairo create mode 100644 tests/nodes/triu_fp16x16_out_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_out_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_out_pos.cairo create mode 100644 tests/nodes/triu_fp16x16_out_pos/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_out_pos/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_pos.cairo create mode 100644 tests/nodes/triu_fp16x16_pos/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_pos/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_square.cairo create mode 100644 tests/nodes/triu_fp16x16_square/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_square/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_square_neg.cairo create mode 100644 tests/nodes/triu_fp16x16_square_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_square_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp16x16_zero.cairo create mode 100644 tests/nodes/triu_fp16x16_zero/input_0.cairo create mode 100644 tests/nodes/triu_fp16x16_zero/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23.cairo create mode 100644 tests/nodes/triu_fp8x23/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_neg.cairo create mode 100644 tests/nodes/triu_fp8x23_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_one_row.cairo create mode 100644 tests/nodes/triu_fp8x23_one_row/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_one_row/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_out_neg.cairo create mode 100644 tests/nodes/triu_fp8x23_out_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_out_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_out_pos.cairo create mode 100644 tests/nodes/triu_fp8x23_out_pos/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_out_pos/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_pos.cairo create mode 100644 tests/nodes/triu_fp8x23_pos/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_pos/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_square.cairo create mode 100644 tests/nodes/triu_fp8x23_square/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_square/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_square_neg.cairo create mode 100644 tests/nodes/triu_fp8x23_square_neg/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_square_neg/output_0.cairo create mode 100644 tests/nodes/triu_fp8x23_zero.cairo create mode 100644 tests/nodes/triu_fp8x23_zero/input_0.cairo create mode 100644 tests/nodes/triu_fp8x23_zero/output_0.cairo create mode 100644 tests/nodes/triu_i32.cairo create mode 100644 tests/nodes/triu_i32/input_0.cairo create mode 100644 tests/nodes/triu_i32/output_0.cairo create mode 100644 tests/nodes/triu_i32_neg.cairo create mode 100644 tests/nodes/triu_i32_neg/input_0.cairo create mode 100644 tests/nodes/triu_i32_neg/output_0.cairo create mode 100644 tests/nodes/triu_i32_one_row.cairo create mode 100644 tests/nodes/triu_i32_one_row/input_0.cairo create mode 100644 tests/nodes/triu_i32_one_row/output_0.cairo create mode 100644 tests/nodes/triu_i32_out_neg.cairo create mode 100644 tests/nodes/triu_i32_out_neg/input_0.cairo create mode 100644 tests/nodes/triu_i32_out_neg/output_0.cairo create mode 100644 tests/nodes/triu_i32_out_pos.cairo create mode 100644 tests/nodes/triu_i32_out_pos/input_0.cairo create mode 100644 tests/nodes/triu_i32_out_pos/output_0.cairo create mode 100644 tests/nodes/triu_i32_pos.cairo create mode 100644 tests/nodes/triu_i32_pos/input_0.cairo create mode 100644 tests/nodes/triu_i32_pos/output_0.cairo create mode 100644 tests/nodes/triu_i32_square.cairo create mode 100644 tests/nodes/triu_i32_square/input_0.cairo create mode 100644 tests/nodes/triu_i32_square/output_0.cairo create mode 100644 tests/nodes/triu_i32_square_neg.cairo create mode 100644 tests/nodes/triu_i32_square_neg/input_0.cairo create mode 100644 tests/nodes/triu_i32_square_neg/output_0.cairo create mode 100644 tests/nodes/triu_i32_zero.cairo create mode 100644 tests/nodes/triu_i32_zero/input_0.cairo create mode 100644 tests/nodes/triu_i32_zero/output_0.cairo create mode 100644 tests/nodes/triu_i8.cairo create mode 100644 tests/nodes/triu_i8/input_0.cairo create mode 100644 tests/nodes/triu_i8/output_0.cairo create mode 100644 tests/nodes/triu_i8_neg.cairo create mode 100644 tests/nodes/triu_i8_neg/input_0.cairo create mode 100644 tests/nodes/triu_i8_neg/output_0.cairo create mode 100644 tests/nodes/triu_i8_one_row.cairo create mode 100644 tests/nodes/triu_i8_one_row/input_0.cairo create mode 100644 tests/nodes/triu_i8_one_row/output_0.cairo create mode 100644 tests/nodes/triu_i8_out_neg.cairo create mode 100644 tests/nodes/triu_i8_out_neg/input_0.cairo create mode 100644 tests/nodes/triu_i8_out_neg/output_0.cairo create mode 100644 tests/nodes/triu_i8_out_pos.cairo create mode 100644 tests/nodes/triu_i8_out_pos/input_0.cairo create mode 100644 tests/nodes/triu_i8_out_pos/output_0.cairo create mode 100644 tests/nodes/triu_i8_pos.cairo create mode 100644 tests/nodes/triu_i8_pos/input_0.cairo create mode 100644 tests/nodes/triu_i8_pos/output_0.cairo create mode 100644 tests/nodes/triu_i8_square.cairo create mode 100644 tests/nodes/triu_i8_square/input_0.cairo create mode 100644 tests/nodes/triu_i8_square/output_0.cairo create mode 100644 tests/nodes/triu_i8_square_neg.cairo create mode 100644 tests/nodes/triu_i8_square_neg/input_0.cairo create mode 100644 tests/nodes/triu_i8_square_neg/output_0.cairo create mode 100644 tests/nodes/triu_i8_zero.cairo create mode 100644 tests/nodes/triu_i8_zero/input_0.cairo create mode 100644 tests/nodes/triu_i8_zero/output_0.cairo create mode 100644 tests/nodes/triu_u32.cairo create mode 100644 tests/nodes/triu_u32/input_0.cairo create mode 100644 tests/nodes/triu_u32/output_0.cairo create mode 100644 tests/nodes/triu_u32_neg.cairo create mode 100644 tests/nodes/triu_u32_neg/input_0.cairo create mode 100644 tests/nodes/triu_u32_neg/output_0.cairo create mode 100644 tests/nodes/triu_u32_one_row.cairo create mode 100644 tests/nodes/triu_u32_one_row/input_0.cairo create mode 100644 tests/nodes/triu_u32_one_row/output_0.cairo create mode 100644 tests/nodes/triu_u32_out_neg.cairo create mode 100644 tests/nodes/triu_u32_out_neg/input_0.cairo create mode 100644 tests/nodes/triu_u32_out_neg/output_0.cairo create mode 100644 tests/nodes/triu_u32_out_pos.cairo create mode 100644 tests/nodes/triu_u32_out_pos/input_0.cairo create mode 100644 tests/nodes/triu_u32_out_pos/output_0.cairo create mode 100644 tests/nodes/triu_u32_pos.cairo create mode 100644 tests/nodes/triu_u32_pos/input_0.cairo create mode 100644 tests/nodes/triu_u32_pos/output_0.cairo create mode 100644 tests/nodes/triu_u32_square.cairo create mode 100644 tests/nodes/triu_u32_square/input_0.cairo create mode 100644 tests/nodes/triu_u32_square/output_0.cairo create mode 100644 tests/nodes/triu_u32_square_neg.cairo create mode 100644 tests/nodes/triu_u32_square_neg/input_0.cairo create mode 100644 tests/nodes/triu_u32_square_neg/output_0.cairo create mode 100644 tests/nodes/triu_u32_zero.cairo create mode 100644 tests/nodes/triu_u32_zero/input_0.cairo create mode 100644 tests/nodes/triu_u32_zero/output_0.cairo diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index d6dd0b35f..e56e7cc29 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -72,5 +72,6 @@ You can see below the list of current supported ONNX Operators: | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | +| [Trilu](operators/tensor/tensor.trilu.md) | :white\_check\_mark: | Current Operators support: **61/156 (39%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 48b1650ad..f83cf8ecc 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -89,6 +89,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | +| [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.min.md b/docs/framework/operators/tensor/tensor.min.md index 50c45e8ad..31157c2dc 100644 --- a/docs/framework/operators/tensor/tensor.min.md +++ b/docs/framework/operators/tensor/tensor.min.md @@ -19,8 +19,8 @@ A new `Tensor` containing the element-wise minimum values ## Panics +* Panics if tensor array is empty * Panics if the shapes are not equal or broadcastable -* Panics if tensor array length is not >= 1 ## Examples diff --git a/docs/framework/operators/tensor/tensor.trilu.md b/docs/framework/operators/tensor/tensor.trilu.md new file mode 100644 index 000000000..afc504691 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.trilu.md @@ -0,0 +1,39 @@ +# tensor.trilu + +```rust + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor; +``` + +Returns a new tensor with the uppper/lower triangular part of the tensor. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `upper`(`bool`) - if true, returns the upper triangular part of the tensor, otherwise returns the lower part. +* `k`(`i64`) - value corresponding to the number diagonals above or below the main diagonal to exclude or include. + +## Panics + +* Panics if the dimension of the tensor is less than 2. + +## Returns + +A `Tensor` instance with the uppper/lower triangular part of the tensor. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn trilu_tensor_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 3, 3].span(), data: array![0, 4, 3, 2, 0, 9, 8, 2, 5, 2, 7, 2, 2, 6, 0, 2, 6 ,5].span(), + ); + + // We can call `trilu` function as follows. + return tensor.trilu(false, 0); +} +>>> [[[0, 0, 0],[2, 0, 0], [8, 2, 5]], [[2, 0, 0], [2, 6, 0], [2, 6, 5]]] +``` diff --git a/docs/framework/operators/tensor/tensor.where.md b/docs/framework/operators/tensor/tensor.where.md index 02d3b0059..187f12ecb 100644 --- a/docs/framework/operators/tensor/tensor.where.md +++ b/docs/framework/operators/tensor/tensor.where.md @@ -37,7 +37,7 @@ fn where_example() -> Tensor { let tensor_x = TensorTrait::::new( shape: array![2, 2].span(), data: array![2, 4, 6, 8].span(), ); - + let tensor_y = TensorTrait::::new( shape: array![2, 2].span(), data: array![1, 3, 5, 9].span(), ); diff --git a/nodegen/helpers.py b/nodegen/helpers.py index c5b7e7de1..9c12d5a04 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -38,7 +38,7 @@ class Trait(Enum): ################ -def make_node(inputs: [Tensor], outputs: [Tensor], dir_name, path="tests/src/nodes/"): +def make_node(inputs: [Tensor], outputs: [Tensor], dir_name, path="tests/nodes/"): path = path + dir_name @@ -143,7 +143,7 @@ def make_test(inputs: [Tensor], output: Tensor, func_sig: str, file_name: str, t code.append(" assert_eq(y, z);\n") code.append("}") - with open(os.path.join("tests/src/nodes", f"{file_name}.cairo"), "a") as f: + with open(os.path.join("tests/nodes", f"{file_name}.cairo"), "a") as f: f.write( ''.join(code) ) @@ -238,14 +238,14 @@ def __generate_data(tensor: Tensor, path: str, name: str): # Add mod parent to nodes.cairo if not os.path.exists(path) or not os.listdir(path): os.makedirs(path, exist_ok=True) - parent = path.replace("tests/src/nodes/", "") - with open("tests/src/nodes.cairo", "a") as f: + parent = path.replace("tests/nodes/", "") + with open("tests/nodes.cairo", "a") as f: f.write(f"mod {parent}; \n") # Add tensor mod in parent file - parent = path.replace("tests/src/nodes/", "") - if not __module_exists(os.path.join("tests/src/nodes/", f"{parent}.cairo"), name): - with open(os.path.join("tests/src/nodes/", f"{parent}.cairo"), "a") as f: + parent = path.replace("tests/nodes/", "") + if not __module_exists(os.path.join("tests/nodes/", f"{parent}.cairo"), name): + with open(os.path.join("tests/nodes/", f"{parent}.cairo"), "a") as f: f.write(f"mod {name}; \n") # Convert tensor to cairo diff --git a/nodegen/node/trilu.py b/nodegen/node/trilu.py new file mode 100644 index 000000000..87553e48c --- /dev/null +++ b/nodegen/node/trilu.py @@ -0,0 +1,1249 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Trilu(RunAll): + @staticmethod + def trilu_u32(): + def tril(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.tril(x) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_neg(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + def tril_one_row(): + x = np.random.randint(0, 255, (3, 1, 5)).astype(np.uint32) + y = np.tril(x) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_out_neg(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.tril(x, k=-7) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -7)", name) + + + def tril_out_pos(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.tril(x, k=6) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def tril_pos(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.tril(x, k=2) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 2)", name) + + + def tril_square(): + x = np.random.randint(0, 255, (2, 3, 3)).astype(np.uint32) + y = np.tril(x, k=0) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + + def tril_square_neg(): + x = np.random.randint(0, 255, (2, 3, 3)).astype(np.uint32) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + + def tril_zero(): + x = np.random.randint(0, 255, (3, 0, 5)).astype(np.uint32) + y = np.tril(x, k=6) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "tril_u32_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def triu(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.triu(x) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_neg(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + def triu_one_row(): + x = np.random.randint(0, 255, (3, 1, 5)).astype(np.uint32) + y = np.triu(x) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_out_neg(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.triu(x, k=-7) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -7)", name) + + + def triu_out_pos(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.triu(x, k=6) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + + def triu_pos(): + x = np.random.randint(0, 255, (4, 5)).astype(np.uint32) + y = np.triu(x, k=2) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 2)", name) + + + def triu_square(): + x = np.random.randint(0, 255, (2, 3, 3)).astype(np.uint32) + y = np.triu(x, k=0) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + + def triu_square_neg(): + x = np.random.randint(0, 255, (2, 3, 3)).astype(np.uint32) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + + def triu_zero(): + x = np.random.randint(0, 255, (3, 0, 5)).astype(np.uint32) + y = np.triu(x, k=6) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "triu_u32_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + tril() + tril_neg() + tril_one_row() + tril_out_neg() + tril_out_pos() + tril_pos() + tril_square() + tril_square_neg() + tril_zero() + triu() + triu_neg() + triu_one_row() + triu_out_neg() + triu_out_pos() + triu_pos() + triu_square() + triu_square_neg() + triu_zero() + + + @staticmethod + def trilu_i32(): + def tril(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.tril(x) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_neg_i32" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + def tril_one_row(): + x = np.random.randint(-127, 127, (3, 1, 5)).astype(np.int32) + y = np.tril(x) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_out_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.tril(x, k=-7) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -7)", name) + + + def tril_out_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.tril(x, k=6) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def tril_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.tril(x, k=2) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 2)", name) + + + def tril_square(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int32) + y = np.tril(x, k=0) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + + def tril_square_neg(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int32) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + + def tril_zero(): + x = np.random.randint(-127, 127, (3, 0, 5)).astype(np.int32) + y = np.tril(x, k=6) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "tril_i32_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def triu(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.triu(x) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + def triu_one_row(): + x = np.random.randint(-127, 127, (3, 1, 5)).astype(np.int32) + y = np.triu(x) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_out_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.triu(x, k=-7) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -7)", name) + + + def triu_out_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.triu(x, k=6) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + + def triu_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int32) + y = np.triu(x, k=2) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 2)", name) + + + def triu_square(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int32) + y = np.triu(x, k=0) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + + def triu_square_neg(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int32) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + + def triu_zero(): + x = np.random.randint(-127, 127, (3, 0, 5)).astype(np.int32) + y = np.triu(x, k=6) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "triu_i32_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + tril() + tril_neg() + tril_one_row() + tril_out_neg() + tril_out_pos() + tril_pos() + tril_square() + tril_square_neg() + tril_zero() + triu() + triu_neg() + triu_one_row() + triu_out_neg() + triu_out_pos() + triu_pos() + triu_square() + triu_square_neg() + triu_zero() + + + @staticmethod + def trilu_i8(): + def tril(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.tril(x) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + def tril_one_row(): + x = np.random.randint(-127, 127, (3, 1, 5)).astype(np.int8) + y = np.tril(x) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_out_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.tril(x, k=-7) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -7)", name) + + + def tril_out_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.tril(x, k=6) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def tril_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.tril(x, k=2) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 2)", name) + + + def tril_square(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int8) + y = np.tril(x, k=0) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + + def tril_square_neg(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int8) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + + def tril_zero(): + x = np.random.randint(-127, 127, (3, 0, 5)).astype(np.int8) + y = np.tril(x, k=6) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "tril_i8_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def triu(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.triu(x) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + def triu_one_row(): + x = np.random.randint(-127, 127, (3, 1, 5)).astype(np.int8) + y = np.triu(x) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_out_neg(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.triu(x, k=-7) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -7)", name) + + + def triu_out_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.triu(x, k=6) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + + def triu_pos(): + x = np.random.randint(-127, 127, (4, 5)).astype(np.int8) + y = np.triu(x, k=2) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 2)", name) + + + def triu_square(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int8) + y = np.triu(x, k=0) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + + def triu_square_neg(): + x = np.random.randint(-127, 127, (2, 3, 3)).astype(np.int8) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + + def triu_zero(): + x = np.random.randint(-127, 127, (3, 0, 5)).astype(np.int8) + y = np.triu(x, k=6) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "triu_i8_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + tril() + tril_neg() + tril_one_row() + tril_out_neg() + tril_out_pos() + tril_pos() + tril_square() + tril_square_neg() + tril_zero() + triu() + triu_neg() + triu_one_row() + triu_out_neg() + triu_out_pos() + triu_pos() + triu_square() + triu_square_neg() + triu_zero() + + + @staticmethod + def trilu_fp8x23(): + def tril(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + def tril_one_row(): + x = to_fp(np.random.randint(-127, 127, (3, 1, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_out_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=-7) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -7)", name) + + + def tril_out_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=6) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def tril_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=2) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 2)", name) + + + def tril_square(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=0) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + + def tril_square_neg(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + + def tril_zero(): + x = to_fp(np.random.randint(-127, 127, (3, 0, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.tril(x, k=6) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "tril_fp8x23_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def triu(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + def triu_one_row(): + x = to_fp(np.random.randint(-127, 127, (3, 1, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_out_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=-7) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -7)", name) + + + def triu_out_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=6) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + + def triu_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=2) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 2)", name) + + + def triu_square(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=0) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + + def triu_square_neg(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + + def triu_zero(): + x = to_fp(np.random.randint(-127, 127, (3, 0, 5)).astype(np.int64), FixedImpl.FP8x23) + y = np.triu(x, k=6) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "triu_fp8x23_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + tril() + tril_neg() + tril_one_row() + tril_out_neg() + tril_out_pos() + tril_pos() + tril_square() + tril_square_neg() + tril_zero() + triu() + triu_neg() + triu_one_row() + triu_out_neg() + triu_out_pos() + triu_pos() + triu_square() + triu_square_neg() + triu_zero() + + + @staticmethod + def trilu_fp16x16(): + def tril(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + def tril_one_row(): + x = to_fp(np.random.randint(-127, 127, (3, 1, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + def tril_out_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=-7) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -7)", name) + + + def tril_out_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=6) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def tril_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=2) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 2)", name) + + + def tril_square(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=0) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 0)", name) + + + def tril_square_neg(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=-1) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, -1)", name) + + + def tril_zero(): + x = to_fp(np.random.randint(-127, 127, (3, 0, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.tril(x, k=6) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "tril_fp16x16_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(false, 6)", name) + + + def triu(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + def triu_one_row(): + x = to_fp(np.random.randint(-127, 127, (3, 1, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_one_row" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + def triu_out_neg(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=-7) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_out_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -7)", name) + + + def triu_out_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=6) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_out_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + + def triu_pos(): + x = to_fp(np.random.randint(-127, 127, (4, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=2) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_pos" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 2)", name) + + + def triu_square(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=0) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_square" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 0)", name) + + + def triu_square_neg(): + x = to_fp(np.random.randint(-127, 127, (2, 3, 3)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=-1) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_square_neg" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, -1)", name) + + + def triu_zero(): + x = to_fp(np.random.randint(-127, 127, (3, 0, 5)).astype(np.int64), FixedImpl.FP16x16) + y = np.triu(x, k=6) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "triu_fp16x16_zero" + make_node([x], [y], name) + make_test( + [x], y, "input_0.trilu(true, 6)", name) + + tril() + tril_neg() + tril_one_row() + tril_out_neg() + tril_out_pos() + tril_pos() + tril_square() + tril_square_neg() + tril_zero() + triu() + triu_neg() + triu_one_row() + triu_out_neg() + triu_out_pos() + triu_pos() + triu_square() + triu_square_neg() + triu_zero() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 44303e8c9..4a5136d57 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -85,6 +85,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3020,7 +3021,7 @@ trait TensorTrait { /// /// ## Example /// - /// ```rust + /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// /// use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; @@ -3041,6 +3042,47 @@ trait TensorTrait { /// ``` /// fn round(self: @Tensor) -> Tensor; + /// # tensor.trilu + /// + /// ```rust + /// fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor; + /// ``` + /// + /// Returns a new tensor with the uppper/lower triangular part of the tensor. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `upper`(`bool`) - if true, returns the upper triangular part of the tensor, otherwise returns the lower part. + /// * `k`(`i64`) - value corresponding to the number diagonals above or below the main diagonal to exclude or include. + /// + /// ## Panics + /// + /// * Panics if the dimension of the tensor is less than 2. + /// + /// ## Returns + /// + /// A `Tensor` instance with the uppper/lower triangular part of the tensor. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn trilu_tensor_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 3, 3].span(), data: array![0, 4, 3, 2, 0, 9, 8, 2, 5, 2, 7, 2, 2, 6, 0, 2, 6 ,5].span(), + /// ); + /// + /// // We can call `trilu` function as follows. + /// return tensor.trilu(false, 0); + /// } + /// >>> [[[0, 0, 0],[2, 0, 0], [8, 2, 5]], [[2, 0, 0], [2, 6, 0], [2, 6, 5]]] + /// ``` + /// + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8a85d5683..1615ff134 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -258,6 +258,9 @@ impl FP16x16Tensor of TensorTrait { math::round::round(*self) } + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 26a5c8060..2666b5da7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -267,6 +267,10 @@ impl FP16x16WTensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 e80b2946d..4f9951b79 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -257,7 +257,11 @@ impl FP32x32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 80189b701..15f8855c8 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -258,6 +258,10 @@ impl FP64x64Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 98bf543b6..8472496c1 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -257,6 +257,10 @@ impl FP8x23Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 bb40c169b..7b82d64d7 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -254,11 +254,14 @@ impl FP8x23WTensor of TensorTrait { math::where::where(self, x, y) } - fn round(self: @Tensor) -> Tensor { + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } -} + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, k) + } +} /// Implements addition for `Tensor` using the `Add` trait. impl FP8x23WTensorAdd< diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 988e81ab5..68daf259d 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -256,6 +256,10 @@ impl I32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 bc1de11ca..7fbb92d36 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -254,7 +254,11 @@ impl I8Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, 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 d5747877d..9eaade6d8 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -249,6 +249,10 @@ impl U32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { + linalg::trilu::trilu(self, upper, k) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/linalg.cairo b/src/operators/tensor/linalg.cairo index 6c2affb11..a6dc6f919 100644 --- a/src/operators/tensor/linalg.cairo +++ b/src/operators/tensor/linalg.cairo @@ -1,2 +1,3 @@ mod matmul; mod transpose; +mod trilu; diff --git a/src/operators/tensor/linalg/trilu.cairo b/src/operators/tensor/linalg/trilu.cairo new file mode 100644 index 000000000..de96b3db5 --- /dev/null +++ b/src/operators/tensor/linalg/trilu.cairo @@ -0,0 +1,77 @@ +use array::ArrayTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::trilu docstring +fn trilu< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, upper: bool, k: i64 +) -> Tensor { + assert((*self.shape).len() >= 2, 'must have at least 2 dimensions'); + + let shape_len = (*self.shape).len(); + let mut output_data = ArrayTrait::new(); + + let mut batch_size = 1; + let n: u32 = *self.shape[shape_len - 2]; + let m: u32 = *self.shape[shape_len - 1]; + + { + let mut i = 0; + loop { + if i == shape_len - 2 { + break (); + } + batch_size *= *self.shape[i]; + i += 1; + } + } + + { + let mut b = 0; + loop { + if b == batch_size { + break (); + } + + let mut i = 0; + loop { + if i == n { + break (); + } + let mut j = 0; + loop { + if j == m { + break (); + } + + let ii: felt252 = i.into(); + let jj: felt252 = j.into(); + + let iii: i64 = ii.try_into().unwrap(); + let jjj: i64 = jj.try_into().unwrap(); + + let result = if (upper && (iii + k <= jjj)) || (!upper && (iii + k >= jjj)) { + *(*self.data)[(b * n * m) + (i * m + j)] + } else { + NumberTrait::zero() + }; + output_data.append(result); + j += 1; + }; + i += 1; + }; + b += 1; + }; + } + + return TensorTrait::new(*self.shape, output_data.span()); +} diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 69473df94..cf441510c 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -37,4 +37,4 @@ mod sign; mod and; mod neg; mod where; -mod round; \ No newline at end of file +mod round; diff --git a/src/operators/tensor/math/max.cairo b/src/operators/tensor/math/max.cairo index 5ed703408..8052733d7 100644 --- a/src/operators/tensor/math/max.cairo +++ b/src/operators/tensor/math/max.cairo @@ -17,7 +17,6 @@ fn max< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn max< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(max_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut max_value = NumberTrait::max(*(max_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut max_value = NumberTrait::max( + *(max_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_max_data.append(max_value); n += 1; @@ -65,4 +68,4 @@ fn max< }; return TensorTrait::::new(max_shape, max_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min.cairo b/src/operators/tensor/math/min.cairo index 3577e69c0..61140f89d 100644 --- a/src/operators/tensor/math/min.cairo +++ b/src/operators/tensor/math/min.cairo @@ -17,7 +17,6 @@ fn min< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn min< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(min_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut min_value = NumberTrait::min(*(min_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut min_value = NumberTrait::min( + *(min_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_min_data.append(min_value); n += 1; @@ -65,4 +68,4 @@ fn min< }; return TensorTrait::::new(min_shape, min_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min_in_tensor.cairo b/src/operators/tensor/math/min_in_tensor.cairo index b9738db1f..e52f4a227 100644 --- a/src/operators/tensor/math/min_in_tensor.cairo +++ b/src/operators/tensor/math/min_in_tensor.cairo @@ -24,9 +24,7 @@ fn min_in_tensor< min_value = check_min; } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 4a6d7c8cb..bb6545866 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -448,42 +448,42 @@ mod identity_fP8x23; mod identity_i32; mod identity_i8; mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; mod where_fp16x16; mod where_fp16x16_broadcast; mod where_fp8x23; @@ -494,25 +494,116 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; + +mod tril_fp16x16; +mod tril_fp16x16_neg; +mod tril_fp16x16_one_row; +mod tril_fp16x16_out_neg; +mod tril_fp16x16_out_pos; +mod tril_fp16x16_pos; +mod tril_fp16x16_square; +mod tril_fp16x16_square_neg; +mod tril_fp16x16_zero; +mod triu_fp16x16; +mod triu_fp16x16_neg; +mod triu_fp16x16_one_row; +mod triu_fp16x16_out_neg; +mod triu_fp16x16_out_pos; +mod triu_fp16x16_pos; +mod triu_fp16x16_square; +mod triu_fp16x16_square_neg; +mod triu_fp16x16_zero; +mod tril_fp8x23; +mod tril_fp8x23_neg; +mod tril_fp8x23_one_row; +mod tril_fp8x23_out_neg; +mod tril_fp8x23_out_pos; +mod tril_fp8x23_pos; +mod tril_fp8x23_square; +mod tril_fp8x23_square_neg; +mod tril_fp8x23_zero; +mod triu_fp8x23; +mod triu_fp8x23_neg; +mod triu_fp8x23_one_row; +mod triu_fp8x23_out_neg; +mod triu_fp8x23_out_pos; +mod triu_fp8x23_pos; +mod triu_fp8x23_square; +mod triu_fp8x23_square_neg; +mod triu_fp8x23_zero; +mod tril_i32; +mod tril_neg_i32; +mod tril_i32_one_row; +mod tril_i32_out_neg; +mod tril_i32_out_pos; +mod tril_i32_pos; +mod tril_i32_square; +mod tril_i32_square_neg; +mod tril_i32_zero; +mod triu_i32; +mod triu_i32_neg; +mod triu_i32_one_row; +mod triu_i32_out_neg; +mod triu_i32_out_pos; +mod triu_i32_pos; +mod triu_i32_square; +mod triu_i32_square_neg; +mod triu_i32_zero; +mod tril_i8; +mod tril_i8_neg; +mod tril_i8_one_row; +mod tril_i8_out_neg; +mod tril_i8_out_pos; +mod tril_i8_pos; +mod tril_i8_square; +mod tril_i8_square_neg; +mod tril_i8_zero; +mod triu_i8; +mod triu_i8_neg; +mod triu_i8_one_row; +mod triu_i8_out_neg; +mod triu_i8_out_pos; +mod triu_i8_pos; +mod triu_i8_square; +mod triu_i8_square_neg; +mod triu_i8_zero; +mod tril_u32; +mod tril_u32_neg; +mod tril_u32_one_row; +mod tril_u32_out_neg; +mod tril_u32_out_pos; +mod tril_u32_pos; +mod tril_u32_square; +mod tril_u32_square_neg; +mod tril_u32_zero; +mod triu_u32; +mod triu_u32_neg; +mod triu_u32_one_row; +mod triu_u32_out_neg; +mod triu_u32_out_pos; +mod triu_u32_pos; +mod triu_u32_square; +mod triu_u32_square_neg; +mod triu_u32_zero; diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo index 2660e4676..e6a9a5db0 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo index fc8d87773..15950d596 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo index 352adab6a..ad2c130c9 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo index b743e5482..2a9d359fe 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo index b5ac6fdcd..b738aeee5 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo index 92152cd37..8caad904d 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo index 4cc6309d7..369a5c13f 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo index 37ead1117..e47fcecfe 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors.cairo b/tests/nodes/max_fp16x16_three_tensors.cairo index 8ca7dfebe..c81211037 100644 --- a/tests/nodes/max_fp16x16_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo index bb6a7efe8..33bfc9dac 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo index 71edb4da9..4690905db 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo index 9845fefbe..51a6c9f52 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo index 139ae932a..d8b8ce390 100644 --- a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors.cairo b/tests/nodes/max_fp16x16_two_tensors.cairo index 98b522b3d..cdf7e83e6 100644 --- a/tests/nodes/max_fp16x16_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo index 1e70f825c..368a064d7 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo index c766b1157..fe6280643 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo index 66b666290..07fd7443c 100644 --- a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo index 2fdd60ff2..ab1082160 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo index 2fa35f877..1de6875da 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo index fdcd11d36..3941d2b7e 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo index 4a9a3a6e3..e17548190 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo index 78bcbc1ed..10e0960d6 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo index b40477513..b77fbfbf6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo index 89cffdd5e..132278138 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo index 297233473..27a35e3b1 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo index 0506f1c0f..e7d95b6f6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors.cairo b/tests/nodes/max_fp8x23_three_tensors.cairo index d5cc6b030..b503bf177 100644 --- a/tests/nodes/max_fp8x23_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo index f0f1d9253..5d8539d1d 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo index f4611bf3c..2e4abdf49 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo index 6eeb29edb..b51cf0f13 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo index e0318aad1..ebb70503a 100644 --- a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors.cairo b/tests/nodes/max_fp8x23_two_tensors.cairo index b54d193d6..8d5ca3c74 100644 --- a/tests/nodes/max_fp8x23_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo index 038c7c361..d16c6a053 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo index da45b3378..a766fbb91 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo index 797bfa996..86eaeb478 100644 --- a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors.cairo b/tests/nodes/max_i32_broadcast_three_tensors.cairo index af4660c1d..91476cad9 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo index 1c894ed65..36c7bbba6 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo index d4cfc3152..f8f8fbca4 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, 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/nodes/max_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo index 5494fd3b3..f997397d7 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_broadcast_two_tensors.cairo b/tests/nodes/max_i32_broadcast_two_tensors.cairo index 25d864bba..63f46ff9f 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo index 65fc1651c..47591a648 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo index b75480afa..f2b5abec2 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo index ffc6f4c24..5fa192944 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors.cairo b/tests/nodes/max_i32_three_tensors.cairo index 186d5e2c5..c72a56cdf 100644 --- a/tests/nodes/max_i32_three_tensors.cairo +++ b/tests/nodes/max_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_0.cairo b/tests/nodes/max_i32_three_tensors/input_0.cairo index e5fdee508..be1f3c151 100644 --- a/tests/nodes/max_i32_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { 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/nodes/max_i32_three_tensors/input_1.cairo b/tests/nodes/max_i32_three_tensors/input_1.cairo index 960743a74..778aba1a0 100644 --- a/tests/nodes/max_i32_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_2.cairo b/tests/nodes/max_i32_three_tensors/input_2.cairo index f90517109..00a20e43b 100644 --- a/tests/nodes/max_i32_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/output_0.cairo b/tests/nodes/max_i32_three_tensors/output_0.cairo index 376bd0a58..10d697501 100644 --- a/tests/nodes/max_i32_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { 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/nodes/max_i32_two_tensors.cairo b/tests/nodes/max_i32_two_tensors.cairo index 18678b57e..c2ddc1b51 100644 --- a/tests/nodes/max_i32_two_tensors.cairo +++ b/tests/nodes/max_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/input_0.cairo b/tests/nodes/max_i32_two_tensors/input_0.cairo index 59ba3b966..0c5e37593 100644 --- a/tests/nodes/max_i32_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_two_tensors/input_1.cairo b/tests/nodes/max_i32_two_tensors/input_1.cairo index 6615ef39a..efd1ec5a2 100644 --- a/tests/nodes/max_i32_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/output_0.cairo b/tests/nodes/max_i32_two_tensors/output_0.cairo index 7eded96da..31eca8b5f 100644 --- a/tests/nodes/max_i32_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i8_broadcast_three_tensors.cairo b/tests/nodes/max_i8_broadcast_three_tensors.cairo index 65ea53cc9..d73af1f9e 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo index 80c86eb24..6569361bf 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo index 05fe8ff14..4f71b1d6f 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo index 381efaf32..ba14221ab 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors.cairo b/tests/nodes/max_i8_broadcast_two_tensors.cairo index 6a2f8b42f..af4a99d9f 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo index ea28aa087..ab27c2d6a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { 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/nodes/max_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo index 273837ef7..11068ef7a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors.cairo b/tests/nodes/max_i8_three_tensors.cairo index 40b83fbcc..b88c9459b 100644 --- a/tests/nodes/max_i8_three_tensors.cairo +++ b/tests/nodes/max_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_0.cairo b/tests/nodes/max_i8_three_tensors/input_0.cairo index 07fbd1690..69d671087 100644 --- a/tests/nodes/max_i8_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_1.cairo b/tests/nodes/max_i8_three_tensors/input_1.cairo index 47afadf00..67ba2e3ed 100644 --- a/tests/nodes/max_i8_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, 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/nodes/max_i8_three_tensors/input_2.cairo b/tests/nodes/max_i8_three_tensors/input_2.cairo index e37ded791..ab0f01d88 100644 --- a/tests/nodes/max_i8_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/output_0.cairo b/tests/nodes/max_i8_three_tensors/output_0.cairo index 5814fe790..4f7334f20 100644 --- a/tests/nodes/max_i8_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, 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/nodes/max_i8_two_tensors.cairo b/tests/nodes/max_i8_two_tensors.cairo index 9f6ee682d..d3ad09730 100644 --- a/tests/nodes/max_i8_two_tensors.cairo +++ b/tests/nodes/max_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_0.cairo b/tests/nodes/max_i8_two_tensors/input_0.cairo index ec6c88799..0d4c5397e 100644 --- a/tests/nodes/max_i8_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_1.cairo b/tests/nodes/max_i8_two_tensors/input_1.cairo index bc48996a9..55509fb6d 100644 --- a/tests/nodes/max_i8_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/output_0.cairo b/tests/nodes/max_i8_two_tensors/output_0.cairo index 889fc62c1..4025af717 100644 --- a/tests/nodes/max_i8_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors.cairo b/tests/nodes/max_u32_broadcast_three_tensors.cairo index a378bd9a7..241a2fc8f 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo index 108d66672..6c083ffa7 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(2); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo index a904f4e58..ea8734bae 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo index ab0ca7fb6..68dfae000 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo index 0f21da101..a0bd55df8 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors.cairo b/tests/nodes/max_u32_broadcast_two_tensors.cairo index ddcd35e04..b32369429 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo index e7dcaeaf3..9e24dfb3b 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo index b09e9c973..19d7a2a17 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo index 8354b7151..71b7b07b4 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors.cairo b/tests/nodes/max_u32_three_tensors.cairo index 655f2a713..c8fb9dfe1 100644 --- a/tests/nodes/max_u32_three_tensors.cairo +++ b/tests/nodes/max_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_0.cairo b/tests/nodes/max_u32_three_tensors/input_0.cairo index e428995ce..15d5eb226 100644 --- a/tests/nodes/max_u32_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(0); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_1.cairo b/tests/nodes/max_u32_three_tensors/input_1.cairo index edb019a72..5e8843449 100644 --- a/tests/nodes/max_u32_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_2.cairo b/tests/nodes/max_u32_three_tensors/input_2.cairo index cdd6dd700..220491901 100644 --- a/tests/nodes/max_u32_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/output_0.cairo b/tests/nodes/max_u32_three_tensors/output_0.cairo index b8b2b72aa..75fb08e26 100644 --- a/tests/nodes/max_u32_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors.cairo b/tests/nodes/max_u32_two_tensors.cairo index faed3d640..b4fbf9e02 100644 --- a/tests/nodes/max_u32_two_tensors.cairo +++ b/tests/nodes/max_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_0.cairo b/tests/nodes/max_u32_two_tensors/input_0.cairo index dde213565..6f1f617cd 100644 --- a/tests/nodes/max_u32_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_1.cairo b/tests/nodes/max_u32_two_tensors/input_1.cairo index bdd40bb01..131ad4f0f 100644 --- a/tests/nodes/max_u32_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(2); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/output_0.cairo b/tests/nodes/max_u32_two_tensors/output_0.cairo index e585ea8dc..4e935e3ea 100644 --- a/tests/nodes/max_u32_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo index c71edce86..220395f62 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo index bf27fbdf0..4589ab5de 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo index 98ef140fa..8bb4c575b 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo index 3b998ca1a..9a2d7a980 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo index c1c0930a4..2cccefb8a 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo index 0e8b2aebb..e6fd1bcce 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors.cairo b/tests/nodes/min_fp16x16_three_tensors.cairo index 8a5d60711..5501d9f70 100644 --- a/tests/nodes/min_fp16x16_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo index 747696a57..b5db9e4f1 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo index 22d5848ef..4aa7ab102 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo index 02084123c..1488424a5 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo index 6931f714a..6db8c5c68 100644 --- a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors.cairo b/tests/nodes/min_fp16x16_two_tensors.cairo index 25adc490e..a0c99e5a5 100644 --- a/tests/nodes/min_fp16x16_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo index 3cc3af9cb..c827d6229 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo index 230c3bfd0..9f62c5305 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo index 785211ceb..9e4c65919 100644 --- a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo index 2596fabad..7a66521a5 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo index c5eee64f3..f45ededce 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo index 5ddfee383..709d521a4 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo index 87ac9a1aa..5759d134b 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo index 6a9b1f878..3b2410704 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo index b231c5d76..babc5664d 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo index 06a77989a..764036b1c 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo index 538d00e70..35cf05e4e 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo index dbb598ae0..6279adb4a 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors.cairo b/tests/nodes/min_fp8x23_three_tensors.cairo index 676f8f312..9a4880f3e 100644 --- a/tests/nodes/min_fp8x23_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo index 9716ed3b9..1a1046aa6 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo index 49311a2b0..a90022ac9 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo index 9b8b0650e..87a644d4e 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo index af08ef421..15f4b94ea 100644 --- a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors.cairo b/tests/nodes/min_fp8x23_two_tensors.cairo index 01d2724ea..dbc7345e4 100644 --- a/tests/nodes/min_fp8x23_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo index 293eb3e83..e0caca041 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo index 76f71b638..3eb98567d 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo index c0e8bbc56..89214df41 100644 --- a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors.cairo b/tests/nodes/min_i32_broadcast_three_tensors.cairo index 74ad7c090..e1eb8036b 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo index 3ffb54363..df439f61e 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo index 97515f83e..b1b65261f 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo index 3031cb2bf..a81378685 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors.cairo b/tests/nodes/min_i32_broadcast_two_tensors.cairo index 43e5f99e0..56f474b6d 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo index b9cd5f819..324736c63 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo index ab5754cf2..bf2fecba4 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo index fa1f29299..9728ec700 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors.cairo b/tests/nodes/min_i32_three_tensors.cairo index adb4350db..332b00c62 100644 --- a/tests/nodes/min_i32_three_tensors.cairo +++ b/tests/nodes/min_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_0.cairo b/tests/nodes/min_i32_three_tensors/input_0.cairo index a255474d1..d7c51ab8d 100644 --- a/tests/nodes/min_i32_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_1.cairo b/tests/nodes/min_i32_three_tensors/input_1.cairo index 33568613e..0c25e152d 100644 --- a/tests/nodes/min_i32_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_2.cairo b/tests/nodes/min_i32_three_tensors/input_2.cairo index 9b822fc6d..f8d3071be 100644 --- a/tests/nodes/min_i32_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 1, 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/nodes/min_i32_three_tensors/output_0.cairo b/tests/nodes/min_i32_three_tensors/output_0.cairo index 9b0a9b23a..3f93c789b 100644 --- a/tests/nodes/min_i32_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors.cairo b/tests/nodes/min_i32_two_tensors.cairo index ae444f6e7..36bff1cd3 100644 --- a/tests/nodes/min_i32_two_tensors.cairo +++ b/tests/nodes/min_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_0.cairo b/tests/nodes/min_i32_two_tensors/input_0.cairo index 518ef5c24..53c2fcaa5 100644 --- a/tests/nodes/min_i32_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 5, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_1.cairo b/tests/nodes/min_i32_two_tensors/input_1.cairo index 42bdad0c9..92a12ff67 100644 --- a/tests/nodes/min_i32_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { 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/nodes/min_i32_two_tensors/output_0.cairo b/tests/nodes/min_i32_two_tensors/output_0.cairo index af1b203d5..d3e493a26 100644 --- a/tests/nodes/min_i32_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors.cairo b/tests/nodes/min_i8_broadcast_three_tensors.cairo index 4b67ffc7d..2256c0b62 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo index 254b04d0a..031cd3791 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo index 4fc8ae5a6..b7f890f64 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo index f472bb1d6..72888bf4c 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo index 9e4345995..289d4ad87 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors.cairo b/tests/nodes/min_i8_broadcast_two_tensors.cairo index a533c5930..d6344af77 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo index 563c07736..0966277be 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo index 060e0a9ec..1748d763f 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo index 86ec9707b..8bedae7e1 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors.cairo b/tests/nodes/min_i8_three_tensors.cairo index cee72024b..5d41e2551 100644 --- a/tests/nodes/min_i8_three_tensors.cairo +++ b/tests/nodes/min_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_0.cairo b/tests/nodes/min_i8_three_tensors/input_0.cairo index 92635527e..d29670a9f 100644 --- a/tests/nodes/min_i8_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_1.cairo b/tests/nodes/min_i8_three_tensors/input_1.cairo index 09e7ab7d1..d33e241c1 100644 --- a/tests/nodes/min_i8_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_2.cairo b/tests/nodes/min_i8_three_tensors/input_2.cairo index 6784429c8..9f66c1a8c 100644 --- a/tests/nodes/min_i8_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/output_0.cairo b/tests/nodes/min_i8_three_tensors/output_0.cairo index 86ccc411f..729e61ba1 100644 --- a/tests/nodes/min_i8_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors.cairo b/tests/nodes/min_i8_two_tensors.cairo index 8f13d360a..ffb3dd382 100644 --- a/tests/nodes/min_i8_two_tensors.cairo +++ b/tests/nodes/min_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_0.cairo b/tests/nodes/min_i8_two_tensors/input_0.cairo index edcba1f05..dfb122bf3 100644 --- a/tests/nodes/min_i8_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_1.cairo b/tests/nodes/min_i8_two_tensors/input_1.cairo index 805f2971a..9a088d52a 100644 --- a/tests/nodes/min_i8_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/output_0.cairo b/tests/nodes/min_i8_two_tensors/output_0.cairo index 4cfdc62b3..35e0b1112 100644 --- a/tests/nodes/min_i8_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors.cairo b/tests/nodes/min_u32_broadcast_three_tensors.cairo index b76ced612..3f90de3a0 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo index e1fde6172..ab5743e17 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(4); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo index 4f6ed249f..eb67448d2 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo index 9b8b57621..9ffbb5a5c 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo index 5af544845..5586a7f29 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors.cairo b/tests/nodes/min_u32_broadcast_two_tensors.cairo index 9fe666a9e..ead761837 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo index a173baaf1..79e203e76 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo index 447f95446..8f2990dec 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(5); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo index 51197a3e8..67ba1889c 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors.cairo b/tests/nodes/min_u32_three_tensors.cairo index 958888c62..82983386f 100644 --- a/tests/nodes/min_u32_three_tensors.cairo +++ b/tests/nodes/min_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_0.cairo b/tests/nodes/min_u32_three_tensors/input_0.cairo index 30bcab8cc..408871093 100644 --- a/tests/nodes/min_u32_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_1.cairo b/tests/nodes/min_u32_three_tensors/input_1.cairo index 73f220714..cbbfc75c3 100644 --- a/tests/nodes/min_u32_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_2.cairo b/tests/nodes/min_u32_three_tensors/input_2.cairo index 1f682b4a7..8e8027f01 100644 --- a/tests/nodes/min_u32_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/output_0.cairo b/tests/nodes/min_u32_three_tensors/output_0.cairo index 7a47c65c1..7e844ee1a 100644 --- a/tests/nodes/min_u32_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors.cairo b/tests/nodes/min_u32_two_tensors.cairo index 94ce36d7a..4b06824b8 100644 --- a/tests/nodes/min_u32_two_tensors.cairo +++ b/tests/nodes/min_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_0.cairo b/tests/nodes/min_u32_two_tensors/input_0.cairo index c20d52a0a..b4de32a93 100644 --- a/tests/nodes/min_u32_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_1.cairo b/tests/nodes/min_u32_two_tensors/input_1.cairo index d4709f0df..375910cbf 100644 --- a/tests/nodes/min_u32_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(3); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/output_0.cairo b/tests/nodes/min_u32_two_tensors/output_0.cairo index fc5f86d90..8fe8219a3 100644 --- a/tests/nodes/min_u32_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16.cairo b/tests/nodes/round_fp16x16.cairo index 02a279685..504ab435d 100644 --- a/tests/nodes/round_fp16x16.cairo +++ b/tests/nodes/round_fp16x16.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp16x16() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/input_0.cairo b/tests/nodes/round_fp16x16/input_0.cairo index 68229762b..711f27428 100644 --- a/tests/nodes/round_fp16x16/input_0.cairo +++ b/tests/nodes/round_fp16x16/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 163840, sign: true }); data.append(FP16x16 { mag: 183500, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/output_0.cairo b/tests/nodes/round_fp16x16/output_0.cairo index e303e30e4..0a920a6c2 100644 --- a/tests/nodes/round_fp16x16/output_0.cairo +++ b/tests/nodes/round_fp16x16/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23.cairo b/tests/nodes/round_fp8x23.cairo index e09a76fd2..8be8ed312 100644 --- a/tests/nodes/round_fp8x23.cairo +++ b/tests/nodes/round_fp8x23.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp8x23() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/input_0.cairo b/tests/nodes/round_fp8x23/input_0.cairo index d812ae1a2..386404257 100644 --- a/tests/nodes/round_fp8x23/input_0.cairo +++ b/tests/nodes/round_fp8x23/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 20971520, sign: true }); data.append(FP8x23 { mag: 23488102, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/output_0.cairo b/tests/nodes/round_fp8x23/output_0.cairo index d5cc73f5f..b984ecfe6 100644 --- a/tests/nodes/round_fp8x23/output_0.cairo +++ b/tests/nodes/round_fp8x23/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/tril_fp16x16.cairo b/tests/nodes/tril_fp16x16.cairo new file mode 100644 index 000000000..c1c50a196 --- /dev/null +++ b/tests/nodes/tril_fp16x16.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16/input_0.cairo b/tests/nodes/tril_fp16x16/input_0.cairo new file mode 100644 index 000000000..8606482b4 --- /dev/null +++ b/tests/nodes/tril_fp16x16/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3801088, sign: false }); + data.append(FP16x16 { mag: 5701632, sign: true }); + data.append(FP16x16 { mag: 8126464, sign: true }); + data.append(FP16x16 { mag: 6422528, sign: false }); + data.append(FP16x16 { mag: 4784128, sign: true }); + data.append(FP16x16 { mag: 4456448, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: true }); + data.append(FP16x16 { mag: 4653056, sign: false }); + data.append(FP16x16 { mag: 7733248, sign: false }); + data.append(FP16x16 { mag: 3866624, sign: true }); + data.append(FP16x16 { mag: 6684672, sign: false }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 4194304, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 8126464, sign: false }); + data.append(FP16x16 { mag: 3276800, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16/output_0.cairo b/tests/nodes/tril_fp16x16/output_0.cairo new file mode 100644 index 000000000..a7c950daf --- /dev/null +++ b/tests/nodes/tril_fp16x16/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3801088, 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: 4456448, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + 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: 4653056, sign: false }); + data.append(FP16x16 { mag: 7733248, sign: false }); + data.append(FP16x16 { mag: 3866624, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4194304, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 8126464, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_neg.cairo b/tests/nodes/tril_fp16x16_neg.cairo new file mode 100644 index 000000000..0d011403b --- /dev/null +++ b/tests/nodes/tril_fp16x16_neg.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_neg/input_0.cairo b/tests/nodes/tril_fp16x16_neg/input_0.cairo new file mode 100644 index 000000000..b8f11eb47 --- /dev/null +++ b/tests/nodes/tril_fp16x16_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 5177344, sign: false }); + data.append(FP16x16 { mag: 7340032, sign: true }); + data.append(FP16x16 { mag: 7077888, sign: false }); + data.append(FP16x16 { mag: 2752512, sign: true }); + data.append(FP16x16 { mag: 4784128, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 4194304, sign: true }); + data.append(FP16x16 { mag: 2359296, sign: true }); + data.append(FP16x16 { mag: 4915200, sign: true }); + data.append(FP16x16 { mag: 2555904, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 6881280, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: true }); + data.append(FP16x16 { mag: 6160384, sign: true }); + data.append(FP16x16 { mag: 4587520, sign: true }); + data.append(FP16x16 { mag: 589824, sign: true }); + data.append(FP16x16 { mag: 4259840, sign: true }); + data.append(FP16x16 { mag: 2686976, sign: true }); + data.append(FP16x16 { mag: 7405568, sign: true }); + data.append(FP16x16 { mag: 786432, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_neg/output_0.cairo b/tests/nodes/tril_fp16x16_neg/output_0.cairo new file mode 100644 index 000000000..3c9229023 --- /dev/null +++ b/tests/nodes/tril_fp16x16_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + 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: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + 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: 458752, sign: false }); + data.append(FP16x16 { mag: 6881280, 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: 589824, sign: true }); + data.append(FP16x16 { mag: 4259840, sign: true }); + data.append(FP16x16 { mag: 2686976, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_one_row.cairo b/tests/nodes/tril_fp16x16_one_row.cairo new file mode 100644 index 000000000..de3bc34fa --- /dev/null +++ b/tests/nodes/tril_fp16x16_one_row.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_one_row/input_0.cairo b/tests/nodes/tril_fp16x16_one_row/input_0.cairo new file mode 100644 index 000000000..158392a5c --- /dev/null +++ b/tests/nodes/tril_fp16x16_one_row/input_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3604480, sign: true }); + data.append(FP16x16 { mag: 2621440, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 2490368, sign: true }); + data.append(FP16x16 { mag: 2555904, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 4849664, sign: false }); + data.append(FP16x16 { mag: 5636096, sign: true }); + data.append(FP16x16 { mag: 2949120, sign: false }); + data.append(FP16x16 { mag: 6291456, sign: false }); + data.append(FP16x16 { mag: 3014656, sign: true }); + data.append(FP16x16 { mag: 3342336, sign: true }); + data.append(FP16x16 { mag: 6750208, sign: true }); + data.append(FP16x16 { mag: 7798784, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_one_row/output_0.cairo b/tests/nodes/tril_fp16x16_one_row/output_0.cairo new file mode 100644 index 000000000..b10586a4a --- /dev/null +++ b/tests/nodes/tril_fp16x16_one_row/output_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3604480, sign: true }); + 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: 2555904, 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: 6291456, 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 }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_out_neg.cairo b/tests/nodes/tril_fp16x16_out_neg.cairo new file mode 100644 index 000000000..8ccb981a1 --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_neg.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_out_neg/input_0.cairo b/tests/nodes/tril_fp16x16_out_neg/input_0.cairo new file mode 100644 index 000000000..eb63a1be4 --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 524288, sign: true }); + data.append(FP16x16 { mag: 1245184, sign: true }); + data.append(FP16x16 { mag: 3801088, sign: false }); + data.append(FP16x16 { mag: 1179648, sign: false }); + data.append(FP16x16 { mag: 4980736, sign: false }); + data.append(FP16x16 { mag: 917504, sign: true }); + data.append(FP16x16 { mag: 3997696, sign: false }); + data.append(FP16x16 { mag: 3538944, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 2490368, sign: true }); + data.append(FP16x16 { mag: 720896, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 5898240, sign: false }); + data.append(FP16x16 { mag: 6750208, sign: false }); + data.append(FP16x16 { mag: 7995392, sign: false }); + data.append(FP16x16 { mag: 2031616, sign: false }); + data.append(FP16x16 { mag: 5308416, sign: true }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 7929856, sign: false }); + data.append(FP16x16 { mag: 4063232, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_out_neg/output_0.cairo b/tests/nodes/tril_fp16x16_out_neg/output_0.cairo new file mode 100644 index 000000000..7bf937a2d --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + 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: 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: 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: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_out_pos.cairo b/tests/nodes/tril_fp16x16_out_pos.cairo new file mode 100644 index 000000000..edc05c02a --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_pos.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_out_pos/input_0.cairo b/tests/nodes/tril_fp16x16_out_pos/input_0.cairo new file mode 100644 index 000000000..a2bef2cd5 --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 5046272, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 5832704, sign: false }); + data.append(FP16x16 { mag: 7340032, sign: true }); + data.append(FP16x16 { mag: 8192000, sign: false }); + data.append(FP16x16 { mag: 6094848, sign: false }); + data.append(FP16x16 { mag: 6488064, sign: true }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 7405568, sign: true }); + data.append(FP16x16 { mag: 5373952, sign: false }); + data.append(FP16x16 { mag: 4521984, sign: true }); + data.append(FP16x16 { mag: 7667712, sign: true }); + data.append(FP16x16 { mag: 3014656, sign: false }); + data.append(FP16x16 { mag: 1900544, sign: false }); + data.append(FP16x16 { mag: 3211264, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 6815744, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: true }); + data.append(FP16x16 { mag: 3866624, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_out_pos/output_0.cairo b/tests/nodes/tril_fp16x16_out_pos/output_0.cairo new file mode 100644 index 000000000..4d8fd07b7 --- /dev/null +++ b/tests/nodes/tril_fp16x16_out_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 5046272, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 5832704, sign: false }); + data.append(FP16x16 { mag: 7340032, sign: true }); + data.append(FP16x16 { mag: 8192000, sign: false }); + data.append(FP16x16 { mag: 6094848, sign: false }); + data.append(FP16x16 { mag: 6488064, sign: true }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 7405568, sign: true }); + data.append(FP16x16 { mag: 5373952, sign: false }); + data.append(FP16x16 { mag: 4521984, sign: true }); + data.append(FP16x16 { mag: 7667712, sign: true }); + data.append(FP16x16 { mag: 3014656, sign: false }); + data.append(FP16x16 { mag: 1900544, sign: false }); + data.append(FP16x16 { mag: 3211264, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 6815744, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: true }); + data.append(FP16x16 { mag: 3866624, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_pos.cairo b/tests/nodes/tril_fp16x16_pos.cairo new file mode 100644 index 000000000..b675621be --- /dev/null +++ b/tests/nodes/tril_fp16x16_pos.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_pos/input_0.cairo b/tests/nodes/tril_fp16x16_pos/input_0.cairo new file mode 100644 index 000000000..0a304441e --- /dev/null +++ b/tests/nodes/tril_fp16x16_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 6750208, sign: false }); + data.append(FP16x16 { mag: 6225920, sign: false }); + data.append(FP16x16 { mag: 2031616, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4980736, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: false }); + data.append(FP16x16 { mag: 7864320, sign: false }); + data.append(FP16x16 { mag: 3276800, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: true }); + data.append(FP16x16 { mag: 2162688, sign: true }); + data.append(FP16x16 { mag: 7077888, sign: true }); + data.append(FP16x16 { mag: 2555904, sign: true }); + data.append(FP16x16 { mag: 2686976, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: false }); + data.append(FP16x16 { mag: 3604480, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_pos/output_0.cairo b/tests/nodes/tril_fp16x16_pos/output_0.cairo new file mode 100644 index 000000000..320c6268a --- /dev/null +++ b/tests/nodes/tril_fp16x16_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 6750208, sign: false }); + data.append(FP16x16 { mag: 6225920, 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: 4980736, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: false }); + data.append(FP16x16 { mag: 7864320, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: true }); + data.append(FP16x16 { mag: 2162688, sign: true }); + data.append(FP16x16 { mag: 7077888, sign: true }); + data.append(FP16x16 { mag: 2555904, sign: true }); + data.append(FP16x16 { mag: 2686976, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: false }); + data.append(FP16x16 { mag: 3604480, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_square.cairo b/tests/nodes/tril_fp16x16_square.cairo new file mode 100644 index 000000000..995e91cb2 --- /dev/null +++ b/tests/nodes/tril_fp16x16_square.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_square/input_0.cairo b/tests/nodes/tril_fp16x16_square/input_0.cairo new file mode 100644 index 000000000..c60715c57 --- /dev/null +++ b/tests/nodes/tril_fp16x16_square/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 7864320, sign: false }); + data.append(FP16x16 { mag: 5308416, sign: true }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + data.append(FP16x16 { mag: 2097152, sign: false }); + data.append(FP16x16 { mag: 5898240, sign: true }); + data.append(FP16x16 { mag: 6225920, sign: true }); + data.append(FP16x16 { mag: 5701632, sign: true }); + data.append(FP16x16 { mag: 4653056, sign: true }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 3538944, sign: true }); + data.append(FP16x16 { mag: 6881280, sign: false }); + data.append(FP16x16 { mag: 5373952, sign: true }); + data.append(FP16x16 { mag: 5242880, sign: true }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 7536640, sign: true }); + data.append(FP16x16 { mag: 5767168, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_square/output_0.cairo b/tests/nodes/tril_fp16x16_square/output_0.cairo new file mode 100644 index 000000000..c6c6d240c --- /dev/null +++ b/tests/nodes/tril_fp16x16_square/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 7864320, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + data.append(FP16x16 { mag: 2097152, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 6225920, sign: true }); + data.append(FP16x16 { mag: 5701632, sign: true }); + data.append(FP16x16 { mag: 4653056, sign: true }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 5373952, sign: true }); + data.append(FP16x16 { mag: 5242880, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 7536640, sign: true }); + data.append(FP16x16 { mag: 5767168, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_square_neg.cairo b/tests/nodes/tril_fp16x16_square_neg.cairo new file mode 100644 index 000000000..0f5abcbf1 --- /dev/null +++ b/tests/nodes/tril_fp16x16_square_neg.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_square_neg/input_0.cairo b/tests/nodes/tril_fp16x16_square_neg/input_0.cairo new file mode 100644 index 000000000..1304a26fa --- /dev/null +++ b/tests/nodes/tril_fp16x16_square_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 2949120, sign: false }); + data.append(FP16x16 { mag: 4128768, sign: false }); + data.append(FP16x16 { mag: 7012352, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 5046272, sign: true }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 2490368, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 2949120, sign: true }); + data.append(FP16x16 { mag: 5701632, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 6488064, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 5111808, sign: true }); + data.append(FP16x16 { mag: 6946816, sign: true }); + data.append(FP16x16 { mag: 4259840, sign: true }); + data.append(FP16x16 { mag: 5111808, sign: false }); + data.append(FP16x16 { mag: 5373952, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_square_neg/output_0.cairo b/tests/nodes/tril_fp16x16_square_neg/output_0.cairo new file mode 100644 index 000000000..c872f81ee --- /dev/null +++ b/tests/nodes/tril_fp16x16_square_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + 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: 1441792, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 2490368, sign: false }); + data.append(FP16x16 { mag: 983040, 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: 655360, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4259840, sign: true }); + data.append(FP16x16 { mag: 5111808, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_zero.cairo b/tests/nodes/tril_fp16x16_zero.cairo new file mode 100644 index 000000000..93609401a --- /dev/null +++ b/tests/nodes/tril_fp16x16_zero.cairo @@ -0,0 +1,20 @@ +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_tril_fp16x16_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp16x16_zero/input_0.cairo b/tests/nodes/tril_fp16x16_zero/input_0.cairo new file mode 100644 index 000000000..073b19063 --- /dev/null +++ b/tests/nodes/tril_fp16x16_zero/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp16x16_zero/output_0.cairo b/tests/nodes/tril_fp16x16_zero/output_0.cairo new file mode 100644 index 000000000..d88922e9a --- /dev/null +++ b/tests/nodes/tril_fp16x16_zero/output_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23.cairo b/tests/nodes/tril_fp8x23.cairo new file mode 100644 index 000000000..1dfdfb4d1 --- /dev/null +++ b/tests/nodes/tril_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_tril_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23/input_0.cairo b/tests/nodes/tril_fp8x23/input_0.cairo new file mode 100644 index 000000000..52fc7dc5d --- /dev/null +++ b/tests/nodes/tril_fp8x23/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 234881024, sign: false }); + data.append(FP8x23 { mag: 327155712, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: true }); + data.append(FP8x23 { mag: 947912704, sign: true }); + data.append(FP8x23 { mag: 687865856, sign: true }); + data.append(FP8x23 { mag: 92274688, sign: true }); + data.append(FP8x23 { mag: 998244352, sign: true }); + data.append(FP8x23 { mag: 805306368, sign: false }); + data.append(FP8x23 { mag: 855638016, sign: false }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 494927872, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 385875968, sign: true }); + data.append(FP8x23 { mag: 855638016, sign: true }); + data.append(FP8x23 { mag: 654311424, sign: true }); + data.append(FP8x23 { mag: 754974720, sign: true }); + data.append(FP8x23 { mag: 1023410176, sign: false }); + data.append(FP8x23 { mag: 520093696, sign: false }); + data.append(FP8x23 { mag: 654311424, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23/output_0.cairo b/tests/nodes/tril_fp8x23/output_0.cairo new file mode 100644 index 000000000..f54e2d0e0 --- /dev/null +++ b/tests/nodes/tril_fp8x23/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 234881024, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: true }); + data.append(FP8x23 { mag: 998244352, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 654311424, sign: true }); + data.append(FP8x23 { mag: 754974720, sign: true }); + data.append(FP8x23 { mag: 1023410176, sign: false }); + data.append(FP8x23 { mag: 520093696, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_neg.cairo b/tests/nodes/tril_fp8x23_neg.cairo new file mode 100644 index 000000000..241a51118 --- /dev/null +++ b/tests/nodes/tril_fp8x23_neg.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_tril_fp8x23_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_neg/input_0.cairo b/tests/nodes/tril_fp8x23_neg/input_0.cairo new file mode 100644 index 000000000..7cc5d9076 --- /dev/null +++ b/tests/nodes/tril_fp8x23_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 520093696, sign: true }); + data.append(FP8x23 { mag: 444596224, sign: false }); + data.append(FP8x23 { mag: 293601280, sign: true }); + data.append(FP8x23 { mag: 218103808, sign: true }); + data.append(FP8x23 { mag: 595591168, sign: true }); + data.append(FP8x23 { mag: 989855744, sign: false }); + data.append(FP8x23 { mag: 411041792, sign: true }); + data.append(FP8x23 { mag: 1023410176, sign: false }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 704643072, sign: true }); + data.append(FP8x23 { mag: 452984832, sign: true }); + data.append(FP8x23 { mag: 813694976, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: false }); + data.append(FP8x23 { mag: 578813952, sign: false }); + data.append(FP8x23 { mag: 427819008, sign: true }); + data.append(FP8x23 { mag: 92274688, sign: true }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 981467136, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: true }); + data.append(FP8x23 { mag: 813694976, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_neg/output_0.cairo b/tests/nodes/tril_fp8x23_neg/output_0.cairo new file mode 100644 index 000000000..ce7d5c553 --- /dev/null +++ b/tests/nodes/tril_fp8x23_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 989855744, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: true }); + data.append(FP8x23 { mag: 813694976, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: true }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 981467136, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_one_row.cairo b/tests/nodes/tril_fp8x23_one_row.cairo new file mode 100644 index 000000000..ae8ea0b19 --- /dev/null +++ b/tests/nodes/tril_fp8x23_one_row.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_tril_fp8x23_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_one_row/input_0.cairo b/tests/nodes/tril_fp8x23_one_row/input_0.cairo new file mode 100644 index 000000000..aedc73859 --- /dev/null +++ b/tests/nodes/tril_fp8x23_one_row/input_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 637534208, sign: true }); + data.append(FP8x23 { mag: 293601280, sign: true }); + data.append(FP8x23 { mag: 620756992, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: false }); + data.append(FP8x23 { mag: 528482304, sign: true }); + data.append(FP8x23 { mag: 1023410176, sign: true }); + data.append(FP8x23 { mag: 553648128, sign: false }); + data.append(FP8x23 { mag: 587202560, sign: false }); + data.append(FP8x23 { mag: 998244352, sign: true }); + data.append(FP8x23 { mag: 671088640, sign: true }); + data.append(FP8x23 { mag: 796917760, sign: true }); + data.append(FP8x23 { mag: 578813952, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_one_row/output_0.cairo b/tests/nodes/tril_fp8x23_one_row/output_0.cairo new file mode 100644 index 000000000..59b20ed24 --- /dev/null +++ b/tests/nodes/tril_fp8x23_one_row/output_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 637534208, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 587202560, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_out_neg.cairo b/tests/nodes/tril_fp8x23_out_neg.cairo new file mode 100644 index 000000000..6158aa992 --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_neg.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_tril_fp8x23_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_out_neg/input_0.cairo b/tests/nodes/tril_fp8x23_out_neg/input_0.cairo new file mode 100644 index 000000000..0ac218229 --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 528482304, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 830472192, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: true }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: false }); + data.append(FP8x23 { mag: 897581056, sign: true }); + data.append(FP8x23 { mag: 385875968, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: true }); + data.append(FP8x23 { mag: 385875968, sign: false }); + data.append(FP8x23 { mag: 411041792, sign: false }); + data.append(FP8x23 { mag: 301989888, sign: true }); + data.append(FP8x23 { mag: 444596224, sign: true }); + data.append(FP8x23 { mag: 905969664, sign: false }); + data.append(FP8x23 { mag: 251658240, sign: false }); + data.append(FP8x23 { mag: 830472192, sign: false }); + data.append(FP8x23 { mag: 864026624, sign: true }); + data.append(FP8x23 { mag: 545259520, sign: true }); + data.append(FP8x23 { mag: 1040187392, sign: false }); + data.append(FP8x23 { mag: 243269632, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_out_neg/output_0.cairo b/tests/nodes/tril_fp8x23_out_neg/output_0.cairo new file mode 100644 index 000000000..54f2a133b --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_out_pos.cairo b/tests/nodes/tril_fp8x23_out_pos.cairo new file mode 100644 index 000000000..42b991aa2 --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_pos.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_tril_fp8x23_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_out_pos/input_0.cairo b/tests/nodes/tril_fp8x23_out_pos/input_0.cairo new file mode 100644 index 000000000..c71ba4b12 --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 872415232, sign: false }); + data.append(FP8x23 { mag: 251658240, sign: true }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: true }); + data.append(FP8x23 { mag: 931135488, sign: false }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: true }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 1006632960, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: true }); + data.append(FP8x23 { mag: 973078528, sign: false }); + data.append(FP8x23 { mag: 662700032, sign: true }); + data.append(FP8x23 { mag: 704643072, sign: false }); + data.append(FP8x23 { mag: 260046848, sign: false }); + data.append(FP8x23 { mag: 478150656, sign: false }); + data.append(FP8x23 { mag: 562036736, sign: true }); + data.append(FP8x23 { mag: 587202560, sign: true }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 100663296, sign: true }); + data.append(FP8x23 { mag: 864026624, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_out_pos/output_0.cairo b/tests/nodes/tril_fp8x23_out_pos/output_0.cairo new file mode 100644 index 000000000..7e9c42c4d --- /dev/null +++ b/tests/nodes/tril_fp8x23_out_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 872415232, sign: false }); + data.append(FP8x23 { mag: 251658240, sign: true }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: true }); + data.append(FP8x23 { mag: 931135488, sign: false }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: true }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 1006632960, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: true }); + data.append(FP8x23 { mag: 973078528, sign: false }); + data.append(FP8x23 { mag: 662700032, sign: true }); + data.append(FP8x23 { mag: 704643072, sign: false }); + data.append(FP8x23 { mag: 260046848, sign: false }); + data.append(FP8x23 { mag: 478150656, sign: false }); + data.append(FP8x23 { mag: 562036736, sign: true }); + data.append(FP8x23 { mag: 587202560, sign: true }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 100663296, sign: true }); + data.append(FP8x23 { mag: 864026624, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_pos.cairo b/tests/nodes/tril_fp8x23_pos.cairo new file mode 100644 index 000000000..20cd67f9e --- /dev/null +++ b/tests/nodes/tril_fp8x23_pos.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_tril_fp8x23_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_pos/input_0.cairo b/tests/nodes/tril_fp8x23_pos/input_0.cairo new file mode 100644 index 000000000..fad04c120 --- /dev/null +++ b/tests/nodes/tril_fp8x23_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 444596224, sign: true }); + data.append(FP8x23 { mag: 796917760, sign: false }); + data.append(FP8x23 { mag: 587202560, sign: true }); + data.append(FP8x23 { mag: 889192448, sign: false }); + data.append(FP8x23 { mag: 872415232, sign: true }); + data.append(FP8x23 { mag: 964689920, sign: true }); + data.append(FP8x23 { mag: 486539264, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: true }); + data.append(FP8x23 { mag: 310378496, sign: false }); + data.append(FP8x23 { mag: 947912704, sign: false }); + data.append(FP8x23 { mag: 998244352, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 226492416, sign: false }); + data.append(FP8x23 { mag: 343932928, sign: true }); + data.append(FP8x23 { mag: 1006632960, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_pos/output_0.cairo b/tests/nodes/tril_fp8x23_pos/output_0.cairo new file mode 100644 index 000000000..4135f6308 --- /dev/null +++ b/tests/nodes/tril_fp8x23_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 587202560, sign: true }); + data.append(FP8x23 { mag: 889192448, sign: false }); + data.append(FP8x23 { mag: 872415232, sign: true }); + data.append(FP8x23 { mag: 964689920, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: true }); + data.append(FP8x23 { mag: 310378496, sign: false }); + data.append(FP8x23 { mag: 947912704, sign: false }); + data.append(FP8x23 { mag: 998244352, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 226492416, sign: false }); + data.append(FP8x23 { mag: 343932928, sign: true }); + data.append(FP8x23 { mag: 1006632960, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_square.cairo b/tests/nodes/tril_fp8x23_square.cairo new file mode 100644 index 000000000..855fd749c --- /dev/null +++ b/tests/nodes/tril_fp8x23_square.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_tril_fp8x23_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_square/input_0.cairo b/tests/nodes/tril_fp8x23_square/input_0.cairo new file mode 100644 index 000000000..535e4516d --- /dev/null +++ b/tests/nodes/tril_fp8x23_square/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 822083584, sign: true }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: true }); + data.append(FP8x23 { mag: 335544320, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 369098752, sign: false }); + data.append(FP8x23 { mag: 687865856, sign: true }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1023410176, sign: false }); + data.append(FP8x23 { mag: 679477248, sign: true }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 637534208, sign: true }); + data.append(FP8x23 { mag: 109051904, sign: true }); + data.append(FP8x23 { mag: 335544320, sign: true }); + data.append(FP8x23 { mag: 243269632, sign: false }); + data.append(FP8x23 { mag: 511705088, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_square/output_0.cairo b/tests/nodes/tril_fp8x23_square/output_0.cairo new file mode 100644 index 000000000..e90debfdb --- /dev/null +++ b/tests/nodes/tril_fp8x23_square/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 822083584, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 335544320, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 687865856, sign: true }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 637534208, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 335544320, sign: true }); + data.append(FP8x23 { mag: 243269632, sign: false }); + data.append(FP8x23 { mag: 511705088, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_square_neg.cairo b/tests/nodes/tril_fp8x23_square_neg.cairo new file mode 100644 index 000000000..3cb29579b --- /dev/null +++ b/tests/nodes/tril_fp8x23_square_neg.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_tril_fp8x23_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_square_neg/input_0.cairo b/tests/nodes/tril_fp8x23_square_neg/input_0.cairo new file mode 100644 index 000000000..148b2a3fd --- /dev/null +++ b/tests/nodes/tril_fp8x23_square_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 243269632, sign: false }); + data.append(FP8x23 { mag: 520093696, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 452984832, sign: false }); + data.append(FP8x23 { mag: 746586112, sign: false }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 838860800, sign: true }); + data.append(FP8x23 { mag: 478150656, sign: true }); + data.append(FP8x23 { mag: 989855744, sign: true }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 763363328, sign: false }); + data.append(FP8x23 { mag: 528482304, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 545259520, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: true }); + data.append(FP8x23 { mag: 704643072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_square_neg/output_0.cairo b/tests/nodes/tril_fp8x23_square_neg/output_0.cairo new file mode 100644 index 000000000..6b3328517 --- /dev/null +++ b/tests/nodes/tril_fp8x23_square_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 746586112, sign: false }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 763363328, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 545259520, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_zero.cairo b/tests/nodes/tril_fp8x23_zero.cairo new file mode 100644 index 000000000..e4f9dafbb --- /dev/null +++ b/tests/nodes/tril_fp8x23_zero.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_tril_fp8x23_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_fp8x23_zero/input_0.cairo b/tests/nodes/tril_fp8x23_zero/input_0.cairo new file mode 100644 index 000000000..0212a6f2b --- /dev/null +++ b/tests/nodes/tril_fp8x23_zero/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_fp8x23_zero/output_0.cairo b/tests/nodes/tril_fp8x23_zero/output_0.cairo new file mode 100644 index 000000000..a21173947 --- /dev/null +++ b/tests/nodes/tril_fp8x23_zero/output_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32.cairo b/tests/nodes/tril_i32.cairo new file mode 100644 index 000000000..2ea659012 --- /dev/null +++ b/tests/nodes/tril_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_tril_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32/input_0.cairo b/tests/nodes/tril_i32/input_0.cairo new file mode 100644 index 000000000..9d6683521 --- /dev/null +++ b/tests/nodes/tril_i32/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 85, sign: false }); + data.append(i32 { mag: 107, sign: false }); + data.append(i32 { mag: 31, sign: true }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 31, sign: true }); + data.append(i32 { mag: 9, sign: true }); + data.append(i32 { mag: 82, sign: true }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 64, sign: true }); + data.append(i32 { mag: 62, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 98, sign: false }); + data.append(i32 { mag: 96, sign: false }); + data.append(i32 { mag: 116, sign: false }); + data.append(i32 { mag: 78, sign: false }); + data.append(i32 { mag: 111, sign: false }); + data.append(i32 { mag: 98, sign: true }); + data.append(i32 { mag: 34, sign: false }); + data.append(i32 { mag: 51, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32/output_0.cairo b/tests/nodes/tril_i32/output_0.cairo new file mode 100644 index 000000000..6fb4b8cd3 --- /dev/null +++ b/tests/nodes/tril_i32/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 85, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 9, sign: true }); + data.append(i32 { mag: 82, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 62, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 98, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 78, sign: false }); + data.append(i32 { mag: 111, sign: false }); + data.append(i32 { mag: 98, sign: true }); + data.append(i32 { mag: 34, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_one_row.cairo b/tests/nodes/tril_i32_one_row.cairo new file mode 100644 index 000000000..1e78d565a --- /dev/null +++ b/tests/nodes/tril_i32_one_row.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_tril_i32_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_one_row/input_0.cairo b/tests/nodes/tril_i32_one_row/input_0.cairo new file mode 100644 index 000000000..d76cc580a --- /dev/null +++ b/tests/nodes/tril_i32_one_row/input_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 51, sign: false }); + data.append(i32 { mag: 114, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 67, sign: true }); + data.append(i32 { mag: 10, sign: true }); + data.append(i32 { mag: 53, sign: true }); + data.append(i32 { mag: 58, sign: true }); + data.append(i32 { mag: 71, sign: false }); + data.append(i32 { mag: 36, sign: false }); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 76, sign: false }); + data.append(i32 { mag: 58, sign: false }); + data.append(i32 { mag: 98, sign: true }); + data.append(i32 { mag: 69, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_one_row/output_0.cairo b/tests/nodes/tril_i32_one_row/output_0.cairo new file mode 100644 index 000000000..cdbbe6273 --- /dev/null +++ b/tests/nodes/tril_i32_one_row/output_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 10, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_out_neg.cairo b/tests/nodes/tril_i32_out_neg.cairo new file mode 100644 index 000000000..c532a4eb9 --- /dev/null +++ b/tests/nodes/tril_i32_out_neg.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_tril_i32_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_out_neg/input_0.cairo b/tests/nodes/tril_i32_out_neg/input_0.cairo new file mode 100644 index 000000000..e25505d7c --- /dev/null +++ b/tests/nodes/tril_i32_out_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 83, sign: true }); + data.append(i32 { mag: 36, sign: true }); + data.append(i32 { mag: 90, sign: true }); + data.append(i32 { mag: 12, sign: true }); + data.append(i32 { mag: 24, sign: false }); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 119, sign: true }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 52, sign: false }); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 40, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 93, sign: true }); + data.append(i32 { mag: 71, sign: false }); + data.append(i32 { mag: 123, sign: true }); + data.append(i32 { mag: 107, sign: false }); + data.append(i32 { mag: 63, sign: false }); + data.append(i32 { mag: 100, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_out_neg/output_0.cairo b/tests/nodes/tril_i32_out_neg/output_0.cairo new file mode 100644 index 000000000..9c3c97fbb --- /dev/null +++ b/tests/nodes/tril_i32_out_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_out_pos.cairo b/tests/nodes/tril_i32_out_pos.cairo new file mode 100644 index 000000000..0666c50d9 --- /dev/null +++ b/tests/nodes/tril_i32_out_pos.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_tril_i32_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_out_pos/input_0.cairo b/tests/nodes/tril_i32_out_pos/input_0.cairo new file mode 100644 index 000000000..557a5df26 --- /dev/null +++ b/tests/nodes/tril_i32_out_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 103, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 34, sign: true }); + data.append(i32 { mag: 43, sign: true }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 106, sign: true }); + data.append(i32 { mag: 104, sign: true }); + data.append(i32 { mag: 105, sign: true }); + data.append(i32 { mag: 97, sign: true }); + data.append(i32 { mag: 126, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 120, sign: false }); + data.append(i32 { mag: 70, sign: true }); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 14, sign: true }); + data.append(i32 { mag: 11, sign: true }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 58, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_out_pos/output_0.cairo b/tests/nodes/tril_i32_out_pos/output_0.cairo new file mode 100644 index 000000000..e12ad85ac --- /dev/null +++ b/tests/nodes/tril_i32_out_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 103, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 34, sign: true }); + data.append(i32 { mag: 43, sign: true }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 106, sign: true }); + data.append(i32 { mag: 104, sign: true }); + data.append(i32 { mag: 105, sign: true }); + data.append(i32 { mag: 97, sign: true }); + data.append(i32 { mag: 126, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 120, sign: false }); + data.append(i32 { mag: 70, sign: true }); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 14, sign: true }); + data.append(i32 { mag: 11, sign: true }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 58, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_pos.cairo b/tests/nodes/tril_i32_pos.cairo new file mode 100644 index 000000000..e5ad051a1 --- /dev/null +++ b/tests/nodes/tril_i32_pos.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_tril_i32_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_pos/input_0.cairo b/tests/nodes/tril_i32_pos/input_0.cairo new file mode 100644 index 000000000..a12fda178 --- /dev/null +++ b/tests/nodes/tril_i32_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 61, sign: true }); + data.append(i32 { mag: 38, sign: true }); + data.append(i32 { mag: 71, sign: false }); + data.append(i32 { mag: 43, sign: false }); + data.append(i32 { mag: 63, sign: true }); + data.append(i32 { mag: 107, sign: false }); + data.append(i32 { mag: 47, sign: false }); + data.append(i32 { mag: 74, sign: true }); + data.append(i32 { mag: 32, sign: true }); + data.append(i32 { mag: 51, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 89, sign: true }); + data.append(i32 { mag: 110, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 93, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 65, sign: false }); + data.append(i32 { mag: 99, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_pos/output_0.cairo b/tests/nodes/tril_i32_pos/output_0.cairo new file mode 100644 index 000000000..c2ae9950b --- /dev/null +++ b/tests/nodes/tril_i32_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 61, sign: true }); + data.append(i32 { mag: 38, sign: true }); + data.append(i32 { mag: 71, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 107, sign: false }); + data.append(i32 { mag: 47, sign: false }); + data.append(i32 { mag: 74, sign: true }); + data.append(i32 { mag: 32, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 89, sign: true }); + data.append(i32 { mag: 110, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 93, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 65, sign: false }); + data.append(i32 { mag: 99, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_square.cairo b/tests/nodes/tril_i32_square.cairo new file mode 100644 index 000000000..b7c5df14f --- /dev/null +++ b/tests/nodes/tril_i32_square.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_tril_i32_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_square/input_0.cairo b/tests/nodes/tril_i32_square/input_0.cairo new file mode 100644 index 000000000..8056a7b1a --- /dev/null +++ b/tests/nodes/tril_i32_square/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 43, sign: true }); + data.append(i32 { mag: 24, sign: true }); + data.append(i32 { mag: 63, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 101, sign: true }); + data.append(i32 { mag: 90, sign: false }); + data.append(i32 { mag: 50, sign: false }); + data.append(i32 { mag: 66, sign: false }); + data.append(i32 { mag: 120, sign: true }); + data.append(i32 { mag: 15, sign: true }); + data.append(i32 { mag: 24, sign: true }); + data.append(i32 { mag: 123, sign: true }); + data.append(i32 { mag: 16, sign: true }); + data.append(i32 { mag: 96, sign: false }); + data.append(i32 { mag: 33, sign: false }); + data.append(i32 { mag: 63, sign: true }); + data.append(i32 { mag: 117, sign: true }); + data.append(i32 { mag: 52, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_square/output_0.cairo b/tests/nodes/tril_i32_square/output_0.cairo new file mode 100644 index 000000000..f7080b89a --- /dev/null +++ b/tests/nodes/tril_i32_square/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 43, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 101, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 50, sign: false }); + data.append(i32 { mag: 66, sign: false }); + data.append(i32 { mag: 120, sign: true }); + data.append(i32 { mag: 15, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 16, sign: true }); + data.append(i32 { mag: 96, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 63, sign: true }); + data.append(i32 { mag: 117, sign: true }); + data.append(i32 { mag: 52, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_square_neg.cairo b/tests/nodes/tril_i32_square_neg.cairo new file mode 100644 index 000000000..0f4e2e1aa --- /dev/null +++ b/tests/nodes/tril_i32_square_neg.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_tril_i32_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_square_neg/input_0.cairo b/tests/nodes/tril_i32_square_neg/input_0.cairo new file mode 100644 index 000000000..ec9d40044 --- /dev/null +++ b/tests/nodes/tril_i32_square_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 114, sign: true }); + data.append(i32 { mag: 68, sign: false }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 105, sign: false }); + data.append(i32 { mag: 115, sign: true }); + data.append(i32 { mag: 54, sign: true }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 83, sign: true }); + data.append(i32 { mag: 41, sign: true }); + data.append(i32 { mag: 66, sign: false }); + data.append(i32 { mag: 34, sign: false }); + data.append(i32 { mag: 67, sign: false }); + data.append(i32 { mag: 57, sign: false }); + data.append(i32 { mag: 58, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 115, sign: true }); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_square_neg/output_0.cairo b/tests/nodes/tril_i32_square_neg/output_0.cairo new file mode 100644 index 000000000..92259ca51 --- /dev/null +++ b/tests/nodes/tril_i32_square_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 54, sign: true }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 67, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 115, sign: true }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_zero.cairo b/tests/nodes/tril_i32_zero.cairo new file mode 100644 index 000000000..4c6736a62 --- /dev/null +++ b/tests/nodes/tril_i32_zero.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_tril_i32_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i32_zero/input_0.cairo b/tests/nodes/tril_i32_zero/input_0.cairo new file mode 100644 index 000000000..a01ddf661 --- /dev/null +++ b/tests/nodes/tril_i32_zero/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i32_zero/output_0.cairo b/tests/nodes/tril_i32_zero/output_0.cairo new file mode 100644 index 000000000..20f0b375e --- /dev/null +++ b/tests/nodes/tril_i32_zero/output_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8.cairo b/tests/nodes/tril_i8.cairo new file mode 100644 index 000000000..14d1e869f --- /dev/null +++ b/tests/nodes/tril_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_tril_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8/input_0.cairo b/tests/nodes/tril_i8/input_0.cairo new file mode 100644 index 000000000..274403e3d --- /dev/null +++ b/tests/nodes/tril_i8/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 98, sign: true }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 50, sign: true }); + data.append(i8 { mag: 92, sign: true }); + data.append(i8 { mag: 56, sign: true }); + data.append(i8 { mag: 84, sign: true }); + data.append(i8 { mag: 65, sign: true }); + data.append(i8 { mag: 88, sign: true }); + data.append(i8 { mag: 68, sign: true }); + data.append(i8 { mag: 40, sign: false }); + data.append(i8 { mag: 121, sign: true }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 41, sign: true }); + data.append(i8 { mag: 62, sign: false }); + data.append(i8 { mag: 68, sign: false }); + data.append(i8 { mag: 73, sign: false }); + data.append(i8 { mag: 111, sign: true }); + data.append(i8 { mag: 27, sign: false }); + data.append(i8 { mag: 75, sign: false }); + data.append(i8 { mag: 6, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8/output_0.cairo b/tests/nodes/tril_i8/output_0.cairo new file mode 100644 index 000000000..25438086d --- /dev/null +++ b/tests/nodes/tril_i8/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 98, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 84, sign: true }); + data.append(i8 { mag: 65, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 121, sign: true }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 41, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 73, sign: false }); + data.append(i8 { mag: 111, sign: true }); + data.append(i8 { mag: 27, sign: false }); + data.append(i8 { mag: 75, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_neg.cairo b/tests/nodes/tril_i8_neg.cairo new file mode 100644 index 000000000..8476087ac --- /dev/null +++ b/tests/nodes/tril_i8_neg.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_tril_i8_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_neg/input_0.cairo b/tests/nodes/tril_i8_neg/input_0.cairo new file mode 100644 index 000000000..e0fe10199 --- /dev/null +++ b/tests/nodes/tril_i8_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 67, sign: true }); + data.append(i8 { mag: 99, sign: true }); + data.append(i8 { mag: 95, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 13, sign: true }); + data.append(i8 { mag: 113, sign: true }); + data.append(i8 { mag: 68, sign: true }); + data.append(i8 { mag: 99, sign: false }); + data.append(i8 { mag: 79, sign: false }); + data.append(i8 { mag: 20, sign: false }); + data.append(i8 { mag: 88, sign: false }); + data.append(i8 { mag: 120, sign: false }); + data.append(i8 { mag: 65, sign: true }); + data.append(i8 { mag: 112, sign: true }); + data.append(i8 { mag: 104, sign: true }); + data.append(i8 { mag: 106, sign: true }); + data.append(i8 { mag: 117, sign: true }); + data.append(i8 { mag: 8, sign: true }); + data.append(i8 { mag: 17, sign: true }); + data.append(i8 { mag: 65, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_neg/output_0.cairo b/tests/nodes/tril_i8_neg/output_0.cairo new file mode 100644 index 000000000..f6a35d821 --- /dev/null +++ b/tests/nodes/tril_i8_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 113, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 88, sign: false }); + data.append(i8 { mag: 120, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 106, sign: true }); + data.append(i8 { mag: 117, sign: true }); + data.append(i8 { mag: 8, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_one_row.cairo b/tests/nodes/tril_i8_one_row.cairo new file mode 100644 index 000000000..6253e81da --- /dev/null +++ b/tests/nodes/tril_i8_one_row.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_tril_i8_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_one_row/input_0.cairo b/tests/nodes/tril_i8_one_row/input_0.cairo new file mode 100644 index 000000000..86753f932 --- /dev/null +++ b/tests/nodes/tril_i8_one_row/input_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 35, sign: true }); + data.append(i8 { mag: 49, sign: true }); + data.append(i8 { mag: 45, sign: true }); + data.append(i8 { mag: 127, sign: true }); + data.append(i8 { mag: 50, sign: false }); + data.append(i8 { mag: 47, sign: true }); + data.append(i8 { mag: 24, sign: true }); + data.append(i8 { mag: 68, sign: false }); + data.append(i8 { mag: 31, sign: true }); + data.append(i8 { mag: 119, sign: true }); + data.append(i8 { mag: 59, sign: true }); + data.append(i8 { mag: 73, sign: false }); + data.append(i8 { mag: 28, sign: false }); + data.append(i8 { mag: 58, sign: true }); + data.append(i8 { mag: 7, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_one_row/output_0.cairo b/tests/nodes/tril_i8_one_row/output_0.cairo new file mode 100644 index 000000000..30cc76297 --- /dev/null +++ b/tests/nodes/tril_i8_one_row/output_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 35, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 47, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 59, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_out_neg.cairo b/tests/nodes/tril_i8_out_neg.cairo new file mode 100644 index 000000000..491b811ee --- /dev/null +++ b/tests/nodes/tril_i8_out_neg.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_tril_i8_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_out_neg/input_0.cairo b/tests/nodes/tril_i8_out_neg/input_0.cairo new file mode 100644 index 000000000..4186c67c5 --- /dev/null +++ b/tests/nodes/tril_i8_out_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 13, sign: false }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 49, sign: true }); + data.append(i8 { mag: 8, sign: true }); + data.append(i8 { mag: 100, sign: true }); + data.append(i8 { mag: 57, sign: true }); + data.append(i8 { mag: 94, sign: false }); + data.append(i8 { mag: 122, sign: false }); + data.append(i8 { mag: 106, sign: true }); + data.append(i8 { mag: 10, sign: true }); + data.append(i8 { mag: 57, sign: true }); + data.append(i8 { mag: 71, sign: false }); + data.append(i8 { mag: 121, sign: false }); + data.append(i8 { mag: 125, sign: false }); + data.append(i8 { mag: 31, sign: false }); + data.append(i8 { mag: 82, sign: false }); + data.append(i8 { mag: 57, sign: true }); + data.append(i8 { mag: 21, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_out_neg/output_0.cairo b/tests/nodes/tril_i8_out_neg/output_0.cairo new file mode 100644 index 000000000..aa1512f92 --- /dev/null +++ b/tests/nodes/tril_i8_out_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_out_pos.cairo b/tests/nodes/tril_i8_out_pos.cairo new file mode 100644 index 000000000..ad8ccdbe7 --- /dev/null +++ b/tests/nodes/tril_i8_out_pos.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_tril_i8_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_out_pos/input_0.cairo b/tests/nodes/tril_i8_out_pos/input_0.cairo new file mode 100644 index 000000000..3304c0003 --- /dev/null +++ b/tests/nodes/tril_i8_out_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 84, sign: true }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 107, sign: false }); + data.append(i8 { mag: 78, sign: true }); + data.append(i8 { mag: 100, sign: true }); + data.append(i8 { mag: 90, sign: true }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 122, sign: false }); + data.append(i8 { mag: 97, sign: false }); + data.append(i8 { mag: 92, sign: true }); + data.append(i8 { mag: 63, sign: false }); + data.append(i8 { mag: 27, sign: false }); + data.append(i8 { mag: 83, sign: true }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 75, sign: true }); + data.append(i8 { mag: 51, sign: true }); + data.append(i8 { mag: 61, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 25, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_out_pos/output_0.cairo b/tests/nodes/tril_i8_out_pos/output_0.cairo new file mode 100644 index 000000000..f03959153 --- /dev/null +++ b/tests/nodes/tril_i8_out_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 84, sign: true }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 107, sign: false }); + data.append(i8 { mag: 78, sign: true }); + data.append(i8 { mag: 100, sign: true }); + data.append(i8 { mag: 90, sign: true }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 122, sign: false }); + data.append(i8 { mag: 97, sign: false }); + data.append(i8 { mag: 92, sign: true }); + data.append(i8 { mag: 63, sign: false }); + data.append(i8 { mag: 27, sign: false }); + data.append(i8 { mag: 83, sign: true }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 75, sign: true }); + data.append(i8 { mag: 51, sign: true }); + data.append(i8 { mag: 61, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 25, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_pos.cairo b/tests/nodes/tril_i8_pos.cairo new file mode 100644 index 000000000..4ac910642 --- /dev/null +++ b/tests/nodes/tril_i8_pos.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_tril_i8_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_pos/input_0.cairo b/tests/nodes/tril_i8_pos/input_0.cairo new file mode 100644 index 000000000..5e3ec5960 --- /dev/null +++ b/tests/nodes/tril_i8_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 45, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 117, sign: true }); + data.append(i8 { mag: 25, sign: false }); + data.append(i8 { mag: 33, sign: false }); + data.append(i8 { mag: 104, sign: true }); + data.append(i8 { mag: 70, sign: true }); + data.append(i8 { mag: 52, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 84, sign: false }); + data.append(i8 { mag: 73, sign: true }); + data.append(i8 { mag: 22, sign: false }); + data.append(i8 { mag: 113, sign: true }); + data.append(i8 { mag: 21, sign: true }); + data.append(i8 { mag: 32, sign: true }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 73, sign: false }); + data.append(i8 { mag: 15, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_pos/output_0.cairo b/tests/nodes/tril_i8_pos/output_0.cairo new file mode 100644 index 000000000..c770d518d --- /dev/null +++ b/tests/nodes/tril_i8_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 45, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 25, sign: false }); + data.append(i8 { mag: 33, sign: false }); + data.append(i8 { mag: 104, sign: true }); + data.append(i8 { mag: 70, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 84, sign: false }); + data.append(i8 { mag: 73, sign: true }); + data.append(i8 { mag: 22, sign: false }); + data.append(i8 { mag: 113, sign: true }); + data.append(i8 { mag: 21, sign: true }); + data.append(i8 { mag: 32, sign: true }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 73, sign: false }); + data.append(i8 { mag: 15, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_square.cairo b/tests/nodes/tril_i8_square.cairo new file mode 100644 index 000000000..9b94e0538 --- /dev/null +++ b/tests/nodes/tril_i8_square.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_tril_i8_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_square/input_0.cairo b/tests/nodes/tril_i8_square/input_0.cairo new file mode 100644 index 000000000..ffbe08a4e --- /dev/null +++ b/tests/nodes/tril_i8_square/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 32, sign: false }); + data.append(i8 { mag: 39, sign: false }); + data.append(i8 { mag: 80, sign: true }); + data.append(i8 { mag: 108, sign: true }); + data.append(i8 { mag: 78, sign: false }); + data.append(i8 { mag: 69, sign: true }); + data.append(i8 { mag: 95, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 81, sign: false }); + data.append(i8 { mag: 88, sign: true }); + data.append(i8 { mag: 89, sign: true }); + data.append(i8 { mag: 10, sign: true }); + data.append(i8 { mag: 126, sign: false }); + data.append(i8 { mag: 53, sign: true }); + data.append(i8 { mag: 36, sign: true }); + data.append(i8 { mag: 14, sign: true }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 20, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_square/output_0.cairo b/tests/nodes/tril_i8_square/output_0.cairo new file mode 100644 index 000000000..585320c0a --- /dev/null +++ b/tests/nodes/tril_i8_square/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 32, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 108, sign: true }); + data.append(i8 { mag: 78, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 95, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 81, sign: false }); + data.append(i8 { mag: 88, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 126, sign: false }); + data.append(i8 { mag: 53, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 14, sign: true }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 20, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_square_neg.cairo b/tests/nodes/tril_i8_square_neg.cairo new file mode 100644 index 000000000..4a503adc2 --- /dev/null +++ b/tests/nodes/tril_i8_square_neg.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_tril_i8_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_square_neg/input_0.cairo b/tests/nodes/tril_i8_square_neg/input_0.cairo new file mode 100644 index 000000000..fa69673e4 --- /dev/null +++ b/tests/nodes/tril_i8_square_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 8, sign: true }); + data.append(i8 { mag: 30, sign: true }); + data.append(i8 { mag: 44, sign: false }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 34, sign: true }); + data.append(i8 { mag: 68, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 105, sign: false }); + data.append(i8 { mag: 56, sign: true }); + data.append(i8 { mag: 97, sign: false }); + data.append(i8 { mag: 92, sign: false }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 117, sign: false }); + data.append(i8 { mag: 35, sign: false }); + data.append(i8 { mag: 72, sign: true }); + data.append(i8 { mag: 103, sign: false }); + data.append(i8 { mag: 73, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_square_neg/output_0.cairo b/tests/nodes/tril_i8_square_neg/output_0.cairo new file mode 100644 index 000000000..7c29fa4c6 --- /dev/null +++ b/tests/nodes/tril_i8_square_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 68, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 72, sign: true }); + data.append(i8 { mag: 103, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_zero.cairo b/tests/nodes/tril_i8_zero.cairo new file mode 100644 index 000000000..a18a2b5b3 --- /dev/null +++ b/tests/nodes/tril_i8_zero.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_tril_i8_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_i8_zero/input_0.cairo b/tests/nodes/tril_i8_zero/input_0.cairo new file mode 100644 index 000000000..90e2d4e74 --- /dev/null +++ b/tests/nodes/tril_i8_zero/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_i8_zero/output_0.cairo b/tests/nodes/tril_i8_zero/output_0.cairo new file mode 100644 index 000000000..07bfa2a91 --- /dev/null +++ b/tests/nodes/tril_i8_zero/output_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_neg_i32.cairo b/tests/nodes/tril_neg_i32.cairo new file mode 100644 index 000000000..094d6b8de --- /dev/null +++ b/tests/nodes/tril_neg_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_tril_neg_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_neg_i32/input_0.cairo b/tests/nodes/tril_neg_i32/input_0.cairo new file mode 100644 index 000000000..a7fc7babe --- /dev/null +++ b/tests/nodes/tril_neg_i32/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 67, sign: false }); + data.append(i32 { mag: 102, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 75, sign: false }); + data.append(i32 { mag: 86, sign: false }); + data.append(i32 { mag: 30, sign: true }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 124, sign: false }); + data.append(i32 { mag: 58, sign: false }); + data.append(i32 { mag: 72, sign: true }); + data.append(i32 { mag: 72, sign: true }); + data.append(i32 { mag: 123, sign: true }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 109, sign: false }); + data.append(i32 { mag: 84, sign: true }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 123, sign: false }); + data.append(i32 { mag: 44, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_neg_i32/output_0.cairo b/tests/nodes/tril_neg_i32/output_0.cairo new file mode 100644 index 000000000..26d768340 --- /dev/null +++ b/tests/nodes/tril_neg_i32/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 30, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 72, sign: true }); + data.append(i32 { mag: 123, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 109, sign: false }); + data.append(i32 { mag: 84, sign: true }); + data.append(i32 { mag: 117, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32.cairo b/tests/nodes/tril_u32.cairo new file mode 100644 index 000000000..5b4f23093 --- /dev/null +++ b/tests/nodes/tril_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_tril_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32/input_0.cairo b/tests/nodes/tril_u32/input_0.cairo new file mode 100644 index 000000000..7a4d31b58 --- /dev/null +++ b/tests/nodes/tril_u32/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(182); + data.append(80); + data.append(147); + data.append(74); + data.append(49); + data.append(129); + data.append(84); + data.append(164); + data.append(205); + data.append(48); + data.append(150); + data.append(158); + data.append(16); + data.append(127); + data.append(250); + data.append(55); + data.append(177); + data.append(114); + data.append(231); + data.append(47); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32/output_0.cairo b/tests/nodes/tril_u32/output_0.cairo new file mode 100644 index 000000000..b964485cb --- /dev/null +++ b/tests/nodes/tril_u32/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(182); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(129); + data.append(84); + data.append(0); + data.append(0); + data.append(0); + data.append(150); + data.append(158); + data.append(16); + data.append(0); + data.append(0); + data.append(55); + data.append(177); + data.append(114); + data.append(231); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_neg.cairo b/tests/nodes/tril_u32_neg.cairo new file mode 100644 index 000000000..dad3881c6 --- /dev/null +++ b/tests/nodes/tril_u32_neg.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_tril_u32_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_neg/input_0.cairo b/tests/nodes/tril_u32_neg/input_0.cairo new file mode 100644 index 000000000..b2cc07603 --- /dev/null +++ b/tests/nodes/tril_u32_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(112); + data.append(12); + data.append(149); + data.append(247); + data.append(144); + data.append(52); + data.append(161); + data.append(15); + data.append(89); + data.append(32); + data.append(118); + data.append(122); + data.append(56); + data.append(100); + data.append(207); + data.append(176); + data.append(97); + data.append(234); + data.append(73); + data.append(53); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_neg/output_0.cairo b/tests/nodes/tril_u32_neg/output_0.cairo new file mode 100644 index 000000000..3cbf289f1 --- /dev/null +++ b/tests/nodes/tril_u32_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(52); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(118); + data.append(122); + data.append(0); + data.append(0); + data.append(0); + data.append(176); + data.append(97); + data.append(234); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_one_row.cairo b/tests/nodes/tril_u32_one_row.cairo new file mode 100644 index 000000000..7aec026e5 --- /dev/null +++ b/tests/nodes/tril_u32_one_row.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_tril_u32_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_one_row/input_0.cairo b/tests/nodes/tril_u32_one_row/input_0.cairo new file mode 100644 index 000000000..ce0684b5c --- /dev/null +++ b/tests/nodes/tril_u32_one_row/input_0.cairo @@ -0,0 +1,28 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(68); + data.append(176); + data.append(238); + data.append(164); + data.append(157); + data.append(211); + data.append(97); + data.append(132); + data.append(224); + data.append(245); + data.append(118); + data.append(25); + data.append(196); + data.append(43); + data.append(124); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_one_row/output_0.cairo b/tests/nodes/tril_u32_one_row/output_0.cairo new file mode 100644 index 000000000..46b0caf6e --- /dev/null +++ b/tests/nodes/tril_u32_one_row/output_0.cairo @@ -0,0 +1,28 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(68); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(211); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(118); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_out_neg.cairo b/tests/nodes/tril_u32_out_neg.cairo new file mode 100644 index 000000000..714fea187 --- /dev/null +++ b/tests/nodes/tril_u32_out_neg.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_tril_u32_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_out_neg/input_0.cairo b/tests/nodes/tril_u32_out_neg/input_0.cairo new file mode 100644 index 000000000..a0880e9bf --- /dev/null +++ b/tests/nodes/tril_u32_out_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(66); + data.append(139); + data.append(229); + data.append(194); + data.append(56); + data.append(188); + data.append(51); + data.append(197); + data.append(237); + data.append(240); + data.append(177); + data.append(112); + data.append(114); + data.append(235); + data.append(200); + data.append(197); + data.append(57); + data.append(67); + data.append(41); + data.append(62); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_out_neg/output_0.cairo b/tests/nodes/tril_u32_out_neg/output_0.cairo new file mode 100644 index 000000000..fff9bce25 --- /dev/null +++ b/tests/nodes/tril_u32_out_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + 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); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_out_pos.cairo b/tests/nodes/tril_u32_out_pos.cairo new file mode 100644 index 000000000..5e5b421e9 --- /dev/null +++ b/tests/nodes/tril_u32_out_pos.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_tril_u32_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_out_pos/input_0.cairo b/tests/nodes/tril_u32_out_pos/input_0.cairo new file mode 100644 index 000000000..909f53a15 --- /dev/null +++ b/tests/nodes/tril_u32_out_pos/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(111); + data.append(50); + data.append(147); + data.append(251); + data.append(54); + data.append(8); + data.append(96); + data.append(236); + data.append(214); + data.append(32); + data.append(100); + data.append(220); + data.append(220); + data.append(137); + data.append(66); + data.append(197); + data.append(45); + data.append(126); + data.append(230); + data.append(72); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_out_pos/output_0.cairo b/tests/nodes/tril_u32_out_pos/output_0.cairo new file mode 100644 index 000000000..f6cf0bec3 --- /dev/null +++ b/tests/nodes/tril_u32_out_pos/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(111); + data.append(50); + data.append(147); + data.append(251); + data.append(54); + data.append(8); + data.append(96); + data.append(236); + data.append(214); + data.append(32); + data.append(100); + data.append(220); + data.append(220); + data.append(137); + data.append(66); + data.append(197); + data.append(45); + data.append(126); + data.append(230); + data.append(72); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_pos.cairo b/tests/nodes/tril_u32_pos.cairo new file mode 100644 index 000000000..96343eebd --- /dev/null +++ b/tests/nodes/tril_u32_pos.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_tril_u32_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_pos/input_0.cairo b/tests/nodes/tril_u32_pos/input_0.cairo new file mode 100644 index 000000000..8c070c414 --- /dev/null +++ b/tests/nodes/tril_u32_pos/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(83); + data.append(229); + data.append(59); + data.append(240); + data.append(114); + data.append(209); + data.append(118); + data.append(37); + data.append(203); + data.append(215); + data.append(49); + data.append(166); + data.append(119); + data.append(199); + data.append(190); + data.append(187); + data.append(3); + data.append(24); + data.append(217); + data.append(121); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_pos/output_0.cairo b/tests/nodes/tril_u32_pos/output_0.cairo new file mode 100644 index 000000000..c8eeefadb --- /dev/null +++ b/tests/nodes/tril_u32_pos/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(83); + data.append(229); + data.append(59); + data.append(0); + data.append(0); + data.append(209); + data.append(118); + data.append(37); + data.append(203); + data.append(0); + data.append(49); + data.append(166); + data.append(119); + data.append(199); + data.append(190); + data.append(187); + data.append(3); + data.append(24); + data.append(217); + data.append(121); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_square.cairo b/tests/nodes/tril_u32_square.cairo new file mode 100644 index 000000000..15de58346 --- /dev/null +++ b/tests/nodes/tril_u32_square.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_tril_u32_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_square/input_0.cairo b/tests/nodes/tril_u32_square/input_0.cairo new file mode 100644 index 000000000..4368056aa --- /dev/null +++ b/tests/nodes/tril_u32_square/input_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(14); + data.append(93); + data.append(16); + data.append(34); + data.append(216); + data.append(129); + data.append(132); + data.append(143); + data.append(161); + data.append(9); + data.append(45); + data.append(114); + data.append(250); + data.append(157); + data.append(239); + data.append(32); + data.append(147); + data.append(90); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_square/output_0.cairo b/tests/nodes/tril_u32_square/output_0.cairo new file mode 100644 index 000000000..b2aea771b --- /dev/null +++ b/tests/nodes/tril_u32_square/output_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(14); + data.append(0); + data.append(0); + data.append(34); + data.append(216); + data.append(0); + data.append(132); + data.append(143); + data.append(161); + data.append(9); + data.append(0); + data.append(0); + data.append(250); + data.append(157); + data.append(0); + data.append(32); + data.append(147); + data.append(90); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_square_neg.cairo b/tests/nodes/tril_u32_square_neg.cairo new file mode 100644 index 000000000..10dafd1e9 --- /dev/null +++ b/tests/nodes/tril_u32_square_neg.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_tril_u32_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_square_neg/input_0.cairo b/tests/nodes/tril_u32_square_neg/input_0.cairo new file mode 100644 index 000000000..d22957815 --- /dev/null +++ b/tests/nodes/tril_u32_square_neg/input_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(124); + data.append(25); + data.append(157); + data.append(20); + data.append(170); + data.append(58); + data.append(130); + data.append(92); + data.append(31); + data.append(125); + data.append(67); + data.append(207); + data.append(191); + data.append(46); + data.append(237); + data.append(175); + data.append(177); + data.append(237); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_square_neg/output_0.cairo b/tests/nodes/tril_u32_square_neg/output_0.cairo new file mode 100644 index 000000000..e5be8ac9d --- /dev/null +++ b/tests/nodes/tril_u32_square_neg/output_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(20); + data.append(0); + data.append(0); + data.append(130); + data.append(92); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(191); + data.append(0); + data.append(0); + data.append(175); + data.append(177); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_zero.cairo b/tests/nodes/tril_u32_zero.cairo new file mode 100644 index 000000000..8bc5b5c52 --- /dev/null +++ b/tests/nodes/tril_u32_zero.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_tril_u32_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(false, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/tril_u32_zero/input_0.cairo b/tests/nodes/tril_u32_zero/input_0.cairo new file mode 100644 index 000000000..179e42905 --- /dev/null +++ b/tests/nodes/tril_u32_zero/input_0.cairo @@ -0,0 +1,13 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/tril_u32_zero/output_0.cairo b/tests/nodes/tril_u32_zero/output_0.cairo new file mode 100644 index 000000000..9b9157818 --- /dev/null +++ b/tests/nodes/tril_u32_zero/output_0.cairo @@ -0,0 +1,13 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16.cairo b/tests/nodes/triu_fp16x16.cairo new file mode 100644 index 000000000..c7ffaf2c8 --- /dev/null +++ b/tests/nodes/triu_fp16x16.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16/input_0.cairo b/tests/nodes/triu_fp16x16/input_0.cairo new file mode 100644 index 000000000..093aa443a --- /dev/null +++ b/tests/nodes/triu_fp16x16/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 6619136, sign: false }); + data.append(FP16x16 { mag: 4784128, sign: true }); + data.append(FP16x16 { mag: 1703936, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 2424832, sign: true }); + data.append(FP16x16 { mag: 2883584, sign: true }); + data.append(FP16x16 { mag: 1966080, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 7471104, sign: true }); + data.append(FP16x16 { mag: 6684672, sign: true }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 7733248, sign: true }); + data.append(FP16x16 { mag: 1900544, sign: false }); + data.append(FP16x16 { mag: 6684672, sign: false }); + data.append(FP16x16 { mag: 3866624, sign: true }); + data.append(FP16x16 { mag: 7733248, sign: false }); + data.append(FP16x16 { mag: 4849664, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16/output_0.cairo b/tests/nodes/triu_fp16x16/output_0.cairo new file mode 100644 index 000000000..1291521c0 --- /dev/null +++ b/tests/nodes/triu_fp16x16/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 6619136, sign: false }); + data.append(FP16x16 { mag: 4784128, sign: true }); + data.append(FP16x16 { mag: 1703936, sign: false }); + data.append(FP16x16 { mag: 5963776, sign: false }); + data.append(FP16x16 { mag: 2293760, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 2424832, sign: true }); + data.append(FP16x16 { mag: 2883584, sign: true }); + data.append(FP16x16 { mag: 1966080, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 6684672, sign: true }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 7733248, sign: true }); + 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: 7733248, sign: false }); + data.append(FP16x16 { mag: 4849664, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_neg.cairo b/tests/nodes/triu_fp16x16_neg.cairo new file mode 100644 index 000000000..41de73a83 --- /dev/null +++ b/tests/nodes/triu_fp16x16_neg.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_neg/input_0.cairo b/tests/nodes/triu_fp16x16_neg/input_0.cairo new file mode 100644 index 000000000..8adc56537 --- /dev/null +++ b/tests/nodes/triu_fp16x16_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 7274496, sign: true }); + data.append(FP16x16 { mag: 1835008, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 4194304, sign: true }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 2097152, sign: true }); + data.append(FP16x16 { mag: 917504, sign: true }); + data.append(FP16x16 { mag: 7208960, sign: false }); + data.append(FP16x16 { mag: 8323072, sign: true }); + data.append(FP16x16 { mag: 458752, sign: true }); + data.append(FP16x16 { mag: 6881280, sign: false }); + data.append(FP16x16 { mag: 3538944, sign: true }); + data.append(FP16x16 { mag: 7929856, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 5767168, sign: false }); + data.append(FP16x16 { mag: 6029312, sign: true }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 3211264, sign: true }); + data.append(FP16x16 { mag: 6488064, sign: false }); + data.append(FP16x16 { mag: 851968, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_neg/output_0.cairo b/tests/nodes/triu_fp16x16_neg/output_0.cairo new file mode 100644 index 000000000..c636e286c --- /dev/null +++ b/tests/nodes/triu_fp16x16_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 7274496, sign: true }); + data.append(FP16x16 { mag: 1835008, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 4194304, sign: true }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 2097152, sign: true }); + data.append(FP16x16 { mag: 917504, sign: true }); + data.append(FP16x16 { mag: 7208960, sign: false }); + data.append(FP16x16 { mag: 8323072, sign: true }); + data.append(FP16x16 { mag: 458752, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 3538944, sign: true }); + data.append(FP16x16 { mag: 7929856, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 5767168, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 3211264, sign: true }); + data.append(FP16x16 { mag: 6488064, sign: false }); + data.append(FP16x16 { mag: 851968, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_one_row.cairo b/tests/nodes/triu_fp16x16_one_row.cairo new file mode 100644 index 000000000..bc21034d6 --- /dev/null +++ b/tests/nodes/triu_fp16x16_one_row.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_one_row/input_0.cairo b/tests/nodes/triu_fp16x16_one_row/input_0.cairo new file mode 100644 index 000000000..2003b9a16 --- /dev/null +++ b/tests/nodes/triu_fp16x16_one_row/input_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 7471104, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: true }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 7602176, sign: true }); + data.append(FP16x16 { mag: 8060928, sign: false }); + data.append(FP16x16 { mag: 4194304, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 4718592, sign: true }); + data.append(FP16x16 { mag: 4784128, sign: false }); + data.append(FP16x16 { mag: 6094848, sign: false }); + data.append(FP16x16 { mag: 5636096, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_one_row/output_0.cairo b/tests/nodes/triu_fp16x16_one_row/output_0.cairo new file mode 100644 index 000000000..9b6c51709 --- /dev/null +++ b/tests/nodes/triu_fp16x16_one_row/output_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 7471104, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: true }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 7602176, sign: true }); + data.append(FP16x16 { mag: 8060928, sign: false }); + data.append(FP16x16 { mag: 4194304, sign: false }); + data.append(FP16x16 { mag: 2818048, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 4718592, sign: true }); + data.append(FP16x16 { mag: 4784128, sign: false }); + data.append(FP16x16 { mag: 6094848, sign: false }); + data.append(FP16x16 { mag: 5636096, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_out_neg.cairo b/tests/nodes/triu_fp16x16_out_neg.cairo new file mode 100644 index 000000000..6185387c1 --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_neg.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_out_neg/input_0.cairo b/tests/nodes/triu_fp16x16_out_neg/input_0.cairo new file mode 100644 index 000000000..60d63f605 --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 8257536, sign: true }); + data.append(FP16x16 { mag: 1835008, sign: true }); + data.append(FP16x16 { mag: 2424832, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: true }); + data.append(FP16x16 { mag: 786432, sign: true }); + data.append(FP16x16 { mag: 3604480, sign: false }); + data.append(FP16x16 { mag: 4849664, sign: true }); + data.append(FP16x16 { mag: 3735552, sign: false }); + data.append(FP16x16 { mag: 8323072, sign: true }); + data.append(FP16x16 { mag: 1703936, sign: true }); + data.append(FP16x16 { mag: 5963776, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: false }); + data.append(FP16x16 { mag: 7471104, sign: false }); + data.append(FP16x16 { mag: 7929856, sign: false }); + data.append(FP16x16 { mag: 1835008, sign: true }); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 8060928, sign: true }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 3014656, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_out_neg/output_0.cairo b/tests/nodes/triu_fp16x16_out_neg/output_0.cairo new file mode 100644 index 000000000..f2bb61147 --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 8257536, sign: true }); + data.append(FP16x16 { mag: 1835008, sign: true }); + data.append(FP16x16 { mag: 2424832, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: true }); + data.append(FP16x16 { mag: 786432, sign: true }); + data.append(FP16x16 { mag: 3604480, sign: false }); + data.append(FP16x16 { mag: 4849664, sign: true }); + data.append(FP16x16 { mag: 3735552, sign: false }); + data.append(FP16x16 { mag: 8323072, sign: true }); + data.append(FP16x16 { mag: 1703936, sign: true }); + data.append(FP16x16 { mag: 5963776, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: false }); + data.append(FP16x16 { mag: 7471104, sign: false }); + data.append(FP16x16 { mag: 7929856, sign: false }); + data.append(FP16x16 { mag: 1835008, sign: true }); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 8060928, sign: true }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 3014656, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_out_pos.cairo b/tests/nodes/triu_fp16x16_out_pos.cairo new file mode 100644 index 000000000..be223c646 --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_pos.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_out_pos/input_0.cairo b/tests/nodes/triu_fp16x16_out_pos/input_0.cairo new file mode 100644 index 000000000..f37edcab4 --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 2752512, sign: true }); + data.append(FP16x16 { mag: 5898240, sign: true }); + data.append(FP16x16 { mag: 7667712, sign: true }); + data.append(FP16x16 { mag: 7798784, sign: true }); + data.append(FP16x16 { mag: 1376256, sign: true }); + data.append(FP16x16 { mag: 5242880, sign: false }); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 4849664, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 6291456, sign: true }); + data.append(FP16x16 { mag: 7471104, sign: true }); + data.append(FP16x16 { mag: 4390912, sign: false }); + data.append(FP16x16 { mag: 8060928, sign: true }); + data.append(FP16x16 { mag: 6619136, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 720896, sign: true }); + data.append(FP16x16 { mag: 5373952, sign: false }); + data.append(FP16x16 { mag: 2490368, sign: false }); + data.append(FP16x16 { mag: 3997696, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_out_pos/output_0.cairo b/tests/nodes/triu_fp16x16_out_pos/output_0.cairo new file mode 100644 index 000000000..7bf937a2d --- /dev/null +++ b/tests/nodes/triu_fp16x16_out_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + 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: 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: 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: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_pos.cairo b/tests/nodes/triu_fp16x16_pos.cairo new file mode 100644 index 000000000..687b39ecb --- /dev/null +++ b/tests/nodes/triu_fp16x16_pos.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_pos/input_0.cairo b/tests/nodes/triu_fp16x16_pos/input_0.cairo new file mode 100644 index 000000000..6aae84a37 --- /dev/null +++ b/tests/nodes/triu_fp16x16_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 2686976, sign: false }); + data.append(FP16x16 { mag: 1703936, sign: true }); + data.append(FP16x16 { mag: 5570560, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 6815744, sign: true }); + data.append(FP16x16 { mag: 4521984, sign: true }); + data.append(FP16x16 { mag: 2228224, sign: true }); + data.append(FP16x16 { mag: 6553600, sign: true }); + data.append(FP16x16 { mag: 8126464, sign: true }); + data.append(FP16x16 { mag: 6356992, sign: false }); + data.append(FP16x16 { mag: 2031616, sign: false }); + data.append(FP16x16 { mag: 4128768, sign: false }); + data.append(FP16x16 { mag: 2883584, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 7667712, sign: false }); + data.append(FP16x16 { mag: 4980736, sign: false }); + data.append(FP16x16 { mag: 3145728, sign: true }); + data.append(FP16x16 { mag: 3538944, sign: true }); + data.append(FP16x16 { mag: 5570560, sign: false }); + data.append(FP16x16 { mag: 3342336, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_pos/output_0.cairo b/tests/nodes/triu_fp16x16_pos/output_0.cairo new file mode 100644 index 000000000..163e2eeb6 --- /dev/null +++ b/tests/nodes/triu_fp16x16_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 5570560, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 6815744, sign: true }); + 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: 8126464, sign: true }); + data.append(FP16x16 { mag: 6356992, 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: 7667712, 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 }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_square.cairo b/tests/nodes/triu_fp16x16_square.cairo new file mode 100644 index 000000000..65c4ee0ef --- /dev/null +++ b/tests/nodes/triu_fp16x16_square.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_square/input_0.cairo b/tests/nodes/triu_fp16x16_square/input_0.cairo new file mode 100644 index 000000000..32914e07d --- /dev/null +++ b/tests/nodes/triu_fp16x16_square/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3735552, sign: true }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 5767168, sign: true }); + data.append(FP16x16 { mag: 8192000, sign: true }); + data.append(FP16x16 { mag: 6422528, sign: true }); + data.append(FP16x16 { mag: 3276800, sign: false }); + data.append(FP16x16 { mag: 5111808, sign: true }); + data.append(FP16x16 { mag: 7536640, sign: false }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 2097152, sign: true }); + data.append(FP16x16 { mag: 786432, sign: true }); + data.append(FP16x16 { mag: 3801088, sign: true }); + data.append(FP16x16 { mag: 5767168, sign: true }); + data.append(FP16x16 { mag: 5570560, sign: true }); + data.append(FP16x16 { mag: 589824, sign: true }); + data.append(FP16x16 { mag: 6553600, sign: true }); + data.append(FP16x16 { mag: 6488064, sign: false }); + data.append(FP16x16 { mag: 4259840, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_square/output_0.cairo b/tests/nodes/triu_fp16x16_square/output_0.cairo new file mode 100644 index 000000000..93d2ce458 --- /dev/null +++ b/tests/nodes/triu_fp16x16_square/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3735552, sign: true }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 5767168, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 6422528, sign: true }); + data.append(FP16x16 { mag: 3276800, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 2097152, sign: true }); + data.append(FP16x16 { mag: 786432, sign: true }); + data.append(FP16x16 { mag: 3801088, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 5570560, sign: true }); + data.append(FP16x16 { mag: 589824, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4259840, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_square_neg.cairo b/tests/nodes/triu_fp16x16_square_neg.cairo new file mode 100644 index 000000000..141e68422 --- /dev/null +++ b/tests/nodes/triu_fp16x16_square_neg.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_square_neg/input_0.cairo b/tests/nodes/triu_fp16x16_square_neg/input_0.cairo new file mode 100644 index 000000000..8941f47c4 --- /dev/null +++ b/tests/nodes/triu_fp16x16_square_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1900544, sign: false }); + data.append(FP16x16 { mag: 5570560, sign: false }); + data.append(FP16x16 { mag: 3735552, sign: false }); + data.append(FP16x16 { mag: 6356992, sign: true }); + data.append(FP16x16 { mag: 2359296, sign: false }); + data.append(FP16x16 { mag: 5308416, sign: true }); + data.append(FP16x16 { mag: 3997696, sign: true }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 5439488, sign: true }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 4718592, sign: true }); + data.append(FP16x16 { mag: 6619136, sign: false }); + data.append(FP16x16 { mag: 5898240, sign: true }); + data.append(FP16x16 { mag: 2490368, sign: false }); + data.append(FP16x16 { mag: 2686976, sign: true }); + data.append(FP16x16 { mag: 3407872, sign: false }); + data.append(FP16x16 { mag: 2031616, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_square_neg/output_0.cairo b/tests/nodes/triu_fp16x16_square_neg/output_0.cairo new file mode 100644 index 000000000..54df155dd --- /dev/null +++ b/tests/nodes/triu_fp16x16_square_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1900544, sign: false }); + data.append(FP16x16 { mag: 5570560, sign: false }); + data.append(FP16x16 { mag: 3735552, sign: false }); + data.append(FP16x16 { mag: 6356992, sign: true }); + data.append(FP16x16 { mag: 2359296, sign: false }); + data.append(FP16x16 { mag: 5308416, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 7208960, sign: true }); + data.append(FP16x16 { mag: 5439488, sign: true }); + data.append(FP16x16 { mag: 5177344, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 4718592, sign: true }); + data.append(FP16x16 { mag: 6619136, sign: false }); + data.append(FP16x16 { mag: 5898240, sign: true }); + data.append(FP16x16 { mag: 2490368, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 3407872, sign: false }); + data.append(FP16x16 { mag: 2031616, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_zero.cairo b/tests/nodes/triu_fp16x16_zero.cairo new file mode 100644 index 000000000..348c91d91 --- /dev/null +++ b/tests/nodes/triu_fp16x16_zero.cairo @@ -0,0 +1,20 @@ +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_triu_fp16x16_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp16x16_zero/input_0.cairo b/tests/nodes/triu_fp16x16_zero/input_0.cairo new file mode 100644 index 000000000..073b19063 --- /dev/null +++ b/tests/nodes/triu_fp16x16_zero/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp16x16_zero/output_0.cairo b/tests/nodes/triu_fp16x16_zero/output_0.cairo new file mode 100644 index 000000000..d88922e9a --- /dev/null +++ b/tests/nodes/triu_fp16x16_zero/output_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23.cairo b/tests/nodes/triu_fp8x23.cairo new file mode 100644 index 000000000..454df242e --- /dev/null +++ b/tests/nodes/triu_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_triu_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23/input_0.cairo b/tests/nodes/triu_fp8x23/input_0.cairo new file mode 100644 index 000000000..b7bb37876 --- /dev/null +++ b/tests/nodes/triu_fp8x23/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: true }); + data.append(FP8x23 { mag: 75497472, sign: true }); + data.append(FP8x23 { mag: 1056964608, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + data.append(FP8x23 { mag: 1006632960, sign: false }); + data.append(FP8x23 { mag: 427819008, sign: true }); + data.append(FP8x23 { mag: 520093696, sign: true }); + data.append(FP8x23 { mag: 109051904, sign: true }); + data.append(FP8x23 { mag: 612368384, sign: true }); + data.append(FP8x23 { mag: 721420288, sign: false }); + data.append(FP8x23 { mag: 662700032, sign: false }); + data.append(FP8x23 { mag: 553648128, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 335544320, sign: true }); + data.append(FP8x23 { mag: 981467136, sign: false }); + data.append(FP8x23 { mag: 562036736, sign: true }); + data.append(FP8x23 { mag: 637534208, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23/output_0.cairo b/tests/nodes/triu_fp8x23/output_0.cairo new file mode 100644 index 000000000..bac79b167 --- /dev/null +++ b/tests/nodes/triu_fp8x23/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: true }); + data.append(FP8x23 { mag: 75497472, sign: true }); + data.append(FP8x23 { mag: 1056964608, sign: false }); + data.append(FP8x23 { mag: 310378496, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1006632960, sign: false }); + data.append(FP8x23 { mag: 427819008, sign: true }); + data.append(FP8x23 { mag: 520093696, sign: true }); + data.append(FP8x23 { mag: 109051904, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 662700032, sign: false }); + data.append(FP8x23 { mag: 553648128, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 637534208, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_neg.cairo b/tests/nodes/triu_fp8x23_neg.cairo new file mode 100644 index 000000000..fa214ace7 --- /dev/null +++ b/tests/nodes/triu_fp8x23_neg.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_triu_fp8x23_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_neg/input_0.cairo b/tests/nodes/triu_fp8x23_neg/input_0.cairo new file mode 100644 index 000000000..8b6719b92 --- /dev/null +++ b/tests/nodes/triu_fp8x23_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 209715200, sign: true }); + data.append(FP8x23 { mag: 218103808, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: false }); + data.append(FP8x23 { mag: 478150656, sign: false }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 562036736, sign: false }); + data.append(FP8x23 { mag: 620756992, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: true }); + data.append(FP8x23 { mag: 813694976, sign: true }); + data.append(FP8x23 { mag: 109051904, sign: true }); + data.append(FP8x23 { mag: 1031798784, sign: false }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 318767104, sign: true }); + data.append(FP8x23 { mag: 377487360, sign: true }); + data.append(FP8x23 { mag: 956301312, sign: false }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 117440512, sign: true }); + data.append(FP8x23 { mag: 931135488, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_neg/output_0.cairo b/tests/nodes/triu_fp8x23_neg/output_0.cairo new file mode 100644 index 000000000..5e0ccc946 --- /dev/null +++ b/tests/nodes/triu_fp8x23_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 209715200, sign: true }); + data.append(FP8x23 { mag: 218103808, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: false }); + data.append(FP8x23 { mag: 478150656, sign: false }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 562036736, sign: false }); + data.append(FP8x23 { mag: 620756992, sign: false }); + data.append(FP8x23 { mag: 452984832, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: true }); + data.append(FP8x23 { mag: 1031798784, sign: false }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 318767104, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 117440512, sign: true }); + data.append(FP8x23 { mag: 931135488, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_one_row.cairo b/tests/nodes/triu_fp8x23_one_row.cairo new file mode 100644 index 000000000..fe5ed4205 --- /dev/null +++ b/tests/nodes/triu_fp8x23_one_row.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_triu_fp8x23_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_one_row/input_0.cairo b/tests/nodes/triu_fp8x23_one_row/input_0.cairo new file mode 100644 index 000000000..e97d36835 --- /dev/null +++ b/tests/nodes/triu_fp8x23_one_row/input_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 721420288, sign: true }); + data.append(FP8x23 { mag: 335544320, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: true }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 1048576000, sign: true }); + data.append(FP8x23 { mag: 914358272, sign: false }); + data.append(FP8x23 { mag: 427819008, sign: false }); + data.append(FP8x23 { mag: 511705088, sign: true }); + data.append(FP8x23 { mag: 612368384, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 662700032, sign: true }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_one_row/output_0.cairo b/tests/nodes/triu_fp8x23_one_row/output_0.cairo new file mode 100644 index 000000000..dc957b6dc --- /dev/null +++ b/tests/nodes/triu_fp8x23_one_row/output_0.cairo @@ -0,0 +1,30 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 721420288, sign: true }); + data.append(FP8x23 { mag: 335544320, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: true }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 1048576000, sign: true }); + data.append(FP8x23 { mag: 914358272, sign: false }); + data.append(FP8x23 { mag: 427819008, sign: false }); + data.append(FP8x23 { mag: 511705088, sign: true }); + data.append(FP8x23 { mag: 612368384, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 662700032, sign: true }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 1015021568, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_out_neg.cairo b/tests/nodes/triu_fp8x23_out_neg.cairo new file mode 100644 index 000000000..cc8da6637 --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_neg.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_triu_fp8x23_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_out_neg/input_0.cairo b/tests/nodes/triu_fp8x23_out_neg/input_0.cairo new file mode 100644 index 000000000..3ece9ebed --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_neg/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 260046848, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 713031680, sign: true }); + data.append(FP8x23 { mag: 1040187392, sign: true }); + data.append(FP8x23 { mag: 520093696, sign: true }); + data.append(FP8x23 { mag: 553648128, sign: true }); + data.append(FP8x23 { mag: 981467136, sign: true }); + data.append(FP8x23 { mag: 402653184, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: true }); + data.append(FP8x23 { mag: 578813952, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 1056964608, sign: true }); + data.append(FP8x23 { mag: 830472192, sign: false }); + data.append(FP8x23 { mag: 813694976, sign: false }); + data.append(FP8x23 { mag: 763363328, sign: true }); + data.append(FP8x23 { mag: 318767104, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_out_neg/output_0.cairo b/tests/nodes/triu_fp8x23_out_neg/output_0.cairo new file mode 100644 index 000000000..5f9edd358 --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_neg/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 260046848, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 713031680, sign: true }); + data.append(FP8x23 { mag: 1040187392, sign: true }); + data.append(FP8x23 { mag: 520093696, sign: true }); + data.append(FP8x23 { mag: 553648128, sign: true }); + data.append(FP8x23 { mag: 981467136, sign: true }); + data.append(FP8x23 { mag: 402653184, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 494927872, sign: true }); + data.append(FP8x23 { mag: 578813952, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 1056964608, sign: true }); + data.append(FP8x23 { mag: 830472192, sign: false }); + data.append(FP8x23 { mag: 813694976, sign: false }); + data.append(FP8x23 { mag: 763363328, sign: true }); + data.append(FP8x23 { mag: 318767104, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_out_pos.cairo b/tests/nodes/triu_fp8x23_out_pos.cairo new file mode 100644 index 000000000..6e55fd9a2 --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_pos.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_triu_fp8x23_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_out_pos/input_0.cairo b/tests/nodes/triu_fp8x23_out_pos/input_0.cairo new file mode 100644 index 000000000..25b09cbea --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 377487360, sign: false }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 620756992, sign: true }); + data.append(FP8x23 { mag: 989855744, sign: true }); + data.append(FP8x23 { mag: 301989888, sign: false }); + data.append(FP8x23 { mag: 645922816, sign: false }); + data.append(FP8x23 { mag: 343932928, sign: false }); + data.append(FP8x23 { mag: 713031680, sign: true }); + data.append(FP8x23 { mag: 310378496, sign: false }); + data.append(FP8x23 { mag: 603979776, sign: false }); + data.append(FP8x23 { mag: 511705088, sign: false }); + data.append(FP8x23 { mag: 377487360, sign: false }); + data.append(FP8x23 { mag: 276824064, sign: false }); + data.append(FP8x23 { mag: 553648128, sign: false }); + data.append(FP8x23 { mag: 788529152, sign: false }); + data.append(FP8x23 { mag: 838860800, sign: true }); + data.append(FP8x23 { mag: 562036736, sign: false }); + data.append(FP8x23 { mag: 989855744, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: true }); + data.append(FP8x23 { mag: 503316480, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_out_pos/output_0.cairo b/tests/nodes/triu_fp8x23_out_pos/output_0.cairo new file mode 100644 index 000000000..54f2a133b --- /dev/null +++ b/tests/nodes/triu_fp8x23_out_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_pos.cairo b/tests/nodes/triu_fp8x23_pos.cairo new file mode 100644 index 000000000..37c1e4c50 --- /dev/null +++ b/tests/nodes/triu_fp8x23_pos.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_triu_fp8x23_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_pos/input_0.cairo b/tests/nodes/triu_fp8x23_pos/input_0.cairo new file mode 100644 index 000000000..16aacaf6e --- /dev/null +++ b/tests/nodes/triu_fp8x23_pos/input_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 293601280, sign: false }); + data.append(FP8x23 { mag: 402653184, sign: true }); + data.append(FP8x23 { mag: 629145600, sign: true }); + data.append(FP8x23 { mag: 838860800, sign: false }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 553648128, sign: true }); + data.append(FP8x23 { mag: 914358272, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: false }); + data.append(FP8x23 { mag: 981467136, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 847249408, sign: false }); + data.append(FP8x23 { mag: 704643072, sign: false }); + data.append(FP8x23 { mag: 746586112, sign: true }); + data.append(FP8x23 { mag: 998244352, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: true }); + data.append(FP8x23 { mag: 914358272, sign: false }); + data.append(FP8x23 { mag: 603979776, sign: true }); + data.append(FP8x23 { mag: 872415232, sign: false }); + data.append(FP8x23 { mag: 872415232, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_pos/output_0.cairo b/tests/nodes/triu_fp8x23_pos/output_0.cairo new file mode 100644 index 000000000..dabd9083c --- /dev/null +++ b/tests/nodes/triu_fp8x23_pos/output_0.cairo @@ -0,0 +1,34 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 629145600, sign: true }); + data.append(FP8x23 { mag: 838860800, sign: false }); + data.append(FP8x23 { mag: 1065353216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 796917760, sign: false }); + data.append(FP8x23 { mag: 981467136, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 998244352, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_square.cairo b/tests/nodes/triu_fp8x23_square.cairo new file mode 100644 index 000000000..a66d8eb92 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square.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_triu_fp8x23_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_square/input_0.cairo b/tests/nodes/triu_fp8x23_square/input_0.cairo new file mode 100644 index 000000000..d000f4f34 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 377487360, sign: true }); + data.append(FP8x23 { mag: 603979776, sign: true }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 251658240, sign: true }); + data.append(FP8x23 { mag: 897581056, sign: false }); + data.append(FP8x23 { mag: 394264576, sign: true }); + data.append(FP8x23 { mag: 805306368, sign: true }); + data.append(FP8x23 { mag: 150994944, sign: true }); + data.append(FP8x23 { mag: 696254464, sign: true }); + data.append(FP8x23 { mag: 612368384, sign: true }); + data.append(FP8x23 { mag: 847249408, sign: false }); + data.append(FP8x23 { mag: 956301312, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: false }); + data.append(FP8x23 { mag: 914358272, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 1040187392, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_square/output_0.cairo b/tests/nodes/triu_fp8x23_square/output_0.cairo new file mode 100644 index 000000000..345365973 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 377487360, sign: true }); + data.append(FP8x23 { mag: 603979776, sign: true }); + data.append(FP8x23 { mag: 905969664, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 251658240, sign: true }); + data.append(FP8x23 { mag: 897581056, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: true }); + data.append(FP8x23 { mag: 696254464, sign: true }); + data.append(FP8x23 { mag: 612368384, sign: true }); + data.append(FP8x23 { mag: 847249408, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 822083584, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1040187392, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_square_neg.cairo b/tests/nodes/triu_fp8x23_square_neg.cairo new file mode 100644 index 000000000..2aa0252f0 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square_neg.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_triu_fp8x23_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_square_neg/input_0.cairo b/tests/nodes/triu_fp8x23_square_neg/input_0.cairo new file mode 100644 index 000000000..fa0bec625 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1040187392, sign: true }); + data.append(FP8x23 { mag: 360710144, sign: true }); + data.append(FP8x23 { mag: 327155712, sign: false }); + data.append(FP8x23 { mag: 461373440, sign: true }); + data.append(FP8x23 { mag: 352321536, sign: true }); + data.append(FP8x23 { mag: 570425344, sign: false }); + data.append(FP8x23 { mag: 989855744, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 268435456, sign: false }); + data.append(FP8x23 { mag: 503316480, sign: true }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 478150656, sign: true }); + data.append(FP8x23 { mag: 411041792, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 427819008, sign: true }); + data.append(FP8x23 { mag: 528482304, sign: true }); + data.append(FP8x23 { mag: 243269632, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_square_neg/output_0.cairo b/tests/nodes/triu_fp8x23_square_neg/output_0.cairo new file mode 100644 index 000000000..41fa1fad3 --- /dev/null +++ b/tests/nodes/triu_fp8x23_square_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1040187392, sign: true }); + data.append(FP8x23 { mag: 360710144, sign: true }); + data.append(FP8x23 { mag: 327155712, sign: false }); + data.append(FP8x23 { mag: 461373440, sign: true }); + data.append(FP8x23 { mag: 352321536, sign: true }); + data.append(FP8x23 { mag: 570425344, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 268435456, sign: false }); + data.append(FP8x23 { mag: 503316480, sign: true }); + data.append(FP8x23 { mag: 276824064, sign: true }); + data.append(FP8x23 { mag: 478150656, sign: true }); + data.append(FP8x23 { mag: 411041792, sign: false }); + data.append(FP8x23 { mag: 780140544, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 528482304, sign: true }); + data.append(FP8x23 { mag: 243269632, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_zero.cairo b/tests/nodes/triu_fp8x23_zero.cairo new file mode 100644 index 000000000..88316af80 --- /dev/null +++ b/tests/nodes/triu_fp8x23_zero.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_triu_fp8x23_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_fp8x23_zero/input_0.cairo b/tests/nodes/triu_fp8x23_zero/input_0.cairo new file mode 100644 index 000000000..0212a6f2b --- /dev/null +++ b/tests/nodes/triu_fp8x23_zero/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_fp8x23_zero/output_0.cairo b/tests/nodes/triu_fp8x23_zero/output_0.cairo new file mode 100644 index 000000000..a21173947 --- /dev/null +++ b/tests/nodes/triu_fp8x23_zero/output_0.cairo @@ -0,0 +1,15 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32.cairo b/tests/nodes/triu_i32.cairo new file mode 100644 index 000000000..302f9406d --- /dev/null +++ b/tests/nodes/triu_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_triu_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32/input_0.cairo b/tests/nodes/triu_i32/input_0.cairo new file mode 100644 index 000000000..bb49d62ae --- /dev/null +++ b/tests/nodes/triu_i32/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 43, sign: false }); + data.append(i32 { mag: 58, sign: true }); + data.append(i32 { mag: 22, sign: true }); + data.append(i32 { mag: 28, sign: true }); + data.append(i32 { mag: 93, sign: true }); + data.append(i32 { mag: 60, sign: false }); + data.append(i32 { mag: 72, sign: false }); + data.append(i32 { mag: 86, sign: false }); + data.append(i32 { mag: 95, sign: false }); + data.append(i32 { mag: 45, sign: false }); + data.append(i32 { mag: 98, sign: false }); + data.append(i32 { mag: 54, sign: false }); + data.append(i32 { mag: 119, sign: true }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 91, sign: true }); + data.append(i32 { mag: 90, sign: true }); + data.append(i32 { mag: 112, sign: false }); + data.append(i32 { mag: 55, sign: false }); + data.append(i32 { mag: 56, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32/output_0.cairo b/tests/nodes/triu_i32/output_0.cairo new file mode 100644 index 000000000..bd1efdddc --- /dev/null +++ b/tests/nodes/triu_i32/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 43, sign: false }); + data.append(i32 { mag: 58, sign: true }); + data.append(i32 { mag: 22, sign: true }); + data.append(i32 { mag: 28, sign: true }); + data.append(i32 { mag: 93, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 72, sign: false }); + data.append(i32 { mag: 86, sign: false }); + data.append(i32 { mag: 95, sign: false }); + data.append(i32 { mag: 45, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 119, sign: true }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 55, sign: false }); + data.append(i32 { mag: 56, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_neg.cairo b/tests/nodes/triu_i32_neg.cairo new file mode 100644 index 000000000..0f18fd90e --- /dev/null +++ b/tests/nodes/triu_i32_neg.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_triu_i32_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_neg/input_0.cairo b/tests/nodes/triu_i32_neg/input_0.cairo new file mode 100644 index 000000000..afaf2309d --- /dev/null +++ b/tests/nodes/triu_i32_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 33, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 44, sign: false }); + data.append(i32 { mag: 40, sign: true }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 90, sign: false }); + data.append(i32 { mag: 37, sign: true }); + data.append(i32 { mag: 73, sign: false }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 53, sign: false }); + data.append(i32 { mag: 32, sign: true }); + data.append(i32 { mag: 86, sign: false }); + data.append(i32 { mag: 55, sign: false }); + data.append(i32 { mag: 106, sign: false }); + data.append(i32 { mag: 85, sign: true }); + data.append(i32 { mag: 32, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 59, sign: true }); + data.append(i32 { mag: 94, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_neg/output_0.cairo b/tests/nodes/triu_i32_neg/output_0.cairo new file mode 100644 index 000000000..dd9a36f22 --- /dev/null +++ b/tests/nodes/triu_i32_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 33, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 44, sign: false }); + data.append(i32 { mag: 40, sign: true }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 90, sign: false }); + data.append(i32 { mag: 37, sign: true }); + data.append(i32 { mag: 73, sign: false }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 32, sign: true }); + data.append(i32 { mag: 86, sign: false }); + data.append(i32 { mag: 55, sign: false }); + data.append(i32 { mag: 106, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 59, sign: true }); + data.append(i32 { mag: 94, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_one_row.cairo b/tests/nodes/triu_i32_one_row.cairo new file mode 100644 index 000000000..3b15f50f9 --- /dev/null +++ b/tests/nodes/triu_i32_one_row.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_triu_i32_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_one_row/input_0.cairo b/tests/nodes/triu_i32_one_row/input_0.cairo new file mode 100644 index 000000000..3633e0bd7 --- /dev/null +++ b/tests/nodes/triu_i32_one_row/input_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 83, sign: false }); + data.append(i32 { mag: 52, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 23, sign: false }); + data.append(i32 { mag: 92, sign: true }); + data.append(i32 { mag: 97, sign: false }); + data.append(i32 { mag: 24, sign: true }); + data.append(i32 { mag: 46, sign: false }); + data.append(i32 { mag: 67, sign: true }); + data.append(i32 { mag: 108, sign: true }); + data.append(i32 { mag: 10, sign: true }); + data.append(i32 { mag: 119, sign: false }); + data.append(i32 { mag: 109, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_one_row/output_0.cairo b/tests/nodes/triu_i32_one_row/output_0.cairo new file mode 100644 index 000000000..c2aac8c8c --- /dev/null +++ b/tests/nodes/triu_i32_one_row/output_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 83, sign: false }); + data.append(i32 { mag: 52, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 23, sign: false }); + data.append(i32 { mag: 92, sign: true }); + data.append(i32 { mag: 97, sign: false }); + data.append(i32 { mag: 24, sign: true }); + data.append(i32 { mag: 46, sign: false }); + data.append(i32 { mag: 67, sign: true }); + data.append(i32 { mag: 108, sign: true }); + data.append(i32 { mag: 10, sign: true }); + data.append(i32 { mag: 119, sign: false }); + data.append(i32 { mag: 109, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_out_neg.cairo b/tests/nodes/triu_i32_out_neg.cairo new file mode 100644 index 000000000..abf18a4bf --- /dev/null +++ b/tests/nodes/triu_i32_out_neg.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_triu_i32_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_out_neg/input_0.cairo b/tests/nodes/triu_i32_out_neg/input_0.cairo new file mode 100644 index 000000000..983434a4e --- /dev/null +++ b/tests/nodes/triu_i32_out_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 57, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 80, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 41, sign: false }); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 47, sign: false }); + data.append(i32 { mag: 27, sign: true }); + data.append(i32 { mag: 108, sign: false }); + data.append(i32 { mag: 59, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 102, sign: false }); + data.append(i32 { mag: 104, sign: false }); + data.append(i32 { mag: 17, sign: true }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 16, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_out_neg/output_0.cairo b/tests/nodes/triu_i32_out_neg/output_0.cairo new file mode 100644 index 000000000..0c9f9d8aa --- /dev/null +++ b/tests/nodes/triu_i32_out_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 57, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 80, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 41, sign: false }); + data.append(i32 { mag: 77, sign: true }); + data.append(i32 { mag: 47, sign: false }); + data.append(i32 { mag: 27, sign: true }); + data.append(i32 { mag: 108, sign: false }); + data.append(i32 { mag: 59, sign: false }); + data.append(i32 { mag: 32, sign: false }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 102, sign: false }); + data.append(i32 { mag: 104, sign: false }); + data.append(i32 { mag: 17, sign: true }); + data.append(i32 { mag: 110, sign: true }); + data.append(i32 { mag: 16, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_out_pos.cairo b/tests/nodes/triu_i32_out_pos.cairo new file mode 100644 index 000000000..9ceb75426 --- /dev/null +++ b/tests/nodes/triu_i32_out_pos.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_triu_i32_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_out_pos/input_0.cairo b/tests/nodes/triu_i32_out_pos/input_0.cairo new file mode 100644 index 000000000..7f816b61c --- /dev/null +++ b/tests/nodes/triu_i32_out_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 35, sign: false }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 58, sign: true }); + data.append(i32 { mag: 91, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 40, sign: true }); + data.append(i32 { mag: 88, sign: false }); + data.append(i32 { mag: 86, sign: true }); + data.append(i32 { mag: 76, sign: true }); + data.append(i32 { mag: 96, sign: true }); + data.append(i32 { mag: 39, sign: true }); + data.append(i32 { mag: 100, sign: false }); + data.append(i32 { mag: 26, sign: true }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 99, sign: false }); + data.append(i32 { mag: 62, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 93, sign: true }); + data.append(i32 { mag: 71, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_out_pos/output_0.cairo b/tests/nodes/triu_i32_out_pos/output_0.cairo new file mode 100644 index 000000000..9c3c97fbb --- /dev/null +++ b/tests/nodes/triu_i32_out_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_pos.cairo b/tests/nodes/triu_i32_pos.cairo new file mode 100644 index 000000000..11bab7e92 --- /dev/null +++ b/tests/nodes/triu_i32_pos.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_triu_i32_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_pos/input_0.cairo b/tests/nodes/triu_i32_pos/input_0.cairo new file mode 100644 index 000000000..fa4a5301b --- /dev/null +++ b/tests/nodes/triu_i32_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 15, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 117, sign: true }); + data.append(i32 { mag: 116, sign: false }); + data.append(i32 { mag: 43, sign: true }); + data.append(i32 { mag: 48, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 35, sign: false }); + data.append(i32 { mag: 98, sign: false }); + data.append(i32 { mag: 40, sign: false }); + data.append(i32 { mag: 35, sign: false }); + data.append(i32 { mag: 122, sign: true }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 125, sign: false }); + data.append(i32 { mag: 102, sign: false }); + data.append(i32 { mag: 55, sign: true }); + data.append(i32 { mag: 39, sign: false }); + data.append(i32 { mag: 98, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_pos/output_0.cairo b/tests/nodes/triu_i32_pos/output_0.cairo new file mode 100644 index 000000000..325790ee3 --- /dev/null +++ b/tests/nodes/triu_i32_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 117, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 49, sign: true }); + data.append(i32 { mag: 35, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_square.cairo b/tests/nodes/triu_i32_square.cairo new file mode 100644 index 000000000..61c66cfd1 --- /dev/null +++ b/tests/nodes/triu_i32_square.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_triu_i32_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_square/input_0.cairo b/tests/nodes/triu_i32_square/input_0.cairo new file mode 100644 index 000000000..90f11620d --- /dev/null +++ b/tests/nodes/triu_i32_square/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 59, sign: true }); + data.append(i32 { mag: 103, sign: false }); + data.append(i32 { mag: 85, sign: false }); + data.append(i32 { mag: 50, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 60, sign: true }); + data.append(i32 { mag: 123, sign: true }); + data.append(i32 { mag: 98, sign: false }); + data.append(i32 { mag: 113, sign: true }); + data.append(i32 { mag: 40, sign: false }); + data.append(i32 { mag: 66, sign: false }); + data.append(i32 { mag: 53, sign: false }); + data.append(i32 { mag: 78, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 30, sign: true }); + data.append(i32 { mag: 64, sign: false }); + data.append(i32 { mag: 60, sign: true }); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_square/output_0.cairo b/tests/nodes/triu_i32_square/output_0.cairo new file mode 100644 index 000000000..47202f985 --- /dev/null +++ b/tests/nodes/triu_i32_square/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 59, sign: true }); + data.append(i32 { mag: 103, sign: false }); + data.append(i32 { mag: 85, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 60, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 113, sign: true }); + data.append(i32 { mag: 40, sign: false }); + data.append(i32 { mag: 66, sign: false }); + data.append(i32 { mag: 53, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 30, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_square_neg.cairo b/tests/nodes/triu_i32_square_neg.cairo new file mode 100644 index 000000000..9269705be --- /dev/null +++ b/tests/nodes/triu_i32_square_neg.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_triu_i32_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_square_neg/input_0.cairo b/tests/nodes/triu_i32_square_neg/input_0.cairo new file mode 100644 index 000000000..479e9dcd7 --- /dev/null +++ b/tests/nodes/triu_i32_square_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 120, sign: true }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 90, sign: true }); + data.append(i32 { mag: 31, sign: false }); + data.append(i32 { mag: 109, sign: true }); + data.append(i32 { mag: 81, sign: false }); + data.append(i32 { mag: 42, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 19, sign: true }); + data.append(i32 { mag: 69, sign: true }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 106, sign: false }); + data.append(i32 { mag: 29, sign: true }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 54, sign: true }); + data.append(i32 { mag: 121, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_square_neg/output_0.cairo b/tests/nodes/triu_i32_square_neg/output_0.cairo new file mode 100644 index 000000000..f19a6f41d --- /dev/null +++ b/tests/nodes/triu_i32_square_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 114, sign: false }); + data.append(i32 { mag: 120, sign: true }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 90, sign: true }); + data.append(i32 { mag: 31, sign: false }); + data.append(i32 { mag: 109, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 42, sign: false }); + data.append(i32 { mag: 8, sign: true }); + data.append(i32 { mag: 19, sign: true }); + data.append(i32 { mag: 69, sign: true }); + data.append(i32 { mag: 49, sign: false }); + data.append(i32 { mag: 106, sign: false }); + data.append(i32 { mag: 29, sign: true }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 54, sign: true }); + data.append(i32 { mag: 121, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_zero.cairo b/tests/nodes/triu_i32_zero.cairo new file mode 100644 index 000000000..f5baa0aec --- /dev/null +++ b/tests/nodes/triu_i32_zero.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_triu_i32_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i32_zero/input_0.cairo b/tests/nodes/triu_i32_zero/input_0.cairo new file mode 100644 index 000000000..a01ddf661 --- /dev/null +++ b/tests/nodes/triu_i32_zero/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i32_zero/output_0.cairo b/tests/nodes/triu_i32_zero/output_0.cairo new file mode 100644 index 000000000..20f0b375e --- /dev/null +++ b/tests/nodes/triu_i32_zero/output_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8.cairo b/tests/nodes/triu_i8.cairo new file mode 100644 index 000000000..c38230c0e --- /dev/null +++ b/tests/nodes/triu_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_triu_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8/input_0.cairo b/tests/nodes/triu_i8/input_0.cairo new file mode 100644 index 000000000..4e4bec160 --- /dev/null +++ b/tests/nodes/triu_i8/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 62, sign: true }); + data.append(i8 { mag: 15, sign: true }); + data.append(i8 { mag: 60, sign: true }); + data.append(i8 { mag: 122, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 92, sign: true }); + data.append(i8 { mag: 59, sign: false }); + data.append(i8 { mag: 113, sign: false }); + data.append(i8 { mag: 126, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 40, sign: true }); + data.append(i8 { mag: 112, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 60, sign: false }); + data.append(i8 { mag: 118, sign: false }); + data.append(i8 { mag: 102, sign: true }); + data.append(i8 { mag: 91, sign: false }); + data.append(i8 { mag: 80, sign: false }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 111, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8/output_0.cairo b/tests/nodes/triu_i8/output_0.cairo new file mode 100644 index 000000000..9c217641f --- /dev/null +++ b/tests/nodes/triu_i8/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 62, sign: true }); + data.append(i8 { mag: 15, sign: true }); + data.append(i8 { mag: 60, sign: true }); + data.append(i8 { mag: 122, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 59, sign: false }); + data.append(i8 { mag: 113, sign: false }); + data.append(i8 { mag: 126, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 60, sign: false }); + data.append(i8 { mag: 118, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 111, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_neg.cairo b/tests/nodes/triu_i8_neg.cairo new file mode 100644 index 000000000..d2d95b6e7 --- /dev/null +++ b/tests/nodes/triu_i8_neg.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_triu_i8_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_neg/input_0.cairo b/tests/nodes/triu_i8_neg/input_0.cairo new file mode 100644 index 000000000..e588aa96b --- /dev/null +++ b/tests/nodes/triu_i8_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 70, sign: false }); + data.append(i8 { mag: 41, sign: true }); + data.append(i8 { mag: 81, sign: true }); + data.append(i8 { mag: 62, sign: true }); + data.append(i8 { mag: 89, sign: false }); + data.append(i8 { mag: 67, sign: true }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 61, sign: true }); + data.append(i8 { mag: 34, sign: true }); + data.append(i8 { mag: 100, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 39, sign: false }); + data.append(i8 { mag: 19, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 43, sign: false }); + data.append(i8 { mag: 43, sign: false }); + data.append(i8 { mag: 30, sign: true }); + data.append(i8 { mag: 110, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_neg/output_0.cairo b/tests/nodes/triu_i8_neg/output_0.cairo new file mode 100644 index 000000000..e7c25817b --- /dev/null +++ b/tests/nodes/triu_i8_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 70, sign: false }); + data.append(i8 { mag: 41, sign: true }); + data.append(i8 { mag: 81, sign: true }); + data.append(i8 { mag: 62, sign: true }); + data.append(i8 { mag: 89, sign: false }); + data.append(i8 { mag: 67, sign: true }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 61, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 100, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 39, sign: false }); + data.append(i8 { mag: 19, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 43, sign: false }); + data.append(i8 { mag: 30, sign: true }); + data.append(i8 { mag: 110, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_one_row.cairo b/tests/nodes/triu_i8_one_row.cairo new file mode 100644 index 000000000..d3060c41b --- /dev/null +++ b/tests/nodes/triu_i8_one_row.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_triu_i8_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_one_row/input_0.cairo b/tests/nodes/triu_i8_one_row/input_0.cairo new file mode 100644 index 000000000..841e7a4b0 --- /dev/null +++ b/tests/nodes/triu_i8_one_row/input_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 123, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 10, sign: true }); + data.append(i8 { mag: 112, sign: false }); + data.append(i8 { mag: 67, sign: true }); + data.append(i8 { mag: 60, sign: true }); + data.append(i8 { mag: 16, sign: false }); + data.append(i8 { mag: 56, sign: true }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 88, sign: true }); + data.append(i8 { mag: 114, sign: false }); + data.append(i8 { mag: 27, sign: true }); + data.append(i8 { mag: 48, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_one_row/output_0.cairo b/tests/nodes/triu_i8_one_row/output_0.cairo new file mode 100644 index 000000000..94a468e4f --- /dev/null +++ b/tests/nodes/triu_i8_one_row/output_0.cairo @@ -0,0 +1,29 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 123, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 10, sign: true }); + data.append(i8 { mag: 112, sign: false }); + data.append(i8 { mag: 67, sign: true }); + data.append(i8 { mag: 60, sign: true }); + data.append(i8 { mag: 16, sign: false }); + data.append(i8 { mag: 56, sign: true }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 88, sign: true }); + data.append(i8 { mag: 114, sign: false }); + data.append(i8 { mag: 27, sign: true }); + data.append(i8 { mag: 48, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_out_neg.cairo b/tests/nodes/triu_i8_out_neg.cairo new file mode 100644 index 000000000..011c2a4e6 --- /dev/null +++ b/tests/nodes/triu_i8_out_neg.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_triu_i8_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_out_neg/input_0.cairo b/tests/nodes/triu_i8_out_neg/input_0.cairo new file mode 100644 index 000000000..996425017 --- /dev/null +++ b/tests/nodes/triu_i8_out_neg/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 29, sign: false }); + data.append(i8 { mag: 63, sign: true }); + data.append(i8 { mag: 73, sign: true }); + data.append(i8 { mag: 20, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 28, sign: false }); + data.append(i8 { mag: 56, sign: false }); + data.append(i8 { mag: 114, sign: true }); + data.append(i8 { mag: 49, sign: true }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 125, sign: true }); + data.append(i8 { mag: 102, sign: true }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 89, sign: false }); + data.append(i8 { mag: 21, sign: true }); + data.append(i8 { mag: 84, sign: false }); + data.append(i8 { mag: 58, sign: true }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 93, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_out_neg/output_0.cairo b/tests/nodes/triu_i8_out_neg/output_0.cairo new file mode 100644 index 000000000..87bbad9eb --- /dev/null +++ b/tests/nodes/triu_i8_out_neg/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 29, sign: false }); + data.append(i8 { mag: 63, sign: true }); + data.append(i8 { mag: 73, sign: true }); + data.append(i8 { mag: 20, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 18, sign: true }); + data.append(i8 { mag: 28, sign: false }); + data.append(i8 { mag: 56, sign: false }); + data.append(i8 { mag: 114, sign: true }); + data.append(i8 { mag: 49, sign: true }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 125, sign: true }); + data.append(i8 { mag: 102, sign: true }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 89, sign: false }); + data.append(i8 { mag: 21, sign: true }); + data.append(i8 { mag: 84, sign: false }); + data.append(i8 { mag: 58, sign: true }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 93, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_out_pos.cairo b/tests/nodes/triu_i8_out_pos.cairo new file mode 100644 index 000000000..0104565c6 --- /dev/null +++ b/tests/nodes/triu_i8_out_pos.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_triu_i8_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_out_pos/input_0.cairo b/tests/nodes/triu_i8_out_pos/input_0.cairo new file mode 100644 index 000000000..70f3e633a --- /dev/null +++ b/tests/nodes/triu_i8_out_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 27, sign: false }); + data.append(i8 { mag: 17, sign: false }); + data.append(i8 { mag: 50, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 111, sign: true }); + data.append(i8 { mag: 31, sign: true }); + data.append(i8 { mag: 41, sign: false }); + data.append(i8 { mag: 51, sign: true }); + data.append(i8 { mag: 60, sign: false }); + data.append(i8 { mag: 65, sign: true }); + data.append(i8 { mag: 106, sign: true }); + data.append(i8 { mag: 54, sign: true }); + data.append(i8 { mag: 103, sign: false }); + data.append(i8 { mag: 85, sign: false }); + data.append(i8 { mag: 66, sign: true }); + data.append(i8 { mag: 32, sign: false }); + data.append(i8 { mag: 106, sign: false }); + data.append(i8 { mag: 23, sign: true }); + data.append(i8 { mag: 59, sign: true }); + data.append(i8 { mag: 66, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_out_pos/output_0.cairo b/tests/nodes/triu_i8_out_pos/output_0.cairo new file mode 100644 index 000000000..aa1512f92 --- /dev/null +++ b/tests/nodes/triu_i8_out_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_pos.cairo b/tests/nodes/triu_i8_pos.cairo new file mode 100644 index 000000000..0b48aa363 --- /dev/null +++ b/tests/nodes/triu_i8_pos.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_triu_i8_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_pos/input_0.cairo b/tests/nodes/triu_i8_pos/input_0.cairo new file mode 100644 index 000000000..5bbbcaba2 --- /dev/null +++ b/tests/nodes/triu_i8_pos/input_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 12, sign: true }); + data.append(i8 { mag: 49, sign: false }); + data.append(i8 { mag: 80, sign: false }); + data.append(i8 { mag: 66, sign: false }); + data.append(i8 { mag: 94, sign: false }); + data.append(i8 { mag: 50, sign: true }); + data.append(i8 { mag: 71, sign: true }); + data.append(i8 { mag: 30, sign: false }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 50, sign: false }); + data.append(i8 { mag: 11, sign: true }); + data.append(i8 { mag: 73, sign: true }); + data.append(i8 { mag: 79, sign: true }); + data.append(i8 { mag: 76, sign: true }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 119, sign: true }); + data.append(i8 { mag: 124, sign: true }); + data.append(i8 { mag: 81, sign: true }); + data.append(i8 { mag: 114, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_pos/output_0.cairo b/tests/nodes/triu_i8_pos/output_0.cairo new file mode 100644 index 000000000..6dbc4240d --- /dev/null +++ b/tests/nodes/triu_i8_pos/output_0.cairo @@ -0,0 +1,33 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 80, sign: false }); + data.append(i8 { mag: 66, sign: false }); + data.append(i8 { mag: 94, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 50, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 69, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_square.cairo b/tests/nodes/triu_i8_square.cairo new file mode 100644 index 000000000..5adc689b3 --- /dev/null +++ b/tests/nodes/triu_i8_square.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_triu_i8_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_square/input_0.cairo b/tests/nodes/triu_i8_square/input_0.cairo new file mode 100644 index 000000000..51cdff013 --- /dev/null +++ b/tests/nodes/triu_i8_square/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 116, sign: false }); + data.append(i8 { mag: 47, sign: false }); + data.append(i8 { mag: 24, sign: true }); + data.append(i8 { mag: 92, sign: false }); + data.append(i8 { mag: 61, sign: true }); + data.append(i8 { mag: 30, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 116, sign: false }); + data.append(i8 { mag: 55, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 115, sign: false }); + data.append(i8 { mag: 54, sign: false }); + data.append(i8 { mag: 100, sign: false }); + data.append(i8 { mag: 110, sign: true }); + data.append(i8 { mag: 28, sign: true }); + data.append(i8 { mag: 75, sign: false }); + data.append(i8 { mag: 25, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_square/output_0.cairo b/tests/nodes/triu_i8_square/output_0.cairo new file mode 100644 index 000000000..757be923d --- /dev/null +++ b/tests/nodes/triu_i8_square/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 116, sign: false }); + data.append(i8 { mag: 47, sign: false }); + data.append(i8 { mag: 24, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 61, sign: true }); + data.append(i8 { mag: 30, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 116, sign: false }); + data.append(i8 { mag: 55, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 115, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 100, sign: false }); + data.append(i8 { mag: 110, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 25, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_square_neg.cairo b/tests/nodes/triu_i8_square_neg.cairo new file mode 100644 index 000000000..59d95d327 --- /dev/null +++ b/tests/nodes/triu_i8_square_neg.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_triu_i8_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_square_neg/input_0.cairo b/tests/nodes/triu_i8_square_neg/input_0.cairo new file mode 100644 index 000000000..d0fe20be9 --- /dev/null +++ b/tests/nodes/triu_i8_square_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 127, sign: true }); + data.append(i8 { mag: 48, sign: true }); + data.append(i8 { mag: 39, sign: true }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 15, sign: true }); + data.append(i8 { mag: 64, sign: true }); + data.append(i8 { mag: 10, sign: false }); + data.append(i8 { mag: 70, sign: true }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 52, sign: false }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 53, sign: true }); + data.append(i8 { mag: 36, sign: false }); + data.append(i8 { mag: 117, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 87, sign: true }); + data.append(i8 { mag: 56, sign: false }); + data.append(i8 { mag: 78, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_square_neg/output_0.cairo b/tests/nodes/triu_i8_square_neg/output_0.cairo new file mode 100644 index 000000000..4e0c5e40a --- /dev/null +++ b/tests/nodes/triu_i8_square_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 127, sign: true }); + data.append(i8 { mag: 48, sign: true }); + data.append(i8 { mag: 39, sign: true }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 15, sign: true }); + data.append(i8 { mag: 64, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 70, sign: true }); + data.append(i8 { mag: 25, sign: true }); + data.append(i8 { mag: 52, sign: false }); + data.append(i8 { mag: 97, sign: true }); + data.append(i8 { mag: 53, sign: true }); + data.append(i8 { mag: 36, sign: false }); + data.append(i8 { mag: 117, sign: false }); + data.append(i8 { mag: 93, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 56, sign: false }); + data.append(i8 { mag: 78, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_zero.cairo b/tests/nodes/triu_i8_zero.cairo new file mode 100644 index 000000000..c8297bcb8 --- /dev/null +++ b/tests/nodes/triu_i8_zero.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_triu_i8_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_i8_zero/input_0.cairo b/tests/nodes/triu_i8_zero/input_0.cairo new file mode 100644 index 000000000..90e2d4e74 --- /dev/null +++ b/tests/nodes/triu_i8_zero/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_i8_zero/output_0.cairo b/tests/nodes/triu_i8_zero/output_0.cairo new file mode 100644 index 000000000..07bfa2a91 --- /dev/null +++ b/tests/nodes/triu_i8_zero/output_0.cairo @@ -0,0 +1,14 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32.cairo b/tests/nodes/triu_u32.cairo new file mode 100644 index 000000000..2c9b3529a --- /dev/null +++ b/tests/nodes/triu_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_triu_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32/input_0.cairo b/tests/nodes/triu_u32/input_0.cairo new file mode 100644 index 000000000..01ae490ca --- /dev/null +++ b/tests/nodes/triu_u32/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(109); + data.append(158); + data.append(245); + data.append(103); + data.append(198); + data.append(122); + data.append(205); + data.append(10); + data.append(11); + data.append(136); + data.append(123); + data.append(80); + data.append(38); + data.append(75); + data.append(181); + data.append(100); + data.append(211); + data.append(121); + data.append(247); + data.append(124); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32/output_0.cairo b/tests/nodes/triu_u32/output_0.cairo new file mode 100644 index 000000000..12551f261 --- /dev/null +++ b/tests/nodes/triu_u32/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(109); + data.append(158); + data.append(245); + data.append(103); + data.append(198); + data.append(0); + data.append(205); + data.append(10); + data.append(11); + data.append(136); + data.append(0); + data.append(0); + data.append(38); + data.append(75); + data.append(181); + data.append(0); + data.append(0); + data.append(0); + data.append(247); + data.append(124); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_neg.cairo b/tests/nodes/triu_u32_neg.cairo new file mode 100644 index 000000000..cfb9e9d4a --- /dev/null +++ b/tests/nodes/triu_u32_neg.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_triu_u32_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_neg/input_0.cairo b/tests/nodes/triu_u32_neg/input_0.cairo new file mode 100644 index 000000000..cb17fe5e5 --- /dev/null +++ b/tests/nodes/triu_u32_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(113); + data.append(87); + data.append(46); + data.append(233); + data.append(48); + data.append(184); + data.append(132); + data.append(29); + data.append(137); + data.append(2); + data.append(28); + data.append(152); + data.append(55); + data.append(58); + data.append(190); + data.append(243); + data.append(41); + data.append(204); + data.append(173); + data.append(150); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_neg/output_0.cairo b/tests/nodes/triu_u32_neg/output_0.cairo new file mode 100644 index 000000000..85001ce2d --- /dev/null +++ b/tests/nodes/triu_u32_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(113); + data.append(87); + data.append(46); + data.append(233); + data.append(48); + data.append(184); + data.append(132); + data.append(29); + data.append(137); + data.append(2); + data.append(0); + data.append(152); + data.append(55); + data.append(58); + data.append(190); + data.append(0); + data.append(0); + data.append(204); + data.append(173); + data.append(150); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_one_row.cairo b/tests/nodes/triu_u32_one_row.cairo new file mode 100644 index 000000000..8bb5f8ab5 --- /dev/null +++ b/tests/nodes/triu_u32_one_row.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_triu_u32_one_row() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_one_row/input_0.cairo b/tests/nodes/triu_u32_one_row/input_0.cairo new file mode 100644 index 000000000..838fc5f4a --- /dev/null +++ b/tests/nodes/triu_u32_one_row/input_0.cairo @@ -0,0 +1,28 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(139); + data.append(223); + data.append(129); + data.append(83); + data.append(41); + data.append(88); + data.append(145); + data.append(7); + data.append(203); + data.append(124); + data.append(5); + data.append(112); + data.append(61); + data.append(77); + data.append(207); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_one_row/output_0.cairo b/tests/nodes/triu_u32_one_row/output_0.cairo new file mode 100644 index 000000000..97a204e7d --- /dev/null +++ b/tests/nodes/triu_u32_one_row/output_0.cairo @@ -0,0 +1,28 @@ +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(3); + shape.append(1); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(139); + data.append(223); + data.append(129); + data.append(83); + data.append(41); + data.append(88); + data.append(145); + data.append(7); + data.append(203); + data.append(124); + data.append(5); + data.append(112); + data.append(61); + data.append(77); + data.append(207); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_out_neg.cairo b/tests/nodes/triu_u32_out_neg.cairo new file mode 100644 index 000000000..13d7ead94 --- /dev/null +++ b/tests/nodes/triu_u32_out_neg.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_triu_u32_out_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -7); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_out_neg/input_0.cairo b/tests/nodes/triu_u32_out_neg/input_0.cairo new file mode 100644 index 000000000..9e70cc881 --- /dev/null +++ b/tests/nodes/triu_u32_out_neg/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(220); + data.append(57); + data.append(12); + data.append(49); + data.append(133); + data.append(203); + data.append(211); + data.append(116); + data.append(97); + data.append(161); + data.append(136); + data.append(68); + data.append(121); + data.append(175); + data.append(87); + data.append(36); + data.append(86); + data.append(11); + data.append(85); + data.append(82); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_out_neg/output_0.cairo b/tests/nodes/triu_u32_out_neg/output_0.cairo new file mode 100644 index 000000000..cf6a9d6bf --- /dev/null +++ b/tests/nodes/triu_u32_out_neg/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(220); + data.append(57); + data.append(12); + data.append(49); + data.append(133); + data.append(203); + data.append(211); + data.append(116); + data.append(97); + data.append(161); + data.append(136); + data.append(68); + data.append(121); + data.append(175); + data.append(87); + data.append(36); + data.append(86); + data.append(11); + data.append(85); + data.append(82); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_out_pos.cairo b/tests/nodes/triu_u32_out_pos.cairo new file mode 100644 index 000000000..abee4067e --- /dev/null +++ b/tests/nodes/triu_u32_out_pos.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_triu_u32_out_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_out_pos/input_0.cairo b/tests/nodes/triu_u32_out_pos/input_0.cairo new file mode 100644 index 000000000..60f218e01 --- /dev/null +++ b/tests/nodes/triu_u32_out_pos/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(193); + data.append(144); + data.append(205); + data.append(145); + data.append(118); + data.append(23); + data.append(17); + data.append(87); + data.append(243); + data.append(169); + data.append(151); + data.append(57); + data.append(211); + data.append(152); + data.append(175); + data.append(47); + data.append(201); + data.append(223); + data.append(42); + data.append(101); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_out_pos/output_0.cairo b/tests/nodes/triu_u32_out_pos/output_0.cairo new file mode 100644 index 000000000..fff9bce25 --- /dev/null +++ b/tests/nodes/triu_u32_out_pos/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + 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); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_pos.cairo b/tests/nodes/triu_u32_pos.cairo new file mode 100644 index 000000000..96d3cc91d --- /dev/null +++ b/tests/nodes/triu_u32_pos.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_triu_u32_pos() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 2); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_pos/input_0.cairo b/tests/nodes/triu_u32_pos/input_0.cairo new file mode 100644 index 000000000..e5559bb5c --- /dev/null +++ b/tests/nodes/triu_u32_pos/input_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(87); + data.append(183); + data.append(123); + data.append(66); + data.append(19); + data.append(149); + data.append(68); + data.append(125); + data.append(0); + data.append(159); + data.append(126); + data.append(205); + data.append(123); + data.append(17); + data.append(4); + data.append(174); + data.append(92); + data.append(233); + data.append(181); + data.append(26); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_pos/output_0.cairo b/tests/nodes/triu_u32_pos/output_0.cairo new file mode 100644 index 000000000..f7ade65b8 --- /dev/null +++ b/tests/nodes/triu_u32_pos/output_0.cairo @@ -0,0 +1,32 @@ +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(4); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(123); + data.append(66); + data.append(19); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(159); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(4); + 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/triu_u32_square.cairo b/tests/nodes/triu_u32_square.cairo new file mode 100644 index 000000000..1996e642d --- /dev/null +++ b/tests/nodes/triu_u32_square.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_triu_u32_square() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 0); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_square/input_0.cairo b/tests/nodes/triu_u32_square/input_0.cairo new file mode 100644 index 000000000..f43b5d341 --- /dev/null +++ b/tests/nodes/triu_u32_square/input_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(221); + data.append(99); + data.append(210); + data.append(132); + data.append(78); + data.append(194); + data.append(197); + data.append(177); + data.append(143); + data.append(17); + data.append(167); + data.append(35); + data.append(146); + data.append(51); + data.append(144); + data.append(72); + data.append(42); + data.append(127); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_square/output_0.cairo b/tests/nodes/triu_u32_square/output_0.cairo new file mode 100644 index 000000000..78eb82b38 --- /dev/null +++ b/tests/nodes/triu_u32_square/output_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(221); + data.append(99); + data.append(210); + data.append(0); + data.append(78); + data.append(194); + data.append(0); + data.append(0); + data.append(143); + data.append(17); + data.append(167); + data.append(35); + data.append(0); + data.append(51); + data.append(144); + data.append(0); + data.append(0); + data.append(127); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_square_neg.cairo b/tests/nodes/triu_u32_square_neg.cairo new file mode 100644 index 000000000..f3c36ea2f --- /dev/null +++ b/tests/nodes/triu_u32_square_neg.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_triu_u32_square_neg() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, -1); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_square_neg/input_0.cairo b/tests/nodes/triu_u32_square_neg/input_0.cairo new file mode 100644 index 000000000..9747a559f --- /dev/null +++ b/tests/nodes/triu_u32_square_neg/input_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(38); + data.append(103); + data.append(89); + data.append(80); + data.append(35); + data.append(166); + data.append(47); + data.append(229); + data.append(247); + data.append(77); + data.append(3); + data.append(229); + data.append(236); + data.append(225); + data.append(89); + data.append(27); + data.append(43); + data.append(253); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_square_neg/output_0.cairo b/tests/nodes/triu_u32_square_neg/output_0.cairo new file mode 100644 index 000000000..bdfe12b09 --- /dev/null +++ b/tests/nodes/triu_u32_square_neg/output_0.cairo @@ -0,0 +1,31 @@ +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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(38); + data.append(103); + data.append(89); + data.append(80); + data.append(35); + data.append(166); + data.append(0); + data.append(229); + data.append(247); + data.append(77); + data.append(3); + data.append(229); + data.append(236); + data.append(225); + data.append(89); + data.append(0); + data.append(43); + data.append(253); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_zero.cairo b/tests/nodes/triu_u32_zero.cairo new file mode 100644 index 000000000..22f6bdad1 --- /dev/null +++ b/tests/nodes/triu_u32_zero.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_triu_u32_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.trilu(true, 6); + + assert_eq(y, z); +} diff --git a/tests/nodes/triu_u32_zero/input_0.cairo b/tests/nodes/triu_u32_zero/input_0.cairo new file mode 100644 index 000000000..179e42905 --- /dev/null +++ b/tests/nodes/triu_u32_zero/input_0.cairo @@ -0,0 +1,13 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/triu_u32_zero/output_0.cairo b/tests/nodes/triu_u32_zero/output_0.cairo new file mode 100644 index 000000000..9b9157818 --- /dev/null +++ b/tests/nodes/triu_u32_zero/output_0.cairo @@ -0,0 +1,13 @@ +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(3); + shape.append(0); + shape.append(5); + + let mut data = ArrayTrait::new(); + TensorTrait::new(shape.span(), data.span()) +} From 81c76d6eb3a732cc5f8d8ede7183b3100eea4cfd Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 3 Nov 2023 10:02:14 +0200 Subject: [PATCH 021/127] start treen ensemble classifier --- src/operators/ml/tree_ensemble.cairo | 3 +- src/operators/ml/tree_ensemble/core.cairo | 10 ++++-- .../tree_ensemble_classifier.cairo | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index ef33ab296..0f09fa8d1 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1 +1,2 @@ -mod core; \ No newline at end of file +mod core; +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 31508ab55..46a4762f5 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -11,12 +11,16 @@ impl UsizeDictDrop of Drop>; #[derive(Copy, Drop)] struct TreeEnsembleAttributes { - nodes_modes: Span, + base_values: Option>, + nodes_falsenodeids: Span, nodes_featureids: Span, + nodes_hitrates: Span, nodes_missing_value_tracks_true: Span, - nodes_values: Span, + nodes_modes: Span, + nodes_nodeids: Span, + nodes_treeids: Span, nodes_truenodeids: Span, - nodes_falsenodeids: Span, + nodes_values: Span, } #[derive(Copy, Drop)] diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo new file mode 100644 index 000000000..e2ea89176 --- /dev/null +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -0,0 +1,33 @@ +use orion::numbers::NumberTrait; +use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleTrait, TreeEnsembleImpl}; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::ArrayTraitExt; +use alexandria_data_structures::vec::{VecTrait, NullableVec}; + +#[derive(Copy, Drop)] +enum PostTransform { + None, + Logistic, + Softmax, + SoftmaxZero, + Probit, +} + +fn classify< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq, +Add, +// +Drop<(Felt252DictEntry::>, Nullable::)>, +// +Copy>> +>( + ref self: TreeEnsemble, + X: Tensor, + post_transform: PostTransform, + class_labels: Span +) { + let leaves_index = self.leave_index_tree(X); + let n_classes = class_labels.len(); + let res_shape: Span = array![*leaves_index.shape[0], n_classes].span(); +} + From 8fc75edad067cdf5d125c378235c2a9265e7092e Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 3 Nov 2023 10:23:58 +0200 Subject: [PATCH 022/127] implement mut matrix --- src/operators.cairo | 1 + src/operators/matrix.cairo | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/operators/matrix.cairo diff --git a/src/operators.cairo b/src/operators.cairo index e71b8e6dc..eee74cf89 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -1,3 +1,4 @@ mod tensor; mod nn; mod ml; +mod matrix; \ No newline at end of file diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo new file mode 100644 index 000000000..4baec91af --- /dev/null +++ b/src/operators/matrix.cairo @@ -0,0 +1,43 @@ +use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; + +impl VecCopy of Copy>; +impl NullCopy of Copy>>; +impl VecDrop of Drop>; +impl NullDrop of Drop>>; + +#[derive(Copy, Drop)] +struct MutMatrix { + data: NullableVec, + rows: usize, + cols: usize, +} + +#[generate_trait] +impl MutMatrixImpl, +Copy> of MutMatrixTrait { + // Constructor for the Matrix + fn new(rows: usize, cols: usize) -> MutMatrix { + MutMatrix { data: NullableVecImpl::new(), rows: rows, cols: cols } + } + + // Get the value at (row, col) + fn get(ref self: MutMatrix, row: usize, col: usize) -> Option { + if row >= self.rows || col >= self.cols { + Option::None + } else { + self.data.get(row * self.cols + col) + } + } + + // Set the value at (row, col) + fn set(ref self: MutMatrix, row: usize, col: usize, value: T) { + if row < self.rows && col < self.cols { + let index = row * self.cols + col; + self.data.set(index, value) + } + } + + // Returns the shape of the matrix as (rows, cols) + fn shape(self: MutMatrix) -> (usize, usize) { + (self.rows, self.cols) + } +} From 9c084a47124ab252a62c35ed2162820bb622353c Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Fri, 3 Nov 2023 14:14:53 +0100 Subject: [PATCH 023/127] scarb.lock update --- Scarb.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarb.lock b/Scarb.lock index 85e5484e6..65dbec62d 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -13,7 +13,7 @@ source = "git+https://github.com/raphaelDkhn/cubit.git#e6331ebf98c5d5f442a0e5ede [[package]] name = "orion" -version = "0.1.2" +version = "0.1.5" dependencies = [ "alexandria_data_structures", "cubit", From 4682ccfdf06cf6cb6c69f906a0863b90c59d136d Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Fri, 3 Nov 2023 16:45:07 +0100 Subject: [PATCH 024/127] reducel1 operator --- src/operators/tensor/core.cairo | 42 +++++++++++++++++++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 3 +- src/operators/tensor/math/reduce_l1.cairo | 25 +++++++++++ 12 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/math/reduce_l1.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 44303e8c9..e58c630f4 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -85,6 +85,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3041,6 +3042,47 @@ trait TensorTrait { /// ``` /// fn round(self: @Tensor) -> Tensor; + /// ## tensor.reduce_l1 + /// + /// ```rust + /// fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the L1 norm of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_l1_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_l1` function as follows. + /// return tensor.reduce_l1(axis: 1, keepdims: false); + /// } + /// >>> [[2,4],[10,12]] + /// ``` + /// + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8a85d5683..22401fe66 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -258,6 +258,10 @@ impl FP16x16Tensor of TensorTrait { math::round::round(*self) } + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } + } /// 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 26a5c8060..d5b8f4e97 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -267,6 +267,10 @@ impl FP16x16WTensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 e80b2946d..abd2f5b4a 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -258,6 +258,10 @@ impl FP32x32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 80189b701..f401bf25a 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -258,6 +258,10 @@ impl FP64x64Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 98bf543b6..9a78f1c1a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -257,6 +257,10 @@ impl FP8x23Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 bb40c169b..9a300de50 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -258,6 +258,10 @@ impl FP8x23WTensor of TensorTrait { math::round::round(*self) } + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } + } /// 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 988e81ab5..ad1556915 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -256,6 +256,10 @@ impl I32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 bc1de11ca..9b6104f09 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -255,6 +255,10 @@ impl I8Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// 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 d5747877d..65cf3aad8 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -249,6 +249,10 @@ impl U32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l1::reduce_l1(self, axis, keepdims) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 69473df94..e70237aa0 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -37,4 +37,5 @@ mod sign; mod and; mod neg; mod where; -mod round; \ No newline at end of file +mod round; +mod reduce_l1; \ No newline at end of file diff --git a/src/operators/tensor/math/reduce_l1.cairo b/src/operators/tensor/math/reduce_l1.cairo new file mode 100644 index 000000000..a53f2507e --- /dev/null +++ b/src/operators/tensor/math/reduce_l1.cairo @@ -0,0 +1,25 @@ +use core::option::OptionTrait; +use array::ArrayTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; +/// Cf: TensorTrait::reduce_sum docstring +fn reduce_l1< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, +>( + self: @Tensor, axis: usize, keepdims: bool +) -> Tensor { + let data_abs = self.abs(); + return data_abs.reduce_sum(axis: axis, keepdims: keepdims); + +} \ No newline at end of file From a9c371f1157ff6ba8b32f001542a1740bb43d897 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Sat, 4 Nov 2023 12:49:06 +0100 Subject: [PATCH 025/127] reduce l2 implemetatiotns added --- src/operators/tensor/implementations/tensor_fp16x16wide.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp32x32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp64x64.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp8x23.cairo | 3 +++ src/operators/tensor/implementations/tensor_fp8x23wide.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i8.cairo | 4 ++++ src/operators/tensor/implementations/tensor_u32.cairo | 4 ++++ src/operators/tensor/math/reduce_l2.cairo | 0 9 files changed, 31 insertions(+) create mode 100644 src/operators/tensor/math/reduce_l2.cairo diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 26a5c8060..e196602db 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -267,6 +267,10 @@ impl FP16x16WTensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 e80b2946d..3f839d670 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -258,6 +258,10 @@ impl FP32x32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 80189b701..92736823a 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -258,6 +258,10 @@ impl FP64x64Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 98bf543b6..cc669e748 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -257,6 +257,9 @@ impl FP8x23Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 bb40c169b..6808d3694 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -258,6 +258,10 @@ impl FP8x23WTensor of TensorTrait { math::round::round(*self) } + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } + } /// 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 988e81ab5..7bdea9223 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -256,6 +256,10 @@ impl I32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 bc1de11ca..b3b3dd49e 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -255,6 +255,10 @@ impl I8Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// 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 d5747877d..0a4a5deb2 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -249,6 +249,10 @@ impl U32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo new file mode 100644 index 000000000..e69de29bb From 025195f863211574aafd3b54ed7857502c5251cc Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Sun, 5 Nov 2023 10:05:26 +0100 Subject: [PATCH 026/127] Reduce L2 test --- docs/CHANGELOG.md | 5 + docs/SUMMARY.md | 2 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/tensor.min.md | 2 +- .../operators/tensor/tensor.where.md | 2 +- nodegen/node/reduce_l2.py | 110 ++++++++++++++++++ src/operators/tensor/core.cairo | 42 +++++++ src/operators/tensor/helpers.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 1 + .../implementations/tensor_fp8x23wide.cairo | 1 - .../tensor/implementations/tensor_i32.cairo | 3 +- .../tensor/implementations/tensor_i8.cairo | 3 +- .../tensor/implementations/tensor_u32.cairo | 3 +- src/operators/tensor/math.cairo | 3 +- src/operators/tensor/math/reduce_l2.cairo | 56 +++++++++ tests/nodes.cairo | 6 + ...ce_l2_fp16x16_export_do_not_keepdims.cairo | 20 ++++ .../input_0.cairo | 27 +++++ .../output_0.cairo | 20 ++++ .../reduce_l2_fp16x16_export_keepdims.cairo | 20 ++++ .../input_0.cairo | 27 +++++ .../output_0.cairo | 21 ++++ ...p16x16_export_negative_axes_keepdims.cairo | 20 ++++ .../input_0.cairo | 42 +++++++ .../output_0.cairo | 24 ++++ ...uce_l2_fp8x23_export_do_not_keepdims.cairo | 20 ++++ .../input_0.cairo | 27 +++++ .../output_0.cairo | 20 ++++ .../reduce_l2_fp8x23_export_keepdims.cairo | 20 ++++ .../input_0.cairo | 27 +++++ .../output_0.cairo | 21 ++++ ...fp8x23_export_negative_axes_keepdims.cairo | 20 ++++ .../input_0.cairo | 42 +++++++ .../output_0.cairo | 24 ++++ 35 files changed, 681 insertions(+), 8 deletions(-) create mode 100644 nodegen/node/reduce_l2.py create mode 100644 tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd3cfa146..de4c44263 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2023-11-05 + +### Added +- ReduceL2 operator. + ## [Unreleased] - 2023-09-27 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index ea9613ce3..2c918ffd3 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -93,6 +93,8 @@ * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) + * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.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 d6dd0b35f..bd744ffe5 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -72,5 +72,6 @@ You can see below the list of current supported ONNX Operators: | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | +| [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | -Current Operators support: **61/156 (39%)** +Current Operators support: **62/156 (39%)** diff --git a/docs/framework/operators/tensor/tensor.min.md b/docs/framework/operators/tensor/tensor.min.md index 50c45e8ad..31157c2dc 100644 --- a/docs/framework/operators/tensor/tensor.min.md +++ b/docs/framework/operators/tensor/tensor.min.md @@ -19,8 +19,8 @@ A new `Tensor` containing the element-wise minimum values ## Panics +* Panics if tensor array is empty * Panics if the shapes are not equal or broadcastable -* Panics if tensor array length is not >= 1 ## Examples diff --git a/docs/framework/operators/tensor/tensor.where.md b/docs/framework/operators/tensor/tensor.where.md index 02d3b0059..187f12ecb 100644 --- a/docs/framework/operators/tensor/tensor.where.md +++ b/docs/framework/operators/tensor/tensor.where.md @@ -37,7 +37,7 @@ fn where_example() -> Tensor { let tensor_x = TensorTrait::::new( shape: array![2, 2].span(), data: array![2, 4, 6, 8].span(), ); - + let tensor_y = TensorTrait::::new( shape: array![2, 2].span(), data: array![1, 3, 5, 9].span(), ); diff --git a/nodegen/node/reduce_l2.py b/nodegen/node/reduce_l2.py new file mode 100644 index 000000000..0ed15fac2 --- /dev/null +++ b/nodegen/node/reduce_l2.py @@ -0,0 +1,110 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +import numpy as np + + +class Reduce_l2(RunAll): + @staticmethod + def reduce_l2_fp8x23(): + def reduce_l2_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False)).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l2_fp8x23_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(2, false)", name) + + def reduce_l2_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l2_fp8x23_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(2, true)", name) + + def reduce_l2_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l2_fp8x23_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(0, true)", name) + + + reduce_l2_export_do_not_keepdims() + reduce_l2_export_keepdims() + reduce_l2_axis_0() + + @staticmethod + def reduce_l2_fp16x16(): + def reduce_l2_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False)).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l2_fp16x16_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(2, false)", name) + + def reduce_l2_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l2_fp16x16_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(2, true)", name) + + def reduce_l2_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l2_fp16x16_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l2(0, true)", name) + + + reduce_l2_export_do_not_keepdims() + reduce_l2_export_keepdims() + reduce_l2_axis_0() \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 44303e8c9..84622e592 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -85,6 +85,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3041,6 +3042,47 @@ trait TensorTrait { /// ``` /// fn round(self: @Tensor) -> Tensor; + /// ## tensor.reduce_l2 + /// + /// ```rust + /// fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the L2 norm of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_l2_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_l2` function as follows. + /// return tensor.reduce_l2(axis: 1, keepdims: false); + /// } + /// >>> [[2,4],[10,12]] + /// ``` + /// + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 471ec7e4e..0aad721d7 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -316,3 +316,4 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span { math::round::round(*self) } + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_l2::reduce_l2(self, axis, keepdims) + } + } /// 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 cc669e748..3c334f50f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -257,6 +257,7 @@ impl FP8x23Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) } + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 6808d3694..a50612c54 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -261,7 +261,6 @@ impl FP8x23WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } - } /// 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 7bdea9223..9e6a2c9cc 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -258,7 +258,8 @@ impl I32Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_l2::reduce_l2(self, axis, keepdims) + // math::reduce_l2::reduce_l2(self, axis, keepdims) + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index b3b3dd49e..ba9fd5576 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -257,7 +257,8 @@ impl I8Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_l2::reduce_l2(self, axis, keepdims) + // math::reduce_l2::reduce_l2(self, axis, keepdims) + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 0a4a5deb2..494097d80 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -251,7 +251,8 @@ impl U32Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_l2::reduce_l2(self, axis, keepdims) + // math::reduce_l2::reduce_l2(self, axis, keepdims) + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 69473df94..84e58a2eb 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -37,4 +37,5 @@ mod sign; mod and; mod neg; mod where; -mod round; \ No newline at end of file +mod round; +mod reduce_l2; \ No newline at end of file diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo index e69de29bb..94e6de46c 100644 --- a/src/operators/tensor/math/reduce_l2.cairo +++ b/src/operators/tensor/math/reduce_l2.cairo @@ -0,0 +1,56 @@ +use core::option::OptionTrait; +use array::ArrayTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; + +fn square< + T, + MAG, + impl FTensorTrait: TensorTrait, + impl FFixed: FixedTrait, + impl FNumber: NumberTrait, + impl TMul: Mul, + impl FCopy: Copy, + impl FDrop: Drop, +>( + self: @Tensor +) -> Tensor { + let mut data = *self.data; + let mut output_data = ArrayTrait::new(); + + loop { + match data.pop_front() { + Option::Some(item) => { + let ele = *item; + output_data.append(ele * ele); + }, + Option::None(_) => { break; } + }; + }; + + let tensor_square = TensorTrait::new(*self.shape, output_data.span()); + return tensor_square; +} +/// Cf: TensorTrait::reduce_l2 docstring +fn reduce_l2< + T, + MAG, + impl TTensor: TensorTrait, + impl FFixed: FixedTrait, + impl TNumber: NumberTrait, + impl TMul: Mul, + impl TCopy: Copy, + impl TDrop: Drop, +>( + self: @Tensor, axis: usize, keepdims: bool +) -> Tensor { + let tensor_square = square(self); + let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); + return tensor_square_sum.sqrt(); + +} \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 4a6d7c8cb..ca936fdf3 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -516,3 +516,9 @@ mod max_u32_three_tensors; mod max_u32_broadcast_three_tensors; mod max_u32_two_tensors; mod max_u32_broadcast_two_tensors; +mod reduce_l2_fp16x16_export_do_not_keepdims; +mod reduce_l2_fp16x16_export_keepdims; +mod reduce_l2_fp16x16_export_negative_axes_keepdims; +mod reduce_l2_fp8x23_export_do_not_keepdims; +mod reduce_l2_fp8x23_export_keepdims; +mod reduce_l2_fp8x23_export_negative_axes_keepdims; diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo new file mode 100644 index 000000000..fa5bc1a97 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l2_fp16x16_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..0c4686379 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + 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: 3, sign: false }); + data.append(FP16x16 { mag: 4, 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/nodes/reduce_l2_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo new file mode 100644 index 000000000..aa7730801 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l2_fp16x16_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo new file mode 100644 index 000000000..c218e25b5 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + 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: 3, sign: false }); + data.append(FP16x16 { mag: 4, 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/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..799cac6a2 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l2_fp16x16_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..3fb854ee1 --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + data.append(FP16x16 { mag: 13, sign: false }); + data.append(FP16x16 { mag: 14, sign: false }); + data.append(FP16x16 { mag: 15, sign: false }); + data.append(FP16x16 { mag: 16, sign: false }); + data.append(FP16x16 { mag: 17, sign: false }); + data.append(FP16x16 { mag: 18, sign: false }); + data.append(FP16x16 { mag: 19, sign: false }); + data.append(FP16x16 { mag: 20, sign: false }); + data.append(FP16x16 { mag: 21, sign: false }); + data.append(FP16x16 { mag: 22, sign: false }); + data.append(FP16x16 { mag: 23, sign: false }); + data.append(FP16x16 { mag: 24, sign: false }); + data.append(FP16x16 { mag: 25, sign: false }); + data.append(FP16x16 { mag: 26, sign: false }); + data.append(FP16x16 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..c73dd7fee --- /dev/null +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,24 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo new file mode 100644 index 000000000..e3ff241a2 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.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_reduce_l2_fp8x23_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..0f1e2d435 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + 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: 3, sign: false }); + data.append(FP8x23 { mag: 4, 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/nodes/reduce_l2_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo new file mode 100644 index 000000000..f9eb738ce --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims.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_reduce_l2_fp8x23_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo new file mode 100644 index 000000000..0eb110933 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + 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: 3, sign: false }); + data.append(FP8x23 { mag: 4, 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/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..8b902498b --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.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_reduce_l2_fp8x23_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l2(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..c811d8c9e --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + data.append(FP8x23 { mag: 13, sign: false }); + data.append(FP8x23 { mag: 14, sign: false }); + data.append(FP8x23 { mag: 15, sign: false }); + data.append(FP8x23 { mag: 16, sign: false }); + data.append(FP8x23 { mag: 17, sign: false }); + data.append(FP8x23 { mag: 18, sign: false }); + data.append(FP8x23 { mag: 19, sign: false }); + data.append(FP8x23 { mag: 20, sign: false }); + data.append(FP8x23 { mag: 21, sign: false }); + data.append(FP8x23 { mag: 22, sign: false }); + data.append(FP8x23 { mag: 23, sign: false }); + data.append(FP8x23 { mag: 24, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 26, sign: false }); + data.append(FP8x23 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..cfad71378 --- /dev/null +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,24 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From 2dc5a8145b08ed5ace6186813c9cf91b5d53802f Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Sun, 5 Nov 2023 10:16:37 +0100 Subject: [PATCH 027/127] Reduce L2 core docs --- src/operators/tensor/core.cairo | 19 ++++++--- src/operators/tensor/math/reduce_l2.cairo | 51 ++++++++++++++++++++++- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 84622e592..b71ef0e77 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3072,14 +3072,21 @@ trait TensorTrait { /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// /// fn reduce_l2_example() -> Tensor { - /// let tensor = TensorTrait::::new( - /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), - /// ); + /// + /// let mut shape = ArrayTrait::::new(); + /// shape.append(2); + /// shape.append(2); + /// let mut data = ArrayTrait::new(); + /// data.append(FixedTrait::new_unscaled(1, false)); + /// data.append(FixedTrait::new_unscaled(2, false)); + /// data.append(FixedTrait::new_unscaled(3, false)); + /// data.append(FixedTrait::new_unscaled(5, false)); + /// let tensor = TensorTrait::::new(shape.span(), data.span()); /// - /// // We can call `reduce_l2` function as follows. - /// return tensor.reduce_l2(axis: 1, keepdims: false); + /// We can call `reduce_l2` function as follows. + /// return tensor.reduce_l2(axis: 1, keepdims: true); /// } - /// >>> [[2,4],[10,12]] + /// >>> [[0x11e3779, 0x2ea5ca1]] /// ``` /// fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo index 94e6de46c..b5a4bb667 100644 --- a/src/operators/tensor/math/reduce_l2.cairo +++ b/src/operators/tensor/math/reduce_l2.cairo @@ -53,4 +53,53 @@ fn reduce_l2< let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); return tensor_square_sum.sqrt(); -} \ No newline at end of file +} + + + +// Tests -------------------------------------------------------------------------------------------------------------- + +use orion::numbers::fixed_point::implementations::fp8x23::helpers::assert_precise; + +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +use orion::numbers::fixed_point::implementations::fp8x23::core::FP8x23; +use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor; + +fn data() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FixedTrait::new_unscaled(1, false)); + data.append(FixedTrait::new_unscaled(2, false)); + data.append(FixedTrait::new_unscaled(3, false)); + data.append(FixedTrait::new_unscaled(5, false)); + + let tensor = TensorTrait::::new(shape.span(), data.span()); + + return tensor; +} + +#[test] +#[available_gas(2000000000)] +fn test_reduce_l2_default() { + let mut data = data(); + + let y = data.reduce_l2(axis: 1, keepdims: true); + let mut output = y.data; + + loop { + match output.pop_front() { + Option::Some(item) => { + (*item).print(); + }, + Option::None(_) => { break; } + }; + }; + +} From f1c109d4be92bf739e1f6998715eab5f0e037640 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 5 Nov 2023 17:30:29 +0200 Subject: [PATCH 028/127] implement TreeEnsembleClassifierImpl --- .../tree_ensemble_classifier.cairo | 256 ++++++++++++++++-- 1 file changed, 239 insertions(+), 17 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index e2ea89176..7f0bb025e 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,33 +1,255 @@ +use core::dict::Felt252DictEntryTrait; +use nullable::{match_nullable, FromNullableResult}; + +use orion::operators::tensor::{Tensor, TensorTrait}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; use orion::numbers::NumberTrait; -use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleTrait, TreeEnsembleImpl}; -use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -use alexandria_data_structures::array_ext::ArrayTraitExt; -use alexandria_data_structures::vec::{VecTrait, NullableVec}; + +#[derive(Copy, Drop)] +struct TreeEnsembleClassifier { + ensemble: TreeEnsemble, + class_ids: Span, + class_nodeids: Span, + class_treeids: Span, + class_weights: Span, + class_labels: Span, + base_values: Option>, + post_transform: PostTransform, +} #[derive(Copy, Drop)] enum PostTransform { None, - Logistic, Softmax, + Logistic, SoftmaxZero, Probit, } +#[generate_trait] +impl TreeEnsembleClassifierImpl< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +Copy>>>, + +Copy>>, + +Copy>>, + +Drop<(Span::, Felt252Dict::>)> +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); + + (predictions, final_scores) + } +} + +fn compute_scores< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +Copy>>>, + +Copy>>, + +Copy>> +>( + ref self: TreeEnsembleClassifier, leaf_indices: Tensor +) -> (Span, Felt252Dict::>) { + // Initialize the scores array, either with base_values or zeros + let num_samples = *leaf_indices.shape[0]; + let num_classes = self.class_labels.len(); + let mut scores_shape = array![num_samples, num_classes].span(); + + // Store scores in dictionary because of immutability of array. + let mut scores_data: Felt252Dict> = Default::default(); + if self.base_values.is_some() { + // Repeat base values for each sample + let mut sample_index: usize = 0; + loop { + if sample_index == num_samples { + break; + } + + let mut class_index: usize = 0; + loop { + if class_index == num_classes { + break; + } + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(sample_index.into(), class_index.into()); + scores_data + .insert(key, NullableTrait::new(*self.base_values.unwrap().at(class_index))); + + class_index += 1; + }; + + sample_index += 1; + } + } + + // Compute class index mapping + let mut class_index: Felt252Dict>> = Default::default(); + let mut class_weights = self.class_weights; + let mut class_ids = self.class_ids; + let mut class_nodeids = self.class_nodeids; + let mut class_treeids = self.class_treeids; + loop { + match class_weights.pop_front() { + Option::Some(class_weight) => { + let mut class_id: usize = *class_ids.pop_front().unwrap(); + let mut node_id: usize = *class_nodeids.pop_front().unwrap(); + let mut tree_id: usize = *class_treeids.pop_front().unwrap(); + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tree_id.into(), node_id.into()); + + let (entry, _prev_value) = class_index.entry(key); + match match_nullable(_prev_value) { + FromNullableResult::Null(()) => { + entry.finalize(NullableTrait::new(array![])) + }, + FromNullableResult::NotNull(val) => { + let mut new_val = _prev_value.deref(); + new_val.append((class_id, *class_weight)); + entry.finalize(NullableTrait::new(new_val)) + }, + }; + }, + Option::None(_) => { break; } + }; + }; + + // Update scores based on class index mapping + let mut sample_index: usize = 0; + let mut leaf_indices_data = leaf_indices.data; + loop { + match leaf_indices_data.pop_front() { + Option::Some(leaf_index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), + (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() + ); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { continue; }, + FromNullableResult::NotNull(class_weight_pairs) => { + let mut class_weight_pairs_span = class_weight_pairs.unbox().span(); + loop { + match class_weight_pairs_span.pop_front() { + Option::Some(class_weight_pair) => { + let (class_id, class_weight) = *class_weight_pair; + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash((sample_index).into(), (class_id).into()); + + let (entry, value) = scores_data.entry(key); + let value = value.deref(); + entry.finalize(NullableTrait::new(value + class_weight)); + }, + Option::None(_) => { break; } + }; + } + }, + } + + sample_index += 1; + }, + Option::None(_) => { break; } + }; + }; + + // Apply post-transform to scores + match self.post_transform { + PostTransform::None => {}, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + } + + (scores_shape, scores_data) +} + fn classify< - T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq, +Add, -// +Drop<(Felt252DictEntry::>, Nullable::)>, -// +Copy>> + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +Copy>>>, + +Copy>>, + +Copy>>, + +Drop<(Span::, Felt252Dict::>)> >( - ref self: TreeEnsemble, - X: Tensor, - post_transform: PostTransform, - class_labels: Span -) { - let leaves_index = self.leave_index_tree(X); - let n_classes = class_labels.len(); - let res_shape: Span = array![*leaves_index.shape[0], n_classes].span(); + ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) +) -> (Tensor, Tensor) { + let (scores_shape, mut scores_data) = scores; + let num_samples = *scores_shape[0]; + let num_classes = *scores_shape[1]; + + let predictions_shape = array![num_samples].span(); + let mut final_scores_shape = scores_shape; + let mut predictions_data = ArrayTrait::new(); + let mut final_scores_data = ArrayTrait::new(); + + let mut sample_index: usize = 0; + loop { + if sample_index == num_samples { + break; + } + + // Placeholder for the minimum value for type T + let mut max_score = NumberTrait::::min_value(); + let mut max_class_index = 0; + + let mut class_index: usize = 0; + loop { + if class_index == num_classes { + break; + } + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash((sample_index).into(), (class_index).into()); + let score = scores_data[key].deref(); + + if score > max_score { + max_score = score; + max_class_index = class_index; + } + + class_index += 1; + }; + + final_scores_data.append(max_score); + predictions_data.append(max_class_index); + sample_index += 1; + }; + + ( + TensorTrait::new(predictions_shape, predictions_data.span()), + TensorTrait::new(final_scores_shape, final_scores_data.span()) + ) } From 5b3c561a1276540f4d4d102d9a5b0548b5279259 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Sun, 5 Nov 2023 17:38:39 +0100 Subject: [PATCH 029/127] removed unneccesary test code and comments --- .../tensor/implementations/tensor_i32.cairo | 1 - .../tensor/implementations/tensor_i8.cairo | 1 - .../tensor/implementations/tensor_u32.cairo | 1 - src/operators/tensor/math/reduce_l2.cairo | 51 +------------------ 4 files changed, 1 insertion(+), 53 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 9e6a2c9cc..38d202de1 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -258,7 +258,6 @@ impl I32Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - // math::reduce_l2::reduce_l2(self, axis, keepdims) panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index ba9fd5576..d14d7d873 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -257,7 +257,6 @@ impl I8Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - // math::reduce_l2::reduce_l2(self, axis, keepdims) panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 494097d80..906b38618 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -251,7 +251,6 @@ impl U32Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - // math::reduce_l2::reduce_l2(self, axis, keepdims) panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo index b5a4bb667..94e6de46c 100644 --- a/src/operators/tensor/math/reduce_l2.cairo +++ b/src/operators/tensor/math/reduce_l2.cairo @@ -53,53 +53,4 @@ fn reduce_l2< let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); return tensor_square_sum.sqrt(); -} - - - -// Tests -------------------------------------------------------------------------------------------------------------- - -use orion::numbers::fixed_point::implementations::fp8x23::helpers::assert_precise; - -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::assert_eq; - -use orion::numbers::fixed_point::implementations::fp8x23::core::FP8x23; -use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor; - -fn data() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FixedTrait::new_unscaled(1, false)); - data.append(FixedTrait::new_unscaled(2, false)); - data.append(FixedTrait::new_unscaled(3, false)); - data.append(FixedTrait::new_unscaled(5, false)); - - let tensor = TensorTrait::::new(shape.span(), data.span()); - - return tensor; -} - -#[test] -#[available_gas(2000000000)] -fn test_reduce_l2_default() { - let mut data = data(); - - let y = data.reduce_l2(axis: 1, keepdims: true); - let mut output = y.data; - - loop { - match output.pop_front() { - Option::Some(item) => { - (*item).print(); - }, - Option::None(_) => { break; } - }; - }; - -} +} \ No newline at end of file From f6c42b8b2a3784ecd282b0017146f8dc6dcbcab7 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 07:36:46 +0100 Subject: [PATCH 030/127] reduce l1 tests --- nodegen/node/reduce_l1.py | 266 ++++++++++++++++++ tests/nodes.cairo | 16 ++ ...ce_l1_fp16x16_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 20 ++ .../reduce_l1_fp16x16_export_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 21 ++ ...p16x16_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 42 +++ .../output_0.cairo | 24 ++ ...uce_l1_fp8x23_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 20 ++ .../reduce_l1_fp8x23_export_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 21 ++ ...fp8x23_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 42 +++ .../output_0.cairo | 24 ++ ...reduce_l1_i32_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 19 ++ .../nodes/reduce_l1_i32_export_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 20 ++ ...l1_i32_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 41 +++ .../output_0.cairo | 23 ++ .../reduce_l1_i8_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 19 ++ .../nodes/reduce_l1_i8_export_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 20 ++ ..._l1_i8_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 41 +++ .../output_0.cairo | 23 ++ ...reduce_l1_u32_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 25 ++ .../output_0.cairo | 18 ++ .../nodes/reduce_l1_u32_export_keepdims.cairo | 20 ++ .../input_0.cairo | 25 ++ .../output_0.cairo | 19 ++ ...l1_u32_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 40 +++ .../output_0.cairo | 22 ++ 47 files changed, 1363 insertions(+) create mode 100644 nodegen/node/reduce_l1.py create mode 100644 tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo diff --git a/nodegen/node/reduce_l1.py b/nodegen/node/reduce_l1.py new file mode 100644 index 000000000..2b5f4ee31 --- /dev/null +++ b/nodegen/node/reduce_l1.py @@ -0,0 +1,266 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +import numpy as np + + +class Reduce_l1(RunAll): + @staticmethod + def reduce_l1_fp8x23(): + def reduce_l1_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l1_fp8x23_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, false)", name) + + def reduce_l1_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l1_fp8x23_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, true)", name) + + def reduce_l1_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_l1_fp8x23_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(0, true)", name) + + + reduce_l1_export_do_not_keepdims() + reduce_l1_export_keepdims() + reduce_l1_axis_0() + + @staticmethod + def reduce_l1_fp16x16(): + def reduce_l1_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l1_fp16x16_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, false)", name) + + def reduce_l1_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l1_fp16x16_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, true)", name) + + def reduce_l1_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_l1_fp16x16_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(0, true)", name) + + + reduce_l1_export_do_not_keepdims() + reduce_l1_export_keepdims() + reduce_l1_axis_0() + + @staticmethod + def reduce_l1_i8(): + def reduce_l1_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int8) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_l1_i8_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, false)", name) + + def reduce_l1_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int8) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_l1_i8_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, true)", name) + + def reduce_l1_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int8) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_l1_i8_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(0, true)", name) + + + reduce_l1_export_do_not_keepdims() + reduce_l1_export_keepdims() + reduce_l1_axis_0() + + @staticmethod + def reduce_l1_i32(): + def reduce_l1_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int32) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_l1_i32_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, false)", name) + + def reduce_l1_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_l1_i32_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, true)", name) + + def reduce_l1_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_l1_i32_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(0, true)", name) + + + reduce_l1_export_do_not_keepdims() + reduce_l1_export_keepdims() + reduce_l1_axis_0() + + @staticmethod + def reduce_l1_u32(): + def reduce_l1_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.uint32) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_l1_u32_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, false)", name) + + def reduce_l1_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.uint32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_l1_u32_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(2, true)", name) + + def reduce_l1_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.uint32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_l1_u32_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_l1(0, true)", name) + + + reduce_l1_export_do_not_keepdims() + reduce_l1_export_keepdims() + reduce_l1_axis_0() \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 4a6d7c8cb..e387113d8 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -516,3 +516,19 @@ mod max_u32_three_tensors; mod max_u32_broadcast_three_tensors; mod max_u32_two_tensors; mod max_u32_broadcast_two_tensors; +mod reduce_l1_fp16x16_export_do_not_keepdims; +mod reduce_l1_fp16x16_export_keepdims; +mod reduce_l1_fp16x16_export_negative_axes_keepdims; +mod reduce_l1_fp8x23_export_do_not_keepdims; +mod reduce_l1_fp8x23_export_keepdims; +mod reduce_l1_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_i32_export_do_not_keepdims; +mod reduce_l1_i32_export_keepdims; +mod reduce_l1_i32_export_negative_axes_keepdims; +mod reduce_l1_i8_export_do_not_keepdims; +mod reduce_l1_i8_export_keepdims; +mod reduce_l1_i8_export_negative_axes_keepdims; +mod reduce_l1_u32_export_do_not_keepdims; +mod reduce_l1_u32_export_keepdims; +mod reduce_l1_u32_export_negative_axes_keepdims; + diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo new file mode 100644 index 000000000..d2edc5b85 --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l1_fp16x16_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..8a217a3e3 --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 15, sign: false }); + data.append(FP16x16 { mag: 19, sign: false }); + data.append(FP16x16 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo new file mode 100644 index 000000000..beecff5ab --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l1_fp16x16_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo new file mode 100644 index 000000000..32d2bf963 --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 3, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 15, sign: false }); + data.append(FP16x16 { mag: 19, sign: false }); + data.append(FP16x16 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..a3c1a3b02 --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_l1_fp16x16_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..3fb854ee1 --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + data.append(FP16x16 { mag: 13, sign: false }); + data.append(FP16x16 { mag: 14, sign: false }); + data.append(FP16x16 { mag: 15, sign: false }); + data.append(FP16x16 { mag: 16, sign: false }); + data.append(FP16x16 { mag: 17, sign: false }); + data.append(FP16x16 { mag: 18, sign: false }); + data.append(FP16x16 { mag: 19, sign: false }); + data.append(FP16x16 { mag: 20, sign: false }); + data.append(FP16x16 { mag: 21, sign: false }); + data.append(FP16x16 { mag: 22, sign: false }); + data.append(FP16x16 { mag: 23, sign: false }); + data.append(FP16x16 { mag: 24, sign: false }); + data.append(FP16x16 { mag: 25, sign: false }); + data.append(FP16x16 { mag: 26, sign: false }); + data.append(FP16x16 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..8e67a074e --- /dev/null +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,24 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 30, sign: false }); + data.append(FP16x16 { mag: 33, sign: false }); + data.append(FP16x16 { mag: 36, sign: false }); + data.append(FP16x16 { mag: 39, sign: false }); + data.append(FP16x16 { mag: 42, sign: false }); + data.append(FP16x16 { mag: 45, sign: false }); + data.append(FP16x16 { mag: 48, sign: false }); + data.append(FP16x16 { mag: 51, sign: false }); + data.append(FP16x16 { mag: 54, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo new file mode 100644 index 000000000..0eba0ba94 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.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_reduce_l1_fp8x23_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..59d8271ec --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 3, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 15, sign: false }); + data.append(FP8x23 { mag: 19, sign: false }); + data.append(FP8x23 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo new file mode 100644 index 000000000..743a5b2d9 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims.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_reduce_l1_fp8x23_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo new file mode 100644 index 000000000..13d940044 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 3, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 15, sign: false }); + data.append(FP8x23 { mag: 19, sign: false }); + data.append(FP8x23 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..527596d05 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.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_reduce_l1_fp8x23_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..c811d8c9e --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + data.append(FP8x23 { mag: 13, sign: false }); + data.append(FP8x23 { mag: 14, sign: false }); + data.append(FP8x23 { mag: 15, sign: false }); + data.append(FP8x23 { mag: 16, sign: false }); + data.append(FP8x23 { mag: 17, sign: false }); + data.append(FP8x23 { mag: 18, sign: false }); + data.append(FP8x23 { mag: 19, sign: false }); + data.append(FP8x23 { mag: 20, sign: false }); + data.append(FP8x23 { mag: 21, sign: false }); + data.append(FP8x23 { mag: 22, sign: false }); + data.append(FP8x23 { mag: 23, sign: false }); + data.append(FP8x23 { mag: 24, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 26, sign: false }); + data.append(FP8x23 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..d3b359f75 --- /dev/null +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,24 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 30, sign: false }); + data.append(FP8x23 { mag: 33, sign: false }); + data.append(FP8x23 { mag: 36, sign: false }); + data.append(FP8x23 { mag: 39, sign: false }); + data.append(FP8x23 { mag: 42, sign: false }); + data.append(FP8x23 { mag: 45, sign: false }); + data.append(FP8x23 { mag: 48, sign: false }); + data.append(FP8x23 { mag: 51, sign: false }); + data.append(FP8x23 { mag: 54, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo new file mode 100644 index 000000000..b6999dcd9 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims.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_reduce_l1_i32_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..9eb75d28a --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..1702243f2 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_keepdims.cairo new file mode 100644 index 000000000..7dd39c047 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_keepdims.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_reduce_l1_i32_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo new file mode 100644 index 000000000..9eb75d28a --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo new file mode 100644 index 000000000..2635bd2d6 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..bc6e69942 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.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_reduce_l1_i32_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..6b7f8d481 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,41 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 23, sign: false }); + data.append(i32 { mag: 24, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 26, sign: false }); + data.append(i32 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..e823cfa25 --- /dev/null +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,23 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 30, sign: false }); + data.append(i32 { mag: 33, sign: false }); + data.append(i32 { mag: 36, sign: false }); + data.append(i32 { mag: 39, sign: false }); + data.append(i32 { mag: 42, sign: false }); + data.append(i32 { mag: 45, sign: false }); + data.append(i32 { mag: 48, sign: false }); + data.append(i32 { mag: 51, sign: false }); + data.append(i32 { mag: 54, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo new file mode 100644 index 000000000..dfea03f2a --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims.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_reduce_l1_i8_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..20c48f542 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 10, sign: false }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..3068a233d --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 15, sign: false }); + data.append(i8 { mag: 19, sign: false }); + data.append(i8 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_keepdims.cairo new file mode 100644 index 000000000..35b1d30c5 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_keepdims.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_reduce_l1_i8_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo new file mode 100644 index 000000000..20c48f542 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 10, sign: false }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo new file mode 100644 index 000000000..25e4fdc57 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 15, sign: false }); + data.append(i8 { mag: 19, sign: false }); + data.append(i8 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..79ec8d936 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.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_reduce_l1_i8_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..920e8898b --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,41 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 10, sign: false }); + data.append(i8 { mag: 11, sign: false }); + data.append(i8 { mag: 12, sign: false }); + data.append(i8 { mag: 13, sign: false }); + data.append(i8 { mag: 14, sign: false }); + data.append(i8 { mag: 15, sign: false }); + data.append(i8 { mag: 16, sign: false }); + data.append(i8 { mag: 17, sign: false }); + data.append(i8 { mag: 18, sign: false }); + data.append(i8 { mag: 19, sign: false }); + data.append(i8 { mag: 20, sign: false }); + data.append(i8 { mag: 21, sign: false }); + data.append(i8 { mag: 22, sign: false }); + data.append(i8 { mag: 23, sign: false }); + data.append(i8 { mag: 24, sign: false }); + data.append(i8 { mag: 25, sign: false }); + data.append(i8 { mag: 26, sign: false }); + data.append(i8 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..bc3a31f63 --- /dev/null +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,23 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 30, sign: false }); + data.append(i8 { mag: 33, sign: false }); + data.append(i8 { mag: 36, sign: false }); + data.append(i8 { mag: 39, sign: false }); + data.append(i8 { mag: 42, sign: false }); + data.append(i8 { mag: 45, sign: false }); + data.append(i8 { mag: 48, sign: false }); + data.append(i8 { mag: 51, sign: false }); + data.append(i8 { mag: 54, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo new file mode 100644 index 000000000..8a0b11c3b --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims.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_reduce_l1_u32_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..1aeead0b2 --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,25 @@ +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(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..a40dbfa0f --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,18 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(7); + data.append(11); + data.append(15); + data.append(19); + data.append(23); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_keepdims.cairo new file mode 100644 index 000000000..50ac5c706 --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_keepdims.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_reduce_l1_u32_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo new file mode 100644 index 000000000..1aeead0b2 --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo @@ -0,0 +1,25 @@ +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(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo new file mode 100644 index 000000000..7a97d1ba5 --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(7); + data.append(11); + data.append(15); + data.append(19); + data.append(23); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..99345a8bc --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.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_reduce_l1_u32_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_l1(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..9fce7f6df --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,40 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..42a13ba2a --- /dev/null +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,22 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(30); + data.append(33); + data.append(36); + data.append(39); + data.append(42); + data.append(45); + data.append(48); + data.append(51); + data.append(54); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From d2d60035d1383b1c9e50a154a13864d87ad1632b Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 07:41:37 +0100 Subject: [PATCH 031/127] updated summary and changelog --- docs/CHANGELOG.md | 5 +++ docs/SUMMARY.md | 2 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + docs/framework/operators/tensor/tensor.min.md | 2 +- .../operators/tensor/tensor.reduce_l1.md | 39 +++++++++++++++++++ .../operators/tensor/tensor.where.md | 2 +- 7 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.reduce_l1.md diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd3cfa146..08db85038 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2023-11-06 + +## Added +- Reduce L1 Operator. + ## [Unreleased] - 2023-09-27 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index ea9613ce3..18effec46 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -93,6 +93,8 @@ * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) + * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.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 d6dd0b35f..e584fc125 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -72,5 +72,6 @@ You can see below the list of current supported ONNX Operators: | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | +| [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | Current Operators support: **61/156 (39%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 48b1650ad..ccfde2752 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -89,6 +89,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | +| [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.min.md b/docs/framework/operators/tensor/tensor.min.md index 50c45e8ad..31157c2dc 100644 --- a/docs/framework/operators/tensor/tensor.min.md +++ b/docs/framework/operators/tensor/tensor.min.md @@ -19,8 +19,8 @@ A new `Tensor` containing the element-wise minimum values ## Panics +* Panics if tensor array is empty * Panics if the shapes are not equal or broadcastable -* Panics if tensor array length is not >= 1 ## Examples diff --git a/docs/framework/operators/tensor/tensor.reduce_l1.md b/docs/framework/operators/tensor/tensor.reduce_l1.md new file mode 100644 index 000000000..b4edd2a22 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_l1.md @@ -0,0 +1,39 @@ +## tensor.reduce_l1 + +```rust + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; +``` + +Computes the L1 norm of the input tensor's elements along the provided axes. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axis`(`usize`) - The dimension to reduce. +* `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axis reduced by summing its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_l1_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_l1` function as follows. + return tensor.reduce_l1(axis: 1, keepdims: false); +} +>>> [[2,4],[10,12]] +``` diff --git a/docs/framework/operators/tensor/tensor.where.md b/docs/framework/operators/tensor/tensor.where.md index 02d3b0059..187f12ecb 100644 --- a/docs/framework/operators/tensor/tensor.where.md +++ b/docs/framework/operators/tensor/tensor.where.md @@ -37,7 +37,7 @@ fn where_example() -> Tensor { let tensor_x = TensorTrait::::new( shape: array![2, 2].span(), data: array![2, 4, 6, 8].span(), ); - + let tensor_y = TensorTrait::::new( shape: array![2, 2].span(), data: array![1, 3, 5, 9].span(), ); From 885124d6e98b74a201fa1109d76c0596e06d1879 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 08:21:39 +0100 Subject: [PATCH 032/127] reduce l2 correct nodegen test --- nodegen/node/reduce_l2.py | 12 ++++++------ tests/nodes.cairo | 1 + .../output_0.cairo | 10 +++++----- .../output_0.cairo | 10 +++++----- .../output_0.cairo | 18 +++++++++--------- .../output_0.cairo | 10 +++++----- .../output_0.cairo | 10 +++++----- .../output_0.cairo | 18 +++++++++--------- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/nodegen/node/reduce_l2.py b/nodegen/node/reduce_l2.py index 0ed15fac2..081125f54 100644 --- a/nodegen/node/reduce_l2.py +++ b/nodegen/node/reduce_l2.py @@ -12,7 +12,7 @@ def reduce_l2_export_do_not_keepdims(): axes = np.array([2], dtype=np.int64) keepdims = False x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=False)).astype(np.int64) x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) @@ -27,7 +27,7 @@ def reduce_l2_export_keepdims(): axes = np.array([2], dtype=np.int64) keepdims = True x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=True)).astype(np.int64) x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) @@ -42,7 +42,7 @@ def reduce_l2_axis_0(): axes = np.array([0], dtype=np.int64) keepdims = True x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=True)).astype(np.int64) x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) @@ -64,7 +64,7 @@ def reduce_l2_export_do_not_keepdims(): axes = np.array([2], dtype=np.int64) keepdims = False x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=False)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=False)).astype(np.int64) x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) @@ -79,7 +79,7 @@ def reduce_l2_export_keepdims(): axes = np.array([2], dtype=np.int64) keepdims = True x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=True)).astype(np.int64) x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) @@ -94,7 +94,7 @@ def reduce_l2_axis_0(): axes = np.array([0], dtype=np.int64) keepdims = True x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) - y = np.sqrt(np.sum(a=np.abs(x), axis=tuple(axes), keepdims=True)).astype(np.int64) + y = np.sqrt(np.sum(a=np.square(x), axis=tuple(axes), keepdims=True)).astype(np.int64) x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) diff --git a/tests/nodes.cairo b/tests/nodes.cairo index ca936fdf3..8b307ab42 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -522,3 +522,4 @@ mod reduce_l2_fp16x16_export_negative_axes_keepdims; mod reduce_l2_fp8x23_export_do_not_keepdims; mod reduce_l2_fp8x23_export_keepdims; mod reduce_l2_fp8x23_export_negative_axes_keepdims; + diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo index 0c4686379..0c036c85e 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo @@ -10,11 +10,11 @@ fn output_0() -> Tensor { 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: 3, sign: false }); - data.append(FP16x16 { mag: 4, sign: false }); - data.append(FP16x16 { mag: 4, sign: false }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 13, sign: false }); + data.append(FP16x16 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo index c218e25b5..569945db0 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo @@ -11,11 +11,11 @@ fn output_0() -> Tensor { shape.append(1); 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: 3, sign: false }); - data.append(FP16x16 { mag: 4, sign: false }); - data.append(FP16x16 { mag: 4, sign: false }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 13, sign: false }); + data.append(FP16x16 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo index c73dd7fee..5feddbc13 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -11,14 +11,14 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 5, sign: false }); - data.append(FP16x16 { mag: 5, sign: false }); - data.append(FP16x16 { mag: 6, sign: false }); - data.append(FP16x16 { mag: 6, sign: false }); - data.append(FP16x16 { mag: 6, sign: false }); - data.append(FP16x16 { mag: 6, sign: false }); - data.append(FP16x16 { mag: 6, sign: false }); - data.append(FP16x16 { mag: 7, sign: false }); - data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 21, sign: false }); + data.append(FP16x16 { mag: 22, sign: false }); + data.append(FP16x16 { mag: 24, sign: false }); + data.append(FP16x16 { mag: 25, sign: false }); + data.append(FP16x16 { mag: 27, sign: false }); + data.append(FP16x16 { mag: 28, sign: false }); + data.append(FP16x16 { mag: 30, sign: false }); + data.append(FP16x16 { mag: 32, sign: false }); + data.append(FP16x16 { mag: 33, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo index 0f1e2d435..01a191e5c 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo @@ -10,11 +10,11 @@ fn output_0() -> Tensor { 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: 3, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 13, sign: false }); + data.append(FP8x23 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo index 0eb110933..98240f104 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo @@ -11,11 +11,11 @@ fn output_0() -> Tensor { shape.append(1); 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: 3, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 13, sign: false }); + data.append(FP8x23 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo index cfad71378..d95c89484 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -11,14 +11,14 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 5, sign: false }); - data.append(FP8x23 { mag: 5, sign: false }); - data.append(FP8x23 { mag: 6, sign: false }); - data.append(FP8x23 { mag: 6, sign: false }); - data.append(FP8x23 { mag: 6, sign: false }); - data.append(FP8x23 { mag: 6, sign: false }); - data.append(FP8x23 { mag: 6, sign: false }); - data.append(FP8x23 { mag: 7, sign: false }); - data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 21, sign: false }); + data.append(FP8x23 { mag: 22, sign: false }); + data.append(FP8x23 { mag: 24, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 27, sign: false }); + data.append(FP8x23 { mag: 28, sign: false }); + data.append(FP8x23 { mag: 30, sign: false }); + data.append(FP8x23 { mag: 32, sign: false }); + data.append(FP8x23 { mag: 33, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From deaedc060daff6e2de3f7a1e27e53af61cd87aae Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 08:47:17 +0100 Subject: [PATCH 033/127] nerge more conflicts --- src/operators/tensor/core.cairo | 5 +---- src/operators/tensor/math.cairo | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index ab123ab48..4ce378ccd 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -86,11 +86,8 @@ impl TensorSerde, impl TDrop: Drop> of Serde>>>>>> bc808751053ef1b3068269cdbb04b8995abb969e +/// reduce_l2 - Computes the L2 norm of the input tensor's elements along the provided axes. trait TensorTrait { /// # tensor.new /// diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 7d3d09bcb..457f6bdee 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,8 +38,5 @@ mod and; mod neg; mod where; mod round; -<<<<<<< HEAD -mod reduce_l2; -======= mod scatter; ->>>>>>> bc808751053ef1b3068269cdbb04b8995abb969e +mod reduce_l2; \ No newline at end of file From 8235d787568569fe93d863160ebddb35171d4446 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 13:00:15 +0100 Subject: [PATCH 034/127] Reduce sum square operator --- docs/CHANGELOG.md | 4 + docs/SUMMARY.md | 2 + docs/framework/compatibility.md | 4 +- docs/framework/operators/tensor/README.md | 1 + .../framework/operators/tensor/scatter.max.md | 0 .../tensor/tensor.reduce_sum_square.md | 38 +++ nodegen/node/reduce_sum_square.py | 266 ++++++++++++++++++ src/operators/tensor/core.cairo | 41 +++ .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 3 +- .../tensor/math/reduce_sum_square.cairo | 56 ++++ tests/nodes.cairo | 17 +- ...quare_fp16x16_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 20 ++ ...e_sum_square_fp16x16_export_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 21 ++ ...p16x16_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 23 ++ .../output_0.cairo | 19 ++ ...square_fp8x23_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 20 ++ ...ce_sum_square_fp8x23_export_keepdims.cairo | 20 ++ .../input_0.cairo | 27 ++ .../output_0.cairo | 21 ++ ...fp8x23_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 42 +++ .../output_0.cairo | 24 ++ ...um_square_i32_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 19 ++ ...educe_sum_square_i32_export_keepdims.cairo | 20 ++ .../input_0.cairo | 26 ++ .../output_0.cairo | 20 ++ ...re_i32_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 41 +++ .../output_0.cairo | 23 ++ ...sum_square_i8_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 22 ++ .../output_0.cairo | 17 ++ ...reduce_sum_square_i8_export_keepdims.cairo | 20 ++ .../input_0.cairo | 22 ++ .../output_0.cairo | 18 ++ ...are_i8_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 22 ++ .../output_0.cairo | 18 ++ ...um_square_u32_export_do_not_keepdims.cairo | 20 ++ .../input_0.cairo | 25 ++ .../output_0.cairo | 18 ++ ...educe_sum_square_u32_export_keepdims.cairo | 20 ++ .../input_0.cairo | 25 ++ .../output_0.cairo | 19 ++ ...re_u32_export_negative_axes_keepdims.cairo | 20 ++ .../input_0.cairo | 40 +++ .../output_0.cairo | 22 ++ 65 files changed, 1486 insertions(+), 3 deletions(-) create mode 100644 docs/framework/operators/tensor/scatter.max.md create mode 100644 docs/framework/operators/tensor/tensor.reduce_sum_square.md create mode 100644 nodegen/node/reduce_sum_square.py create mode 100644 src/operators/tensor/math/reduce_sum_square.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index be5423456..871600de7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2023-11-06 + +## Added +- Reduce Sum Square Operator. ## [Unreleased] - 2023-11-03 diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 4b3c18068..f6bfaae7a 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -96,6 +96,8 @@ * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.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 98bfca62a..85aad40e6 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,6 +74,8 @@ You can see below the list of current supported ONNX Operators: | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | -| [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [Scatter](operators/tensor/tensor.scatter.md) | :white\_check\_mark: | +| [ReduceSumSquare](operators/tensor/tensor.reduce\_sum\_square.md) | :white\_check\_mark: | + Current Operators support: **68/156 (43%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 1a343debd..d17b5b2a0 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -92,6 +92,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | +| [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/scatter.max.md b/docs/framework/operators/tensor/scatter.max.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/framework/operators/tensor/tensor.reduce_sum_square.md b/docs/framework/operators/tensor/tensor.reduce_sum_square.md new file mode 100644 index 000000000..6e174f76b --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_sum_square.md @@ -0,0 +1,38 @@ +## tensor.reduce_sum_square + +```rust + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; +``` + +Computes the sum square of the input tensor's elements along the provided axes. +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axis`(`usize`) - The dimension to reduce. +* `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axis reduced by summing its elements. + +fn reduce_sum_square_example() -> 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); + let tensor = TensorTrait::::new(shape.span(), data.span()); + + We can call `reduce_sum_square` function as follows. + return tensor.reduce_sum_square(axis: 1, keepdims: true); +} +>>> [[5, 25]] +``` diff --git a/nodegen/node/reduce_sum_square.py b/nodegen/node/reduce_sum_square.py new file mode 100644 index 000000000..79932b236 --- /dev/null +++ b/nodegen/node/reduce_sum_square.py @@ -0,0 +1,266 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +import numpy as np + + +class Reduce_sum_square(RunAll): + @staticmethod + def reduce_sum_square_fp8x23(): + def reduce_sum_square_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=False).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_sum_square_fp8x23_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, false)", name) + + def reduce_sum_square_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_sum_square_fp8x23_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, true)", name) + + def reduce_sum_square_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_sum_square_fp8x23_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(0, true)", name) + + + reduce_sum_square_export_do_not_keepdims() + reduce_sum_square_export_keepdims() + reduce_sum_square_axis_0() + + @staticmethod + def reduce_sum_square_fp16x16(): + def reduce_sum_square_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=False).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_sum_square_fp16x16_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, false)", name) + + def reduce_sum_square_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_sum_square_fp16x16_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, true)", name) + + def reduce_sum_square_axis_0(): + shape = [2, 2, 2] + axes = np.array([0], dtype=np.int64) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int64) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) + + name = "reduce_sum_square_fp16x16_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(0, true)", name) + + + reduce_sum_square_export_do_not_keepdims() + reduce_sum_square_export_keepdims() + reduce_sum_square_axis_0() + + @staticmethod + def reduce_sum_square_i8(): + def reduce_sum_square_export_do_not_keepdims(): + shape = [2, 2, 2] + axes = np.array([2], dtype=np.int8) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=False).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_sum_square_i8_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, false)", name) + + def reduce_sum_square_export_keepdims(): + shape = [2, 2, 2] + axes = np.array([2], dtype=np.int8) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_sum_square_i8_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, true)", name) + + def reduce_sum_square_axis_0(): + shape = [2, 2, 2] + axes = np.array([0], dtype=np.int8) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int8) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "reduce_sum_square_i8_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(0, true)", name) + + + reduce_sum_square_export_do_not_keepdims() + reduce_sum_square_export_keepdims() + reduce_sum_square_axis_0() + + @staticmethod + def reduce_sum_square_i32(): + def reduce_sum_square_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int32) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_sum_square_i32_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, false)", name) + + def reduce_sum_square_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.int32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_sum_square_i32_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, true)", name) + + def reduce_sum_square_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.int32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.int32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_sum_square_i32_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(0, true)", name) + + + reduce_sum_square_export_do_not_keepdims() + reduce_sum_square_export_keepdims() + reduce_sum_square_axis_0() + + @staticmethod + def reduce_sum_square_u32(): + def reduce_sum_square_export_do_not_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.uint32) + keepdims = False + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_sum_square_u32_export_do_not_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, false)", name) + + def reduce_sum_square_export_keepdims(): + shape = [3, 2, 2] + axes = np.array([2], dtype=np.uint32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_sum_square_u32_export_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(2, true)", name) + + def reduce_sum_square_axis_0(): + shape = [3, 3, 3] + axes = np.array([0], dtype=np.uint32) + keepdims = True + x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np.float32), shape).astype(np.uint32) + y = np.sum(a=np.square(x), axis=tuple(axes), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_sum_square_u32_export_negative_axes_keepdims" + make_node([x], [y], name) + make_test( + [x], y, "input_0.reduce_sum_square(0, true)", name) + + + reduce_sum_square_export_do_not_keepdims() + reduce_sum_square_export_keepdims() + reduce_sum_square_axis_0() \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 1e1758cd7..49e6b0641 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -88,6 +88,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3324,6 +3325,46 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// ## tensor.reduce_sum_square + /// + /// ```rust + /// fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the sum square of the input tensor's elements along the provided axes. + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// fn reduce_sum_square_example() -> 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); + /// let tensor = TensorTrait::::new(shape.span(), data.span()); + /// + /// We can call `reduce_sum_square` function as follows. + /// return tensor.reduce_sum_square(axis: 1, keepdims: true); + /// } + /// >>> [[5, 25]] + /// ``` + /// + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 6142420a8..4750c8202 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -312,6 +312,10 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } + } /// 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 1064c90c6..de5d54b79 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -299,6 +299,10 @@ impl FP16x16WTensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// 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 076d217cb..287223f5d 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -312,6 +312,10 @@ impl FP32x32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// 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 1dca0598a..798c1403d 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -313,6 +313,10 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } + } /// 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 3ac08cb58..e536e1fff 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -311,6 +311,10 @@ impl FP8x23Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// 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 e707a4a55..c7af71d0b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -290,6 +290,10 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } + } /// 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 e0f9480e0..e335202dd 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -311,6 +311,10 @@ impl I32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// 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 9b179a93f..8b5dcb5f3 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -310,6 +310,10 @@ impl I8Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// 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 a150846ef..b281ca986 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -281,6 +281,10 @@ impl U32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 79404dcd5..596832340 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,4 +38,5 @@ mod and; mod neg; mod where; mod round; -mod scatter; \ No newline at end of file +mod scatter; +mod reduce_sum_square; \ No newline at end of file diff --git a/src/operators/tensor/math/reduce_sum_square.cairo b/src/operators/tensor/math/reduce_sum_square.cairo new file mode 100644 index 000000000..6d993c83f --- /dev/null +++ b/src/operators/tensor/math/reduce_sum_square.cairo @@ -0,0 +1,56 @@ +use core::option::OptionTrait; +use array::ArrayTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; + + +fn square< + T, + MAG, + impl FTensorTrait: TensorTrait, + impl FNumber: NumberTrait, + impl TMul: Mul, + impl FCopy: Copy, + impl FDrop: Drop, +>( + self: @Tensor +) -> Tensor { + let mut data = *self.data; + let mut output_data = ArrayTrait::new(); + + loop { + match data.pop_front() { + Option::Some(item) => { + let ele = *item; + output_data.append(ele * ele); + }, + Option::None(_) => { break; } + }; + }; + + let tensor_square = TensorTrait::new(*self.shape, output_data.span()); + return tensor_square; +} +/// Cf: TensorTrait::reduce_sum_square docstring +fn reduce_sum_square< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TMul: Mul, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, +>( + self: @Tensor, axis: usize, keepdims: bool +) -> Tensor { + let tensor_square = square(self); + let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); + return tensor_square_sum; + +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..c1ef084c3 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,4 +527,19 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod scatter_u32_add; +mod reduce_sum_square_fp16x16_export_do_not_keepdims; +mod reduce_sum_square_fp16x16_export_keepdims; +mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +mod reduce_sum_square_fp8x23_export_do_not_keepdims; +mod reduce_sum_square_fp8x23_export_keepdims; +mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +mod reduce_sum_square_i32_export_do_not_keepdims; +mod reduce_sum_square_i32_export_keepdims; +mod reduce_sum_square_i32_export_negative_axes_keepdims; +mod reduce_sum_square_i8_export_do_not_keepdims; +mod reduce_sum_square_i8_export_keepdims; +mod reduce_sum_square_i8_export_negative_axes_keepdims; +mod reduce_sum_square_u32_export_do_not_keepdims; +mod reduce_sum_square_u32_export_keepdims; +mod reduce_sum_square_u32_export_negative_axes_keepdims; diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo new file mode 100644 index 000000000..38ee4224e --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_sum_square_fp16x16_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..9163477b3 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 25, sign: false }); + data.append(FP16x16 { mag: 61, sign: false }); + data.append(FP16x16 { mag: 113, sign: false }); + data.append(FP16x16 { mag: 181, sign: false }); + data.append(FP16x16 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo new file mode 100644 index 000000000..0d719ecbe --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_sum_square_fp16x16_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo new file mode 100644 index 000000000..7ad478c1f --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + data.append(FP16x16 { mag: 9, sign: false }); + data.append(FP16x16 { mag: 10, sign: false }); + data.append(FP16x16 { mag: 11, sign: false }); + data.append(FP16x16 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo new file mode 100644 index 000000000..047175d25 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 25, sign: false }); + data.append(FP16x16 { mag: 61, sign: false }); + data.append(FP16x16 { mag: 113, sign: false }); + data.append(FP16x16 { mag: 181, sign: false }); + data.append(FP16x16 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..f6cdef499 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo @@ -0,0 +1,20 @@ +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_reduce_sum_square_fp16x16_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..cfd388d38 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,23 @@ +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); + 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 }); + data.append(FP16x16 { mag: 5, sign: false }); + data.append(FP16x16 { mag: 6, sign: false }); + data.append(FP16x16 { mag: 7, sign: false }); + data.append(FP16x16 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..d2b14f466 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(1); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 26, sign: false }); + data.append(FP16x16 { mag: 40, sign: false }); + data.append(FP16x16 { mag: 58, sign: false }); + data.append(FP16x16 { mag: 80, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo new file mode 100644 index 000000000..c2862201c --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.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_reduce_sum_square_fp8x23_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..b47aee451 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 61, sign: false }); + data.append(FP8x23 { mag: 113, sign: false }); + data.append(FP8x23 { mag: 181, sign: false }); + data.append(FP8x23 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo new file mode 100644 index 000000000..8436ea724 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.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_reduce_sum_square_fp8x23_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo new file mode 100644 index 000000000..ea37e2ec6 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo @@ -0,0 +1,27 @@ +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(3); + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo new file mode 100644 index 000000000..eacbeb69b --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo @@ -0,0 +1,21 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 61, sign: false }); + data.append(FP8x23 { mag: 113, sign: false }); + data.append(FP8x23 { mag: 181, sign: false }); + data.append(FP8x23 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..5257b13fa --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.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_reduce_sum_square_fp8x23_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..c811d8c9e --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(FP8x23 { mag: 5, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + data.append(FP8x23 { mag: 7, sign: false }); + data.append(FP8x23 { mag: 8, sign: false }); + data.append(FP8x23 { mag: 9, sign: false }); + data.append(FP8x23 { mag: 10, sign: false }); + data.append(FP8x23 { mag: 11, sign: false }); + data.append(FP8x23 { mag: 12, sign: false }); + data.append(FP8x23 { mag: 13, sign: false }); + data.append(FP8x23 { mag: 14, sign: false }); + data.append(FP8x23 { mag: 15, sign: false }); + data.append(FP8x23 { mag: 16, sign: false }); + data.append(FP8x23 { mag: 17, sign: false }); + data.append(FP8x23 { mag: 18, sign: false }); + data.append(FP8x23 { mag: 19, sign: false }); + data.append(FP8x23 { mag: 20, sign: false }); + data.append(FP8x23 { mag: 21, sign: false }); + data.append(FP8x23 { mag: 22, sign: false }); + data.append(FP8x23 { mag: 23, sign: false }); + data.append(FP8x23 { mag: 24, sign: false }); + data.append(FP8x23 { mag: 25, sign: false }); + data.append(FP8x23 { mag: 26, sign: false }); + data.append(FP8x23 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..188936e46 --- /dev/null +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,24 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 462, sign: false }); + data.append(FP8x23 { mag: 525, sign: false }); + data.append(FP8x23 { mag: 594, sign: false }); + data.append(FP8x23 { mag: 669, sign: false }); + data.append(FP8x23 { mag: 750, sign: false }); + data.append(FP8x23 { mag: 837, sign: false }); + data.append(FP8x23 { mag: 930, sign: false }); + data.append(FP8x23 { mag: 1029, sign: false }); + data.append(FP8x23 { mag: 1134, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo new file mode 100644 index 000000000..60f2eb08b --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.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_reduce_sum_square_i32_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..9eb75d28a --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..628310be4 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 113, sign: false }); + data.append(i32 { mag: 181, sign: false }); + data.append(i32 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo new file mode 100644 index 000000000..f75199c20 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims.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_reduce_sum_square_i32_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo new file mode 100644 index 000000000..9eb75d28a --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo new file mode 100644 index 000000000..4005461de --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 61, sign: false }); + data.append(i32 { mag: 113, sign: false }); + data.append(i32 { mag: 181, sign: false }); + data.append(i32 { mag: 265, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..5e6d9d87b --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.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_reduce_sum_square_i32_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..6b7f8d481 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,41 @@ +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(3); + shape.append(3); + shape.append(3); + + 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 }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 23, sign: false }); + data.append(i32 { mag: 24, sign: false }); + data.append(i32 { mag: 25, sign: false }); + data.append(i32 { mag: 26, sign: false }); + data.append(i32 { mag: 27, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..770b6e29e --- /dev/null +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,23 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 462, sign: false }); + data.append(i32 { mag: 525, sign: false }); + data.append(i32 { mag: 594, sign: false }); + data.append(i32 { mag: 669, sign: false }); + data.append(i32 { mag: 750, sign: false }); + data.append(i32 { mag: 837, sign: false }); + data.append(i32 { mag: 930, sign: false }); + data.append(i32 { mag: 1029, sign: false }); + data.append(i32 { mag: 1134, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo new file mode 100644 index 000000000..aed5b8cc7 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.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_reduce_sum_square_i8_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..5fe3138cd --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,22 @@ +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); + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..7a559c76a --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/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: 5, sign: false }); + data.append(i8 { mag: 25, sign: false }); + data.append(i8 { mag: 61, sign: false }); + data.append(i8 { mag: 113, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo new file mode 100644 index 000000000..2f8162e20 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims.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_reduce_sum_square_i8_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo new file mode 100644 index 000000000..5fe3138cd --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo @@ -0,0 +1,22 @@ +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); + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo new file mode 100644 index 000000000..e8e49e9e5 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo @@ -0,0 +1,18 @@ +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); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 25, sign: false }); + data.append(i8 { mag: 61, sign: false }); + data.append(i8 { mag: 113, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..2619e1c19 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.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_reduce_sum_square_i8_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..5fe3138cd --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,22 @@ +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); + 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 }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..a6e80a392 --- /dev/null +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,18 @@ +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(1); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 26, sign: false }); + data.append(i8 { mag: 40, sign: false }); + data.append(i8 { mag: 58, sign: false }); + data.append(i8 { mag: 80, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo new file mode 100644 index 000000000..1710b3440 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.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_reduce_sum_square_u32_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, false); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..1aeead0b2 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo @@ -0,0 +1,25 @@ +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(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..f08f41055 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo @@ -0,0 +1,18 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(25); + data.append(61); + data.append(113); + data.append(181); + data.append(265); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo new file mode 100644 index 000000000..3e1b50888 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims.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_reduce_sum_square_u32_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(2, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo new file mode 100644 index 000000000..1aeead0b2 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo @@ -0,0 +1,25 @@ +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(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo new file mode 100644 index 000000000..eb641605e --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(25); + data.append(61); + data.append(113); + data.append(181); + data.append(265); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..f6259fa60 --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.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_reduce_sum_square_u32_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_sum_square(0, true); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..9fce7f6df --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,40 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..31844609a --- /dev/null +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo @@ -0,0 +1,22 @@ +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(1); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(462); + data.append(525); + data.append(594); + data.append(669); + data.append(750); + data.append(837); + data.append(930); + data.append(1029); + data.append(1134); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From c41189e2637b19da98ccc6328502c80cc95b50b3 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Mon, 6 Nov 2023 16:02:28 +0200 Subject: [PATCH 035/127] replace drop with destruct --- src/operators/ml/tree_ensemble/core.cairo | 12 +- .../tree_ensemble_classifier.cairo | 8 +- tests/ml.cairo | 1 + tests/ml/tree_ensemble_classifier.cairo | 134 ++++++++++++++++++ 4 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 tests/ml/tree_ensemble_classifier.cairo diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 46a4762f5..cd8992eb9 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -1,3 +1,5 @@ +use core::array::ArrayTrait; +use alexandria_data_structures::array_ext::SpanTraitExt; use orion::numbers::NumberTrait; use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; use orion::utils::get_row; @@ -5,16 +7,11 @@ use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::ArrayTraitExt; -impl UsizeDictCopy of Copy>; -impl UsizeDictDrop of Drop>; - -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Destruct)] struct TreeEnsembleAttributes { - base_values: Option>, nodes_falsenodeids: Span, nodes_featureids: Span, - nodes_hitrates: Span, nodes_missing_value_tracks_true: Span, nodes_modes: Span, nodes_nodeids: Span, @@ -23,7 +20,7 @@ struct TreeEnsembleAttributes { nodes_values: Span, } -#[derive(Copy, Drop)] +#[derive(Destruct)] struct TreeEnsemble { atts: TreeEnsembleAttributes, tree_ids: Span, @@ -42,6 +39,7 @@ enum NODE_MODES { LEAF } + #[generate_trait] impl TreeEnsembleImpl< T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 7f0bb025e..ae3c50a33 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -7,7 +7,7 @@ use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -#[derive(Copy, Drop)] +#[derive(Destruct)] struct TreeEnsembleClassifier { ensemble: TreeEnsemble, class_ids: Span, @@ -43,7 +43,7 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)> + +Drop<(Span::, Felt252Dict::>)>, > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -65,7 +65,7 @@ fn compute_scores< +Add, +Copy>>>, +Copy>>, - +Copy>> + +Copy>>, >( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { @@ -201,7 +201,7 @@ fn classify< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)> + +Drop<(Span::, Felt252Dict::>)>, >( ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) ) -> (Tensor, Tensor) { diff --git a/tests/ml.cairo b/tests/ml.cairo index eca55a25b..f75954665 100644 --- a/tests/ml.cairo +++ b/tests/ml.cairo @@ -1 +1,2 @@ mod tree_regressor; +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo new file mode 100644 index 000000000..a4d6122be --- /dev/null +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -0,0 +1,134 @@ +use core::dict::Felt252DictTrait; +use orion::numbers::FP16x16; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor}; +use orion::operators::ml::tree_ensemble::core::{ + NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl +//TreeEnsembleHelperTrait +}; +// use orion::operators::ml::tree_ensemble::implementations::{FP16x16TreeEnsembleHelper}; + +#[test] +#[available_gas(2000000000)] +fn test_tree_ensemble_classifier_multi() { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let class_labels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts: atts, tree_ids: tree_ids, root_index: root_index, node_index: node_index + }; + + TreeEnsembleImpl::leave_index_tree( + ref ensemble, + TensorTrait::new(array![1].span(), array![FP16x16 { mag: 0, sign: false }].span()) + ); +} + From 36ba47da77ecda547b32a214953edb7a26c35a19 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Mon, 6 Nov 2023 18:50:25 +0200 Subject: [PATCH 036/127] fix get_row --- .../tree_ensemble_classifier.cairo | 9 ---- src/utils.cairo | 3 +- tests/ml/tree_ensemble_classifier.cairo | 43 ++++++++++++++++--- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index ae3c50a33..f4cbd7218 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -43,7 +43,6 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)>, > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -60,8 +59,6 @@ fn compute_scores< +Drop, +Copy, +NumberTrait, - +PartialOrd, - +PartialEq, +Add, +Copy>>>, +Copy>>, @@ -194,14 +191,8 @@ fn classify< +Copy, +NumberTrait, +PartialOrd, - +PartialEq, - +Add, +TensorTrait, +TensorTrait, - +Copy>>>, - +Copy>>, - +Copy>>, - +Drop<(Span::, Felt252Dict::>)>, >( ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) ) -> (Tensor, Tensor) { diff --git a/src/utils.cairo b/src/utils.cairo index dc2c35b0b..ab48c3d7d 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -36,7 +36,6 @@ fn get_row, +Copy>(self: Tensor, row: usize) -> Span { let row_length = *self.shape[1]; let start = row * row_length; - let end = start + row_length; - self.data.slice(start, end) + self.data.slice(start, row_length) } diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index a4d6122be..e1cdfcecc 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,11 +1,12 @@ use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; -use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor}; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl -//TreeEnsembleHelperTrait }; -// use orion::operators::ml::tree_ensemble::implementations::{FP16x16TreeEnsembleHelper}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform +}; #[test] #[available_gas(2000000000)] @@ -123,12 +124,40 @@ fn test_tree_ensemble_classifier_multi() { }; let mut ensemble: TreeEnsemble = TreeEnsemble { - atts: atts, tree_ids: tree_ids, root_index: root_index, node_index: node_index + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let post_transform = PostTransform::None; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + class_labels, + base_values, + post_transform }; - TreeEnsembleImpl::leave_index_tree( - ref ensemble, - TensorTrait::new(array![1].span(), array![FP16x16 { mag: 0, sign: false }].span()) + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() ); + + TreeEnsembleClassifierImpl::predict(ref classifier, X); } From b95cc43a74958548fff93e4e2fd520a888e64403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Mon, 6 Nov 2023 19:21:26 +0000 Subject: [PATCH 037/127] docs: bitwise_and operator docs are ready --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.bitwise_and.md | 44 +++++++++++++++++++ src/operators/tensor/core.cairo | 37 +++------------- 5 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.bitwise_and.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 409c1715e..d0db9f653 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -90,6 +90,7 @@ * [tensor.identity](framework/operators/tensor/tensor.identity.md) * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) + * [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.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 29d537ff6..c34623ab7 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -67,5 +67,6 @@ You can see below the list of current supported ONNX Operators: | [Or](operators/tensor/tensor.or.md) | :white\_check\_mark: | | [Gemm](operators/neural-network/nn.gemm.md) | :white\_check\_mark: | | [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: | +| [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: | -Current Operators support: **61/156 (39%)** +Current Operators support: **62/156 (39%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 361401570..01b0ae0c4 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -86,6 +86,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.and`](tensor.and.md) | Computes the logical AND of two tensors element-wise. | | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | +| [`tensor.bitwise_and`](tensor.bitwise\_and.md) | Computes the bitwise AND of two tensors element-wise. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.bitwise_and.md b/docs/framework/operators/tensor/tensor.bitwise_and.md new file mode 100644 index 000000000..5288ab953 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.bitwise_and.md @@ -0,0 +1,44 @@ +#tensor.bitwise_and + +```rust + fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; +``` + +Computes the bitwise AND of two tensors element-wise. +The input tensors must have either: +* Exactly the same shape +* The same number of dimensions and the length of each dimension is either a common length or 1. + +## Args + +* `self`(`@Tensor`) - The first tensor to be compared +* `other`(`@Tensor`) - The second tensor to be compared + +## Panics + +* Panics if the shapes are not equal or broadcastable + +## Returns + +A new `Tensor` with the same shape as the broadcasted inputs. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn and_example() -> Tensor { + let tensor_1 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + ); + + let tensor_2 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 0, 4, 5, 0, 6, 2].span(), + ); + + return tensor_1.bitwise_and(@tensor_2); +} +>>> [0,1,2,0,4,5,0,6,2] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index a91ad0dfc..0a557efd2 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -2869,13 +2869,13 @@ trait TensorTrait { /// ``` /// fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor; - /// #tensor.and + /// #tensor.bitwise_and /// /// ```rust /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; /// ``` /// - /// Computes the logical AND of two tensors element-wise. + /// Computes the bitwise AND of two tensors element-wise. /// The input tensors must have either: /// * Exactly the same shape /// * The same number of dimensions and the length of each dimension is either a common length or 1. @@ -2891,32 +2891,9 @@ trait TensorTrait { /// /// ## Returns /// - /// A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. - /// - /// ## Examples - /// - /// Case 1: Compare tensors with same shape + /// A new `Tensor` with the same shape as the broadcasted inputs. /// - /// ```rust - /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; - /// - /// fn and_example() -> Tensor { - /// let tensor_1 = TensorTrait::::new( - /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), - /// ); - /// - /// let tensor_2 = TensorTrait::::new( - /// shape: array![3, 3].span(), data: array![0, 1, 2, 0, 1, 2, 0, 1, 2].span(), - /// ); - /// - /// return tensor_1.and(@tensor_2); - /// } - /// >>> [0,1,1,0,1,1,0,1,1] - /// ``` - /// - /// Case 2: Compare tensors with different shapes + /// ## Example /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; @@ -2929,12 +2906,12 @@ trait TensorTrait { /// ); /// /// let tensor_2 = TensorTrait::::new( - /// shape: array![1, 3].span(), data: array![0, 1, 2].span(), + /// shape: array![3, 3].span(), data: array![0, 1, 2, 0, 4, 5, 0, 6, 2].span(), /// ); /// - /// return tensor_1.and(@tensor_2); + /// return tensor_1.bitwise_and(@tensor_2); /// } - /// >>> [0,1,1,0,1,1,0,1,1] + /// >>> [0,1,2,0,4,5,0,6,2] /// ``` /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; From 05dc01dc642f31296dd01594368ff7ffb9d05570 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 7 Nov 2023 13:03:04 +0100 Subject: [PATCH 038/127] feat Add assert_seq_eq --- src/utils.cairo | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils.cairo b/src/utils.cairo index b8062f733..6d648d627 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -28,3 +28,18 @@ fn assert_eq, impl TCopy: Copy, impl TDrop: ) { assert(lhs == rhs, 'should be equal'); } + +fn assert_seq_eq, impl TCopy: Copy, impl TDrop: Drop>( + lhs: Array, rhs: Array +) { + assert(lhs.len() == rhs.len(), 'should be equal'); + + let mut i = 0; + loop { + if i >= lhs.len() { + break; + } + assert_eq(lhs[i], rhs[i]); + i += 1; + } +} From d37c07edf4e29c1310233759e5b0ef7d105ea8e6 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 7 Nov 2023 14:48:51 +0200 Subject: [PATCH 039/127] add implementation --- src/operators/ml/tree_ensemble.cairo | 3 ++- .../ml/tree_ensemble/implementations.cairo | 13 +++++++++++ .../tree_ensemble_classifier.cairo | 23 +++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/implementations.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 0f09fa8d1..194732749 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,2 +1,3 @@ mod core; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; +mod implementations; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/implementations.cairo b/src/operators/ml/tree_ensemble/implementations.cairo new file mode 100644 index 000000000..d5b018d6e --- /dev/null +++ b/src/operators/ml/tree_ensemble/implementations.cairo @@ -0,0 +1,13 @@ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifierTrait, TreeEnsembleClassifier, predict +}; +use orion::numbers::FP16x16; +use orion::operators::tensor::{FP16x16Tensor, U32Tensor, Tensor}; + +impl FP16x16TreeEnsembleClassifier of TreeEnsembleClassifierTrait { + fn predict( + ref self: TreeEnsembleClassifier, X: Tensor + ) -> (Tensor, Tensor) { + predict(ref self, X) + } +} diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index f4cbd7218..5b31eeef7 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -28,8 +28,12 @@ enum PostTransform { Probit, } -#[generate_trait] -impl TreeEnsembleClassifierImpl< + +trait TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor); +} + +fn predict< T, MAG, +Drop, @@ -43,16 +47,17 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, -> of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); +>( + ref self: TreeEnsembleClassifier, X: Tensor +) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); - (predictions, final_scores) - } + (predictions, final_scores) } + fn compute_scores< T, MAG, From a163eb9928c1a0787824ab5ef04e7518a7d1a0aa Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 7 Nov 2023 15:40:14 +0200 Subject: [PATCH 040/127] fix compilation --- src/operators/ml/tree_ensemble.cairo | 3 +- .../ml/tree_ensemble/implementations.cairo | 13 ---- .../tree_ensemble_classifier.cairo | 66 ++++++++----------- tests/ml/tree_ensemble_classifier.cairo | 5 +- 4 files changed, 32 insertions(+), 55 deletions(-) delete mode 100644 src/operators/ml/tree_ensemble/implementations.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 194732749..0f09fa8d1 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,3 +1,2 @@ mod core; -mod tree_ensemble_classifier; -mod implementations; \ No newline at end of file +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/implementations.cairo b/src/operators/ml/tree_ensemble/implementations.cairo deleted file mode 100644 index d5b018d6e..000000000 --- a/src/operators/ml/tree_ensemble/implementations.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifierTrait, TreeEnsembleClassifier, predict -}; -use orion::numbers::FP16x16; -use orion::operators::tensor::{FP16x16Tensor, U32Tensor, Tensor}; - -impl FP16x16TreeEnsembleClassifier of TreeEnsembleClassifierTrait { - fn predict( - ref self: TreeEnsembleClassifier, X: Tensor - ) -> (Tensor, Tensor) { - predict(ref self, X) - } -} diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 5b31eeef7..5ac2cf43f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,5 @@ +use core::nullable::NullableTrait; +use core::dict::Felt252DictTrait; use core::dict::Felt252DictEntryTrait; use nullable::{match_nullable, FromNullableResult}; @@ -6,6 +8,7 @@ use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::{SpanTraitExt}; #[derive(Destruct)] struct TreeEnsembleClassifier { @@ -29,11 +32,8 @@ enum PostTransform { } -trait TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor); -} - -fn predict< +#[generate_trait] +impl TreeEnsembleClassifierImpl< T, MAG, +Drop, @@ -44,31 +44,18 @@ fn predict< +Add, +TensorTrait, +TensorTrait, - +Copy>>>, - +Copy>>, - +Copy>>, ->( - ref self: TreeEnsembleClassifier, X: Tensor -) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); - (predictions, final_scores) + (predictions, final_scores) + } } -fn compute_scores< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +Add, - +Copy>>>, - +Copy>>, - +Copy>>, ->( +fn compute_scores, +Copy, +NumberTrait, +Add,>( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { // Initialize the scores array, either with base_values or zeros @@ -105,7 +92,7 @@ fn compute_scores< } // Compute class index mapping - let mut class_index: Felt252Dict>> = Default::default(); + let mut class_index: Felt252Dict>> = Default::default(); let mut class_weights = self.class_weights; let mut class_ids = self.class_ids; let mut class_nodeids = self.class_nodeids; @@ -120,15 +107,14 @@ fn compute_scores< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash(tree_id.into(), node_id.into()); - let (entry, _prev_value) = class_index.entry(key); - match match_nullable(_prev_value) { - FromNullableResult::Null(()) => { - entry.finalize(NullableTrait::new(array![])) + let prev_value = class_index.get(key); + match match_nullable(prev_value) { + FromNullableResult::Null(()) => { // entry.finalize(NullableTrait::new(array![])) }, FromNullableResult::NotNull(val) => { - let mut new_val = _prev_value.deref(); - new_val.append((class_id, *class_weight)); - entry.finalize(NullableTrait::new(new_val)) + let mut new_val = prev_value.deref(); + let new_va = new_val.concat(array![(class_id, *class_weight)].span()); + class_index.insert(key, nullable_from_box(BoxTrait::new(new_va))); }, }; }, @@ -148,10 +134,11 @@ fn compute_scores< (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() ); + match match_nullable(class_index.get(key)) { FromNullableResult::Null(()) => { continue; }, FromNullableResult::NotNull(class_weight_pairs) => { - let mut class_weight_pairs_span = class_weight_pairs.unbox().span(); + let mut class_weight_pairs_span = class_weight_pairs.unbox(); loop { match class_weight_pairs_span.pop_front() { Option::Some(class_weight_pair) => { @@ -161,9 +148,12 @@ fn compute_scores< let key: felt252 = key .hash((sample_index).into(), (class_id).into()); - let (entry, value) = scores_data.entry(key); - let value = value.deref(); - entry.finalize(NullableTrait::new(value + class_weight)); + let value = scores_data.get(key).deref(); + scores_data + .insert( + key, + nullable_from_box(BoxTrait::new(value + class_weight)) + ); }, Option::None(_) => { break; } }; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index e1cdfcecc..48497b267 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -5,7 +5,8 @@ use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform + //TreeEnsembleClassifierImpl, + TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; #[test] @@ -158,6 +159,6 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - TreeEnsembleClassifierImpl::predict(ref classifier, X); + TreeEnsembleClassifierTrait::predict(ref classifier, X); } From b023605660f182ab8e58ed5321c852415be9196b Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 7 Nov 2023 18:31:46 +0100 Subject: [PATCH 041/127] Implement binarizer operator --- src/operators/tensor/core.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 3 +- src/operators/tensor/math/binarizer.cairo | 38 +++++++++++++++++++ 12 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/math/binarizer.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 8a3ae7e68..74c6485b0 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 508134a2f..429e2cf8d 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,6 +288,10 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// 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 d87f6dd9d..c9e5d9e61 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -286,6 +286,10 @@ impl FP16x16WTensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 30b85b755..bd73890cc 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -288,6 +288,10 @@ impl FP32x32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 c86420354..fd3c8afc2 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,6 +289,10 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// 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 3ddcf0369..c4db51e7f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -287,6 +287,10 @@ impl FP8x23Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 3c36ee737..82ffe8c55 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,6 +277,10 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// 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 bf0592c41..2accf79fb 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -287,6 +287,10 @@ impl I32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 bfadc3be5..d682114d8 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -286,6 +286,10 @@ impl I8Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 2faf21b0b..7c18fb79d 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -268,6 +268,10 @@ impl U32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 79404dcd5..2e761e4cd 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,4 +38,5 @@ mod and; mod neg; mod where; mod round; -mod scatter; \ No newline at end of file +mod scatter; +mod binarizer; \ No newline at end of file diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo new file mode 100644 index 000000000..d28be43d0 --- /dev/null +++ b/src/operators/tensor/math/binarizer.cairo @@ -0,0 +1,38 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::binarizer docstring +fn binarizer< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, threshold: @T +) -> Tensor { + let mut binarized_data: Array = ArrayTrait::new(); + + loop { + match self.data.pop_front() { + Option::Some(item) => { + if (*item) > (*threshold) { + binarized_data.append(1); + } else { + binarized_data.append(0); + } + }, + Option::None(_) => { + break; + } + }; + }; + + return TensorTrait::new(self.shape, binarized_data.span()); +} From 9fb808db5d2d31abfd3b0abe09a7e3812425e583 Mon Sep 17 00:00:00 2001 From: 0x73e <132935850+0x73e@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:38:17 -0500 Subject: [PATCH 042/127] feat: constant_of_shape --- docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.constant_of_shape.md | 53 ++++++ src/operators/tensor/core.cairo | 86 +++++++++- .../implementations/tensor_fp16x16.cairo | 16 +- .../implementations/tensor_fp16x16wide.cairo | 17 +- .../implementations/tensor_fp32x32.cairo | 17 +- .../implementations/tensor_fp64x64.cairo | 16 +- .../implementations/tensor_fp8x23.cairo | 17 +- .../implementations/tensor_fp8x23wide.cairo | 20 ++- .../tensor/implementations/tensor_i32.cairo | 15 +- .../tensor/implementations/tensor_i8.cairo | 17 +- .../tensor/implementations/tensor_u32.cairo | 15 +- src/operators/tensor/math.cairo | 2 +- src/operators/tensor/math/max.cairo | 11 +- src/operators/tensor/math/min.cairo | 11 +- src/operators/tensor/math/min_in_tensor.cairo | 4 +- src/operators/tensor/math/scatter.cairo | 156 ++++++++---------- .../tensor/quantization/qlinear_add.cairo | 3 - tests/nodes.cairo | 140 ++++++++-------- .../max_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp16x16_three_tensors.cairo | 10 +- .../max_fp16x16_three_tensors/input_0.cairo | 2 +- .../max_fp16x16_three_tensors/input_1.cairo | 2 +- .../max_fp16x16_three_tensors/input_2.cairo | 2 +- .../max_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp16x16_two_tensors.cairo | 8 +- .../max_fp16x16_two_tensors/input_0.cairo | 2 +- .../max_fp16x16_two_tensors/input_1.cairo | 2 +- .../max_fp16x16_two_tensors/output_0.cairo | 2 +- .../max_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp8x23_three_tensors.cairo | 10 +- .../max_fp8x23_three_tensors/input_0.cairo | 2 +- .../max_fp8x23_three_tensors/input_1.cairo | 2 +- .../max_fp8x23_three_tensors/input_2.cairo | 2 +- .../max_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp8x23_two_tensors.cairo | 8 +- .../max_fp8x23_two_tensors/input_0.cairo | 2 +- .../max_fp8x23_two_tensors/input_1.cairo | 2 +- .../max_fp8x23_two_tensors/output_0.cairo | 2 +- .../max_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i32_three_tensors.cairo | 10 +- .../nodes/max_i32_three_tensors/input_0.cairo | 2 +- .../nodes/max_i32_three_tensors/input_1.cairo | 2 +- .../nodes/max_i32_three_tensors/input_2.cairo | 2 +- .../max_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i32_two_tensors.cairo | 8 +- tests/nodes/max_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i32_two_tensors/input_1.cairo | 2 +- .../nodes/max_i32_two_tensors/output_0.cairo | 2 +- .../max_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i8_three_tensors.cairo | 10 +- .../nodes/max_i8_three_tensors/input_0.cairo | 2 +- .../nodes/max_i8_three_tensors/input_1.cairo | 2 +- .../nodes/max_i8_three_tensors/input_2.cairo | 2 +- .../nodes/max_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i8_two_tensors.cairo | 8 +- tests/nodes/max_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/max_i8_two_tensors/output_0.cairo | 2 +- .../max_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_u32_three_tensors.cairo | 10 +- .../nodes/max_u32_three_tensors/input_0.cairo | 2 +- .../nodes/max_u32_three_tensors/input_1.cairo | 2 +- .../nodes/max_u32_three_tensors/input_2.cairo | 2 +- .../max_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_u32_two_tensors.cairo | 8 +- tests/nodes/max_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_u32_two_tensors/input_1.cairo | 2 +- .../nodes/max_u32_two_tensors/output_0.cairo | 2 +- .../min_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp16x16_three_tensors.cairo | 10 +- .../min_fp16x16_three_tensors/input_0.cairo | 2 +- .../min_fp16x16_three_tensors/input_1.cairo | 2 +- .../min_fp16x16_three_tensors/input_2.cairo | 2 +- .../min_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp16x16_two_tensors.cairo | 8 +- .../min_fp16x16_two_tensors/input_0.cairo | 2 +- .../min_fp16x16_two_tensors/input_1.cairo | 2 +- .../min_fp16x16_two_tensors/output_0.cairo | 2 +- .../min_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp8x23_three_tensors.cairo | 10 +- .../min_fp8x23_three_tensors/input_0.cairo | 2 +- .../min_fp8x23_three_tensors/input_1.cairo | 2 +- .../min_fp8x23_three_tensors/input_2.cairo | 2 +- .../min_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp8x23_two_tensors.cairo | 8 +- .../min_fp8x23_two_tensors/input_0.cairo | 2 +- .../min_fp8x23_two_tensors/input_1.cairo | 2 +- .../min_fp8x23_two_tensors/output_0.cairo | 2 +- .../min_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i32_three_tensors.cairo | 10 +- .../nodes/min_i32_three_tensors/input_0.cairo | 2 +- .../nodes/min_i32_three_tensors/input_1.cairo | 2 +- .../nodes/min_i32_three_tensors/input_2.cairo | 2 +- .../min_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i32_two_tensors.cairo | 8 +- tests/nodes/min_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i32_two_tensors/input_1.cairo | 2 +- .../nodes/min_i32_two_tensors/output_0.cairo | 2 +- .../min_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i8_three_tensors.cairo | 10 +- .../nodes/min_i8_three_tensors/input_0.cairo | 2 +- .../nodes/min_i8_three_tensors/input_1.cairo | 2 +- .../nodes/min_i8_three_tensors/input_2.cairo | 2 +- .../nodes/min_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i8_two_tensors.cairo | 8 +- tests/nodes/min_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/min_i8_two_tensors/output_0.cairo | 2 +- .../min_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_u32_three_tensors.cairo | 10 +- .../nodes/min_u32_three_tensors/input_0.cairo | 2 +- .../nodes/min_u32_three_tensors/input_1.cairo | 2 +- .../nodes/min_u32_three_tensors/input_2.cairo | 2 +- .../min_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_u32_two_tensors.cairo | 8 +- tests/nodes/min_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_u32_two_tensors/input_1.cairo | 2 +- .../nodes/min_u32_two_tensors/output_0.cairo | 2 +- tests/nodes/round_fp16x16.cairo | 6 +- tests/nodes/round_fp16x16/input_0.cairo | 2 +- tests/nodes/round_fp16x16/output_0.cairo | 2 +- tests/nodes/round_fp8x23.cairo | 6 +- tests/nodes/round_fp8x23/input_0.cairo | 2 +- tests/nodes/round_fp8x23/output_0.cairo | 2 +- tests/nodes/scatter_fp16x16_3d_axis1.cairo | 18 +- .../scatter_fp16x16_3d_axis1/input_0.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_1.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_2.cairo | 2 +- .../scatter_fp16x16_3d_axis1/output_0.cairo | 2 +- .../nodes/scatter_fp16x16_3d_axis1_add.cairo | 18 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/scatter_fp16x16_3d_default.cairo | 18 +- .../scatter_fp16x16_3d_default/input_0.cairo | 2 +- .../scatter_fp16x16_3d_default/input_1.cairo | 2 +- .../scatter_fp16x16_3d_default/input_2.cairo | 2 +- .../scatter_fp16x16_3d_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_axis1.cairo | 18 +- .../nodes/scatter_fp8x23_axis1/input_0.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_1.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_2.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_default.cairo | 18 +- .../scatter_fp8x23_default/input_0.cairo | 2 +- .../scatter_fp8x23_default/input_1.cairo | 2 +- .../scatter_fp8x23_default/input_2.cairo | 2 +- .../scatter_fp8x23_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul.cairo | 18 +- tests/nodes/scatter_fp8x23_mul/input_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_1.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_2.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1.cairo | 18 +- tests/nodes/scatter_i8_axis1/input_0.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_1.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_2.cairo | 2 +- tests/nodes/scatter_i8_axis1/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1_max.cairo | 18 +- .../nodes/scatter_i8_axis1_max/input_0.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_1.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_2.cairo | 2 +- .../nodes/scatter_i8_axis1_max/output_0.cairo | 2 +- tests/nodes/scatter_i8_default.cairo | 18 +- tests/nodes/scatter_i8_default/input_0.cairo | 2 +- tests/nodes/scatter_i8_default/input_1.cairo | 2 +- tests/nodes/scatter_i8_default/input_2.cairo | 2 +- tests/nodes/scatter_i8_default/output_0.cairo | 2 +- tests/nodes/scatter_u32_add.cairo | 18 +- tests/nodes/scatter_u32_add/input_0.cairo | 2 +- tests/nodes/scatter_u32_add/input_1.cairo | 2 +- tests/nodes/scatter_u32_add/input_2.cairo | 2 +- tests/nodes/scatter_u32_add/output_0.cairo | 2 +- tests/nodes/scatter_u32_axis1.cairo | 18 +- tests/nodes/scatter_u32_axis1/input_0.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_1.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_2.cairo | 2 +- tests/nodes/scatter_u32_axis1/output_0.cairo | 2 +- tests/nodes/scatter_u32_default.cairo | 18 +- tests/nodes/scatter_u32_default/input_0.cairo | 2 +- tests/nodes/scatter_u32_default/input_1.cairo | 2 +- tests/nodes/scatter_u32_default/input_2.cairo | 2 +- .../nodes/scatter_u32_default/output_0.cairo | 2 +- tests/operators.cairo | 1 + tests/operators/constant_of_shape_test.cairo | 13 ++ tests/operators/qlinear_add_test.cairo | 20 ++- 269 files changed, 958 insertions(+), 666 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.constant_of_shape.md create mode 100644 tests/operators/constant_of_shape_test.cairo diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 98bfca62a..d4115da0a 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -75,5 +75,6 @@ You can see below the list of current supported ONNX Operators: | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | | [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | Current Operators support: **68/156 (43%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 1a343debd..74803415f 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -37,6 +37,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.new`](tensor.new.md) | Returns a new tensor with the given shape and data. | | [`tensor.reshape`](tensor.reshape.md) | Returns a new tensor with the specified target shape and the same data as the input tensor. | | [`tensor.flatten`](tensor.flatten.md) | Flattens the input tensor into a 2D tensor. | +| [`tensor.constant_of_shape`](tensor.constant\_of\_shape.md) | Generate a tensor with given value and shape. | | [`tensor.transpose`](tensor.transpose.md) | Returns a new tensor with the axes rearranged according to the given permutation. | | [`tensor.at`](tensor.at.md) | Retrieves the value at the specified indices of a Tensor. | | [`tensor.ravel_index`](tensor.ravel\_index.md) | Converts a multi-dimensional index to a one-dimensional index. | diff --git a/docs/framework/operators/tensor/tensor.constant_of_shape.md b/docs/framework/operators/tensor/tensor.constant_of_shape.md new file mode 100644 index 000000000..3faef9822 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.constant_of_shape.md @@ -0,0 +1,53 @@ +# tensor.constant_of_shape + +```rust + fn constant_of_shape(shape: Span, value: T) -> Tensor; +``` + +Returns a new tensor with the given shape and constant value. + +## Args + +* `shape`(`Span`) - A span representing the shape of the tensor. +* `value` (`T`) - the constant value. + +## Returns + +A new `Tensor` instance. + +## Examples + +Let's create new u32 Tensor with constant 0. + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, // we import the trait + Tensor, // we import the type + U32Tensor // we import the implementation. +}; + +// 1D TENSOR +fn tensor_1D() -> Tensor { + let tensor = TensorTrait::new(shape: array![3].span(), value: 0); + + return tensor; +} + +// 2D TENSOR +fn tensor_2D() -> Tensor { + let tensor = TensorTrait::new(shape: array![2, 2].span(), value: 10); + + return tensor; +} + +// 3D TENSOR +fn tensor_3D() -> Tensor { + let tensor = TensorTrait::new( + shape: array![2, 2, 2].span(), value: 20, + ); + + return tensor; +} +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 1e1758cd7..902a86afa 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -33,6 +33,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ``` /// fn new(shape: Span, data: Span) -> Tensor; + /// # tensor.constant_of_shape + /// + /// ```rust + /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ``` + /// + /// Returns a new tensor with the given shape and constant value. + /// + /// ## Args + /// + /// * `shape`(`Span`) - A span representing the shape of the tensor. + /// * `value` (`T`) - the constant value. + /// + /// ## Returns + /// + /// A new `Tensor` instance. + /// + /// ## Examples + /// + /// Let's create new u32 Tensor with constant 0. + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{ + /// TensorTrait, // we import the trait + /// Tensor, // we import the type + /// U32Tensor // we import the implementation. + /// }; + /// + /// // 1D TENSOR + /// fn tensor_1D() -> Tensor { + /// let tensor = TensorTrait::new(shape: array![3].span(), value: 0); + /// + /// return tensor; + /// } + /// + /// // 2D TENSOR + /// fn tensor_2D() -> Tensor { + /// let tensor = TensorTrait::new(shape: array![2, 2].span(), value: 10); + /// + /// return tensor; + /// } + /// + /// // 3D TENSOR + /// fn tensor_3D() -> Tensor { + /// let tensor = TensorTrait::new( + /// shape: array![2, 2, 2].span(), value: 20, + /// ); + /// + /// return tensor; + /// } + /// ``` + /// + fn constant_of_shape(shape: Span, value: T) -> Tensor; /// # tensor.at /// /// ```rust @@ -3239,7 +3295,7 @@ trait TensorTrait { /// /// ## Example /// - /// ```rust + /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// /// use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; @@ -3323,7 +3379,13 @@ trait TensorTrait { /// [ 4, 0, 3, 0, 0]] /// ``` /// - fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor; } /// Cf: TensorTrait::new docstring @@ -3332,6 +3394,26 @@ fn new_tensor(shape: Span, data: Span) -> Tensor { Tensor:: { shape, data } } +/// Cf: TensorTrait::constant_of_shape docstring +fn constant_of_shape, impl FDrop: Drop,>( + shape: Span, value: T +) -> Tensor { + let mut data = ArrayTrait::new(); + + let mut i = 0; + let length = len_from_shape(shape); + + loop { + if i == length { + break (); + } + data.append(value.clone()); + i += 1; + }; + + Tensor:: { shape, data: data.span() } +} + /// Cf: TensorTrait::ravel_index docstring fn ravel_index(mut shape: Span, mut indices: Span) -> usize { assert(shape.len() == indices.len(), 'shape & indices length unequal'); diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 6142420a8..410c9c478 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP16x16}; @@ -16,6 +17,10 @@ impl FP16x16Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP16x16) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP16x16 { *at_tensor(self, indices) } @@ -307,11 +312,14 @@ impl FP16x16Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// 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 1064c90c6..84bab92b7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP16x16W}; @@ -16,6 +17,10 @@ impl FP16x16WTensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP16x16W) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP16x16W { *at_tensor(self, indices) } @@ -294,9 +299,13 @@ impl FP16x16WTensor of TensorTrait { math::round::round(*self) } - fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 076d217cb..a90c6fe10 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP32x32, FP32x32Impl}; @@ -17,6 +18,10 @@ impl FP32x32Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP32x32) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP32x32 { *at_tensor(self, indices) } @@ -305,11 +310,15 @@ impl FP32x32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 1dca0598a..051e23a27 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP64x64, FP64x64Impl}; @@ -17,6 +18,10 @@ impl FP64x64Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP64x64) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP64x64 { *at_tensor(self, indices) } @@ -308,11 +313,14 @@ impl FP64x64Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// 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 3ac08cb58..e9fe343c6 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP8x23}; @@ -16,6 +17,10 @@ impl FP8x23Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP8x23) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP8x23 { *at_tensor(self, indices) } @@ -307,9 +312,13 @@ impl FP8x23Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { - math::scatter::scatter(self, updates, indices, axis, reduction) + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index e707a4a55..e4011bebb 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait, FP8x23W}; @@ -16,6 +17,10 @@ impl FP8x23WTensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: FP8x23W) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> FP8x23W { *at_tensor(self, indices) } @@ -280,17 +285,20 @@ impl FP8x23WTensor of TensorTrait { math::where::where(self, x, y) } - fn round(self: @Tensor) -> Tensor { + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - -} +} /// Implements addition for `Tensor` using the `Add` trait. impl FP8x23WTensorAdd< diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index e0f9480e0..fc711b738 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i32, i8, NumberTrait}; @@ -17,6 +18,10 @@ impl I32Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: i32) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> i32 { *at_tensor(self, indices) } @@ -307,8 +312,12 @@ impl I32Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 9b179a93f..8cd69e570 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait}; @@ -16,6 +17,10 @@ impl I8Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: i8) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> i8 { *at_tensor(self, indices) } @@ -303,11 +308,15 @@ impl I8Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index a150846ef..cff77a571 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -5,7 +5,8 @@ use traits::{TryInto, Into}; use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ - new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, + new_tensor, constant_of_shape, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, + at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; use orion::numbers::{i8, i32, NumberTrait}; @@ -16,6 +17,10 @@ impl U32Tensor of TensorTrait { new_tensor(shape, data) } + fn constant_of_shape(shape: Span, value: u32) -> Tensor { + constant_of_shape(shape, value) + } + fn at(self: @Tensor, indices: Span) -> u32 { *at_tensor(self, indices) } @@ -277,8 +282,12 @@ impl U32Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 79404dcd5..0aaa3f459 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,4 +38,4 @@ mod and; mod neg; mod where; mod round; -mod scatter; \ No newline at end of file +mod scatter; diff --git a/src/operators/tensor/math/max.cairo b/src/operators/tensor/math/max.cairo index 5ed703408..8052733d7 100644 --- a/src/operators/tensor/math/max.cairo +++ b/src/operators/tensor/math/max.cairo @@ -17,7 +17,6 @@ fn max< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn max< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(max_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut max_value = NumberTrait::max(*(max_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut max_value = NumberTrait::max( + *(max_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_max_data.append(max_value); n += 1; @@ -65,4 +68,4 @@ fn max< }; return TensorTrait::::new(max_shape, max_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min.cairo b/src/operators/tensor/math/min.cairo index 3577e69c0..61140f89d 100644 --- a/src/operators/tensor/math/min.cairo +++ b/src/operators/tensor/math/min.cairo @@ -17,7 +17,6 @@ fn min< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn min< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(min_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut min_value = NumberTrait::min(*(min_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut min_value = NumberTrait::min( + *(min_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_min_data.append(min_value); n += 1; @@ -65,4 +68,4 @@ fn min< }; return TensorTrait::::new(min_shape, min_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min_in_tensor.cairo b/src/operators/tensor/math/min_in_tensor.cairo index b9738db1f..e52f4a227 100644 --- a/src/operators/tensor/math/min_in_tensor.cairo +++ b/src/operators/tensor/math/min_in_tensor.cairo @@ -24,9 +24,7 @@ fn min_in_tensor< min_value = check_min; } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/scatter.cairo b/src/operators/tensor/math/scatter.cairo index ea26f1b7e..bcd15c36d 100644 --- a/src/operators/tensor/math/scatter.cairo +++ b/src/operators/tensor/math/scatter.cairo @@ -14,9 +14,21 @@ use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; use dict::Felt252DictTrait; use nullable::{nullable_from_box, match_nullable, FromNullableResult}; /// Cf: TensorTrait::scatter docstring -fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDrop: Drop, impl TAddEq: AddEq, - impl TMulEq: MulEq, impl TPartialOrd: PartialOrd, impl TPartialEq: PartialEq,>( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option +fn scatter< + T, + impl TTensorTrait: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop, + impl TAddEq: AddEq, + impl TMulEq: MulEq, + impl TPartialOrd: PartialOrd, + impl TPartialEq: PartialEq, +>( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option ) -> Tensor { let mut axis = match axis { Option::Some(val) => val, @@ -40,7 +52,10 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_shape = *self.shape; let mut indices_shape = indices.shape; let updates_shape = updates.shape; - assert((*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), 'shape must be same'); + assert( + (*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), + 'shape must be same' + ); let mut output_data = ArrayTrait::new(); let mut data_indices = indices.data; @@ -54,31 +69,27 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_loop_first = *data_shape_copy.pop_front().unwrap(); let indices_loop_first = *indices_shape_copy.pop_front().unwrap(); - let mut indices_loop: usize = 1; - let mut data_loop:usize = 1; + let mut indices_loop: usize = 1; + let mut data_loop: usize = 1; if (axis == 0) { loop { match indices_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - indices_loop *= *val; + Option::Some(val) => { + let d = *val; + indices_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - loop { + loop { match data_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - data_loop *= *val; + Option::Some(val) => { + let d = *val; + data_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; } @@ -93,8 +104,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro axis = 2; transpose = true; } - - if (axis == (data_rank - 1) ){ + + if (axis == (data_rank - 1)) { data_loop = *data_shape_copy.pop_back().unwrap(); indices_loop = *indices_shape_copy.pop_back().unwrap(); } @@ -104,24 +115,26 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { let mut i: usize = 0; - let mut result:usize = 0; + let mut result: usize = 0; match data_indices.pop_front() { Option::Some(val) => { - let value = total_count+1; + let value = total_count + 1; if (axis == 0) { let column = total_count % indices_loop; result = (*val * data_loop) + (column); - if ((result % *data_shape.at(data_rank -1)) != total_count % *indices_shape.at(data_rank -1)){ - result += (*data_shape.at(data_rank -1) - *indices_shape.at(data_rank -1)); + if ((result % *data_shape.at(data_rank - 1)) != total_count % *indices_shape + .at(data_rank - 1)) { + result += + (*data_shape.at(data_rank - 1) - *indices_shape.at(data_rank - 1)); } } - if( axis == (data_rank - 1)) { + if (axis == (data_rank - 1)) { let mut row = total_count / indices_loop; - if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))){ - shift = ( *data_shape.at(1) - *indices_shape.at(1)); + if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))) { + shift = (*data_shape.at(1) - *indices_shape.at(1)); } result = *val + (data_loop * (row + shift)); @@ -129,8 +142,7 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'none') { indices_updates.insert(result.into(), value.into()); - } - else { + } else { let mut arr = ArrayTrait::new(); let val = indices_updates_reduction.get(result.into()); @@ -142,22 +154,17 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { match span.pop_front() { - Option::Some(val) => { - arr.append(*val); - }, - Option::None(_) => { - break; - } + Option::Some(val) => { arr.append(*val); }, + Option::None(_) => { break; } }; }; arr.append(total_count); - indices_updates_reduction.insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); + indices_updates_reduction + .insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); } total_count += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; @@ -170,13 +177,11 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let value = indices_updates.get(i.into()); if (value == 0) { output_data.append(*val); - } - else { - let data_value = data_updates[value-1]; + } else { + let data_value = data_updates[value - 1]; output_data.append(*data_value); } - } - else { + } else { let value = indices_updates_reduction.get(i.into()); let mut a = ArrayTrait::new(); let mut span = match match_nullable(value) { @@ -186,22 +191,15 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (span.len() == 0) { output_data.append(*val); - } - - else { + } else { // let mut result = *data_updates.at(*span.pop_front().unwrap()); let mut result = *val; - if (reduction == 'add') { loop { match span.pop_front() { - Option::Some(val) => { - result += *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result += *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -210,12 +208,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'mul') { loop { match span.pop_front() { - Option::Some(val) => { - result *= *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result *= *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -224,15 +218,13 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'max') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder > result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder > result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -241,27 +233,23 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'min') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder < result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder < result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); } } } - - i+=1; + + i += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/quantization/qlinear_add.cairo b/src/operators/tensor/quantization/qlinear_add.cairo index 7f9f3eaa1..1574e8fd8 100644 --- a/src/operators/tensor/quantization/qlinear_add.cairo +++ b/src/operators/tensor/quantization/qlinear_add.cairo @@ -8,8 +8,6 @@ use orion::operators::tensor::quantization::quantize_linear::quantize_linear; use orion::operators::tensor::{TensorTrait, Tensor}; - - fn qlinear_add< T, MAG, @@ -46,7 +44,6 @@ fn qlinear_add< min: T, max: T ) -> Tensor { - let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..f68cfac54 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -448,42 +448,42 @@ mod identity_fP8x23; mod identity_i32; mod identity_i8; mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; mod where_fp16x16; mod where_fp16x16_broadcast; mod where_fp8x23; @@ -494,37 +494,37 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo index 2660e4676..e6a9a5db0 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo index fc8d87773..15950d596 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo index 352adab6a..ad2c130c9 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo index b743e5482..2a9d359fe 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo index b5ac6fdcd..b738aeee5 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo index 92152cd37..8caad904d 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo index 4cc6309d7..369a5c13f 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo index 37ead1117..e47fcecfe 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors.cairo b/tests/nodes/max_fp16x16_three_tensors.cairo index 8ca7dfebe..c81211037 100644 --- a/tests/nodes/max_fp16x16_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo index bb6a7efe8..33bfc9dac 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo index 71edb4da9..4690905db 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo index 9845fefbe..51a6c9f52 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo index 139ae932a..d8b8ce390 100644 --- a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors.cairo b/tests/nodes/max_fp16x16_two_tensors.cairo index 98b522b3d..cdf7e83e6 100644 --- a/tests/nodes/max_fp16x16_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo index 1e70f825c..368a064d7 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo index c766b1157..fe6280643 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo index 66b666290..07fd7443c 100644 --- a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo index 2fdd60ff2..ab1082160 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo index 2fa35f877..1de6875da 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo index fdcd11d36..3941d2b7e 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo index 4a9a3a6e3..e17548190 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo index 78bcbc1ed..10e0960d6 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo index b40477513..b77fbfbf6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo index 89cffdd5e..132278138 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo index 297233473..27a35e3b1 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo index 0506f1c0f..e7d95b6f6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors.cairo b/tests/nodes/max_fp8x23_three_tensors.cairo index d5cc6b030..b503bf177 100644 --- a/tests/nodes/max_fp8x23_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo index f0f1d9253..5d8539d1d 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo index f4611bf3c..2e4abdf49 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo index 6eeb29edb..b51cf0f13 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo index e0318aad1..ebb70503a 100644 --- a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors.cairo b/tests/nodes/max_fp8x23_two_tensors.cairo index b54d193d6..8d5ca3c74 100644 --- a/tests/nodes/max_fp8x23_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo index 038c7c361..d16c6a053 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo index da45b3378..a766fbb91 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo index 797bfa996..86eaeb478 100644 --- a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors.cairo b/tests/nodes/max_i32_broadcast_three_tensors.cairo index af4660c1d..91476cad9 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo index 1c894ed65..36c7bbba6 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo index d4cfc3152..f8f8fbca4 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, 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/nodes/max_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo index 5494fd3b3..f997397d7 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_broadcast_two_tensors.cairo b/tests/nodes/max_i32_broadcast_two_tensors.cairo index 25d864bba..63f46ff9f 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo index 65fc1651c..47591a648 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo index b75480afa..f2b5abec2 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo index ffc6f4c24..5fa192944 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors.cairo b/tests/nodes/max_i32_three_tensors.cairo index 186d5e2c5..c72a56cdf 100644 --- a/tests/nodes/max_i32_three_tensors.cairo +++ b/tests/nodes/max_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_0.cairo b/tests/nodes/max_i32_three_tensors/input_0.cairo index e5fdee508..be1f3c151 100644 --- a/tests/nodes/max_i32_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { 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/nodes/max_i32_three_tensors/input_1.cairo b/tests/nodes/max_i32_three_tensors/input_1.cairo index 960743a74..778aba1a0 100644 --- a/tests/nodes/max_i32_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_2.cairo b/tests/nodes/max_i32_three_tensors/input_2.cairo index f90517109..00a20e43b 100644 --- a/tests/nodes/max_i32_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/output_0.cairo b/tests/nodes/max_i32_three_tensors/output_0.cairo index 376bd0a58..10d697501 100644 --- a/tests/nodes/max_i32_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { 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/nodes/max_i32_two_tensors.cairo b/tests/nodes/max_i32_two_tensors.cairo index 18678b57e..c2ddc1b51 100644 --- a/tests/nodes/max_i32_two_tensors.cairo +++ b/tests/nodes/max_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/input_0.cairo b/tests/nodes/max_i32_two_tensors/input_0.cairo index 59ba3b966..0c5e37593 100644 --- a/tests/nodes/max_i32_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i32_two_tensors/input_1.cairo b/tests/nodes/max_i32_two_tensors/input_1.cairo index 6615ef39a..efd1ec5a2 100644 --- a/tests/nodes/max_i32_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/output_0.cairo b/tests/nodes/max_i32_two_tensors/output_0.cairo index 7eded96da..31eca8b5f 100644 --- a/tests/nodes/max_i32_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, 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/nodes/max_i8_broadcast_three_tensors.cairo b/tests/nodes/max_i8_broadcast_three_tensors.cairo index 65ea53cc9..d73af1f9e 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo index 80c86eb24..6569361bf 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo index 05fe8ff14..4f71b1d6f 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo index 381efaf32..ba14221ab 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors.cairo b/tests/nodes/max_i8_broadcast_two_tensors.cairo index 6a2f8b42f..af4a99d9f 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo index ea28aa087..ab27c2d6a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { 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/nodes/max_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo index 273837ef7..11068ef7a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors.cairo b/tests/nodes/max_i8_three_tensors.cairo index 40b83fbcc..b88c9459b 100644 --- a/tests/nodes/max_i8_three_tensors.cairo +++ b/tests/nodes/max_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_0.cairo b/tests/nodes/max_i8_three_tensors/input_0.cairo index 07fbd1690..69d671087 100644 --- a/tests/nodes/max_i8_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_1.cairo b/tests/nodes/max_i8_three_tensors/input_1.cairo index 47afadf00..67ba2e3ed 100644 --- a/tests/nodes/max_i8_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, 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/nodes/max_i8_three_tensors/input_2.cairo b/tests/nodes/max_i8_three_tensors/input_2.cairo index e37ded791..ab0f01d88 100644 --- a/tests/nodes/max_i8_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/output_0.cairo b/tests/nodes/max_i8_three_tensors/output_0.cairo index 5814fe790..4f7334f20 100644 --- a/tests/nodes/max_i8_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, 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/nodes/max_i8_two_tensors.cairo b/tests/nodes/max_i8_two_tensors.cairo index 9f6ee682d..d3ad09730 100644 --- a/tests/nodes/max_i8_two_tensors.cairo +++ b/tests/nodes/max_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_0.cairo b/tests/nodes/max_i8_two_tensors/input_0.cairo index ec6c88799..0d4c5397e 100644 --- a/tests/nodes/max_i8_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_1.cairo b/tests/nodes/max_i8_two_tensors/input_1.cairo index bc48996a9..55509fb6d 100644 --- a/tests/nodes/max_i8_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/output_0.cairo b/tests/nodes/max_i8_two_tensors/output_0.cairo index 889fc62c1..4025af717 100644 --- a/tests/nodes/max_i8_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors.cairo b/tests/nodes/max_u32_broadcast_three_tensors.cairo index a378bd9a7..241a2fc8f 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo index 108d66672..6c083ffa7 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(2); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo index a904f4e58..ea8734bae 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo index ab0ca7fb6..68dfae000 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo index 0f21da101..a0bd55df8 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors.cairo b/tests/nodes/max_u32_broadcast_two_tensors.cairo index ddcd35e04..b32369429 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo index e7dcaeaf3..9e24dfb3b 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo index b09e9c973..19d7a2a17 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo index 8354b7151..71b7b07b4 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors.cairo b/tests/nodes/max_u32_three_tensors.cairo index 655f2a713..c8fb9dfe1 100644 --- a/tests/nodes/max_u32_three_tensors.cairo +++ b/tests/nodes/max_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_0.cairo b/tests/nodes/max_u32_three_tensors/input_0.cairo index e428995ce..15d5eb226 100644 --- a/tests/nodes/max_u32_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(0); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_1.cairo b/tests/nodes/max_u32_three_tensors/input_1.cairo index edb019a72..5e8843449 100644 --- a/tests/nodes/max_u32_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_2.cairo b/tests/nodes/max_u32_three_tensors/input_2.cairo index cdd6dd700..220491901 100644 --- a/tests/nodes/max_u32_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/output_0.cairo b/tests/nodes/max_u32_three_tensors/output_0.cairo index b8b2b72aa..75fb08e26 100644 --- a/tests/nodes/max_u32_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors.cairo b/tests/nodes/max_u32_two_tensors.cairo index faed3d640..b4fbf9e02 100644 --- a/tests/nodes/max_u32_two_tensors.cairo +++ b/tests/nodes/max_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_0.cairo b/tests/nodes/max_u32_two_tensors/input_0.cairo index dde213565..6f1f617cd 100644 --- a/tests/nodes/max_u32_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_1.cairo b/tests/nodes/max_u32_two_tensors/input_1.cairo index bdd40bb01..131ad4f0f 100644 --- a/tests/nodes/max_u32_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(2); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/output_0.cairo b/tests/nodes/max_u32_two_tensors/output_0.cairo index e585ea8dc..4e935e3ea 100644 --- a/tests/nodes/max_u32_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo index c71edce86..220395f62 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo index bf27fbdf0..4589ab5de 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo index 98ef140fa..8bb4c575b 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo index 3b998ca1a..9a2d7a980 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo index c1c0930a4..2cccefb8a 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo index 0e8b2aebb..e6fd1bcce 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors.cairo b/tests/nodes/min_fp16x16_three_tensors.cairo index 8a5d60711..5501d9f70 100644 --- a/tests/nodes/min_fp16x16_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo index 747696a57..b5db9e4f1 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo index 22d5848ef..4aa7ab102 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo index 02084123c..1488424a5 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo index 6931f714a..6db8c5c68 100644 --- a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors.cairo b/tests/nodes/min_fp16x16_two_tensors.cairo index 25adc490e..a0c99e5a5 100644 --- a/tests/nodes/min_fp16x16_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo index 3cc3af9cb..c827d6229 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo index 230c3bfd0..9f62c5305 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo index 785211ceb..9e4c65919 100644 --- a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo index 2596fabad..7a66521a5 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo index c5eee64f3..f45ededce 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo index 5ddfee383..709d521a4 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo index 87ac9a1aa..5759d134b 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo index 6a9b1f878..3b2410704 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo index b231c5d76..babc5664d 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo index 06a77989a..764036b1c 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo index 538d00e70..35cf05e4e 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo index dbb598ae0..6279adb4a 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors.cairo b/tests/nodes/min_fp8x23_three_tensors.cairo index 676f8f312..9a4880f3e 100644 --- a/tests/nodes/min_fp8x23_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo index 9716ed3b9..1a1046aa6 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo index 49311a2b0..a90022ac9 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo index 9b8b0650e..87a644d4e 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo index af08ef421..15f4b94ea 100644 --- a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors.cairo b/tests/nodes/min_fp8x23_two_tensors.cairo index 01d2724ea..dbc7345e4 100644 --- a/tests/nodes/min_fp8x23_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo index 293eb3e83..e0caca041 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo index 76f71b638..3eb98567d 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo index c0e8bbc56..89214df41 100644 --- a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors.cairo b/tests/nodes/min_i32_broadcast_three_tensors.cairo index 74ad7c090..e1eb8036b 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo index 3ffb54363..df439f61e 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo index 97515f83e..b1b65261f 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo index 3031cb2bf..a81378685 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors.cairo b/tests/nodes/min_i32_broadcast_two_tensors.cairo index 43e5f99e0..56f474b6d 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo index b9cd5f819..324736c63 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo index ab5754cf2..bf2fecba4 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo index fa1f29299..9728ec700 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors.cairo b/tests/nodes/min_i32_three_tensors.cairo index adb4350db..332b00c62 100644 --- a/tests/nodes/min_i32_three_tensors.cairo +++ b/tests/nodes/min_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_0.cairo b/tests/nodes/min_i32_three_tensors/input_0.cairo index a255474d1..d7c51ab8d 100644 --- a/tests/nodes/min_i32_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_1.cairo b/tests/nodes/min_i32_three_tensors/input_1.cairo index 33568613e..0c25e152d 100644 --- a/tests/nodes/min_i32_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_2.cairo b/tests/nodes/min_i32_three_tensors/input_2.cairo index 9b822fc6d..f8d3071be 100644 --- a/tests/nodes/min_i32_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 1, 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/nodes/min_i32_three_tensors/output_0.cairo b/tests/nodes/min_i32_three_tensors/output_0.cairo index 9b0a9b23a..3f93c789b 100644 --- a/tests/nodes/min_i32_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors.cairo b/tests/nodes/min_i32_two_tensors.cairo index ae444f6e7..36bff1cd3 100644 --- a/tests/nodes/min_i32_two_tensors.cairo +++ b/tests/nodes/min_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_0.cairo b/tests/nodes/min_i32_two_tensors/input_0.cairo index 518ef5c24..53c2fcaa5 100644 --- a/tests/nodes/min_i32_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 5, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_1.cairo b/tests/nodes/min_i32_two_tensors/input_1.cairo index 42bdad0c9..92a12ff67 100644 --- a/tests/nodes/min_i32_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { 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/nodes/min_i32_two_tensors/output_0.cairo b/tests/nodes/min_i32_two_tensors/output_0.cairo index af1b203d5..d3e493a26 100644 --- a/tests/nodes/min_i32_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors.cairo b/tests/nodes/min_i8_broadcast_three_tensors.cairo index 4b67ffc7d..2256c0b62 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo index 254b04d0a..031cd3791 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo index 4fc8ae5a6..b7f890f64 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo index f472bb1d6..72888bf4c 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo index 9e4345995..289d4ad87 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors.cairo b/tests/nodes/min_i8_broadcast_two_tensors.cairo index a533c5930..d6344af77 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo index 563c07736..0966277be 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo index 060e0a9ec..1748d763f 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo index 86ec9707b..8bedae7e1 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors.cairo b/tests/nodes/min_i8_three_tensors.cairo index cee72024b..5d41e2551 100644 --- a/tests/nodes/min_i8_three_tensors.cairo +++ b/tests/nodes/min_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_0.cairo b/tests/nodes/min_i8_three_tensors/input_0.cairo index 92635527e..d29670a9f 100644 --- a/tests/nodes/min_i8_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_1.cairo b/tests/nodes/min_i8_three_tensors/input_1.cairo index 09e7ab7d1..d33e241c1 100644 --- a/tests/nodes/min_i8_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_2.cairo b/tests/nodes/min_i8_three_tensors/input_2.cairo index 6784429c8..9f66c1a8c 100644 --- a/tests/nodes/min_i8_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/output_0.cairo b/tests/nodes/min_i8_three_tensors/output_0.cairo index 86ccc411f..729e61ba1 100644 --- a/tests/nodes/min_i8_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors.cairo b/tests/nodes/min_i8_two_tensors.cairo index 8f13d360a..ffb3dd382 100644 --- a/tests/nodes/min_i8_two_tensors.cairo +++ b/tests/nodes/min_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_0.cairo b/tests/nodes/min_i8_two_tensors/input_0.cairo index edcba1f05..dfb122bf3 100644 --- a/tests/nodes/min_i8_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_1.cairo b/tests/nodes/min_i8_two_tensors/input_1.cairo index 805f2971a..9a088d52a 100644 --- a/tests/nodes/min_i8_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/output_0.cairo b/tests/nodes/min_i8_two_tensors/output_0.cairo index 4cfdc62b3..35e0b1112 100644 --- a/tests/nodes/min_i8_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors.cairo b/tests/nodes/min_u32_broadcast_three_tensors.cairo index b76ced612..3f90de3a0 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo index e1fde6172..ab5743e17 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(4); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo index 4f6ed249f..eb67448d2 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo index 9b8b57621..9ffbb5a5c 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo index 5af544845..5586a7f29 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors.cairo b/tests/nodes/min_u32_broadcast_two_tensors.cairo index 9fe666a9e..ead761837 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo index a173baaf1..79e203e76 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo index 447f95446..8f2990dec 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(5); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo index 51197a3e8..67ba1889c 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors.cairo b/tests/nodes/min_u32_three_tensors.cairo index 958888c62..82983386f 100644 --- a/tests/nodes/min_u32_three_tensors.cairo +++ b/tests/nodes/min_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_0.cairo b/tests/nodes/min_u32_three_tensors/input_0.cairo index 30bcab8cc..408871093 100644 --- a/tests/nodes/min_u32_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_1.cairo b/tests/nodes/min_u32_three_tensors/input_1.cairo index 73f220714..cbbfc75c3 100644 --- a/tests/nodes/min_u32_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_2.cairo b/tests/nodes/min_u32_three_tensors/input_2.cairo index 1f682b4a7..8e8027f01 100644 --- a/tests/nodes/min_u32_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/output_0.cairo b/tests/nodes/min_u32_three_tensors/output_0.cairo index 7a47c65c1..7e844ee1a 100644 --- a/tests/nodes/min_u32_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors.cairo b/tests/nodes/min_u32_two_tensors.cairo index 94ce36d7a..4b06824b8 100644 --- a/tests/nodes/min_u32_two_tensors.cairo +++ b/tests/nodes/min_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_0.cairo b/tests/nodes/min_u32_two_tensors/input_0.cairo index c20d52a0a..b4de32a93 100644 --- a/tests/nodes/min_u32_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_1.cairo b/tests/nodes/min_u32_two_tensors/input_1.cairo index d4709f0df..375910cbf 100644 --- a/tests/nodes/min_u32_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(3); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/output_0.cairo b/tests/nodes/min_u32_two_tensors/output_0.cairo index fc5f86d90..8fe8219a3 100644 --- a/tests/nodes/min_u32_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16.cairo b/tests/nodes/round_fp16x16.cairo index 02a279685..504ab435d 100644 --- a/tests/nodes/round_fp16x16.cairo +++ b/tests/nodes/round_fp16x16.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp16x16() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/input_0.cairo b/tests/nodes/round_fp16x16/input_0.cairo index 68229762b..711f27428 100644 --- a/tests/nodes/round_fp16x16/input_0.cairo +++ b/tests/nodes/round_fp16x16/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 163840, sign: true }); data.append(FP16x16 { mag: 183500, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/output_0.cairo b/tests/nodes/round_fp16x16/output_0.cairo index e303e30e4..0a920a6c2 100644 --- a/tests/nodes/round_fp16x16/output_0.cairo +++ b/tests/nodes/round_fp16x16/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23.cairo b/tests/nodes/round_fp8x23.cairo index e09a76fd2..8be8ed312 100644 --- a/tests/nodes/round_fp8x23.cairo +++ b/tests/nodes/round_fp8x23.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp8x23() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/input_0.cairo b/tests/nodes/round_fp8x23/input_0.cairo index d812ae1a2..386404257 100644 --- a/tests/nodes/round_fp8x23/input_0.cairo +++ b/tests/nodes/round_fp8x23/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 20971520, sign: true }); data.append(FP8x23 { mag: 23488102, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/output_0.cairo b/tests/nodes/round_fp8x23/output_0.cairo index d5cc73f5f..b984ecfe6 100644 --- a/tests/nodes/round_fp8x23/output_0.cairo +++ b/tests/nodes/round_fp8x23/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1.cairo index ddd2ed77a..10838d6e7 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo index e450321a6..cfa417414 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 589824, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo index c8027a1a5..87045d082 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo index 47d99b23f..1b2e7a743 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 1048576, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default.cairo b/tests/nodes/scatter_fp16x16_3d_default.cairo index ebc06014d..06cfd4fdd 100644 --- a/tests/nodes/scatter_fp16x16_3d_default.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo index 9edd74528..fa9f6a8b6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1.cairo b/tests/nodes/scatter_fp8x23_axis1.cairo index 31ec2ea7c..ef903f3ad 100644 --- a/tests/nodes/scatter_fp8x23_axis1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo index 888cee255..46d23fbd5 100644 --- a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 75497472, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default.cairo b/tests/nodes/scatter_fp8x23_default.cairo index 66e5a6064..0ffd910b4 100644 --- a/tests/nodes/scatter_fp8x23_default.cairo +++ b/tests/nodes/scatter_fp8x23_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_0.cairo b/tests/nodes/scatter_fp8x23_default/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_default/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_1.cairo b/tests/nodes/scatter_fp8x23_default/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_default/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_2.cairo b/tests/nodes/scatter_fp8x23_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_default/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/output_0.cairo b/tests/nodes/scatter_fp8x23_default/output_0.cairo index 6c198c3af..c2011e04b 100644 --- a/tests/nodes/scatter_fp8x23_default/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul.cairo b/tests/nodes/scatter_fp8x23_mul.cairo index 8f6a9e5ae..dc90cfcbe 100644 --- a/tests/nodes/scatter_fp8x23_mul.cairo +++ b/tests/nodes/scatter_fp8x23_mul.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_mul() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('mul') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_0.cairo b/tests/nodes/scatter_fp8x23_mul/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_1.cairo b/tests/nodes/scatter_fp8x23_mul/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_2.cairo b/tests/nodes/scatter_fp8x23_mul/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/output_0.cairo b/tests/nodes/scatter_fp8x23_mul/output_0.cairo index 73c873293..b0b7353cc 100644 --- a/tests/nodes/scatter_fp8x23_mul/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1.cairo b/tests/nodes/scatter_i8_axis1.cairo index aeed6cea2..2374e89c5 100644 --- a/tests/nodes/scatter_i8_axis1.cairo +++ b/tests/nodes/scatter_i8_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_0.cairo b/tests/nodes/scatter_i8_axis1/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_1.cairo b/tests/nodes/scatter_i8_axis1/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_2.cairo b/tests/nodes/scatter_i8_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/output_0.cairo b/tests/nodes/scatter_i8_axis1/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max.cairo b/tests/nodes/scatter_i8_axis1_max.cairo index 0b1cc537c..b4d1a8799 100644 --- a/tests/nodes/scatter_i8_axis1_max.cairo +++ b/tests/nodes/scatter_i8_axis1_max.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1_max() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('max') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_0.cairo b/tests/nodes/scatter_i8_axis1_max/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_1.cairo b/tests/nodes/scatter_i8_axis1_max/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_2.cairo b/tests/nodes/scatter_i8_axis1_max/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/output_0.cairo b/tests/nodes/scatter_i8_axis1_max/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1_max/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default.cairo b/tests/nodes/scatter_i8_default.cairo index b0d10c89d..e28a0549c 100644 --- a/tests/nodes/scatter_i8_default.cairo +++ b/tests/nodes/scatter_i8_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_0.cairo b/tests/nodes/scatter_i8_default/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_default/input_0.cairo +++ b/tests/nodes/scatter_i8_default/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_1.cairo b/tests/nodes/scatter_i8_default/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_default/input_1.cairo +++ b/tests/nodes/scatter_i8_default/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_2.cairo b/tests/nodes/scatter_i8_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_default/input_2.cairo +++ b/tests/nodes/scatter_i8_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/output_0.cairo b/tests/nodes/scatter_i8_default/output_0.cairo index 9f1cf79dd..dfc02ca20 100644 --- a/tests/nodes/scatter_i8_default/output_0.cairo +++ b/tests/nodes/scatter_i8_default/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add.cairo b/tests/nodes/scatter_u32_add.cairo index 5c28a9394..3d1a8a0a9 100644 --- a/tests/nodes/scatter_u32_add.cairo +++ b/tests/nodes/scatter_u32_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_0.cairo b/tests/nodes/scatter_u32_add/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_add/input_0.cairo +++ b/tests/nodes/scatter_u32_add/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_1.cairo b/tests/nodes/scatter_u32_add/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_add/input_1.cairo +++ b/tests/nodes/scatter_u32_add/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_2.cairo b/tests/nodes/scatter_u32_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_add/input_2.cairo +++ b/tests/nodes/scatter_u32_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/output_0.cairo b/tests/nodes/scatter_u32_add/output_0.cairo index 924837c12..e892f73f8 100644 --- a/tests/nodes/scatter_u32_add/output_0.cairo +++ b/tests/nodes/scatter_u32_add/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1.cairo b/tests/nodes/scatter_u32_axis1.cairo index 784c28787..da79a252c 100644 --- a/tests/nodes/scatter_u32_axis1.cairo +++ b/tests/nodes/scatter_u32_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_0.cairo b/tests/nodes/scatter_u32_axis1/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_axis1/input_0.cairo +++ b/tests/nodes/scatter_u32_axis1/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_1.cairo b/tests/nodes/scatter_u32_axis1/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_axis1/input_1.cairo +++ b/tests/nodes/scatter_u32_axis1/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_2.cairo b/tests/nodes/scatter_u32_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_axis1/input_2.cairo +++ b/tests/nodes/scatter_u32_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/output_0.cairo b/tests/nodes/scatter_u32_axis1/output_0.cairo index 2a2d51eda..85db8a36f 100644 --- a/tests/nodes/scatter_u32_axis1/output_0.cairo +++ b/tests/nodes/scatter_u32_axis1/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(9); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default.cairo b/tests/nodes/scatter_u32_default.cairo index fd2607de7..5cf0e53d7 100644 --- a/tests/nodes/scatter_u32_default.cairo +++ b/tests/nodes/scatter_u32_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_0.cairo b/tests/nodes/scatter_u32_default/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_default/input_0.cairo +++ b/tests/nodes/scatter_u32_default/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_1.cairo b/tests/nodes/scatter_u32_default/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_default/input_1.cairo +++ b/tests/nodes/scatter_u32_default/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_2.cairo b/tests/nodes/scatter_u32_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_default/input_2.cairo +++ b/tests/nodes/scatter_u32_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/output_0.cairo b/tests/nodes/scatter_u32_default/output_0.cairo index 3bea6d3a7..09bc154f4 100644 --- a/tests/nodes/scatter_u32_default/output_0.cairo +++ b/tests/nodes/scatter_u32_default/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/operators.cairo b/tests/operators.cairo index 687bd30ea..fb1ebc4e8 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -1,3 +1,4 @@ mod transpose_test; mod qlinear_matmul_test; mod qlinear_add_test; +mod constant_of_shape_test; diff --git a/tests/operators/constant_of_shape_test.cairo b/tests/operators/constant_of_shape_test.cairo new file mode 100644 index 000000000..445dffe61 --- /dev/null +++ b/tests/operators/constant_of_shape_test.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; +use debug::PrintTrait; + + +#[test] +#[available_gas(200000000000)] +fn constant_of_shape_test() { + let tensor = TensorTrait::::constant_of_shape(shape: array![4, 2].span(), value: 20); + + assert(tensor.shape == array![4, 2].span(), 'wrong dim'); + assert(tensor.data == array![20, 20, 20, 20, 20, 20, 20, 20].span(), 'wrong values'); +} diff --git a/tests/operators/qlinear_add_test.cairo b/tests/operators/qlinear_add_test.cairo index 4c08a77ea..667d64411 100644 --- a/tests/operators/qlinear_add_test.cairo +++ b/tests/operators/qlinear_add_test.cairo @@ -5,7 +5,7 @@ use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tens use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; use orion::numbers::{NumberTrait, IntegerTrait}; use orion::numbers::{i8, i32}; - + #[test] #[available_gas(200000000000)] @@ -144,7 +144,7 @@ fn qlinearadd_broadcast_test() { #[test] #[available_gas(200000000000)] -fn test_example_doc() { +fn test_example_doc() { let a = TensorTrait::< i8 >::new( @@ -173,7 +173,9 @@ fn test_example_doc() { let a_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); let a_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); @@ -186,19 +188,19 @@ fn test_example_doc() { let y_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); let y_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, true)].span(),); let actual_output = a - .qlinear_add( - @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point - ); + .qlinear_add(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); assert((*actual_output.data[0]).into() == 1, '*result[0] == 1'); assert((*actual_output.data[1]).into() == 1, '*result[1] == 1'); assert((*actual_output.data[2]).into() == 1, '*result[2] == 1'); assert((*actual_output.data[3]).into() == 2, '*result[3] == 2'); assert((*actual_output.data[4]).into() == 2, '*result[4] == 2'); - assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); -} + assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); +} From 9f4e1bace6473249ef2c640f7ca832829404e066 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 8 Nov 2023 11:07:08 +0200 Subject: [PATCH 043/127] fix deref issue --- .../tree_ensemble_classifier.cairo | 41 +++++++++++++------ tests/ml/tree_ensemble_classifier.cairo | 1 - 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 5ac2cf43f..b7f9432f4 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -10,6 +10,8 @@ use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::{SpanTraitExt}; +use debug::PrintTrait; + #[derive(Destruct)] struct TreeEnsembleClassifier { ensemble: TreeEnsemble, @@ -107,14 +109,18 @@ fn compute_scores, +Copy, +NumberTrait, +Add,>( let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash(tree_id.into(), node_id.into()); - let prev_value = class_index.get(key); - match match_nullable(prev_value) { - FromNullableResult::Null(()) => { // entry.finalize(NullableTrait::new(array![])) + let value = class_index.get(key); + match match_nullable(value) { + FromNullableResult::Null(()) => { + class_index + .insert( + key, NullableTrait::new(array![(class_id, *class_weight)].span()) + ); }, FromNullableResult::NotNull(val) => { - let mut new_val = prev_value.deref(); - let new_va = new_val.concat(array![(class_id, *class_weight)].span()); - class_index.insert(key, nullable_from_box(BoxTrait::new(new_va))); + let mut new_val = value.deref(); + let new_val = new_val.concat(array![(class_id, *class_weight)].span()); + class_index.insert(key, NullableTrait::new(new_val)); }, }; }, @@ -148,12 +154,20 @@ fn compute_scores, +Copy, +NumberTrait, +Add,>( let key: felt252 = key .hash((sample_index).into(), (class_id).into()); - let value = scores_data.get(key).deref(); - scores_data - .insert( - key, - nullable_from_box(BoxTrait::new(value + class_weight)) - ); + let value = scores_data.get(key); + match match_nullable(value) { + FromNullableResult::Null(()) => { + scores_data + .insert(key, NullableTrait::new(class_weight)); + }, + FromNullableResult::NotNull(val) => { + scores_data + .insert( + key, + NullableTrait::new(value.deref() + class_weight) + ); + }, + } }, Option::None(_) => { break; } }; @@ -218,7 +232,8 @@ fn classify< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key].deref(); + let score = scores_data[key] + .deref(); // <-- PANICS HERE WITH 'Attempted to deref null value' if score > max_score { max_score = score; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 48497b267..66a8f44a4 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -5,7 +5,6 @@ use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - //TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; From a6782eb55ea02fc1329a98483e7109e8827d6376 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 8 Nov 2023 10:47:20 +0100 Subject: [PATCH 044/127] fix path --- nodegen/helpers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index c5b7e7de1..848a18879 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -4,6 +4,9 @@ import numpy as np + +__PATH = "/tests/nodes" + ###################### # DATA STRUCTURES ###################### @@ -38,7 +41,7 @@ class Trait(Enum): ################ -def make_node(inputs: [Tensor], outputs: [Tensor], dir_name, path="tests/src/nodes/"): +def make_node(inputs: [Tensor], outputs: [Tensor], dir_name, path=__PATH): path = path + dir_name @@ -143,7 +146,7 @@ def make_test(inputs: [Tensor], output: Tensor, func_sig: str, file_name: str, t code.append(" assert_eq(y, z);\n") code.append("}") - with open(os.path.join("tests/src/nodes", f"{file_name}.cairo"), "a") as f: + with open(os.path.join(__PATH, f"{file_name}.cairo"), "a") as f: f.write( ''.join(code) ) @@ -238,14 +241,14 @@ def __generate_data(tensor: Tensor, path: str, name: str): # Add mod parent to nodes.cairo if not os.path.exists(path) or not os.listdir(path): os.makedirs(path, exist_ok=True) - parent = path.replace("tests/src/nodes/", "") - with open("tests/src/nodes.cairo", "a") as f: + parent = path.replace(__PATH, "") + with open(f"{__PATH}.cairo", "a") as f: f.write(f"mod {parent}; \n") # Add tensor mod in parent file - parent = path.replace("tests/src/nodes/", "") - if not __module_exists(os.path.join("tests/src/nodes/", f"{parent}.cairo"), name): - with open(os.path.join("tests/src/nodes/", f"{parent}.cairo"), "a") as f: + parent = path.replace(__PATH, "") + if not __module_exists(os.path.join(__PATH, f"{parent}.cairo"), name): + with open(os.path.join(__PATH, f"{parent}.cairo"), "a") as f: f.write(f"mod {name}; \n") # Convert tensor to cairo From a623f6bbdd2079b9e0944ba757f9cf8b0394aa5a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 8 Nov 2023 12:17:50 +0200 Subject: [PATCH 045/127] fix tensor wrong shape --- .../ml/tree_ensemble/tree_ensemble_classifier.cairo | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index b7f9432f4..10523ab11 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -232,8 +232,9 @@ fn classify< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key] - .deref(); // <-- PANICS HERE WITH 'Attempted to deref null value' + let score = scores_data[key].deref(); + + final_scores_data.append(score); if score > max_score { max_score = score; @@ -243,7 +244,6 @@ fn classify< class_index += 1; }; - final_scores_data.append(max_score); predictions_data.append(max_class_index); sample_index += 1; }; From b21b9310da2b2e4d3e8aa935c75dcc8b0b8abfe8 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 11:26:43 +0100 Subject: [PATCH 046/127] Add tests and adjust implementations --- nodegen/node/binarizer.py | 49 +++++++++++++++++++ .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- tests/nodes.cairo | 5 +- tests/nodes/binarizer_fp16x16.cairo | 21 ++++++++ tests/nodes/binarizer_fp16x16/input_0.cairo | 42 ++++++++++++++++ tests/nodes/binarizer_fp16x16/output_0.cairo | 40 +++++++++++++++ tests/nodes/binarizer_fp8x23.cairo | 21 ++++++++ tests/nodes/binarizer_fp8x23/input_0.cairo | 42 ++++++++++++++++ tests/nodes/binarizer_fp8x23/output_0.cairo | 40 +++++++++++++++ tests/nodes/binarizer_i32.cairo | 21 ++++++++ tests/nodes/binarizer_i32/input_0.cairo | 41 ++++++++++++++++ tests/nodes/binarizer_i32/output_0.cairo | 40 +++++++++++++++ 13 files changed, 363 insertions(+), 3 deletions(-) create mode 100644 nodegen/node/binarizer.py create mode 100644 tests/nodes/binarizer_fp16x16.cairo create mode 100644 tests/nodes/binarizer_fp16x16/input_0.cairo create mode 100644 tests/nodes/binarizer_fp16x16/output_0.cairo create mode 100644 tests/nodes/binarizer_fp8x23.cairo create mode 100644 tests/nodes/binarizer_fp8x23/input_0.cairo create mode 100644 tests/nodes/binarizer_fp8x23/output_0.cairo create mode 100644 tests/nodes/binarizer_i32.cairo create mode 100644 tests/nodes/binarizer_i32/input_0.cairo create mode 100644 tests/nodes/binarizer_i32/output_0.cairo diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py new file mode 100644 index 000000000..661fcf95a --- /dev/null +++ b/nodegen/node/binarizer.py @@ -0,0 +1,49 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Binarizer(RunAll): + + @staticmethod + def binarizer_i32(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) + threshold = 1 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_i32" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false));", name) + + + @staticmethod + def binarizer_fp8x23(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + threshold = 1.0 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_fp8x23" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false));", name) + + + @staticmethod + def binarizer_fp16x16(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + threshold = 1.0 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_fp16x16" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false));", name) diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index d682114d8..cd7247aa9 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -288,7 +288,7 @@ impl I8Tensor of TensorTrait { } fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { - math::binarizer::binarizer(*self, threshold) + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 7c18fb79d..2fd0063f4 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -270,7 +270,7 @@ impl U32Tensor of TensorTrait { } fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { - math::binarizer::binarizer(*self, threshold) + panic(array!['not supported!']) } } diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..e841e15aa 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,4 +527,7 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod scatter_u32_add; +mod binarizer_fp16x16; +mod binarizer_fp8x23; +mod binarizer_i32; diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo new file mode 100644 index 000000000..258bfa8f1 --- /dev/null +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_binarizer_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo new file mode 100644 index 000000000..2aaa53e2b --- /dev/null +++ b/tests/nodes/binarizer_fp16x16/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 146027, sign: true }); + data.append(FP16x16 { mag: 29998, sign: false }); + data.append(FP16x16 { mag: 79381, sign: true }); + data.append(FP16x16 { mag: 52502, sign: true }); + data.append(FP16x16 { mag: 141943, sign: true }); + data.append(FP16x16 { mag: 77493, sign: true }); + data.append(FP16x16 { mag: 143847, sign: true }); + data.append(FP16x16 { mag: 40577, sign: true }); + data.append(FP16x16 { mag: 15396, sign: false }); + data.append(FP16x16 { mag: 194266, sign: true }); + data.append(FP16x16 { mag: 73878, sign: true }); + data.append(FP16x16 { mag: 123262, sign: true }); + data.append(FP16x16 { mag: 106458, sign: false }); + data.append(FP16x16 { mag: 173856, sign: false }); + data.append(FP16x16 { mag: 80438, sign: true }); + data.append(FP16x16 { mag: 164829, sign: true }); + data.append(FP16x16 { mag: 89224, sign: true }); + data.append(FP16x16 { mag: 2691, sign: false }); + data.append(FP16x16 { mag: 181152, sign: true }); + data.append(FP16x16 { mag: 128977, sign: false }); + data.append(FP16x16 { mag: 78823, sign: true }); + data.append(FP16x16 { mag: 65209, sign: true }); + data.append(FP16x16 { mag: 56918, sign: false }); + data.append(FP16x16 { mag: 118799, sign: true }); + data.append(FP16x16 { mag: 179883, sign: false }); + data.append(FP16x16 { mag: 114165, sign: true }); + data.append(FP16x16 { mag: 142, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo new file mode 100644 index 000000000..9499a7848 --- /dev/null +++ b/tests/nodes/binarizer_fp16x16/output_0.cairo @@ -0,0 +1,40 @@ +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(3); + shape.append(3); + 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(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + 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(0); + data.append(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo new file mode 100644 index 000000000..4de3cbb7d --- /dev/null +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_binarizer_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo new file mode 100644 index 000000000..39d12c3be --- /dev/null +++ b/tests/nodes/binarizer_fp8x23/input_0.cairo @@ -0,0 +1,42 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 7205493, sign: true }); + data.append(FP8x23 { mag: 14503128, sign: false }); + data.append(FP8x23 { mag: 9682839, sign: false }); + data.append(FP8x23 { mag: 25030485, sign: false }); + data.append(FP8x23 { mag: 3669115, sign: true }); + data.append(FP8x23 { mag: 16376632, sign: true }); + data.append(FP8x23 { mag: 4670619, sign: false }); + data.append(FP8x23 { mag: 24976405, sign: true }); + data.append(FP8x23 { mag: 19811890, sign: false }); + data.append(FP8x23 { mag: 10781071, sign: true }); + data.append(FP8x23 { mag: 10216945, sign: false }); + data.append(FP8x23 { mag: 25004285, sign: false }); + data.append(FP8x23 { mag: 7482592, sign: false }); + data.append(FP8x23 { mag: 1360, sign: true }); + data.append(FP8x23 { mag: 10632602, sign: true }); + data.append(FP8x23 { mag: 275175, sign: true }); + data.append(FP8x23 { mag: 21731586, sign: true }); + data.append(FP8x23 { mag: 5638921, sign: true }); + data.append(FP8x23 { mag: 6096613, sign: false }); + data.append(FP8x23 { mag: 22105612, sign: false }); + data.append(FP8x23 { mag: 17084000, sign: true }); + data.append(FP8x23 { mag: 12627954, sign: true }); + data.append(FP8x23 { mag: 23194838, sign: false }); + data.append(FP8x23 { mag: 9012947, sign: false }); + data.append(FP8x23 { mag: 5163417, sign: true }); + data.append(FP8x23 { mag: 13580853, sign: false }); + data.append(FP8x23 { mag: 5624227, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo new file mode 100644 index 000000000..d5317e309 --- /dev/null +++ b/tests/nodes/binarizer_fp8x23/output_0.cairo @@ -0,0 +1,40 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + 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(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo new file mode 100644 index 000000000..dc82a3bd1 --- /dev/null +++ b/tests/nodes/binarizer_i32.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::IntegerTrait; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_binarizer_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo new file mode 100644 index 000000000..f4e25323a --- /dev/null +++ b/tests/nodes/binarizer_i32/input_0.cairo @@ -0,0 +1,41 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo new file mode 100644 index 000000000..23163214e --- /dev/null +++ b/tests/nodes/binarizer_i32/output_0.cairo @@ -0,0 +1,40 @@ +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(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(1); + 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(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(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From ff2e85748e7c72e1c410e66062c2fabf0a1ec159 Mon Sep 17 00:00:00 2001 From: 0x73e <132935850+0x73e@users.noreply.github.com> Date: Wed, 8 Nov 2023 07:24:34 -0500 Subject: [PATCH 047/127] refactor --- src/operators/tensor/core.cairo | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 902a86afa..6e0feddb8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3400,15 +3400,16 @@ fn constant_of_shape, impl FDrop: Drop,>( ) -> Tensor { let mut data = ArrayTrait::new(); - let mut i = 0; - let length = len_from_shape(shape); + let mut length = len_from_shape(shape); loop { - if i == length { - break (); + match length.into() { + 0 => { break (); }, + _ => { + data.append(value.clone()); + length -= 1; + } } - data.append(value.clone()); - i += 1; }; Tensor:: { shape, data: data.span() } From 73da4eb5622e1530d0a12573185b79cf90d56151 Mon Sep 17 00:00:00 2001 From: 0x73e <132935850+0x73e@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:06:44 -0500 Subject: [PATCH 048/127] refactor: use pop_front to avoid the use of .at() for gas optimizations --- src/operators/tensor/linalg/trilu.cairo | 38 ++++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/operators/tensor/linalg/trilu.cairo b/src/operators/tensor/linalg/trilu.cairo index de96b3db5..a7a0f03d8 100644 --- a/src/operators/tensor/linalg/trilu.cairo +++ b/src/operators/tensor/linalg/trilu.cairo @@ -19,23 +19,35 @@ fn trilu< let shape_len = (*self.shape).len(); let mut output_data = ArrayTrait::new(); + let mut output_size = ArrayTrait::new(); let mut batch_size = 1; - let n: u32 = *self.shape[shape_len - 2]; - let m: u32 = *self.shape[shape_len - 1]; + let mut n: u32 = 0; + let mut m: u32 = 0; { + let mut self_shape = *self.shape; let mut i = 0; loop { - if i == shape_len - 2 { - break (); + match self_shape.pop_front() { + Option::Some(val) => { + if i == shape_len - 2 { + n = *val; + } else if i == shape_len - 1 { + m = *val; + } else { + batch_size *= *val; + } + i += 1; + output_size.append(*val); + }, + Option::None(_) => { break (); } } - batch_size *= *self.shape[i]; - i += 1; } } { + let mut self_data = *self.data; let mut b = 0; loop { if b == batch_size { @@ -59,11 +71,17 @@ fn trilu< let iii: i64 = ii.try_into().unwrap(); let jjj: i64 = jj.try_into().unwrap(); - let result = if (upper && (iii + k <= jjj)) || (!upper && (iii + k >= jjj)) { - *(*self.data)[(b * n * m) + (i * m + j)] - } else { - NumberTrait::zero() + let result = match self_data.pop_front() { + Option::Some(val) => { + if (upper && (iii + k <= jjj)) || (!upper && (iii + k >= jjj)) { + *val + } else { + NumberTrait::zero() + } + }, + Option::None(_) => { break (); } }; + output_data.append(result); j += 1; }; From 94a543088d9e16558f337efdfb94619ef15401b6 Mon Sep 17 00:00:00 2001 From: 0x73e <132935850+0x73e@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:18:06 -0500 Subject: [PATCH 049/127] fmt --- src/operators/tensor/core.cairo | 9 +- .../implementations/tensor_fp16x16.cairo | 9 +- .../implementations/tensor_fp16x16wide.cairo | 11 +- .../implementations/tensor_fp32x32.cairo | 10 +- .../implementations/tensor_fp64x64.cairo | 9 +- .../implementations/tensor_fp8x23.cairo | 10 +- .../implementations/tensor_fp8x23wide.cairo | 11 +- .../tensor/implementations/tensor_i32.cairo | 10 +- .../tensor/implementations/tensor_i8.cairo | 10 +- .../tensor/implementations/tensor_u32.cairo | 8 +- src/operators/tensor/math/scatter.cairo | 156 ++++++++---------- .../tensor/quantization/qlinear_add.cairo | 3 - tests/nodes.cairo | 24 +-- tests/nodes/scatter_fp16x16_3d_axis1.cairo | 18 +- .../scatter_fp16x16_3d_axis1/input_0.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_1.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_2.cairo | 2 +- .../scatter_fp16x16_3d_axis1/output_0.cairo | 2 +- .../nodes/scatter_fp16x16_3d_axis1_add.cairo | 18 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/scatter_fp16x16_3d_default.cairo | 18 +- .../scatter_fp16x16_3d_default/input_0.cairo | 2 +- .../scatter_fp16x16_3d_default/input_1.cairo | 2 +- .../scatter_fp16x16_3d_default/input_2.cairo | 2 +- .../scatter_fp16x16_3d_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_axis1.cairo | 18 +- .../nodes/scatter_fp8x23_axis1/input_0.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_1.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_2.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_default.cairo | 18 +- .../scatter_fp8x23_default/input_0.cairo | 2 +- .../scatter_fp8x23_default/input_1.cairo | 2 +- .../scatter_fp8x23_default/input_2.cairo | 2 +- .../scatter_fp8x23_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul.cairo | 18 +- tests/nodes/scatter_fp8x23_mul/input_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_1.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_2.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1.cairo | 18 +- tests/nodes/scatter_i8_axis1/input_0.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_1.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_2.cairo | 2 +- tests/nodes/scatter_i8_axis1/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1_max.cairo | 18 +- .../nodes/scatter_i8_axis1_max/input_0.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_1.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_2.cairo | 2 +- .../nodes/scatter_i8_axis1_max/output_0.cairo | 2 +- tests/nodes/scatter_i8_default.cairo | 18 +- tests/nodes/scatter_i8_default/input_0.cairo | 2 +- tests/nodes/scatter_i8_default/input_1.cairo | 2 +- tests/nodes/scatter_i8_default/input_2.cairo | 2 +- tests/nodes/scatter_i8_default/output_0.cairo | 2 +- tests/nodes/scatter_u32_add.cairo | 18 +- tests/nodes/scatter_u32_add/input_0.cairo | 2 +- tests/nodes/scatter_u32_add/input_1.cairo | 2 +- tests/nodes/scatter_u32_add/input_2.cairo | 2 +- tests/nodes/scatter_u32_add/output_0.cairo | 2 +- tests/nodes/scatter_u32_axis1.cairo | 18 +- tests/nodes/scatter_u32_axis1/input_0.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_1.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_2.cairo | 2 +- tests/nodes/scatter_u32_axis1/output_0.cairo | 2 +- tests/nodes/scatter_u32_default.cairo | 18 +- tests/nodes/scatter_u32_default/input_0.cairo | 2 +- tests/nodes/scatter_u32_default/input_1.cairo | 2 +- tests/nodes/scatter_u32_default/input_2.cairo | 2 +- .../nodes/scatter_u32_default/output_0.cairo | 2 +- tests/operators/qlinear_add_test.cairo | 20 ++- 74 files changed, 355 insertions(+), 257 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 716dd9f9e..b5ae4bb13 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3261,7 +3261,6 @@ trait TensorTrait { /// ``` /// fn round(self: @Tensor) -> Tensor; -<<<<<<< HEAD /// # tensor.trilu /// /// ```rust @@ -3361,7 +3360,13 @@ trait TensorTrait { /// [ 4, 0, 3, 0, 0]] /// ``` /// - fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 24ef67de0..835c03562 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -311,11 +311,14 @@ impl FP16x16Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// 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 f0b227670..aa79d8a14 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -296,10 +296,15 @@ impl FP16x16WTensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) - + } + fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 55af99e30..bbd08f374 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -309,11 +309,15 @@ impl FP32x32Tensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 0104e345e..c4d3efa41 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -311,11 +311,14 @@ impl FP64x64Tensor of TensorTrait { linalg::trilu::trilu(self, upper, k) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// 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 29cb48c46..6308e2928 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -310,9 +310,13 @@ impl FP8x23Tensor of TensorTrait { linalg::trilu::trilu(self, upper, k) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { - math::scatter::scatter(self, updates, indices, axis, reduction) + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 0bdffdd70..213b3fbe9 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -288,12 +288,15 @@ impl FP8x23WTensor of TensorTrait { linalg::trilu::trilu(self, upper, k) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - -} +} /// Implements addition for `Tensor` using the `Add` trait. impl FP8x23WTensorAdd< diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index fb4624d62..805e0878d 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -308,10 +308,14 @@ impl I32Tensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 4917e9510..75bf843b7 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -307,11 +307,15 @@ impl I8Tensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index d849ae775..e52338359 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -280,8 +280,12 @@ impl U32Tensor of TensorTrait { linalg::trilu::trilu(self, upper, k) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/math/scatter.cairo b/src/operators/tensor/math/scatter.cairo index ea26f1b7e..bcd15c36d 100644 --- a/src/operators/tensor/math/scatter.cairo +++ b/src/operators/tensor/math/scatter.cairo @@ -14,9 +14,21 @@ use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; use dict::Felt252DictTrait; use nullable::{nullable_from_box, match_nullable, FromNullableResult}; /// Cf: TensorTrait::scatter docstring -fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDrop: Drop, impl TAddEq: AddEq, - impl TMulEq: MulEq, impl TPartialOrd: PartialOrd, impl TPartialEq: PartialEq,>( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option +fn scatter< + T, + impl TTensorTrait: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop, + impl TAddEq: AddEq, + impl TMulEq: MulEq, + impl TPartialOrd: PartialOrd, + impl TPartialEq: PartialEq, +>( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option ) -> Tensor { let mut axis = match axis { Option::Some(val) => val, @@ -40,7 +52,10 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_shape = *self.shape; let mut indices_shape = indices.shape; let updates_shape = updates.shape; - assert((*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), 'shape must be same'); + assert( + (*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), + 'shape must be same' + ); let mut output_data = ArrayTrait::new(); let mut data_indices = indices.data; @@ -54,31 +69,27 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_loop_first = *data_shape_copy.pop_front().unwrap(); let indices_loop_first = *indices_shape_copy.pop_front().unwrap(); - let mut indices_loop: usize = 1; - let mut data_loop:usize = 1; + let mut indices_loop: usize = 1; + let mut data_loop: usize = 1; if (axis == 0) { loop { match indices_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - indices_loop *= *val; + Option::Some(val) => { + let d = *val; + indices_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - loop { + loop { match data_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - data_loop *= *val; + Option::Some(val) => { + let d = *val; + data_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; } @@ -93,8 +104,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro axis = 2; transpose = true; } - - if (axis == (data_rank - 1) ){ + + if (axis == (data_rank - 1)) { data_loop = *data_shape_copy.pop_back().unwrap(); indices_loop = *indices_shape_copy.pop_back().unwrap(); } @@ -104,24 +115,26 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { let mut i: usize = 0; - let mut result:usize = 0; + let mut result: usize = 0; match data_indices.pop_front() { Option::Some(val) => { - let value = total_count+1; + let value = total_count + 1; if (axis == 0) { let column = total_count % indices_loop; result = (*val * data_loop) + (column); - if ((result % *data_shape.at(data_rank -1)) != total_count % *indices_shape.at(data_rank -1)){ - result += (*data_shape.at(data_rank -1) - *indices_shape.at(data_rank -1)); + if ((result % *data_shape.at(data_rank - 1)) != total_count % *indices_shape + .at(data_rank - 1)) { + result += + (*data_shape.at(data_rank - 1) - *indices_shape.at(data_rank - 1)); } } - if( axis == (data_rank - 1)) { + if (axis == (data_rank - 1)) { let mut row = total_count / indices_loop; - if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))){ - shift = ( *data_shape.at(1) - *indices_shape.at(1)); + if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))) { + shift = (*data_shape.at(1) - *indices_shape.at(1)); } result = *val + (data_loop * (row + shift)); @@ -129,8 +142,7 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'none') { indices_updates.insert(result.into(), value.into()); - } - else { + } else { let mut arr = ArrayTrait::new(); let val = indices_updates_reduction.get(result.into()); @@ -142,22 +154,17 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { match span.pop_front() { - Option::Some(val) => { - arr.append(*val); - }, - Option::None(_) => { - break; - } + Option::Some(val) => { arr.append(*val); }, + Option::None(_) => { break; } }; }; arr.append(total_count); - indices_updates_reduction.insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); + indices_updates_reduction + .insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); } total_count += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; @@ -170,13 +177,11 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let value = indices_updates.get(i.into()); if (value == 0) { output_data.append(*val); - } - else { - let data_value = data_updates[value-1]; + } else { + let data_value = data_updates[value - 1]; output_data.append(*data_value); } - } - else { + } else { let value = indices_updates_reduction.get(i.into()); let mut a = ArrayTrait::new(); let mut span = match match_nullable(value) { @@ -186,22 +191,15 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (span.len() == 0) { output_data.append(*val); - } - - else { + } else { // let mut result = *data_updates.at(*span.pop_front().unwrap()); let mut result = *val; - if (reduction == 'add') { loop { match span.pop_front() { - Option::Some(val) => { - result += *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result += *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -210,12 +208,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'mul') { loop { match span.pop_front() { - Option::Some(val) => { - result *= *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result *= *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -224,15 +218,13 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'max') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder > result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder > result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -241,27 +233,23 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'min') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder < result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder < result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); } } } - - i+=1; + + i += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/quantization/qlinear_add.cairo b/src/operators/tensor/quantization/qlinear_add.cairo index 7f9f3eaa1..1574e8fd8 100644 --- a/src/operators/tensor/quantization/qlinear_add.cairo +++ b/src/operators/tensor/quantization/qlinear_add.cairo @@ -8,8 +8,6 @@ use orion::operators::tensor::quantization::quantize_linear::quantize_linear; use orion::operators::tensor::{TensorTrait, Tensor}; - - fn qlinear_add< T, MAG, @@ -46,7 +44,6 @@ fn qlinear_add< min: T, max: T ) -> Tensor { - let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 941bfd8e2..b35601531 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -606,15 +606,15 @@ mod triu_u32_pos; mod triu_u32_square; mod triu_u32_square_neg; mod triu_u32_zero; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; diff --git a/tests/nodes/scatter_fp16x16_3d_axis1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1.cairo index ddd2ed77a..10838d6e7 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo index e450321a6..cfa417414 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 589824, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo index c8027a1a5..87045d082 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo index 47d99b23f..1b2e7a743 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 1048576, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default.cairo b/tests/nodes/scatter_fp16x16_3d_default.cairo index ebc06014d..06cfd4fdd 100644 --- a/tests/nodes/scatter_fp16x16_3d_default.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo index 9edd74528..fa9f6a8b6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1.cairo b/tests/nodes/scatter_fp8x23_axis1.cairo index 31ec2ea7c..ef903f3ad 100644 --- a/tests/nodes/scatter_fp8x23_axis1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo index 888cee255..46d23fbd5 100644 --- a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 75497472, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default.cairo b/tests/nodes/scatter_fp8x23_default.cairo index 66e5a6064..0ffd910b4 100644 --- a/tests/nodes/scatter_fp8x23_default.cairo +++ b/tests/nodes/scatter_fp8x23_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_0.cairo b/tests/nodes/scatter_fp8x23_default/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_default/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_1.cairo b/tests/nodes/scatter_fp8x23_default/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_default/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_2.cairo b/tests/nodes/scatter_fp8x23_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_default/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/output_0.cairo b/tests/nodes/scatter_fp8x23_default/output_0.cairo index 6c198c3af..c2011e04b 100644 --- a/tests/nodes/scatter_fp8x23_default/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul.cairo b/tests/nodes/scatter_fp8x23_mul.cairo index 8f6a9e5ae..dc90cfcbe 100644 --- a/tests/nodes/scatter_fp8x23_mul.cairo +++ b/tests/nodes/scatter_fp8x23_mul.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_mul() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('mul') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_0.cairo b/tests/nodes/scatter_fp8x23_mul/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_1.cairo b/tests/nodes/scatter_fp8x23_mul/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_2.cairo b/tests/nodes/scatter_fp8x23_mul/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/output_0.cairo b/tests/nodes/scatter_fp8x23_mul/output_0.cairo index 73c873293..b0b7353cc 100644 --- a/tests/nodes/scatter_fp8x23_mul/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1.cairo b/tests/nodes/scatter_i8_axis1.cairo index aeed6cea2..2374e89c5 100644 --- a/tests/nodes/scatter_i8_axis1.cairo +++ b/tests/nodes/scatter_i8_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_0.cairo b/tests/nodes/scatter_i8_axis1/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_1.cairo b/tests/nodes/scatter_i8_axis1/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_2.cairo b/tests/nodes/scatter_i8_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/output_0.cairo b/tests/nodes/scatter_i8_axis1/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max.cairo b/tests/nodes/scatter_i8_axis1_max.cairo index 0b1cc537c..b4d1a8799 100644 --- a/tests/nodes/scatter_i8_axis1_max.cairo +++ b/tests/nodes/scatter_i8_axis1_max.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1_max() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('max') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_0.cairo b/tests/nodes/scatter_i8_axis1_max/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_1.cairo b/tests/nodes/scatter_i8_axis1_max/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_2.cairo b/tests/nodes/scatter_i8_axis1_max/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/output_0.cairo b/tests/nodes/scatter_i8_axis1_max/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1_max/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default.cairo b/tests/nodes/scatter_i8_default.cairo index b0d10c89d..e28a0549c 100644 --- a/tests/nodes/scatter_i8_default.cairo +++ b/tests/nodes/scatter_i8_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_0.cairo b/tests/nodes/scatter_i8_default/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_default/input_0.cairo +++ b/tests/nodes/scatter_i8_default/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_1.cairo b/tests/nodes/scatter_i8_default/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_default/input_1.cairo +++ b/tests/nodes/scatter_i8_default/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_2.cairo b/tests/nodes/scatter_i8_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_default/input_2.cairo +++ b/tests/nodes/scatter_i8_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/output_0.cairo b/tests/nodes/scatter_i8_default/output_0.cairo index 9f1cf79dd..dfc02ca20 100644 --- a/tests/nodes/scatter_i8_default/output_0.cairo +++ b/tests/nodes/scatter_i8_default/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add.cairo b/tests/nodes/scatter_u32_add.cairo index 5c28a9394..3d1a8a0a9 100644 --- a/tests/nodes/scatter_u32_add.cairo +++ b/tests/nodes/scatter_u32_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_0.cairo b/tests/nodes/scatter_u32_add/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_add/input_0.cairo +++ b/tests/nodes/scatter_u32_add/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_1.cairo b/tests/nodes/scatter_u32_add/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_add/input_1.cairo +++ b/tests/nodes/scatter_u32_add/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_2.cairo b/tests/nodes/scatter_u32_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_add/input_2.cairo +++ b/tests/nodes/scatter_u32_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/output_0.cairo b/tests/nodes/scatter_u32_add/output_0.cairo index 924837c12..e892f73f8 100644 --- a/tests/nodes/scatter_u32_add/output_0.cairo +++ b/tests/nodes/scatter_u32_add/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1.cairo b/tests/nodes/scatter_u32_axis1.cairo index 784c28787..da79a252c 100644 --- a/tests/nodes/scatter_u32_axis1.cairo +++ b/tests/nodes/scatter_u32_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_0.cairo b/tests/nodes/scatter_u32_axis1/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_axis1/input_0.cairo +++ b/tests/nodes/scatter_u32_axis1/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_1.cairo b/tests/nodes/scatter_u32_axis1/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_axis1/input_1.cairo +++ b/tests/nodes/scatter_u32_axis1/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_2.cairo b/tests/nodes/scatter_u32_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_axis1/input_2.cairo +++ b/tests/nodes/scatter_u32_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/output_0.cairo b/tests/nodes/scatter_u32_axis1/output_0.cairo index 2a2d51eda..85db8a36f 100644 --- a/tests/nodes/scatter_u32_axis1/output_0.cairo +++ b/tests/nodes/scatter_u32_axis1/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(9); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default.cairo b/tests/nodes/scatter_u32_default.cairo index fd2607de7..5cf0e53d7 100644 --- a/tests/nodes/scatter_u32_default.cairo +++ b/tests/nodes/scatter_u32_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_0.cairo b/tests/nodes/scatter_u32_default/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_default/input_0.cairo +++ b/tests/nodes/scatter_u32_default/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_1.cairo b/tests/nodes/scatter_u32_default/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_default/input_1.cairo +++ b/tests/nodes/scatter_u32_default/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_2.cairo b/tests/nodes/scatter_u32_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_default/input_2.cairo +++ b/tests/nodes/scatter_u32_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/output_0.cairo b/tests/nodes/scatter_u32_default/output_0.cairo index 3bea6d3a7..09bc154f4 100644 --- a/tests/nodes/scatter_u32_default/output_0.cairo +++ b/tests/nodes/scatter_u32_default/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/operators/qlinear_add_test.cairo b/tests/operators/qlinear_add_test.cairo index 4c08a77ea..667d64411 100644 --- a/tests/operators/qlinear_add_test.cairo +++ b/tests/operators/qlinear_add_test.cairo @@ -5,7 +5,7 @@ use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tens use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; use orion::numbers::{NumberTrait, IntegerTrait}; use orion::numbers::{i8, i32}; - + #[test] #[available_gas(200000000000)] @@ -144,7 +144,7 @@ fn qlinearadd_broadcast_test() { #[test] #[available_gas(200000000000)] -fn test_example_doc() { +fn test_example_doc() { let a = TensorTrait::< i8 >::new( @@ -173,7 +173,9 @@ fn test_example_doc() { let a_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); let a_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); @@ -186,19 +188,19 @@ fn test_example_doc() { let y_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); let y_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, true)].span(),); let actual_output = a - .qlinear_add( - @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point - ); + .qlinear_add(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); assert((*actual_output.data[0]).into() == 1, '*result[0] == 1'); assert((*actual_output.data[1]).into() == 1, '*result[1] == 1'); assert((*actual_output.data[2]).into() == 1, '*result[2] == 1'); assert((*actual_output.data[3]).into() == 2, '*result[3] == 2'); assert((*actual_output.data[4]).into() == 2, '*result[4] == 2'); - assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); -} + assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); +} From f50f9f773fe8e25f40b6b84c857d43e7905fabfc Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 16:03:26 +0100 Subject: [PATCH 050/127] Refactor output tensor type and adjust tests --- nodegen/node/binarizer.py | 20 ++++--- src/operators/tensor/core.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 2 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- src/operators/tensor/math/binarizer.cairo | 10 ++-- tests/nodes/binarizer_fp16x16.cairo | 2 +- tests/nodes/binarizer_fp16x16/input_0.cairo | 54 ++++++++--------- tests/nodes/binarizer_fp16x16/output_0.cairo | 60 ++++++++++--------- tests/nodes/binarizer_fp8x23.cairo | 2 +- tests/nodes/binarizer_fp8x23/input_0.cairo | 54 ++++++++--------- tests/nodes/binarizer_fp8x23/output_0.cairo | 60 ++++++++++--------- tests/nodes/binarizer_i32.cairo | 2 +- tests/nodes/binarizer_i32/input_0.cairo | 28 ++++----- tests/nodes/binarizer_i32/output_0.cairo | 59 +++++++++--------- 21 files changed, 189 insertions(+), 182 deletions(-) diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py index 661fcf95a..f1a07d07a 100644 --- a/nodegen/node/binarizer.py +++ b/nodegen/node/binarizer.py @@ -8,11 +8,11 @@ class Binarizer(RunAll): @staticmethod def binarizer_i32(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) - threshold = 1 - y = (x > threshold).astype(np.uint32) + threshold = np.int32(1) + y = (x > threshold).astype(np.int32) x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "binarizer_i32" make_node([x], [y], name) @@ -22,12 +22,13 @@ def binarizer_i32(): @staticmethod def binarizer_fp8x23(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) - threshold = 1.0 - y = (x > threshold).astype(np.uint32) + threshold = np.float64(1) + y = (x > threshold).astype(np.float64) x = Tensor(Dtype.FP8x23, x.shape, to_fp( x.flatten(), FixedImpl.FP8x23)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) name = "binarizer_fp8x23" make_node([x], [y], name) @@ -37,12 +38,13 @@ def binarizer_fp8x23(): @staticmethod def binarizer_fp16x16(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) - threshold = 1.0 - y = (x > threshold).astype(np.uint32) + threshold = np.float64(1) + y = (x > threshold).astype(np.float64) x = Tensor(Dtype.FP16x16, x.shape, to_fp( x.flatten(), FixedImpl.FP16x16)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) name = "binarizer_fp16x16" make_node([x], [y], name) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 74c6485b0..92d93fcc8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,7 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; - fn binarizer(self: @Tensor, threshold: @T) -> Tensor; + fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 429e2cf8d..16c3d178a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,7 +288,7 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c9e5d9e61..5d7ac3908 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -287,7 +287,7 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index bd73890cc..8bd01a0e3 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -289,7 +289,7 @@ impl FP32x32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index fd3c8afc2..6c094b827 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,7 +289,7 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index c4db51e7f..01455b675 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -288,7 +288,7 @@ impl FP8x23Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 82ffe8c55..5a15a7cd2 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,7 +277,7 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 2accf79fb..dbfac85d5 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -288,7 +288,7 @@ impl I32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index cd7247aa9..65a0e5081 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -287,7 +287,7 @@ impl I8Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2fd0063f4..ed3903921 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -269,7 +269,7 @@ impl U32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index d28be43d0..697c4e293 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -9,23 +9,23 @@ use orion::numbers::NumberTrait; fn binarizer< T, MAG, - impl TTensor: TensorTrait, + impl TTensor: TensorTrait, impl TNumber: NumberTrait, impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( mut self: Tensor, threshold: @T -) -> Tensor { - let mut binarized_data: Array = ArrayTrait::new(); +) -> Tensor { + let mut binarized_data = ArrayTrait::::new(); loop { match self.data.pop_front() { Option::Some(item) => { if (*item) > (*threshold) { - binarized_data.append(1); + binarized_data.append(NumberTrait::one()); } else { - binarized_data.append(0); + binarized_data.append(NumberTrait::zero()); } }, Option::None(_) => { diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 258bfa8f1..5ddd92826 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::FixedTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo index 2aaa53e2b..597143f74 100644 --- a/tests/nodes/binarizer_fp16x16/input_0.cairo +++ b/tests/nodes/binarizer_fp16x16/input_0.cairo @@ -11,32 +11,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 146027, sign: true }); - data.append(FP16x16 { mag: 29998, sign: false }); - data.append(FP16x16 { mag: 79381, sign: true }); - data.append(FP16x16 { mag: 52502, sign: true }); - data.append(FP16x16 { mag: 141943, sign: true }); - data.append(FP16x16 { mag: 77493, sign: true }); - data.append(FP16x16 { mag: 143847, sign: true }); - data.append(FP16x16 { mag: 40577, sign: true }); - data.append(FP16x16 { mag: 15396, sign: false }); - data.append(FP16x16 { mag: 194266, sign: true }); - data.append(FP16x16 { mag: 73878, sign: true }); - data.append(FP16x16 { mag: 123262, sign: true }); - data.append(FP16x16 { mag: 106458, sign: false }); - data.append(FP16x16 { mag: 173856, sign: false }); - data.append(FP16x16 { mag: 80438, sign: true }); - data.append(FP16x16 { mag: 164829, sign: true }); - data.append(FP16x16 { mag: 89224, sign: true }); - data.append(FP16x16 { mag: 2691, sign: false }); - data.append(FP16x16 { mag: 181152, sign: true }); - data.append(FP16x16 { mag: 128977, sign: false }); - data.append(FP16x16 { mag: 78823, sign: true }); - data.append(FP16x16 { mag: 65209, sign: true }); - data.append(FP16x16 { mag: 56918, sign: false }); - data.append(FP16x16 { mag: 118799, sign: true }); - data.append(FP16x16 { mag: 179883, sign: false }); - data.append(FP16x16 { mag: 114165, sign: true }); - data.append(FP16x16 { mag: 142, sign: false }); + data.append(FP16x16 { mag: 116651, sign: true }); + data.append(FP16x16 { mag: 45255, sign: false }); + data.append(FP16x16 { mag: 132067, sign: true }); + data.append(FP16x16 { mag: 83631, sign: true }); + data.append(FP16x16 { mag: 151971, sign: false }); + data.append(FP16x16 { mag: 46816, sign: true }); + data.append(FP16x16 { mag: 4353, sign: false }); + data.append(FP16x16 { mag: 188531, sign: false }); + data.append(FP16x16 { mag: 104593, sign: false }); + data.append(FP16x16 { mag: 41997, sign: true }); + data.append(FP16x16 { mag: 127090, sign: false }); + data.append(FP16x16 { mag: 79053, sign: false }); + data.append(FP16x16 { mag: 139184, sign: true }); + data.append(FP16x16 { mag: 439, sign: false }); + data.append(FP16x16 { mag: 115688, sign: false }); + data.append(FP16x16 { mag: 184428, sign: true }); + data.append(FP16x16 { mag: 161855, sign: true }); + data.append(FP16x16 { mag: 42551, sign: true }); + data.append(FP16x16 { mag: 40207, sign: false }); + data.append(FP16x16 { mag: 72062, sign: false }); + data.append(FP16x16 { mag: 195673, sign: false }); + data.append(FP16x16 { mag: 27413, sign: true }); + data.append(FP16x16 { mag: 173891, sign: true }); + data.append(FP16x16 { mag: 69697, sign: true }); + data.append(FP16x16 { mag: 162632, sign: false }); + data.append(FP16x16 { mag: 53852, sign: true }); + data.append(FP16x16 { mag: 93775, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo index 9499a7848..b4bbbde98 100644 --- a/tests/nodes/binarizer_fp16x16/output_0.cairo +++ b/tests/nodes/binarizer_fp16x16/output_0.cairo @@ -1,40 +1,42 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(3); shape.append(3); 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(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(1); - 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(0); - data.append(1); - data.append(0); - data.append(0); + 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: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, 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: 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: 65536, 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: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 4de3cbb7d..62d6f3ee4 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::FixedTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo index 39d12c3be..e11d8a9f4 100644 --- a/tests/nodes/binarizer_fp8x23/input_0.cairo +++ b/tests/nodes/binarizer_fp8x23/input_0.cairo @@ -11,32 +11,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 7205493, sign: true }); - data.append(FP8x23 { mag: 14503128, sign: false }); - data.append(FP8x23 { mag: 9682839, sign: false }); - data.append(FP8x23 { mag: 25030485, sign: false }); - data.append(FP8x23 { mag: 3669115, sign: true }); - data.append(FP8x23 { mag: 16376632, sign: true }); - data.append(FP8x23 { mag: 4670619, sign: false }); - data.append(FP8x23 { mag: 24976405, sign: true }); - data.append(FP8x23 { mag: 19811890, sign: false }); - data.append(FP8x23 { mag: 10781071, sign: true }); - data.append(FP8x23 { mag: 10216945, sign: false }); - data.append(FP8x23 { mag: 25004285, sign: false }); - data.append(FP8x23 { mag: 7482592, sign: false }); - data.append(FP8x23 { mag: 1360, sign: true }); - data.append(FP8x23 { mag: 10632602, sign: true }); - data.append(FP8x23 { mag: 275175, sign: true }); - data.append(FP8x23 { mag: 21731586, sign: true }); - data.append(FP8x23 { mag: 5638921, sign: true }); - data.append(FP8x23 { mag: 6096613, sign: false }); - data.append(FP8x23 { mag: 22105612, sign: false }); - data.append(FP8x23 { mag: 17084000, sign: true }); - data.append(FP8x23 { mag: 12627954, sign: true }); - data.append(FP8x23 { mag: 23194838, sign: false }); - data.append(FP8x23 { mag: 9012947, sign: false }); - data.append(FP8x23 { mag: 5163417, sign: true }); - data.append(FP8x23 { mag: 13580853, sign: false }); - data.append(FP8x23 { mag: 5624227, sign: false }); + data.append(FP8x23 { mag: 19910639, sign: true }); + data.append(FP8x23 { mag: 16200109, sign: false }); + data.append(FP8x23 { mag: 7318221, sign: false }); + data.append(FP8x23 { mag: 3839710, sign: true }); + data.append(FP8x23 { mag: 5198439, sign: true }); + data.append(FP8x23 { mag: 13440550, sign: false }); + data.append(FP8x23 { mag: 3475736, sign: false }); + data.append(FP8x23 { mag: 12659448, sign: false }); + data.append(FP8x23 { mag: 22040361, sign: true }); + data.append(FP8x23 { mag: 16960032, sign: true }); + data.append(FP8x23 { mag: 20980250, sign: false }); + data.append(FP8x23 { mag: 19528339, sign: true }); + data.append(FP8x23 { mag: 24567413, sign: true }); + data.append(FP8x23 { mag: 3374986, sign: true }); + data.append(FP8x23 { mag: 5428617, sign: false }); + data.append(FP8x23 { mag: 16499249, sign: true }); + data.append(FP8x23 { mag: 14111693, sign: false }); + data.append(FP8x23 { mag: 22806062, sign: false }); + data.append(FP8x23 { mag: 5020958, sign: false }); + data.append(FP8x23 { mag: 20749322, sign: false }); + data.append(FP8x23 { mag: 7503709, sign: true }); + data.append(FP8x23 { mag: 24435895, sign: false }); + data.append(FP8x23 { mag: 12933406, sign: true }); + data.append(FP8x23 { mag: 11401085, sign: true }); + data.append(FP8x23 { mag: 97331, sign: false }); + data.append(FP8x23 { mag: 21216642, sign: true }); + data.append(FP8x23 { mag: 2018862, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo index d5317e309..8ec654745 100644 --- a/tests/nodes/binarizer_fp8x23/output_0.cairo +++ b/tests/nodes/binarizer_fp8x23/output_0.cairo @@ -1,40 +1,42 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(3); shape.append(3); shape.append(3); let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(1); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - 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(1); - data.append(1); - data.append(0); - data.append(1); - data.append(0); + data.append(FP8x23 { mag: 0, sign: false }); + 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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + 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 }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + 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: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo index dc82a3bd1..7793b74ae 100644 --- a/tests/nodes/binarizer_i32.cairo +++ b/tests/nodes/binarizer_i32.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::IntegerTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::I32TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo index f4e25323a..3059b3649 100644 --- a/tests/nodes/binarizer_i32/input_0.cairo +++ b/tests/nodes/binarizer_i32/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo index 23163214e..3adef88e2 100644 --- a/tests/nodes/binarizer_i32/output_0.cairo +++ b/tests/nodes/binarizer_i32/output_0.cairo @@ -1,40 +1,41 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(3); shape.append(3); shape.append(3); let mut data = ArrayTrait::new(); - data.append(0); - data.append(0); - data.append(1); - 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(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(1); - data.append(0); - data.append(0); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From 6cebe286db4bd84a70d217b05c577c9342152f3c Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 16:38:12 +0100 Subject: [PATCH 051/127] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.binarizer.md | 44 ++++++++++++++++++ src/operators/tensor/core.cairo | 46 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.binarizer.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f96dd7a6f..c24d92ce5 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -95,6 +95,7 @@ * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + * [tensor.binarizer](framework/operators/tensor/tensor.binarizer.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 e5f7f39cf..28b2624df 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,5 +74,6 @@ You can see below the list of current supported ONNX Operators: | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | | [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [Binarizer](operators/tensor/tensor.binarizer.md) | :white\_check\_mark: | -Current Operators support: **68/156 (43%)** +Current Operators support: **69/156 (44%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 369713044..42282fb8f 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -91,6 +91,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | +| [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md new file mode 100644 index 000000000..14cac3d65 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -0,0 +1,44 @@ +# tensor.binarizer + +```rust + fn binarizer(self: @Tensor, threshold: @T) -> Tensor +``` + +Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + +## Args +* `self`(`@Tensor`) - The input tensor to be binarized. +* `threshold`(`@T`) - The threshold for the binarization operation. + +## Returns +A new `Tensor` of the same shape as the input tensor with binarized values. + +## Type Constraints + +Constrain input and output types to fixed point and int32 tensors. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn binarizer_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::new(1, true), + IntegerTrait::new(0, false), + IntegerTrait::new(1, false), + IntegerTrait::new(2, false), + ] + .span(), + ); + let threshold = IntegerTrait::::new(1, false) + + return tensor.binarizer(@tensor, @threshold); +} +>>> [0, 0, 0, 1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 92d93fcc8..c1d1271bb 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -87,6 +87,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3212,6 +3213,51 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// # tensor.binarizer + /// + /// ```rust + /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor + /// ``` + /// + /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be binarized. + /// * `threshold`(`@T`) - The threshold for the binarization operation. + /// + /// ## Returns + /// A new `Tensor` of the same shape as the input tensor with binarized values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point and int32 tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn binarizer_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::new(1, true), + /// IntegerTrait::new(0, false), + /// IntegerTrait::new(1, false), + /// IntegerTrait::new(2, false), + /// ] + /// .span(), + /// ); + /// let threshold = IntegerTrait::::new(1, false) + /// + /// return tensor.binarizer(@tensor, @threshold); + /// } + /// >>> [0, 0, 0, 1] + /// ``` + /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } From 4d2a52a4f1851447feb9dedbc30b4de51712a54e Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Wed, 8 Nov 2023 17:04:47 +0100 Subject: [PATCH 052/127] Feat: Bool Tensor Type with Tests --- src/operators/tensor.cairo | 4 + src/operators/tensor/implementations.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 60 ++++++----- tests/tensor_core/at/at_bool_test.cairo | 84 ++++++++++++++- tests/tensor_core/stride.cairo | 1 + .../tensor_core/stride/stride_bool_test.cairo | 102 ++++++++++++++++++ 6 files changed, 224 insertions(+), 28 deletions(-) create mode 100644 tests/tensor_core/stride/stride_bool_test.cairo diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 976102b52..e5b767975 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -30,3 +30,7 @@ use orion::operators::tensor::implementations::tensor_u32::{ U32Tensor, U32TensorAdd, U32TensorSub, U32TensorMul, U32TensorDiv, U32TensorPartialEq }; +use orion::operators::tensor::implementations::tensor_bool::{ + BoolTensor +}; + diff --git a/src/operators/tensor/implementations.cairo b/src/operators/tensor/implementations.cairo index 61dd41674..61ee08dd3 100644 --- a/src/operators/tensor/implementations.cairo +++ b/src/operators/tensor/implementations.cairo @@ -1,3 +1,4 @@ +mod tensor_bool; mod tensor_u32; mod tensor_i8; mod tensor_i32; diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index e9d830947..5b0ee08b9 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -8,7 +8,7 @@ use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; use orion::operators::tensor::{math, linalg, quantization, core}; -use orion::numbers::{bool, i32, NumberTrait}; +use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; impl BoolTensor of TensorTrait { @@ -21,11 +21,11 @@ impl BoolTensor of TensorTrait { } fn min(self: @Tensor) -> bool { - math::min::min_in_tensor::(*self.data) + panic(array!['not supported!']) } fn max(self: @Tensor) -> bool { - math::max::max_in_tensor(*self.data) + panic(array!['not supported!']) } fn stride(self: @Tensor) -> Span { @@ -45,19 +45,19 @@ impl BoolTensor of TensorTrait { } fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + panic(array!['not supported!']) } fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { - math::argmax::argmax(self, axis, keepdims, select_last_index) + panic(array!['not supported!']) } fn argmin( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { - math::argmin::argmin(self, axis, keepdims, select_last_index) + panic(array!['not supported!']) } fn transpose(self: @Tensor, axes: Span) -> Tensor { @@ -65,7 +65,7 @@ impl BoolTensor of TensorTrait { } fn matmul(self: @Tensor, other: @Tensor) -> Tensor { - linalg::matmul::matmul(self, other) + panic(array!['not supported!']) } fn exp(self: @Tensor) -> Tensor { @@ -81,23 +81,23 @@ impl BoolTensor of TensorTrait { } fn greater(self: @Tensor, other: @Tensor) -> Tensor { - math::greater::greater(self, other) + panic(array!['not supported!']) } fn greater_equal(self: @Tensor, other: @Tensor) -> Tensor { - math::greater_equal::greater_equal(self, other) + panic(array!['not supported!']) } fn less(self: @Tensor, other: @Tensor) -> Tensor { - math::less::less(self, other) + panic(array!['not supported!']) } fn less_equal(self: @Tensor, other: @Tensor) -> Tensor { - math::less_equal::less_equal(self, other) + panic(array!['not supported!']) } fn abs(self: @Tensor) -> Tensor { - math::abs::abs(*self) + panic(array!['not supported!']) } fn ceil(self: @Tensor) -> Tensor { @@ -123,7 +123,7 @@ impl BoolTensor of TensorTrait { } fn flatten(self: @Tensor, axis: usize) -> Tensor { - math::flatten::flatten(self, axis) + panic(array!['not supported!']) } fn sinh(self: @Tensor) -> Tensor { @@ -151,11 +151,11 @@ impl BoolTensor of TensorTrait { } fn xor(self: @Tensor, other: @Tensor) -> Tensor { - math::xor::xor(self, other) + panic(array!['not supported!']) } fn or(self: @Tensor, other: @Tensor) -> Tensor { - math::or::or(self, other) + panic(array!['not supported!']) } fn acos(self: @Tensor) -> Tensor { @@ -178,20 +178,14 @@ impl BoolTensor of TensorTrait { fn quantize_linear( self: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor - ) -> Tensor:: { - quantization::quantize_linear::quantize_linear( - self, - y_scale, - y_zero_point, - NumberTrait::new_unscaled(128, true), - NumberTrait::new_unscaled(127, false) - ) + ) -> Tensor:: { + panic(array!['not supported!']) } fn dequantize_linear( - self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor + self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor ) -> Tensor:: { - quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) + panic(array!['not supported!']) } fn slice( @@ -227,6 +221,22 @@ impl BoolTensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { panic(array!['not supported!']) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn identity(self: @Tensor) -> Tensor { + core::identity(self) + } + + fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn neg(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/tests/tensor_core/at/at_bool_test.cairo b/tests/tensor_core/at/at_bool_test.cairo index 78c7c10f9..12625c027 100644 --- a/tests/tensor_core/at/at_bool_test.cairo +++ b/tests/tensor_core/at/at_bool_test.cairo @@ -3,7 +3,7 @@ #[cfg(test)] mod tensor_1D { use array::ArrayTrait; - use orion::operators::tensor::BoolTensor; + use orion::operators::tensor::{BoolTensor}; use orion::operators::tensor::core::{TensorTrait}; @@ -24,8 +24,86 @@ mod tensor_1D { let mut indices = ArrayTrait::new(); indices.append(1); - let result = tensor.at(indices.span()).mag; + let result = tensor.at(indices.span()); assert(result == true, 'result[2] = true'); } -} \ No newline at end of file +} + + +// ===== 2D ===== // + +#[cfg(test)] +mod tensor_2D { + use array::ArrayTrait; + use orion::operators::tensor::{BoolTensor}; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + + let mut indices = ArrayTrait::new(); + indices.append(1); + indices.append(1); + + let result = tensor.at(indices.span()); + + assert(result == true, 'result[4] = true'); + } +} + +// ===== 3D ===== // + +#[cfg(test)] +mod tensor_3D { + use array::ArrayTrait; + use orion::operators::tensor::{BoolTensor}; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + + let mut indices = ArrayTrait::new(); + indices.append(0); + indices.append(1); + indices.append(1); + + let result = tensor.at(indices.span()); + + assert(result == true, 'result[3] = true'); + } +} diff --git a/tests/tensor_core/stride.cairo b/tests/tensor_core/stride.cairo index 7c475bc3b..d8c67056b 100644 --- a/tests/tensor_core/stride.cairo +++ b/tests/tensor_core/stride.cairo @@ -1,3 +1,4 @@ mod stride_u32_test; mod stride_i32_test; +mod stride_bool_test; mod stride_fp_test; diff --git a/tests/tensor_core/stride/stride_bool_test.cairo b/tests/tensor_core/stride/stride_bool_test.cairo new file mode 100644 index 000000000..314e97f7b --- /dev/null +++ b/tests/tensor_core/stride/stride_bool_test.cairo @@ -0,0 +1,102 @@ +// ===== 1D ===== // + +#[cfg(test)] +mod tensor_1D { + use array::ArrayTrait; + use orion::operators::tensor::{BoolTensor}; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(true); + data.append(false); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + + let result = tensor.stride(); + + assert(*result[0] == 1, 'stride x = 1'); + assert(result.len() == 1, 'len = 1'); + } +} + + +// ===== 2D ===== // + +#[cfg(test)] +mod tensor_2D { + use array::ArrayTrait; + use orion::operators::tensor::{BoolTensor}; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + + let result = tensor.stride(); + + assert(*result[0] == 2, 'stride x = 2'); + assert(*result[1] == 1, 'stride y = 1'); + assert(result.len() == 2, 'len = 2'); + } +} + +// ===== 3D ===== // + +#[cfg(test)] +mod tensor_3D { + use array::ArrayTrait; + use orion::operators::tensor::{BoolTensor}; + use orion::operators::tensor::core::{TensorTrait}; + + + #[test] + #[available_gas(2000000)] + fn tensor_at() { + + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + let result = tensor.stride(); + + assert(*result[0] == 4, 'stride x = 4'); + assert(*result[1] == 2, 'stride y = 2'); + assert(*result[2] == 1, 'stride z = 1'); + assert(result.len() == 3, 'len = 3'); + } +} From fea70ecb93e3aa0c916a7093d534fa2781c7c68a Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Wed, 8 Nov 2023 14:53:31 -0600 Subject: [PATCH 053/127] fix: incorrect type issue with softmax --- docs/framework/operators/neural-network/nn.softmax.md | 10 +++++----- src/operators/nn/core.cairo | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/framework/operators/neural-network/nn.softmax.md b/docs/framework/operators/neural-network/nn.softmax.md index 13717bdb3..6b1b0c982 100644 --- a/docs/framework/operators/neural-network/nn.softmax.md +++ b/docs/framework/operators/neural-network/nn.softmax.md @@ -28,7 +28,7 @@ Constrain input and output types to fixed point tensors. ```rust use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor, FP8x23}; +use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; use orion::operators::nn::{NNTrait, FP8x23NN}; use orion::numbers::{FP8x23, FixedTrait}; @@ -36,10 +36,10 @@ fn softmax_example() -> Tensor { let tensor = TensorTrait::::new( shape: array![2, 2].span(), data: array![ - NNTrait::new(0, false), - NNTrait::new(1, false), - NNTrait::new(2, false), - NNTrait::new(3, false), + FixedTrait::new(0, false), + FixedTrait::new(1, false), + FixedTrait::new(2, false), + FixedTrait::new(3, false), ] .span(), ); diff --git a/src/operators/nn/core.cairo b/src/operators/nn/core.cairo index c0e391dd2..69531746e 100644 --- a/src/operators/nn/core.cairo +++ b/src/operators/nn/core.cairo @@ -91,7 +91,7 @@ trait NNTrait { /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// - /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23}; + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; /// use orion::operators::nn::{NNTrait, FP8x23NN}; /// use orion::numbers::{FP8x23, FixedTrait}; /// @@ -99,10 +99,10 @@ trait NNTrait { /// let tensor = TensorTrait::::new( /// shape: array![2, 2].span(), /// data: array![ - /// NNTrait::new(0, false), - /// NNTrait::new(1, false), - /// NNTrait::new(2, false), - /// NNTrait::new(3, false), + /// FixedTrait::new(0, false), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false), + /// FixedTrait::new(3, false), /// ] /// .span(), /// ); From d6c8fd263ddfe7b1d6c1a770075d585fbd439b55 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 9 Nov 2023 13:25:49 +0200 Subject: [PATCH 054/127] implement other version --- src/operators/matrix.cairo | 102 ++++++++- src/operators/ml/tree_ensemble.cairo | 3 +- src/operators/ml/tree_ensemble/core.cairo | 2 +- .../tree_ensemble_classifier.cairo | 4 +- .../tree_ensemble_classifier2.cairo | 197 ++++++++++++++++++ src/utils.cairo | 6 +- tests/ml/tree_ensemble_classifier.cairo | 15 +- 7 files changed, 314 insertions(+), 15 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 4baec91af..5f49c2b7e 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,5 +1,9 @@ +use core::array::ArrayTrait; +use core::option::OptionTrait; use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; +use orion::numbers::NumberTrait; + impl VecCopy of Copy>; impl NullCopy of Copy>>; impl VecDrop of Drop>; @@ -13,13 +17,15 @@ struct MutMatrix { } #[generate_trait] -impl MutMatrixImpl, +Copy> of MutMatrixTrait { - // Constructor for the Matrix +impl MutMatrixImpl< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd +> of MutMatrixTrait { + /// Constructor for the Matrix fn new(rows: usize, cols: usize) -> MutMatrix { MutMatrix { data: NullableVecImpl::new(), rows: rows, cols: cols } } - // Get the value at (row, col) + /// Get the value at (row, col) fn get(ref self: MutMatrix, row: usize, col: usize) -> Option { if row >= self.rows || col >= self.cols { Option::None @@ -28,7 +34,7 @@ impl MutMatrixImpl, +Copy> of MutMatrixTrait { } } - // Set the value at (row, col) + /// Set the value at (row, col) fn set(ref self: MutMatrix, row: usize, col: usize, value: T) { if row < self.rows && col < self.cols { let index = row * self.cols + col; @@ -36,8 +42,94 @@ impl MutMatrixImpl, +Copy> of MutMatrixTrait { } } - // Returns the shape of the matrix as (rows, cols) + /// Returns the shape of the matrix as (rows, cols) fn shape(self: MutMatrix) -> (usize, usize) { (self.rows, self.cols) } + + /// Returns the index of the maximum value along the specified axis + fn argmax(ref self: MutMatrix, axis: usize) -> Span { + assert(axis < 2, 'Invalid axis'); + + let mut result: Array = ArrayTrait::new(); + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut max_value = self.get(0, col); + let mut max_value = match max_value { + Option::Some => { max_value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + let mut max_index = 0; + + let mut row: usize = 1; + loop { + if row == self.rows { + break; + } + + let mut value = self.get(row, col); + let mut value = match value { + Option::Some => { value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + if value > max_value { + max_value = value; + max_index = row; + } + + row += 1; + }; + + result.append(max_index); + + col += 1; + }; + + return result.span(); + } + + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut max_value = self.get(row, 0); + let mut max_value = match max_value { + Option::Some => { max_value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + let mut max_index = 0; + + let mut col: usize = 1; + loop { + if col == self.cols { + break; + } + + let mut value = self.get(row, col); + let mut value = match value { + Option::Some => { value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + if value > max_value { + max_value = value; + max_index = col; + } + + col += 1; + }; + + result.append(max_index); + + row += 1; + }; + + return result.span(); + } } diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 0f09fa8d1..32177e813 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,2 +1,3 @@ mod core; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; +mod tree_ensemble_classifier2; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index cd8992eb9..a54295822 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -101,7 +101,7 @@ impl TreeEnsembleImpl< break; } - let row_data: Span = get_row(x, i); + let row_data: Span = get_row(@x, i); let mut outs = ArrayTrait::new(); let mut tree_ids = self.tree_ids; loop { diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 10523ab11..4d7723d8e 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,4 @@ +use core::array::SpanTrait; use core::nullable::NullableTrait; use core::dict::Felt252DictTrait; use core::dict::Felt252DictEntryTrait; @@ -46,6 +47,7 @@ impl TreeEnsembleClassifierImpl< +Add, +TensorTrait, +TensorTrait, + +PrintTrait > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -57,7 +59,7 @@ impl TreeEnsembleClassifierImpl< } -fn compute_scores, +Copy, +NumberTrait, +Add,>( +fn compute_scores, +Copy, +NumberTrait, +Add, +PrintTrait>( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { // Initialize the scores array, either with base_values or zeros diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo new file mode 100644 index 000000000..cc6b5f4a0 --- /dev/null +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo @@ -0,0 +1,197 @@ +use core::array::ArrayTrait; +use core::clone::Clone; +use core::box::BoxTrait; +use core::traits::Into; +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; +use core::array::SpanTrait; +use core::nullable::NullableTrait; +use core::dict::Felt252DictTrait; +use core::dict::Felt252DictEntryTrait; +use nullable::{match_nullable, FromNullableResult}; + +use orion::operators::tensor::{Tensor, TensorTrait}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; +use orion::numbers::NumberTrait; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + +use debug::PrintTrait; + +#[derive(Destruct)] +struct TreeEnsembleClassifier { + ensemble: TreeEnsemble, + class_ids: Span, + class_nodeids: Span, + class_treeids: Span, + class_weights: Span, + classlabels: Span, + base_values: Option>, + post_transform: PostTransform, +} + +#[derive(Copy, Drop)] +enum PostTransform { + None, + Softmax, + Logistic, + SoftmaxZero, + Probit, +} + +#[generate_trait] +impl TreeEnsembleClassifierImpl< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +PrintTrait +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { + let leaves_index = self.ensemble.leave_index_tree(X); + let n_classes = self.classlabels.len(); + let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); + + // Set base values + if self.base_values.is_some() { + let mut base_values = self.base_values.unwrap(); + let mut row: usize = 0; + loop { + if row == res.rows { + break; + } + + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } + + let value = *base_values.pop_front().unwrap(); + res.set(row, col, value); + + col += 1 + }; + + row += 1; + } + } + + let mut class_index: Felt252Dict>> = Default::default(); + let mut i: usize = 0; + loop { + if i == self.class_treeids.len() { + break; + } + + let tid = *self.class_treeids[i]; + let nid = *self.class_nodeids[i]; + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tid.into(), nid.into()); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { continue; }, + FromNullableResult::NotNull(val) => { + let mut new_val = val.unbox(); + let new_val = new_val.concat(array![i].span()); + class_index.insert(key, NullableTrait::new(new_val)); + }, + } + + i += 1; + }; + let mut i: usize = 0; + loop { + if i == res.rows { + break; + } + + let mut indices = get_row(@leaves_index, i); + let mut t_index: Array> = ArrayTrait::new(); + loop { + match indices.pop_front() { + Option::Some(index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*index]).into(), + (*self.ensemble.atts.nodes_treeids[*index]).into() + ); + t_index.append(class_index.get(key).deref()); + }, + Option::None(_) => { break; } + }; + }; + let mut t_index = t_index.span(); + loop { + match t_index.pop_front() { + Option::Some(its) => { + loop { + let mut its = *its; + match its.pop_front() { + Option::Some(it) => { + let prev_val = res.get(i, *self.class_ids[*it]); + match prev_val { + Option::Some(prev) => { + res + .set( + i, + *self.class_ids[*it], + prev + *self.class_weights[*it] + ); + }, + Option::None => { + res + .set( + i, + *self.class_ids[*it], + *self.class_weights[*it] + ); + } + } + }, + Option::None(_) => { break; } + }; + }; + }, + Option::None(_) => { break; } + }; + }; + i += 1; + }; + + // TODO: Binary case + + // Post Transform + let mut new_scores = match self.post_transform { + PostTransform::None => { res }, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + }; + + // Labels + let mut labels = new_scores.argmax(1); + let mut labels_list = ArrayTrait::new(); + loop { + match labels.pop_front() { + Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, + Option::None(_) => { break; } + }; + }; + + return (labels, new_scores); + } +} + diff --git a/src/utils.cairo b/src/utils.cairo index ab48c3d7d..2e66a093d 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -31,11 +31,11 @@ fn assert_eq, impl TCopy: Copy, impl TDrop: assert(lhs == rhs, 'should be equal'); } -fn get_row, +Copy>(self: Tensor, row: usize) -> Span { - assert(self.shape.len() == 2, 'Expected a 2D tensor'); +fn get_row, +Copy>(self: @Tensor, row: usize) -> Span { + assert((*self).shape.len() == 2, 'Expected a 2D tensor'); let row_length = *self.shape[1]; let start = row * row_length; - self.data.slice(start, row_length) + (*self).data.slice(start, row_length) } diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 66a8f44a4..c5b24601a 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,13 +1,16 @@ +use core::array::SpanTrait; use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier2::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; +use debug::PrintTrait; + #[test] #[available_gas(2000000000)] fn test_tree_ensemble_classifier_multi() { @@ -42,7 +45,7 @@ fn test_tree_ensemble_classifier_multi() { ] .span(); - let class_labels: Span = array![0, 1, 2].span(); + let classlabels: Span = array![0, 1, 2].span(); let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); @@ -137,7 +140,7 @@ fn test_tree_ensemble_classifier_multi() { class_nodeids, class_treeids, class_weights, - class_labels, + classlabels, base_values, post_transform }; @@ -158,6 +161,10 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - TreeEnsembleClassifierTrait::predict(ref classifier, X); + let (prediction, score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // (*score.data.at(0)).print(); + // (*score.data.at(1)).print(); + // (*score.data.at(2)).print(); } From 58c7b36f7f285dc7b9297da3711e4aded50b293b Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Thu, 9 Nov 2023 12:27:38 +0100 Subject: [PATCH 055/127] add file_manager --- nodegen/file_manager.py | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 nodegen/file_manager.py diff --git a/nodegen/file_manager.py b/nodegen/file_manager.py new file mode 100644 index 000000000..aaa4e189d --- /dev/null +++ b/nodegen/file_manager.py @@ -0,0 +1,79 @@ +import os +from pathlib import Path + + +PATH = "./tests/nodes" + + +class File: + def __init__(self, path: str, empty_buffer: bool = False): + self.path = Path(path) + self.path.parent.mkdir(parents=True, exist_ok=True) + self.buffer = [] + + if empty_buffer: + return + + if os.path.isfile(path): + with self.path.open('r') as f: + self.buffer = f.readlines() + + def dump(self): + with self.path.open('w') as f: + f.writelines([f"{line}\n" for line in self.buffer]) + + +class Mod(File): + def __init__(self): + super().__init__(path=f"{PATH}.cairo") + + def update(self, name: str): + statement = f"mod {name};" + if statement not in self.buffer: + self.buffer.append(statement) + + +class Test(File): + def __init__(self, file: str): + super().__init__(os.path.join(PATH, file), empty_buffer=True) + + @classmethod + def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + return [ + *[f"mod input_{i};" for i in range(arg_cnt)], + *[ "mod output_0;"], + *[ ""], + *[ ""], + *[f"use {ref};" for ref in refs], + *[ ""], + *[ "#[test]"], + *[ "#[available_gas(2000000000)]"], + *[f"fn test_{name}()"+" {"], + *[f" let input_{i} = input_{i}::input_{i}();" for i in range(arg_cnt)], + *[ " let z = output_0::output_0();"], + *[ ""], + *[f" let y = {func_sig};"], + *[ ""], + *[ " assert_eq(y, z);"], + *[ "}"], + ] + + +class Data(File): + def __init__(self, file: str): + super().__init__(os.path.join(PATH, file), empty_buffer=True) + + @classmethod + def template(cls, func: str, dtype: str, refs: list[str], data: list[str], shape: tuple) -> list[str]: + return [ + *[f"use {ref};" for ref in refs], + *[ ""], + *[f"fn {func}() -> Tensor<{dtype}>"+" {"], + *[ " let mut shape = ArrayTrait::::new();"], + *[f" shape.append({s});" for s in shape], + *[ ""], + *[ " let mut data = ArrayTrait::new();"], + *[f" data.append({d});" for d in data], + *[ " TensorTrait::new(shape.span(), data.span())"], + *[ "}"], + ] From db4ef23178846b4fc25dced6fedf85e2cc1ab1cf Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Thu, 9 Nov 2023 15:27:56 +0100 Subject: [PATCH 056/127] restructure helpers.py --- nodegen/helpers.py | 363 +++++++++++-------------------- nodegen/node/abs.py | 6 +- nodegen/node/acos.py | 4 +- nodegen/node/acosh.py | 4 +- nodegen/node/add.py | 12 +- nodegen/node/and.py | 12 +- nodegen/node/argmax.py | 47 +--- nodegen/node/argmin.py | 47 +--- nodegen/node/asin.py | 4 +- nodegen/node/asinh.py | 4 +- nodegen/node/atan.py | 4 +- nodegen/node/ceil.py | 12 +- nodegen/node/clip.py | 12 +- nodegen/node/concat.py | 137 +++++------- nodegen/node/cos.py | 4 +- nodegen/node/cosh.py | 4 +- nodegen/node/cumsum.py | 32 +-- nodegen/node/div.py | 12 +- nodegen/node/equal.py | 12 +- nodegen/node/exp.py | 4 +- nodegen/node/gather.py | 49 ++--- nodegen/node/gemm.py | 10 +- nodegen/node/greater.py | 12 +- nodegen/node/greater_equal.py | 12 +- nodegen/node/hard_sigmoid.py | 4 +- nodegen/node/identity.py | 9 +- nodegen/node/leaky_relu.py | 4 +- nodegen/node/less.py | 12 +- nodegen/node/less_equal.py | 12 +- nodegen/node/linear.py | 7 +- nodegen/node/log.py | 4 +- nodegen/node/logsoftmax.py | 6 +- nodegen/node/matmul.py | 22 +- nodegen/node/max.py | 64 ++---- nodegen/node/min.py | 62 ++---- nodegen/node/mul.py | 12 +- nodegen/node/neg.py | 6 +- nodegen/node/nonzero.py | 12 +- nodegen/node/or.py | 12 +- nodegen/node/reduce_sum.py | 22 +- nodegen/node/relu.py | 8 +- nodegen/node/round.py | 6 +- nodegen/node/scatter.py | 50 ++--- nodegen/node/sigmoid.py | 4 +- nodegen/node/sign.py | 9 +- nodegen/node/sin.py | 4 +- nodegen/node/sinh.py | 4 +- nodegen/node/slice.py | 12 +- nodegen/node/softmax.py | 4 +- nodegen/node/softplus.py | 4 +- nodegen/node/softsign.py | 4 +- nodegen/node/sqrt.py | 4 +- nodegen/node/squeeze.py | 9 +- nodegen/node/sub.py | 12 +- nodegen/node/tanh.py | 4 +- nodegen/node/thresholded_relu.py | 4 +- nodegen/node/transpose.py | 12 +- nodegen/node/unsqueeze.py | 12 +- nodegen/node/where.py | 12 +- nodegen/node/xor.py | 12 +- 60 files changed, 312 insertions(+), 967 deletions(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 848a18879..5970582c6 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -1,32 +1,34 @@ from enum import Enum import os -import re -import numpy as np - - -__PATH = "/tests/nodes" +from .file_manager import Test, Data, Mod -###################### -# DATA STRUCTURES -###################### +import numpy as np -class Dtype(Enum): +class FixedImpl(Enum): FP8x23 = 'FP8x23' FP16x16 = 'FP16x16' - I8 = 'I8' - I32 = 'I32' - U32 = 'U32' -class FixedImpl(Enum): +def to_fp(x: np.ndarray, fp_impl: FixedImpl): + match fp_impl: + case FixedImpl.FP8x23: + return (x * 2**23).astype(np.int64) + case FixedImpl.FP16x16: + return (x * 2**16).astype(np.int64) + + +class Dtype(Enum): FP8x23 = 'FP8x23' FP16x16 = 'FP16x16' + I8 = 'i8' + I32 = 'i32' + U32 = 'u32' class Tensor: - def __init__(self, dtype: Dtype, shape: [], data: []): + def __init__(self, dtype: Dtype, shape: tuple, data: np.ndarray): self.dtype = dtype self.shape = shape self.data = data @@ -36,247 +38,132 @@ class Trait(Enum): TENSOR = 'TENSOR' NN = 'NN' -################ -# EXTERNALS -################ - - -def make_node(inputs: [Tensor], outputs: [Tensor], dir_name, path=__PATH): - path = path + dir_name +def make_test(inputs: list[Tensor], output: Tensor, func_sig: str, name: str, trait: Trait = Trait.TENSOR): + Mod().update(name) for i, input in enumerate(inputs): - __generate_data(input, path, f"input_{i}") - - for i, output in enumerate(outputs): - __generate_data(output, path, f"output_{i}") - - -def make_test(inputs: [Tensor], output: Tensor, func_sig: str, file_name: str, trait_type: Trait = Trait.TENSOR): - - code = [] - type_of_first_input = inputs[0].dtype - type_of_output = output.dtype - func_sig = re.sub("^[^.]*", "input_0", - func_sig) if trait_type == Trait.TENSOR else func_sig - - match trait_type: - case Trait.TENSOR: - code.append("\n\nuse array::{ArrayTrait, SpanTrait};\n") - code.append("use orion::operators::tensor::TensorTrait;\n") - match type_of_first_input: - case Dtype.U32: - code.append( - "use orion::operators::tensor::U32Tensor;\n") - case Dtype.I32: - code.append( - "use orion::operators::tensor::I32Tensor;\n") - case Dtype.I8: - code.append( - "use orion::operators::tensor::I8Tensor;\n") - case Dtype.FP8x23: - code.append( - "use orion::operators::tensor::FP8x23Tensor;\n") - case Dtype.FP16x16: - code.append( - "use orion::operators::tensor::FP16x16Tensor;\n") - match type_of_output: - case Dtype.U32: - code.append( - "use orion::operators::tensor::U32TensorPartialEq;\n") - case Dtype.I32: - code.append( - "use orion::operators::tensor::I32TensorPartialEq;\n") - case Dtype.I8: - code.append( - "use orion::operators::tensor::I8TensorPartialEq;\n") - case Dtype.FP16x16: - code.append( - "use orion::operators::tensor::FP16x16TensorPartialEq;\n") - case Dtype.FP8x23: - code.append( - "use orion::operators::tensor::FP8x23TensorPartialEq;\n") - case Trait.NN: - code.append("\n\nuse orion::operators::nn::NNTrait;\n") - code.append("use orion::numbers::FixedTrait;\n") - match type_of_first_input: - case Dtype.I32: - code.append( - "use orion::operators::nn::I32NN;\n") - case Dtype.I8: - code.append( - "use orion::operators::nn::I8NN;\n") - case Dtype.U32: - code.append( - "use orion::operators::nn::U32NN;\n") - case Dtype.FP8x23: - code.append( - "use orion::operators::nn::FP8x23NN;\n") - case Dtype.FP16x16: - code.append( - "use orion::operators::nn::FP16x16NN;\n") - match type_of_output: - case Dtype.U32: - code.append( - "use orion::operators::tensor::U32TensorPartialEq;\n") - case Dtype.I32: - code.append( - "use orion::operators::tensor::I32TensorPartialEq;\n") - case Dtype.I8: - code.append( - "use orion::operators::tensor::I8TensorPartialEq;\n") - case Dtype.FP16x16: - code.append( - "use orion::operators::tensor::FP16x16TensorPartialEq;\n") - case Dtype.FP8x23: - code.append( - "use orion::operators::tensor::FP8x23TensorPartialEq;\n") - - code.append("use orion::utils::assert_eq;\n\n") - code.append("#[test]\n") - code.append("#[available_gas(2000000000)]\n") - code.append(f"fn test_{file_name}() {{\n") - - for i, input in enumerate(inputs): - code.append(f" let input_{i} = input_{i}::input_{i}();\n") - - code.append(" let z = output_0::output_0();\n\n") + input_data = Data(os.path.join(name, f"input_{i}.cairo")) + input_data.buffer = Data.template( + func=f"input_{i}", + dtype=input.dtype.value, + refs=get_data_refs(input.dtype), + data=get_data_data(input.data, input.dtype), + shape=input.shape, + ) + input_data.dump() - code.append(f" let y = {func_sig};\n\n") - code.append(" assert_eq(y, z);\n") - code.append("}") + output_data = Data(os.path.join(name, "output_0.cairo")) + output_data.buffer = Data.template( + func="output_0", + dtype=output.dtype.value, + refs=get_data_refs(output.dtype), + data=get_data_data(output.data, output.dtype), + shape=output.shape, + ) + output_data.dump() - with open(os.path.join(__PATH, f"{file_name}.cairo"), "a") as f: - f.write( - ''.join(code) - ) + test_file = Test(f"{name}.cairo") + test_file.buffer = Test.template( + name=name, + arg_cnt=len(inputs), + refs=get_all_use(find_all_types([*inputs, output]), trait), + func_sig=func_sig, + ) + test_file.dump() -def to_fp(x: np.array, fp_impl: FixedImpl): +def find_all_types(tensors: list[Tensor]) -> list[Dtype]: + return list(set([tensor.dtype for tensor in tensors])) - match fp_impl: - case FixedImpl.FP8x23: - return (x * 2**23).astype(np.int64) - case FixedImpl.FP16x16: - return (x * 2**16).astype(np.int64) -################ -# INTERNALS -################ +def get_all_use(dtypes: list[Dtype], trait: Trait) -> list[str]: + refs = [] + for dtype in dtypes: + refs += get_test_refs(dtype, trait) + return list(set(refs)) -def __build_tensor_code(tensor: Tensor, name: str, type_string: str, is_fixed: bool = False, is_signed_int: bool = False) -> []: - result = [ - "use array::{ArrayTrait, SpanTrait};\n", - "use orion::operators::tensor::{TensorTrait, Tensor};\n", - ] - match tensor.dtype: +def get_data_data(data: np.ndarray, dtype: Dtype) -> list[str]: + match dtype: case Dtype.U32: - result.append( - "use orion::operators::tensor::U32Tensor;\n") + return [f"{int(x)}" for x in data.flatten()] case Dtype.I32: - result.append( - "use orion::operators::tensor::I32Tensor;\n") - result.append( - "use orion::numbers::{IntegerTrait, i32};\n") + return ["i32 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] case Dtype.I8: - result.append( - "use orion::operators::tensor::I8Tensor;\n") - result.append( - "use orion::numbers::{IntegerTrait, i8};\n") + return ["i8 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] case Dtype.FP8x23: - result.append( - "use orion::operators::tensor::FP8x23Tensor;\n") - result.append( - "use orion::numbers::FixedTrait;\n") - result.append( - "use orion::numbers::FP8x23;\n") + return ["FP8x23 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] case Dtype.FP16x16: - result.append( - "use orion::operators::tensor::FP16x16Tensor;\n") - result.append( - "use orion::numbers::FixedTrait;\n") - result.append( - "use orion::numbers::FP16x16;\n") - - result.append(f"\nfn {name}() -> Tensor<{type_string}> {{\n") - result.append(" let mut shape = ArrayTrait::::new();\n") - for dim in tensor.shape: - result.append(f" shape.append({dim});\n") - result.append("\n let mut data = ArrayTrait::new();\n") - if is_signed_int | is_fixed: - for val in tensor.data: - result.append( - f" data.append({type_string} {{ mag: {abs(int(val))}, sign: {str(val < 0).lower()} }});\n") - else: - for val in tensor.data: - result.append(f" data.append({abs(int(val))});\n") - result.append( - " TensorTrait::new(shape.span(), data.span())\n") - result.append("}") - return result - - -def __convert_tensor_to_cairo(tensor: Tensor, name: str) -> []: - dtype_mapping = { - Dtype.FP8x23: ('FP8x23', True, False), - Dtype.FP16x16: ('FP16x16', True, False), - Dtype.I32: ('i32', False, True), - Dtype.I8: ('i8', False, True), - Dtype.U32: ('u32', False, False), - } - - dtype_info = dtype_mapping.get(tensor.dtype) - if dtype_info is None: - raise ValueError(f"Invalid dtype: {tensor.dtype}") - - return __build_tensor_code(tensor, name, *dtype_info) - - -def __generate_data(tensor: Tensor, path: str, name: str): - - # If path not exist: - # Create directory - # Add mod parent to nodes.cairo - if not os.path.exists(path) or not os.listdir(path): - os.makedirs(path, exist_ok=True) - parent = path.replace(__PATH, "") - with open(f"{__PATH}.cairo", "a") as f: - f.write(f"mod {parent}; \n") - - # Add tensor mod in parent file - parent = path.replace(__PATH, "") - if not __module_exists(os.path.join(__PATH, f"{parent}.cairo"), name): - with open(os.path.join(__PATH, f"{parent}.cairo"), "a") as f: - f.write(f"mod {name}; \n") - - # Convert tensor to cairo - content = __convert_tensor_to_cairo(tensor, name) - # Create tensor cairo file - with open(os.path.join(path, f"{name}.cairo"), "w") as f: - f.write( - ''.join(content) - ) + return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] -def __module_exists(filepath: str, mod_name: str) -> bool: - """ - Checks if a module already exists in a file. - - Parameters: - - filepath: The path to the file to check. - - mod_name: The module to look for. - - Returns: - - True if the module exists, False otherwise. - """ - if not os.path.exists(filepath): - return False - - with open(filepath, 'r') as f: - for line in f: - if f"mod {mod_name};" in line: - return True +def get_data_refs(dtype: Dtype) -> list[str]: + refs = [ + *trait2use[Trait.TENSOR], + *dtype2tensor[dtype], + *dtype2numbers[dtype], + ] - return False + return refs + + +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: + dtype_ref = dtype2nn[dtype] if trait == Trait.NN else dtype2tensor[dtype] + refs = [ + *trait2use[trait], + *dtype_ref, + *dtype2partial[dtype], + "orion::utils::assert_eq", + ] + + return refs + + +trait2use = { + Trait.TENSOR: [ + "array::{ArrayTrait, SpanTrait}", + "orion::operators::tensor::{TensorTrait, Tensor}", + ], + Trait.NN: [ + "orion::numbers::FixedTrait", + "orion::operators::nn::NNTrait", + ], +} + + +dtype2tensor = { + Dtype.U32: ["orion::operators::tensor::U32Tensor",], + Dtype.I32: ["orion::operators::tensor::I32Tensor",], + Dtype.I8: ["orion::operators::tensor::I8Tensor",], + Dtype.FP8x23: ["orion::operators::tensor::FP8x23Tensor",], + Dtype.FP16x16: ["orion::operators::tensor::FP16x16Tensor",], +} + + +dtype2nn = { + Dtype.U32: ["orion::operators::nn::U32NN",], + Dtype.I32: ["orion::operators::nn::I32NN",], + Dtype.I8: ["orion::operators::nn::I8NN",], + Dtype.FP8x23: ["orion::operators::nn::FP8x23NN",], + Dtype.FP16x16: ["orion::operators::nn::FP16x16NN",], +} + + +dtype2partial = { + Dtype.U32: ["orion::operators::tensor::U32TensorPartialEq",], + Dtype.I32: ["orion::operators::tensor::I32TensorPartialEq",], + Dtype.I8: ["orion::operators::tensor::I8TensorPartialEq",], + Dtype.FP8x23: ["orion::operators::tensor::FP8x23TensorPartialEq",], + Dtype.FP16x16: ["orion::operators::tensor::FP16x16TensorPartialEq",], +} + + +dtype2numbers = { + Dtype.U32: [], + Dtype.I32: ["orion::numbers::{IntegerTrait, i32}",], + Dtype.I8: ["orion::numbers::{IntegerTrait, i8}",], + Dtype.FP8x23: ["orion::numbers::{FixedTrait, FP8x23}",], + Dtype.FP16x16: ["orion::numbers::{FixedTrait, FP16x16}",], +} diff --git a/nodegen/node/abs.py b/nodegen/node/abs.py index 13467e4ea..05d727c38 100644 --- a/nodegen/node/abs.py +++ b/nodegen/node/abs.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Abs(RunAll): @@ -13,7 +13,6 @@ def abs_i32(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "abs_i32" - make_node([x], [y], name) make_test([x], y, "input_0.abs()", name) @staticmethod @@ -25,7 +24,6 @@ def abs_i8(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "abs_i8" - make_node([x], [y], name) make_test([x], y, "input_0.abs()", name) @staticmethod @@ -38,7 +36,6 @@ def abs_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "abs_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.abs()", name) @staticmethod @@ -51,5 +48,4 @@ def abs_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "abs_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.abs()", name) diff --git a/nodegen/node/acos.py b/nodegen/node/acos.py index 6b7015e6e..d62988988 100644 --- a/nodegen/node/acos.py +++ b/nodegen/node/acos.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Acos(RunAll): @@ -13,7 +13,6 @@ def acos_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "acos_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.acos()", name) @staticmethod @@ -25,7 +24,6 @@ def acos_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "acos_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.acos()", name) diff --git a/nodegen/node/acosh.py b/nodegen/node/acosh.py index 62f870206..cc631acca 100644 --- a/nodegen/node/acosh.py +++ b/nodegen/node/acosh.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Acosh(RunAll): @@ -15,7 +15,6 @@ def acosh_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "acosh_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.acosh()", name) @staticmethod @@ -29,5 +28,4 @@ def acosh_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "acosh_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.acosh()", name) diff --git a/nodegen/node/add.py b/nodegen/node/add.py index 1f274208c..677c215a6 100644 --- a/nodegen/node/add.py +++ b/nodegen/node/add.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Add(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "add_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "add_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "add_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "add_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "add_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "add_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) default() @@ -112,7 +106,6 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "add_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) def broadcast(): @@ -128,7 +121,6 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "add_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) default() @@ -149,7 +141,6 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "add_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) def broadcast(): @@ -165,7 +156,6 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "add_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0 + input_1", name) default() diff --git a/nodegen/node/and.py b/nodegen/node/and.py index 0a1741a21..b446354d5 100644 --- a/nodegen/node/and.py +++ b/nodegen/node/and.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class And(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "and_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.and(@input_1)", name) default() diff --git a/nodegen/node/argmax.py b/nodegen/node/argmax.py index bf5dfa432..c874b2eea 100644 --- a/nodegen/node/argmax.py +++ b/nodegen/node/argmax.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl def argmax_use_numpy(data: np.ndarray, axis: int = 0, keepdims: int = 1, dtype=np.int64) -> np.ndarray: @@ -34,7 +34,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -47,7 +46,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -60,7 +58,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -78,7 +75,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -91,7 +87,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -104,7 +99,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -122,7 +116,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -135,7 +128,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -148,7 +140,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_u32_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -168,7 +159,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -181,7 +171,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -194,7 +183,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -212,7 +200,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -225,7 +212,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -238,7 +224,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -256,7 +241,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -269,7 +253,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -282,7 +265,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i32_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -302,7 +284,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -315,7 +296,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -328,7 +308,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -346,7 +325,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -359,7 +337,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -372,7 +349,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -390,7 +366,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -403,7 +378,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -416,7 +390,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_i8_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -437,7 +410,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -451,7 +423,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -465,7 +436,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -484,7 +454,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -498,7 +467,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -512,7 +480,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -531,7 +498,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -545,7 +511,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -559,7 +524,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp16x16_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -581,7 +545,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -596,7 +559,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -611,7 +573,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -630,7 +591,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -645,7 +605,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -660,7 +619,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) @@ -680,7 +638,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::None(()))", name) @@ -695,7 +652,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::Some(false), Option::None(()))", name) @@ -710,7 +666,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmax_fp8x23_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmax(0, Option::None(()), Option::Some(true))", name) diff --git a/nodegen/node/argmin.py b/nodegen/node/argmin.py index fd3249a55..e09b9c442 100644 --- a/nodegen/node/argmin.py +++ b/nodegen/node/argmin.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl def argmin_use_numpy(data: np.ndarray, axis: int = 0, keepdims: int = 1, dtype=np.int64) -> np.ndarray: @@ -34,7 +34,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -47,7 +46,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -60,7 +58,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -78,7 +75,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -91,7 +87,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -104,7 +99,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -122,7 +116,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -135,7 +128,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -148,7 +140,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_u32_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -168,7 +159,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -181,7 +171,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -194,7 +183,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -212,7 +200,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -225,7 +212,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -238,7 +224,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -256,7 +241,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -269,7 +253,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -282,7 +265,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i32_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -302,7 +284,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -315,7 +296,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -328,7 +308,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -346,7 +325,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -359,7 +337,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -372,7 +349,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -390,7 +366,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -403,7 +378,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -416,7 +390,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_i8_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -437,7 +410,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -451,7 +423,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -465,7 +436,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -484,7 +454,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -498,7 +467,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -512,7 +480,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -531,7 +498,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -545,7 +511,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -559,7 +524,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp16x16_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -581,7 +545,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_1D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -596,7 +559,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_1D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -611,7 +573,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_1D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -630,7 +591,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -645,7 +605,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_2D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -660,7 +619,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_2D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) @@ -680,7 +638,6 @@ def default_params(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_3D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::None(()))", name) @@ -695,7 +652,6 @@ def keepdims_false(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_3D_keepdims_false" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::Some(false), Option::None(()))", name) @@ -710,7 +666,6 @@ def last_index(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "argmin_fp8x23_3D_last_index" - make_node([x], [y], name) make_test( [x], y, "input_0.argmin(0, Option::None(()), Option::Some(true))", name) diff --git a/nodegen/node/asin.py b/nodegen/node/asin.py index 7268666ed..78024ad43 100644 --- a/nodegen/node/asin.py +++ b/nodegen/node/asin.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Asin(RunAll): @@ -13,7 +13,6 @@ def asin_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "asin_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.asin()", name) @staticmethod @@ -25,7 +24,6 @@ def asin_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "asin_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.asin()", name) diff --git a/nodegen/node/asinh.py b/nodegen/node/asinh.py index 995e93d4a..2b6fb999d 100644 --- a/nodegen/node/asinh.py +++ b/nodegen/node/asinh.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Asinh(RunAll): @@ -16,7 +16,6 @@ def asinh_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "asinh_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.asinh()", name) @staticmethod @@ -30,5 +29,4 @@ def asinh_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "asinh_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.asinh()", name) diff --git a/nodegen/node/atan.py b/nodegen/node/atan.py index 8731a6838..ad4308ea5 100644 --- a/nodegen/node/atan.py +++ b/nodegen/node/atan.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Atan(RunAll): @@ -15,7 +15,6 @@ def atan_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "atan_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.atan()", name) @staticmethod @@ -29,5 +28,4 @@ def atan_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "atan_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.atan()", name) diff --git a/nodegen/node/ceil.py b/nodegen/node/ceil.py index 361cf74d4..51fae6a23 100644 --- a/nodegen/node/ceil.py +++ b/nodegen/node/ceil.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Ceil(RunAll): @@ -13,7 +13,6 @@ def ceil_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "ceil_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.ceil()", name) @staticmethod @@ -25,13 +24,4 @@ def ceil_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "ceil_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.ceil()", name) - - - - - - - - diff --git a/nodegen/node/clip.py b/nodegen/node/clip.py index 90cab026f..393ac4dde 100644 --- a/nodegen/node/clip.py +++ b/nodegen/node/clip.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Clip(RunAll): @@ -14,7 +14,6 @@ def clip_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "clip_u32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(u32 { mag: 10, sign: false }), Option::Some(u32 { mag: 20, sign: false }))", name) @@ -26,7 +25,6 @@ def clip_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "clip_u32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(u32 { mag: 10, sign: false }), Option::Some(u32 { mag: 20, sign: false }))", name) @@ -43,7 +41,6 @@ def clip_2D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "clip_i32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(i32 { mag: 10, sign: true }), Option::Some(i32 { mag: 20, sign: false }))", name) @@ -55,7 +52,6 @@ def clip_3D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "clip_i32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(i32 { mag: 10, sign: true }), Option::Some(i32 { mag: 20, sign: false }))", name) @@ -73,7 +69,6 @@ def clip_2D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "clip_i8_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(i8 { mag: 10, sign: true }), Option::Some(i8 { mag: 20, sign: false }))", name) @@ -85,7 +80,6 @@ def clip_3D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "clip_i8_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(i8 { mag: 10, sign: true }), Option::Some(i8 { mag: 20, sign: false }))", name) @@ -103,7 +97,6 @@ def clip_2D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "clip_fp8x23_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(FP8x23 { mag: 83886080, sign: true }), Option::Some(FP8x23 { mag: 167772160, sign: false }))", name) @@ -116,7 +109,6 @@ def clip_3D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "clip_fp8x23_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(FP8x23 { mag: 83886080, sign: true }), Option::Some(FP8x23 { mag: 167772160, sign: false }))", name) @@ -134,7 +126,6 @@ def clip_2D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "clip_fp16x16_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(FP16x16 { mag: 655360, sign: true }), Option::Some(FP16x16 { mag: 1310720, sign: false }))", name) @@ -147,7 +138,6 @@ def clip_3D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "clip_fp16x16_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.clip(Option::Some(FP16x16 { mag: 655360, sign: true }), Option::Some(FP16x16 { mag: 1310720, sign: false }))", name) diff --git a/nodegen/node/concat.py b/nodegen/node/concat.py index 794fedd8d..801423cbc 100644 --- a/nodegen/node/concat.py +++ b/nodegen/node/concat.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait # 687 class Concat(RunAll): @staticmethod @@ -16,10 +16,9 @@ def concat_1D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_1d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_2D(): @@ -32,10 +31,9 @@ def concat_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_2d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_3D(): def default(): @@ -48,10 +46,9 @@ def default(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_3d_default" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def axis_1(): x1 = np.arange(0,27).astype(np.uint32).reshape(3,3,3) @@ -63,10 +60,9 @@ def axis_1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_3d_axis_1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def axis_2(): x1 = np.arange(0,27).astype(np.uint32).reshape(3,3,3) @@ -78,10 +74,9 @@ def axis_2(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_3d_axis_2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_1(): x1 = np.arange(0,27).astype(np.uint32).reshape(3,3,3) @@ -97,10 +92,9 @@ def three_tensors_axis_1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_3d_three_tensors_axis_1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_2(): x1 = np.arange(0,27).astype(np.uint32).reshape(3,3,3) @@ -116,10 +110,9 @@ def three_tensors_axis_2(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "concat_u32_3d_three_tensors_axis_2" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) default() axis_1() @@ -143,10 +136,9 @@ def concat_1D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_1d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR.TENSOR) def concat_2D(): @@ -159,10 +151,9 @@ def concat_2D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_2d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_3D(): def default(): @@ -175,10 +166,9 @@ def default(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_3d_default" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def axis_1(): x1 = np.arange(0,27).astype(np.int32).reshape(3,3,3) @@ -190,10 +180,9 @@ def axis_1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_3d_axis_1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def axis_2(): x1 = np.arange(0,27).astype(np.int32).reshape(3,3,3) @@ -205,10 +194,9 @@ def axis_2(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_3d_axis_2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_1(): x1 = np.arange(0,27).astype(np.int32).reshape(3,3,3) @@ -224,10 +212,9 @@ def three_tensors_axis_1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_3d_three_tensors_axis_1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_2(): x1 = np.arange(0,27).astype(np.int32).reshape(3,3,3) @@ -243,10 +230,9 @@ def three_tensors_axis_2(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "concat_i32_3d_three_tensors_axis_2" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) default() axis_1() @@ -270,10 +256,9 @@ def concat_1D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_1d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR.TENSOR) def concat_2D(): @@ -286,10 +271,9 @@ def concat_2D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_2d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_3D(): def default(): @@ -302,10 +286,9 @@ def default(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_3d_default" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def axis_1(): x1 = np.arange(0,27).astype(np.int8).reshape(3,3,3) @@ -317,10 +300,9 @@ def axis_1(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_3d_axis_1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def axis_2(): x1 = np.arange(0,27).astype(np.int8).reshape(3,3,3) @@ -332,10 +314,9 @@ def axis_2(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_3d_axis_2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_1(): x1 = np.arange(0,27).astype(np.int8).reshape(3,3,3) @@ -351,10 +332,9 @@ def three_tensors_axis_1(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_3d_three_tensors_axis_1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_2(): x1 = np.arange(0,27).astype(np.int8).reshape(3,3,3) @@ -370,10 +350,9 @@ def three_tensors_axis_2(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "concat_i8_3d_three_tensors_axis_2" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) default() axis_1() @@ -400,10 +379,9 @@ def concat_1D(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_1d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR.TENSOR) def concat_2D(): @@ -419,10 +397,9 @@ def concat_2D(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_2d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_3D(): def default(): @@ -438,10 +415,9 @@ def default(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_3d_default" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def axis_1(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -456,10 +432,9 @@ def axis_1(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_3d_axis_1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def axis_2(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -474,10 +449,9 @@ def axis_2(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_3d_axis_2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_1(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -497,10 +471,9 @@ def three_tensors_axis_1(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_3d_three_tensors_axis_1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_2(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -520,10 +493,9 @@ def three_tensors_axis_2(): y.flatten(), FixedImpl.FP8x23)) name = "concat_fp8x23_3d_three_tensors_axis_2" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) default() axis_1() @@ -550,10 +522,9 @@ def concat_1D(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_1d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR.TENSOR) def concat_2D(): @@ -569,10 +540,9 @@ def concat_2D(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_2d" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def concat_3D(): def default(): @@ -588,10 +558,9 @@ def default(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_3d_default" - make_node([x1, x2], [y], name) make_test( - inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0);", - file_name= name, trait_type= Trait.TENSOR) + inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 0)", + name= name, trait= Trait.TENSOR) def axis_1(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -606,10 +575,9 @@ def axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_3d_axis_1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def axis_2(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -624,10 +592,9 @@ def axis_2(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_3d_axis_2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_1(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -647,10 +614,9 @@ def three_tensors_axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_3d_three_tensors_axis_1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 1)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) def three_tensors_axis_2(): x1 = np.arange(0,27).astype(np.int64).reshape(3,3,3) @@ -670,10 +636,9 @@ def three_tensors_axis_2(): y.flatten(), FixedImpl.FP16x16)) name = "concat_fp16x16_3d_three_tensors_axis_2" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "TensorTrait::concat(array![input_0, input_1, input_2].span(), 2)", - file_name= name, trait_type= Trait.TENSOR) + name= name, trait= Trait.TENSOR) default() axis_1() diff --git a/nodegen/node/cos.py b/nodegen/node/cos.py index c6f965432..68ef595b5 100644 --- a/nodegen/node/cos.py +++ b/nodegen/node/cos.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Cos(RunAll): @@ -16,7 +16,6 @@ def cos_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "cos_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.cos()", name) @staticmethod @@ -30,5 +29,4 @@ def cos_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "cos_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.cos()", name) diff --git a/nodegen/node/cosh.py b/nodegen/node/cosh.py index fac5f3ef5..a2e998609 100644 --- a/nodegen/node/cosh.py +++ b/nodegen/node/cosh.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Cosh(RunAll): @@ -16,7 +16,6 @@ def cosh_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "cosh_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.cosh()", name) @staticmethod @@ -30,5 +29,4 @@ def cosh_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "cosh_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.cosh()", name) diff --git a/nodegen/node/cumsum.py b/nodegen/node/cumsum.py index 9ed5c6747..8350d375d 100644 --- a/nodegen/node/cumsum.py +++ b/nodegen/node/cumsum.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Cumsum(RunAll): @@ -15,7 +15,6 @@ def default(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_1d_default" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -27,7 +26,6 @@ def exclusive(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_1d_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(false))", name) @@ -39,7 +37,6 @@ def reverse(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_1d_reverse" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(false), Option::Some(true))", name) @@ -51,7 +48,6 @@ def reverse_exclusive(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_1d_reverse_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(true))", name) @@ -72,7 +68,6 @@ def axis_0(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_2d_axis_0" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -86,7 +81,6 @@ def axis_1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "cumsum_u32_2d_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(1, Option::None(()), Option::None(()))", name) @@ -105,7 +99,6 @@ def default(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_1d_default" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -117,7 +110,6 @@ def exclusive(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_1d_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(false))", name) @@ -129,7 +121,6 @@ def reverse(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_1d_reverse" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(false), Option::Some(true))", name) @@ -141,7 +132,6 @@ def reverse_exclusive(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_1d_reverse_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(true))", name) @@ -162,7 +152,6 @@ def axis_0(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_2d_axis_0" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -176,7 +165,6 @@ def axis_1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "cumsum_i32_2d_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(1, Option::None(()), Option::None(()))", name) @@ -195,7 +183,6 @@ def default(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_1d_default" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -207,7 +194,6 @@ def exclusive(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_1d_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(false))", name) @@ -219,7 +205,6 @@ def reverse(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_1d_reverse" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(false), Option::Some(true))", name) @@ -231,7 +216,6 @@ def reverse_exclusive(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_1d_reverse_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(true))", name) @@ -252,7 +236,6 @@ def axis_0(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_2d_axis_0" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -266,7 +249,6 @@ def axis_1(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "cumsum_i8_2d_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(1, Option::None(()), Option::None(()))", name) @@ -287,7 +269,6 @@ def default(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_1d_default" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -301,7 +282,6 @@ def exclusive(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_1d_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(false))", name) @@ -315,7 +295,6 @@ def reverse(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_1d_reverse" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(false), Option::Some(true))", name) @@ -329,7 +308,6 @@ def reverse_exclusive(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_1d_reverse_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(true))", name) @@ -352,7 +330,6 @@ def axis_0(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_2d_axis_0" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -368,7 +345,6 @@ def axis_1(): y.flatten(), FixedImpl.FP8x23)) name = "cumsum_fp8x23_2d_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(1, Option::None(()), Option::None(()))", name) @@ -389,7 +365,6 @@ def default(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_1d_default" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -403,7 +378,6 @@ def exclusive(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_1d_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(false))", name) @@ -417,7 +391,6 @@ def reverse(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_1d_reverse" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(false), Option::Some(true))", name) @@ -431,7 +404,6 @@ def reverse_exclusive(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_1d_reverse_exclusive" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::Some(true), Option::Some(true))", name) @@ -454,7 +426,6 @@ def axis_0(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_2d_axis_0" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(0, Option::None(()), Option::None(()))", name) @@ -470,7 +441,6 @@ def axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "cumsum_fp16x16_2d_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.cumsum(1, Option::None(()), Option::None(()))", name) diff --git a/nodegen/node/div.py b/nodegen/node/div.py index 92fe6cc1a..ab7d291db 100644 --- a/nodegen/node/div.py +++ b/nodegen/node/div.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Div(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "div_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "div_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "div_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "div_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "div_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "div_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) default() @@ -112,7 +106,6 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "div_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) def broadcast(): @@ -128,7 +121,6 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "div_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) default() @@ -149,7 +141,6 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "div_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) def broadcast(): @@ -165,7 +156,6 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "div_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.div(@input_1)", name) default() diff --git a/nodegen/node/equal.py b/nodegen/node/equal.py index a4b6c070a..f995ae999 100644 --- a/nodegen/node/equal.py +++ b/nodegen/node/equal.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Equal(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "equal_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.equal(@input_1)", name) default() diff --git a/nodegen/node/exp.py b/nodegen/node/exp.py index 3194c1081..7b8ad6d7f 100644 --- a/nodegen/node/exp.py +++ b/nodegen/node/exp.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Exp(RunAll): @@ -16,7 +16,6 @@ def exp_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "exp_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.exp()", name) @staticmethod @@ -30,5 +29,4 @@ def exp_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "exp_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.exp()", name) diff --git a/nodegen/node/gather.py b/nodegen/node/gather.py index 689c00943..5ba2692fb 100644 --- a/nodegen/node/gather.py +++ b/nodegen/node/gather.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Gather(RunAll): @@ -19,10 +19,9 @@ def default(): y.flatten(), FixedImpl.FP16x16)) name = "gather_fp16x16_3d_default" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(0))", - file_name= name) + name= name) def axis1(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) @@ -35,10 +34,9 @@ def axis1(): y.flatten(), FixedImpl.FP16x16)) name = "gather_fp16x16_3d_axis1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(1))", - file_name= name) + name= name) def axis2(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) @@ -51,10 +49,9 @@ def axis2(): y.flatten(), FixedImpl.FP16x16)) name = "gather_fp16x16_3d_axis2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(2))", - file_name= name) + name= name) default() axis1() @@ -75,10 +72,9 @@ def default(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "gather_fp8x23_3d_default" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(0))", - file_name= name) + name= name) def axis1(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) @@ -90,10 +86,9 @@ def axis1(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "gather_fp8x23_3d_axis1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(1))", - file_name= name) + name= name) def axis2(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) @@ -105,10 +100,9 @@ def axis2(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "gather_fp8x23_3d_axis2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(2))", - file_name= name) + name= name) default() axis1() @@ -129,10 +123,9 @@ def default(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "gather_i8_3d_default" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(0))", - file_name= name) + name= name) def axis1(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int8) @@ -144,10 +137,9 @@ def axis1(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "gather_i8_3d_axis1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(1))", - file_name= name) + name= name) def axis2(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int8) @@ -159,10 +151,9 @@ def axis2(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "gather_i8_3d_axis2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(2))", - file_name= name) + name= name) default() axis1() @@ -184,10 +175,9 @@ def default(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "gather_i32_3d_default" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(0))", - file_name= name) + name= name) def axis1(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int32) @@ -199,10 +189,9 @@ def axis1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "gather_i32_3d_axis1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(1))", - file_name= name) + name= name) def axis2(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int32) @@ -214,10 +203,9 @@ def axis2(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "gather_i32_3d_axis2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(2))", - file_name= name) + name= name) default() axis1() @@ -238,10 +226,9 @@ def default(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "gather_u32_3d_default" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(0))", - file_name= name) + name= name) def axis1(): x1 = np.arange(0,36).reshape(3,4,3).astype(np.uint32) @@ -253,10 +240,9 @@ def axis1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "gather_u32_3d_axis1" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(1))", - file_name= name) + name= name) def axis2(): x1 = np.arange(0,36).reshape(3,4,3).astype(np.uint32) @@ -268,12 +254,11 @@ def axis2(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "gather_u32_3d_axis2" - make_node([x1, x2], [y], name) make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather(indices:input_1, axis:Option::Some(2))", - file_name= name) + name= name) default() axis1() axis2() - gather_3D() \ No newline at end of file + gather_3D() diff --git a/nodegen/node/gemm.py b/nodegen/node/gemm.py index f4d7ed13d..162de7f51 100644 --- a/nodegen/node/gemm.py +++ b/nodegen/node/gemm.py @@ -2,7 +2,7 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def gemm_reference_implementation( @@ -39,7 +39,6 @@ def gemm_default_zero_bias(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_default_no_bias" - make_node([a, b], [y], name) make_test( [a, b], y, "NNTrait::gemm(input_0, input_1, Option::None(()), Option::None(()), Option::None(()), false, false)", name, Trait.NN) @@ -60,7 +59,6 @@ def gemm_default_vector_bias(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_default_vector_bias" - make_node([a, b, c], [y], name) make_test( [a, b, c], y, "NNTrait::gemm(input_0, input_1, Option::Some(input_2), Option::None(()), Option::None(()), false, false)", name, Trait.NN) @@ -81,7 +79,6 @@ def gemm_default_matrix_bias(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_default_matrix_bias" - make_node([a, b, c], [y], name) make_test( [a, b, c], y, "NNTrait::gemm(input_0, input_1, Option::Some(input_2), Option::None(()), Option::None(()), false, false)", name, Trait.NN) @@ -100,7 +97,6 @@ def gemm_transposeA(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_transposeA" - make_node([a, b], [y], name) make_test( [a, b], y, "NNTrait::gemm(input_0, input_1, Option::None(()), Option::None(()), Option::None(()), true, false)", name, Trait.NN) @@ -119,7 +115,6 @@ def gemm_transposeB(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_transposeB" - make_node([a, b], [y], name) make_test( [a, b], y, "NNTrait::gemm(input_0, input_1, Option::None(()), Option::None(()), Option::None(()), false, true)", name, Trait.NN) @@ -138,7 +133,6 @@ def gemm_alpha(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_alpha" - make_node([a, b], [y], name) make_test( [a, b], y, "NNTrait::gemm(input_0, input_1, Option::None(()), Option::Some(FixedTrait::new(32768, false)), Option::None(()), false, false)", name, Trait.NN) @@ -159,7 +153,6 @@ def gemm_beta(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_beta" - make_node([a, b, c], [y], name) make_test( [a, b, c], y, "NNTrait::gemm(input_0, input_1, Option::Some(input_2), Option::None(()), Option::Some(FixedTrait::new(32768, false)), false, false)", name, Trait.NN) @@ -182,7 +175,6 @@ def gemm_all_attributes(): y.flatten(), FixedImpl.FP16x16)) name = "gemm_all_attributes" - make_node([a, b, c], [y], name) make_test( [a, b, c], y, "NNTrait::gemm(input_0, input_1, Option::Some(input_2), Option::Some(FixedTrait::new(16384, false)), Option::Some(FixedTrait::new(22938, false)), true, true)", name, Trait.NN) diff --git a/nodegen/node/greater.py b/nodegen/node/greater.py index 8abf66f47..2fd793847 100644 --- a/nodegen/node/greater.py +++ b/nodegen/node/greater.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Greater(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater(@input_1)", name) default() diff --git a/nodegen/node/greater_equal.py b/nodegen/node/greater_equal.py index 1606150ff..2d43f7cc2 100644 --- a/nodegen/node/greater_equal.py +++ b/nodegen/node/greater_equal.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Greater_equal(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() diff --git a/nodegen/node/hard_sigmoid.py b/nodegen/node/hard_sigmoid.py index 11de116d2..19b384ddd 100644 --- a/nodegen/node/hard_sigmoid.py +++ b/nodegen/node/hard_sigmoid.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Hard_sigmoid(RunAll): @@ -17,7 +17,6 @@ def fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "hard_sigmoid_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::hard_sigmoid(@input_0, @FixedTrait::new(1677721, false), @FixedTrait::new(4194304, false))", name, Trait.NN) @@ -34,7 +33,6 @@ def fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "hard_sigmoid_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::hard_sigmoid(@input_0, @FixedTrait::new(13107, false), @FixedTrait::new(32768, false))", name, Trait.NN) diff --git a/nodegen/node/identity.py b/nodegen/node/identity.py index eb46b93e9..e475313c3 100644 --- a/nodegen/node/identity.py +++ b/nodegen/node/identity.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Identity(RunAll): @@ -15,7 +15,6 @@ def identity(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "identity_fP8x23" - make_node([x], [y], name) make_test( [x], y, "input_0.identity()", name) @@ -31,7 +30,6 @@ def identity(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "identity_fP16x16" - make_node([x], [y], name) make_test( [x], y, "input_0.identity()", name) @@ -47,7 +45,6 @@ def identity(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "identity_i8" - make_node([x], [y], name) make_test( [x], y, "input_0.identity()", name) @@ -63,7 +60,6 @@ def identity(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "identity_i32" - make_node([x], [y], name) make_test( [x], y, "input_0.identity()", name) @@ -79,8 +75,7 @@ def identity(): 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 + identity() diff --git a/nodegen/node/leaky_relu.py b/nodegen/node/leaky_relu.py index a20704f3c..a33da9bd9 100644 --- a/nodegen/node/leaky_relu.py +++ b/nodegen/node/leaky_relu.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait import tensorflow as tf @@ -19,7 +19,6 @@ def leaky_relu_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "leaky_relu_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::leaky_relu(@input_0, @FixedTrait::new(838861, false))", name, Trait.NN) @@ -36,6 +35,5 @@ def leaky_relu_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "leaky_relu_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::leaky_relu(@input_0, @FixedTrait::new(6554, false))", name, Trait.NN) diff --git a/nodegen/node/less.py b/nodegen/node/less.py index 8b694ef5d..20b39263d 100644 --- a/nodegen/node/less.py +++ b/nodegen/node/less.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Less(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less(@input_1)", name) default() diff --git a/nodegen/node/less_equal.py b/nodegen/node/less_equal.py index 26cef6453..c54040331 100644 --- a/nodegen/node/less_equal.py +++ b/nodegen/node/less_equal.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Less_equal(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "less_equal_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.less_equal(@input_1)", name) default() diff --git a/nodegen/node/linear.py b/nodegen/node/linear.py index b3a486398..fbbe5db3b 100644 --- a/nodegen/node/linear.py +++ b/nodegen/node/linear.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait from typing import Optional @@ -28,7 +28,6 @@ def linear_i32(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "linear_i32" - make_node([i, w, b], [y], name) make_test([i, w, b], y, "NNTrait::linear(input_0, input_1, input_2)", name, Trait.NN) @@ -45,7 +44,6 @@ def linear_i8(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "linear_i8" - make_node([i, w, b], [y], name) make_test([i, w, b], y, "NNTrait::linear(input_0, input_1, input_2)", name, Trait.NN) @@ -62,7 +60,6 @@ def linear_u32(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "linear_u32" - make_node([i, w, b], [y], name) make_test([i, w, b], y, "NNTrait::linear(input_0, input_1, input_2)", name, Trait.NN) @@ -83,7 +80,6 @@ def linear_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "linear_fp8x23" - make_node([i, w, b], [y], name) make_test([i, w, b], y, "NNTrait::linear(input_0, input_1, input_2)", name, Trait.NN) @@ -104,6 +100,5 @@ def linear_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "linear_fp16x16" - make_node([i, w, b], [y], name) make_test([i, w, b], y, "NNTrait::linear(input_0, input_1, input_2)", name, Trait.NN) diff --git a/nodegen/node/log.py b/nodegen/node/log.py index 0465dc95f..0957146b1 100644 --- a/nodegen/node/log.py +++ b/nodegen/node/log.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Log(RunAll): @@ -16,7 +16,6 @@ def log_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "log_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.log()", name) @staticmethod @@ -30,5 +29,4 @@ def log_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "log_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.log()", name) diff --git a/nodegen/node/logsoftmax.py b/nodegen/node/logsoftmax.py index af87e76ee..ed90126cf 100644 --- a/nodegen/node/logsoftmax.py +++ b/nodegen/node/logsoftmax.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def logsoftmax(x: np.ndarray, axis: int = -1) -> np.ndarray: @@ -23,7 +23,6 @@ def axis_0(): y.flatten(), FixedImpl.FP8x23)) name = "logsoftmax_fp8x23_axis_0" - make_node([x], [y], name) make_test([x], y, "NNTrait::logsoftmax(@input_0, 0)", name, Trait.NN) @@ -37,7 +36,6 @@ def axis_1(): y.flatten(), FixedImpl.FP8x23)) name = "logsoftmax_fp8x23_axis_1" - make_node([x], [y], name) make_test([x], y, "NNTrait::logsoftmax(@input_0, 1)", name, Trait.NN) @@ -55,7 +53,6 @@ def axis_0(): y.flatten(), FixedImpl.FP16x16)) name = "logsoftmax_fp16x16_axis_0" - make_node([x], [y], name) make_test([x], y, "NNTrait::logsoftmax(@input_0, 0)", name, Trait.NN) @@ -69,7 +66,6 @@ def axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "logsoftmax_fp16x16_axis_1" - make_node([x], [y], name) make_test([x], y, "NNTrait::logsoftmax(@input_0, 1)", name, Trait.NN) diff --git a/nodegen/node/matmul.py b/nodegen/node/matmul.py index 6965fcc41..575c36933 100644 --- a/nodegen/node/matmul.py +++ b/nodegen/node/matmul.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Matmul(RunAll): @@ -17,7 +17,6 @@ def matmul_1D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "matmul_u32_1d" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -31,7 +30,6 @@ def matmul_2x2(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "matmul_u32_2x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -45,7 +43,6 @@ def matmul_2x1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "matmul_u32_2x1" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -59,7 +56,6 @@ def matmul_1x2(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "matmul_u32_1x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -80,7 +76,6 @@ def matmul_1D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "matmul_i32_1d" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -94,7 +89,6 @@ def matmul_2x2(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "matmul_i32_2x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -108,7 +102,6 @@ def matmul_2x1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "matmul_i32_2x1" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -122,7 +115,6 @@ def matmul_1x2(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "matmul_i32_1x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -143,7 +135,6 @@ def matmul_1D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "matmul_i8_1d" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -157,7 +148,6 @@ def matmul_2x2(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "matmul_i8_2x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -171,7 +161,6 @@ def matmul_2x1(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "matmul_i8_2x1" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -185,7 +174,6 @@ def matmul_1x2(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "matmul_i8_1x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -209,7 +197,6 @@ def matmul_1D(): y.flatten(), FixedImpl.FP8x23)) name = "matmul_fp8x23_1d" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -226,7 +213,6 @@ def matmul_2x2(): y.flatten(), FixedImpl.FP8x23)) name = "matmul_fp8x23_2x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -243,7 +229,6 @@ def matmul_2x1(): y.flatten(), FixedImpl.FP8x23)) name = "matmul_fp8x23_2x1" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -260,7 +245,6 @@ def matmul_1x2(): y.flatten(), FixedImpl.FP8x23)) name = "matmul_fp8x23_1x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -284,7 +268,6 @@ def matmul_1D(): y.flatten(), FixedImpl.FP16x16)) name = "matmul_fp16x16_1d" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -301,7 +284,6 @@ def matmul_2x2(): y.flatten(), FixedImpl.FP16x16)) name = "matmul_fp16x16_2x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -318,7 +300,6 @@ def matmul_2x1(): y.flatten(), FixedImpl.FP16x16)) name = "matmul_fp16x16_2x1" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) @@ -335,7 +316,6 @@ def matmul_1x2(): y.flatten(), FixedImpl.FP16x16)) name = "matmul_fp16x16_1x2" - make_node([a, b], [y], name) make_test( [a, b], y, "input_0.matmul(@input_1)", name) diff --git a/nodegen/node/max.py b/nodegen/node/max.py index b1079a30c..5513d1fa7 100644 --- a/nodegen/node/max.py +++ b/nodegen/node/max.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Max(RunAll): @@ -16,8 +16,7 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "max_u32_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) @@ -29,8 +28,7 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "max_u32_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) default() broadcast() @@ -47,8 +45,7 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "max_i32_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int32) @@ -60,8 +57,7 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "max_i32_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) default() broadcast() @@ -78,8 +74,7 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "max_i8_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int8) @@ -91,8 +86,7 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "max_i8_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) default() broadcast() @@ -112,8 +106,7 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "max_fp8x23_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -128,8 +121,7 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "max_fp8x23_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) default() broadcast() @@ -149,8 +141,7 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "max_fp16x16_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -165,8 +156,7 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "max_fp16x16_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span())", name) default() broadcast() @@ -186,8 +176,7 @@ def default(): m = Tensor(Dtype.U32, m.shape, m.flatten()) name = "max_u32_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) @@ -201,8 +190,7 @@ def broadcast(): m = Tensor(Dtype.U32, m.shape, m.flatten()) name = "max_u32_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -221,8 +209,7 @@ def default(): m = Tensor(Dtype.I32, m.shape, m.flatten()) name = "max_i32_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int32) @@ -236,8 +223,7 @@ def broadcast(): m = Tensor(Dtype.I32, m.shape, m.flatten()) name = "max_i32_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -256,8 +242,7 @@ def default(): m = Tensor(Dtype.I8, m.shape, m.flatten()) name = "max_i8_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int8) @@ -271,8 +256,7 @@ def broadcast(): m = Tensor(Dtype.I8, m.shape, m.flatten()) name = "max_i8_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -295,8 +279,7 @@ def default(): m.flatten(), FixedImpl.FP8x23)) name = "max_fp8x23_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -314,8 +297,7 @@ def broadcast(): m.flatten(), FixedImpl.FP8x23)) name = "max_fp8x23_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -338,8 +320,7 @@ def default(): m.flatten(), FixedImpl.FP16x16)) name = "max_fp16x16_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -357,8 +338,7 @@ def broadcast(): m.flatten(), FixedImpl.FP16x16)) name = "max_fp16x16_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span())", name) default() - broadcast() \ No newline at end of file + broadcast() diff --git a/nodegen/node/min.py b/nodegen/node/min.py index a6299cea0..af75655e4 100644 --- a/nodegen/node/min.py +++ b/nodegen/node/min.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Min(RunAll): @@ -16,8 +16,7 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "min_u32_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) @@ -29,8 +28,7 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "min_u32_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) default() broadcast() @@ -47,8 +45,7 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "min_i32_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int32) @@ -60,8 +57,7 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "min_i32_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) default() broadcast() @@ -78,8 +74,7 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "min_i8_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int8) @@ -91,8 +86,7 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "min_i8_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) default() broadcast() @@ -112,8 +106,7 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "min_fp8x23_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -128,8 +121,7 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "min_fp8x23_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) default() broadcast() @@ -149,8 +141,7 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "min_fp16x16_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -165,8 +156,7 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "min_fp16x16_broadcast_two_tensors" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span())", name) default() broadcast() @@ -186,8 +176,7 @@ def default(): m = Tensor(Dtype.U32, m.shape, m.flatten()) name = "min_u32_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) @@ -201,8 +190,7 @@ def broadcast(): m = Tensor(Dtype.U32, m.shape, m.flatten()) name = "min_u32_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -221,8 +209,7 @@ def default(): m = Tensor(Dtype.I32, m.shape, m.flatten()) name = "min_i32_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int32) @@ -236,8 +223,7 @@ def broadcast(): m = Tensor(Dtype.I32, m.shape, m.flatten()) name = "min_i32_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -256,8 +242,7 @@ def default(): m = Tensor(Dtype.I8, m.shape, m.flatten()) name = "min_i8_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(0, 6, (2, 2)).astype(np.int8) @@ -271,8 +256,7 @@ def broadcast(): m = Tensor(Dtype.I8, m.shape, m.flatten()) name = "min_i8_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -295,8 +279,7 @@ def default(): m.flatten(), FixedImpl.FP8x23)) name = "min_fp8x23_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -314,8 +297,7 @@ def broadcast(): m.flatten(), FixedImpl.FP8x23)) name = "min_fp8x23_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) default() broadcast() @@ -338,8 +320,7 @@ def default(): m.flatten(), FixedImpl.FP16x16)) name = "min_fp16x16_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) def broadcast(): x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) @@ -357,8 +338,7 @@ def broadcast(): m.flatten(), FixedImpl.FP16x16)) name = "min_fp16x16_broadcast_three_tensors" - make_node([x, y, z], [m], name) - make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span())", name) default() broadcast() diff --git a/nodegen/node/mul.py b/nodegen/node/mul.py index 2922c6bc1..63b0b863a 100644 --- a/nodegen/node/mul.py +++ b/nodegen/node/mul.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Mul(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "mul_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "mul_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "mul_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "mul_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "mul_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "mul_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) default() @@ -112,7 +106,6 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "mul_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) def broadcast(): @@ -128,7 +121,6 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "mul_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) default() @@ -149,7 +141,6 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "mul_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) def broadcast(): @@ -165,7 +156,6 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "mul_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.mul(@input_1)", name) default() diff --git a/nodegen/node/neg.py b/nodegen/node/neg.py index a78456428..c35aca0c6 100644 --- a/nodegen/node/neg.py +++ b/nodegen/node/neg.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Neg(RunAll): @@ -13,7 +13,6 @@ def neg_i32(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "neg_i32" - make_node([x], [y], name) make_test([x], y, "input_0.neg()", name) @staticmethod @@ -25,7 +24,6 @@ def neg_i8(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "neg_i8" - make_node([x], [y], name) make_test([x], y, "input_0.neg()", name) @staticmethod @@ -38,7 +36,6 @@ def neg_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "neg_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.neg()", name) @staticmethod @@ -51,5 +48,4 @@ def neg_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "neg_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.neg()", name) diff --git a/nodegen/node/nonzero.py b/nodegen/node/nonzero.py index 213331671..9322d75d2 100644 --- a/nodegen/node/nonzero.py +++ b/nodegen/node/nonzero.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Nonzero(RunAll): @@ -14,7 +14,6 @@ def nonzero_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_u32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -26,7 +25,6 @@ def nonzero_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_u32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -43,7 +41,6 @@ def nonzero_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_i32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -55,7 +52,6 @@ def nonzero_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_i32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -73,7 +69,6 @@ def nonzero_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_i8_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -85,7 +80,6 @@ def nonzero_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_i8_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -103,7 +97,6 @@ def nonzero_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_fp8x23_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -116,7 +109,6 @@ def nonzero_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_fp8x23_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -134,7 +126,6 @@ def nonzero_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_fp16x16_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) @@ -147,7 +138,6 @@ def nonzero_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "nonzero_fp16x16_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.nonzero()", name) diff --git a/nodegen/node/or.py b/nodegen/node/or.py index f67778749..a39d2adb3 100644 --- a/nodegen/node/or.py +++ b/nodegen/node/or.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Or(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) default() @@ -111,7 +105,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) def broadcast(): @@ -126,7 +119,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) default() @@ -146,7 +138,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) def broadcast(): @@ -161,7 +152,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "or_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.or(@input_1)", name) default() diff --git a/nodegen/node/reduce_sum.py b/nodegen/node/reduce_sum.py index 3a4449032..111724001 100644 --- a/nodegen/node/reduce_sum.py +++ b/nodegen/node/reduce_sum.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Reduce_sum(RunAll): @@ -14,7 +14,6 @@ def reduce_sum_1D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_u32_1D" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -27,7 +26,6 @@ def default(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_u32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -39,7 +37,6 @@ def keepdims(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_u32_2D_keepdims" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, true)", name) @@ -51,7 +48,6 @@ def axis_1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_u32_2D_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(1, false)", name) @@ -71,7 +67,6 @@ def reduce_sum_1D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reduce_sum_i32_1D" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -84,7 +79,6 @@ def default(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reduce_sum_i32_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -96,7 +90,6 @@ def keepdims(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reduce_sum_i32_2D_keepdims" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, true)", name) @@ -108,7 +101,6 @@ def axis_1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reduce_sum_i32_2D_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(1, false)", name) @@ -128,7 +120,6 @@ def reduce_sum_1D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "reduce_sum_i8_1D" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -141,7 +132,6 @@ def default(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "reduce_sum_i8_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -153,7 +143,6 @@ def keepdims(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "reduce_sum_i8_2D_keepdims" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, true)", name) @@ -165,7 +154,6 @@ def axis_1(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "reduce_sum_i8_2D_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(1, false)", name) @@ -187,7 +175,6 @@ def reduce_sum_1D(): y.flatten(), FixedImpl.FP8x23)) name = "reduce_sum_fp8x23_1D" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -202,7 +189,6 @@ def default(): y.flatten(), FixedImpl.FP8x23)) name = "reduce_sum_fp8x23_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -216,7 +202,6 @@ def keepdims(): y.flatten(), FixedImpl.FP8x23)) name = "reduce_sum_fp8x23_2D_keepdims" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, true)", name) @@ -230,7 +215,6 @@ def axis_1(): y.flatten(), FixedImpl.FP8x23)) name = "reduce_sum_fp8x23_2D_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(1, false)", name) @@ -253,7 +237,6 @@ def reduce_sum_1D(): y.flatten(), FixedImpl.FP16x16)) name = "reduce_sum_fp16x16_1D" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -268,7 +251,6 @@ def default(): y.flatten(), FixedImpl.FP16x16)) name = "reduce_sum_fp16x16_2D_default" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, false)", name) @@ -282,7 +264,6 @@ def keepdims(): y.flatten(), FixedImpl.FP16x16)) name = "reduce_sum_fp16x16_2D_keepdims" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(0, true)", name) @@ -296,7 +277,6 @@ def axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "reduce_sum_fp16x16_2D_axis_1" - make_node([x], [y], name) make_test( [x], y, "input_0.reduce_sum(1, false)", name) diff --git a/nodegen/node/relu.py b/nodegen/node/relu.py index 5e72850b5..cf46cb736 100644 --- a/nodegen/node/relu.py +++ b/nodegen/node/relu.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, Trait, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, Trait, FixedImpl import tensorflow as tf @@ -16,7 +16,6 @@ def relu_i32(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "relu_i32" - make_node([x], [y], name) make_test([x], y, "NNTrait::relu(@input_0)", name, Trait.NN) @@ -30,7 +29,6 @@ def relu_i8(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "relu_i8" - make_node([x], [y], name) make_test([x], y, "NNTrait::relu(@input_0)", name, Trait.NN) @@ -46,7 +44,6 @@ def relu_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "relu_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::relu(@input_0)", name, Trait.NN) @@ -62,6 +59,5 @@ def relu_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "relu_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::relu(@input_0)", - name, Trait.NN) \ No newline at end of file + name, Trait.NN) diff --git a/nodegen/node/round.py b/nodegen/node/round.py index 1d12c3fdc..52b6fcc60 100644 --- a/nodegen/node/round.py +++ b/nodegen/node/round.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Round(RunAll): @@ -13,7 +13,6 @@ def round_fp8x23(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "round_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.round()", name) @staticmethod @@ -25,5 +24,4 @@ def round_fp16x16(): y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "round_fp16x16" - make_node([x], [y], name) - make_test([x], y, "input_0.round()", name) \ No newline at end of file + make_test([x], y, "input_0.round()", name) diff --git a/nodegen/node/scatter.py b/nodegen/node/scatter.py index 3e833a840..77b136e1f 100644 --- a/nodegen/node/scatter.py +++ b/nodegen/node/scatter.py @@ -1,7 +1,6 @@ import numpy as np -import torch from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait # The below ScatterElements' numpy implementation is from https://stackoverflow.com/a/46204790/11767360 def scatter_elements(data, indices, updates, axis=0, reduction="none"): # type: ignore @@ -91,10 +90,9 @@ def default(): y.flatten(), FixedImpl.FP16x16)) name = "scatter_fp16x16_3d_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis_1(): x1 = np.zeros((3, 3)).astype(np.int64) @@ -113,10 +111,9 @@ def axis_1(): y.flatten(), FixedImpl.FP16x16)) name = "scatter_fp16x16_3d_axis1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis_1_add(): x1 = np.zeros((3, 3)).astype(np.int64) @@ -135,10 +132,9 @@ def axis_1_add(): y.flatten(), FixedImpl.FP16x16)) name = "scatter_fp16x16_3d_axis1_add" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add'))", - file_name= name) + name= name) default() axis_1() @@ -166,10 +162,9 @@ def default(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "scatter_fp8x23_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1(): @@ -188,10 +183,9 @@ def axis1(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "scatter_fp8x23_axis1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1_mul(): x1 = np.zeros((3, 3)).astype(np.int64) @@ -209,10 +203,9 @@ def axis1_mul(): y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) name = "scatter_fp8x23_mul" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul'))", - file_name= name) + name= name) default() axis1() @@ -239,10 +232,9 @@ def default(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "scatter_i8_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1(): x1 = np.zeros((3, 3)).astype(np.int8) @@ -260,10 +252,9 @@ def axis1(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "scatter_i8_axis1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1_max(): @@ -282,10 +273,9 @@ def axis1_max(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "scatter_i8_axis1_max" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max'))", - file_name= name) + name= name) default() axis1() @@ -312,10 +302,9 @@ def default(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "scatter_i8_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1(): x1 = np.zeros((3, 3)).astype(np.int32) @@ -333,10 +322,9 @@ def axis1(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "scatter_i8_axis1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis_min(): x1 = np.zeros((3, 3)).astype(np.int32) @@ -354,10 +342,9 @@ def axis_min(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "scatter_i8_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('min'))", - file_name= name) + name= name) default() axis1() @@ -385,10 +372,9 @@ def default(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "scatter_u32_default" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis1(): @@ -407,10 +393,9 @@ def axis1(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "scatter_u32_axis1" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", - file_name= name) + name= name) def axis_add(): x1 = np.zeros((3, 3)).astype(np.uint32) @@ -428,12 +413,11 @@ def axis_add(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "scatter_u32_add" - make_node([x1, x2, x3], [y], name) make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add'))", - file_name= name) + name= name) default() axis1() axis_add() - scatter_3D() \ No newline at end of file + scatter_3D() diff --git a/nodegen/node/sigmoid.py b/nodegen/node/sigmoid.py index 0f5052eae..e67d4d89b 100644 --- a/nodegen/node/sigmoid.py +++ b/nodegen/node/sigmoid.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait import tensorflow as tf @@ -17,7 +17,6 @@ def fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "sigmoid_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::sigmoid(@input_0)", name, Trait.NN) @@ -32,7 +31,6 @@ def fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "sigmoid_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::sigmoid(@input_0)", name, Trait.NN) diff --git a/nodegen/node/sign.py b/nodegen/node/sign.py index a9003f342..8945e5479 100644 --- a/nodegen/node/sign.py +++ b/nodegen/node/sign.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Sign(RunAll): @staticmethod @@ -13,7 +13,6 @@ def sign(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "sign_i8" - make_node([x], [y], name) make_test( [x], y, "input_0.sign()", name) sign() @@ -28,7 +27,6 @@ def sign(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "sign_i32" - make_node([x], [y], name) make_test( [x], y, "input_0.sign()", name) sign() @@ -44,7 +42,6 @@ def sign(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "sign_fail" - make_node([x], [y], name) make_test( [x], y, "input_0.sign()", name) sign() @@ -60,7 +57,6 @@ def sign(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "sign_fP16x16" - make_node([x], [y], name) make_test( [x], y, "input_0.sign()", name) sign() @@ -76,7 +72,6 @@ def sign(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "sign_fP8x23" - make_node([x], [y], name) make_test( [x], y, "input_0.sign()", name) - sign() \ No newline at end of file + sign() diff --git a/nodegen/node/sin.py b/nodegen/node/sin.py index e62eb38d8..baecf0c55 100644 --- a/nodegen/node/sin.py +++ b/nodegen/node/sin.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Sin(RunAll): @@ -16,7 +16,6 @@ def sin_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "sin_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.sin()", name) @staticmethod @@ -30,5 +29,4 @@ def sin_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "sin_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.sin()", name) diff --git a/nodegen/node/sinh.py b/nodegen/node/sinh.py index 27710d3ed..a76f6e6c3 100644 --- a/nodegen/node/sinh.py +++ b/nodegen/node/sinh.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Sinh(RunAll): @@ -16,7 +16,6 @@ def sinh_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "sinh_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.sinh()", name) @staticmethod @@ -30,5 +29,4 @@ def sinh_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "sinh_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.sinh()", name) diff --git a/nodegen/node/slice.py b/nodegen/node/slice.py index b87ec3bc9..7124f984e 100644 --- a/nodegen/node/slice.py +++ b/nodegen/node/slice.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Slice(RunAll): @@ -14,7 +14,6 @@ def slice_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "slice_u32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 2].span(), array![2, 4].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 1].span()))", name) @@ -26,7 +25,6 @@ def slice_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "slice_u32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 0].span(), array![3, 10].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 3].span()))", name) @@ -43,7 +41,6 @@ def slice_2D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "slice_i32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 2].span(), array![2, 4].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 1].span()))", name) @@ -55,7 +52,6 @@ def slice_3D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "slice_i32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 0].span(), array![3, 10].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 3].span()))", name) @@ -73,7 +69,6 @@ def slice_2D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "slice_i8_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 2].span(), array![2, 4].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 1].span()))", name) @@ -85,7 +80,6 @@ def slice_3D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "slice_i8_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 0].span(), array![3, 10].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 3].span()))", name) @@ -103,7 +97,6 @@ def slice_2D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "slice_fp8x23_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 2].span(), array![2, 4].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 1].span()))", name) @@ -116,7 +109,6 @@ def slice_3D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "slice_fp8x23_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 0].span(), array![3, 10].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 3].span()))", name) @@ -134,7 +126,6 @@ def slice_2D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "slice_fp16x16_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 2].span(), array![2, 4].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 1].span()))", name) @@ -147,7 +138,6 @@ def slice_3D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "slice_fp16x16_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.slice(array![0, 0].span(), array![3, 10].span(), Option::Some(array![0, 1].span()), Option::Some(array![1, 3].span()))", name) diff --git a/nodegen/node/softmax.py b/nodegen/node/softmax.py index 2c42b9844..9e5ee99c1 100644 --- a/nodegen/node/softmax.py +++ b/nodegen/node/softmax.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def softmax(x: np.ndarray, axis: int = -1) -> np.ndarray: @@ -24,7 +24,6 @@ def fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "softmax_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::softmax(@input_0, 0)", name, Trait.NN) @@ -39,7 +38,6 @@ def fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "softmax_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::softmax(@input_0, 1)", name, Trait.NN) diff --git a/nodegen/node/softplus.py b/nodegen/node/softplus.py index 9c8b72106..3f7238df0 100644 --- a/nodegen/node/softplus.py +++ b/nodegen/node/softplus.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def softplus(x: np.ndarray) -> np.ndarray: @@ -21,7 +21,6 @@ def fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "softplus_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::softplus(@input_0)", name, Trait.NN) @@ -35,7 +34,6 @@ def fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "softplus_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::softplus(@input_0)", name, Trait.NN) diff --git a/nodegen/node/softsign.py b/nodegen/node/softsign.py index 381d3e2d7..b435fa43a 100644 --- a/nodegen/node/softsign.py +++ b/nodegen/node/softsign.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def softsign(x: np.ndarray) -> np.ndarray: @@ -21,7 +21,6 @@ def fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "softsign_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::softsign(@input_0)", name, Trait.NN) @@ -35,7 +34,6 @@ def fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "softsign_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::softsign(@input_0)", name, Trait.NN) diff --git a/nodegen/node/sqrt.py b/nodegen/node/sqrt.py index 62222c43b..f577682ad 100644 --- a/nodegen/node/sqrt.py +++ b/nodegen/node/sqrt.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Sqrt(RunAll): @@ -16,7 +16,6 @@ def sqrt_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "sqrt_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.sqrt()", name) @staticmethod @@ -30,5 +29,4 @@ def sqrt_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "sqrt_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.sqrt()", name) diff --git a/nodegen/node/squeeze.py b/nodegen/node/squeeze.py index 81661833e..d34e82b39 100644 --- a/nodegen/node/squeeze.py +++ b/nodegen/node/squeeze.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Squeeze(RunAll): @@ -14,7 +14,6 @@ def squeeze(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "squeeze_i8" - make_node([x], [y], name) make_test( [x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) squeeze() @@ -29,7 +28,6 @@ def squeeze(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "squeeze_i32" - make_node([x], [y], name) make_test( [x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) squeeze() @@ -44,7 +42,6 @@ def squeeze(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "squeeze_u32" - make_node([x], [y], name) make_test( [x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) squeeze() @@ -61,7 +58,6 @@ def squeeze(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "squeeze_fP16x16" - make_node([x], [y], name) make_test( [x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) squeeze() @@ -78,7 +74,6 @@ def squeeze(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "squeeze_fP8x23" - make_node([x], [y], name) make_test( [x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) - squeeze() \ No newline at end of file + squeeze() diff --git a/nodegen/node/sub.py b/nodegen/node/sub.py index b16ef020f..dcce20452 100644 --- a/nodegen/node/sub.py +++ b/nodegen/node/sub.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Sub(RunAll): @@ -16,7 +16,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "sub_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) def broadcast(): @@ -29,7 +28,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "sub_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) default() @@ -47,7 +45,6 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "sub_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) def broadcast(): @@ -60,7 +57,6 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "sub_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) default() @@ -78,7 +74,6 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "sub_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) def broadcast(): @@ -91,7 +86,6 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "sub_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) default() @@ -112,7 +106,6 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "sub_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) def broadcast(): @@ -128,7 +121,6 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "sub_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) default() @@ -149,7 +141,6 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "sub_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) def broadcast(): @@ -165,7 +156,6 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "sub_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.sub(@input_1)", name) default() diff --git a/nodegen/node/tanh.py b/nodegen/node/tanh.py index f09dc1342..e8a7d6db2 100644 --- a/nodegen/node/tanh.py +++ b/nodegen/node/tanh.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Tanh(RunAll): @@ -16,7 +16,6 @@ def tanh_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "tanh_fp8x23" - make_node([x], [y], name) make_test([x], y, "input_0.tanh()", name) @staticmethod @@ -30,5 +29,4 @@ def tanh_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "tanh_fp16x16" - make_node([x], [y], name) make_test([x], y, "input_0.tanh()", name) diff --git a/nodegen/node/thresholded_relu.py b/nodegen/node/thresholded_relu.py index 9785cc779..2da9f5243 100644 --- a/nodegen/node/thresholded_relu.py +++ b/nodegen/node/thresholded_relu.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Thresholded_relu(RunAll): @@ -20,7 +20,6 @@ def thresholded_relu_fp8x23(): y.flatten(), FixedImpl.FP8x23)) name = "thresholded_relu_fp8x23" - make_node([x], [y], name) make_test([x], y, "NNTrait::thresholded_relu(@input_0, @FixedTrait::new(256, false))", name, Trait.NN) @@ -39,6 +38,5 @@ def thresholded_relu_fp16x16(): y.flatten(), FixedImpl.FP16x16)) name = "thresholded_relu_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::thresholded_relu(@input_0, @FixedTrait::new(65536, false))", name, Trait.NN) diff --git a/nodegen/node/transpose.py b/nodegen/node/transpose.py index f18e82faf..192ee2f1f 100644 --- a/nodegen/node/transpose.py +++ b/nodegen/node/transpose.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Transpose(RunAll): @@ -14,7 +14,6 @@ def transpose_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "transpose_u32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 0].span())", name) @@ -26,7 +25,6 @@ def transpose_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "transpose_u32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 2, 0].span())", name) @@ -43,7 +41,6 @@ def transpose_2D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "transpose_i32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 0].span())", name) @@ -55,7 +52,6 @@ def transpose_3D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "transpose_i32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 2, 0].span())", name) @@ -73,7 +69,6 @@ def transpose_2D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "transpose_i8_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 0].span())", name) @@ -85,7 +80,6 @@ def transpose_3D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "transpose_i8_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 2, 0].span())", name) @@ -103,7 +97,6 @@ def transpose_2D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "transpose_fp8x23_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 0].span())", name) @@ -116,7 +109,6 @@ def transpose_3D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "transpose_fp8x23_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 2, 0].span())", name) @@ -134,7 +126,6 @@ def transpose_2D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "transpose_fp16x16_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 0].span())", name) @@ -147,7 +138,6 @@ def transpose_3D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "transpose_fp16x16_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.transpose(array![1, 2, 0].span())", name) diff --git a/nodegen/node/unsqueeze.py b/nodegen/node/unsqueeze.py index 60c11024d..527706ce9 100644 --- a/nodegen/node/unsqueeze.py +++ b/nodegen/node/unsqueeze.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Unsqueeze(RunAll): @@ -16,7 +16,6 @@ def unsqueeze_2D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "unsqueeze_u32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![1, 4, 0].span())", name) @@ -30,7 +29,6 @@ def unsqueeze_3D(): y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "unsqueeze_u32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![5, 4, 2].span())", name) @@ -49,7 +47,6 @@ def unsqueeze_2D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "unsqueeze_i32_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![1, 4, 0].span())", name) @@ -63,7 +60,6 @@ def unsqueeze_3D(): y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "unsqueeze_i32_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![5, 4, 2].span())", name) @@ -83,7 +79,6 @@ def unsqueeze_2D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "unsqueeze_i8_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![1, 4, 0].span())", name) @@ -97,7 +92,6 @@ def unsqueeze_3D(): y = Tensor(Dtype.I8, y.shape, y.flatten()) name = "unsqueeze_i8_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![5, 4, 2].span())", name) @@ -117,7 +111,6 @@ def unsqueeze_2D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "unsqueeze_fp8x23_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![1, 4, 0].span())", name) @@ -132,7 +125,6 @@ def unsqueeze_3D(): y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "unsqueeze_fp8x23_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![5, 4, 2].span())", name) @@ -152,7 +144,6 @@ def unsqueeze_2D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "unsqueeze_fp16x16_2d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![1, 4, 0].span())", name) @@ -167,7 +158,6 @@ def unsqueeze_3D(): y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "unsqueeze_fp16x16_3d" - make_node([x], [y], name) make_test( [x], y, "input_0.unsqueeze(array![5, 4, 2].span())", name) diff --git a/nodegen/node/where.py b/nodegen/node/where.py index 9b86ae663..be5dbf41b 100644 --- a/nodegen/node/where.py +++ b/nodegen/node/where.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Where(RunAll): @@ -20,7 +20,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "where_u32" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) def broadcast(): @@ -36,7 +35,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "where_u32_broadcast" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) default() @@ -57,7 +55,6 @@ def default(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "where_i32" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) def broadcast(): @@ -73,7 +70,6 @@ def broadcast(): z = Tensor(Dtype.I32, z.shape, z.flatten()) name = "where_i32_broadcast" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) default() @@ -94,7 +90,6 @@ def default(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "where_i8" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) def broadcast(): @@ -110,7 +105,6 @@ def broadcast(): z = Tensor(Dtype.I8, z.shape, z.flatten()) name = "where_i8_broadcast" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) default() @@ -135,7 +129,6 @@ def default(): z.flatten(), FixedImpl.FP8x23)) name = "where_fp8x23" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) def broadcast(): @@ -155,7 +148,6 @@ def broadcast(): z.flatten(), FixedImpl.FP8x23)) name = "where_fp8x23_broadcast" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) default() @@ -180,7 +172,6 @@ def default(): z.flatten(), FixedImpl.FP16x16)) name = "where_fp16x16" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) def broadcast(): @@ -200,7 +191,6 @@ def broadcast(): z.flatten(), FixedImpl.FP16x16)) name = "where_fp16x16_broadcast" - make_node([cond, x, y], [z], name) make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) default() diff --git a/nodegen/node/xor.py b/nodegen/node/xor.py index 0b77a0f5a..bd8c025c6 100644 --- a/nodegen/node/xor.py +++ b/nodegen/node/xor.py @@ -1,6 +1,6 @@ import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Xor(RunAll): @@ -17,7 +17,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_u32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) def broadcast(): @@ -30,7 +29,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_u32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) default() @@ -48,7 +46,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_i32" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) def broadcast(): @@ -61,7 +58,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_i32_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) default() @@ -79,7 +75,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_i8" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) def broadcast(): @@ -92,7 +87,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_i8_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) default() @@ -112,7 +106,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_fp8x23" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) def broadcast(): @@ -127,7 +120,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_fp8x23_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) default() @@ -147,7 +139,6 @@ def default(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_fp16x16" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) def broadcast(): @@ -162,7 +153,6 @@ def broadcast(): z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "xor_fp16x16_broadcast" - make_node([x, y], [z], name) make_test([x, y], z, "input_0.xor(@input_1)", name) default() From 82daa218d0d95deb45ddad6c6c1c8ee5c1d2fe6a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 09:18:45 +0200 Subject: [PATCH 057/127] fix classifier --- src/operators.cairo | 3 +- src/operators/matrix.cairo | 15 +- src/operators/ml/tree_ensemble.cairo | 1 - .../tree_ensemble_classifier.cairo | 310 ++++++++---------- .../tree_ensemble_classifier2.cairo | 197 ----------- src/operators/vec.cairo | 60 ++++ tests/ml/tree_ensemble_classifier.cairo | 17 +- 7 files changed, 216 insertions(+), 387 deletions(-) delete mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo create mode 100644 src/operators/vec.cairo diff --git a/src/operators.cairo b/src/operators.cairo index eee74cf89..9f8628255 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -1,4 +1,5 @@ mod tensor; mod nn; mod ml; -mod matrix; \ No newline at end of file +mod matrix; +mod vec; \ No newline at end of file diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 5f49c2b7e..1e19e0bc2 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,21 +1,22 @@ use core::array::ArrayTrait; use core::option::OptionTrait; -use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; +// use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; use orion::numbers::NumberTrait; +use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; -impl VecCopy of Copy>; -impl NullCopy of Copy>>; -impl VecDrop of Drop>; -impl NullDrop of Drop>>; - -#[derive(Copy, Drop)] struct MutMatrix { data: NullableVec, rows: usize, cols: usize, } +impl MutMatrixDestruct> of Destruct> { + fn destruct(self: MutMatrix) nopanic { + self.data.destruct() + } +} + #[generate_trait] impl MutMatrixImpl< T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 32177e813..b02ddeb4d 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,3 +1,2 @@ mod core; mod tree_ensemble_classifier; -mod tree_ensemble_classifier2; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 4d7723d8e..f4e9aac2f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,9 @@ +use core::array::ArrayTrait; +use core::clone::Clone; +use core::box::BoxTrait; +use core::traits::Into; +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; use core::array::SpanTrait; use core::nullable::NullableTrait; use core::dict::Felt252DictTrait; @@ -7,10 +13,14 @@ use nullable::{match_nullable, FromNullableResult}; use orion::operators::tensor::{Tensor, TensorTrait}; use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; use orion::numbers::NumberTrait; +use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::{SpanTraitExt}; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; +use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; + use debug::PrintTrait; #[derive(Destruct)] @@ -20,7 +30,7 @@ struct TreeEnsembleClassifier { class_nodeids: Span, class_treeids: Span, class_weights: Span, - class_labels: Span, + classlabels: Span, base_values: Option>, post_transform: PostTransform, } @@ -34,7 +44,6 @@ enum PostTransform { Probit, } - #[generate_trait] impl TreeEnsembleClassifierImpl< T, @@ -47,212 +56,163 @@ impl TreeEnsembleClassifierImpl< +Add, +TensorTrait, +TensorTrait, - +PrintTrait + +PrintTrait, > of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { + let leaves_index = self.ensemble.leave_index_tree(X); + let n_classes = self.classlabels.len(); + let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); + + // Set base values + if self.base_values.is_some() { + let mut base_values = self.base_values.unwrap(); + let mut row: usize = 0; + loop { + if row == res.rows { + break; + } - (predictions, final_scores) - } -} + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } + let value = *base_values.pop_front().unwrap(); + res.set(row, col, value); -fn compute_scores, +Copy, +NumberTrait, +Add, +PrintTrait>( - ref self: TreeEnsembleClassifier, leaf_indices: Tensor -) -> (Span, Felt252Dict::>) { - // Initialize the scores array, either with base_values or zeros - let num_samples = *leaf_indices.shape[0]; - let num_classes = self.class_labels.len(); - let mut scores_shape = array![num_samples, num_classes].span(); + col += 1 + }; - // Store scores in dictionary because of immutability of array. - let mut scores_data: Felt252Dict> = Default::default(); - if self.base_values.is_some() { - // Repeat base values for each sample - let mut sample_index: usize = 0; - loop { - if sample_index == num_samples { - break; + row += 1; } - - let mut class_index: usize = 0; + } else { + let mut row: usize = 0; loop { - if class_index == num_classes { + if row == res.rows { break; } - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(sample_index.into(), class_index.into()); - scores_data - .insert(key, NullableTrait::new(*self.base_values.unwrap().at(class_index))); + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } - class_index += 1; - }; + res.set(row, col, NumberTrait::zero()); + + col += 1 + }; - sample_index += 1; + row += 1; + } } - } - // Compute class index mapping - let mut class_index: Felt252Dict>> = Default::default(); - let mut class_weights = self.class_weights; - let mut class_ids = self.class_ids; - let mut class_nodeids = self.class_nodeids; - let mut class_treeids = self.class_treeids; - loop { - match class_weights.pop_front() { - Option::Some(class_weight) => { - let mut class_id: usize = *class_ids.pop_front().unwrap(); - let mut node_id: usize = *class_nodeids.pop_front().unwrap(); - let mut tree_id: usize = *class_treeids.pop_front().unwrap(); + let mut class_index: Felt252Dict>> = Default::default(); + let mut i: usize = 0; + loop { + if i == self.class_treeids.len() { + break; + } + + let tid = *self.class_treeids[i]; + let nid = *self.class_nodeids[i]; - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(tree_id.into(), node_id.into()); + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tid.into(), nid.into()); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { + class_index.insert(key, NullableTrait::new(array![i].span())); + }, + FromNullableResult::NotNull(val) => { + let mut new_val = val.unbox(); + let new_val = new_val.concat(array![i].span()); + class_index.insert(key, NullableTrait::new(new_val)); + }, + } - let value = class_index.get(key); - match match_nullable(value) { - FromNullableResult::Null(()) => { - class_index - .insert( - key, NullableTrait::new(array![(class_id, *class_weight)].span()) + i += 1; + }; + let mut i: usize = 0; + loop { + if i == res.rows { + break; + } + + let mut indices = get_row(@leaves_index, i); + let mut t_index: Array> = ArrayTrait::new(); + loop { + match indices.pop_front() { + Option::Some(index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*index]).into(), + (*self.ensemble.atts.nodes_nodeids[*index]).into() ); + t_index.append(class_index.get(key).deref()); }, - FromNullableResult::NotNull(val) => { - let mut new_val = value.deref(); - let new_val = new_val.concat(array![(class_id, *class_weight)].span()); - class_index.insert(key, NullableTrait::new(new_val)); - }, + Option::None(_) => { break; } }; - }, - Option::None(_) => { break; } - }; - }; - - // Update scores based on class index mapping - let mut sample_index: usize = 0; - let mut leaf_indices_data = leaf_indices.data; - loop { - match leaf_indices_data.pop_front() { - Option::Some(leaf_index) => { - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash( - (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), - (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() - ); - - match match_nullable(class_index.get(key)) { - FromNullableResult::Null(()) => { continue; }, - FromNullableResult::NotNull(class_weight_pairs) => { - let mut class_weight_pairs_span = class_weight_pairs.unbox(); + }; + let mut t_index = t_index.span(); + loop { + match t_index.pop_front() { + Option::Some(its) => { + let mut its = *its; loop { - match class_weight_pairs_span.pop_front() { - Option::Some(class_weight_pair) => { - let (class_id, class_weight) = *class_weight_pair; - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash((sample_index).into(), (class_id).into()); - - let value = scores_data.get(key); - match match_nullable(value) { - FromNullableResult::Null(()) => { - scores_data - .insert(key, NullableTrait::new(class_weight)); + match its.pop_front() { + Option::Some(it) => { + let prev_val = match res.get(i, *self.class_ids[*it]) { + Option::Some(val) => { + res + .set( + i, + *self.class_ids[*it], + val + *self.class_weights[*it] + ); }, - FromNullableResult::NotNull(val) => { - scores_data - .insert( - key, - NullableTrait::new(value.deref() + class_weight) + Option::None => { + res + .set( + i, + *self.class_ids[*it], + *self.class_weights[*it] ); }, - } + }; }, Option::None(_) => { break; } }; - } + }; }, - } - - sample_index += 1; - }, - Option::None(_) => { break; } + Option::None(_) => { break; } + }; + }; + i += 1; }; - }; - - // Apply post-transform to scores - match self.post_transform { - PostTransform::None => {}, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), - } - - (scores_shape, scores_data) -} - -fn classify< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +PartialOrd, - +TensorTrait, - +TensorTrait, ->( - ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) -) -> (Tensor, Tensor) { - let (scores_shape, mut scores_data) = scores; - let num_samples = *scores_shape[0]; - let num_classes = *scores_shape[1]; - let predictions_shape = array![num_samples].span(); - let mut final_scores_shape = scores_shape; - let mut predictions_data = ArrayTrait::new(); - let mut final_scores_data = ArrayTrait::new(); - - let mut sample_index: usize = 0; - loop { - if sample_index == num_samples { - break; - } + // Post Transform + let mut new_scores = match self.post_transform { + PostTransform::None => { res }, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + }; - // Placeholder for the minimum value for type T - let mut max_score = NumberTrait::::min_value(); - let mut max_class_index = 0; + // Labels + let mut labels = new_scores.argmax(1); - let mut class_index: usize = 0; + let mut labels_list = ArrayTrait::new(); loop { - if class_index == num_classes { - break; - } - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key].deref(); - - final_scores_data.append(score); - - if score > max_score { - max_score = score; - max_class_index = class_index; - } - - class_index += 1; + match labels.pop_front() { + Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, + Option::None(_) => { break; } + }; }; - predictions_data.append(max_class_index); - sample_index += 1; - }; - - ( - TensorTrait::new(predictions_shape, predictions_data.span()), - TensorTrait::new(final_scores_shape, final_scores_data.span()) - ) + return (labels_list.span(), new_scores); + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo deleted file mode 100644 index cc6b5f4a0..000000000 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo +++ /dev/null @@ -1,197 +0,0 @@ -use core::array::ArrayTrait; -use core::clone::Clone; -use core::box::BoxTrait; -use core::traits::Into; -use core::option::OptionTrait; -use orion::operators::matrix::MutMatrixTrait; -use core::array::SpanTrait; -use core::nullable::NullableTrait; -use core::dict::Felt252DictTrait; -use core::dict::Felt252DictEntryTrait; -use nullable::{match_nullable, FromNullableResult}; - -use orion::operators::tensor::{Tensor, TensorTrait}; -use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; -use orion::numbers::NumberTrait; -use orion::utils::get_row; - -use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -use alexandria_data_structures::array_ext::{SpanTraitExt}; - -use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; - -use debug::PrintTrait; - -#[derive(Destruct)] -struct TreeEnsembleClassifier { - ensemble: TreeEnsemble, - class_ids: Span, - class_nodeids: Span, - class_treeids: Span, - class_weights: Span, - classlabels: Span, - base_values: Option>, - post_transform: PostTransform, -} - -#[derive(Copy, Drop)] -enum PostTransform { - None, - Softmax, - Logistic, - SoftmaxZero, - Probit, -} - -#[generate_trait] -impl TreeEnsembleClassifierImpl< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +PartialOrd, - +PartialEq, - +Add, - +TensorTrait, - +TensorTrait, - +PrintTrait -> of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { - let leaves_index = self.ensemble.leave_index_tree(X); - let n_classes = self.classlabels.len(); - let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); - - // Set base values - if self.base_values.is_some() { - let mut base_values = self.base_values.unwrap(); - let mut row: usize = 0; - loop { - if row == res.rows { - break; - } - - let mut col: usize = 0; - loop { - if col == res.cols { - break; - } - - let value = *base_values.pop_front().unwrap(); - res.set(row, col, value); - - col += 1 - }; - - row += 1; - } - } - - let mut class_index: Felt252Dict>> = Default::default(); - let mut i: usize = 0; - loop { - if i == self.class_treeids.len() { - break; - } - - let tid = *self.class_treeids[i]; - let nid = *self.class_nodeids[i]; - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(tid.into(), nid.into()); - match match_nullable(class_index.get(key)) { - FromNullableResult::Null(()) => { continue; }, - FromNullableResult::NotNull(val) => { - let mut new_val = val.unbox(); - let new_val = new_val.concat(array![i].span()); - class_index.insert(key, NullableTrait::new(new_val)); - }, - } - - i += 1; - }; - let mut i: usize = 0; - loop { - if i == res.rows { - break; - } - - let mut indices = get_row(@leaves_index, i); - let mut t_index: Array> = ArrayTrait::new(); - loop { - match indices.pop_front() { - Option::Some(index) => { - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash( - (*self.ensemble.atts.nodes_treeids[*index]).into(), - (*self.ensemble.atts.nodes_treeids[*index]).into() - ); - t_index.append(class_index.get(key).deref()); - }, - Option::None(_) => { break; } - }; - }; - let mut t_index = t_index.span(); - loop { - match t_index.pop_front() { - Option::Some(its) => { - loop { - let mut its = *its; - match its.pop_front() { - Option::Some(it) => { - let prev_val = res.get(i, *self.class_ids[*it]); - match prev_val { - Option::Some(prev) => { - res - .set( - i, - *self.class_ids[*it], - prev + *self.class_weights[*it] - ); - }, - Option::None => { - res - .set( - i, - *self.class_ids[*it], - *self.class_weights[*it] - ); - } - } - }, - Option::None(_) => { break; } - }; - }; - }, - Option::None(_) => { break; } - }; - }; - i += 1; - }; - - // TODO: Binary case - - // Post Transform - let mut new_scores = match self.post_transform { - PostTransform::None => { res }, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), - }; - - // Labels - let mut labels = new_scores.argmax(1); - let mut labels_list = ArrayTrait::new(); - loop { - match labels.pop_front() { - Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, - Option::None(_) => { break; } - }; - }; - - return (labels, new_scores); - } -} - diff --git a/src/operators/vec.cairo b/src/operators/vec.cairo new file mode 100644 index 000000000..6fb43b6db --- /dev/null +++ b/src/operators/vec.cairo @@ -0,0 +1,60 @@ +use core::box::BoxTrait; +use core::traits::Into; +use alexandria_data_structures::vec::{VecTrait}; +use core::nullable::{Nullable, match_nullable, FromNullableResult}; +use orion::numbers::NumberTrait; + +struct NullableVec { + items: Felt252Dict>, + len: usize, +} + +impl DestructNullableVec> of Destruct> { + fn destruct(self: NullableVec) nopanic { + self.items.squash(); + } +} + +impl NullableVecImpl< + T, MAG, impl TDrop: Drop, impl TCopy: Copy, +NumberTrait +> of VecTrait, T> { + fn new() -> NullableVec { + NullableVec { items: Default::default(), len: 0 } + } + + fn get(ref self: NullableVec, index: usize) -> Option { + if (index < self.len()) { + return match match_nullable(self.items.get(index.into())) { + FromNullableResult::Null(()) => { Option::Some(NumberTrait::zero()) }, + FromNullableResult::NotNull(val) => { Option::Some(val.unbox()) }, + }; + } else { + Option::::None + } + } + + fn at(ref self: NullableVec, index: usize) -> T { + assert(index < self.len(), 'Index out of bounds'); + + return match self.get(index) { + Option::Some(val) => val, + Option::None => NumberTrait::zero(), + }; + } + + fn push(ref self: NullableVec, value: T) -> () { + self.items.insert(self.len.into(), nullable_from_box(BoxTrait::new(value))); + self.len = integer::u32_wrapping_add(self.len, 1_usize); + } + + fn set(ref self: NullableVec, index: usize, value: T) { + if index >= self.len() { + self.len = index + 1; + } + self.items.insert(index.into(), nullable_from_box(BoxTrait::new(value))); + } + + fn len(self: @NullableVec) -> usize { + *self.len + } +} diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index c5b24601a..a18811be0 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,3 +1,5 @@ +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; use core::array::SpanTrait; use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; @@ -5,14 +7,16 @@ use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier2::{ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + use debug::PrintTrait; #[test] -#[available_gas(2000000000)] +#[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi() { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -161,10 +165,11 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - let (prediction, score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + let (labels, mut score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + // (*labels.at(0)).print(); + // (*labels.at(1)).print(); + // (*labels.at(2)).print(); - // (*score.data.at(0)).print(); - // (*score.data.at(1)).print(); - // (*score.data.at(2)).print(); + score.get(0, 0).unwrap().print(); } From e58f6dec391649cd50591b3b23d66372ca3c6f2c Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 09:39:35 +0200 Subject: [PATCH 058/127] test none post transform case --- tests/ml/tree_ensemble_classifier.cairo | 51 ++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index a18811be0..9caaec039 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -10,7 +10,7 @@ use orion::operators::ml::tree_ensemble::core::{ use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; - +use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; use debug::PrintTrait; @@ -165,11 +165,50 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - let (labels, mut score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); - // (*labels.at(0)).print(); - // (*labels.at(1)).print(); - // (*labels.at(2)).print(); + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); - score.get(0, 0).unwrap().print(); + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 60075, sign: false }) == true, + 'score[0, 0] == 0.9166666' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, + 'score[0, 1] == 0' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 5461, sign: false }) == true, + 'score[0, 2] == 0.08333334' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 37329, sign: false }) == true, + 'score[1, 0] == 0.56960785' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 12528, sign: false }) == true, + 'score[1, 1] == 0.19117647' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 15677, sign: false }) == true, + 'score[1, 2] == 0.23921569' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, + 'score[2, 0] == 0.30294117' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 28257, sign: false }) == true, + 'score[2, 1] == 0.43117648' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 17424, sign: false }) == true, + 'score[2, 2] == 0.26588234' + ); } From 523c09b8a12f723db93f2f0a63b18f1d4ab5e17b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 10:09:29 +0200 Subject: [PATCH 059/127] add softmax postr transform --- src/operators/matrix.cairo | 83 +++++++- .../tree_ensemble_classifier.cairo | 10 +- tests/ml/tree_ensemble_classifier.cairo | 199 +++++++++++++++++- 3 files changed, 286 insertions(+), 6 deletions(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 1e19e0bc2..3de48a7e8 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,6 +1,5 @@ use core::array::ArrayTrait; use core::option::OptionTrait; -// use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; use orion::numbers::NumberTrait; use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; @@ -133,4 +132,86 @@ impl MutMatrixImpl< return result.span(); } + + /// Apply softmax to the matrix along the specified axis + /// Apply softmax to the matrix along the specified axis + fn softmax<+AddEq, +Div>(ref self: MutMatrix, axis: usize) -> MutMatrix { + assert(axis < 2, 'Invalid axis'); + + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + sum_exp += value.exp(); + + row += 1; + }; + + row = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + + row += 1; + }; + + col += 1; + }; + } else { + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + sum_exp += value.exp(); + + col += 1; + }; + + col = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + + col += 1; + }; + + row += 1; + }; + } + + result + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index f4e9aac2f..e9ac8a5c6 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -57,6 +57,8 @@ impl TreeEnsembleClassifierImpl< +TensorTrait, +TensorTrait, +PrintTrait, + +AddEq, + +Div > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); @@ -195,10 +197,10 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { PostTransform::None => { res }, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), + PostTransform::Softmax => { res.softmax(1) }, + PostTransform::Logistic => panic_with_felt252('Logistic not supported yet'), + PostTransform::SoftmaxZero => panic_with_felt252('SoftmaxZero not supported yet'), + PostTransform::Probit => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 9caaec039..3428a2fd5 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -17,7 +17,7 @@ use debug::PrintTrait; #[test] #[available_gas(200000000000)] -fn test_tree_ensemble_classifier_multi() { +fn test_tree_ensemble_classifier_multi_pt_none() { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -212,3 +212,200 @@ fn test_tree_ensemble_classifier_multi() { ); } +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_softmax() { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let classlabels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let post_transform = PostTransform::Softmax; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + classlabels, + base_values, + post_transform + }; + + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() + ); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, + 'score[0, 0] == 0.545123' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, + 'score[0, 1] == 0.217967' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, + 'score[0, 2] == 0.23691' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0] == 0.416047' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1] == 0.284965' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2] == 0.298988' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0] == 0.322535' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1] == 0.366664' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2] == 0.310801' + ); +} + From d9d628a18bfb85d3d05b644255389b715b17da29 Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Fri, 10 Nov 2023 10:00:56 +0100 Subject: [PATCH 060/127] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Fix=20cubit=20depe?= =?UTF-8?q?ndency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scarb.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarb.toml b/Scarb.toml index 502513ba4..ed13d778d 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,7 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion" [dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } -cubit = { git = "https://github.com/raphaelDkhn/cubit.git" } +cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" } [scripts] sierra = "cairo-compile . -r" From 5847a4ad6e8e3931aaa0fb4d61ca7786729471f5 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 10 Nov 2023 11:20:29 +0100 Subject: [PATCH 061/127] add sequence support --- nodegen/file_manager.py | 28 ++++++++++++++++++ nodegen/helpers.py | 63 ++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/nodegen/file_manager.py b/nodegen/file_manager.py index aaa4e189d..7e3779d65 100644 --- a/nodegen/file_manager.py +++ b/nodegen/file_manager.py @@ -77,3 +77,31 @@ def template(cls, func: str, dtype: str, refs: list[str], data: list[str], shape *[ " TensorTrait::new(shape.span(), data.span())"], *[ "}"], ] + + @classmethod + def template_sequence(cls, func: str, dtype: str, refs: list[str], data: list[list[str]], shape: list[tuple]) -> list[str]: + def rep(s: list[tuple], d: list[list[str]]) -> list[str]: + x = [] + for i in range(len(s)): + x += [ + *[ " let mut shape = ArrayTrait::::new();"], + *[f" shape.append({s});" for s in s[i]], + *[ ""], + *[ " let mut data = ArrayTrait::new();"], + *[f" data.append({d});" for d in d[i]], + *[ ""], + *[ " sequence.append(TensorTrait::new(shape.span(), data.span()));"], + *[ ""], + ] + return x + + return [ + *[f"use {ref};" for ref in refs], + *[ ""], + *[f"fn {func}() -> Array>"+" {"], + *[ " let mut sequence = ArrayTrait::new();"], + *[ ""], + *rep(shape, data), + *[ " sequence"], + *[ "}"], + ] diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 5970582c6..8f7b51218 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -39,28 +39,46 @@ class Trait(Enum): NN = 'NN' -def make_test(inputs: list[Tensor], output: Tensor, func_sig: str, name: str, trait: Trait = Trait.TENSOR): +def make_test(inputs: list[Tensor | list[Tensor]], output: Tensor | list[Tensor], func_sig: str, name: str, trait: Trait = Trait.TENSOR): Mod().update(name) for i, input in enumerate(inputs): input_data = Data(os.path.join(name, f"input_{i}.cairo")) - input_data.buffer = Data.template( - func=f"input_{i}", - dtype=input.dtype.value, - refs=get_data_refs(input.dtype), - data=get_data_data(input.data, input.dtype), - shape=input.shape, - ) + if isinstance(input, list): + input_data.buffer = Data.template_sequence( + func=f"input_{i}", + dtype=input[0].dtype.value, + refs=get_data_refs(input[0].dtype), + data=get_data_data_sequence(input, input[0].dtype), + shape=[x.shape for x in input], + ) + else: + input_data.buffer = Data.template( + func=f"input_{i}", + dtype=input.dtype.value, + refs=get_data_refs(input.dtype), + data=get_data_data(input.data, input.dtype), + shape=input.shape, + ) input_data.dump() output_data = Data(os.path.join(name, "output_0.cairo")) - output_data.buffer = Data.template( - func="output_0", - dtype=output.dtype.value, - refs=get_data_refs(output.dtype), - data=get_data_data(output.data, output.dtype), - shape=output.shape, - ) + if isinstance(output, list): + output_data.buffer = Data.template_sequence( + func="output_0", + dtype=output[0].dtype.value, + refs=get_data_refs(output[0].dtype), + data=get_data_data_sequence(output, output[0].dtype), + shape=[x.shape for x in output], + ) + else: + output_data.buffer = Data.template( + func="output_0", + dtype=output.dtype.value, + refs=get_data_refs(output.dtype), + data=get_data_data(output.data, output.dtype), + shape=output.shape, + ) output_data.dump() test_file = Test(f"{name}.cairo") @@ -73,8 +91,15 @@ def make_test(inputs: list[Tensor], output: Tensor, func_sig: str, name: str, tr test_file.dump() -def find_all_types(tensors: list[Tensor]) -> list[Dtype]: - return list(set([tensor.dtype for tensor in tensors])) +def find_all_types(tensors: list[Tensor | list[Tensor]]) -> list[Dtype]: + dtypes = [] + for tensor in tensors: + if isinstance(tensor, list): + dtypes += [x.dtype for x in tensor] + else: + dtypes.append(tensor.dtype) + + return list(set(dtypes)) def get_all_use(dtypes: list[Dtype], trait: Trait) -> list[str]: @@ -99,6 +124,10 @@ def get_data_data(data: np.ndarray, dtype: Dtype) -> list[str]: return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] +def get_data_data_sequence(data: list[Tensor], dtype: Dtype) -> list[list[str]]: + return [get_data_data(x.data, dtype) for x in data] + + def get_data_refs(dtype: Dtype) -> list[str]: refs = [ *trait2use[Trait.TENSOR], From dcc017f8f6dbc8ccfcc5bfd2460fe235c47a1bdb Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 10 Nov 2023 13:54:37 +0100 Subject: [PATCH 062/127] clean up and add docstrings --- nodegen/file_manager.py | 146 +++++++++++++++++++++++++++------- nodegen/helpers.py | 168 ++++++++++++++++++++++------------------ 2 files changed, 209 insertions(+), 105 deletions(-) diff --git a/nodegen/file_manager.py b/nodegen/file_manager.py index 7e3779d65..215bacbcc 100644 --- a/nodegen/file_manager.py +++ b/nodegen/file_manager.py @@ -2,43 +2,92 @@ from pathlib import Path -PATH = "./tests/nodes" +BASE_PATH = "./tests/nodes" + + +class ModFile: + def __init__(self): + """ + Initialize a ModFile object. + + This method creates a new file with a .cairo extension in the BASE_PATH directory. + If the directory doesn't exist, it's created. The contents of the file are then read + into the buffer attribute. + """ + self.path = Path(f"{BASE_PATH}.cairo") + self.path.parent.mkdir(parents=True, exist_ok=True) + with self.path.open("r") as f: + self.buffer = f.readlines() + + def update(self, name: str): + """ + Update the .cairo file with a new module statement. + + Args: + name (str): The name of the module to be added. + + This method checks if a module statement for the given name already exists in the buffer. + If it doesn't, the new module statement is appended to the file. + """ + statement = f"mod {name};" + if any([line.startswith(statement) for line in self.buffer]): + return + + with self.path.open("a") as f: + f.write(f"{statement}\n") class File: - def __init__(self, path: str, empty_buffer: bool = False): + def __init__(self, path: str): + """ + Initialize a File object. + + Args: + path (str): The file path where the File object will operate. + + This method creates a new file at the specified path. If the file already exists, its + contents are read into the buffer attribute. + """ self.path = Path(path) self.path.parent.mkdir(parents=True, exist_ok=True) self.buffer = [] - if empty_buffer: - return - if os.path.isfile(path): - with self.path.open('r') as f: + with self.path.open("r") as f: self.buffer = f.readlines() def dump(self): - with self.path.open('w') as f: - f.writelines([f"{line}\n" for line in self.buffer]) - - -class Mod(File): - def __init__(self): - super().__init__(path=f"{PATH}.cairo") + """ + Write the contents of the buffer to the file. - def update(self, name: str): - statement = f"mod {name};" - if statement not in self.buffer: - self.buffer.append(statement) + This method writes each line in the buffer to the file, ensuring each line is + properly terminated with a newline character. + """ + with self.path.open("w") as f: + f.writelines([f"{line}\n" for line in self.buffer]) -class Test(File): +class CairoTest(File): def __init__(self, file: str): - super().__init__(os.path.join(PATH, file), empty_buffer=True) + super().__init__(os.path.join(BASE_PATH, file)) @classmethod def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + """ + Create a template for a Cairo test function. + + Args: + name (str): Name of the test function. + arg_cnt (int): Number of arguments for the function. + refs (list[str]): List of references (modules) to be used in the function. + func_sig (str): The function signature. + + Returns: + list[str]: A list of strings that together form the template of a Cairo test function. + + This method generates a list of strings that form the template of a Cairo test function, + including module imports, function definition, and assertions. + """ return [ *[f"mod input_{i};" for i in range(arg_cnt)], *[ "mod output_0;"], @@ -59,13 +108,29 @@ def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> li ] -class Data(File): +class CairoData(File): def __init__(self, file: str): - super().__init__(os.path.join(PATH, file), empty_buffer=True) + super().__init__(os.path.join(BASE_PATH, file)) @classmethod - def template(cls, func: str, dtype: str, refs: list[str], data: list[str], shape: tuple) -> list[str]: - return [ + def base_template(cls, func: str, dtype: str, refs: list[str], data: list[str], shape: tuple) -> list[str]: + """ + Create a base template for data representation in Cairo. + + Args: + func (str): The function name. + dtype (str): The data type of the tensor. + refs (list[str]): A list of module references. + data (list[str]): The data to be included in the tensor. + shape (tuple): The shape of the tensor. + + Returns: + list[str]: A list of strings that together form the template of a data function in Cairo. + + This method generates a list of strings representing a function in Cairo for data handling, + defining the shape and contents of a tensor. + """ + template = [ *[f"use {ref};" for ref in refs], *[ ""], *[f"fn {func}() -> Tensor<{dtype}>"+" {"], @@ -78,12 +143,30 @@ def template(cls, func: str, dtype: str, refs: list[str], data: list[str], shape *[ "}"], ] + return template + @classmethod - def template_sequence(cls, func: str, dtype: str, refs: list[str], data: list[list[str]], shape: list[tuple]) -> list[str]: - def rep(s: list[tuple], d: list[list[str]]) -> list[str]: - x = [] + def sequence_template(cls, func: str, dtype: str, refs: list[str], data: list[list[str]], shape: list[tuple]) -> list[str]: + """ + Create a template for handling tensor sequences in Cairo. + + Args: + func (str): The function name. + dtype (str): The data type of the tensor sequence. + refs (list[str]): A list of module references. + data (list[list[str]]): The data to be included in each tensor. + shape (list[tuple]): The shapes of each tensor in the sequence. + + Returns: + list[str]: A list of strings that together form the template of a sequence tensor function in Cairo. + + This method generates a list of strings representing a function in Cairo for handling a sequence + of tensors, each with its own data and shape. + """ + def expand_sequence_init(s: list[tuple], d: list[list[str]]) -> list[str]: + snippet = [] for i in range(len(s)): - x += [ + snippet += [ *[ " let mut shape = ArrayTrait::::new();"], *[f" shape.append({s});" for s in s[i]], *[ ""], @@ -93,15 +176,18 @@ def rep(s: list[tuple], d: list[list[str]]) -> list[str]: *[ " sequence.append(TensorTrait::new(shape.span(), data.span()));"], *[ ""], ] - return x - return [ + return snippet + + template = [ *[f"use {ref};" for ref in refs], *[ ""], *[f"fn {func}() -> Array>"+" {"], *[ " let mut sequence = ArrayTrait::new();"], *[ ""], - *rep(shape, data), + *expand_sequence_init(shape, data), *[ " sequence"], *[ "}"], ] + + return template diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 8f7b51218..d027a7ec5 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -1,7 +1,8 @@ from enum import Enum import os +from typing import List -from .file_manager import Test, Data, Mod +from .file_manager import CairoTest, CairoData, ModFile import numpy as np @@ -34,83 +35,91 @@ def __init__(self, dtype: Dtype, shape: tuple, data: np.ndarray): self.data = data +Sequence = List[Tensor] + + class Trait(Enum): TENSOR = 'TENSOR' NN = 'NN' -def make_test(inputs: list[Tensor | list[Tensor]], output: Tensor | list[Tensor], func_sig: str, name: str, trait: Trait = Trait.TENSOR): - Mod().update(name) +def make_test(inputs: list[Tensor | Sequence], output: Tensor | Sequence, func_sig: str, name: str, trait: Trait = Trait.TENSOR): + """ + Generate and write Cairo tests based on the provided inputs and output. + + Args: + inputs (list[Tensor | list[Tensor]]): A list of input tensors or tensor sequences. + output (Tensor | list[Tensor]): The expected output tensor or tensor sequences. + func_sig (str): The signature of the function to be tested. + name (str): The name of the test. + trait (Trait, optional): The trait of the tensors. Defaults to Trait.TENSOR. + """ + ModFile().update(name) for i, input in enumerate(inputs): - input_data = Data(os.path.join(name, f"input_{i}.cairo")) - if isinstance(input, list): - input_data.buffer = Data.template_sequence( - func=f"input_{i}", - dtype=input[0].dtype.value, - refs=get_data_refs(input[0].dtype), - data=get_data_data_sequence(input, input[0].dtype), - shape=[x.shape for x in input], + input_data = CairoData(os.path.join(name, f"input_{i}.cairo")) + match input: + case list(): + input_data.buffer = CairoData.sequence_template( + func=f"input_{i}", + dtype=input[0].dtype.value, + refs=get_data_refs(input[0].dtype), + data=get_data_statement_for_sequences(input, input[0].dtype), + shape=[x.shape for x in input], + ) + case Tensor(): + input_data.buffer = CairoData.base_template( + func=f"input_{i}", + dtype=input.dtype.value, + refs=get_data_refs(input.dtype), + data=get_data_statement(input.data, input.dtype), + shape=input.shape, + ) + + input_data.dump() + + output_data = CairoData(os.path.join(name, "output_0.cairo")) + match output: + case list(): + output_data.buffer = CairoData.sequence_template( + func="output_0", + dtype=output[0].dtype.value, + refs=get_data_refs(output[0].dtype), + data=get_data_statement_for_sequences(output, output[0].dtype), + shape=[x.shape for x in output], ) - else: - input_data.buffer = Data.template( - func=f"input_{i}", - dtype=input.dtype.value, - refs=get_data_refs(input.dtype), - data=get_data_data(input.data, input.dtype), - shape=input.shape, + case Tensor(): + output_data.buffer = CairoData.base_template( + func="output_0", + dtype=output.dtype.value, + refs=get_data_refs(output.dtype), + data=get_data_statement(output.data, output.dtype), + shape=output.shape, ) - input_data.dump() - output_data = Data(os.path.join(name, "output_0.cairo")) - if isinstance(output, list): - output_data.buffer = Data.template_sequence( - func="output_0", - dtype=output[0].dtype.value, - refs=get_data_refs(output[0].dtype), - data=get_data_data_sequence(output, output[0].dtype), - shape=[x.shape for x in output], - ) - else: - output_data.buffer = Data.template( - func="output_0", - dtype=output.dtype.value, - refs=get_data_refs(output.dtype), - data=get_data_data(output.data, output.dtype), - shape=output.shape, - ) output_data.dump() - test_file = Test(f"{name}.cairo") - test_file.buffer = Test.template( + test_file = CairoTest(f"{name}.cairo") + test_file.buffer = CairoTest.template( name=name, arg_cnt=len(inputs), - refs=get_all_use(find_all_types([*inputs, output]), trait), + refs=get_all_test_refs(find_all_types([*inputs, output]), trait, isinstance(output, list)), func_sig=func_sig, ) test_file.dump() -def find_all_types(tensors: list[Tensor | list[Tensor]]) -> list[Dtype]: - dtypes = [] - for tensor in tensors: - if isinstance(tensor, list): - dtypes += [x.dtype for x in tensor] - else: - dtypes.append(tensor.dtype) - - return list(set(dtypes)) - - -def get_all_use(dtypes: list[Dtype], trait: Trait) -> list[str]: - refs = [] - for dtype in dtypes: - refs += get_test_refs(dtype, trait) +def get_data_refs(dtype: Dtype) -> list[str]: + refs = [ + *trait_to_ref[Trait.TENSOR], + *dtype_to_tensor[dtype], + *dtype_to_numbers[dtype], + ] - return list(set(refs)) + return refs -def get_data_data(data: np.ndarray, dtype: Dtype) -> list[str]: +def get_data_statement(data: np.ndarray, dtype: Dtype) -> list[str]: match dtype: case Dtype.U32: return [f"{int(x)}" for x in data.flatten()] @@ -124,33 +133,42 @@ def get_data_data(data: np.ndarray, dtype: Dtype) -> list[str]: return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] -def get_data_data_sequence(data: list[Tensor], dtype: Dtype) -> list[list[str]]: - return [get_data_data(x.data, dtype) for x in data] +def get_data_statement_for_sequences(data: Sequence, dtype: Dtype) -> list[list[str]]: + return [get_data_statement(x.data, dtype) for x in data] -def get_data_refs(dtype: Dtype) -> list[str]: - refs = [ - *trait2use[Trait.TENSOR], - *dtype2tensor[dtype], - *dtype2numbers[dtype], - ] +def get_all_test_refs(dtypes: list[Dtype], trait: Trait, is_sequence: bool) -> list[str]: + refs = [] + for dtype in dtypes: + refs += get_test_refs(dtype, trait, is_sequence) - return refs + return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: - dtype_ref = dtype2nn[dtype] if trait == Trait.NN else dtype2tensor[dtype] +def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: + dtype_ref = dtype_to_nn[dtype] if trait == Trait.NN else dtype_to_tensor[dtype] refs = [ - *trait2use[trait], + *trait_to_ref[trait], *dtype_ref, - *dtype2partial[dtype], - "orion::utils::assert_eq", + *dtype_to_partial_eq[dtype], + "orion::utils::{assert_eq, assert_seq_eq}", ] return refs -trait2use = { +def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: + dtypes = [] + for tensor in tensors: + if isinstance(tensor, list): + dtypes += [x.dtype for x in tensor] + else: + dtypes.append(tensor.dtype) + + return list(set(dtypes)) + + +trait_to_ref = { Trait.TENSOR: [ "array::{ArrayTrait, SpanTrait}", "orion::operators::tensor::{TensorTrait, Tensor}", @@ -162,7 +180,7 @@ def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: } -dtype2tensor = { +dtype_to_tensor = { Dtype.U32: ["orion::operators::tensor::U32Tensor",], Dtype.I32: ["orion::operators::tensor::I32Tensor",], Dtype.I8: ["orion::operators::tensor::I8Tensor",], @@ -171,7 +189,7 @@ def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: } -dtype2nn = { +dtype_to_nn = { Dtype.U32: ["orion::operators::nn::U32NN",], Dtype.I32: ["orion::operators::nn::I32NN",], Dtype.I8: ["orion::operators::nn::I8NN",], @@ -180,7 +198,7 @@ def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: } -dtype2partial = { +dtype_to_partial_eq = { Dtype.U32: ["orion::operators::tensor::U32TensorPartialEq",], Dtype.I32: ["orion::operators::tensor::I32TensorPartialEq",], Dtype.I8: ["orion::operators::tensor::I8TensorPartialEq",], @@ -189,7 +207,7 @@ def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: } -dtype2numbers = { +dtype_to_numbers = { Dtype.U32: [], Dtype.I32: ["orion::numbers::{IntegerTrait, i32}",], Dtype.I8: ["orion::numbers::{IntegerTrait, i8}",], From ac8487ddd1f2cec1bc56a7ac315e7f9d3f35b716 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 10 Nov 2023 14:03:48 +0100 Subject: [PATCH 063/127] update docs --- docs/academy/tutorials/implement-new-operators-in-orion.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/academy/tutorials/implement-new-operators-in-orion.md b/docs/academy/tutorials/implement-new-operators-in-orion.md index 87e990077..24fd698d1 100644 --- a/docs/academy/tutorials/implement-new-operators-in-orion.md +++ b/docs/academy/tutorials/implement-new-operators-in-orion.md @@ -268,7 +268,7 @@ Finally, we create a Softmax class, containing tests for each dtypes. ```python import numpy as np from nodegen.node import RunAll -from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def softmax(x: np.ndarray, axis: int = -1) -> np.ndarray: x_max = np.max(x, axis=axis, keepdims=True) @@ -293,8 +293,6 @@ class Softmax(RunAll): # Define the name of the generated folder. name = "softmax_fp8x23" - # Invoke `make_node` method to generate Cairo representation of `x` and `y`: - make_node([x], [y], name) # Invoke `make_test` method to generate corresponding Cairo tests: make_test( [x], # List of input tensors. @@ -316,7 +314,6 @@ class Softmax(RunAll): y.flatten(), FixedImpl.FP16x16)) name = "softmax_fp16x16" - make_node([x], [y], name) make_test([x], y, "NNTrait::softmax(@input_0, 1)", name, Trait.NN) ``` From 7775465d707bdb4d1194dda9a148ffe5d2d6316a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 16:12:59 +0200 Subject: [PATCH 064/127] rename post transform --- .../tree_ensemble_classifier.cairo | 20 +++++++++---------- tests/ml/tree_ensemble_classifier.cairo | 14 +++---------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index e9ac8a5c6..850a28d94 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -37,11 +37,11 @@ struct TreeEnsembleClassifier { #[derive(Copy, Drop)] enum PostTransform { - None, - Softmax, - Logistic, - SoftmaxZero, - Probit, + NONE, + SOFTMAX, + LOGISTIC, + SOFTMAXZERO, + PROBIT, } #[generate_trait] @@ -196,11 +196,11 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { - PostTransform::None => { res }, // No action required - PostTransform::Softmax => { res.softmax(1) }, - PostTransform::Logistic => panic_with_felt252('Logistic not supported yet'), - PostTransform::SoftmaxZero => panic_with_felt252('SoftmaxZero not supported yet'), - PostTransform::Probit => panic_with_felt252('Probit not supported yet'), + PostTransform::NONE => { res }, // No action required + PostTransform::SOFTMAX => { res.softmax(1) }, + PostTransform::LOGISTIC => panic_with_felt252('Logistic not supported yet'), + PostTransform::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + PostTransform::PROBIT => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 3428a2fd5..18e6d99bf 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,20 +1,12 @@ -use core::option::OptionTrait; -use orion::operators::matrix::MutMatrixTrait; -use core::array::SpanTrait; -use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{ - NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl -}; +use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; -use debug::PrintTrait; - #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_none() { @@ -136,7 +128,7 @@ fn test_tree_ensemble_classifier_multi_pt_none() { let base_values: Option> = Option::None; - let post_transform = PostTransform::None; + let post_transform = PostTransform::NONE; let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, @@ -333,7 +325,7 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { let base_values: Option> = Option::None; - let post_transform = PostTransform::Softmax; + let post_transform = PostTransform::SOFTMAX; let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, From 5d78374d3f25b9163750067f3f0136782c25a52a Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Fri, 10 Nov 2023 13:32:43 +0100 Subject: [PATCH 065/127] Implement operator --- src/operators/tensor.cairo | 1 + src/operators/tensor/core.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 6 +- .../implementations/tensor_fp16x16wide.cairo | 6 +- .../implementations/tensor_fp32x32.cairo | 6 +- .../implementations/tensor_fp64x64.cairo | 6 +- .../implementations/tensor_fp8x23.cairo | 6 +- .../implementations/tensor_fp8x23wide.cairo | 6 +- .../tensor/implementations/tensor_i32.cairo | 6 +- .../tensor/implementations/tensor_i8.cairo | 6 +- .../tensor/implementations/tensor_u32.cairo | 6 +- src/operators/tensor/ml.cairo | 1 + .../tensor/ml/array_feature_extractor.cairo | 87 +++++++++++++++++++ 13 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/operators/tensor/ml.cairo create mode 100644 src/operators/tensor/ml/array_feature_extractor.cairo diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 30403831f..612ec8c11 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -4,6 +4,7 @@ mod math; mod linalg; mod quantization; mod implementations; +mod ml; use orion::operators::tensor::core::{Tensor, TensorSerde, TensorTrait}; diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 8a3ae7e68..17ee93256 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 508134a2f..78628105c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -288,6 +288,10 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// 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 d87f6dd9d..e15eaeb90 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16W}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -286,6 +286,10 @@ impl FP16x16WTensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 30b85b755..58089059a 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP32x32, FP32x32Impl}; use orion::numbers::fixed_point::implementations::fp32x32::core::ONE; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -288,6 +288,10 @@ impl FP32x32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 c86420354..c09844e13 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP64x64, FP64x64Impl}; use orion::numbers::fixed_point::implementations::fp64x64::core::ONE; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -289,6 +289,10 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// 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 3ddcf0369..f043bdd5a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -287,6 +287,10 @@ impl FP8x23Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 3c36ee737..802fb078c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23W}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -277,6 +277,10 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// 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 bf0592c41..acbab214e 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i32, i8, NumberTrait}; use orion::operators::tensor::implementations::{tensor_u32::U32Tensor, tensor_i8::I8Tensor}; @@ -287,6 +287,10 @@ impl I32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 bfadc3be5..c370543c6 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; @@ -286,6 +286,10 @@ impl I8Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// 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 2faf21b0b..667057ad3 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_i8::I8Tensor; @@ -268,6 +268,10 @@ impl U32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/ml.cairo b/src/operators/tensor/ml.cairo new file mode 100644 index 000000000..e9c3faa09 --- /dev/null +++ b/src/operators/tensor/ml.cairo @@ -0,0 +1 @@ +mod array_feature_extractor; \ No newline at end of file diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo new file mode 100644 index 000000000..c3918e859 --- /dev/null +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -0,0 +1,87 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::array_feature_extractor docstring +fn array_feature_extractor< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, indices: Tensor +) -> Tensor { + + assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); + + let input_shape: Span = self.shape; + let input_data: Span = self.data; + let mut last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + + let mut input_shape_counter: usize = 0; + + let mut total_elements: usize = 1; + + let mut output_shape: Array = ArrayTrait::new(); + + loop { + if input_shape_counter > input_shape.len() - 2 { + break; + } + + let mut current_shape_value = *input_shape.at(input_shape_counter); + + output_shape.append(current_shape_value); + + total_elements = total_elements * current_shape_value; + + input_shape_counter += 1; + + }; + + output_shape.append(indices.data.len()); + + let mut output_data = ArrayTrait::::new(); + + let strides: Span = TensorTrait::stride(@self); + + let mut element_counter: usize = 0; + + loop { + if element_counter > total_elements - 1 { + break; + } + + let mut base_index = element_counter * (*strides.at(strides.len() - 2)); + + let mut indices_counter: usize = 0; + + loop { + if indices_counter > indices.data.len() - 1 { + break; + } + + let mut current_indices_value = *indices.data.at(indices_counter); + + let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); + + let mut current_data_value = *input_data.at(flat_index); + + output_data.append(current_data_value); + + indices_counter += 1; + + }; + + element_counter += 1; + }; + + return TensorTrait::new(output_shape.span(), output_data.span()); + +} \ No newline at end of file From f1f60a7bc89368b17b51740ba3a107ecc12cecf3 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sat, 11 Nov 2023 00:54:30 +0100 Subject: [PATCH 066/127] Add tests --- nodegen/node/array_feature_extractor.py | 54 +++++++++++++++++++ tests/nodes.cairo | 5 +- .../array_feature_extractor_fp16x16.cairo | 22 ++++++++ .../input_0.cairo | 39 ++++++++++++++ .../input_1.cairo | 13 +++++ .../output_0.cairo | 27 ++++++++++ .../array_feature_extractor_fp8x23.cairo | 22 ++++++++ .../input_0.cairo | 39 ++++++++++++++ .../input_1.cairo | 13 +++++ .../output_0.cairo | 27 ++++++++++ tests/nodes/array_feature_extractor_i32.cairo | 22 ++++++++ .../array_feature_extractor_i32/input_0.cairo | 38 +++++++++++++ .../array_feature_extractor_i32/input_1.cairo | 13 +++++ .../output_0.cairo | 26 +++++++++ 14 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 nodegen/node/array_feature_extractor.py create mode 100644 tests/nodes/array_feature_extractor_fp16x16.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_i32.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/output_0.cairo diff --git a/nodegen/node/array_feature_extractor.py b/nodegen/node/array_feature_extractor.py new file mode 100644 index 000000000..7055dc05c --- /dev/null +++ b/nodegen/node/array_feature_extractor.py @@ -0,0 +1,54 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Array_feature_extractor(RunAll): + + @staticmethod + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + @staticmethod + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + @staticmethod + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..12ee077cd 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,4 +527,7 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod scatter_u32_add; +mod array_feature_extractor_fp16x16; +mod array_feature_extractor_fp8x23; +mod array_feature_extractor_i32; diff --git a/tests/nodes/array_feature_extractor_fp16x16.cairo b/tests/nodes/array_feature_extractor_fp16x16.cairo new file mode 100644 index 000000000..9dfcd177e --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo new file mode 100644 index 000000000..a32b3a3a2 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo @@ -0,0 +1,39 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + 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: false }); + 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: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo new file mode 100644 index 000000000..b72170ad1 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo @@ -0,0 +1,27 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + 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: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23.cairo b/tests/nodes/array_feature_extractor_fp8x23.cairo new file mode 100644 index 000000000..a249ced57 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo new file mode 100644 index 000000000..e92d71a5a --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo @@ -0,0 +1,39 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo new file mode 100644 index 000000000..268e7335d --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo @@ -0,0 +1,27 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32.cairo b/tests/nodes/array_feature_extractor_i32.cairo new file mode 100644 index 000000000..987cd02f6 --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_0.cairo b/tests/nodes/array_feature_extractor_i32/input_0.cairo new file mode 100644 index 000000000..a922d8f8e --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/input_0.cairo @@ -0,0 +1,38 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_1.cairo b/tests/nodes/array_feature_extractor_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/output_0.cairo b/tests/nodes/array_feature_extractor_i32/output_0.cairo new file mode 100644 index 000000000..4e64044fa --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/output_0.cairo @@ -0,0 +1,26 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From b0f52d9bace52acfdf49c164d0c605d02f57086a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sat, 11 Nov 2023 22:48:47 +0200 Subject: [PATCH 067/127] Update tensor_fp8x23.cairo --- .../tensor/implementations/tensor_fp8x23.cairo | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index d026e268b..96f67b3a4 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -315,13 +315,9 @@ impl FP8x23Tensor of TensorTrait { } fn scatter( - self: @Tensor, - updates: Tensor, - indices: Tensor, - axis: Option, - reduction: Option - ) -> Tensor { - math::scatter::scatter(self, updates, indices, axis, reduction) + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) } } From e14ddf0a111174a6ea8f0ce071a5c114c98a788b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sat, 11 Nov 2023 23:10:04 +0200 Subject: [PATCH 068/127] Update math.cairo --- src/operators/tensor/math.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index f13ffb968..dcee7331c 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -42,4 +42,3 @@ mod scatter; mod reduce_l2; mod reduce_l1; mod bitwise_and; -mod scatter; From 8d96c2d1e7f220cc0512c840b3ead62c5f0e740d Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sat, 11 Nov 2023 23:23:38 +0200 Subject: [PATCH 069/127] Update reduce_sum_square.cairo --- src/operators/tensor/math/reduce_sum_square.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/tensor/math/reduce_sum_square.cairo b/src/operators/tensor/math/reduce_sum_square.cairo index 6d993c83f..38d1fa6a5 100644 --- a/src/operators/tensor/math/reduce_sum_square.cairo +++ b/src/operators/tensor/math/reduce_sum_square.cairo @@ -36,6 +36,7 @@ fn square< let tensor_square = TensorTrait::new(*self.shape, output_data.span()); return tensor_square; } + /// Cf: TensorTrait::reduce_sum_square docstring fn reduce_sum_square< T, From 98494987932036bcc25bde5004eec09a00ae8489 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 11 Nov 2023 21:32:59 +0000 Subject: [PATCH 070/127] docs: update README.md [skip ci] --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a89893233..256adf381 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -95,6 +95,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Thomas S. Bauer
Thomas S. Bauer

💻 Andres
Andres

💻 + + Tony Stark
Tony Stark

📖 + From 58617635d681c8703ee0c4ca568994de9959f446 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 11 Nov 2023 21:33:00 +0000 Subject: [PATCH 071/127] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 84be25e8a..7b03c0fde 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -197,6 +197,15 @@ "contributions": [ "code" ] + }, + { + "login": "okhaimie-dev", + "name": "Tony Stark", + "avatar_url": "https://avatars.githubusercontent.com/u/57156589?v=4", + "profile": "https://okhaimie.com", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 7, From 5e1bc1095d026a14296dfbb0c170ee8e1b1adebf Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 08:43:00 +0200 Subject: [PATCH 072/127] Create orion-usage.md --- orion-usage.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 orion-usage.md diff --git a/orion-usage.md b/orion-usage.md new file mode 100644 index 000000000..9c8daa69e --- /dev/null +++ b/orion-usage.md @@ -0,0 +1,65 @@ +# Orion Usage + +*Last Update: 12 nov. 2023* + +## Contributors + +| Author | # PRs | +| ------------- | ----- | +| raphaelDkhn | 87 | +| credence0x | 21 | +| franalgaba | 14 | +| hakymulla | 12 | +| Roee-87 | 8 | +| chachaleo | 6 | +| 0x73e | 5 | +| Dl-Vv | 4 | +| dincerguner | 4 | +| CountryCousin | 3 | +| TsBauer | 2 | +| richwarner | 1 | +| BemTG | 1 | +| Falco90 | 1 | +| dbejarano820 | 1 | +| omahs | 1 | +| moodysalem | 1 | + + +## Tutorials + +Learn how to use Orion with tutorials. We encourage you to contribute by sharing your own tutorial. + +| Author | Title | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------ | +| 0xd3bs | [Verifiable Support Vector Machine](https://orion.gizatech.xyz/academy/tutorials/verifiable-support-vector-machine) | +| Bem Baraki | [Verifiable Linear Regression Model](https://orion.gizatech.xyz/academy/tutorials/verifiable-linear-regression-model-in-orion) | +| Raphael Doukhan | [Implement new operators in Orion](https://orion.gizatech.xyz/academy/tutorials/implement-new-operators-in-orion) | +| Raphael Doukhan | [MNIST Classification with Orion](https://orion.gizatech.xyz/academy/tutorials/mnist-classification-with-orion) | + +## Models + +Discover ML models made by the community with Orion! + +| Author | Title | +| --------------- | --------------------------------------------------------------------------------------------------------------------- | +| Raphael Doukhan | [Tic-Tac-Stark](https://github.com/gizatechxyz/Tic-Tac-Stark) | +| 0xd3bs | [SVM](https://github.com/gizatechxyz/orion_tutorials/blob/main/verifiable_support_vector_machine/notebooks/svm.ipynb) | +| Bowen | [Logistic Regression](https://github.com/bowenyou/cairo-logistic-regression) | +| Bem Baraki | [Linear Regression](https://github.com/BemTG/Verifiable-Linear-Regression-) | +| Raphael Doukhan | [MNIST MLP](https://github.com/gizatechxyz/orion_tutorials/blob/main/mnist_nn/QAT_MNIST_MLP.ipynb) | + +## Hackathon Projects + +| Author | Event | Title | Prizes | +| --------------------- | -------------- | -------------------------------------------------------------------------------------- | ------------------ | +| manuj-mishra | Lambda ZK week | [ZK Differential Privacy](https://github.com/manuj-mishra/zkdiffpriv) | 🏅 | +| codingnirvana | Lambda ZK week | [Cairo Convolution ](https://github.com/gizatechxyz/orion/pull/160) | | +| danilo, richie, falco | ETHGlobal | [Cairo Einsum](https://x.com/danilowhk2/status/1683138159985545216?s=20) | 🥇 (Starknet track) | +| 0xbyyou | ETHToronto | [Cairo Logistic Regression](https://x.com/gizatechxyz/status/1695016787698417770?s=20) | | + +## Use Cases + +| Author | Title | Description | +| ----------------------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | +| dblancove & dataonchain | A verifiable anomaly detection model for in fraud detection and analysis of bank transaction alerts. | From 12c483db6b114c248922600449ce660d31dec6b0 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 08:44:35 +0200 Subject: [PATCH 073/127] Update orion-usage.md --- orion-usage.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/orion-usage.md b/orion-usage.md index 9c8daa69e..7d8802205 100644 --- a/orion-usage.md +++ b/orion-usage.md @@ -59,7 +59,7 @@ Discover ML models made by the community with Orion! ## Use Cases -| Author | Title | Description | -| ----------------------- | ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | -| dblancove & dataonchain | A verifiable anomaly detection model for in fraud detection and analysis of bank transaction alerts. | +| Author | Title | Description | +| ----------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | +| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model for in fraud detection and analysis of bank transaction alerts. | From fd8cb32ccd7838aaa05a27e863fddc9e0d2cf2e7 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 08:45:22 +0200 Subject: [PATCH 074/127] Update orion-usage.md --- orion-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orion-usage.md b/orion-usage.md index 7d8802205..a24a8ef7f 100644 --- a/orion-usage.md +++ b/orion-usage.md @@ -62,4 +62,4 @@ Discover ML models made by the community with Orion! | Author | Title | Description | | ----------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | -| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model for in fraud detection and analysis of bank transaction alerts. | +| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model in fraud detection and analysis of bank transaction alerts. | From f6933c96ca254e91cc643421bd051a6322dbbba1 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 09:10:30 +0200 Subject: [PATCH 075/127] fix doc --- docs/framework/operators/tensor/README.md | 3 +- .../tensor/tensor.constant_of_shape.md | 23 +---- .../operators/tensor/tensor.reduce_l2.md | 38 +++++++++ src/operators/tensor/core.cairo | 83 ++----------------- 4 files changed, 53 insertions(+), 94 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.reduce_l2.md diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 5ab42cab4..d793cc692 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -93,10 +93,11 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.bitwise_and`](tensor.bitwise\_and.md) | Computes the bitwise AND of two tensors element-wise. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | +| [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. | | [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | -| [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. | +| [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.constant_of_shape.md b/docs/framework/operators/tensor/tensor.constant_of_shape.md index 3faef9822..ca275e375 100644 --- a/docs/framework/operators/tensor/tensor.constant_of_shape.md +++ b/docs/framework/operators/tensor/tensor.constant_of_shape.md @@ -17,7 +17,7 @@ A new `Tensor` instance. ## Examples -Let's create new u32 Tensor with constant 0. +Let's create new u32 Tensor with constant 42. ```rust use array::{ArrayTrait, SpanTrait}; @@ -28,26 +28,11 @@ use orion::operators::tensor::{ U32Tensor // we import the implementation. }; -// 1D TENSOR -fn tensor_1D() -> Tensor { - let tensor = TensorTrait::new(shape: array![3].span(), value: 0); +fn constant_of_shape_example() -> Tensor { + let tensor = TensorTrait::constant_of_shape(shape: array![3].span(), value: 42); return tensor; } -// 2D TENSOR -fn tensor_2D() -> Tensor { - let tensor = TensorTrait::new(shape: array![2, 2].span(), value: 10); - - return tensor; -} - -// 3D TENSOR -fn tensor_3D() -> Tensor { - let tensor = TensorTrait::new( - shape: array![2, 2, 2].span(), value: 20, - ); - - return tensor; -} +>>> [42, 42, 42] ``` diff --git a/docs/framework/operators/tensor/tensor.reduce_l2.md b/docs/framework/operators/tensor/tensor.reduce_l2.md new file mode 100644 index 000000000..7b75df0ab --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_l2.md @@ -0,0 +1,38 @@ +## tensor.reduce_l2 + +```rust + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; +``` + +Computes the L2 norm of the input tensor's elements along the provided axes. +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axis`(`usize`) - The dimension to reduce. +* `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axis reduced by summing its elements. + +fn reduce_l2_example() -> Tensor { + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + let mut data = ArrayTrait::new(); + data.append(FixedTrait::new_unscaled(1, false)); + data.append(FixedTrait::new_unscaled(2, false)); + data.append(FixedTrait::new_unscaled(3, false)); + data.append(FixedTrait::new_unscaled(5, false)); + let tensor = TensorTrait::::new(shape.span(), data.span()); + + We can call `reduce_l2` function as follows. + return tensor.reduce_l2(axis: 1, keepdims: true); +} +>>> [[0x11e3779, 0x2ea5ca1]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 482d5ae99..ee6a179c8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -154,61 +154,6 @@ trait TensorTrait { /// ``` /// fn new(shape: Span, data: Span) -> Tensor; - /// # tensor.constant_of_shape - /// - /// ```rust - /// fn constant_of_shape(shape: Span, value: T) -> Tensor; - /// ``` - /// - /// Returns a new tensor with the given shape and constant value. - /// - /// ## Args - /// - /// * `shape`(`Span`) - A span representing the shape of the tensor. - /// * `value` (`T`) - the constant value. - /// - /// ## Returns - /// - /// A new `Tensor` instance. - /// - /// ## Examples - /// - /// Let's create new u32 Tensor with constant 0. - /// - /// ```rust - /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{ - /// TensorTrait, // we import the trait - /// Tensor, // we import the type - /// U32Tensor // we import the implementation. - /// }; - /// - /// // 1D TENSOR - /// fn tensor_1D() -> Tensor { - /// let tensor = TensorTrait::new(shape: array![3].span(), value: 0); - /// - /// return tensor; - /// } - /// - /// // 2D TENSOR - /// fn tensor_2D() -> Tensor { - /// let tensor = TensorTrait::new(shape: array![2, 2].span(), value: 10); - /// - /// return tensor; - /// } - /// - /// // 3D TENSOR - /// fn tensor_3D() -> Tensor { - /// let tensor = TensorTrait::new( - /// shape: array![2, 2, 2].span(), value: 20, - /// ); - /// - /// return tensor; - /// } - /// ``` - /// - fn constant_of_shape(shape: Span, value: T) -> Tensor; /// # tensor.at /// /// ```rust @@ -3452,6 +3397,11 @@ trait TensorTrait { /// /// ## Example /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// /// fn and_example() -> Tensor { /// let tensor_1 = TensorTrait::::new( /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), @@ -3607,7 +3557,7 @@ trait TensorTrait { /// /// ## Examples /// - /// Let's create new u32 Tensor with constant 0. + /// Let's create new u32 Tensor with constant 42. /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; @@ -3618,28 +3568,13 @@ trait TensorTrait { /// U32Tensor // we import the implementation. /// }; /// - /// // 1D TENSOR - /// fn tensor_1D() -> Tensor { - /// let tensor = TensorTrait::new(shape: array![3].span(), value: 0); + /// fn constant_of_shape_example() -> Tensor { + /// let tensor = TensorTrait::constant_of_shape(shape: array![3].span(), value: 42); /// /// return tensor; /// } /// - /// // 2D TENSOR - /// fn tensor_2D() -> Tensor { - /// let tensor = TensorTrait::new(shape: array![2, 2].span(), value: 10); - /// - /// return tensor; - /// } - /// - /// // 3D TENSOR - /// fn tensor_3D() -> Tensor { - /// let tensor = TensorTrait::new( - /// shape: array![2, 2, 2].span(), value: 20, - /// ); - /// - /// return tensor; - /// } + /// >>> [42, 42, 42] /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; From 022e1a91c27806e6b85f870869ddc85e5f17f463 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 08:02:22 +0000 Subject: [PATCH 076/127] docs: update README.md [skip ci] --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a89893233..5c750aabb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -95,6 +95,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Thomas S. Bauer
Thomas S. Bauer

💻 Andres
Andres

💻 + + Bal7hazar
Bal7hazar

🐛 + From e1fa8d8f1a955b633db125ec26946d997d2528f6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 08:02:23 +0000 Subject: [PATCH 077/127] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 84be25e8a..c56e8ddf4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -197,6 +197,15 @@ "contributions": [ "code" ] + }, + { + "login": "Bal7hazar", + "name": "Bal7hazar", + "avatar_url": "https://avatars.githubusercontent.com/u/97087040?v=4", + "profile": "https://github.com/Bal7hazar", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, From 045dfc1bdccb652e5f93f92ee41158b3baf00399 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 10:21:25 +0200 Subject: [PATCH 078/127] remove arithmetic implementations --- .../tensor/implementations/tensor_bool.cairo | 60 ------------------- 1 file changed, 60 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 24d4a8e89..efca27e3c 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -239,66 +239,6 @@ impl BoolTensor of TensorTrait { } } -/// Implements addition for `Tensor` using the `Add` trait. -impl BoolTensorAdd of Add> { - /// Adds two `Tensor` instances element-wise. - /// - /// # Arguments - /// * `lhs` - The first tensor. - /// * `rhs` - The second tensor. - /// - /// # Returns - /// * A `Tensor` instance representing the result of the element-wise addition. - fn add(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) - } -} - -/// Implements subtraction for `Tensor` using the `Sub` trait. -impl BoolTensorSub of Sub> { - /// Subtracts two `Tensor` instances element-wise. - /// - /// # Arguments - /// * `lhs` - The first tensor. - /// * `rhs` - The second tensor. - /// - /// # Returns - /// * A `Tensor` instance representing the result of the element-wise subtraction. - fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) - } -} - -/// Implements multiplication for `Tensor` using the `Mul` trait. -impl BoolTensorMul of Mul> { - /// Multiplies two `Tensor` instances element-wise. - /// - /// # Arguments - /// * `lhs` - The first tensor. - /// * `rhs` - The second tensor. - /// - /// # Returns - /// * A `Tensor` instance representing the result of the element-wise multiplication. - fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) - } -} - -/// Implements division for `Tensor` using the `Div` trait. -impl BoolTensorDiv of Div> { - /// Divides two `Tensor` instances element-wise. - /// - /// # Arguments - /// * `lhs` - The first tensor. - /// * `rhs` - The second tensor. - /// - /// # Returns - /// * A `Tensor` instance representing the result of the element-wise division. - fn div(lhs: Tensor, rhs: Tensor) -> Tensor { - panic(array!['not supported!']) - } -} - /// Implements partial equal for two `Tensor` using the `PartialEq` trait. impl BoolTensorPartialEq of PartialEq> { fn eq(lhs: @Tensor, rhs: @Tensor) -> bool { From cde3ff862b6bb49b77f530e559bc391162c4d1b8 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 10:35:10 +0200 Subject: [PATCH 079/127] Update implementations.cairo --- src/operators/tensor/implementations.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/operators/tensor/implementations.cairo b/src/operators/tensor/implementations.cairo index 79119f5cd..61ee08dd3 100644 --- a/src/operators/tensor/implementations.cairo +++ b/src/operators/tensor/implementations.cairo @@ -8,4 +8,3 @@ mod tensor_fp64x64; mod tensor_fp32x32; mod tensor_fp16x16wide; mod tensor_fp8x23wide; -mod tensor_bool; \ No newline at end of file From 6593b9598ad10b1a0debf45a15484ac108426e46 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 08:40:36 +0000 Subject: [PATCH 080/127] docs: update README.md [skip ci] --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a89893233..df336ba32 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -95,6 +95,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Thomas S. Bauer
Thomas S. Bauer

💻 Andres
Andres

💻 + + Ephraim Chukwu
Ephraim Chukwu

💻 + From 15fcbb24ec79b7a89704b91cb9516ced9cc9fcd1 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 08:40:36 +0000 Subject: [PATCH 081/127] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 84be25e8a..02f84147c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -197,6 +197,15 @@ "contributions": [ "code" ] + }, + { + "login": "Ephraim-nonso", + "name": "Ephraim Chukwu", + "avatar_url": "https://avatars.githubusercontent.com/u/68496788?v=4", + "profile": "https://audits.quillhash.com/smart-contract-audit", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, From 349583986df6dac0949b079bcec20f3f609ff898 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 10:52:45 +0200 Subject: [PATCH 082/127] format code --- .../implementations/fp16x16/math/comp.cairo | 4 +- .../fp16x16wide/math/comp.cairo | 4 +- .../implementations/fp8x23/math/comp.cairo | 5 +- .../fp8x23wide/math/comp.cairo | 4 +- src/numbers/signed_integer/i64.cairo | 2 +- src/operators/tensor.cairo | 4 +- src/operators/tensor/core.cairo | 8 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 16 ++-- .../implementations/tensor_fp32x32.cairo | 6 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 6 +- .../implementations/tensor_fp8x23wide.cairo | 4 +- .../tensor/implementations/tensor_i32.cairo | 6 +- .../tensor/implementations/tensor_i8.cairo | 4 +- .../tensor/implementations/tensor_u32.cairo | 8 +- src/operators/tensor/math/bitwise_and.cairo | 2 +- src/operators/tensor/math/not.cairo | 17 ++-- src/operators/tensor/math/reduce_l1.cairo | 3 +- src/operators/tensor/math/reduce_l2.cairo | 11 +-- .../tensor/math/reduce_sum_square.cairo | 9 +- src/utils.cairo | 10 +- tests/nodes.cairo | 96 +++++++++---------- ...ce_l1_fp16x16_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_l1_fp16x16_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...p16x16_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...uce_l1_fp8x23_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_l1_fp8x23_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...fp8x23_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...reduce_l1_i32_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/reduce_l1_i32_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...l1_i32_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_l1_i8_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/reduce_l1_i8_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ..._l1_i8_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...reduce_l1_u32_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/reduce_l1_u32_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...l1_u32_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...ce_l2_fp16x16_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_l2_fp16x16_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...p16x16_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...uce_l2_fp8x23_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_l2_fp8x23_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...fp8x23_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...quare_fp16x16_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...e_sum_square_fp16x16_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...p16x16_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...square_fp8x23_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...ce_sum_square_fp8x23_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...fp8x23_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...um_square_i32_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...educe_sum_square_i32_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...re_i32_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...sum_square_i8_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...reduce_sum_square_i8_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...are_i8_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...um_square_u32_export_do_not_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...educe_sum_square_u32_export_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- ...re_u32_export_negative_axes_keepdims.cairo | 6 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- tests/tensor_core/at/at_bool_test.cairo | 10 +- .../tensor_core/stride/stride_bool_test.cairo | 13 +-- 133 files changed, 305 insertions(+), 311 deletions(-) diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 59067e17d..12003fc75 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -103,8 +103,8 @@ mod tests { #[test] fn test_bitwise_and() { - let a = FixedTrait::new(225280, false); // 3.4375 - let b = FixedTrait::new(4160843776, true); // -2046.5625 + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 let c = FixedTrait::new(94208, false); // 1.4375 assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 04e9fe3d4..012d959c1 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -103,8 +103,8 @@ mod tests { #[test] fn test_bitwise_and() { - let a = FixedTrait::new(225280, false); // 3.4375 - let b = FixedTrait::new(4160843776, true); // -2046.5625 + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 let c = FixedTrait::new(94208, false); // 1.4375 assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index 5ca6233f4..f329371e6 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -101,10 +101,9 @@ mod tests { } #[test] fn test_bitwise_and() { - let a = FixedTrait::new(28835840, false); // 3.4375 - let b = FixedTrait::new(1639448576, true); // -60.5625 + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } - } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index 3c583f60c..da3739fb0 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -103,8 +103,8 @@ mod tests { #[test] fn test_bitwise_and() { - let a = FixedTrait::new(28835840, false); // 3.4375 - let b = FixedTrait::new(1639448576, true); // -60.5625 + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index 99dddd68c..0b5db1c6b 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -472,4 +472,4 @@ fn i64_sign(a: i64) -> i64 { fn i64_bitwise_and(a: i64, b: i64) -> i64 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) -} \ No newline at end of file +} diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 49b01c63e..b413696e2 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -35,7 +35,5 @@ use orion::operators::tensor::implementations::tensor_u32::{ U32Tensor, U32TensorAdd, U32TensorSub, U32TensorMul, U32TensorDiv, U32TensorPartialEq }; -use orion::operators::tensor::implementations::tensor_bool::{ - BoolTensor, BoolTensorPartialEq -}; +use orion::operators::tensor::implementations::tensor_bool::{BoolTensor, BoolTensorPartialEq}; diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index ee6a179c8..9ac16691e 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3329,7 +3329,13 @@ trait TensorTrait { /// [ 4, 0, 3, 0, 0]] /// ``` /// - fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor; /// # tensor.trilu /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index cecf35067..8b27883fa 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -310,7 +310,7 @@ impl FP16x16Tensor of TensorTrait { fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } - + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 9be986156..68f2482e7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -298,7 +298,7 @@ impl FP16x16WTensor of TensorTrait { fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } - + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } @@ -312,18 +312,22 @@ impl FP16x16WTensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - - fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) - } + } } /// 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 0bd590503..f764b1920 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -311,14 +311,14 @@ impl FP32x32Tensor of TensorTrait { fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } - + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) - } + } fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l1::reduce_l1(self, axis, keepdims) @@ -337,7 +337,7 @@ impl FP32x32Tensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 560d012e5..6cded29b3 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -331,7 +331,7 @@ impl FP64x64Tensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) } - + fn scatter( self: @Tensor, updates: Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 8fb8311fc..fdcdac1eb 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -318,11 +318,11 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l1::reduce_l1(self, axis, keepdims) } - + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) } - + fn scatter( self: @Tensor, updates: Tensor, @@ -336,7 +336,7 @@ impl FP8x23Tensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index a6678cb39..510731702 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -300,7 +300,7 @@ impl FP8x23WTensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } @@ -308,7 +308,7 @@ impl FP8x23WTensor of TensorTrait { fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) } - + fn scatter( self: @Tensor, updates: Tensor, diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 0d3abdb64..8017ab300 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -318,11 +318,11 @@ impl I32Tensor of TensorTrait { fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l1::reduce_l1(self, axis, keepdims) } - + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) } - + fn scatter( self: @Tensor, updates: Tensor, @@ -336,7 +336,7 @@ impl I32Tensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 086f7298b..4f2731b80 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -309,7 +309,7 @@ impl I8Tensor of TensorTrait { fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } - + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } @@ -335,7 +335,7 @@ impl I8Tensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index d8aed6aa7..2f3c3a2ef 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -280,7 +280,7 @@ impl U32Tensor of TensorTrait { fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_and::bitwise_and(self, other) } - + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } @@ -288,11 +288,11 @@ impl U32Tensor of TensorTrait { fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l1::reduce_l1(self, axis, keepdims) } - + fn trilu(self: @Tensor, upper: bool, k: i64) -> Tensor { linalg::trilu::trilu(self, upper, k) } - + fn scatter( self: @Tensor, updates: Tensor, @@ -306,7 +306,7 @@ impl U32Tensor of TensorTrait { fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } - + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } diff --git a/src/operators/tensor/math/bitwise_and.cairo b/src/operators/tensor/math/bitwise_and.cairo index 6dd3f88ba..41e9304e3 100644 --- a/src/operators/tensor/math/bitwise_and.cairo +++ b/src/operators/tensor/math/bitwise_and.cairo @@ -48,4 +48,4 @@ fn bitwise_and< }; return TensorTrait::::new(broadcasted_shape, result.span()); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/not.cairo b/src/operators/tensor/math/not.cairo index a727de4e5..ee6b42baa 100644 --- a/src/operators/tensor/math/not.cairo +++ b/src/operators/tensor/math/not.cairo @@ -8,7 +8,7 @@ use orion::operators::tensor::core::{Tensor, TensorTrait}; // Cf TensorTrait::not docstring -fn not < +fn not< T, MAG, impl TTensor: TensorTrait, @@ -16,20 +16,17 @@ fn not < impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop -> (mut z: Tensor) -> Tensor { +>( + mut z: Tensor +) -> Tensor { let mut data_result = ArrayTrait::::new(); loop { match z.data.pop_front() { - Option::Some(item) => { - data_result.append(!*item); - - }, - Option::None(_) => { - break; - } + Option::Some(item) => { data_result.append(!*item); }, + Option::None(_) => { break; } }; }; return TensorTrait::new(z.shape, data_result.span()); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/reduce_l1.cairo b/src/operators/tensor/math/reduce_l1.cairo index a53f2507e..27241e32d 100644 --- a/src/operators/tensor/math/reduce_l1.cairo +++ b/src/operators/tensor/math/reduce_l1.cairo @@ -21,5 +21,4 @@ fn reduce_l1< ) -> Tensor { let data_abs = self.abs(); return data_abs.reduce_sum(axis: axis, keepdims: keepdims); - -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo index 94e6de46c..45c6b3ddd 100644 --- a/src/operators/tensor/math/reduce_l2.cairo +++ b/src/operators/tensor/math/reduce_l2.cairo @@ -25,10 +25,10 @@ fn square< loop { match data.pop_front() { - Option::Some(item) => { + Option::Some(item) => { let ele = *item; - output_data.append(ele * ele); - }, + output_data.append(ele * ele); + }, Option::None(_) => { break; } }; }; @@ -50,7 +50,6 @@ fn reduce_l2< self: @Tensor, axis: usize, keepdims: bool ) -> Tensor { let tensor_square = square(self); - let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); + let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); return tensor_square_sum.sqrt(); - -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/reduce_sum_square.cairo b/src/operators/tensor/math/reduce_sum_square.cairo index 38d1fa6a5..3537982a0 100644 --- a/src/operators/tensor/math/reduce_sum_square.cairo +++ b/src/operators/tensor/math/reduce_sum_square.cairo @@ -25,10 +25,10 @@ fn square< loop { match data.pop_front() { - Option::Some(item) => { + Option::Some(item) => { let ele = *item; - output_data.append(ele * ele); - }, + output_data.append(ele * ele); + }, Option::None(_) => { break; } }; }; @@ -51,7 +51,6 @@ fn reduce_sum_square< self: @Tensor, axis: usize, keepdims: bool ) -> Tensor { let tensor_square = square(self); - let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); + let tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); return tensor_square_sum; - } diff --git a/src/utils.cairo b/src/utils.cairo index 6d648d627..4d4834889 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -36,10 +36,10 @@ fn assert_seq_eq, impl TCopy: Copy, impl TDr let mut i = 0; loop { - if i >= lhs.len() { - break; - } - assert_eq(lhs[i], rhs[i]); - i += 1; + if i >= lhs.len() { + break; + } + assert_eq(lhs[i], rhs[i]); + i += 1; } } diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 01f06fd0d..23f5c9731 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -606,51 +606,51 @@ mod triu_u32_pos; mod triu_u32_square; mod triu_u32_square_neg; mod triu_u32_zero; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; -mod reduce_sum_square_fp16x16_export_do_not_keepdims; -mod reduce_sum_square_fp16x16_export_keepdims; -mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; -mod reduce_sum_square_fp8x23_export_do_not_keepdims; -mod reduce_sum_square_fp8x23_export_keepdims; -mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; -mod reduce_sum_square_i32_export_do_not_keepdims; -mod reduce_sum_square_i32_export_keepdims; -mod reduce_sum_square_i32_export_negative_axes_keepdims; -mod reduce_sum_square_i8_export_do_not_keepdims; -mod reduce_sum_square_i8_export_keepdims; -mod reduce_sum_square_i8_export_negative_axes_keepdims; -mod reduce_sum_square_u32_export_do_not_keepdims; -mod reduce_sum_square_u32_export_keepdims; -mod reduce_sum_square_u32_export_negative_axes_keepdims; -mod reduce_l2_fp16x16_export_do_not_keepdims; -mod reduce_l2_fp16x16_export_keepdims; -mod reduce_l2_fp16x16_export_negative_axes_keepdims; -mod reduce_l2_fp8x23_export_do_not_keepdims; -mod reduce_l2_fp8x23_export_keepdims; -mod reduce_l2_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_fp16x16_export_do_not_keepdims; -mod reduce_l1_fp16x16_export_keepdims; -mod reduce_l1_fp16x16_export_negative_axes_keepdims; -mod reduce_l1_fp8x23_export_do_not_keepdims; -mod reduce_l1_fp8x23_export_keepdims; -mod reduce_l1_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_i32_export_do_not_keepdims; -mod reduce_l1_i32_export_keepdims; -mod reduce_l1_i32_export_negative_axes_keepdims; -mod reduce_l1_i8_export_do_not_keepdims; -mod reduce_l1_i8_export_keepdims; -mod reduce_l1_i8_export_negative_axes_keepdims; -mod reduce_l1_u32_export_do_not_keepdims; -mod reduce_l1_u32_export_keepdims; -mod reduce_l1_u32_export_negative_axes_keepdims; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; +mod reduce_sum_square_fp16x16_export_do_not_keepdims; +mod reduce_sum_square_fp16x16_export_keepdims; +mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +mod reduce_sum_square_fp8x23_export_do_not_keepdims; +mod reduce_sum_square_fp8x23_export_keepdims; +mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +mod reduce_sum_square_i32_export_do_not_keepdims; +mod reduce_sum_square_i32_export_keepdims; +mod reduce_sum_square_i32_export_negative_axes_keepdims; +mod reduce_sum_square_i8_export_do_not_keepdims; +mod reduce_sum_square_i8_export_keepdims; +mod reduce_sum_square_i8_export_negative_axes_keepdims; +mod reduce_sum_square_u32_export_do_not_keepdims; +mod reduce_sum_square_u32_export_keepdims; +mod reduce_sum_square_u32_export_negative_axes_keepdims; +mod reduce_l2_fp16x16_export_do_not_keepdims; +mod reduce_l2_fp16x16_export_keepdims; +mod reduce_l2_fp16x16_export_negative_axes_keepdims; +mod reduce_l2_fp8x23_export_do_not_keepdims; +mod reduce_l2_fp8x23_export_keepdims; +mod reduce_l2_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_fp16x16_export_do_not_keepdims; +mod reduce_l1_fp16x16_export_keepdims; +mod reduce_l1_fp16x16_export_negative_axes_keepdims; +mod reduce_l1_fp8x23_export_do_not_keepdims; +mod reduce_l1_fp8x23_export_keepdims; +mod reduce_l1_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_i32_export_do_not_keepdims; +mod reduce_l1_i32_export_keepdims; +mod reduce_l1_i32_export_negative_axes_keepdims; +mod reduce_l1_i8_export_do_not_keepdims; +mod reduce_l1_i8_export_keepdims; +mod reduce_l1_i8_export_negative_axes_keepdims; +mod reduce_l1_u32_export_do_not_keepdims; +mod reduce_l1_u32_export_keepdims; +mod reduce_l1_u32_export_negative_axes_keepdims; diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo index d2edc5b85..f6bb75879 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp16x16_export_do_not_keepdims() { let y = input_0.reduce_l1(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo index 8a217a3e3..469065dfb 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 19, sign: false }); data.append(FP16x16 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo index beecff5ab..78fcf0745 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp16x16_export_keepdims() { let y = input_0.reduce_l1(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo index 32d2bf963..9b891a9d8 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 19, sign: false }); data.append(FP16x16 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo index a3c1a3b02..06e2979d1 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp16x16_export_negative_axes_keepdims() { let y = input_0.reduce_l1(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo index 3fb854ee1..24b177504 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 26, sign: false }); data.append(FP16x16 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo index 8e67a074e..2c32d5175 100644 --- a/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -21,4 +21,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 51, sign: false }); data.append(FP16x16 { mag: 54, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo index 0eba0ba94..48aad5edc 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp8x23_export_do_not_keepdims() { let y = input_0.reduce_l1(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo index 59d8271ec..f00310f21 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 19, sign: false }); data.append(FP8x23 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo index 743a5b2d9..6a8fe3025 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp8x23_export_keepdims() { let y = input_0.reduce_l1(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo index 13d940044..ed64785b0 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 19, sign: false }); data.append(FP8x23 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo index 527596d05..c34580015 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_fp8x23_export_negative_axes_keepdims() { let y = input_0.reduce_l1(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo index c811d8c9e..83083d532 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 26, sign: false }); data.append(FP8x23 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo index d3b359f75..e63f27eb6 100644 --- a/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -21,4 +21,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 51, sign: false }); data.append(FP8x23 { mag: 54, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo index b6999dcd9..a61abd308 100644 --- a/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i32_export_do_not_keepdims() { let y = input_0.reduce_l1(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo index 9eb75d28a..473726054 100644 --- a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 11, sign: false }); data.append(i32 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo index 1702243f2..54b9bb2e2 100644 --- a/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_do_not_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 19, sign: false }); data.append(i32 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_keepdims.cairo index 7dd39c047..93c0097fe 100644 --- a/tests/nodes/reduce_l1_i32_export_keepdims.cairo +++ b/tests/nodes/reduce_l1_i32_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i32_export_keepdims() { let y = input_0.reduce_l1(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo index 9eb75d28a..473726054 100644 --- a/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 11, sign: false }); data.append(i32 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo index 2635bd2d6..0d2a269cc 100644 --- a/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 19, sign: false }); data.append(i32 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo index bc6e69942..401147413 100644 --- a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i32_export_negative_axes_keepdims() { let y = input_0.reduce_l1(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo index 6b7f8d481..f6679d594 100644 --- a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 26, sign: false }); data.append(i32 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo index e823cfa25..ee60e4b2d 100644 --- a/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i32_export_negative_axes_keepdims/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 51, sign: false }); data.append(i32 { mag: 54, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo index dfea03f2a..3c10a98ca 100644 --- a/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i8_export_do_not_keepdims() { let y = input_0.reduce_l1(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo index 20c48f542..f0b35dada 100644 --- a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 11, sign: false }); data.append(i8 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo index 3068a233d..48759052e 100644 --- a/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_do_not_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 19, sign: false }); data.append(i8 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_keepdims.cairo index 35b1d30c5..fe78e32b1 100644 --- a/tests/nodes/reduce_l1_i8_export_keepdims.cairo +++ b/tests/nodes/reduce_l1_i8_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i8_export_keepdims() { let y = input_0.reduce_l1(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo index 20c48f542..f0b35dada 100644 --- a/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 11, sign: false }); data.append(i8 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo index 25e4fdc57..eb47fa2ec 100644 --- a/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 19, sign: false }); data.append(i8 { mag: 23, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo index 79ec8d936..696b43e57 100644 --- a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_i8_export_negative_axes_keepdims() { let y = input_0.reduce_l1(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo index 920e8898b..303e14acb 100644 --- a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 26, sign: false }); data.append(i8 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo index bc3a31f63..b6e133c08 100644 --- a/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_i8_export_negative_axes_keepdims/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 51, sign: false }); data.append(i8 { mag: 54, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo index 8a0b11c3b..19d04b91e 100644 --- a/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_u32_export_do_not_keepdims() { let y = input_0.reduce_l1(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo index 1aeead0b2..ffe2ae114 100644 --- a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(11); data.append(12); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo index a40dbfa0f..628d60f78 100644 --- a/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_do_not_keepdims/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(19); data.append(23); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_keepdims.cairo index 50ac5c706..b7b53a21e 100644 --- a/tests/nodes/reduce_l1_u32_export_keepdims.cairo +++ b/tests/nodes/reduce_l1_u32_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_u32_export_keepdims() { let y = input_0.reduce_l1(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo index 1aeead0b2..ffe2ae114 100644 --- a/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_keepdims/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(11); data.append(12); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo index 7a97d1ba5..f9fbfe99b 100644 --- a/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(19); data.append(23); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo index 99345a8bc..d3dc9612c 100644 --- a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l1_u32_export_negative_axes_keepdims() { let y = input_0.reduce_l1(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo index 9fce7f6df..d24e18d36 100644 --- a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(26); data.append(27); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo index 42a13ba2a..12c8f37e5 100644 --- a/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l1_u32_export_negative_axes_keepdims/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(51); data.append(54); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo index fa5bc1a97..a8391d898 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp16x16_export_do_not_keepdims() { let y = input_0.reduce_l2(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo index 0c036c85e..2ac178998 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 13, sign: false }); data.append(FP16x16 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo index aa7730801..6c9f3ba96 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp16x16_export_keepdims() { let y = input_0.reduce_l2(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo index 569945db0..f6fb5dcd2 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 13, sign: false }); data.append(FP16x16 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo index 799cac6a2..d7fb90de0 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp16x16_export_negative_axes_keepdims() { let y = input_0.reduce_l2(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo index 3fb854ee1..24b177504 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 26, sign: false }); data.append(FP16x16 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo index 5feddbc13..da695728b 100644 --- a/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -21,4 +21,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 32, sign: false }); data.append(FP16x16 { mag: 33, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo index e3ff241a2..b9a893a55 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp8x23_export_do_not_keepdims() { let y = input_0.reduce_l2(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo index 01a191e5c..a3e1b86e6 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 13, sign: false }); data.append(FP8x23 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo index f9eb738ce..bf4cc316c 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp8x23_export_keepdims() { let y = input_0.reduce_l2(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo index 98240f104..f836af1df 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 13, sign: false }); data.append(FP8x23 { mag: 16, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo index 8b902498b..8419e0f01 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_l2_fp8x23_export_negative_axes_keepdims() { let y = input_0.reduce_l2(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo index c811d8c9e..83083d532 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 26, sign: false }); data.append(FP8x23 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo index d95c89484..0b24b02b4 100644 --- a/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_l2_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -21,4 +21,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 32, sign: false }); data.append(FP8x23 { mag: 33, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo index 38ee4224e..01b66ce55 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp16x16_export_do_not_keepdims() { let y = input_0.reduce_sum_square(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo index 9163477b3..27229e38c 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 181, sign: false }); data.append(FP16x16 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo index 0d719ecbe..b0d58226a 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp16x16_export_keepdims() { let y = input_0.reduce_sum_square(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo index 7ad478c1f..d65ccc294 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 11, sign: false }); data.append(FP16x16 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo index 047175d25..746290f27 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 181, sign: false }); data.append(FP16x16 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo index f6cdef499..a755cd3c7 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp16x16_export_negative_axes_keepdims() { let y = input_0.reduce_sum_square(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo index cfd388d38..3bf061882 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 7, sign: false }); data.append(FP16x16 { mag: 8, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo index d2b14f466..64235ba5b 100644 --- a/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 58, sign: false }); data.append(FP16x16 { mag: 80, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo index c2862201c..455491f61 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp8x23_export_do_not_keepdims() { let y = input_0.reduce_sum_square(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo index b47aee451..36829be8a 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_do_not_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 181, sign: false }); data.append(FP8x23 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo index 8436ea724..df7587e27 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp8x23_export_keepdims() { let y = input_0.reduce_sum_square(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo index ea37e2ec6..974166ede 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/input_0.cairo @@ -24,4 +24,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 11, sign: false }); data.append(FP8x23 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo index eacbeb69b..46558ba27 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_keepdims/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 181, sign: false }); data.append(FP8x23 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo index 5257b13fa..70eaa2026 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_fp8x23_export_negative_axes_keepdims() { let y = input_0.reduce_sum_square(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo index c811d8c9e..83083d532 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 26, sign: false }); data.append(FP8x23 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo index 188936e46..e20695c11 100644 --- a/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -21,4 +21,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 1029, sign: false }); data.append(FP8x23 { mag: 1134, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo index 60f2eb08b..d3fe70de2 100644 --- a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i32_export_do_not_keepdims() { let y = input_0.reduce_sum_square(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo index 9eb75d28a..473726054 100644 --- a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 11, sign: false }); data.append(i32 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo index 628310be4..633aaf89a 100644 --- a/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_do_not_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 181, sign: false }); data.append(i32 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo index f75199c20..ee20e9705 100644 --- a/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i32_export_keepdims() { let y = input_0.reduce_sum_square(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo index 9eb75d28a..473726054 100644 --- a/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 11, sign: false }); data.append(i32 { mag: 12, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo index 4005461de..8c8496888 100644 --- a/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_keepdims/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 181, sign: false }); data.append(i32 { mag: 265, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo index 5e6d9d87b..c6568b72e 100644 --- a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i32_export_negative_axes_keepdims() { let y = input_0.reduce_sum_square(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo index 6b7f8d481..f6679d594 100644 --- a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 26, sign: false }); data.append(i32 { mag: 27, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo index 770b6e29e..e5d345b9d 100644 --- a/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i32_export_negative_axes_keepdims/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1029, sign: false }); data.append(i32 { mag: 1134, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo index aed5b8cc7..6279189fb 100644 --- a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i8_export_do_not_keepdims() { let y = input_0.reduce_sum_square(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo index 5fe3138cd..c73e6026f 100644 --- a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 7, sign: false }); data.append(i8 { mag: 8, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo index 7a559c76a..55ad2f174 100644 --- a/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_do_not_keepdims/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 61, sign: false }); data.append(i8 { mag: 113, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo index 2f8162e20..339cef0fc 100644 --- a/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i8_export_keepdims() { let y = input_0.reduce_sum_square(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo index 5fe3138cd..c73e6026f 100644 --- a/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 7, sign: false }); data.append(i8 { mag: 8, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo index e8e49e9e5..50ea0db9c 100644 --- a/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_keepdims/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 61, sign: false }); data.append(i8 { mag: 113, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo index 2619e1c19..545f0b7a9 100644 --- a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_i8_export_negative_axes_keepdims() { let y = input_0.reduce_sum_square(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo index 5fe3138cd..c73e6026f 100644 --- a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 7, sign: false }); data.append(i8 { mag: 8, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo index a6e80a392..65a421543 100644 --- a/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_i8_export_negative_axes_keepdims/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 58, sign: false }); data.append(i8 { mag: 80, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo index 1710b3440..45f781299 100644 --- a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_u32_export_do_not_keepdims() { let y = input_0.reduce_sum_square(2, false); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo index 1aeead0b2..ffe2ae114 100644 --- a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(11); data.append(12); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo index f08f41055..cb13caf04 100644 --- a/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_do_not_keepdims/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(181); data.append(265); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo index 3e1b50888..51bfc851b 100644 --- a/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_u32_export_keepdims() { let y = input_0.reduce_sum_square(2, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo index 1aeead0b2..ffe2ae114 100644 --- a/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(11); data.append(12); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo index eb641605e..0b53bfc0f 100644 --- a/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_keepdims/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(181); data.append(265); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo index f6259fa60..ad95a1868 100644 --- a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_reduce_sum_square_u32_export_negative_axes_keepdims() { let y = input_0.reduce_sum_square(0, true); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo index 9fce7f6df..d24e18d36 100644 --- a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(26); data.append(27); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo index 31844609a..01bc3598a 100644 --- a/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_square_u32_export_negative_axes_keepdims/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(1029); data.append(1134); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/tensor_core/at/at_bool_test.cairo b/tests/tensor_core/at/at_bool_test.cairo index c95902631..ae511cbda 100644 --- a/tests/tensor_core/at/at_bool_test.cairo +++ b/tests/tensor_core/at/at_bool_test.cairo @@ -20,7 +20,6 @@ mod tensor_1D { let tensor = TensorTrait::::new(sizes.span(), data.span()); - let mut indices = ArrayTrait::new(); indices.append(1); @@ -43,7 +42,7 @@ mod tensor_2D { #[test] #[available_gas(2000000)] fn tensor_at() { - let mut sizes = ArrayTrait::new(); + let mut sizes = ArrayTrait::new(); sizes.append(2); sizes.append(2); @@ -55,7 +54,6 @@ mod tensor_2D { let tensor = TensorTrait::::new(sizes.span(), data.span()); - let mut indices = ArrayTrait::new(); indices.append(1); indices.append(1); @@ -78,7 +76,6 @@ mod tensor_3D { #[test] #[available_gas(2000000)] fn tensor_at() { - let mut sizes = ArrayTrait::new(); sizes.append(2); sizes.append(2); @@ -88,15 +85,14 @@ mod tensor_3D { data.append(false); data.append(false); data.append(false); - data.append(true); + data.append(true); + data.append(false); data.append(false); data.append(false); - data.append(false); data.append(false); let tensor = TensorTrait::::new(sizes.span(), data.span()); - let mut indices = ArrayTrait::new(); indices.append(0); indices.append(1); diff --git a/tests/tensor_core/stride/stride_bool_test.cairo b/tests/tensor_core/stride/stride_bool_test.cairo index 314e97f7b..ed56853ae 100644 --- a/tests/tensor_core/stride/stride_bool_test.cairo +++ b/tests/tensor_core/stride/stride_bool_test.cairo @@ -20,10 +20,9 @@ mod tensor_1D { let tensor = TensorTrait::::new(sizes.span(), data.span()); - let result = tensor.stride(); - assert(*result[0] == 1, 'stride x = 1'); + assert(*result[0] == 1, 'stride x = 1'); assert(result.len() == 1, 'len = 1'); } } @@ -41,7 +40,7 @@ mod tensor_2D { #[test] #[available_gas(2000000)] fn tensor_at() { - let mut sizes = ArrayTrait::new(); + let mut sizes = ArrayTrait::new(); sizes.append(2); sizes.append(2); @@ -53,10 +52,9 @@ mod tensor_2D { let tensor = TensorTrait::::new(sizes.span(), data.span()); - let result = tensor.stride(); - assert(*result[0] == 2, 'stride x = 2'); + assert(*result[0] == 2, 'stride x = 2'); assert(*result[1] == 1, 'stride y = 1'); assert(result.len() == 2, 'len = 2'); } @@ -74,7 +72,6 @@ mod tensor_3D { #[test] #[available_gas(2000000)] fn tensor_at() { - let mut sizes = ArrayTrait::new(); sizes.append(2); sizes.append(2); @@ -84,10 +81,10 @@ mod tensor_3D { data.append(false); data.append(false); data.append(false); - data.append(true); + data.append(true); + data.append(false); data.append(false); data.append(false); - data.append(false); data.append(false); let tensor = TensorTrait::::new(sizes.span(), data.span()); From ed10a4c0f1b938cbb56d36f4bfd6456933615182 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 10:56:18 +0200 Subject: [PATCH 083/127] Update Scarb.toml --- Scarb.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarb.toml b/Scarb.toml index ed13d778d..84f1195c9 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,6 +1,6 @@ [package] name = "orion" -version = "0.1.5" +version = "0.1.7" description = "ONNX Runtime in Cairo for verifiable ML inference using STARK" homepage = "https://github.com/gizatechxyz/orion" From 1744d7598ccea4ccf6233218109da9c8c974de8c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 09:05:40 +0000 Subject: [PATCH 084/127] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3631dc7cc..28d6d66bd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -99,6 +99,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Ephraim Chukwu
Ephraim Chukwu

💻 Bal7hazar
Bal7hazar

🐛 Tony Stark
Tony Stark

📖 + Bilgin Koçak
Bilgin Koçak

💻 From 951ecbb8c422916185683643c2ec0b044bc3d6c6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 09:05:41 +0000 Subject: [PATCH 085/127] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b282fc04..07d81f637 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -224,6 +224,15 @@ "contributions": [ "doc" ] + }, + { + "login": "bilgin-kocak", + "name": "Bilgin Koçak", + "avatar_url": "https://avatars.githubusercontent.com/u/30844607?v=4", + "profile": "https://www.bilginkocak.com/", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, From c849d67899b6c7ceae248124d2bc945bb42cf3d9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn <113879115+raphaelDkhn@users.noreply.github.com> Date: Sun, 12 Nov 2023 11:06:59 +0200 Subject: [PATCH 086/127] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28d6d66bd..a84cbc4b8 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ See [LICENSE](https://github.com/franalgaba/onnx-cairo/blob/main/LICENSE/README. ## Contributors ✨ -Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): +Thanks goes to these wonderful people: From 6df8b68f2df87021631be4a232edf62736018473 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 11:22:04 +0200 Subject: [PATCH 087/127] Update compatibility.md --- docs/framework/compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 6748af545..ebc50ad77 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -82,4 +82,4 @@ You can see below the list of current supported ONNX Operators: | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | -Current Operators support: **68/156 (43%)** +Current Operators support: **75/156 (48%)** From 61fd0d150b294d18a23e26fba8a110954c3e7070 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 16:25:57 +0100 Subject: [PATCH 088/127] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.array_feature_extractor.md | 50 ++++++++++++++++++ src/operators/tensor/core.cairo | 51 +++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.array_feature_extractor.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f96dd7a6f..ae7052c9a 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -95,6 +95,7 @@ * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + * [tensor.array_feature_extractor](framework/operators/tensor/tensor.array\_feature\_extractor.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 e5f7f39cf..9e024779b 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,5 +74,6 @@ You can see below the list of current supported ONNX Operators: | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | | [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [ArrayFeatureExtractor](operators/tensor/tensor.array\_feature\_extractor.md) | :white\_check\_mark: | -Current Operators support: **68/156 (43%)** +Current Operators support: **69/156 (44%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 369713044..402971f7c 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -91,6 +91,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | +| [`tensor.array_feature_extractor`](tensor.array_feature_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.array_feature_extractor.md b/docs/framework/operators/tensor/tensor.array_feature_extractor.md new file mode 100644 index 000000000..a852239d4 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.array_feature_extractor.md @@ -0,0 +1,50 @@ +# tensor.array_feature_extractor + +```rust + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; +``` + +Selects elements of the input tensor based on the indices passed applied to the last tensor axis. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `indices`(`Tensor`) - Tensor of indices. + +## Panics + +* Panics if indices tensor is not 1-dimensional. + +## Returns + +A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn array_feature_extractor_example() -> Tensor { + let input_tensor = TensorTrait::new( + shape: array![3, 4].span(), + data: array![ + IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), + IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), + IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) + ] + .span(), + ); + + let indices = TensorTrait::::new( + shape: array![2].span(), data: array![1, 3].span(), + ); + + return tensor.array_feature_extractor(@input_tensor, @indices); +} +>>> [[1, 3] + [5, 7] + [9, 11]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 17ee93256..47aa8ba2c 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,57 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// # tensor.array_feature_extractor + /// + /// ```rust + /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// ``` + /// + /// Selects elements of the input tensor based on the indices passed applied to the last tensor axis. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// + /// ## Panics + /// + /// * Panics if indices tensor is not 1-dimensional. + /// + /// ## Returns + /// + /// A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn array_feature_extractor_example() -> Tensor { + /// let input_tensor = TensorTrait::new( + /// shape: array![3, 4].span(), + /// data: array![ + /// IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), + /// IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), + /// IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) + /// ] + /// .span(), + /// ); + /// + /// let indices = TensorTrait::::new( + /// shape: array![2].span(), data: array![1, 3].span(), + /// ); + /// + /// return tensor.array_feature_extractor(@input_tensor, @indices); + /// } + /// >>> [[1, 3] + /// [5, 7] + /// [9, 11]] + /// ``` + /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; } From e2e81174a754283731466a66f3074ae15297a8a0 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 17:34:40 +0200 Subject: [PATCH 089/127] implement logistic post transform --- src/operators/matrix.cairo | 34 +- .../tree_ensemble_classifier.cairo | 17 +- tests/ml/tree_ensemble_classifier.cairo | 331 +++++++----------- 3 files changed, 165 insertions(+), 217 deletions(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 3de48a7e8..a9a381a20 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -133,7 +133,6 @@ impl MutMatrixImpl< return result.span(); } - /// Apply softmax to the matrix along the specified axis /// Apply softmax to the matrix along the specified axis fn softmax<+AddEq, +Div>(ref self: MutMatrix, axis: usize) -> MutMatrix { assert(axis < 2, 'Invalid axis'); @@ -214,4 +213,37 @@ impl MutMatrixImpl< result } + + /// Apply the sigmoid function to each element of the matrix + fn sigmoid<+Mul, +Add, +Div>(ref self: MutMatrix) -> MutMatrix { + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col); + if value.is_some() { + let value = NumberTrait::one() + / (NumberTrait::one() + (value.unwrap() * NumberTrait::neg_one()).exp()); + + result.set(row, col, value); + } + + col += 1; + }; + + row += 1; + }; + + result + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 850a28d94..d6898b961 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -32,11 +32,11 @@ struct TreeEnsembleClassifier { class_weights: Span, classlabels: Span, base_values: Option>, - post_transform: PostTransform, + post_transform: POST_TRANSFORM, } #[derive(Copy, Drop)] -enum PostTransform { +enum POST_TRANSFORM { NONE, SOFTMAX, LOGISTIC, @@ -58,7 +58,8 @@ impl TreeEnsembleClassifierImpl< +TensorTrait, +PrintTrait, +AddEq, - +Div + +Div, + +Mul > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); @@ -196,11 +197,11 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { - PostTransform::NONE => { res }, // No action required - PostTransform::SOFTMAX => { res.softmax(1) }, - PostTransform::LOGISTIC => panic_with_felt252('Logistic not supported yet'), - PostTransform::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), - PostTransform::PROBIT => panic_with_felt252('Probit not supported yet'), + POST_TRANSFORM::NONE => res, // No action required + POST_TRANSFORM::SOFTMAX => res.softmax(1), + POST_TRANSFORM::LOGISTIC => res.sigmoid(), + POST_TRANSFORM::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + POST_TRANSFORM::PROBIT => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 18e6d99bf..12d19cd26 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -2,7 +2,7 @@ use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait + TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait }; use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; @@ -10,203 +10,165 @@ use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_none() { - let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] - .span(); - - let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] - .span(); - - let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] - .span(); - - let class_weights: Span = array![ - FP16x16 { mag: 30583, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 2185, sign: false }, - FP16x16 { mag: 13107, sign: false }, - FP16x16 { mag: 15729, sign: false }, - FP16x16 { mag: 3932, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 32768, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 32768, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 29491, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 3277, sign: false }, - FP16x16 { mag: 6746, sign: false }, - FP16x16 { mag: 12529, sign: false }, - FP16x16 { mag: 13493, sign: false }, - ] - .span(); - - let classlabels: Span = array![0, 1, 2].span(); - - let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); - - let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); - - let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); - - let nodes_modes: Span = array![ - NODE_MODES::BRANCH_LEQ, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - ] - .span(); - - let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); - - let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); - - let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); - - let nodes_values: Span = array![ - FP16x16 { mag: 81892, sign: false }, - FP16x16 { mag: 19992, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 110300, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 44245, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - ] - .span(); - - let tree_ids: Span = array![0, 1].span(); - - let mut root_index: Felt252Dict = Default::default(); - root_index.insert(0, 0); - root_index.insert(1, 5); - - let mut node_index: Felt252Dict = Default::default(); - node_index - .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); - node_index - .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); - node_index - .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); - node_index - .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); - node_index - .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); - node_index - .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); - node_index - .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); - node_index - .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); - node_index - .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); - node_index - .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); - - let atts = TreeEnsembleAttributes { - nodes_falsenodeids, - nodes_featureids, - nodes_missing_value_tracks_true, - nodes_modes, - nodes_nodeids, - nodes_treeids, - nodes_truenodeids, - nodes_values - }; - - let mut ensemble: TreeEnsemble = TreeEnsemble { - atts, tree_ids, root_index, node_index - }; - - let base_values: Option> = Option::None; - - let post_transform = PostTransform::NONE; - - let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { - ensemble, - class_ids, - class_nodeids, - class_treeids, - class_weights, - classlabels, - base_values, - post_transform - }; - - let mut X: Tensor = TensorTrait::new( - array![3, 3].span(), - array![ - FP16x16 { mag: 65536, sign: true }, - FP16x16 { mag: 52429, sign: true }, - FP16x16 { mag: 39322, sign: true }, - FP16x16 { mag: 26214, sign: true }, - FP16x16 { mag: 13107, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 13107, sign: false }, - FP16x16 { mag: 26214, sign: false }, - FP16x16 { mag: 39322, sign: false }, - ] - .span() - ); + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::NONE); let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); // ASSERT LABELS - assert(*labels[0] == 0, 'labels[0] == 0'); - assert(*labels[1] == 0, 'labels[1] == 0'); - assert(*labels[2] == 1, 'labels[2] == 1'); - assert(labels.len() == 3, 'len(labels) == 3'); + assert(*labels[0] == 0, 'labels[0]'); + assert(*labels[1] == 0, 'labels[1]'); + assert(*labels[2] == 1, 'labels[2]'); + assert(labels.len() == 3, 'len(labels)'); // ASSERT SCORES assert( relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 60075, sign: false }) == true, - 'score[0, 0] == 0.9166666' + 'score[0, 0]' ); assert( relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, - 'score[0, 1] == 0' + 'score[0, 1]' ); assert( relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 5461, sign: false }) == true, - 'score[0, 2] == 0.08333334' + 'score[0, 2]' ); assert( relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 37329, sign: false }) == true, - 'score[1, 0] == 0.56960785' + 'score[1, 0]' ); assert( relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 12528, sign: false }) == true, - 'score[1, 1] == 0.19117647' + 'score[1, 1]' ); assert( relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 15677, sign: false }) == true, - 'score[1, 2] == 0.23921569' + 'score[1, 2]' ); assert( relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, - 'score[2, 0] == 0.30294117' + 'score[2, 0]' ); assert( relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 28257, sign: false }) == true, - 'score[2, 1] == 0.43117648' + 'score[2, 1]' ); assert( relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 17424, sign: false }) == true, - 'score[2, 2] == 0.26588234' + 'score[2, 2]' ); } #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_softmax() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0]'); + assert(*labels[1] == 0, 'labels[1]'); + assert(*labels[2] == 1, 'labels[2]'); + assert(labels.len() == 3, 'len(labels)'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2]' + ); +} + +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_logistic() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::LOGISTIC); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 46816, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 32768, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 34132, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 41856, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 35890, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 36668, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 37693, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 39724, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 37098, sign: false }) == true, + 'score[2, 2]' + ); +} + + +// ============ HELPER ============ // + +fn tree_ensemble_classifier_helper( + post_transform: POST_TRANSFORM +) -> (TreeEnsembleClassifier, Tensor) { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -325,8 +287,6 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { let base_values: Option> = Option::None; - let post_transform = PostTransform::SOFTMAX; - let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, class_ids, @@ -354,50 +314,5 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { .span() ); - let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); - - // ASSERT LABELS - assert(*labels[0] == 0, 'labels[0] == 0'); - assert(*labels[1] == 0, 'labels[1] == 0'); - assert(*labels[2] == 1, 'labels[2] == 1'); - assert(labels.len() == 3, 'len(labels) == 3'); - - // ASSERT SCORES - assert( - relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, - 'score[0, 0] == 0.545123' - ); - assert( - relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, - 'score[0, 1] == 0.217967' - ); - assert( - relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, - 'score[0, 2] == 0.23691' - ); - assert( - relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, - 'score[1, 0] == 0.416047' - ); - assert( - relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, - 'score[1, 1] == 0.284965' - ); - assert( - relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, - 'score[1, 2] == 0.298988' - ); - assert( - relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, - 'score[2, 0] == 0.322535' - ); - assert( - relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, - 'score[2, 1] == 0.366664' - ); - assert( - relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, - 'score[2, 2] == 0.310801' - ); + (classifier, X) } - From 19ef9ee45d80edb0baede8980f5fe32a848adebf Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 17:54:31 +0200 Subject: [PATCH 090/127] add softmax_zero pt --- src/operators/matrix.cairo | 94 +++++++++++++++++++ .../tree_ensemble_classifier.cairo | 2 +- tests/ml/tree_ensemble_classifier.cairo | 53 +++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index a9a381a20..0d19a7a4d 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -214,6 +214,100 @@ impl MutMatrixImpl< result } + /// Apply softmax to the matrix along the specified axis, treating zeros as neutral + fn softmax_zero<+AddEq, +Div, +PartialEq>( + ref self: MutMatrix, axis: usize + ) -> MutMatrix { + assert(axis < 2, 'Invalid axis'); + + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + sum_exp += value.exp(); + } + row += 1; + }; + + row = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + } else { + result.set(row, col, NumberTrait::zero()); + } + + row += 1; + }; + + col += 1; + }; + } else { + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + sum_exp += value.exp(); + } + col += 1; + }; + + col = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + + if value != NumberTrait::zero() { + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + } else { + result.set(row, col, NumberTrait::zero()); + } + + col += 1; + }; + + row += 1; + }; + } + + result + } + /// Apply the sigmoid function to each element of the matrix fn sigmoid<+Mul, +Add, +Div>(ref self: MutMatrix) -> MutMatrix { let mut result = MutMatrixImpl::new(self.rows, self.cols); diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index d6898b961..75e82df4f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -200,7 +200,7 @@ impl TreeEnsembleClassifierImpl< POST_TRANSFORM::NONE => res, // No action required POST_TRANSFORM::SOFTMAX => res.softmax(1), POST_TRANSFORM::LOGISTIC => res.sigmoid(), - POST_TRANSFORM::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + POST_TRANSFORM::SOFTMAXZERO => res.softmax_zero(1), POST_TRANSFORM::PROBIT => panic_with_felt252('Probit not supported yet'), }; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 12d19cd26..cee9ee80d 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -111,6 +111,59 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { ); } +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_softmax_zero() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAXZERO); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 45682, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2]' + ); +} + + #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_logistic() { From dedb48ace675684530824d84c445a35e672e56a9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 18:17:34 +0200 Subject: [PATCH 091/127] Update tree_ensemble_classifier.cairo --- src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 75e82df4f..badaa549d 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -64,6 +64,7 @@ impl TreeEnsembleClassifierImpl< fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); let n_classes = self.classlabels.len(); + assert(n_classes > 1, 'binary class not supported yet'); let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); // Set base values From 8316c47d25db54ab20b15206fb0e7689719c0def Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 18:49:40 +0200 Subject: [PATCH 092/127] generate doc --- docgen/src/main.rs | 8 + docs/SUMMARY.md | 2 + .../tree-ensemble-classifier/README.md | 27 +++ .../tree_ensemble_classifier.predict.md | 199 +++++++++++++++++ .../tree_ensemble_classifier.cairo | 208 +++++++++++++++++- 5 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md create mode 100644 docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md diff --git a/docgen/src/main.rs b/docgen/src/main.rs index 54a8e9fcc..97d11b112 100644 --- a/docgen/src/main.rs +++ b/docgen/src/main.rs @@ -58,6 +58,14 @@ fn main() { let trait_name: &str = "XGBoostRegressorTrait"; doc_trait(trait_path, doc_path, label); doc_functions(trait_path, doc_path, trait_name, label); + + // TREE ENSEMBLE CLASSIFIER DOC + let trait_path = "src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo"; + let doc_path = "docs/framework/operators/machine-learning/tree-ensemble-classifier"; + let label = "tree_ensemble_classifier"; + let trait_name: &str = "TreeEnsembleClassifierTrait"; + doc_trait(trait_path, doc_path, label); + doc_functions(trait_path, doc_path, trait_name, label); } fn doc_trait(trait_path: &str, doc_path: &str, label: &str) { diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index ea9613ce3..2de1306f5 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -106,6 +106,8 @@ * [nn.thresholded\_relu](framework/operators/neural-network/nn.thresholded_relu.md) * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) + * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) + * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md new file mode 100644 index 000000000..a3028a8be --- /dev/null +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md @@ -0,0 +1,27 @@ +# Tree Ensemble Classifier + +`TreeEnsembleClassifierTrait` provides a trait definition for tree ensemble classification problem. + +```rust +use orion::operators::ml::TreeEnsembleClassifierTrait; +``` + +### Data types + +Orion supports currently only fixed point data types for `TreeEnsembleClassifierTrait`. + +| Data type | dtype | +| -------------------- | ------------------------------------------------------------- | +| Fixed point (signed) | `TreeRegressorTrait` | + +### How to construct `TreeEnsembleClassifier` + +You can utilize [this notebook](https://colab.research.google.com/drive/1qem56rUKJcNongXsLZ16_869q8395prz#scrollTo=V3qGW_kfXudk) to translate parameters from your ONNX TreeEnsembleClassifier model into Cairo code. Efforts are underway to integrate this functionality into Giza-CLI, aiming to enhance the user experience. + + +*** + +| function | description | +| ------------------------------------------------------------------------- | ------------------------------------------- | +| [`tree_ensemble_classifier.predict`](tree_ensemble_classifier.predict.md) | Returns the top class for each of N inputs. | + diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md new file mode 100644 index 000000000..8998fcfb7 --- /dev/null +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md @@ -0,0 +1,199 @@ +# TreeEnsembleClassifier::predict + +```rust + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); +``` + +Tree Ensemble classifier. Returns the top class for each of N inputs. + +## Args + +* `self`: TreeEnsembleClassifier - A TreeEnsembleClassifier object. +* `X`: Input 2D tensor. + +## Returns + +* N Top class for each point +* The class score Matrix for each class, for each point. + +## Type Constraints + +`TreeEnsembleClassifier` and `X` must be fixed points + +## Examples + +```rust +use orion::numbers::FP16x16; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; +use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait +}; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + +fn tree_ensemble_classifier_helper( + post_transform: POST_TRANSFORM +) -> (TreeEnsembleClassifier, Tensor) { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let classlabels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + classlabels, + base_values, + post_transform + }; + + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() + ); + + (classifier, X) +} + +fn test_tree_ensemble_classifier_multi_pt_softmax() -> (Span, MutMatrix::) { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + + let (labels, scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + (labels, scores) +} + +>>> +([0, 0, 1], + [ + [0.545123, 0.217967, 0.23691], + [0.416047, 0.284965, 0.298988], + [0.322535, 0.366664, 0.310801], + ]) +``` diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index badaa549d..0adb8a638 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -44,7 +44,213 @@ enum POST_TRANSFORM { PROBIT, } -#[generate_trait] +/// Trait +/// +/// predict - Returns the top class for each of N inputs. +trait TreeEnsembleClassifierTrait { + /// # TreeEnsembleClassifier::predict + /// + /// ```rust + /// fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); + /// ``` + /// + /// Tree Ensemble classifier. Returns the top class for each of N inputs. + /// + /// ## Args + /// + /// * `self`: TreeEnsembleClassifier - A TreeEnsembleClassifier object. + /// * `X`: Input 2D tensor. + /// + /// ## Returns + /// + /// * N Top class for each point + /// * The class score Matrix for each class, for each point. + /// + /// ## Type Constraints + /// + /// `TreeEnsembleClassifier` and `X` must be fixed points + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::FP16x16; + /// use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; + /// use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; + /// use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + /// TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait + /// }; + /// use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + /// + /// fn tree_ensemble_classifier_helper( + /// post_transform: POST_TRANSFORM + ///) -> (TreeEnsembleClassifier, Tensor) { + /// let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + /// .span(); + /// + /// let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + /// .span(); + /// + /// let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + /// .span(); + /// + /// let class_weights: Span = array![ + /// FP16x16 { mag: 30583, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 2185, sign: false }, + /// FP16x16 { mag: 13107, sign: false }, + /// FP16x16 { mag: 15729, sign: false }, + /// FP16x16 { mag: 3932, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 32768, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 32768, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 29491, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 3277, sign: false }, + /// FP16x16 { mag: 6746, sign: false }, + /// FP16x16 { mag: 12529, sign: false }, + /// FP16x16 { mag: 13493, sign: false }, + /// ] + /// .span(); + /// + /// let classlabels: Span = array![0, 1, 2].span(); + /// + /// let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + /// + /// let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + /// + /// let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + /// + /// let nodes_modes: Span = array![ + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// ] + /// .span(); + /// + /// let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + /// + /// let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + /// + /// let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + /// + /// let nodes_values: Span = array![ + /// FP16x16 { mag: 81892, sign: false }, + /// FP16x16 { mag: 19992, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 110300, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 44245, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// ] + /// .span(); + /// + /// let tree_ids: Span = array![0, 1].span(); + /// + /// let mut root_index: Felt252Dict = Default::default(); + /// root_index.insert(0, 0); + /// root_index.insert(1, 5); + /// + /// let mut node_index: Felt252Dict = Default::default(); + /// node_index + /// .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + /// node_index + /// .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + /// node_index + /// .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + /// node_index + /// .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + /// node_index + /// .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + /// node_index + /// .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + /// node_index + /// .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + /// node_index + /// .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + /// node_index + /// .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + /// node_index + /// .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + /// + /// let atts = TreeEnsembleAttributes { + /// nodes_falsenodeids, + /// nodes_featureids, + /// nodes_missing_value_tracks_true, + /// nodes_modes, + /// nodes_nodeids, + /// nodes_treeids, + /// nodes_truenodeids, + /// nodes_values + /// }; + /// + /// let mut ensemble: TreeEnsemble = TreeEnsemble { + /// atts, tree_ids, root_index, node_index + /// }; + /// + /// let base_values: Option> = Option::None; + /// + /// let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + /// ensemble, + /// class_ids, + /// class_nodeids, + /// class_treeids, + /// class_weights, + /// classlabels, + /// base_values, + /// post_transform + /// }; + /// + /// let mut X: Tensor = TensorTrait::new( + /// array![3, 3].span(), + /// array![ + /// FP16x16 { mag: 65536, sign: true }, + /// FP16x16 { mag: 52429, sign: true }, + /// FP16x16 { mag: 39322, sign: true }, + /// FP16x16 { mag: 26214, sign: true }, + /// FP16x16 { mag: 13107, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 13107, sign: false }, + /// FP16x16 { mag: 26214, sign: false }, + /// FP16x16 { mag: 39322, sign: false }, + /// ] + /// .span() + /// ); + /// + /// (classifier, X) + /// } + /// + /// fn test_tree_ensemble_classifier_multi_pt_softmax() -> (Span, MutMatrix::) { + /// let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + /// + /// let (labels, scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + /// (labels, scores) + /// } + /// + /// >>> + /// ([0, 0, 1], + /// [ + /// [0.545123, 0.217967, 0.23691], + /// [0.416047, 0.284965, 0.298988], + /// [0.322535, 0.366664, 0.310801], + /// ]) + /// ``` + /// + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); +} + impl TreeEnsembleClassifierImpl< T, MAG, From 18ab7831bfb606864efc01573ec184ddd7f2ef37 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 19:05:00 +0200 Subject: [PATCH 093/127] fix doc --- docs/SUMMARY.md | 2 +- .../machine-learning/tree-ensemble-classifier/README.md | 4 ++-- .../tree_ensemble_classifier.predict.md | 4 ++-- src/operators/ml.cairo | 7 +++++++ .../ml/tree_ensemble/tree_ensemble_classifier.cairo | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b1265951a..a5d4b59c3 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,7 +114,7 @@ * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) - * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) + * [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md index a3028a8be..d3baaad57 100644 --- a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md @@ -21,7 +21,7 @@ You can utilize [this notebook](https://colab.research.google.com/drive/1qem56rU *** -| function | description | -| ------------------------------------------------------------------------- | ------------------------------------------- | +| function | description | +| --- | --- | | [`tree_ensemble_classifier.predict`](tree_ensemble_classifier.predict.md) | Returns the top class for each of N inputs. | diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md index 8998fcfb7..6d839e873 100644 --- a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md @@ -25,8 +25,8 @@ Tree Ensemble classifier. Returns the top class for each of N inputs. ```rust use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ +use orion::operators::ml::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; +use orion::operators::ml::{ TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait }; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; diff --git a/src/operators/ml.cairo b/src/operators/ml.cairo index 721751fdd..826f51f51 100644 --- a/src/operators/ml.cairo +++ b/src/operators/ml.cairo @@ -20,3 +20,10 @@ use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_ use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp8x23::FP8x23XGBoostRegressor; use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp32x32::FP32x32XGBoostRegressor; use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp64x64::FP64x64XGBoostRegressor; + +use orion::operators::ml::tree_ensemble::core::{ + TreeEnsemble, TreeEnsembleAttributes, TreeEnsembleImpl, NODE_MODES +}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifier, TreeEnsembleClassifierImpl, TreeEnsembleClassifierTrait, POST_TRANSFORM +}; diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 0adb8a638..8925cb560 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -75,8 +75,8 @@ trait TreeEnsembleClassifierTrait { /// ```rust /// use orion::numbers::FP16x16; /// use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; - /// use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; - /// use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + /// use orion::operators::ml::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; + /// use orion::operators::ml::{ /// TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait /// }; /// use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; From b2de055f8e23fdc83973e2985d403d84884e64cf Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 19:08:59 +0200 Subject: [PATCH 094/127] Update SUMMARY.md --- docs/SUMMARY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b1265951a..580ccf1dc 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,7 +114,11 @@ * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) +<<<<<<< Updated upstream * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) +======= + * [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md) +>>>>>>> Stashed changes * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) From 5bf67a9b4d447070e0dce7a1ceac8fcaa2dc8e8b Mon Sep 17 00:00:00 2001 From: Raphael Doukhan Date: Sun, 12 Nov 2023 17:14:31 +0000 Subject: [PATCH 095/127] GITBOOK-39: change request with no subject merged in GitBook --- docs/framework/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/get-started.md b/docs/framework/get-started.md index adad08a5a..972ecc2e4 100644 --- a/docs/framework/get-started.md +++ b/docs/framework/get-started.md @@ -14,7 +14,7 @@ Orion supports **Cairo and Scarb v2.3.0** **Step 1: Install Cairo** -There are different ways to install Cairo. Use the one that suits you best: [Cairo installer](https://cairo-book.github.io/ch01-01-installation.html). +There are different ways to install Cairo. Use the one that suits you best: [Cairo installer.](https://book.cairo-lang.org/ch01-01-installation.html) **Step 2: Setup Language Server** From 4cb5ae71d6adff51b03850f939338558e227d847 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 20:21:26 +0100 Subject: [PATCH 096/127] Fix bug and add tests for 1D/2D tensors --- nodegen/node/array_feature_extractor.py | 187 ++++++++++++++---- .../tensor/ml/array_feature_extractor.cairo | 30 ++- tests/nodes.cairo | 14 +- ... array_feature_extractor_1D_fp16x16.cairo} | 2 +- .../input_0.cairo | 17 ++ .../input_1.cairo | 0 .../output_0.cairo | 15 ++ ...> array_feature_extractor_1D_fp8x23.cairo} | 2 +- .../input_0.cairo | 17 ++ .../input_1.cairo | 0 .../output_0.cairo | 15 ++ ...o => array_feature_extractor_1D_i32.cairo} | 2 +- .../input_0.cairo | 16 ++ .../input_1.cairo | 0 .../output_0.cairo | 14 ++ .../array_feature_extractor_2D_fp16x16.cairo | 22 +++ .../input_0.cairo | 26 +++ .../input_1.cairo | 13 ++ .../output_0.cairo | 20 ++ .../array_feature_extractor_2D_fp8x23.cairo | 22 +++ .../input_0.cairo} | 17 +- .../input_1.cairo | 13 ++ .../output_0.cairo | 20 ++ .../array_feature_extractor_2D_i32.cairo | 22 +++ .../input_0.cairo | 25 +++ .../input_1.cairo | 13 ++ .../output_0.cairo | 19 ++ .../array_feature_extractor_3D_fp16x16.cairo | 22 +++ .../input_0.cairo | 30 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 14 +- .../array_feature_extractor_3D_fp8x23.cairo | 22 +++ .../input_0.cairo | 24 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 27 +++ .../array_feature_extractor_3D_i32.cairo | 22 +++ .../input_0.cairo | 28 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 12 +- 39 files changed, 691 insertions(+), 112 deletions(-) rename tests/nodes/{array_feature_extractor_fp16x16.cairo => array_feature_extractor_1D_fp16x16.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_1D_fp16x16}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo rename tests/nodes/{array_feature_extractor_fp8x23.cairo => array_feature_extractor_1D_fp8x23.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo rename tests/nodes/{array_feature_extractor_fp8x23 => array_feature_extractor_1D_fp8x23}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo rename tests/nodes/{array_feature_extractor_i32.cairo => array_feature_extractor_1D_i32.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_i32/input_0.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_1D_i32}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_i32/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23.cairo rename tests/nodes/{array_feature_extractor_fp8x23/output_0.cairo => array_feature_extractor_2D_fp8x23/input_0.cairo} (72%) create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_fp16x16.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_3D_fp16x16}/input_0.cairo (81%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_3D_fp16x16}/output_0.cairo (74%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23.cairo rename tests/nodes/{array_feature_extractor_fp8x23 => array_feature_extractor_3D_fp8x23}/input_0.cairo (77%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_i32.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_3D_i32}/input_0.cairo (81%) create mode 100644 tests/nodes/array_feature_extractor_3D_i32/input_1.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_3D_i32}/output_0.cairo (90%) diff --git a/nodegen/node/array_feature_extractor.py b/nodegen/node/array_feature_extractor.py index 7055dc05c..bf8071e60 100644 --- a/nodegen/node/array_feature_extractor.py +++ b/nodegen/node/array_feature_extractor.py @@ -6,49 +6,156 @@ class Array_feature_extractor(RunAll): @staticmethod - def array_feature_extractor_i32(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) + def array_feature_extractor_3D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.I32, z.shape, z.flatten()) + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) - name = "array_feature_extractor_i32" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + name = "array_feature_extractor_3D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_3D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_3D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() @staticmethod - def array_feature_extractor_fp8x23(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) - - x = Tensor(Dtype.FP8x23, x.shape, to_fp( - x.flatten(), FixedImpl.FP8x23)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.FP8x23, z.shape, to_fp( - z.flatten(), FixedImpl.FP8x23)) - - name = "array_feature_extractor_fp8x23" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) - - + def array_feature_extractor_2D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_2D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_2D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_2D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() + + @staticmethod - def array_feature_extractor_fp16x16(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) - - x = Tensor(Dtype.FP16x16, x.shape, to_fp( - x.flatten(), FixedImpl.FP16x16)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.FP16x16, z.shape, to_fp( - z.flatten(), FixedImpl.FP16x16)) - - name = "array_feature_extractor_fp16x16" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) \ No newline at end of file + def array_feature_extractor_1D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_1D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_1D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_1D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() \ No newline at end of file diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index c3918e859..31b8a24aa 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -22,7 +22,29 @@ fn array_feature_extractor< let input_shape: Span = self.shape; let input_data: Span = self.data; - let mut last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + + if input_shape.len() == 1 { + + let mut output_data = ArrayTrait::::new(); + + let mut indices_counter: usize = 0; + + loop { + if indices_counter > indices.data.len() - 1 { + break; + } + + let mut current_indices_value = *indices.data.at(indices_counter); + + let mut current_data_value = *input_data.at(current_indices_value); + + output_data.append(current_data_value); + + indices_counter += 1; + }; + + return TensorTrait::new(indices.shape, output_data.span()); + } let mut input_shape_counter: usize = 0; @@ -58,7 +80,11 @@ fn array_feature_extractor< break; } - let mut base_index = element_counter * (*strides.at(strides.len() - 2)); + let mut base_index = if strides.len() > 1 { + element_counter * (*strides.at(strides.len() - 2)) + } else { + 0 + }; let mut indices_counter: usize = 0; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 12ee077cd..342d8c6e8 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,7 +527,13 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_fp16x16; -mod array_feature_extractor_fp8x23; -mod array_feature_extractor_i32; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; diff --git a/tests/nodes/array_feature_extractor_fp16x16.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_fp16x16.cairo rename to tests/nodes/array_feature_extractor_1D_fp16x16.cairo index 9dfcd177e..a24571c9d 100644 --- a/tests/nodes/array_feature_extractor_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_fp16x16() { +fn test_array_feature_extractor_1D_fp16x16() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo new file mode 100644 index 000000000..e9eefbabf --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo @@ -0,0 +1,17 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_fp16x16/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo new file mode 100644 index 000000000..2472bf84b --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo @@ -0,0 +1,15 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_fp8x23.cairo rename to tests/nodes/array_feature_extractor_1D_fp8x23.cairo index a249ced57..72ccfa9fc 100644 --- a/tests/nodes/array_feature_extractor_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_fp8x23() { +fn test_array_feature_extractor_1D_fp8x23() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo new file mode 100644 index 000000000..e3f37db08 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo @@ -0,0 +1,17 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_fp8x23/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo new file mode 100644 index 000000000..26340a8b6 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo @@ -0,0 +1,15 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32.cairo b/tests/nodes/array_feature_extractor_1D_i32.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_i32.cairo rename to tests/nodes/array_feature_extractor_1D_i32.cairo index 987cd02f6..0d8dde9d8 100644 --- a/tests/nodes/array_feature_extractor_i32.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_i32() { +fn test_array_feature_extractor_1D_i32() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo new file mode 100644 index 000000000..761aa81c4 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo @@ -0,0 +1,16 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_1.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_i32/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_i32/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo new file mode 100644 index 000000000..b5a56f1ff --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo @@ -0,0 +1,14 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo new file mode 100644 index 000000000..7023d621a --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_2D_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo new file mode 100644 index 000000000..4742c7e7d --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo @@ -0,0 +1,26 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + 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: 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: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo new file mode 100644 index 000000000..c2ebb541a --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo new file mode 100644 index 000000000..06608774f --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_2D_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo similarity index 72% rename from tests/nodes/array_feature_extractor_fp8x23/output_0.cairo rename to tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo index 268e7335d..8b577178a 100644 --- a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo @@ -4,23 +4,22 @@ use orion::operators::tensor::FP8x23Tensor; use orion::numbers::FixedTrait; use orion::numbers::FP8x23; -fn output_0() -> Tensor { +fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); shape.append(3); - shape.append(2); + shape.append(4); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo new file mode 100644 index 000000000..91bd19d12 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo @@ -0,0 +1,20 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32.cairo b/tests/nodes/array_feature_extractor_2D_i32.cairo new file mode 100644 index 000000000..29368f5f3 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_2D_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo new file mode 100644 index 000000000..c7b027450 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo @@ -0,0 +1,25 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo new file mode 100644 index 000000000..c9d6cedf5 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo @@ -0,0 +1,19 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo new file mode 100644 index 000000000..eab071c49 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_3D_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo similarity index 81% rename from tests/nodes/array_feature_extractor_fp16x16/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo index a32b3a3a2..559a6ec9b 100644 --- a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo @@ -11,29 +11,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); - 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: false }); 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + 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: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo similarity index 74% rename from tests/nodes/array_feature_extractor_fp16x16/output_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo index b72170ad1..dc974161d 100644 --- a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo @@ -11,17 +11,17 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); + 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: 131072, sign: false }); 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: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo new file mode 100644 index 000000000..8315e0caf --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_3D_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo similarity index 77% rename from tests/nodes/array_feature_extractor_fp8x23/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo index e92d71a5a..b74c32e6e 100644 --- a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo @@ -11,29 +11,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo new file mode 100644 index 000000000..093210ec7 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo @@ -0,0 +1,27 @@ +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(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_i32.cairo b/tests/nodes/array_feature_extractor_3D_i32.cairo new file mode 100644 index 000000000..e8688a4e9 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +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_array_feature_extractor_3D_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo similarity index 81% rename from tests/nodes/array_feature_extractor_i32/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_i32/input_0.cairo index a922d8f8e..e53f9a696 100644 --- a/tests/nodes/array_feature_extractor_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo @@ -10,29 +10,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/output_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo similarity index 90% rename from tests/nodes/array_feature_extractor_i32/output_0.cairo rename to tests/nodes/array_feature_extractor_3D_i32/output_0.cairo index 4e64044fa..56e50441e 100644 --- a/tests/nodes/array_feature_extractor_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo @@ -11,16 +11,16 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From b5ec8c0169ec5290be2b3c5b8636059963faa02f Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 21:01:03 +0100 Subject: [PATCH 097/127] Add assertion for indices range --- src/operators/tensor/ml/array_feature_extractor.cairo | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 31b8a24aa..0ad7942a8 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -36,6 +36,8 @@ fn array_feature_extractor< let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < *input_shape.at(0), 'Indices out of range'); + let mut current_data_value = *input_data.at(current_indices_value); output_data.append(current_data_value); @@ -46,6 +48,8 @@ fn array_feature_extractor< return TensorTrait::new(indices.shape, output_data.span()); } + let last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + let mut input_shape_counter: usize = 0; let mut total_elements: usize = 1; @@ -95,6 +99,8 @@ fn array_feature_extractor< let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < last_tensor_axis, 'Indices out of range'); + let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); let mut current_data_value = *input_data.at(flat_index); From 33ae8dead1b06796869b547444ce2d874f2cbe8f Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 15:59:40 +0100 Subject: [PATCH 098/127] Add nodegen script --- nodegen/node/sequence_empty.py | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 nodegen/node/sequence_empty.py diff --git a/nodegen/node/sequence_empty.py b/nodegen/node/sequence_empty.py new file mode 100644 index 000000000..91dc78dbc --- /dev/null +++ b/nodegen/node/sequence_empty.py @@ -0,0 +1,81 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, Dtype, Tensor + + +class Sequence_empty(RunAll): + + @staticmethod + def sequence_empty_u32(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.uint32) + t = Tensor(Dtype.U32, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_u32", + ) + + default() + + @staticmethod + def sequence_empty_i32(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.int32) + t = Tensor(Dtype.I32, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_i32", + ) + + default() + + @staticmethod + def sequence_empty_i8(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.int8) + t = Tensor(Dtype.I8, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_i8", + ) + + default() + + @staticmethod + def sequence_empty_fp8x23(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.float64) + t = Tensor(Dtype.FP8x23, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_fp8x23", + ) + + default() + + @staticmethod + def sequence_empty_fp16x16(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.float64) + t = Tensor(Dtype.FP16x16, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_fp16x16", + ) + + default() From 49e04edc46bc4cd4ca536e30e16da82cdf36c4a5 Mon Sep 17 00:00:00 2001 From: Dincer Guner Date: Mon, 13 Nov 2023 20:32:14 +0300 Subject: [PATCH 099/127] implement reduce_mean --- Scarb.toml | 1 + docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.reduce_mean.md | 42 +++ nodegen/node/reduce_mean.py | 288 ++++++++++++++++++ src/operators/tensor/core.cairo | 45 +++ src/operators/tensor/helpers.cairo | 24 ++ .../tensor/implementations/tensor_bool.cairo | 9 + .../implementations/tensor_fp16x16.cairo | 9 + .../implementations/tensor_fp16x16wide.cairo | 9 + .../implementations/tensor_fp32x32.cairo | 9 + .../implementations/tensor_fp64x64.cairo | 9 + .../implementations/tensor_fp8x23.cairo | 9 + .../implementations/tensor_fp8x23wide.cairo | 9 + .../tensor/implementations/tensor_i32.cairo | 9 + .../tensor/implementations/tensor_i8.cairo | 9 + .../tensor/implementations/tensor_u32.cairo | 9 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/reduce_mean.cairo | 192 ++++++++++++ tests/nodes.cairo | 20 ++ tests/nodes/reduce_mean_fp16x16_1D.cairo | 20 ++ .../reduce_mean_fp16x16_1D/input_0.cairo | 15 + .../reduce_mean_fp16x16_1D/output_0.cairo | 13 + .../nodes/reduce_mean_fp16x16_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../reduce_mean_fp16x16_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_mean_fp16x16_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_fp8x23_1D.cairo | 20 ++ .../nodes/reduce_mean_fp8x23_1D/input_0.cairo | 15 + .../reduce_mean_fp8x23_1D/output_0.cairo | 13 + .../nodes/reduce_mean_fp8x23_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_mean_fp8x23_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_mean_fp8x23_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_i32_1D.cairo | 20 ++ tests/nodes/reduce_mean_i32_1D/input_0.cairo | 15 + tests/nodes/reduce_mean_i32_1D/output_0.cairo | 13 + tests/nodes/reduce_mean_i32_2D_axis_1.cairo | 20 ++ .../reduce_mean_i32_2D_axis_1/input_0.cairo | 17 ++ .../reduce_mean_i32_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_mean_i32_2D_default.cairo | 20 ++ .../reduce_mean_i32_2D_default/input_0.cairo | 17 ++ .../reduce_mean_i32_2D_default/output_0.cairo | 14 + tests/nodes/reduce_mean_i32_2D_keepdims.cairo | 20 ++ .../reduce_mean_i32_2D_keepdims/input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_i8_1D.cairo | 20 ++ tests/nodes/reduce_mean_i8_1D/input_0.cairo | 15 + tests/nodes/reduce_mean_i8_1D/output_0.cairo | 13 + tests/nodes/reduce_mean_i8_2D_axis_1.cairo | 20 ++ .../reduce_mean_i8_2D_axis_1/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_mean_i8_2D_default.cairo | 20 ++ .../reduce_mean_i8_2D_default/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_default/output_0.cairo | 14 + tests/nodes/reduce_mean_i8_2D_keepdims.cairo | 20 ++ .../reduce_mean_i8_2D_keepdims/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_mean_u32_1D.cairo | 20 ++ tests/nodes/reduce_mean_u32_1D/input_0.cairo | 14 + tests/nodes/reduce_mean_u32_1D/output_0.cairo | 12 + tests/nodes/reduce_mean_u32_2D_axis_1.cairo | 20 ++ .../reduce_mean_u32_2D_axis_1/input_0.cairo | 16 + .../reduce_mean_u32_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_mean_u32_2D_default.cairo | 20 ++ .../reduce_mean_u32_2D_default/input_0.cairo | 16 + .../reduce_mean_u32_2D_default/output_0.cairo | 13 + tests/nodes/reduce_mean_u32_2D_keepdims.cairo | 20 ++ .../reduce_mean_u32_2D_keepdims/input_0.cairo | 16 + .../output_0.cairo | 11 + 80 files changed, 1697 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.reduce_mean.md create mode 100644 nodegen/node/reduce_mean.py create mode 100644 src/operators/tensor/math/reduce_mean.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo diff --git a/Scarb.toml b/Scarb.toml index 84f1195c9..f28aa8bd1 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,6 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion" [dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } +alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" } [scripts] diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..8afe831e4 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.reduce_mean](framework/operators/tensor/tensor.reduce\_mean.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..324cc244d 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.reduce_mean.md b/docs/framework/operators/tensor/tensor.reduce_mean.md new file mode 100644 index 000000000..633f8ab00 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_mean.md @@ -0,0 +1,42 @@ +## tensor.reduce_mean + +```rust + fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; +``` + +Computes the mean of the input tensor's elements along the provided axes. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. +* `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. +* `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axes reduced by meaning its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_mean_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_mean` function as follows. + return tensor.reduce_mean(axes: array![1].span(), + keepdims: Option::None(()), + noop_with_empty_axes: Option::None(())); +} +>>> [[1,2],[5,6]] +``` diff --git a/nodegen/node/reduce_mean.py b/nodegen/node/reduce_mean.py new file mode 100644 index 000000000..6f1119323 --- /dev/null +++ b/nodegen/node/reduce_mean.py @@ -0,0 +1,288 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Reduce_mean(RunAll): + @staticmethod + def reduce_mean_u32(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.uint32) + y = np.mean(x, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_i32(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int32) + y = np.mean(x, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_i8(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int8) + y = np.mean(x, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_fp8x23(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.mean(x, keepdims=True) + + 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 = "reduce_mean_fp8x23_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=True) + + 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 = "reduce_mean_fp8x23_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=False) + + 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 = "reduce_mean_fp8x23_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True) + + 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 = "reduce_mean_fp8x23_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_fp16x16(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.mean(x, keepdims=True) + + 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 = "reduce_mean_fp16x16_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=True) + + 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 = "reduce_mean_fp16x16_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=False) + + 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 = "reduce_mean_fp16x16_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True) + + 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 = "reduce_mean_fp16x16_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_mean_1D() + reduce_mean_2D() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..f48407807 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,50 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.reduce_mean + /// + /// ```rust + /// fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the mean of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by meaning its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_mean_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_mean(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[1,2],[5,6]] + /// ``` + /// + fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 0aad721d7..6b65eb736 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -317,3 +317,27 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. +fn get_all_axes(shape: Span) -> Span{ + let mut ret: Array = ArrayTrait::new(); + let mut i: usize = 0; + let stop_i = shape.len() - 1; + loop { + ret.append(i); + if i == stop_i { + break (); + } + i += 1; + }; + ret.span() +} \ No newline at end of file diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..26351c601 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,15 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..90cfbcf64 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,15 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 68f2482e7..d0ec261b7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,15 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 f764b1920..f77fb80ec 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,15 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 6cded29b3..1ef4b2693 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,15 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 fdcdac1eb..28ba13668 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,15 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 510731702..4d61e066e 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,15 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 8017ab300..5e799c9bd 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,15 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 4f2731b80..88f814937 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,15 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 2f3c3a2ef..e293bc52f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,15 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..ad6ed146e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod reduce_mean; diff --git a/src/operators/tensor/math/reduce_mean.cairo b/src/operators/tensor/math/reduce_mean.cairo new file mode 100644 index 000000000..7d64d85b5 --- /dev/null +++ b/src/operators/tensor/math/reduce_mean.cairo @@ -0,0 +1,192 @@ +use core::option::OptionTrait; +use core::traits::Div; +use core::traits::TryInto; +use core::traits::Into; + +use array::ArrayTrait; +use array::SpanTrait; + +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; + +use alexandria_sorting::bubble_sort; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + + +/// Cf: TensorTrait::reduce_mean docstring +fn reduce_mean< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TDiv: Div, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option +) -> Tensor { + let noop_with_empty_axes = match noop_with_empty_axes { + Option::Some(noop_with_empty_axes) => noop_with_empty_axes, + Option::None(_) => { + false + }, + }; + let axes = match axes { + Option::Some(axes) => { + if(axes.len() == 0) { + get_all_axes(*self.shape) + } + else { + assert(axes.len() == axes.unique().len(), 'duplicated axis.'); + let mut axes_arr = ArrayTrait::new(); + let mut copy_axes = axes; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + axes_arr.append(*axis); + }, + Option::None(_) => { + break; + } + }; + }; + let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); + sorted_axes + } + }, + Option::None(_) => { + if (noop_with_empty_axes == true) { + return *self; + } + get_all_axes(*self.shape) + }, + }; + let keepdims = match keepdims { + Option::Some(keepdims) => keepdims, + Option::None(_) => { + true + }, + }; + + let mut axis_c = 0; + let mut copy_axes = axes; + let mut shape = *self.shape; + let mut data = *self.data; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + if (shape.len() == 1) { + let current_mean = accumulate_mean::(data, shape, shape, 0); + shape = array![].span(); + data = array![current_mean].span(); + break(); + } + let mut temp_data = ArrayTrait::new(); + let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let data_len = len_from_shape(temp_shape); + let mut index: usize = 0; + loop { + let indices = unravel_index(index, temp_shape); + let current_mean = accumulate_mean::(data, shape, indices, *axis-axis_c); + + temp_data.append(current_mean); + + index += 1; + if index == data_len { + break (); + }; + }; + shape = temp_shape; + data = temp_data.span(); + axis_c += 1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut axes_copy = axes; + if keepdims == true { + shape = *self.shape; + loop { + match axes_copy.pop_front() { + Option::Some(axis) => { + shape = reduce_output_shape(shape, *axis, true); + }, + Option::None(_) => { + break; + } + }; + }; + return TensorTrait::::new(shape, data); + } else { + return TensorTrait::::new(shape, data); + } +} + +/// Helper function that accumulates the mean of elements along a specific axis. +/// +/// # Arguments +/// * `input_data` - The input's data. +/// * `input_shape` - The input's shape. +/// * `output_indices` - A span of output indices. +/// * `axis` - The axis along which to accumulate the mean. +/// +/// # Panics +/// * Panics if gas limit is exceeded during execution. +/// +/// # Returns +/// * A value representing the accumulated mean along the specified axis. +fn accumulate_mean< + T, + MAG, + impl TNumber: NumberTrait, + impl TDiv: Div, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut input_data: Span, input_shape: Span, output_indices: Span, axis: usize +) -> T { + let axis_len = *(input_shape)[axis]; + let mut acc: T = NumberTrait::zero(); + + let mut axis_index: T = NumberTrait::zero(); + let mut axis_indexu32 = 0; + + if (input_shape).len() > 1 { + loop { + if axis_indexu32 == axis_len { + break (); + } + + let input_indices = combine_indices(output_indices, axis_indexu32, axis); + let input_index = ravel_index(input_shape, input_indices); + let ele = *(input_data)[input_index]; + acc += ele; + axis_index += NumberTrait::one(); + axis_indexu32 +=1; + }; + } else { + loop { + match input_data.pop_front() { + Option::Some(item) => { + acc += *item; + axis_index += NumberTrait::one(); + axis_indexu32 +=1; + }, + Option::None(_) => { break; } + }; + }; + } + // let axis_index: T = NumberTrait::::new(axis_index.try_into().unwrap(), false); + return acc/axis_index; +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..7df444889 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,23 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_mean_fp16x16_1D; +mod reduce_mean_fp16x16_2D_default; +mod reduce_mean_fp16x16_2D_keepdims; +mod reduce_mean_fp16x16_2D_axis_1; +mod reduce_mean_fp8x23_1D; +mod reduce_mean_fp8x23_2D_default; +mod reduce_mean_fp8x23_2D_keepdims; +mod reduce_mean_fp8x23_2D_axis_1; +mod reduce_mean_i32_1D; +mod reduce_mean_i32_2D_default; +mod reduce_mean_i32_2D_keepdims; +mod reduce_mean_i32_2D_axis_1; +mod reduce_mean_i8_1D; +mod reduce_mean_i8_2D_default; +mod reduce_mean_i8_2D_keepdims; +mod reduce_mean_i8_2D_axis_1; +mod reduce_mean_u32_1D; +mod reduce_mean_u32_2D_default; +mod reduce_mean_u32_2D_keepdims; +mod reduce_mean_u32_2D_axis_1; diff --git a/tests/nodes/reduce_mean_fp16x16_1D.cairo b/tests/nodes/reduce_mean_fp16x16_1D.cairo new file mode 100644 index 000000000..fff2a717f --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo new file mode 100644 index 000000000..4ce1ac478 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo new file mode 100644 index 000000000..c1a241ef9 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo new file mode 100644 index 000000000..d7ac8e7cc --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..c5e778de8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 32768, sign: false }); + data.append(FP16x16 { mag: 163840, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default.cairo new file mode 100644 index 000000000..4daa61cb0 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo new file mode 100644 index 000000000..cb0b45c75 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 98304, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo new file mode 100644 index 000000000..aadf6ca8d --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..f49fbed25 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 98304, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D.cairo b/tests/nodes/reduce_mean_fp8x23_1D.cairo new file mode 100644 index 000000000..6f0b2fce3 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo new file mode 100644 index 000000000..e0b0864ea --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo new file mode 100644 index 000000000..ce0d44c93 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo new file mode 100644 index 000000000..4eb932a74 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..11d2f60eb --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 4194304, sign: false }); + data.append(FP8x23 { mag: 20971520, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default.cairo new file mode 100644 index 000000000..aba87b8ed --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo new file mode 100644 index 000000000..b0971092f --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 12582912, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo new file mode 100644 index 000000000..9aa5ebf31 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..7d6a238a0 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 12582912, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_1D.cairo b/tests/nodes/reduce_mean_i32_1D.cairo new file mode 100644 index 000000000..1a3ee408f --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_1D/input_0.cairo b/tests/nodes/reduce_mean_i32_1D/input_0.cairo new file mode 100644 index 000000000..0f01c1e62 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_1D/output_0.cairo b/tests/nodes/reduce_mean_i32_1D/output_0.cairo new file mode 100644 index 000000000..8f879b6fd --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D/output_0.cairo @@ -0,0 +1,13 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1.cairo new file mode 100644 index 000000000..c0f26b36e --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..33f9f46e3 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_default.cairo b/tests/nodes/reduce_mean_i32_2D_default.cairo new file mode 100644 index 000000000..60c974c13 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_default/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_default/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo new file mode 100644 index 000000000..a2da83559 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims.cairo new file mode 100644 index 000000000..fa68cbd94 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..15657a928 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_1D.cairo b/tests/nodes/reduce_mean_i8_1D.cairo new file mode 100644 index 000000000..283a41dac --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_1D/input_0.cairo b/tests/nodes/reduce_mean_i8_1D/input_0.cairo new file mode 100644 index 000000000..1d76655fb --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_1D/output_0.cairo b/tests/nodes/reduce_mean_i8_1D/output_0.cairo new file mode 100644 index 000000000..7e87c24f4 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1.cairo new file mode 100644 index 000000000..0cc13fcd0 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..9689a7aa4 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_default.cairo b/tests/nodes/reduce_mean_i8_2D_default.cairo new file mode 100644 index 000000000..88b0c9080 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo new file mode 100644 index 000000000..47c647ea8 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims.cairo new file mode 100644 index 000000000..f46833611 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..3b2ebf796 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_1D.cairo b/tests/nodes/reduce_mean_u32_1D.cairo new file mode 100644 index 000000000..02df97953 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_1D/input_0.cairo b/tests/nodes/reduce_mean_u32_1D/input_0.cairo new file mode 100644 index 000000000..60317db10 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_1D/output_0.cairo b/tests/nodes/reduce_mean_u32_1D/output_0.cairo new file mode 100644 index 000000000..35f3cdfce --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D/output_0.cairo @@ -0,0 +1,12 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1.cairo new file mode 100644 index 000000000..6a5790d28 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..8e871bbfd --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_default.cairo b/tests/nodes/reduce_mean_u32_2D_default.cairo new file mode 100644 index 000000000..33ea58412 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_default/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_default/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo new file mode 100644 index 000000000..54c4dbbc0 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo @@ -0,0 +1,13 @@ +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(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims.cairo new file mode 100644 index 000000000..82a019f4c --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..abdf2e9d5 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} From 617c8815ea83f7521994dbe8c51970f36abec8d4 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 19:46:05 +0100 Subject: [PATCH 100/127] Add tests and implementation --- src/operators/tensor/core.cairo | 4 ++++ .../tensor/implementations/tensor_bool.cairo | 5 ++++- .../implementations/tensor_fp16x16.cairo | 4 ++++ .../implementations/tensor_fp16x16wide.cairo | 4 ++++ .../implementations/tensor_fp32x32.cairo | 4 ++++ .../implementations/tensor_fp64x64.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23.cairo | 4 ++++ .../implementations/tensor_fp8x23wide.cairo | 4 ++++ .../tensor/implementations/tensor_i32.cairo | 4 ++++ .../tensor/implementations/tensor_i8.cairo | 4 ++++ .../tensor/implementations/tensor_u32.cairo | 4 ++++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/sequence_empty.cairo | 18 ++++++++++++++++++ tests/nodes.cairo | 5 +++++ tests/nodes/sequence_empty_fp16x16.cairo | 18 ++++++++++++++++++ .../sequence_empty_fp16x16/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_fp8x23.cairo | 18 ++++++++++++++++++ .../nodes/sequence_empty_fp8x23/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_i32.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_i32/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_i8.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_i8/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_u32.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_u32/output_0.cairo | 16 ++++++++++++++++ 24 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/math/sequence_empty.cairo create mode 100644 tests/nodes/sequence_empty_fp16x16.cairo create mode 100644 tests/nodes/sequence_empty_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_empty_fp8x23.cairo create mode 100644 tests/nodes/sequence_empty_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_empty_i32.cairo create mode 100644 tests/nodes/sequence_empty_i32/output_0.cairo create mode 100644 tests/nodes/sequence_empty_i8.cairo create mode 100644 tests/nodes/sequence_empty_i8/output_0.cairo create mode 100644 tests/nodes/sequence_empty_u32.cairo create mode 100644 tests/nodes/sequence_empty_u32/output_0.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..c364213e1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,9 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// # tensor.sequence_empty + /// TODO + fn sequence_empty() -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..88e59599e 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -308,10 +308,13 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } - fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..40e86a42b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 68f2482e7..2e5938c71 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 f764b1920..bc4a15ebe 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 6cded29b3..90a6d6383 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 fdcdac1eb..da8c8b15a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 510731702..45f6939d5 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 8017ab300..6a8eb9803 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 4f2731b80..d87c51a92 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 2f3c3a2ef..d830a3499 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..8926f3db3 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_empty; diff --git a/src/operators/tensor/math/sequence_empty.cairo b/src/operators/tensor/math/sequence_empty.cairo new file mode 100644 index 000000000..4e32a0429 --- /dev/null +++ b/src/operators/tensor/math/sequence_empty.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; + + +fn sequence_empty, impl TDrop: Drop>() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + let tensor = TensorTrait::new(shape.span(), data.span()); + + sequence.append(tensor); + + sequence +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..3aa54bd4c 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,8 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_empty_fp16x16; +mod sequence_empty_fp8x23; +mod sequence_empty_i32; +mod sequence_empty_i8; +mod sequence_empty_u32; diff --git a/tests/nodes/sequence_empty_fp16x16.cairo b/tests/nodes/sequence_empty_fp16x16.cairo new file mode 100644 index 000000000..745c52c01 --- /dev/null +++ b/tests/nodes/sequence_empty_fp16x16.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_fp16x16() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_fp16x16/output_0.cairo b/tests/nodes/sequence_empty_fp16x16/output_0.cairo new file mode 100644 index 000000000..afa31e131 --- /dev/null +++ b/tests/nodes/sequence_empty_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_fp8x23.cairo b/tests/nodes/sequence_empty_fp8x23.cairo new file mode 100644 index 000000000..8d8e3f047 --- /dev/null +++ b/tests/nodes/sequence_empty_fp8x23.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_fp8x23() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_fp8x23/output_0.cairo b/tests/nodes/sequence_empty_fp8x23/output_0.cairo new file mode 100644 index 000000000..68ec1797b --- /dev/null +++ b/tests/nodes/sequence_empty_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_i32.cairo b/tests/nodes/sequence_empty_i32.cairo new file mode 100644 index 000000000..68b8f1f5e --- /dev/null +++ b/tests/nodes/sequence_empty_i32.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_i32() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_i32/output_0.cairo b/tests/nodes/sequence_empty_i32/output_0.cairo new file mode 100644 index 000000000..9a3cb338b --- /dev/null +++ b/tests/nodes/sequence_empty_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() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_i8.cairo b/tests/nodes/sequence_empty_i8.cairo new file mode 100644 index 000000000..c08a9bf45 --- /dev/null +++ b/tests/nodes/sequence_empty_i8.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_i8() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_i8/output_0.cairo b/tests/nodes/sequence_empty_i8/output_0.cairo new file mode 100644 index 000000000..123ac1980 --- /dev/null +++ b/tests/nodes/sequence_empty_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() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_u32.cairo b/tests/nodes/sequence_empty_u32.cairo new file mode 100644 index 000000000..0b20e2c65 --- /dev/null +++ b/tests/nodes/sequence_empty_u32.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_u32() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_u32/output_0.cairo b/tests/nodes/sequence_empty_u32/output_0.cairo new file mode 100644 index 000000000..e2bdd6e71 --- /dev/null +++ b/tests/nodes/sequence_empty_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() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From 9d394daa915a6a35b069817c0bd7029c01b94c9e Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 14:01:17 +0100 Subject: [PATCH 101/127] Implement shrink operator --- src/numbers.cairo | 164 +++++++++++++++++- src/numbers/fixed_point/core.cairo | 1 + .../implementations/fp16x16/core.cairo | 4 + .../implementations/fp16x16wide/core.cairo | 4 + .../implementations/fp32x32/core.cairo | 6 +- .../implementations/fp64x64/core.cairo | 6 + .../implementations/fp8x23/core.cairo | 4 + .../implementations/fp8x23wide/core.cairo | 4 + src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/shrink.cairo | 55 ++++++ 21 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 src/operators/tensor/math/shrink.cairo diff --git a/src/numbers.cairo b/src/numbers.cairo index 6c6a06c86..1471c09f0 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -35,6 +35,7 @@ trait NumberTrait { fn tanh(self: T) -> T; fn zero() -> T; fn is_zero(self: T) -> bool; + fn half() -> T; fn one() -> T; fn is_one(self: T) -> bool; fn neg_one() -> T; @@ -50,9 +51,11 @@ trait NumberTrait { fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; fn bitwise_and(lhs: T, rhs: T) -> T; + fn add(lhs: T, rhs: T) -> T; + fn sub(lhs: T, rhs: T) -> T; } -use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; +use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub}; use orion::numbers::fixed_point::implementations::fp8x23::math::core as core_fp8x23; use orion::numbers::fixed_point::implementations::fp8x23::math::comp as comp_fp8x23; @@ -164,6 +167,10 @@ impl FP8x23Number of NumberTrait { core_fp8x23::eq(@self, @FP8x23Impl::ZERO()) } + fn half() -> FP8x23 { + FP8x23Impl::HALF() + } + fn one() -> FP8x23 { FP8x23Impl::ONE() } @@ -231,9 +238,17 @@ impl FP8x23Number of NumberTrait { fn bitwise_and(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { comp_fp8x23::bitwise_and(lhs, rhs) } + + fn add(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + FP8x23Add::add(lhs, rhs) + } + + fn sub(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + FP8x23Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; +use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub}; use orion::numbers::fixed_point::implementations::fp8x23wide::math::core as core_fp8x23wide; use orion::numbers::fixed_point::implementations::fp8x23wide::math::comp as comp_fp8x23wide; @@ -345,6 +360,10 @@ impl FP8x23WNumber of NumberTrait { core_fp8x23wide::eq(@self, @FP8x23WImpl::ZERO()) } + fn half() -> FP8x23W { + FP8x23WImpl::HALF() + } + fn one() -> FP8x23W { FP8x23WImpl::ONE() } @@ -412,9 +431,17 @@ impl FP8x23WNumber of NumberTrait { fn bitwise_and(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { comp_fp8x23wide::bitwise_and(lhs, rhs) } + + fn add(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + FP8x23WAdd::add(lhs, rhs) + } + + fn sub(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + FP8x23WSub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; +use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub}; use orion::numbers::fixed_point::implementations::fp16x16::math::core as core_fp16x16; use orion::numbers::fixed_point::implementations::fp16x16::math::comp as comp_fp16x16; @@ -526,6 +553,10 @@ impl FP16x16Number of NumberTrait { core_fp16x16::eq(@self, @FP16x16Impl::ZERO()) } + fn half() -> FP16x16 { + FP16x16Impl::HALF() + } + fn one() -> FP16x16 { FP16x16Impl::ONE() } @@ -593,9 +624,17 @@ impl FP16x16Number of NumberTrait { fn bitwise_and(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { comp_fp16x16::bitwise_and(lhs, rhs) } + + fn add(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + FP16x16Add::add(lhs, rhs) + } + + fn sub(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + FP16x16Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; +use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub}; use orion::numbers::fixed_point::implementations::fp16x16wide::math::core as core_fp16x16wide; use orion::numbers::fixed_point::implementations::fp16x16wide::math::comp as comp_fp16x16wide; @@ -707,6 +746,10 @@ impl FP16x16WNumber of NumberTrait { core_fp16x16wide::eq(@self, @FP16x16WImpl::ZERO()) } + fn half() -> FP16x16W { + FP16x16WImpl::HALF() + } + fn one() -> FP16x16W { FP16x16WImpl::ONE() } @@ -774,9 +817,17 @@ impl FP16x16WNumber of NumberTrait { fn bitwise_and(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { comp_fp16x16wide::bitwise_and(lhs, rhs) } + + fn add(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + FP16x16WAdd::add(lhs, rhs) + } + + fn sub(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + FP16x16WSub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; +use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub}; use orion::numbers::fixed_point::implementations::fp64x64::core as core_fp64x64; use orion::numbers::fixed_point::implementations::fp64x64::comp as comp_fp64x64; use cubit::f128 as fp64x64; @@ -889,6 +940,10 @@ impl FP64x64Number of NumberTrait { fp64x64::core::eq(@self, @FP64x64Impl::ZERO()) } + fn half() -> FP64x64 { + FP64x64Impl::HALF() + } + fn one() -> FP64x64 { FP64x64Impl::ONE() } @@ -956,9 +1011,17 @@ impl FP64x64Number of NumberTrait { fn bitwise_and(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { comp_fp64x64::bitwise_and(lhs, rhs) } + + fn add(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + FP64x64Add::add(lhs, rhs) + } + + fn sub(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + FP64x64Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; +use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub}; use orion::numbers::fixed_point::implementations::fp32x32::core as core_fp32x32; use orion::numbers::fixed_point::implementations::fp32x32::comp as comp_fp32x32; use cubit::f64 as fp32x32; @@ -1071,6 +1134,10 @@ impl FP32x32Number of NumberTrait { fp32x32::core::eq(@self, @FP32x32Impl::ZERO()) } + fn half() -> FP32x32 { + FP32x32Impl::HALF() + } + fn one() -> FP32x32 { FP32x32Impl::ONE() } @@ -1138,10 +1205,19 @@ impl FP32x32Number of NumberTrait { fn bitwise_and(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { comp_fp32x32::bitwise_and(lhs, rhs) } + + fn add(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + FP32x32Add::add(lhs, rhs) + } + + fn sub(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + FP32x32Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i8 as i8_core; use orion::numbers::signed_integer::i8::i8; +use orion::numbers::signed_integer::i8::{i8Add, i8Sub}; impl I8Number of NumberTrait { fn new(mag: u8, sign: bool) -> i8 { @@ -1251,6 +1327,10 @@ impl I8Number of NumberTrait { i8_core::i8_eq(self, i8 { mag: 0, sign: false }) } + fn half() -> i8 { + panic(array!['not supported!']) + } + fn one() -> i8 { i8 { mag: 1, sign: false } } @@ -1334,10 +1414,19 @@ impl I8Number of NumberTrait { fn bitwise_and(lhs: i8, rhs: i8) -> i8 { i8_core::i8_bitwise_and(lhs, rhs) } + + fn add(lhs: i8, rhs: i8) -> i8 { + i8Add::add(lhs, rhs) + } + + fn sub(lhs: i8, rhs: i8) -> i8 { + i8Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i16 as i16_core; use orion::numbers::signed_integer::i16::i16; +use orion::numbers::signed_integer::i16::{i16Add, i16Sub}; impl i16Number of NumberTrait { fn new(mag: u16, sign: bool) -> i16 { @@ -1447,6 +1536,10 @@ impl i16Number of NumberTrait { i16_core::i16_eq(self, i16 { mag: 0, sign: false }) } + fn half() -> i16 { + panic(array!['not supported!']) + } + fn one() -> i16 { i16 { mag: 1, sign: false } } @@ -1530,10 +1623,19 @@ impl i16Number of NumberTrait { fn bitwise_and(lhs: i16, rhs: i16) -> i16 { i16_core::i16_bitwise_and(lhs, rhs) } + + fn add(lhs: i16, rhs: i16) -> i16 { + i16Add::add(lhs, rhs) + } + + fn sub(lhs: i16, rhs: i16) -> i16 { + i16Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i32 as i32_core; use orion::numbers::signed_integer::i32::i32; +use orion::numbers::signed_integer::i32::{i32Add, i32Sub}; impl i32Number of NumberTrait { fn new(mag: u32, sign: bool) -> i32 { @@ -1643,6 +1745,10 @@ impl i32Number of NumberTrait { i32_core::i32_eq(self, i32 { mag: 0, sign: false }) } + fn half() -> i32 { + panic(array!['not supported!']) + } + fn one() -> i32 { i32 { mag: 1, sign: false } } @@ -1726,10 +1832,19 @@ impl i32Number of NumberTrait { fn bitwise_and(lhs: i32, rhs: i32) -> i32 { i32_core::i32_bitwise_and(lhs, rhs) } + + fn add(lhs: i32, rhs: i32) -> i32 { + i32Add::add(lhs, rhs) + } + + fn sub(lhs: i32, rhs: i32) -> i32 { + i32Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i64 as i64_core; use orion::numbers::signed_integer::i64::i64; +use orion::numbers::signed_integer::i64::{i64Add, i64Sub}; impl i64Number of NumberTrait { fn new(mag: u64, sign: bool) -> i64 { @@ -1839,6 +1954,10 @@ impl i64Number of NumberTrait { i64_core::i64_eq(self, i64 { mag: 0, sign: false }) } + fn half() -> i64 { + panic(array!['not supported!']) + } + fn one() -> i64 { i64 { mag: 1, sign: false } } @@ -1922,10 +2041,19 @@ impl i64Number of NumberTrait { fn bitwise_and(lhs: i64, rhs: i64) -> i64 { i64_core::i64_bitwise_and(lhs, rhs) } + + fn add(lhs: i64, rhs: i64) -> i64 { + i64Add::add(lhs, rhs) + } + + fn sub(lhs: i64, rhs: i64) -> i64 { + i64Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i128 as i128_core; use orion::numbers::signed_integer::i128::i128; +use orion::numbers::signed_integer::i128::{i128Add, i128Sub}; impl i128Number of NumberTrait { fn new(mag: u128, sign: bool) -> i128 { @@ -2036,6 +2164,10 @@ impl i128Number of NumberTrait { i128_core::i128_eq(self, i128 { mag: 0, sign: false }) } + fn half() -> i128 { + panic(array!['not supported!']) + } + fn one() -> i128 { i128 { mag: 1, sign: false } } @@ -2119,6 +2251,14 @@ impl i128Number of NumberTrait { fn bitwise_and(lhs: i128, rhs: i128) -> i128 { i128_core::i128_bitwise_and(lhs, rhs) } + + fn add(lhs: i128, rhs: i128) -> i128 { + i128Add::add(lhs, rhs) + } + + fn sub(lhs: i128, rhs: i128) -> i128 { + i128Sub::sub(lhs, rhs) + } } impl u32Number of NumberTrait { @@ -2230,6 +2370,10 @@ impl u32Number of NumberTrait { self == 0 } + fn half() -> u32 { + panic(array!['not supported!']) + } + fn one() -> u32 { 1 } @@ -2321,4 +2465,12 @@ impl u32Number of NumberTrait { fn bitwise_and(lhs: u32, rhs: u32) -> u32 { lhs & rhs } + + fn add(lhs: u32, rhs: u32) -> u32 { + lhs + rhs + } + + fn sub(lhs: u32, rhs: u32) -> u32 { + lhs - rhs + } } diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 6581b018f..b7afc3ee1 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1100,6 +1100,7 @@ trait FixedTrait { fn sign(self: T) -> T; fn ZERO() -> T; + fn HALF() -> T; fn ONE() -> T; fn MAX() -> T; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index 10aed6e09..f34f1ef63 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -29,6 +29,10 @@ impl FP16x16Impl of FixedTrait { return FP16x16 { mag: 0, sign: false }; } + fn HALF() -> FP16x16 { + return FP16x16 { mag: HALF, sign: false }; + } + fn ONE() -> FP16x16 { return FP16x16 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index f04f4e690..ebcf9c999 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -29,6 +29,10 @@ impl FP16x16WImpl of FixedTrait { return FP16x16W { mag: 0, sign: false }; } + fn HALF() -> FP16x16W { + return FP16x16W { mag: HALF, sign: false }; + } + fn ONE() -> FP16x16W { return FP16x16W { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index a84373883..506c04dbb 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -6,7 +6,7 @@ use traits::{TryInto, Into}; use cubit::f64 as fp32x32; use cubit::f64::Fixed as FP32x32; -use cubit::f64::ONE; +use cubit::f64::{ONE, HALF}; use cubit::f64::types::fixed; use orion::numbers::fixed_point::core::{FixedTrait}; @@ -20,6 +20,10 @@ impl FP32x32Impl of FixedTrait { return FP32x32 { mag: 0, sign: false }; } + fn HALF() -> FP32x32 { + return FP32x32 { mag: HALF, sign: false }; + } + fn ONE() -> FP32x32 { return FP32x32 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index 706fe21a6..d42a6747d 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -13,11 +13,17 @@ use orion::numbers::fixed_point::core::{FixedTrait}; use orion::numbers::fixed_point::utils; use orion::numbers::{i32, i8}; +const HALF: u128 = 9223372036854775808_u128; // 2 ** 63 + impl FP64x64Impl of FixedTrait { fn ZERO() -> FP64x64 { return FP64x64 { mag: 0, sign: false }; } + fn HALF() -> FP64x64 { + return FP64x64 { mag: HALF, sign: false }; + } + fn ONE() -> FP64x64 { return FP64x64 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 12ef49e24..a4b4311e1 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -29,6 +29,10 @@ impl FP8x23Impl of FixedTrait { return FP8x23 { mag: 0, sign: false }; } + fn HALF() -> FP8x23 { + return FP8x23 { mag: HALF, sign: false }; + } + fn ONE() -> FP8x23 { return FP8x23 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 0243b56fc..cafafd6b0 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -29,6 +29,10 @@ impl FP8x23WImpl of FixedTrait { return FP8x23W { mag: 0, sign: false }; } + fn HALF() -> FP8x23W { + return FP8x23W { mag: HALF, sign: false }; + } + fn ONE() -> FP8x23W { return FP8x23W { mag: ONE, sign: false }; } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..dfbc2acb4 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + fn shrink(self: Tensor, bias: Option, lambd: 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 29bf1c77b..df9f15077 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..8de4ea892 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 68f2482e7..38d6da67a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 f764b1920..51d7f3f79 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 6cded29b3..cc04b49a1 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 fdcdac1eb..320206b7d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 510731702..e462be25d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 8017ab300..9e3c61860 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// 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 4f2731b80..0c3ac82dd 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// 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 2f3c3a2ef..b5d22686f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..a82a8befa 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod shrink; diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo new file mode 100644 index 000000000..7c8c90e6a --- /dev/null +++ b/src/operators/tensor/math/shrink.cairo @@ -0,0 +1,55 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; + +/// Cf: TensorTrait::shrink docstring +fn shrink< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, bias: Option, lambd: Option +) -> Tensor { + + let bias: T = if bias.is_some() { + bias.unwrap() + } else { + NumberTrait::one() + }; + + let lambd: T = if lambd.is_some() { + lambd.unwrap() + } else { + NumberTrait::half() + }; + + let mut data_result = ArrayTrait::::new(); + + loop { + match self.data.pop_front() { + Option::Some(item) => { + if (*item) < lambd.neg() { + let mut y = NumberTrait::add(*item, bias); + data_result.append(y); + } else if (*item) > lambd { + let mut y = NumberTrait::sub(*item, bias); + data_result.append(y); + } else { + data_result.append(NumberTrait::zero()); + } + }, + Option::None(_) => { + break; + } + }; + }; + + return TensorTrait::new(self.shape, data_result.span()); +} From d767924c41edd19fb7acfd71240d4ec360e88e86 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 16:09:16 +0100 Subject: [PATCH 102/127] Adjust for optional attribute and limit to fixed point --- nodegen/node/binarizer.py | 18 +------- src/operators/tensor/core.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 4 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- src/operators/tensor/math/binarizer.cairo | 11 ++++- tests/nodes.cairo | 3 +- tests/nodes/binarizer_fp16x16.cairo | 2 +- tests/nodes/binarizer_fp8x23.cairo | 2 +- tests/nodes/binarizer_i32.cairo | 21 ---------- tests/nodes/binarizer_i32/input_0.cairo | 41 ------------------- tests/nodes/binarizer_i32/output_0.cairo | 41 ------------------- 18 files changed, 25 insertions(+), 136 deletions(-) delete mode 100644 tests/nodes/binarizer_i32.cairo delete mode 100644 tests/nodes/binarizer_i32/input_0.cairo delete mode 100644 tests/nodes/binarizer_i32/output_0.cairo diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py index f1a07d07a..47930aaf4 100644 --- a/nodegen/node/binarizer.py +++ b/nodegen/node/binarizer.py @@ -5,20 +5,6 @@ class Binarizer(RunAll): - @staticmethod - def binarizer_i32(): - x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) - threshold = np.int32(1) - y = (x > threshold).astype(np.int32) - - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) - - name = "binarizer_i32" - make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false));", name) - - @staticmethod def binarizer_fp8x23(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) @@ -32,7 +18,7 @@ def binarizer_fp8x23(): name = "binarizer_fp8x23" make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false));", name) + make_test([x], y, "TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false));", name) @staticmethod @@ -48,4 +34,4 @@ def binarizer_fp16x16(): name = "binarizer_fp16x16" make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false));", name) + make_test([x], y, "TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false));", name) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index c1d1271bb..b76142d13 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3258,7 +3258,7 @@ trait TensorTrait { /// >>> [0, 0, 0, 1] /// ``` /// - fn binarizer(self: @Tensor, threshold: @T) -> Tensor; + fn binarizer(self: @Tensor, threshold: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 16c3d178a..71470e379 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,7 +288,7 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 5d7ac3908..964a98250 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -287,7 +287,7 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 8bd01a0e3..7a8d19111 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -289,7 +289,7 @@ impl FP32x32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 6c094b827..ed6c3f86c 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,7 +289,7 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 01455b675..df2416684 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -288,7 +288,7 @@ impl FP8x23Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 5a15a7cd2..1a4a32f12 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,7 +277,7 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index dbfac85d5..3be767db6 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -288,8 +288,8 @@ impl I32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { - math::binarizer::binarizer(*self, threshold) + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 65a0e5081..bbed5ed3c 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -287,7 +287,7 @@ impl I8Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index ed3903921..b55c3b9d3 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -269,7 +269,7 @@ impl U32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index 697c4e293..9b37a98ef 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -15,14 +15,21 @@ fn binarizer< impl TCopy: Copy, impl TDrop: Drop >( - mut self: Tensor, threshold: @T + mut self: Tensor, threshold: Option ) -> Tensor { + + let threshold: T = if threshold.is_some() { + threshold.unwrap() + } else { + NumberTrait::zero() + }; + let mut binarized_data = ArrayTrait::::new(); loop { match self.data.pop_front() { Option::Some(item) => { - if (*item) > (*threshold) { + if (*item) > threshold { binarized_data.append(NumberTrait::one()); } else { binarized_data.append(NumberTrait::zero()); diff --git a/tests/nodes.cairo b/tests/nodes.cairo index e841e15aa..19469328f 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -529,5 +529,4 @@ mod scatter_u32_default; mod scatter_u32_axis1; mod scatter_u32_add; mod binarizer_fp16x16; -mod binarizer_fp8x23; -mod binarizer_i32; +mod binarizer_fp8x23; diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 5ddd92826..87306959b 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -15,7 +15,7 @@ fn test_binarizer_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false)); + let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false))); assert_eq(y, z); } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 62d6f3ee4..91b481fa3 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -15,7 +15,7 @@ fn test_binarizer_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false)); + let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false))); assert_eq(y, z); } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo deleted file mode 100644 index 7793b74ae..000000000 --- a/tests/nodes/binarizer_i32.cairo +++ /dev/null @@ -1,21 +0,0 @@ -mod input_0; -mod output_0; - - -use array::{ArrayTrait, SpanTrait}; -use orion::numbers::IntegerTrait; -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_binarizer_i32() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false)); - - assert_eq(y, z); -} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo deleted file mode 100644 index 3059b3649..000000000 --- a/tests/nodes/binarizer_i32/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -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(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo deleted file mode 100644 index 3adef88e2..000000000 --- a/tests/nodes/binarizer_i32/output_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -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(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file From cd9227d4be8a826b54fafb8f8908c69b615920b7 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 16:14:17 +0100 Subject: [PATCH 103/127] Fix generating tests for sequence output --- nodegen/file_manager.py | 40 ++++++++++++++++++++++++++++++++++++++-- nodegen/helpers.py | 22 ++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/nodegen/file_manager.py b/nodegen/file_manager.py index 215bacbcc..b1020f0c7 100644 --- a/nodegen/file_manager.py +++ b/nodegen/file_manager.py @@ -72,9 +72,9 @@ def __init__(self, file: str): super().__init__(os.path.join(BASE_PATH, file)) @classmethod - def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + def base_template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: """ - Create a template for a Cairo test function. + Create a template for a Cairo test function which expects a tensor output. Args: name (str): Name of the test function. @@ -107,6 +107,42 @@ def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> li *[ "}"], ] + @classmethod + def sequence_template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + """ + Create a template for a Cairo test function which expects a tensor sequence. + + Args: + name (str): Name of the test function. + arg_cnt (int): Number of arguments for the function. + refs (list[str]): List of references (modules) to be used in the function. + func_sig (str): The function signature. + + Returns: + list[str]: A list of strings that together form the template of a Cairo test function. + + This method generates a list of strings that form the template of a Cairo test function, + including module imports, function definition, and assertions. + """ + return [ + *[f"mod input_{i};" for i in range(arg_cnt)], + *[ "mod output_0;"], + *[ ""], + *[ ""], + *[f"use {ref};" for ref in refs], + *[ ""], + *[ "#[test]"], + *[ "#[available_gas(2000000000)]"], + *[f"fn test_{name}()"+" {"], + *[f" let input_{i} = input_{i}::input_{i}();" for i in range(arg_cnt)], + *[ " let z = output_0::output_0();"], + *[ ""], + *[f" let y = {func_sig};"], + *[ ""], + *[ " assert_seq_eq(y, z);"], + *[ "}"], + ] + class CairoData(File): def __init__(self, file: str): diff --git a/nodegen/helpers.py b/nodegen/helpers.py index d027a7ec5..6eac7a003 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -100,12 +100,22 @@ def make_test(inputs: list[Tensor | Sequence], output: Tensor | Sequence, func_s output_data.dump() test_file = CairoTest(f"{name}.cairo") - test_file.buffer = CairoTest.template( - name=name, - arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, output]), trait, isinstance(output, list)), - func_sig=func_sig, - ) + match output: + case list(): + test_file.buffer = CairoTest.sequence_template( + name=name, + arg_cnt=len(inputs), + refs=get_all_test_refs(find_all_types([*inputs, *output]), trait, True), + func_sig=func_sig, + ) + case Tensor(): + test_file.buffer = CairoTest.base_template( + name=name, + arg_cnt=len(inputs), + refs=get_all_test_refs(find_all_types([*inputs, output]), trait, False), + func_sig=func_sig, + ) + test_file.dump() From 0cc9d4d89807a253d74a53a6c9efa42e01712999 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 16:31:15 +0100 Subject: [PATCH 104/127] Remove redundant `is_sequence` argument --- nodegen/helpers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 6eac7a003..a9290362d 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -105,14 +105,14 @@ def make_test(inputs: list[Tensor | Sequence], output: Tensor | Sequence, func_s test_file.buffer = CairoTest.sequence_template( name=name, arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, *output]), trait, True), + refs=get_all_test_refs(find_all_types([*inputs, *output]), trait), func_sig=func_sig, ) case Tensor(): test_file.buffer = CairoTest.base_template( name=name, arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, output]), trait, False), + refs=get_all_test_refs(find_all_types([*inputs, output]), trait), func_sig=func_sig, ) @@ -147,15 +147,15 @@ def get_data_statement_for_sequences(data: Sequence, dtype: Dtype) -> list[list[ return [get_data_statement(x.data, dtype) for x in data] -def get_all_test_refs(dtypes: list[Dtype], trait: Trait, is_sequence: bool) -> list[str]: +def get_all_test_refs(dtypes: list[Dtype], trait: Trait) -> list[str]: refs = [] for dtype in dtypes: - refs += get_test_refs(dtype, trait, is_sequence) + refs += get_test_refs(dtype, trait) return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: dtype_ref = dtype_to_nn[dtype] if trait == Trait.NN else dtype_to_tensor[dtype] refs = [ *trait_to_ref[trait], From 6e3cea97f957471e70c7da00cde1b3a5d6d8e7f9 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 16:41:47 +0100 Subject: [PATCH 105/127] Adjust docstring --- .../operators/tensor/tensor.binarizer.md | 28 ++++++++++--------- src/operators/tensor/core.cairo | 28 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md index 14cac3d65..01e24e58e 100644 --- a/docs/framework/operators/tensor/tensor.binarizer.md +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -8,37 +8,39 @@ Maps the values of a tensor element-wise to 0 or 1 based on the comparison again ## Args * `self`(`@Tensor`) - The input tensor to be binarized. -* `threshold`(`@T`) - The threshold for the binarization operation. +* `threshold`(`Option`) - The threshold for the binarization operation. ## Returns A new `Tensor` of the same shape as the input tensor with binarized values. ## Type Constraints -Constrain input and output types to fixed point and int32 tensors. +Constrain input and output types to fixed point numbers. ## Examples ```rust use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; -use orion::numbers::{i32, IntegerTrait}; +use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; +use orion::numbers::{FixedTrait, FP8x23}; -fn binarizer_example() -> Tensor { - let tensor = TensorTrait::::new( +fn binarizer_example() -> Tensor { + let tensor = TensorTrait::::new( shape: array![2, 2].span(), data: array![ - IntegerTrait::new(1, true), - IntegerTrait::new(0, false), - IntegerTrait::new(1, false), - IntegerTrait::new(2, false), + FixedTrait::new(0, false), + FixedTrait::new(1, false), + FixedTrait::new(2, false), + FixedTrait::new(3, false) ] .span(), ); - let threshold = IntegerTrait::::new(1, false) + let threshold = Option::Some(FixedTrait::new(1, false)) - return tensor.binarizer(@tensor, @threshold); + return tensor.binarizer(@tensor, threshold); } ->>> [0, 0, 0, 1] +>>> [0, 0, 8388608, 8388608] + // The fixed point representation of + [0, 0, 1, 1] ``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index b76142d13..931b42564 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3223,39 +3223,41 @@ trait TensorTrait { /// /// ## Args /// * `self`(`@Tensor`) - The input tensor to be binarized. - /// * `threshold`(`@T`) - The threshold for the binarization operation. + /// * `threshold`(`Option`) - The threshold for the binarization operation. /// /// ## Returns /// A new `Tensor` of the same shape as the input tensor with binarized values. /// /// ## Type Constraints /// - /// Constrain input and output types to fixed point and int32 tensors. + /// Constrain input and output types to fixed point numbers. /// /// ## Examples /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// - /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; - /// use orion::numbers::{i32, IntegerTrait}; + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; /// - /// fn binarizer_example() -> Tensor { - /// let tensor = TensorTrait::::new( + /// fn binarizer_example() -> Tensor { + /// let tensor = TensorTrait::::new( /// shape: array![2, 2].span(), /// data: array![ - /// IntegerTrait::new(1, true), - /// IntegerTrait::new(0, false), - /// IntegerTrait::new(1, false), - /// IntegerTrait::new(2, false), + /// FixedTrait::new(0, false), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false), + /// FixedTrait::new(3, false) /// ] /// .span(), /// ); - /// let threshold = IntegerTrait::::new(1, false) + /// let threshold = Option::Some(FixedTrait::new(1, false)) /// - /// return tensor.binarizer(@tensor, @threshold); + /// return tensor.binarizer(@tensor, threshold); /// } - /// >>> [0, 0, 0, 1] + /// >>> [0, 0, 8388608, 8388608] + /// // The fixed point representation of + /// [0, 0, 1, 1] /// ``` /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor; From 908a82070d0b844976603e45fd2b8bbdb6a6a614 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 19:05:16 +0100 Subject: [PATCH 106/127] Add support for boolean tensors --- nodegen/helpers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index d027a7ec5..821a4944a 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -26,6 +26,7 @@ class Dtype(Enum): I8 = 'i8' I32 = 'i32' U32 = 'u32' + BOOL = 'bool' class Tensor: @@ -131,6 +132,8 @@ def get_data_statement(data: np.ndarray, dtype: Dtype) -> list[str]: return ["FP8x23 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] case Dtype.FP16x16: return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] + case Dtype.BOOL: + return [str(x).lower() for x in data.flatten()] def get_data_statement_for_sequences(data: Sequence, dtype: Dtype) -> list[list[str]]: @@ -146,6 +149,9 @@ def get_all_test_refs(dtypes: list[Dtype], trait: Trait, is_sequence: bool) -> l def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: + if trait == Trait.NN and dtype == Dtype.BOOL: + raise Exception("NN trait does not support bool dtype") + dtype_ref = dtype_to_nn[dtype] if trait == Trait.NN else dtype_to_tensor[dtype] refs = [ *trait_to_ref[trait], @@ -186,6 +192,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::operators::tensor::I8Tensor",], Dtype.FP8x23: ["orion::operators::tensor::FP8x23Tensor",], Dtype.FP16x16: ["orion::operators::tensor::FP16x16Tensor",], + Dtype.BOOL: ["orion::operators::tensor::BoolTensor",], } @@ -204,6 +211,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::operators::tensor::I8TensorPartialEq",], Dtype.FP8x23: ["orion::operators::tensor::FP8x23TensorPartialEq",], Dtype.FP16x16: ["orion::operators::tensor::FP16x16TensorPartialEq",], + Dtype.BOOL: ["orion::operators::tensor::BoolTensorPartialEq",], } @@ -213,4 +221,5 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::numbers::{IntegerTrait, i8}",], Dtype.FP8x23: ["orion::numbers::{FixedTrait, FP8x23}",], Dtype.FP16x16: ["orion::numbers::{FixedTrait, FP16x16}",], + Dtype.BOOL: [], } From ef774119af9cdf89c8de87457c1df40bba6f95ae Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 19:45:13 +0100 Subject: [PATCH 107/127] Add tests and fix bug in operator --- nodegen/node/shrink.py | 79 +++++++++++++++++++ src/operators/tensor/math/shrink.cairo | 2 +- tests/nodes.cairo | 4 + tests/nodes/shrink_hard_fp16x16.cairo | 21 +++++ tests/nodes/shrink_hard_fp16x16/input_0.cairo | 41 ++++++++++ .../nodes/shrink_hard_fp16x16/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_hard_fp8x23.cairo | 21 +++++ tests/nodes/shrink_hard_fp8x23/input_0.cairo | 41 ++++++++++ tests/nodes/shrink_hard_fp8x23/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp16x16.cairo | 21 +++++ tests/nodes/shrink_soft_fp16x16/input_0.cairo | 41 ++++++++++ .../nodes/shrink_soft_fp16x16/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp8x23.cairo | 21 +++++ tests/nodes/shrink_soft_fp8x23/input_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp8x23/output_0.cairo | 41 ++++++++++ 15 files changed, 496 insertions(+), 1 deletion(-) create mode 100644 nodegen/node/shrink.py create mode 100644 tests/nodes/shrink_hard_fp16x16.cairo create mode 100644 tests/nodes/shrink_hard_fp16x16/input_0.cairo create mode 100644 tests/nodes/shrink_hard_fp16x16/output_0.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23/input_0.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23/output_0.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16/input_0.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16/output_0.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23/input_0.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23/output_0.cairo diff --git a/nodegen/node/shrink.py b/nodegen/node/shrink.py new file mode 100644 index 000000000..8e6556226 --- /dev/null +++ b/nodegen/node/shrink.py @@ -0,0 +1,79 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +def shrink(input_array: np.ndarray, bias: float, lambd: float) -> np.ndarray: + output_array = np.where(input_array > lambd, input_array - bias, + np.where(input_array < -lambd, input_array + bias, 0)) + return output_array + + +class Shrink(RunAll): + + @staticmethod + def shrink_fp8x23(): + def shrink_hard(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(0) # Default value + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + 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 = "shrink_hard_fp8x23" + make_test([x], y, "TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false)))", name) + + def shrink_soft(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(1) + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + 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 = "shrink_soft_fp8x23" + make_test([x], y, "TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false)))", name) + + shrink_hard() + shrink_soft() + + + @staticmethod + def shrink_fp16x16(): + def shrink_hard(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(0) # Default value + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + 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 = "shrink_hard_fp16x16" + make_test([x], y, "TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false)))", name) + + def shrink_soft(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(1) + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + 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 = "shrink_soft_fp16x16" + make_test([x], y, "TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false)))", name) + + shrink_hard() + shrink_soft() \ No newline at end of file diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo index 7c8c90e6a..90c010f85 100644 --- a/src/operators/tensor/math/shrink.cairo +++ b/src/operators/tensor/math/shrink.cairo @@ -21,7 +21,7 @@ fn shrink< let bias: T = if bias.is_some() { bias.unwrap() } else { - NumberTrait::one() + NumberTrait::zero() }; let lambd: T = if lambd.is_some() { diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..03fc9bc94 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,7 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod shrink_hard_fp16x16; +mod shrink_soft_fp16x16; +mod shrink_hard_fp8x23; +mod shrink_soft_fp8x23; diff --git a/tests/nodes/shrink_hard_fp16x16.cairo b/tests/nodes/shrink_hard_fp16x16.cairo new file mode 100644 index 000000000..2272fd758 --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_hard_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_hard_fp16x16/input_0.cairo b/tests/nodes/shrink_hard_fp16x16/input_0.cairo new file mode 100644 index 000000000..1c0d4c303 --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 53724, sign: false }); + data.append(FP16x16 { mag: 100114, sign: true }); + data.append(FP16x16 { mag: 105707, sign: true }); + data.append(FP16x16 { mag: 172713, sign: false }); + data.append(FP16x16 { mag: 117489, sign: true }); + data.append(FP16x16 { mag: 131055, sign: false }); + data.append(FP16x16 { mag: 136968, sign: true }); + data.append(FP16x16 { mag: 139039, sign: true }); + data.append(FP16x16 { mag: 179765, sign: false }); + data.append(FP16x16 { mag: 116549, sign: false }); + data.append(FP16x16 { mag: 86012, sign: true }); + data.append(FP16x16 { mag: 42842, sign: false }); + data.append(FP16x16 { mag: 102196, sign: false }); + data.append(FP16x16 { mag: 91319, sign: true }); + data.append(FP16x16 { mag: 154563, sign: true }); + data.append(FP16x16 { mag: 148265, sign: false }); + data.append(FP16x16 { mag: 147485, sign: false }); + data.append(FP16x16 { mag: 18844, sign: true }); + data.append(FP16x16 { mag: 87916, sign: true }); + data.append(FP16x16 { mag: 53116, sign: false }); + data.append(FP16x16 { mag: 189184, sign: false }); + data.append(FP16x16 { mag: 172959, sign: true }); + data.append(FP16x16 { mag: 24790, sign: false }); + data.append(FP16x16 { mag: 141694, sign: false }); + data.append(FP16x16 { mag: 142845, sign: false }); + data.append(FP16x16 { mag: 88179, sign: false }); + data.append(FP16x16 { mag: 76572, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp16x16/output_0.cairo b/tests/nodes/shrink_hard_fp16x16/output_0.cairo new file mode 100644 index 000000000..056cb881d --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 100114, sign: true }); + data.append(FP16x16 { mag: 105707, sign: true }); + data.append(FP16x16 { mag: 172713, sign: false }); + data.append(FP16x16 { mag: 117489, sign: true }); + data.append(FP16x16 { mag: 131055, sign: false }); + data.append(FP16x16 { mag: 136968, sign: true }); + data.append(FP16x16 { mag: 139039, sign: true }); + data.append(FP16x16 { mag: 179765, sign: false }); + data.append(FP16x16 { mag: 116549, sign: false }); + data.append(FP16x16 { mag: 86012, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 102196, sign: false }); + data.append(FP16x16 { mag: 91319, sign: true }); + data.append(FP16x16 { mag: 154563, sign: true }); + data.append(FP16x16 { mag: 148265, sign: false }); + data.append(FP16x16 { mag: 147485, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 87916, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 189184, sign: false }); + data.append(FP16x16 { mag: 172959, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 141694, sign: false }); + data.append(FP16x16 { mag: 142845, sign: false }); + data.append(FP16x16 { mag: 88179, sign: false }); + data.append(FP16x16 { mag: 76572, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp8x23.cairo b/tests/nodes/shrink_hard_fp8x23.cairo new file mode 100644 index 000000000..d9294c755 --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_hard_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_hard_fp8x23/input_0.cairo b/tests/nodes/shrink_hard_fp8x23/input_0.cairo new file mode 100644 index 000000000..9148dbd07 --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16287022, sign: true }); + data.append(FP8x23 { mag: 10799553, sign: false }); + data.append(FP8x23 { mag: 2484402, sign: true }); + data.append(FP8x23 { mag: 17585288, sign: true }); + data.append(FP8x23 { mag: 6428, sign: false }); + data.append(FP8x23 { mag: 22747410, sign: false }); + data.append(FP8x23 { mag: 7024249, sign: false }); + data.append(FP8x23 { mag: 1080111, sign: false }); + data.append(FP8x23 { mag: 21293057, sign: true }); + data.append(FP8x23 { mag: 1501238, sign: true }); + data.append(FP8x23 { mag: 8554184, sign: true }); + data.append(FP8x23 { mag: 12577394, sign: false }); + data.append(FP8x23 { mag: 14241673, sign: true }); + data.append(FP8x23 { mag: 316469, sign: true }); + data.append(FP8x23 { mag: 16672164, sign: false }); + data.append(FP8x23 { mag: 23534429, sign: false }); + data.append(FP8x23 { mag: 22979924, sign: false }); + data.append(FP8x23 { mag: 12554544, sign: true }); + data.append(FP8x23 { mag: 8831121, sign: false }); + data.append(FP8x23 { mag: 12310986, sign: false }); + data.append(FP8x23 { mag: 16220051, sign: false }); + data.append(FP8x23 { mag: 1096465, sign: true }); + data.append(FP8x23 { mag: 1158077, sign: false }); + data.append(FP8x23 { mag: 7755965, sign: false }); + data.append(FP8x23 { mag: 24795265, sign: false }); + data.append(FP8x23 { mag: 1285412, sign: true }); + data.append(FP8x23 { mag: 12210140, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp8x23/output_0.cairo b/tests/nodes/shrink_hard_fp8x23/output_0.cairo new file mode 100644 index 000000000..68f66101f --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16287022, sign: true }); + data.append(FP8x23 { mag: 10799553, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 17585288, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 22747410, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 21293057, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8554184, sign: true }); + data.append(FP8x23 { mag: 12577394, sign: false }); + data.append(FP8x23 { mag: 14241673, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16672164, sign: false }); + data.append(FP8x23 { mag: 23534429, sign: false }); + data.append(FP8x23 { mag: 22979924, sign: false }); + data.append(FP8x23 { mag: 12554544, sign: true }); + data.append(FP8x23 { mag: 8831121, sign: false }); + data.append(FP8x23 { mag: 12310986, sign: false }); + data.append(FP8x23 { mag: 16220051, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 24795265, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 12210140, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp16x16.cairo b/tests/nodes/shrink_soft_fp16x16.cairo new file mode 100644 index 000000000..e5a8ef066 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_soft_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_soft_fp16x16/input_0.cairo b/tests/nodes/shrink_soft_fp16x16/input_0.cairo new file mode 100644 index 000000000..5c4f4a480 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 78056, sign: true }); + data.append(FP16x16 { mag: 31456, sign: true }); + data.append(FP16x16 { mag: 172639, sign: true }); + data.append(FP16x16 { mag: 78597, sign: false }); + data.append(FP16x16 { mag: 62154, sign: false }); + data.append(FP16x16 { mag: 171656, sign: false }); + data.append(FP16x16 { mag: 157535, sign: false }); + data.append(FP16x16 { mag: 49284, sign: false }); + data.append(FP16x16 { mag: 97008, sign: false }); + data.append(FP16x16 { mag: 123759, sign: true }); + data.append(FP16x16 { mag: 190267, sign: false }); + data.append(FP16x16 { mag: 107363, sign: false }); + data.append(FP16x16 { mag: 7956, sign: true }); + data.append(FP16x16 { mag: 68542, sign: false }); + data.append(FP16x16 { mag: 116678, sign: false }); + data.append(FP16x16 { mag: 85597, sign: false }); + data.append(FP16x16 { mag: 19210, sign: true }); + data.append(FP16x16 { mag: 99774, sign: false }); + data.append(FP16x16 { mag: 173484, sign: false }); + data.append(FP16x16 { mag: 127017, sign: true }); + data.append(FP16x16 { mag: 83696, sign: false }); + data.append(FP16x16 { mag: 16087, sign: true }); + data.append(FP16x16 { mag: 80426, sign: false }); + data.append(FP16x16 { mag: 187986, sign: false }); + data.append(FP16x16 { mag: 45262, sign: true }); + data.append(FP16x16 { mag: 46955, sign: false }); + data.append(FP16x16 { mag: 38631, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp16x16/output_0.cairo b/tests/nodes/shrink_soft_fp16x16/output_0.cairo new file mode 100644 index 000000000..6132122d8 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 12520, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 107103, sign: true }); + data.append(FP16x16 { mag: 13061, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 106120, sign: false }); + data.append(FP16x16 { mag: 91999, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 31472, sign: false }); + data.append(FP16x16 { mag: 58223, sign: true }); + data.append(FP16x16 { mag: 124731, sign: false }); + data.append(FP16x16 { mag: 41827, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 3006, sign: false }); + data.append(FP16x16 { mag: 51142, sign: false }); + data.append(FP16x16 { mag: 20061, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 34238, sign: false }); + data.append(FP16x16 { mag: 107948, sign: false }); + data.append(FP16x16 { mag: 61481, sign: true }); + data.append(FP16x16 { mag: 18160, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 14890, sign: false }); + data.append(FP16x16 { mag: 122450, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp8x23.cairo b/tests/nodes/shrink_soft_fp8x23.cairo new file mode 100644 index 000000000..66884de9f --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_soft_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_soft_fp8x23/input_0.cairo b/tests/nodes/shrink_soft_fp8x23/input_0.cairo new file mode 100644 index 000000000..0189876bb --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 13404706, sign: true }); + data.append(FP8x23 { mag: 1642563, sign: true }); + data.append(FP8x23 { mag: 16689459, sign: false }); + data.append(FP8x23 { mag: 2347829, sign: false }); + data.append(FP8x23 { mag: 3467112, sign: false }); + data.append(FP8x23 { mag: 592703, sign: true }); + data.append(FP8x23 { mag: 1941576, sign: false }); + data.append(FP8x23 { mag: 4972, sign: true }); + data.append(FP8x23 { mag: 21738998, sign: false }); + data.append(FP8x23 { mag: 11513586, sign: true }); + data.append(FP8x23 { mag: 23646070, sign: false }); + data.append(FP8x23 { mag: 13206001, sign: true }); + data.append(FP8x23 { mag: 10769444, sign: false }); + data.append(FP8x23 { mag: 10345798, sign: false }); + data.append(FP8x23 { mag: 1337911, sign: true }); + data.append(FP8x23 { mag: 23240711, sign: false }); + data.append(FP8x23 { mag: 3398664, sign: false }); + data.append(FP8x23 { mag: 13332160, sign: true }); + data.append(FP8x23 { mag: 2545195, sign: false }); + data.append(FP8x23 { mag: 21250720, sign: true }); + data.append(FP8x23 { mag: 16789138, sign: true }); + data.append(FP8x23 { mag: 23029037, sign: true }); + data.append(FP8x23 { mag: 19022158, sign: false }); + data.append(FP8x23 { mag: 20748602, sign: false }); + data.append(FP8x23 { mag: 21590667, sign: false }); + data.append(FP8x23 { mag: 1180061, sign: false }); + data.append(FP8x23 { mag: 8043052, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp8x23/output_0.cairo b/tests/nodes/shrink_soft_fp8x23/output_0.cairo new file mode 100644 index 000000000..72dde7a12 --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 5016098, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8300851, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 13350390, sign: false }); + data.append(FP8x23 { mag: 3124978, sign: true }); + data.append(FP8x23 { mag: 15257462, sign: false }); + data.append(FP8x23 { mag: 4817393, sign: true }); + data.append(FP8x23 { mag: 2380836, sign: false }); + data.append(FP8x23 { mag: 1957190, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 14852103, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 4943552, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 12862112, sign: true }); + data.append(FP8x23 { mag: 8400530, sign: true }); + data.append(FP8x23 { mag: 14640429, sign: true }); + data.append(FP8x23 { mag: 10633550, sign: false }); + data.append(FP8x23 { mag: 12359994, sign: false }); + data.append(FP8x23 { mag: 13202059, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} From 1270e1feb0e5e2cb123e5fb876121cdb87cdf054 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 22:02:37 +0100 Subject: [PATCH 108/127] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.shrink.md | 49 ++++++++++++++++++ src/operators/tensor/core.cairo | 50 +++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.shrink.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..1a2942a23 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.shrink](framework/operators/tensor/tensor.shrink.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 ebc50ad77..2395d35a1 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [Shrink](operators/tensor/tensor.shrink.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..670436ead 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.shrink.md b/docs/framework/operators/tensor/tensor.shrink.md new file mode 100644 index 000000000..37c2e74aa --- /dev/null +++ b/docs/framework/operators/tensor/tensor.shrink.md @@ -0,0 +1,49 @@ +# tensor.shrink + +```rust + fn shrink(self: @Tensor, bias: Option, lambd: Option) -> Tensor +``` + +Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on the following formula: +If x < -lambd: y = x + bias; If x > lambd: y = x - bias; Otherwise: y = 0. + +## Args +* `self`(`@Tensor`) - The input tensor to be shrinked. +* `bias`(`Option`) - The bias value added to or subtracted from input tensor values. +* `lambd`(`Option`) - The lambd value defining the shrink condition. + +## Returns +A new `Tensor` of the same datatype and shape as the input tensor with shrinked values. + +## Type Constraints + +Constrain input and output types to fixed point numbers. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; +use orion::numbers::{FixedTrait, FP8x23}; + +fn shrink_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2].span(), + data: array![ + FixedTrait::new(2, true), + FixedTrait::new(1, true), + FixedTrait::new(1, false), + FixedTrait::new(2, false) + ] + .span(), + ); + let bias = Option::Some(FixedTrait::new(1, false)) + let lambd = Option::Some(FixedTrait::new(1, false)) + + return tensor.shrink(tensor, bias, lambd); +} +>>> [-8388608, 0, 0, 8388608] + // The fixed point representation of + [-1, 0, 0, 1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index dfbc2acb4..81ab443c9 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,56 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// # tensor.shrink + /// + /// ```rust + /// fn shrink(self: @Tensor, bias: Option, lambd: Option) -> Tensor + /// ``` + /// + /// Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on the following formula: + /// If x < -lambd: y = x + bias; If x > lambd: y = x - bias; Otherwise: y = 0. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be shrinked. + /// * `bias`(`Option`) - The bias value added to or subtracted from input tensor values. + /// * `lambd`(`Option`) - The lambd value defining the shrink condition. + /// + /// ## Returns + /// A new `Tensor` of the same datatype and shape as the input tensor with shrinked values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point numbers. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// fn shrink_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// FixedTrait::new(2, true), + /// FixedTrait::new(1, true), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false) + /// ] + /// .span(), + /// ); + /// let bias = Option::Some(FixedTrait::new(1, false)) + /// let lambd = Option::Some(FixedTrait::new(1, false)) + /// + /// return tensor.shrink(tensor, bias, lambd); + /// } + /// >>> [-8388608, 0, 0, 8388608] + /// // The fixed point representation of + /// [-1, 0, 0, 1] + /// ``` + /// fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; } From c3b486fb980f95abe51f0bc439c4e70f2c62b043 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 22:11:51 +0100 Subject: [PATCH 109/127] Fix docstring --- docs/framework/operators/tensor/tensor.binarizer.md | 2 +- src/operators/tensor/core.cairo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md index 01e24e58e..f97dcd446 100644 --- a/docs/framework/operators/tensor/tensor.binarizer.md +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -1,7 +1,7 @@ # tensor.binarizer ```rust - fn binarizer(self: @Tensor, threshold: @T) -> Tensor + fn binarizer(self: @Tensor, threshold: Option) -> Tensor ``` Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 931b42564..0f36a83c8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3216,7 +3216,7 @@ trait TensorTrait { /// # tensor.binarizer /// /// ```rust - /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor + /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor /// ``` /// /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. From c8dca89672de50cb0a24633b704405a9f7408489 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 15 Nov 2023 11:40:46 +0200 Subject: [PATCH 110/127] datasource generator --- tests/nodes/and_fp16x16.cairo | 6 ++- tests/nodes/and_fp16x16/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp16x16/input_1.cairo | 33 ++++++++--------- tests/nodes/and_fp16x16/output_0.cairo | 14 +++---- tests/nodes/and_fp16x16_broadcast.cairo | 6 ++- .../nodes/and_fp16x16_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp16x16_broadcast/input_1.cairo | 7 ++-- .../and_fp16x16_broadcast/output_0.cairo | 6 +-- tests/nodes/and_fp8x23.cairo | 6 ++- tests/nodes/and_fp8x23/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp8x23/input_1.cairo | 37 +++++++++---------- tests/nodes/and_fp8x23/output_0.cairo | 8 ++-- tests/nodes/and_fp8x23_broadcast.cairo | 6 ++- .../nodes/and_fp8x23_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp8x23_broadcast/input_1.cairo | 5 +-- .../nodes/and_fp8x23_broadcast/output_0.cairo | 4 +- tests/nodes/and_i32.cairo | 6 ++- tests/nodes/and_i32/input_0.cairo | 26 ++++++------- tests/nodes/and_i32/input_1.cairo | 30 +++++++-------- tests/nodes/and_i32/output_0.cairo | 8 ++-- tests/nodes/and_i32_broadcast.cairo | 6 ++- tests/nodes/and_i32_broadcast/input_0.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_1.cairo | 2 +- tests/nodes/and_i32_broadcast/output_0.cairo | 4 +- tests/nodes/and_i8.cairo | 8 ++-- tests/nodes/and_i8/input_0.cairo | 28 +++++++------- tests/nodes/and_i8/input_1.cairo | 28 +++++++------- tests/nodes/and_i8/output_0.cairo | 14 +++---- tests/nodes/and_i8_broadcast.cairo | 8 ++-- tests/nodes/and_i8_broadcast/input_0.cairo | 4 +- tests/nodes/and_i8_broadcast/input_1.cairo | 2 +- tests/nodes/and_u32.cairo | 4 +- tests/nodes/and_u32/input_0.cairo | 28 +++++++------- tests/nodes/and_u32/input_1.cairo | 30 +++++++-------- tests/nodes/and_u32/output_0.cairo | 10 ++--- tests/nodes/and_u32_broadcast.cairo | 4 +- tests/nodes/and_u32_broadcast/input_0.cairo | 4 +- tests/nodes/and_u32_broadcast/input_1.cairo | 4 +- tests/nodes/and_u32_broadcast/output_0.cairo | 4 +- 39 files changed, 245 insertions(+), 237 deletions(-) diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo index dcd53ea37..4dc2ad9f6 100644 --- a/tests/nodes/and_fp16x16.cairo +++ b/tests/nodes/and_fp16x16.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::FP16x16TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo index b32a5f0b6..60341e471 100644 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ b/tests/nodes/and_fp16x16/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 65536, sign: false }); - 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: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); - 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: 65536, sign: true }); - 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: 0, sign: false }); + 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: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); 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: 65536, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo index 2b2036fce..0fa0aab56 100644 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ b/tests/nodes/and_fp16x16/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - 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: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + 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: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo index 8a754463f..f33e1f678 100644 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ b/tests/nodes/and_fp16x16/output_0.cairo @@ -12,29 +12,29 @@ fn output_0() -> Tensor { data.append(1); data.append(1); data.append(1); + data.append(0); + data.append(0); + data.append(1); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo index 0f0a979da..a94e21b2c 100644 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ b/tests/nodes/and_fp16x16_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::FP16x16TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo index 2554de21d..50048a641 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo index 019f2f532..a92003169 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_fp16x16_broadcast/output_0.cairo index 12e081541..486b39f3d 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); data.append(0); - data.append(1); - data.append(1); + data.append(0); + data.append(0); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo index 373cfadaf..70b96f1d5 100644 --- a/tests/nodes/and_fp8x23.cairo +++ b/tests/nodes/and_fp8x23.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo index b093e4c53..95ee20a11 100644 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ b/tests/nodes/and_fp8x23/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + 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: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo index 0553e0019..e689e6c06 100644 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ b/tests/nodes/and_fp8x23/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo index fa2a76b74..6a3748b94 100644 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ b/tests/nodes/and_fp8x23/output_0.cairo @@ -10,7 +10,6 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); @@ -18,23 +17,24 @@ fn output_0() -> Tensor { data.append(0); data.append(1); data.append(1); - data.append(0); - data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(0); data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo index ad50264f8..12ef3a56f 100644 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ b/tests/nodes/and_fp8x23_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo index f7cb3a134..bd881a8c8 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,8 +10,8 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo index 35cf05e4e..ab5b373e8 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_fp8x23_broadcast/output_0.cairo index 3883dcaf3..f90728ddd 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(0); data.append(1); - data.append(1); - data.append(1); + data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_i32.cairo index fd56fd1bb..c33b4b693 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_i32.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32TensorPartialEq; use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo index bb190dea5..f24395659 100644 --- a/tests/nodes/and_i32/input_0.cairo +++ b/tests/nodes/and_i32/input_0.cairo @@ -11,31 +11,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo index 45d38f5a8..e9e10b011 100644 --- a/tests/nodes/and_i32/input_1.cairo +++ b/tests/nodes/and_i32/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo index bb81daa72..b4d327559 100644 --- a/tests/nodes/and_i32/output_0.cairo +++ b/tests/nodes/and_i32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); + data.append(1); data.append(0); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); data.append(0); - data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(0); - data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo index 761e4e147..261a9f678 100644 --- a/tests/nodes/and_i32_broadcast.cairo +++ b/tests/nodes/and_i32_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32TensorPartialEq; use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo index 2d6775e4b..8c1a32e15 100644 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ b/tests/nodes/and_i32_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo index 07dcdc4f2..f254b84b0 100644 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ b/tests/nodes/and_i32_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_i32_broadcast/output_0.cairo index f7205c752..3883dcaf3 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_i32_broadcast/output_0.cairo @@ -10,7 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); data.append(1); - data.append(0); - data.append(0); + data.append(1); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_i8.cairo index 5f03b69eb..8d0033616 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_i8.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo index 0c3934de7..5455e41fe 100644 --- a/tests/nodes/and_i8/input_0.cairo +++ b/tests/nodes/and_i8/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: true }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo index 43c7fdb27..d1795b1f2 100644 --- a/tests/nodes/and_i8/input_1.cairo +++ b/tests/nodes/and_i8/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: true }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo index f3a1ad29a..2c1e28acc 100644 --- a/tests/nodes/and_i8/output_0.cairo +++ b/tests/nodes/and_i8/output_0.cairo @@ -9,30 +9,30 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(0); data.append(1); data.append(1); - data.append(0); - data.append(0); - data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(0); - data.append(0); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); data.append(0); - data.append(1); data.append(0); data.append(1); + data.append(1); data.append(0); - data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); data.append(1); data.append(0); data.append(1); diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo index d2da45ca6..3083033b0 100644 --- a/tests/nodes/and_i8_broadcast.cairo +++ b/tests/nodes/and_i8_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo index 542c0c702..795d54aa9 100644 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ b/tests/nodes/and_i8_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo index e9b39b561..6b11828c4 100644 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ b/tests/nodes/and_i8_broadcast/input_1.cairo @@ -10,6 +10,6 @@ fn input_1() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo index f5c996719..bcaaa3bed 100644 --- a/tests/nodes/and_u32.cairo +++ b/tests/nodes/and_u32.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo index f04e9df2f..77c92fd0c 100644 --- a/tests/nodes/and_u32/input_0.cairo +++ b/tests/nodes/and_u32/input_0.cairo @@ -9,32 +9,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(5); - data.append(2); - data.append(5); - data.append(2); - data.append(4); - data.append(3); + data.append(1); data.append(1); data.append(0); + data.append(1); data.append(2); - data.append(0); data.append(4); - data.append(3); - data.append(0); - data.append(2); data.append(5); - data.append(1); - data.append(3); data.append(5); - data.append(0); data.append(5); data.append(1); - data.append(5); + data.append(1); data.append(0); data.append(2); + data.append(2); + data.append(1); data.append(0); data.append(0); + data.append(3); + data.append(1); + data.append(4); + data.append(3); + data.append(3); + data.append(2); + data.append(3); data.append(1); + data.append(2); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo index 3b2fcb9c1..a213c91a6 100644 --- a/tests/nodes/and_u32/input_1.cairo +++ b/tests/nodes/and_u32/input_1.cairo @@ -9,32 +9,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(2); - data.append(0); - data.append(3); - data.append(0); data.append(4); data.append(5); - data.append(2); - data.append(1); - data.append(3); data.append(5); + data.append(5); + data.append(4); + data.append(3); + data.append(1); data.append(0); data.append(0); + data.append(1); + data.append(3); data.append(0); - data.append(5); - data.append(2); data.append(1); - data.append(2); data.append(5); - data.append(1); - data.append(4); - data.append(1); - data.append(4); + data.append(3); + data.append(5); + data.append(5); data.append(4); + data.append(5); + data.append(3); data.append(1); - data.append(1); + data.append(0); data.append(3); + data.append(2); + data.append(0); + data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo index 576401ac8..88f761904 100644 --- a/tests/nodes/and_u32/output_0.cairo +++ b/tests/nodes/and_u32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); - data.append(0); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(0); data.append(0); - data.append(0); - data.append(0); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); data.append(0); + data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(0); + data.append(1); + data.append(1); data.append(0); data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo index cf022d7e5..301f481ed 100644 --- a/tests/nodes/and_u32_broadcast.cairo +++ b/tests/nodes/and_u32_broadcast.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo index 17f01780b..2b490c8f6 100644 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ b/tests/nodes/and_u32_broadcast/input_0.cairo @@ -8,9 +8,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); data.append(2); - data.append(2); - data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo index a11f0a16e..4e6f9c12f 100644 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ b/tests/nodes/and_u32_broadcast/input_1.cairo @@ -8,7 +8,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(5); - data.append(5); + data.append(2); + data.append(3); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo index 3883dcaf3..745afb892 100644 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ b/tests/nodes/and_u32_broadcast/output_0.cairo @@ -8,8 +8,8 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) From 8687ee92ee6277cf6d891bc91a4e5a0143802503 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 15 Nov 2023 11:43:20 +0200 Subject: [PATCH 111/127] Revert "datasource generator" This reverts commit c8dca89672de50cb0a24633b704405a9f7408489. --- tests/nodes/and_fp16x16.cairo | 6 +-- tests/nodes/and_fp16x16/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp16x16/input_1.cairo | 33 +++++++++-------- tests/nodes/and_fp16x16/output_0.cairo | 14 +++---- tests/nodes/and_fp16x16_broadcast.cairo | 6 +-- .../nodes/and_fp16x16_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp16x16_broadcast/input_1.cairo | 7 ++-- .../and_fp16x16_broadcast/output_0.cairo | 6 +-- tests/nodes/and_fp8x23.cairo | 6 +-- tests/nodes/and_fp8x23/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp8x23/input_1.cairo | 37 ++++++++++--------- tests/nodes/and_fp8x23/output_0.cairo | 8 ++-- tests/nodes/and_fp8x23_broadcast.cairo | 6 +-- .../nodes/and_fp8x23_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp8x23_broadcast/input_1.cairo | 5 ++- .../nodes/and_fp8x23_broadcast/output_0.cairo | 4 +- tests/nodes/and_i32.cairo | 6 +-- tests/nodes/and_i32/input_0.cairo | 26 ++++++------- tests/nodes/and_i32/input_1.cairo | 30 +++++++-------- tests/nodes/and_i32/output_0.cairo | 8 ++-- tests/nodes/and_i32_broadcast.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_0.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_1.cairo | 2 +- tests/nodes/and_i32_broadcast/output_0.cairo | 4 +- tests/nodes/and_i8.cairo | 8 ++-- tests/nodes/and_i8/input_0.cairo | 28 +++++++------- tests/nodes/and_i8/input_1.cairo | 28 +++++++------- tests/nodes/and_i8/output_0.cairo | 14 +++---- tests/nodes/and_i8_broadcast.cairo | 8 ++-- tests/nodes/and_i8_broadcast/input_0.cairo | 4 +- tests/nodes/and_i8_broadcast/input_1.cairo | 2 +- tests/nodes/and_u32.cairo | 4 +- tests/nodes/and_u32/input_0.cairo | 28 +++++++------- tests/nodes/and_u32/input_1.cairo | 30 +++++++-------- tests/nodes/and_u32/output_0.cairo | 10 ++--- tests/nodes/and_u32_broadcast.cairo | 4 +- tests/nodes/and_u32_broadcast/input_0.cairo | 4 +- tests/nodes/and_u32_broadcast/input_1.cairo | 4 +- tests/nodes/and_u32_broadcast/output_0.cairo | 4 +- 39 files changed, 237 insertions(+), 245 deletions(-) diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo index 4dc2ad9f6..dcd53ea37 100644 --- a/tests/nodes/and_fp16x16.cairo +++ b/tests/nodes/and_fp16x16.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo index 60341e471..b32a5f0b6 100644 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ b/tests/nodes/and_fp16x16/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,31 +12,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 65536, sign: false }); + 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: 65536, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - 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: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); 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: 0, sign: false }); + data.append(FP16x16 { mag: 131072, 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: 131072, sign: false }); - 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: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo index 0fa0aab56..2b2036fce 100644 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ b/tests/nodes/and_fp16x16/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,32 +11,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - 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: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo index f33e1f678..8a754463f 100644 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ b/tests/nodes/and_fp16x16/output_0.cairo @@ -12,29 +12,29 @@ fn output_0() -> Tensor { data.append(1); data.append(1); data.append(1); - data.append(0); - data.append(0); - data.append(1); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); - data.append(1); - data.append(1); - data.append(1); + data.append(0); + data.append(0); + data.append(0); data.append(0); data.append(1); data.append(1); - data.append(0); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo index a94e21b2c..0f0a979da 100644 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ b/tests/nodes/and_fp16x16_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo index 50048a641..2554de21d 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,9 +10,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo index a92003169..019f2f532 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,7 +10,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_fp16x16_broadcast/output_0.cairo index 486b39f3d..12e081541 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(1); data.append(0); - data.append(0); - data.append(0); - data.append(0); + data.append(1); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo index 70b96f1d5..373cfadaf 100644 --- a/tests/nodes/and_fp8x23.cairo +++ b/tests/nodes/and_fp8x23.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo index 95ee20a11..b093e4c53 100644 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ b/tests/nodes/and_fp8x23/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,31 +12,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - 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: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo index e689e6c06..0553e0019 100644 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ b/tests/nodes/and_fp8x23/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,32 +11,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + 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/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo index 6a3748b94..fa2a76b74 100644 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ b/tests/nodes/and_fp8x23/output_0.cairo @@ -10,6 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); @@ -17,24 +18,23 @@ fn output_0() -> Tensor { data.append(0); data.append(1); data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); - data.append(0); - data.append(0); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(0); data.append(1); - data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo index 12ef3a56f..ad50264f8 100644 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ b/tests/nodes/and_fp8x23_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo index bd881a8c8..f7cb3a134 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,8 +11,8 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo index ab5b373e8..35cf05e4e 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,7 +10,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_fp8x23_broadcast/output_0.cairo index f90728ddd..3883dcaf3 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); data.append(1); - data.append(0); + data.append(1); + data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_i32.cairo index c33b4b693..fd56fd1bb 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_i32.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo index f24395659..bb190dea5 100644 --- a/tests/nodes/and_i32/input_0.cairo +++ b/tests/nodes/and_i32/input_0.cairo @@ -11,31 +11,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo index e9e10b011..45d38f5a8 100644 --- a/tests/nodes/and_i32/input_1.cairo +++ b/tests/nodes/and_i32/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo index b4d327559..bb81daa72 100644 --- a/tests/nodes/and_i32/output_0.cairo +++ b/tests/nodes/and_i32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); - data.append(1); data.append(0); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); - data.append(0); - data.append(0); data.append(1); data.append(1); data.append(1); data.append(1); data.append(1); data.append(0); + data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(0); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo index 261a9f678..761e4e147 100644 --- a/tests/nodes/and_i32_broadcast.cairo +++ b/tests/nodes/and_i32_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo index 8c1a32e15..2d6775e4b 100644 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ b/tests/nodes/and_i32_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo index f254b84b0..07dcdc4f2 100644 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ b/tests/nodes/and_i32_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_i32_broadcast/output_0.cairo index 3883dcaf3..f7205c752 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_i32_broadcast/output_0.cairo @@ -10,7 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); data.append(1); - data.append(1); - data.append(1); + data.append(0); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_i8.cairo index 8d0033616..5f03b69eb 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_i8.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo index 5455e41fe..0c3934de7 100644 --- a/tests/nodes/and_i8/input_0.cairo +++ b/tests/nodes/and_i8/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: true }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo index d1795b1f2..43c7fdb27 100644 --- a/tests/nodes/and_i8/input_1.cairo +++ b/tests/nodes/and_i8/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo index 2c1e28acc..f3a1ad29a 100644 --- a/tests/nodes/and_i8/output_0.cairo +++ b/tests/nodes/and_i8/output_0.cairo @@ -9,30 +9,30 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); - data.append(1); - data.append(1); - data.append(1); data.append(0); data.append(1); data.append(1); data.append(0); - data.append(1); + data.append(0); data.append(0); data.append(1); data.append(1); data.append(1); + data.append(1); + data.append(1); data.append(0); data.append(0); data.append(1); - data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); + data.append(0); data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(0); data.append(1); diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo index 3083033b0..d2da45ca6 100644 --- a/tests/nodes/and_i8_broadcast.cairo +++ b/tests/nodes/and_i8_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo index 795d54aa9..542c0c702 100644 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ b/tests/nodes/and_i8_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo index 6b11828c4..e9b39b561 100644 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ b/tests/nodes/and_i8_broadcast/input_1.cairo @@ -10,6 +10,6 @@ fn input_1() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo index bcaaa3bed..f5c996719 100644 --- a/tests/nodes/and_u32.cairo +++ b/tests/nodes/and_u32.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo index 77c92fd0c..f04e9df2f 100644 --- a/tests/nodes/and_u32/input_0.cairo +++ b/tests/nodes/and_u32/input_0.cairo @@ -9,32 +9,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(2); - data.append(4); - data.append(5); data.append(5); - data.append(5); - data.append(1); - data.append(1); - data.append(0); data.append(2); + data.append(5); data.append(2); + data.append(4); + data.append(3); data.append(1); data.append(0); + data.append(2); data.append(0); - data.append(3); - data.append(1); data.append(4); data.append(3); - data.append(3); + data.append(0); data.append(2); + data.append(5); + data.append(1); data.append(3); + data.append(5); + data.append(0); + data.append(5); data.append(1); + data.append(5); + data.append(0); data.append(2); data.append(0); + data.append(0); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo index a213c91a6..3b2fcb9c1 100644 --- a/tests/nodes/and_u32/input_1.cairo +++ b/tests/nodes/and_u32/input_1.cairo @@ -9,32 +9,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); + data.append(2); + data.append(0); + data.append(3); + data.append(0); data.append(4); data.append(5); - data.append(5); - data.append(5); - data.append(4); - data.append(3); + data.append(2); data.append(1); + data.append(3); + data.append(5); data.append(0); data.append(0); - data.append(1); - data.append(3); data.append(0); - data.append(1); - data.append(5); - data.append(3); data.append(5); + data.append(2); + data.append(1); + data.append(2); data.append(5); + data.append(1); data.append(4); - data.append(5); - data.append(3); data.append(1); - data.append(0); + data.append(4); + data.append(4); + data.append(1); + data.append(1); data.append(3); - data.append(2); - data.append(0); - data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo index 88f761904..576401ac8 100644 --- a/tests/nodes/and_u32/output_0.cairo +++ b/tests/nodes/and_u32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); + data.append(0); data.append(1); data.append(0); data.append(1); data.append(1); data.append(1); + data.append(0); data.append(1); data.append(0); data.append(0); + data.append(0); + data.append(0); data.append(1); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); data.append(0); - data.append(0); - data.append(1); data.append(1); data.append(1); data.append(1); data.append(0); data.append(1); - data.append(1); data.append(0); - data.append(1); data.append(0); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo index 301f481ed..cf022d7e5 100644 --- a/tests/nodes/and_u32_broadcast.cairo +++ b/tests/nodes/and_u32_broadcast.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo index 2b490c8f6..17f01780b 100644 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ b/tests/nodes/and_u32_broadcast/input_0.cairo @@ -8,9 +8,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); - data.append(0); data.append(2); + data.append(2); + data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo index 4e6f9c12f..a11f0a16e 100644 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ b/tests/nodes/and_u32_broadcast/input_1.cairo @@ -8,7 +8,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(2); - data.append(3); + data.append(5); + data.append(5); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo index 745afb892..3883dcaf3 100644 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ b/tests/nodes/and_u32_broadcast/output_0.cairo @@ -8,8 +8,8 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); - data.append(0); + data.append(1); + data.append(1); data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) From d00fec9ece23c3eabfea1a3d17ba84bafbf5a3b3 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 12:18:56 +0100 Subject: [PATCH 112/127] Refactor operator with subfunctions --- .../tensor/ml/array_feature_extractor.cairo | 101 ++++++++++++------ 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 0ad7942a8..4aee41f7e 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -11,74 +11,110 @@ fn array_feature_extractor< MAG, impl TTensor: TensorTrait, impl TNumber: NumberTrait, - impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( - mut self: Tensor, indices: Tensor + self: Tensor, indices: Tensor ) -> Tensor { assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); - let input_shape: Span = self.shape; - let input_data: Span = self.data; - - if input_shape.len() == 1 { + if self.shape.len() == 1 { + return process_1D_tensor(self, indices); + } - let mut output_data = ArrayTrait::::new(); + let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); - let mut indices_counter: usize = 0; + let output_data = calculate_output_data::(self, indices, total_elements); - loop { - if indices_counter > indices.data.len() - 1 { - break; - } + return TensorTrait::new(output_shape.span(), output_data.span()); +} - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < *input_shape.at(0), 'Indices out of range'); +fn process_1D_tensor< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: Tensor, indices: Tensor +) -> Tensor { - let mut current_data_value = *input_data.at(current_indices_value); + let mut output_data = ArrayTrait::::new(); - output_data.append(current_data_value); - - indices_counter += 1; - }; + let mut indices_counter: usize = 0; + loop { + if indices_counter > indices.data.len() - 1 { + break; + } - return TensorTrait::new(indices.shape, output_data.span()); - } + let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < *self.shape.at(0), 'Indices out of range'); - let last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + let mut current_data_value = *self.data.at(current_indices_value); + output_data.append(current_data_value); + + indices_counter += 1; + }; - let mut input_shape_counter: usize = 0; + return TensorTrait::new(indices.shape, output_data.span()); +} - let mut total_elements: usize = 1; +fn calculate_output_shape< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + input_shape: Span, indices: Tensor +) -> (Array, usize) { + + let mut total_elements: usize = 1; let mut output_shape: Array = ArrayTrait::new(); + let mut input_shape_counter: usize = 0; loop { if input_shape_counter > input_shape.len() - 2 { break; } let mut current_shape_value = *input_shape.at(input_shape_counter); - output_shape.append(current_shape_value); total_elements = total_elements * current_shape_value; input_shape_counter += 1; - }; output_shape.append(indices.data.len()); + return (output_shape, total_elements); +} + + +fn calculate_output_data< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: Tensor, indices: Tensor, total_elements: usize +) -> Array { + + let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); + let mut output_data = ArrayTrait::::new(); let strides: Span = TensorTrait::stride(@self); let mut element_counter: usize = 0; - loop { if element_counter > total_elements - 1 { break; @@ -91,29 +127,24 @@ fn array_feature_extractor< }; let mut indices_counter: usize = 0; - loop { if indices_counter > indices.data.len() - 1 { break; } let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < last_tensor_axis, 'Indices out of range'); let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); - let mut current_data_value = *input_data.at(flat_index); - + let mut current_data_value = *self.data.at(flat_index); output_data.append(current_data_value); indices_counter += 1; - }; element_counter += 1; }; - return TensorTrait::new(output_shape.span(), output_data.span()); - -} \ No newline at end of file + return output_data; +} From 9a72346c56989194dc9fe70da82487515b1270f2 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 20:24:55 +0100 Subject: [PATCH 113/127] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.sequence_empty.md | 35 ++++++++++++++++++ src/operators/tensor/core.cairo | 36 ++++++++++++++++++- .../tensor/math/sequence_empty.cairo | 1 + 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_empty.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..234ff7acd 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_empty](framework/operators/tensor/tensor.sequence\_empty.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 ebc50ad77..0042cdcc4 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..6a58898ff 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_empty.md b/docs/framework/operators/tensor/tensor.sequence_empty.md new file mode 100644 index 000000000..a95f952b9 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_empty.md @@ -0,0 +1,35 @@ +# tensor.sequence_empty + +```rust + fn sequence_empty() -> Array>; +``` + +Returns an empty tensor sequence. + +## Args + +## Returns + +An empty `Array>` instance. + +## Examples + +Let's create a new empty sequence. + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, // we import the trait + Tensor, // we import the type + U32Tensor // we import the implementation. +}; + +fn sequence_empty_example() -> Array> { + let sequence = TensorTrait::sequence_empty(); + + return sequence; +} + +>>> [] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index c364213e1..4a262b919 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3586,7 +3586,41 @@ trait TensorTrait { /// fn constant_of_shape(shape: Span, value: T) -> Tensor; /// # tensor.sequence_empty - /// TODO + /// + /// ```rust + /// fn sequence_empty() -> Array>; + /// ``` + /// + /// Returns an empty tensor sequence. + /// + /// ## Args + /// + /// ## Returns + /// + /// An empty `Array>` instance. + /// + /// ## Examples + /// + /// Let's create a new empty sequence. + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{ + /// TensorTrait, // we import the trait + /// Tensor, // we import the type + /// U32Tensor // we import the implementation. + /// }; + /// + /// fn sequence_empty_example() -> Array> { + /// let sequence = TensorTrait::sequence_empty(); + /// + /// return sequence; + /// } + /// + /// >>> [] + /// ``` + /// fn sequence_empty() -> Array>; } diff --git a/src/operators/tensor/math/sequence_empty.cairo b/src/operators/tensor/math/sequence_empty.cairo index 4e32a0429..c823cabe8 100644 --- a/src/operators/tensor/math/sequence_empty.cairo +++ b/src/operators/tensor/math/sequence_empty.cairo @@ -3,6 +3,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; +/// Cf: TensorTrait::sequence_empty docstring fn sequence_empty, impl TDrop: Drop>() -> Array> { let mut sequence = ArrayTrait::new(); From 5d3400f37796a169feedf0d3b966b44623563593 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:31:13 +0100 Subject: [PATCH 114/127] Implement operator --- src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 ++++ .../tensor/implementations/tensor_fp16x16.cairo | 4 ++++ .../tensor/implementations/tensor_fp16x16wide.cairo | 4 ++++ .../tensor/implementations/tensor_fp32x32.cairo | 4 ++++ .../tensor/implementations/tensor_fp64x64.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23wide.cairo | 4 ++++ .../tensor/implementations/tensor_i32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i8.cairo | 4 ++++ .../tensor/implementations/tensor_u32.cairo | 4 ++++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/sequence_construct.cairo | 12 ++++++++++++ 13 files changed, 54 insertions(+) create mode 100644 src/operators/tensor/math/sequence_construct.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..04b6d5db1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + fn sequence_construct(tensors: Array>) -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..64997045a 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..6c529f9d1 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 68f2482e7..b4667be75 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 f764b1920..f1ef49bb6 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 6cded29b3..56c42bdd4 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 fdcdac1eb..33a8144ae 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 510731702..95b19e98d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 8017ab300..521d92fa2 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 4f2731b80..3816d8da4 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 2f3c3a2ef..72c1f4f77 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..bb4384da1 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_construct; diff --git a/src/operators/tensor/math/sequence_construct.cairo b/src/operators/tensor/math/sequence_construct.cairo new file mode 100644 index 000000000..7bf0d1a54 --- /dev/null +++ b/src/operators/tensor/math/sequence_construct.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; + + +/// Cf: TensorTrait::sequence_construct docstring +fn sequence_construct>(tensors: Array>) -> Array> { + + assert(tensors.len() >= 1, 'Input tensors must be >= 1'); + + return tensors; +} \ No newline at end of file From 195781a3329172bac794a3376b36f9e86afd39ac Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:39:31 +0100 Subject: [PATCH 115/127] Fix docstring --- src/operators/tensor/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 47aa8ba2c..220fa90b5 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -87,6 +87,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// From a2d44994f27a8307bf3a040e20b421cab27ca6b2 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:43:21 +0100 Subject: [PATCH 116/127] Fix docstring --- src/operators/tensor/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 81ab443c9..b4bb2208a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// From 00378a04186306593d021533381dcb1b12fbae00 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 17:25:09 +0100 Subject: [PATCH 117/127] Add tests --- nodegen/node/sequence_construct.py | 85 ++++++++++++++++++ tests/nodes.cairo | 5 ++ tests/nodes/sequence_construct_fp16x16.cairo | 20 +++++ .../sequence_construct_fp16x16/input_0.cairo | 76 ++++++++++++++++ .../sequence_construct_fp16x16/output_0.cairo | 76 ++++++++++++++++ tests/nodes/sequence_construct_fp8x23.cairo | 20 +++++ .../sequence_construct_fp8x23/input_0.cairo | 90 +++++++++++++++++++ .../sequence_construct_fp8x23/output_0.cairo | 90 +++++++++++++++++++ tests/nodes/sequence_construct_i32.cairo | 20 +++++ .../sequence_construct_i32/input_0.cairo | 30 +++++++ .../sequence_construct_i32/output_0.cairo | 30 +++++++ tests/nodes/sequence_construct_i8.cairo | 20 +++++ .../nodes/sequence_construct_i8/input_0.cairo | 43 +++++++++ .../sequence_construct_i8/output_0.cairo | 43 +++++++++ tests/nodes/sequence_construct_u32.cairo | 20 +++++ .../sequence_construct_u32/input_0.cairo | 90 +++++++++++++++++++ .../sequence_construct_u32/output_0.cairo | 90 +++++++++++++++++++ 17 files changed, 848 insertions(+) create mode 100644 nodegen/node/sequence_construct.py create mode 100644 tests/nodes/sequence_construct_fp16x16.cairo create mode 100644 tests/nodes/sequence_construct_fp16x16/input_0.cairo create mode 100644 tests/nodes/sequence_construct_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23/input_0.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_construct_i32.cairo create mode 100644 tests/nodes/sequence_construct_i32/input_0.cairo create mode 100644 tests/nodes/sequence_construct_i32/output_0.cairo create mode 100644 tests/nodes/sequence_construct_i8.cairo create mode 100644 tests/nodes/sequence_construct_i8/input_0.cairo create mode 100644 tests/nodes/sequence_construct_i8/output_0.cairo create mode 100644 tests/nodes/sequence_construct_u32.cairo create mode 100644 tests/nodes/sequence_construct_u32/input_0.cairo create mode 100644 tests/nodes/sequence_construct_u32/output_0.cairo diff --git a/nodegen/node/sequence_construct.py b/nodegen/node/sequence_construct.py new file mode 100644 index 000000000..7c76d1532 --- /dev/null +++ b/nodegen/node/sequence_construct.py @@ -0,0 +1,85 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Sequence_construct(RunAll): + + @staticmethod + def sequence_construct_u32(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_u32" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_i32(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_i32" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_i8(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_i8" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_fp8x23(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + name = "sequence_construct_fp8x23" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_fp16x16(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + name = "sequence_construct_fp16x16" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..1c35ea8f6 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,8 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_construct_fp16x16; +mod sequence_construct_fp8x23; +mod sequence_construct_i32; +mod sequence_construct_i8; +mod sequence_construct_u32; diff --git a/tests/nodes/sequence_construct_fp16x16.cairo b/tests/nodes/sequence_construct_fp16x16.cairo new file mode 100644 index 000000000..926a57fe2 --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_fp16x16/input_0.cairo b/tests/nodes/sequence_construct_fp16x16/input_0.cairo new file mode 100644 index 000000000..770942e5b --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16/input_0.cairo @@ -0,0 +1,76 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp16x16/output_0.cairo b/tests/nodes/sequence_construct_fp16x16/output_0.cairo new file mode 100644 index 000000000..1de556154 --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16/output_0.cairo @@ -0,0 +1,76 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp8x23.cairo b/tests/nodes/sequence_construct_fp8x23.cairo new file mode 100644 index 000000000..9a024885d --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_fp8x23/input_0.cairo b/tests/nodes/sequence_construct_fp8x23/input_0.cairo new file mode 100644 index 000000000..37fb75902 --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23/input_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp8x23/output_0.cairo b/tests/nodes/sequence_construct_fp8x23/output_0.cairo new file mode 100644 index 000000000..8bae335fe --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23/output_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i32.cairo b/tests/nodes/sequence_construct_i32.cairo new file mode 100644 index 000000000..8c4f6a19f --- /dev/null +++ b/tests/nodes/sequence_construct_i32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_i32/input_0.cairo b/tests/nodes/sequence_construct_i32/input_0.cairo new file mode 100644 index 000000000..872cd3195 --- /dev/null +++ b/tests/nodes/sequence_construct_i32/input_0.cairo @@ -0,0 +1,30 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i32/output_0.cairo b/tests/nodes/sequence_construct_i32/output_0.cairo new file mode 100644 index 000000000..4f246f2d1 --- /dev/null +++ b/tests/nodes/sequence_construct_i32/output_0.cairo @@ -0,0 +1,30 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i8.cairo b/tests/nodes/sequence_construct_i8.cairo new file mode 100644 index 000000000..0c0dda805 --- /dev/null +++ b/tests/nodes/sequence_construct_i8.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_i8/input_0.cairo b/tests/nodes/sequence_construct_i8/input_0.cairo new file mode 100644 index 000000000..b66c72889 --- /dev/null +++ b/tests/nodes/sequence_construct_i8/input_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i8/output_0.cairo b/tests/nodes/sequence_construct_i8/output_0.cairo new file mode 100644 index 000000000..e048ee27a --- /dev/null +++ b/tests/nodes/sequence_construct_i8/output_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_u32.cairo b/tests/nodes/sequence_construct_u32.cairo new file mode 100644 index 000000000..9301350d7 --- /dev/null +++ b/tests/nodes/sequence_construct_u32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_u32/input_0.cairo b/tests/nodes/sequence_construct_u32/input_0.cairo new file mode 100644 index 000000000..6fa9b512b --- /dev/null +++ b/tests/nodes/sequence_construct_u32/input_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_u32/output_0.cairo b/tests/nodes/sequence_construct_u32/output_0.cairo new file mode 100644 index 000000000..78e4ce013 --- /dev/null +++ b/tests/nodes/sequence_construct_u32/output_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From 8a1671a14e8e3d733ae1e4e78352cc17ba660d25 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 19:56:10 +0100 Subject: [PATCH 118/127] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.sequence_construct.md | 35 ++++++++++++++++++ src/operators/tensor/core.cairo | 37 +++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_construct.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..a01af8f4e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_construct](framework/operators/tensor/tensor.sequence\_construct.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 ebc50ad77..9889027a8 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceConstruct](operators/tensor/tensor.sequence\_construct.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..01ba367bd 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_construct`](tensor.sequence\_construct.md) | Constructs a tensor sequence containing the input tensors. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_construct.md b/docs/framework/operators/tensor/tensor.sequence_construct.md new file mode 100644 index 000000000..fea30780d --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_construct.md @@ -0,0 +1,35 @@ +## tensor.sequence_construct + +```rust + fn sequence_construct(tensors: Array>) -> Array>; +``` + +Constructs a tensor sequence containing the input tensors. + +## Args + +* `tensors`(`Array>`) - The array of input tensors. + +## Panics + +* Panics if input tensor array is empty. + +## Returns + +A tensor sequence `Array>` containing the input tensors. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn sequence_construct_example() -> Array> { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + return result; +} +>>> [[0, 1, 2, 3], [4, 5, 6, 7]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 04b6d5db1..feddd2267 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,42 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.sequence_construct + /// + /// ```rust + /// fn sequence_construct(tensors: Array>) -> Array>; + /// ``` + /// + /// Constructs a tensor sequence containing the input tensors. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The array of input tensors. + /// + /// ## Panics + /// + /// * Panics if input tensor array is empty. + /// + /// ## Returns + /// + /// A tensor sequence `Array>` containing the input tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn sequence_construct_example() -> Array> { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [4, 5, 6, 7]] + /// ``` + /// fn sequence_construct(tensors: Array>) -> Array>; } From 0bb3c460628abaa426110d0073584b52e2894c00 Mon Sep 17 00:00:00 2001 From: Dincer Guner Date: Thu, 16 Nov 2023 02:41:44 +0300 Subject: [PATCH 119/127] implement reduce_min --- Scarb.toml | 1 + docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.reduce_min.md | 42 +++ nodegen/node/reduce_min.py | 288 ++++++++++++++++++ src/operators/tensor/core.cairo | 45 +++ src/operators/tensor/helpers.cairo | 24 ++ .../tensor/implementations/tensor_bool.cairo | 9 + .../implementations/tensor_fp16x16.cairo | 9 + .../implementations/tensor_fp16x16wide.cairo | 9 + .../implementations/tensor_fp32x32.cairo | 9 + .../implementations/tensor_fp64x64.cairo | 9 + .../implementations/tensor_fp8x23.cairo | 9 + .../implementations/tensor_fp8x23wide.cairo | 9 + .../tensor/implementations/tensor_i32.cairo | 9 + .../tensor/implementations/tensor_i8.cairo | 9 + .../tensor/implementations/tensor_u32.cairo | 9 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/reduce_min.cairo | 189 ++++++++++++ tests/nodes.cairo | 20 ++ tests/nodes/reduce_min_fp16x16_1D.cairo | 20 ++ .../nodes/reduce_min_fp16x16_1D/input_0.cairo | 15 + .../reduce_min_fp16x16_1D/output_0.cairo | 13 + .../nodes/reduce_min_fp16x16_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_min_fp16x16_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_min_fp16x16_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_min_fp8x23_1D.cairo | 20 ++ .../nodes/reduce_min_fp8x23_1D/input_0.cairo | 15 + .../nodes/reduce_min_fp8x23_1D/output_0.cairo | 13 + tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo | 20 ++ .../reduce_min_fp8x23_2D_axis_1/input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_min_fp8x23_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../nodes/reduce_min_fp8x23_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_min_i32_1D.cairo | 20 ++ tests/nodes/reduce_min_i32_1D/input_0.cairo | 15 + tests/nodes/reduce_min_i32_1D/output_0.cairo | 13 + tests/nodes/reduce_min_i32_2D_axis_1.cairo | 20 ++ .../reduce_min_i32_2D_axis_1/input_0.cairo | 17 ++ .../reduce_min_i32_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_min_i32_2D_default.cairo | 20 ++ .../reduce_min_i32_2D_default/input_0.cairo | 17 ++ .../reduce_min_i32_2D_default/output_0.cairo | 14 + tests/nodes/reduce_min_i32_2D_keepdims.cairo | 20 ++ .../reduce_min_i32_2D_keepdims/input_0.cairo | 17 ++ .../reduce_min_i32_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_min_i8_1D.cairo | 20 ++ tests/nodes/reduce_min_i8_1D/input_0.cairo | 15 + tests/nodes/reduce_min_i8_1D/output_0.cairo | 13 + tests/nodes/reduce_min_i8_2D_axis_1.cairo | 20 ++ .../reduce_min_i8_2D_axis_1/input_0.cairo | 17 ++ .../reduce_min_i8_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_min_i8_2D_default.cairo | 20 ++ .../reduce_min_i8_2D_default/input_0.cairo | 17 ++ .../reduce_min_i8_2D_default/output_0.cairo | 14 + tests/nodes/reduce_min_i8_2D_keepdims.cairo | 20 ++ .../reduce_min_i8_2D_keepdims/input_0.cairo | 17 ++ .../reduce_min_i8_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_min_u32_1D.cairo | 20 ++ tests/nodes/reduce_min_u32_1D/input_0.cairo | 14 + tests/nodes/reduce_min_u32_1D/output_0.cairo | 12 + tests/nodes/reduce_min_u32_2D_axis_1.cairo | 20 ++ .../reduce_min_u32_2D_axis_1/input_0.cairo | 16 + .../reduce_min_u32_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_min_u32_2D_default.cairo | 20 ++ .../reduce_min_u32_2D_default/input_0.cairo | 16 + .../reduce_min_u32_2D_default/output_0.cairo | 13 + tests/nodes/reduce_min_u32_2D_keepdims.cairo | 20 ++ .../reduce_min_u32_2D_keepdims/input_0.cairo | 16 + .../reduce_min_u32_2D_keepdims/output_0.cairo | 11 + 80 files changed, 1694 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.reduce_min.md create mode 100644 nodegen/node/reduce_min.py create mode 100644 src/operators/tensor/math/reduce_min.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_1D.cairo create mode 100644 tests/nodes/reduce_min_i32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_1D.cairo create mode 100644 tests/nodes/reduce_min_i8_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_1D.cairo create mode 100644 tests/nodes/reduce_min_u32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo diff --git a/Scarb.toml b/Scarb.toml index b05876e7b..bcbb9f9c1 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,6 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion" [dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } +alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" } [scripts] diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..b45341d37 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.reduce\_min](framework/operators/tensor/tensor.reduce\_min.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..5da2c1e51 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.reduce_min.md b/docs/framework/operators/tensor/tensor.reduce_min.md new file mode 100644 index 000000000..611324be3 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_min.md @@ -0,0 +1,42 @@ +## tensor.reduce_min + +```rust + fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; +``` + +Computes the min of the input tensor's elements along the provided axes. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. +* `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. +* `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axes reduced by minimum of its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_min_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_mean` function as follows. + return tensor.reduce_min(axes: array![1].span(), + keepdims: Option::None(()), + noop_with_empty_axes: Option::None(())); +} +>>> [[0,1],[4,5]] +``` diff --git a/nodegen/node/reduce_min.py b/nodegen/node/reduce_min.py new file mode 100644 index 000000000..b9d27eeaa --- /dev/null +++ b/nodegen/node/reduce_min.py @@ -0,0 +1,288 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Reduce_min(RunAll): + @staticmethod + def reduce_min_u32(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.uint32) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_i32(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int32) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_i8(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int8) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_fp8x23(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + 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 = "reduce_min_fp8x23_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + 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 = "reduce_min_fp8x23_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False) + + 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 = "reduce_min_fp8x23_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True) + + 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 = "reduce_min_fp8x23_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_fp16x16(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + 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 = "reduce_min_fp16x16_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + 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 = "reduce_min_fp16x16_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False) + + 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 = "reduce_min_fp16x16_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True) + + 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 = "reduce_min_fp16x16_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_min_1D() + reduce_min_2D() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..e9ae9d9f4 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,50 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.reduce_min + /// + /// ```rust + /// fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the min of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by minimum of its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_min_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_min(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[0,1],[4,5]] + /// ``` + /// + fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 0aad721d7..6b65eb736 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -317,3 +317,27 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. +fn get_all_axes(shape: Span) -> Span{ + let mut ret: Array = ArrayTrait::new(); + let mut i: usize = 0; + let stop_i = shape.len() - 1; + loop { + ret.append(i); + if i == stop_i { + break (); + } + i += 1; + }; + ret.span() +} \ No newline at end of file diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..595389e76 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,15 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..9b014178c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,15 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 68f2482e7..4bf9a335a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,15 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 f764b1920..62abbaa81 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,15 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 6cded29b3..42fc24636 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,15 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 fdcdac1eb..6bd8aadab 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,15 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 510731702..0af5e926b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,15 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 8017ab300..5ea4d37cd 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,15 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 4f2731b80..c6bdb6ff4 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,15 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 2f3c3a2ef..a0af0c021 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,15 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..9fd72ba9e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod reduce_min; \ No newline at end of file diff --git a/src/operators/tensor/math/reduce_min.cairo b/src/operators/tensor/math/reduce_min.cairo new file mode 100644 index 000000000..7299d9384 --- /dev/null +++ b/src/operators/tensor/math/reduce_min.cairo @@ -0,0 +1,189 @@ +use core::option::OptionTrait; +use core::traits::TryInto; +use core::traits::Into; + +use array::ArrayTrait; +use array::SpanTrait; + +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; + +use alexandria_sorting::bubble_sort; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + + +/// Cf: TensorTrait::reduce_min docstring +fn reduce_min< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option +) -> Tensor { + let noop_with_empty_axes = match noop_with_empty_axes { + Option::Some(noop_with_empty_axes) => noop_with_empty_axes, + Option::None(_) => { + false + }, + }; + let axes = match axes { + Option::Some(axes) => { + if(axes.len() == 0) { + get_all_axes(*self.shape) + } + else { + assert(axes.len() == axes.unique().len(), 'duplicated axis.'); + let mut axes_arr = ArrayTrait::new(); + let mut copy_axes = axes; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + axes_arr.append(*axis); + }, + Option::None(_) => { + break; + } + }; + }; + let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); + sorted_axes + } + }, + Option::None(_) => { + if (noop_with_empty_axes == true) { + return *self; + } + get_all_axes(*self.shape) + }, + }; + let keepdims = match keepdims { + Option::Some(keepdims) => keepdims, + Option::None(_) => { + true + }, + }; + + let mut axis_c = 0; + let mut copy_axes = axes; + let mut shape = *self.shape; + let mut data = *self.data; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + if (shape.len() == 1) { + let current_min = accumulate_min::(data, shape, shape, 0); + shape = array![].span(); + data = array![current_min].span(); + break(); + } + let mut temp_data = ArrayTrait::new(); + let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let data_len = len_from_shape(temp_shape); + let mut index: usize = 0; + loop { + let indices = unravel_index(index, temp_shape); + let current_min = accumulate_min::(data, shape, indices, *axis-axis_c); + + temp_data.append(current_min); + + index += 1; + if index == data_len { + break (); + }; + }; + shape = temp_shape; + data = temp_data.span(); + axis_c += 1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut axes_copy = axes; + if keepdims == true { + shape = *self.shape; + loop { + match axes_copy.pop_front() { + Option::Some(axis) => { + shape = reduce_output_shape(shape, *axis, true); + }, + Option::None(_) => { + break; + } + }; + }; + return TensorTrait::::new(shape, data); + } else { + return TensorTrait::::new(shape, data); + } +} + +/// Helper function that accumulates the minimum of elements along a specific axis. +/// +/// # Arguments +/// * `input_data` - The input's data. +/// * `input_shape` - The input's shape. +/// * `output_indices` - A span of output indices. +/// * `axis` - The axis along which to accumulate the minimum. +/// +/// # Panics +/// * Panics if gas limit is exceeded during execution. +/// +/// # Returns +/// * A value representing the accumulated minimum along the specified axis. +fn accumulate_min< + T, + MAG, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut input_data: Span, input_shape: Span, output_indices: Span, axis: usize +) -> T { + let axis_len = *(input_shape)[axis]; + let mut min: T = NumberTrait::max_value(); + + let mut axis_index = 0; + + if (input_shape).len() > 1 { + loop { + if axis_index == axis_len { + break (); + } + + let input_indices = combine_indices(output_indices, axis_index, axis); + let input_index = ravel_index(input_shape, input_indices); + let ele = *(input_data)[input_index]; + if (ele < min) { + min = ele; + } + + axis_index += 1; + }; + } else { + loop { + match input_data.pop_front() { + Option::Some(item) => { + if (*item < min) { + min = *item; + } + }, + Option::None(_) => { break; } + }; + }; + } + return min; +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..9ca9f8af1 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,23 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_min_fp16x16_1D; +mod reduce_min_fp16x16_2D_default; +mod reduce_min_fp16x16_2D_keepdims; +mod reduce_min_fp16x16_2D_axis_1; +mod reduce_min_fp8x23_1D; +mod reduce_min_fp8x23_2D_default; +mod reduce_min_fp8x23_2D_keepdims; +mod reduce_min_fp8x23_2D_axis_1; +mod reduce_min_i32_1D; +mod reduce_min_i32_2D_default; +mod reduce_min_i32_2D_keepdims; +mod reduce_min_i32_2D_axis_1; +mod reduce_min_i8_1D; +mod reduce_min_i8_2D_default; +mod reduce_min_i8_2D_keepdims; +mod reduce_min_i8_2D_axis_1; +mod reduce_min_u32_1D; +mod reduce_min_u32_2D_default; +mod reduce_min_u32_2D_keepdims; +mod reduce_min_u32_2D_axis_1; diff --git a/tests/nodes/reduce_min_fp16x16_1D.cairo b/tests/nodes/reduce_min_fp16x16_1D.cairo new file mode 100644 index 000000000..2fe04eab0 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo new file mode 100644 index 000000000..4ce1ac478 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo new file mode 100644 index 000000000..b6702d88e --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo new file mode 100644 index 000000000..c2b02de4f --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..3a7987ad7 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default.cairo b/tests/nodes/reduce_min_fp16x16_2D_default.cairo new file mode 100644 index 000000000..e09a43e6b --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo new file mode 100644 index 000000000..e0814d34d --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo new file mode 100644 index 000000000..f5c70c06b --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..2f6936ccb --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_1D.cairo b/tests/nodes/reduce_min_fp8x23_1D.cairo new file mode 100644 index 000000000..362f99aca --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo new file mode 100644 index 000000000..e0b0864ea --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo new file mode 100644 index 000000000..cc23ecd7d --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..5379c89de --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default.cairo b/tests/nodes/reduce_min_fp8x23_2D_default.cairo new file mode 100644 index 000000000..f4440ca3b --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo new file mode 100644 index 000000000..4bbff30a2 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo new file mode 100644 index 000000000..0164304a4 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..a1e9688f6 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_1D.cairo b/tests/nodes/reduce_min_i32_1D.cairo new file mode 100644 index 000000000..b4ef5b675 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_1D/input_0.cairo b/tests/nodes/reduce_min_i32_1D/input_0.cairo new file mode 100644 index 000000000..0f01c1e62 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D/input_0.cairo @@ -0,0 +1,15 @@ +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(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_1D/output_0.cairo b/tests/nodes/reduce_min_i32_1D/output_0.cairo new file mode 100644 index 000000000..cc24fe978 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D/output_0.cairo @@ -0,0 +1,13 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1.cairo b/tests/nodes/reduce_min_i32_2D_axis_1.cairo new file mode 100644 index 000000000..18aac7c13 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..33f9f46e3 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_default.cairo b/tests/nodes/reduce_min_i32_2D_default.cairo new file mode 100644 index 000000000..5f6673bb4 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_default/input_0.cairo b/tests/nodes/reduce_min_i32_2D_default/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_default/output_0.cairo b/tests/nodes/reduce_min_i32_2D_default/output_0.cairo new file mode 100644 index 000000000..e8178c3ce --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims.cairo b/tests/nodes/reduce_min_i32_2D_keepdims.cairo new file mode 100644 index 000000000..680c38f7b --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims/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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..905606cf2 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_1D.cairo b/tests/nodes/reduce_min_i8_1D.cairo new file mode 100644 index 000000000..a10609e44 --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_1D/input_0.cairo b/tests/nodes/reduce_min_i8_1D/input_0.cairo new file mode 100644 index 000000000..1d76655fb --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_1D/output_0.cairo b/tests/nodes/reduce_min_i8_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1.cairo b/tests/nodes/reduce_min_i8_2D_axis_1.cairo new file mode 100644 index 000000000..afc054a84 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..9689a7aa4 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_default.cairo b/tests/nodes/reduce_min_i8_2D_default.cairo new file mode 100644 index 000000000..ef9103279 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_default/input_0.cairo b/tests/nodes/reduce_min_i8_2D_default/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_default/output_0.cairo b/tests/nodes/reduce_min_i8_2D_default/output_0.cairo new file mode 100644 index 000000000..4bbff30a2 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims.cairo b/tests/nodes/reduce_min_i8_2D_keepdims.cairo new file mode 100644 index 000000000..7e879c2cb --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +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: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..a1e9688f6 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_1D.cairo b/tests/nodes/reduce_min_u32_1D.cairo new file mode 100644 index 000000000..4f5051e52 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_1D/input_0.cairo b/tests/nodes/reduce_min_u32_1D/input_0.cairo new file mode 100644 index 000000000..60317db10 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D/input_0.cairo @@ -0,0 +1,14 @@ +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(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_1D/output_0.cairo b/tests/nodes/reduce_min_u32_1D/output_0.cairo new file mode 100644 index 000000000..2374279b0 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D/output_0.cairo @@ -0,0 +1,12 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1.cairo b/tests/nodes/reduce_min_u32_2D_axis_1.cairo new file mode 100644 index 000000000..d3a6e895f --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..8e871bbfd --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_default.cairo b/tests/nodes/reduce_min_u32_2D_default.cairo new file mode 100644 index 000000000..40e69e302 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_default/input_0.cairo b/tests/nodes/reduce_min_u32_2D_default/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_default/output_0.cairo b/tests/nodes/reduce_min_u32_2D_default/output_0.cairo new file mode 100644 index 000000000..962f113cb --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default/output_0.cairo @@ -0,0 +1,13 @@ +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(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims.cairo b/tests/nodes/reduce_min_u32_2D_keepdims.cairo new file mode 100644 index 000000000..f107c14f4 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims/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(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..8b3006d47 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} From 833b86e0f9e3e2245a17657afb9b8186863daeab Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 09:59:58 +0200 Subject: [PATCH 120/127] add tensor_bool implementation --- src/operators/tensor/implementations/tensor_bool.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..eba4483f7 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. From 91721138dc1df5c65fede38418524c1aa13ddb7c Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 10:41:53 +0200 Subject: [PATCH 121/127] refactor loops --- .../tensor/ml/array_feature_extractor.cairo | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 4aee41f7e..5da16fc77 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -16,9 +16,8 @@ fn array_feature_extractor< >( self: Tensor, indices: Tensor ) -> Tensor { - assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); - + if self.shape.len() == 1 { return process_1D_tensor(self, indices); } @@ -41,22 +40,21 @@ fn process_1D_tensor< >( self: Tensor, indices: Tensor ) -> Tensor { - let mut output_data = ArrayTrait::::new(); let mut indices_counter: usize = 0; - loop { - if indices_counter > indices.data.len() - 1 { - break; - } - - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < *self.shape.at(0), 'Indices out of range'); - let mut current_data_value = *self.data.at(current_indices_value); - output_data.append(current_data_value); - - indices_counter += 1; + let mut indices_values: Span = indices.data; + let self_len = *self.shape.at(0); + loop { + match indices_values.pop_front() { + Option::Some(current_indices_value) => { + assert(*current_indices_value < self_len, 'Indices out of range'); + let mut current_data_value = *self.data.at(*current_indices_value); + output_data.append(current_data_value); + }, + Option::None(_) => { break; } + }; }; return TensorTrait::new(indices.shape, output_data.span()); @@ -73,22 +71,25 @@ fn calculate_output_shape< >( input_shape: Span, indices: Tensor ) -> (Array, usize) { - let mut total_elements: usize = 1; let mut output_shape: Array = ArrayTrait::new(); + let mut input_shape_copy = input_shape; let mut input_shape_counter: usize = 0; + let breaker = input_shape.len() - 2; loop { - if input_shape_counter > input_shape.len() - 2 { - break; - } - - let mut current_shape_value = *input_shape.at(input_shape_counter); - output_shape.append(current_shape_value); - - total_elements = total_elements * current_shape_value; - - input_shape_counter += 1; + match input_shape_copy.pop_front() { + Option::Some(current_shape_value) => { + if input_shape_counter > breaker { + break; + } + output_shape.append(*current_shape_value); + total_elements = total_elements * *current_shape_value; + + input_shape_counter += 1; + }, + Option::None(_) => { break; } + }; }; output_shape.append(indices.data.len()); @@ -107,7 +108,6 @@ fn calculate_output_data< >( self: Tensor, indices: Tensor, total_elements: usize ) -> Array { - let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); let mut output_data = ArrayTrait::::new(); @@ -115,32 +115,31 @@ fn calculate_output_data< let strides: Span = TensorTrait::stride(@self); let mut element_counter: usize = 0; + let mut stride_l2 = *strides.at(strides.len() - 2); + let mut stride_l1 = *strides.at(strides.len() - 1); loop { if element_counter > total_elements - 1 { break; } let mut base_index = if strides.len() > 1 { - element_counter * (*strides.at(strides.len() - 2)) + element_counter * stride_l2 } else { - 0 + 0 }; - let mut indices_counter: usize = 0; + let mut indices_values = indices.data; loop { - if indices_counter > indices.data.len() - 1 { - break; - } - - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < last_tensor_axis, 'Indices out of range'); - - let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); - - let mut current_data_value = *self.data.at(flat_index); - output_data.append(current_data_value); - - indices_counter += 1; + match indices_values.pop_front() { + Option::Some(current_indices_value) => { + assert(*current_indices_value < last_tensor_axis, 'Indices out of range'); + let mut flat_index = base_index + *current_indices_value * (stride_l1); + + let mut current_data_value = *self.data.at(flat_index); + output_data.append(current_data_value); + }, + Option::None(_) => { break; } + }; }; element_counter += 1; From 53bb27dc015eb80dd10b69567d8160dcad7314ad Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 11:02:08 +0200 Subject: [PATCH 122/127] implement feature to tensor bool --- .../tensor/implementations/tensor_bool.cairo | 6 +++++- .../tensor/ml/array_feature_extractor.cairo | 12 ++---------- tests/nodes.cairo | 1 - 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index eba4483f7..5fa0ca992 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -8,7 +8,7 @@ use orion::operators::tensor::core::{ constant_of_shape, new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; @@ -316,6 +316,10 @@ impl BoolTensor of TensorTrait { fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 5da16fc77..25e0aac16 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -8,9 +8,7 @@ use orion::numbers::NumberTrait; /// Cf: TensorTrait::array_feature_extractor docstring fn array_feature_extractor< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -22,9 +20,9 @@ fn array_feature_extractor< return process_1D_tensor(self, indices); } - let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); + let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); - let output_data = calculate_output_data::(self, indices, total_elements); + let output_data = calculate_output_data::(self, indices, total_elements); return TensorTrait::new(output_shape.span(), output_data.span()); } @@ -32,9 +30,7 @@ fn array_feature_extractor< fn process_1D_tensor< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -63,9 +59,7 @@ fn process_1D_tensor< fn calculate_output_shape< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -100,9 +94,7 @@ fn calculate_output_shape< fn calculate_output_data< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 0f60c10aa..147a88d67 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -537,7 +537,6 @@ mod array_feature_extractor_2D_fp16x16; mod array_feature_extractor_3D_i32; mod array_feature_extractor_3D_fp8x23; mod array_feature_extractor_3D_fp16x16; -mod scatter_u32_add; mod binarizer_fp16x16; mod binarizer_fp8x23; mod tril_fp16x16; From 4719dd826159663eb853d06d388d3ccdb44bf6fd Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 12:23:13 +0200 Subject: [PATCH 123/127] Update core.cairo --- src/operators/tensor/core.cairo | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 1701feee0..9b1ffbf5d 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3822,6 +3822,43 @@ trait TensorTrait { /// ``` /// fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; + /// ## tensor.sequence_construct + /// + /// ```rust + /// fn sequence_construct(tensors: Array>) -> Array>; + /// ``` + /// + /// Constructs a tensor sequence containing the input tensors. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The array of input tensors. + /// + /// ## Panics + /// + /// * Panics if input tensor array is empty. + /// + /// ## Returns + /// + /// A tensor sequence `Array>` containing the input tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn sequence_construct_example() -> Array> { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [4, 5, 6, 7]] + /// ``` + /// + fn sequence_construct(tensors: Array>) -> Array>; } /// Cf: TensorTrait::new docstring From 0299f2be4c02394c72a5c8a472ccc184912fabf1 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 12:48:40 +0200 Subject: [PATCH 124/127] format code --- docs/framework/compatibility.md | 2 +- src/numbers.cairo | 24 +++-- src/operators.cairo | 2 +- src/operators/tensor/core.cairo | 14 ++- src/operators/tensor/helpers.cairo | 4 +- .../tensor/implementations/tensor_bool.cairo | 9 +- .../implementations/tensor_fp16x16.cairo | 10 ++- .../implementations/tensor_fp16x16wide.cairo | 16 ++-- .../implementations/tensor_fp32x32.cairo | 14 +-- .../implementations/tensor_fp64x64.cairo | 12 +-- .../implementations/tensor_fp8x23.cairo | 12 ++- .../implementations/tensor_fp8x23wide.cairo | 16 ++-- .../tensor/implementations/tensor_i32.cairo | 10 +-- .../tensor/implementations/tensor_i8.cairo | 13 ++- .../tensor/implementations/tensor_u32.cairo | 12 +-- src/operators/tensor/math/binarizer.cairo | 5 +- src/operators/tensor/math/reduce_mean.cairo | 55 +++++------- src/operators/tensor/math/reduce_min.cairo | 55 +++++------- .../tensor/math/sequence_construct.cairo | 3 +- src/operators/tensor/math/shrink.cairo | 5 +- src/operators/tensor/ml.cairo | 2 +- .../tensor/ml/array_feature_extractor.cairo | 24 +---- tests/ml.cairo | 2 +- tests/nodes.cairo | 90 +++++++++---------- .../array_feature_extractor_1D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_1D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_1D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/binarizer_fp16x16.cairo | 6 +- tests/nodes/binarizer_fp16x16/input_0.cairo | 2 +- tests/nodes/binarizer_fp16x16/output_0.cairo | 2 +- tests/nodes/binarizer_fp8x23.cairo | 6 +- tests/nodes/binarizer_fp8x23/input_0.cairo | 2 +- tests/nodes/binarizer_fp8x23/output_0.cairo | 2 +- tests/nodes/shrink_hard_fp16x16.cairo | 4 +- tests/nodes/shrink_hard_fp8x23.cairo | 4 +- tests/nodes/shrink_soft_fp16x16.cairo | 6 +- tests/nodes/shrink_soft_fp8x23.cairo | 6 +- 70 files changed, 283 insertions(+), 294 deletions(-) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 770049261..7cd555358 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -88,4 +88,4 @@ You can see below the list of current supported ONNX Operators: | [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | -Current Operators support: **76/156 (49%)** +Current Operators support: **81/156 (52%)** diff --git a/src/numbers.cairo b/src/numbers.cairo index 95573ae7a..bb781afb3 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -57,7 +57,9 @@ trait NumberTrait { fn sub(lhs: T, rhs: T) -> T; } -use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub}; +use orion::numbers::fixed_point::implementations::fp8x23::core::{ + FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub +}; use orion::numbers::fixed_point::implementations::fp8x23::math::core as core_fp8x23; use orion::numbers::fixed_point::implementations::fp8x23::math::comp as comp_fp8x23; @@ -258,7 +260,9 @@ impl FP8x23Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub}; +use orion::numbers::fixed_point::implementations::fp8x23wide::core::{ + FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub +}; use orion::numbers::fixed_point::implementations::fp8x23wide::math::core as core_fp8x23wide; use orion::numbers::fixed_point::implementations::fp8x23wide::math::comp as comp_fp8x23wide; @@ -459,7 +463,9 @@ impl FP8x23WNumber of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub}; +use orion::numbers::fixed_point::implementations::fp16x16::core::{ + FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub +}; use orion::numbers::fixed_point::implementations::fp16x16::math::core as core_fp16x16; use orion::numbers::fixed_point::implementations::fp16x16::math::comp as comp_fp16x16; @@ -660,7 +666,9 @@ impl FP16x16Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub}; +use orion::numbers::fixed_point::implementations::fp16x16wide::core::{ + FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub +}; use orion::numbers::fixed_point::implementations::fp16x16wide::math::core as core_fp16x16wide; use orion::numbers::fixed_point::implementations::fp16x16wide::math::comp as comp_fp16x16wide; @@ -861,7 +869,9 @@ impl FP16x16WNumber of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub}; +use orion::numbers::fixed_point::implementations::fp64x64::core::{ + FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub +}; use orion::numbers::fixed_point::implementations::fp64x64::core as core_fp64x64; use orion::numbers::fixed_point::implementations::fp64x64::comp as comp_fp64x64; use cubit::f128 as fp64x64; @@ -1063,7 +1073,9 @@ impl FP64x64Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub}; +use orion::numbers::fixed_point::implementations::fp32x32::core::{ + FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub +}; use orion::numbers::fixed_point::implementations::fp32x32::core as core_fp32x32; use orion::numbers::fixed_point::implementations::fp32x32::comp as comp_fp32x32; use cubit::f64 as fp32x32; diff --git a/src/operators.cairo b/src/operators.cairo index 9f8628255..1ca6cdee2 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -2,4 +2,4 @@ mod tensor; mod nn; mod ml; mod matrix; -mod vec; \ No newline at end of file +mod vec; diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 7e7c44d7d..6e7c728e3 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3734,7 +3734,12 @@ trait TensorTrait { /// >>> [[1,2],[5,6]] /// ``` /// - fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; /// # tensor.sequence_empty /// /// ```rust @@ -3903,7 +3908,12 @@ trait TensorTrait { /// >>> [[0,1],[4,5]] /// ``` /// - fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 6b65eb736..e55701dd6 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -328,7 +328,7 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. -fn get_all_axes(shape: Span) -> Span{ +fn get_all_axes(shape: Span) -> Span { let mut ret: Array = ArrayTrait::new(); let mut i: usize = 0; let stop_i = shape.len() - 1; @@ -340,4 +340,4 @@ fn get_all_axes(shape: Span) -> Span{ i += 1; }; ret.span() -} \ No newline at end of file +} diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d4ec7d2ee..d24d9a88b 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -315,15 +315,15 @@ impl BoolTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -332,7 +332,7 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } @@ -349,7 +349,6 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } - } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 889234c13..610ffba1e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -352,15 +352,17 @@ impl FP16x16Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 7d5373839..3a9873570 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -321,7 +321,9 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + fn array_feature_extractor( + self: @Tensor, indices: Tensor + ) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } @@ -340,15 +342,17 @@ impl FP16x16WTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 03a8f5e26..6b50b1074 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -337,11 +337,11 @@ impl FP32x32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -353,15 +353,17 @@ impl FP32x32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index b5b0be29d..9931dd661 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -353,15 +353,17 @@ impl FP64x64Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index c7863d82c..5d5e2e06a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -344,15 +344,15 @@ impl FP8x23Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -361,7 +361,7 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } @@ -378,8 +378,6 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - - } /// 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 5e41c45c1..8fd044343 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -305,7 +305,7 @@ impl FP8x23WTensor of TensorTrait { fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -331,15 +331,17 @@ impl FP8x23WTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -357,8 +359,6 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - - } /// 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 6aefcdf96..9c7c2dc3b 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -336,7 +336,7 @@ impl I32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } @@ -352,15 +352,15 @@ impl I32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 49ff938e2..2d8b7ab4c 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -335,10 +335,9 @@ impl I8Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - - fn binarizer(self: @Tensor, threshold: Option) -> Tensor { - panic(array!['not supported!']) + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) } fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { @@ -352,15 +351,15 @@ impl I8Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index ed885913e..d5ec1bd4b 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -306,11 +306,11 @@ impl U32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -322,15 +322,15 @@ impl U32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index 9b37a98ef..a75013d16 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -17,7 +17,6 @@ fn binarizer< >( mut self: Tensor, threshold: Option ) -> Tensor { - let threshold: T = if threshold.is_some() { threshold.unwrap() } else { @@ -35,9 +34,7 @@ fn binarizer< binarized_data.append(NumberTrait::zero()); } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/reduce_mean.cairo b/src/operators/tensor/math/reduce_mean.cairo index 7d64d85b5..23abf4840 100644 --- a/src/operators/tensor/math/reduce_mean.cairo +++ b/src/operators/tensor/math/reduce_mean.cairo @@ -10,7 +10,9 @@ use orion::numbers::signed_integer::integer_trait::IntegerTrait; use orion::numbers::fixed_point::core::FixedTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; -use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; +use orion::operators::tensor::helpers::{ + reduce_output_shape, len_from_shape, combine_indices, get_all_axes +}; use alexandria_sorting::bubble_sort; use alexandria_data_structures::array_ext::{SpanTraitExt}; @@ -34,27 +36,20 @@ fn reduce_mean< ) -> Tensor { let noop_with_empty_axes = match noop_with_empty_axes { Option::Some(noop_with_empty_axes) => noop_with_empty_axes, - Option::None(_) => { - false - }, + Option::None(_) => { false }, }; let axes = match axes { Option::Some(axes) => { - if(axes.len() == 0) { + if (axes.len() == 0) { get_all_axes(*self.shape) - } - else { + } else { assert(axes.len() == axes.unique().len(), 'duplicated axis.'); let mut axes_arr = ArrayTrait::new(); let mut copy_axes = axes; loop { match copy_axes.pop_front() { - Option::Some(axis) => { - axes_arr.append(*axis); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { axes_arr.append(*axis); }, + Option::None(_) => { break; } }; }; let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); @@ -70,11 +65,9 @@ fn reduce_mean< }; let keepdims = match keepdims { Option::Some(keepdims) => keepdims, - Option::None(_) => { - true - }, + Option::None(_) => { true }, }; - + let mut axis_c = 0; let mut copy_axes = axes; let mut shape = *self.shape; @@ -86,15 +79,15 @@ fn reduce_mean< let current_mean = accumulate_mean::(data, shape, shape, 0); shape = array![].span(); data = array![current_mean].span(); - break(); + break (); } let mut temp_data = ArrayTrait::new(); - let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let mut temp_shape = reduce_output_shape(shape, *axis - axis_c, false); let data_len = len_from_shape(temp_shape); let mut index: usize = 0; loop { let indices = unravel_index(index, temp_shape); - let current_mean = accumulate_mean::(data, shape, indices, *axis-axis_c); + let current_mean = accumulate_mean::(data, shape, indices, *axis - axis_c); temp_data.append(current_mean); @@ -107,23 +100,17 @@ fn reduce_mean< data = temp_data.span(); axis_c += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - + let mut axes_copy = axes; if keepdims == true { shape = *self.shape; loop { match axes_copy.pop_front() { - Option::Some(axis) => { - shape = reduce_output_shape(shape, *axis, true); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { shape = reduce_output_shape(shape, *axis, true); }, + Option::None(_) => { break; } }; }; return TensorTrait::::new(shape, data); @@ -173,20 +160,20 @@ fn accumulate_mean< let ele = *(input_data)[input_index]; acc += ele; axis_index += NumberTrait::one(); - axis_indexu32 +=1; + axis_indexu32 += 1; }; } else { loop { match input_data.pop_front() { - Option::Some(item) => { + Option::Some(item) => { acc += *item; axis_index += NumberTrait::one(); - axis_indexu32 +=1; + axis_indexu32 += 1; }, Option::None(_) => { break; } }; }; } // let axis_index: T = NumberTrait::::new(axis_index.try_into().unwrap(), false); - return acc/axis_index; + return acc / axis_index; } diff --git a/src/operators/tensor/math/reduce_min.cairo b/src/operators/tensor/math/reduce_min.cairo index 7299d9384..00568012f 100644 --- a/src/operators/tensor/math/reduce_min.cairo +++ b/src/operators/tensor/math/reduce_min.cairo @@ -9,7 +9,9 @@ use orion::numbers::signed_integer::integer_trait::IntegerTrait; use orion::numbers::fixed_point::core::FixedTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; -use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; +use orion::operators::tensor::helpers::{ + reduce_output_shape, len_from_shape, combine_indices, get_all_axes +}; use alexandria_sorting::bubble_sort; use alexandria_data_structures::array_ext::{SpanTraitExt}; @@ -32,27 +34,20 @@ fn reduce_min< ) -> Tensor { let noop_with_empty_axes = match noop_with_empty_axes { Option::Some(noop_with_empty_axes) => noop_with_empty_axes, - Option::None(_) => { - false - }, + Option::None(_) => { false }, }; let axes = match axes { Option::Some(axes) => { - if(axes.len() == 0) { + if (axes.len() == 0) { get_all_axes(*self.shape) - } - else { + } else { assert(axes.len() == axes.unique().len(), 'duplicated axis.'); let mut axes_arr = ArrayTrait::new(); let mut copy_axes = axes; loop { match copy_axes.pop_front() { - Option::Some(axis) => { - axes_arr.append(*axis); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { axes_arr.append(*axis); }, + Option::None(_) => { break; } }; }; let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); @@ -68,11 +63,9 @@ fn reduce_min< }; let keepdims = match keepdims { Option::Some(keepdims) => keepdims, - Option::None(_) => { - true - }, + Option::None(_) => { true }, }; - + let mut axis_c = 0; let mut copy_axes = axes; let mut shape = *self.shape; @@ -84,15 +77,15 @@ fn reduce_min< let current_min = accumulate_min::(data, shape, shape, 0); shape = array![].span(); data = array![current_min].span(); - break(); + break (); } let mut temp_data = ArrayTrait::new(); - let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let mut temp_shape = reduce_output_shape(shape, *axis - axis_c, false); let data_len = len_from_shape(temp_shape); let mut index: usize = 0; loop { let indices = unravel_index(index, temp_shape); - let current_min = accumulate_min::(data, shape, indices, *axis-axis_c); + let current_min = accumulate_min::(data, shape, indices, *axis - axis_c); temp_data.append(current_min); @@ -105,23 +98,17 @@ fn reduce_min< data = temp_data.span(); axis_c += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - + let mut axes_copy = axes; if keepdims == true { shape = *self.shape; loop { match axes_copy.pop_front() { - Option::Some(axis) => { - shape = reduce_output_shape(shape, *axis, true); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { shape = reduce_output_shape(shape, *axis, true); }, + Option::None(_) => { break; } }; }; return TensorTrait::::new(shape, data); @@ -176,11 +163,9 @@ fn accumulate_min< } else { loop { match input_data.pop_front() { - Option::Some(item) => { - if (*item < min) { - min = *item; - } - }, + Option::Some(item) => { if (*item < min) { + min = *item; + } }, Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/sequence_construct.cairo b/src/operators/tensor/math/sequence_construct.cairo index 7bf0d1a54..dd8ff3101 100644 --- a/src/operators/tensor/math/sequence_construct.cairo +++ b/src/operators/tensor/math/sequence_construct.cairo @@ -5,8 +5,7 @@ use orion::operators::tensor::{TensorTrait, Tensor}; /// Cf: TensorTrait::sequence_construct docstring fn sequence_construct>(tensors: Array>) -> Array> { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); return tensors; -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo index 90c010f85..194fc18dc 100644 --- a/src/operators/tensor/math/shrink.cairo +++ b/src/operators/tensor/math/shrink.cairo @@ -17,7 +17,6 @@ fn shrink< >( mut self: Tensor, bias: Option, lambd: Option ) -> Tensor { - let bias: T = if bias.is_some() { bias.unwrap() } else { @@ -45,9 +44,7 @@ fn shrink< data_result.append(NumberTrait::zero()); } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/ml.cairo b/src/operators/tensor/ml.cairo index e9c3faa09..f47deeffd 100644 --- a/src/operators/tensor/ml.cairo +++ b/src/operators/tensor/ml.cairo @@ -1 +1 @@ -mod array_feature_extractor; \ No newline at end of file +mod array_feature_extractor; diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 25e0aac16..240a69b43 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -7,10 +7,7 @@ use orion::numbers::NumberTrait; /// Cf: TensorTrait::array_feature_extractor docstring fn array_feature_extractor< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( self: Tensor, indices: Tensor ) -> Tensor { @@ -28,12 +25,7 @@ fn array_feature_extractor< } -fn process_1D_tensor< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop ->( +fn process_1D_tensor, impl TCopy: Copy, impl TDrop: Drop>( self: Tensor, indices: Tensor ) -> Tensor { let mut output_data = ArrayTrait::::new(); @@ -58,10 +50,7 @@ fn process_1D_tensor< fn calculate_output_shape< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( input_shape: Span, indices: Tensor ) -> (Array, usize) { @@ -92,12 +81,7 @@ fn calculate_output_shape< } -fn calculate_output_data< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop ->( +fn calculate_output_data, impl TCopy: Copy, impl TDrop: Drop>( self: Tensor, indices: Tensor, total_elements: usize ) -> Array { let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); diff --git a/tests/ml.cairo b/tests/ml.cairo index f75954665..411cc99b2 100644 --- a/tests/ml.cairo +++ b/tests/ml.cairo @@ -1,2 +1,2 @@ mod tree_regressor; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5bf6366d6..5270a5048 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -494,51 +494,51 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_1D_i32; -mod array_feature_extractor_1D_fp8x23; -mod array_feature_extractor_1D_fp16x16; -mod array_feature_extractor_2D_i32; -mod array_feature_extractor_2D_fp8x23; -mod array_feature_extractor_2D_fp16x16; -mod array_feature_extractor_3D_i32; -mod array_feature_extractor_3D_fp8x23; -mod array_feature_extractor_3D_fp16x16; -mod binarizer_fp16x16; -mod binarizer_fp8x23; +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; +mod binarizer_fp16x16; +mod binarizer_fp8x23; mod tril_fp16x16; mod tril_fp16x16_neg; mod tril_fp16x16_one_row; diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo index a24571c9d..0dd7c5316 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo index e9eefbabf..f9acf6ef4 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo index 2472bf84b..85c53d04f 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo @@ -12,4 +12,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo index 72ccfa9fc..324db7177 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo index e3f37db08..bd7c3dccd 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo index 26340a8b6..da4e8d825 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo @@ -12,4 +12,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32.cairo b/tests/nodes/array_feature_extractor_1D_i32.cairo index 0d8dde9d8..15b7d39c3 100644 --- a/tests/nodes/array_feature_extractor_1D_i32.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo index 761aa81c4..780a73780 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo index b5a56f1ff..e503408e9 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo @@ -11,4 +11,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo index 7023d621a..94cfa0009 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo index 4742c7e7d..f9dd3a2ed 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo index c2ebb541a..239df58be 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo index 06608774f..923418064 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo index 8b577178a..a00ffaaa6 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo index 91bd19d12..c782ae873 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32.cairo b/tests/nodes/array_feature_extractor_2D_i32.cairo index 29368f5f3..ccbeb10dc 100644 --- a/tests/nodes/array_feature_extractor_2D_i32.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo index c7b027450..8ebfdd9d7 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo index c9d6cedf5..944dd7e3b 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo index eab071c49..eb9efd824 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo index 559a6ec9b..5424be3ef 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo @@ -36,4 +36,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo index dc974161d..30519ac61 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo @@ -24,4 +24,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo index 8315e0caf..07dbf6383 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo index b74c32e6e..ad209c9a9 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo @@ -36,4 +36,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo index 093210ec7..59aac2329 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo @@ -24,4 +24,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32.cairo b/tests/nodes/array_feature_extractor_3D_i32.cairo index e8688a4e9..092b5ff9d 100644 --- a/tests/nodes/array_feature_extractor_3D_i32.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo index e53f9a696..6c37cf5af 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo @@ -35,4 +35,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo index 56e50441e..6e25fdfd9 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo @@ -23,4 +23,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 87306959b..d23d27c3e 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,4 +18,4 @@ fn test_binarizer_fp16x16() { let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false))); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo index 597143f74..9fac068e6 100644 --- a/tests/nodes/binarizer_fp16x16/input_0.cairo +++ b/tests/nodes/binarizer_fp16x16/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 53852, sign: true }); data.append(FP16x16 { mag: 93775, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo index b4bbbde98..d3f54efb4 100644 --- a/tests/nodes/binarizer_fp16x16/output_0.cairo +++ b/tests/nodes/binarizer_fp16x16/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 91b481fa3..c5d1190dd 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,4 +18,4 @@ fn test_binarizer_fp8x23() { let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false))); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo index e11d8a9f4..680882f20 100644 --- a/tests/nodes/binarizer_fp8x23/input_0.cairo +++ b/tests/nodes/binarizer_fp8x23/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 21216642, sign: true }); data.append(FP8x23 { mag: 2018862, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo index 8ec654745..a6c5e5513 100644 --- a/tests/nodes/binarizer_fp8x23/output_0.cairo +++ b/tests/nodes/binarizer_fp8x23/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/shrink_hard_fp16x16.cairo b/tests/nodes/shrink_hard_fp16x16.cairo index 2272fd758..bd5635a2f 100644 --- a/tests/nodes/shrink_hard_fp16x16.cairo +++ b/tests/nodes/shrink_hard_fp16x16.cairo @@ -15,7 +15,9 @@ fn test_shrink_hard_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false))); + let y = TensorTrait::shrink( + input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_hard_fp8x23.cairo b/tests/nodes/shrink_hard_fp8x23.cairo index d9294c755..45b743bbd 100644 --- a/tests/nodes/shrink_hard_fp8x23.cairo +++ b/tests/nodes/shrink_hard_fp8x23.cairo @@ -15,7 +15,9 @@ fn test_shrink_hard_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false))); + let y = TensorTrait::shrink( + input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_soft_fp16x16.cairo b/tests/nodes/shrink_soft_fp16x16.cairo index e5a8ef066..5c90ef120 100644 --- a/tests/nodes/shrink_soft_fp16x16.cairo +++ b/tests/nodes/shrink_soft_fp16x16.cairo @@ -15,7 +15,11 @@ fn test_shrink_soft_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false))); + let y = TensorTrait::shrink( + input_0, + Option::Some(FixedTrait::new(65536, false)), + Option::Some(FixedTrait::new(65536, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_soft_fp8x23.cairo b/tests/nodes/shrink_soft_fp8x23.cairo index 66884de9f..3ee05b53d 100644 --- a/tests/nodes/shrink_soft_fp8x23.cairo +++ b/tests/nodes/shrink_soft_fp8x23.cairo @@ -15,7 +15,11 @@ fn test_shrink_soft_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false))); + let y = TensorTrait::shrink( + input_0, + Option::Some(FixedTrait::new(8388608, false)), + Option::Some(FixedTrait::new(8388608, false)) + ); assert_eq(y, z); } From 1f3306897ab69a97d6cc958f999724345582bb3d Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 17 Nov 2023 12:26:02 +0100 Subject: [PATCH 125/127] Fix missing argument --- nodegen/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 517954c14..a5b84efb3 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -158,7 +158,7 @@ def get_all_test_refs(dtypes: list[Dtype], trait: Trait) -> list[str]: return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: if trait == Trait.NN and dtype == Dtype.BOOL: raise Exception("NN trait does not support bool dtype") From 961f1336137a2eab166c4704a871a5ed7a1fb1a8 Mon Sep 17 00:00:00 2001 From: Raphael Doukhan Date: Mon, 20 Nov 2023 08:54:19 +0000 Subject: [PATCH 126/127] GITBOOK-40: Update models and spaces --- docs/hub/algorithms.md | 4 ++-- docs/hub/spaces.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/hub/algorithms.md b/docs/hub/algorithms.md index 138e4b535..bd54d70d9 100644 --- a/docs/hub/algorithms.md +++ b/docs/hub/algorithms.md @@ -1,7 +1,7 @@ # Models -Discover amazing ML models made by the community with Orion! +Discover amazing ML models made by the community with Orion! -
Verifiable Support Vector Machine

September 26 - 0xd3bs

Verifiable-Logistic-Regression

August 20 - Bowen

Verifiable-Linear-Regression
August 15 - Bem Baraki
MNIST Classification with Feedforward Neural Network June 8, 2023 - Raphael Doukhan
+
Tic-Tac-Toe AI AgentNovember 10 - Raphael Doukhanhttps://github.com/gizatechxyz/Orion-Hub/tree/main/gaming/tic_tac_toe
Verifiable Support Vector MachineSeptember 26 - 0xd3bshttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/verifiable_support_vector_machine
Verifiable-Logistic-RegressionAugust 20 - Bowenhttps://github.com/bowenyou/cairo-logistic-regression
Verifiable-Linear-RegressionAugust 15 - Bem Barakihttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/verifiable_linear_regression_model
MNIST Classification with Feedforward Neural NetworkJune 8, 2023 - Raphael Doukhanhttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/mnist_nn
We encourage you to contribute your own implementations and help grow this collection, benefiting the community and driving innovation in verifiable ML model inference. diff --git a/docs/hub/spaces.md b/docs/hub/spaces.md index 4c5323940..a1dcd041e 100644 --- a/docs/hub/spaces.md +++ b/docs/hub/spaces.md @@ -2,6 +2,6 @@ Discover amazing ML apps and POCs made by the community with Orion! -{% hint style="info" %} -This section is currently under development. If you're looking for ideas for POCs that can be implemented using Orion, don't hesitate to contact [Raphael](https://twitter.com/raphael\_dkhn) or [Fran](https://twitter.com/franalgaba\_). We have a bunch of exciting ideas to share! -{% endhint %} + + +
Tic Tac Toe in PixeLAWWelcome to the Tic Tac Toe game integrated into the PixeLAW world, where you can challenge an ML bot to a game of Tic Tac Toe onchain!https://github.com/OwnerOfJK/TicTacToeAgent/tree/main
From 9ceb845817af86f8d1daaed924fefe33cb058938 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 21 Nov 2023 11:56:38 +0200 Subject: [PATCH 127/127] Update orion-usage.md --- orion-usage.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/orion-usage.md b/orion-usage.md index a24a8ef7f..855254937 100644 --- a/orion-usage.md +++ b/orion-usage.md @@ -48,18 +48,27 @@ Discover ML models made by the community with Orion! | Bem Baraki | [Linear Regression](https://github.com/BemTG/Verifiable-Linear-Regression-) | | Raphael Doukhan | [MNIST MLP](https://github.com/gizatechxyz/orion_tutorials/blob/main/mnist_nn/QAT_MNIST_MLP.ipynb) | +# Spaces + +Discover amazing ML apps and POCs made by the community with Orion! + +| Author | Title | +| --------------------------------- | ------------------------------------------------------------------------------------------- | +| ownerofjk, umburloko, coostendorp | [Tic Tac Toe in PixeLAW with ML Bot](https://github.com/OwnerOfJK/TicTacToeAgent/tree/main) | + ## Hackathon Projects -| Author | Event | Title | Prizes | -| --------------------- | -------------- | -------------------------------------------------------------------------------------- | ------------------ | -| manuj-mishra | Lambda ZK week | [ZK Differential Privacy](https://github.com/manuj-mishra/zkdiffpriv) | 🏅 | -| codingnirvana | Lambda ZK week | [Cairo Convolution ](https://github.com/gizatechxyz/orion/pull/160) | | -| danilo, richie, falco | ETHGlobal | [Cairo Einsum](https://x.com/danilowhk2/status/1683138159985545216?s=20) | 🥇 (Starknet track) | -| 0xbyyou | ETHToronto | [Cairo Logistic Regression](https://x.com/gizatechxyz/status/1695016787698417770?s=20) | | +| Author | Event | Title | Prizes | +| --------------------------------- | -------------- | ------------------------------------------------------------------------------------------- | ------------------ | +| manuj-mishra | Lambda ZK week | [ZK Differential Privacy](https://github.com/manuj-mishra/zkdiffpriv) | 🏅 | +| codingnirvana | Lambda ZK week | [Cairo Convolution ](https://github.com/gizatechxyz/orion/pull/160) | | +| danilo, richie, falco | ETHGlobal | [Cairo Einsum](https://x.com/danilowhk2/status/1683138159985545216?s=20) | 🥇 (Starknet track) | +| 0xbyyou | ETHToronto | [Cairo Logistic Regression](https://x.com/gizatechxyz/status/1695016787698417770?s=20) | | +| ownerofjk, umburloko, coostendorp | ETHGlobal Ist. | [Tic Tac Toe in PixeLAW with ML Bot](https://github.com/OwnerOfJK/TicTacToeAgent/tree/main) | 🥇 (Starknet track) | ## Use Cases | Author | Title | Description | | ----------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | -| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model in fraud detection and analysis of bank transaction alerts. | +| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model in fraud detection and analysis of bank transaction alerts. |