diff --git a/docs/framework/operators/tensor/tensor.reduce_sum.md b/docs/framework/operators/tensor/tensor.reduce_sum.md index 3aa77d2ce..be4ef4029 100644 --- a/docs/framework/operators/tensor/tensor.reduce_sum.md +++ b/docs/framework/operators/tensor/tensor.reduce_sum.md @@ -1,7 +1,7 @@ ## tensor.reduce_sum ```rust - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + fn reduce_sum(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; ``` Reduces a tensor by summing its elements along a specified axis. @@ -9,16 +9,13 @@ Reduces a tensor by summing its elements along a specified axis. ## 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. +* `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 1 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. ## Returns -A new `Tensor` instance with the specified axis reduced by summing its elements. +Reduced output tensor. ## Examples @@ -33,7 +30,7 @@ fn reduce_sum_example() -> Tensor { ); // We can call `reduce_sum` function as follows. - return tensor.reduce_sum(axis: 0, keepdims: false); + return tensor.reduce_sum(axes: Option::None, keepdims: false); } >>> [[4,6],[8,10]] ``` diff --git a/nodegen/node/reduce_sum.py b/nodegen/node/reduce_sum.py index 111724001..d3f311b25 100644 --- a/nodegen/node/reduce_sum.py +++ b/nodegen/node/reduce_sum.py @@ -4,285 +4,79 @@ class Reduce_sum(RunAll): - @staticmethod - def reduce_sum_u32(): - def reduce_sum_1D(): - x = np.array([0, 1, 2,]).astype(np.uint32) - y = np.array([3]).astype(np.uint32) - - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - - name = "reduce_sum_u32_1D" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def reduce_sum_2D(): - def default(): - x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) - y = np.array([2, 4]).astype(np.uint32) - - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - - name = "reduce_sum_u32_2D_default" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def keepdims(): - x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) - y = np.array([2, 4]).astype(np.uint32).reshape(1, 2) - - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - - name = "reduce_sum_u32_2D_keepdims" - make_test( - [x], y, "input_0.reduce_sum(0, true)", name) - - def axis_1(): - x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) - y = np.array([1, 5]).astype(np.uint32) - - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - - name = "reduce_sum_u32_2D_axis_1" - make_test( - [x], y, "input_0.reduce_sum(1, false)", name) - - default() - keepdims() - axis_1() - reduce_sum_1D() - reduce_sum_2D() @staticmethod - def reduce_sum_i32(): - def reduce_sum_1D(): - x = np.array([0, 1, 2,]).astype(np.int32) - y = np.array([3]).astype(np.int32) + def reduce_sum_no_keep_dims(): + axes = np.array([1], dtype=np.uint32) + keepdims = 0 - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) + x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ + [9, 10], [11, 12]]]).astype(np.uint32) + y = np.sum(x, axis=tuple(axes.tolist()), keepdims=keepdims == 1) - name = "reduce_sum_i32_1D" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) - def reduce_sum_2D(): - def default(): - x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) - y = np.array([2, 4]).astype(np.int32) - - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) - - name = "reduce_sum_i32_2D_default" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def keepdims(): - x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) - y = np.array([2, 4]).astype(np.int32).reshape(1, 2) - - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) - - name = "reduce_sum_i32_2D_keepdims" - make_test( - [x], y, "input_0.reduce_sum(0, true)", name) - - def axis_1(): - x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) - y = np.array([1, 5]).astype(np.int32) - - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) - - name = "reduce_sum_i32_2D_axis_1" - make_test( - [x], y, "input_0.reduce_sum(1, false)", name) - - default() - keepdims() - axis_1() - reduce_sum_1D() - reduce_sum_2D() + name = "reduce_sum_no_keep_dims" + make_test( + [x], y, "input_0.reduce_sum(Option::Some(array![1].span()), Option::Some(false), Option::None)", name) @staticmethod - def reduce_sum_i8(): - def reduce_sum_1D(): - x = np.array([0, 1, 2,]).astype(np.int8) - y = np.array([3]).astype(np.int8) - - x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) - y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) - - name = "reduce_sum_i8_1D" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def reduce_sum_2D(): - def default(): - x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) - y = np.array([2, 4]).astype(np.int8) + def reduce_sum_keep_dims(): + axes = np.array([1], dtype=np.uint32) + keepdims = 1 - x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) - y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ + [9, 10], [11, 12]]]).astype(np.uint32) + y = np.sum(x, axis=tuple(axes.tolist()), keepdims=keepdims == 1) - name = "reduce_sum_i8_2D_default" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) - def keepdims(): - x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) - y = np.array([2, 4]).astype(np.int8).reshape(1, 2) - - x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) - y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) - - name = "reduce_sum_i8_2D_keepdims" - make_test( - [x], y, "input_0.reduce_sum(0, true)", name) - - def axis_1(): - x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) - y = np.array([1, 5]).astype(np.int8) - - x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) - y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) - - name = "reduce_sum_i8_2D_axis_1" - make_test( - [x], y, "input_0.reduce_sum(1, false)", name) - - default() - keepdims() - axis_1() - reduce_sum_1D() - reduce_sum_2D() + name = "reduce_sum_keep_dims" + make_test( + [x], y, "input_0.reduce_sum(Option::Some(array![1].span()), Option::Some(true), Option::None)", name) @staticmethod - def reduce_sum_fp8x23(): - def reduce_sum_1D(): - x = np.array([0, 1, 2,]).astype(np.int64) - y = np.array([3]).astype(np.int64) - - 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_sum_fp8x23_1D" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def reduce_sum_2D(): - def default(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([2, 4]).astype(np.int64) - - 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_sum_fp8x23_2D_default" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) - - def keepdims(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([2, 4]).astype(np.int64).reshape(1, 2) + def reduce_sum_default_axes_keepdims(): + keepdims = 1 - x = Tensor(Dtype.FP8x23, x.shape, to_fp( - x.flatten(), FixedImpl.FP8x23)) - y = Tensor(Dtype.FP8x23, y.shape, to_fp( - y.flatten(), FixedImpl.FP8x23)) + x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ + [9, 10], [11, 12]]]).astype(np.uint32) + y = np.sum(x, axis=None, keepdims=keepdims == 1) - name = "reduce_sum_fp8x23_2D_keepdims" - make_test( - [x], y, "input_0.reduce_sum(0, true)", name) - - def axis_1(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([1, 5]).astype(np.int64) - - 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_sum_fp8x23_2D_axis_1" - make_test( - [x], y, "input_0.reduce_sum(1, false)", name) - - default() - keepdims() - axis_1() - - reduce_sum_1D() - reduce_sum_2D() + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + name = "reduce_sum_default_axes_keepdims" + make_test( + [x], y, "input_0.reduce_sum(Option::Some(array![].span()), Option::Some(true), Option::None)", name) + @staticmethod - def reduce_sum_fp16x16(): - def reduce_sum_1D(): - x = np.array([0, 1, 2,]).astype(np.int64) - y = np.array([3]).astype(np.int64) - - 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_sum_fp16x16_1D" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) + def reduce_sum_negative_axes_keepdims(): + axes = np.array([-2], dtype=np.int64) + keepdims = 1 - def reduce_sum_2D(): - def default(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([2, 4]).astype(np.int64) + x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ + [9, 10], [11, 12]]]).astype(np.uint32) + y = np.sum(x, axis=tuple(axes.tolist()), keepdims=keepdims == 1) - x = Tensor(Dtype.FP16x16, x.shape, to_fp( - x.flatten(), FixedImpl.FP16x16)) - y = Tensor(Dtype.FP16x16, y.shape, to_fp( - y.flatten(), FixedImpl.FP16x16)) + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) - name = "reduce_sum_fp16x16_2D_default" - make_test( - [x], y, "input_0.reduce_sum(0, false)", name) + name = "reduce_sum_negative_axes_keepdims" + make_test( + [x], y, "input_0.reduce_sum(Option::Some(array![-2].span()), Option::Some(true), Option::None)", name) - def keepdims(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([2, 4]).astype(np.int64).reshape(1, 2) - - 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_sum_fp16x16_2D_keepdims" - make_test( - [x], y, "input_0.reduce_sum(0, true)", name) - - def axis_1(): - x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) - y = np.array([1, 5]).astype(np.int64) - - 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_sum_fp16x16_2D_axis_1" - make_test( - [x], y, "input_0.reduce_sum(1, false)", name) + @staticmethod + def reduce_sum_empty_axes_input_noop(): + x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ + [9, 10], [11, 12]]]).astype(np.uint32) + y = np.array(x) - default() - keepdims() - axis_1() + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) - reduce_sum_1D() - reduce_sum_2D() + name = "reduce_sum_empty_axes_input_noop" + make_test( + [x], y, "input_0.reduce_sum(Option::None, Option::Some(true), Option::Some(true))", name) \ No newline at end of file diff --git a/src/operators/nn/functional/logsoftmax.cairo b/src/operators/nn/functional/logsoftmax.cairo index fdf89c43d..82283844f 100644 --- a/src/operators/nn/functional/logsoftmax.cairo +++ b/src/operators/nn/functional/logsoftmax.cairo @@ -10,7 +10,12 @@ fn logsoftmax< z: @Tensor, axis: usize ) -> Tensor { let exp_tensor = z.exp(); - let sum = exp_tensor.reduce_sum(axis, true); + let sum = exp_tensor + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(true), + Option::Some(false) + ); let softmax = exp_tensor / sum; let logsoftmax = softmax.log(); @@ -38,7 +43,12 @@ fn logsoftmaxWide< z: @Tensor, axis: usize ) -> Tensor { let exp_tensor: Tensor = exp_upcast(*z); - let sum = exp_tensor.reduce_sum(axis, true); + let sum = exp_tensor + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(true), + Option::Some(false) + ); let softmax = div_downcast(@exp_tensor, @sum); softmax.log() diff --git a/src/operators/nn/functional/softmax.cairo b/src/operators/nn/functional/softmax.cairo index 10602bde7..ba83438a4 100644 --- a/src/operators/nn/functional/softmax.cairo +++ b/src/operators/nn/functional/softmax.cairo @@ -13,7 +13,12 @@ fn softmax< z: @Tensor, axis: usize ) -> Tensor { let exp_tensor = z.exp(); - let sum = exp_tensor.reduce_sum(axis, true); + let sum = exp_tensor + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(true), + Option::Some(false) + ); exp_tensor / sum } @@ -39,7 +44,12 @@ fn softmaxWide< z: @Tensor, axis: usize ) -> Tensor { let exp_tensor: Tensor = exp_upcast(*z); - let sum = exp_tensor.reduce_sum(axis, true); + let sum = exp_tensor + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(true), + Option::Some(false) + ); div_downcast(@exp_tensor, @sum) } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 2348bff86..70f551ec8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -644,7 +644,7 @@ trait TensorTrait { /// ## tensor.reduce_sum /// /// ```rust - /// fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// fn reduce_sum(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; /// ``` /// /// Reduces a tensor by summing its elements along a specified axis. @@ -652,16 +652,13 @@ trait TensorTrait { /// ## 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. + /// * `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 1 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. /// /// ## Returns /// - /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// Reduced output tensor. /// /// ## Examples /// @@ -676,12 +673,17 @@ trait TensorTrait { /// ); /// /// // We can call `reduce_sum` function as follows. - /// return tensor.reduce_sum(axis: 0, keepdims: false); + /// return tensor.reduce_sum(axes: Option::None, keepdims: false); /// } /// >>> [[4,6],[8,10]] /// ``` /// - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; /// # tensor.argmax /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 165a3af29..a6c54261c 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -64,7 +64,12 @@ impl BoolTensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { panic(array!['not supported!']) } @@ -570,17 +575,19 @@ impl BoolTryIntobool of TryInto { fn tensor_eq(mut lhs: Tensor, mut rhs: Tensor,) -> bool { let mut is_eq = true; - while lhs.shape.len() != 0 && is_eq { - is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); - }; + while lhs.shape.len() != 0 + && is_eq { + is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); + }; if !is_eq { return false; } - while lhs.data.len() != 0 && is_eq { - is_eq = lhs.data.pop_front().unwrap() == rhs.data.pop_front().unwrap(); - }; + while lhs.data.len() != 0 + && is_eq { + is_eq = lhs.data.pop_front().unwrap() == rhs.data.pop_front().unwrap(); + }; is_eq } diff --git a/src/operators/tensor/implementations/tensor_complex64.cairo b/src/operators/tensor/implementations/tensor_complex64.cairo index 9f5e612d7..fa465b33e 100644 --- a/src/operators/tensor/implementations/tensor_complex64.cairo +++ b/src/operators/tensor/implementations/tensor_complex64.cairo @@ -69,12 +69,19 @@ impl Complex64Tensor of TensorTrait { unravel_index(index, *self.shape) } - fn reshape(self: @Tensor, target_shape: Span, allowzero: bool) -> Tensor { + fn reshape( + self: @Tensor, target_shape: Span, allowzero: bool + ) -> Tensor { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { @@ -668,17 +675,19 @@ fn eq(lhs: @complex64, rhs: @complex64) -> bool { fn tensor_eq(mut lhs: Tensor, mut rhs: Tensor,) -> bool { let mut is_eq = true; - while lhs.shape.len() != 0 && is_eq { - is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); - }; + while lhs.shape.len() != 0 + && is_eq { + is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); + }; if !is_eq { return false; } - while lhs.data.len() != 0 && is_eq { - is_eq = eq(lhs.data.pop_front().unwrap(), rhs.data.pop_front().unwrap()); - }; + while lhs.data.len() != 0 + && is_eq { + is_eq = eq(lhs.data.pop_front().unwrap(), rhs.data.pop_front().unwrap()); + }; is_eq } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 64ae522fd..e1795000b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -75,8 +75,13 @@ impl FP16x16Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c18ffdf2e..c2e9b9344 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -79,8 +79,13 @@ impl FP16x16WTensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 0bfef5890..5cbf64139 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -72,8 +72,13 @@ impl FP32x32Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 3e29b3d35..3c18ae38a 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -72,8 +72,13 @@ impl FP64x64Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 7927bc9cd..33a19c080 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -72,8 +72,13 @@ impl FP8x23Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { @@ -345,9 +350,7 @@ impl FP8x23Tensor of TensorTrait { core_ops::slice::(self, starts, ends, axes, steps) } - fn gather( - self: @Tensor, indices: Tensor, axis: Option - ) -> Tensor { + fn gather(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { math::gather::gather(self, indices, axis) } @@ -777,17 +780,19 @@ fn relative_eq(lhs: @FP8x23, rhs: @FP8x23) -> bool { fn tensor_eq(mut lhs: Tensor, mut rhs: Tensor,) -> bool { let mut is_eq = true; - while lhs.shape.len() != 0 && is_eq { - is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); - }; + while lhs.shape.len() != 0 + && is_eq { + is_eq = lhs.shape.pop_front().unwrap() == rhs.shape.pop_front().unwrap(); + }; if !is_eq { return false; } - while lhs.data.len() != 0 && is_eq { - is_eq = relative_eq(lhs.data.pop_front().unwrap(), rhs.data.pop_front().unwrap()); - }; + while lhs.data.len() != 0 + && is_eq { + is_eq = relative_eq(lhs.data.pop_front().unwrap(), rhs.data.pop_front().unwrap()); + }; is_eq } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index e65e4cfda..459657891 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -75,8 +75,13 @@ impl FP8x23WTensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index f78e8c2b4..d4fa1b09c 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -72,8 +72,13 @@ impl I32Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index bcd2e40e4..903d66638 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -70,8 +70,13 @@ impl I8Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index daf9e9d32..01456aec6 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -69,8 +69,13 @@ impl U32Tensor of TensorTrait { reshape(self, target_shape, allowzero) } - fn reduce_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_sum::reduce_sum(self, axis, keepdims) + fn reduce_sum( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_sum::reduce_sum(self, axes, keepdims, noop_with_empty_axes) } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { diff --git a/src/operators/tensor/math/layer_normalization.cairo b/src/operators/tensor/math/layer_normalization.cairo index 4adfdca91..b6aa33ec0 100644 --- a/src/operators/tensor/math/layer_normalization.cairo +++ b/src/operators/tensor/math/layer_normalization.cairo @@ -92,13 +92,14 @@ fn layer_normalization< one_tensor.append(NumberTrait::one()); let x_mat = self.reshape(shape_matrix.span(), false); - let x_mean = x_mat.reduce_sum(1, true) + let x_mean = x_mat + .reduce_sum(Option::Some(array![1].span()), Option::Some(true), Option::Some(false)) / TensorTrait::new(shape_one.span(), col_number_tensor.span()); let x_diff = x_mat - x_mean; let x_squared_diff = x_diff * x_diff; - let variance = x_squared_diff.reduce_sum(1, true) + let variance = x_squared_diff.reduce_sum(Option::Some(array![1].span()), Option::Some(true), Option::Some(false)) / TensorTrait::new(shape_one.span(), col_number_tensor.span()); let variance_eps = variance + TensorTrait::new(shape_one.span(), epsilon_tensor.span()); diff --git a/src/operators/tensor/math/reduce_l1.cairo b/src/operators/tensor/math/reduce_l1.cairo index ba2be9215..29b83b69d 100644 --- a/src/operators/tensor/math/reduce_l1.cairo +++ b/src/operators/tensor/math/reduce_l1.cairo @@ -16,5 +16,5 @@ fn reduce_l1< ) -> Tensor { let data_abs = self.abs(); - data_abs.reduce_sum(axis: axis, keepdims: keepdims) + data_abs.reduce_sum(Option::Some(array![axis.try_into().unwrap()].span()), Option::Some(keepdims), Option::Some(false)) } diff --git a/src/operators/tensor/math/reduce_l2.cairo b/src/operators/tensor/math/reduce_l2.cairo index 96f4b7245..82f2d6e92 100644 --- a/src/operators/tensor/math/reduce_l2.cairo +++ b/src/operators/tensor/math/reduce_l2.cairo @@ -46,7 +46,12 @@ 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( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(keepdims), + Option::Some(false) + ); tensor_square_sum.sqrt() } @@ -64,7 +69,12 @@ fn reduce_l2_complex< self: @Tensor, axis: usize, keepdims: bool ) -> Tensor { let mut tensor_square = square(@self.abs()); - let mut tensor_square_sum = tensor_square.reduce_sum(axis: axis, keepdims: keepdims); + let mut tensor_square_sum = tensor_square + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(keepdims), + Option::Some(false) + ); tensor_square_sum.sqrt() } diff --git a/src/operators/tensor/math/reduce_log_sum.cairo b/src/operators/tensor/math/reduce_log_sum.cairo index 60a5225cb..0cc60f9cb 100644 --- a/src/operators/tensor/math/reduce_log_sum.cairo +++ b/src/operators/tensor/math/reduce_log_sum.cairo @@ -15,7 +15,12 @@ fn reduce_log_sum< >( self: @Tensor, axis: usize, keepdims: bool ) -> Tensor { - let tensor_square_sum = self.reduce_sum(axis: axis, keepdims: keepdims); + let tensor_square_sum = self + .reduce_sum( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(keepdims), + Option::Some(false) + ); let tensor_square_sum_log = tensor_square_sum.log(); tensor_square_sum_log diff --git a/src/operators/tensor/math/reduce_sum.cairo b/src/operators/tensor/math/reduce_sum.cairo index 078345f4a..ace480561 100644 --- a/src/operators/tensor/math/reduce_sum.cairo +++ b/src/operators/tensor/math/reduce_sum.cairo @@ -1,6 +1,14 @@ +use core::option::OptionTrait; +use core::traits::TryInto; +use alexandria_sorting::bubble_sort; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + +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}; +use orion::operators::tensor::helpers::{ + reduce_output_shape, len_from_shape, combine_indices, get_all_axes +}; /// Cf: TensorTrait::reduce_sum docstring fn reduce_sum< @@ -8,48 +16,108 @@ fn reduce_sum< MAG, impl TTensor: TensorTrait, impl TNumber: NumberTrait, - impl TAddEq: AddEq, impl TCopy: Copy, impl TDrop: Drop >( - self: @Tensor, axis: usize, keepdims: bool + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option ) -> Tensor { - let mut output_data: Array = array![]; - - if (*self.shape).len() == 1 { - assert(axis == 0, 'axis out of dimensions'); - let current_sum = accumulate_sum::(*self.data, *self.shape, *self.shape, axis); - output_data.append(current_sum); + 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: Array = array![]; + let mut copy_axes = axes.clone(); + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + // Adjust negative axes to positive + let adjusted_axis = if *axis < 0 { + ((*self.shape).len().try_into().unwrap() + *axis) + .try_into() + .unwrap() + } else { + (*axis).try_into().unwrap() + }; + axes_arr.append(adjusted_axis); + }, + Option::None => { break; } + }; + }; + let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr, true).span(); + sorted_axes + } + }, + Option::None => { + if noop_with_empty_axes { + return *self; + } + get_all_axes(*self.shape) + }, + }; + let keepdims = match keepdims { + Option::Some(keepdims) => keepdims, + Option::None => true, + }; - let mut output_shape: Array = array![]; - output_shape.append(1); + let mut axis_c = 0; + let mut copy_axes = axes.clone(); + 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_sum = accumulate_sum::(data, shape, shape, 0); + shape = array![].span(); + data = array![current_sum].span(); + break (); + } + let mut temp_data = array![]; + 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; + while index != data_len { + let indices = unravel_index(index, temp_shape); + let current_sum = accumulate_sum::(data, shape, indices, *axis - axis_c); - return TensorTrait::new(output_shape.span(), output_data.span()); - } else { - assert(axis <= (*self.shape).len(), 'axis out of dimensions'); - let output_shape = reduce_output_shape(*self.shape, axis, false); - let output_data_len = len_from_shape(output_shape); - let mut index: usize = 0; - while index != output_data_len { - let output_indices = unravel_index(index, output_shape); - let current_sum = accumulate_sum::(*self.data, *self.shape, output_indices, axis); + temp_data.append(current_sum); - output_data.append(current_sum); + index += 1; + }; - index += 1; + shape = temp_shape; + data = temp_data.span(); + axis_c += 1; + }, + Option::None => { break; } }; + }; - if keepdims { - let output_shape = reduce_output_shape(*self.shape, axis, true); + let mut axes_copy = axes.clone(); + if keepdims { + shape = *self.shape; + loop { + match axes_copy.pop_front() { + Option::Some(axis) => { shape = reduce_output_shape(shape, *axis, true); }, + Option::None => { break; } + }; + }; - TensorTrait::::new(output_shape, output_data.span()) - } else { - TensorTrait::::new(output_shape, output_data.span()) - } + TensorTrait::::new(shape, data) + } else { + TensorTrait::::new(shape, data) } } - /// Helper function that accumulates the sum of elements along a specific axis. /// /// # Arguments @@ -62,42 +130,34 @@ fn reduce_sum< /// * Panics if gas limit is exceeded during execution. /// /// # Returns -/// * An i32 value representing the accumulated sum along the specified axis. +/// * A value representing the accumulated sum along the specified axis. fn accumulate_sum< - T, - MAG, - impl TNumber: NumberTrait, - impl TAddEq: AddEq, - impl TCopy: Copy, - impl TDrop: Drop + T, MAG, impl TNumber: NumberTrait, 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 sum: T = NumberTrait::zero(); - let mut axis_index: usize = 0; + let mut axis_index = 0; if (input_shape).len() > 1 { - loop { - if axis_index == axis_len { - break (); - } - + while axis_index != axis_len { 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]; - acc += ele; + sum = NumberTrait::add(sum, ele); + axis_index += 1; }; } else { loop { match input_data.pop_front() { - Option::Some(item) => { acc += *item; }, + Option::Some(item) => sum = NumberTrait::add(sum, *item), Option::None => { break; } }; }; } - return acc; + sum } diff --git a/src/operators/tensor/math/reduce_sum_square.cairo b/src/operators/tensor/math/reduce_sum_square.cairo index b8ad7df99..fc7789150 100644 --- a/src/operators/tensor/math/reduce_sum_square.cairo +++ b/src/operators/tensor/math/reduce_sum_square.cairo @@ -45,7 +45,12 @@ 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( + Option::Some(array![axis.try_into().unwrap()].span()), + Option::Some(keepdims), + Option::Some(false) + ); tensor_square_sum } diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 122cb8d28..c43ec76d3 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -278,26 +278,6 @@ // 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; @@ -1031,6 +1011,11 @@ mod reshape_reordered_all_dims; mod reshape_reordered_last_dims; mod reshape_zero_and_negative_dim; mod reshape_zero_dim; +mod reduce_sum_default_axes_keepdims; +mod reduce_sum_empty_axes_input_noop; +mod reduce_sum_keep_dims; +mod reduce_sum_negative_axes_keepdims; +mod reduce_sum_no_keep_dims; mod gather_elements_default; mod gather_elements_axis1; mod gather_elements_axis2; diff --git a/tests/nodes/reduce_sum_default_axes_keepdims.cairo b/tests/nodes/reduce_sum_default_axes_keepdims.cairo new file mode 100644 index 000000000..93bb951e3 --- /dev/null +++ b/tests/nodes/reduce_sum_default_axes_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_sum_default_axes_keepdims() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.reduce_sum(Option::Some(array![].span()), Option::Some(true), Option::None); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/reduce_sum_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_sum_default_axes_keepdims/input_0.cairo similarity index 50% rename from tests/nodes/reduce_sum_i32_2D_axis_1/input_0.cairo rename to tests/nodes/reduce_sum_default_axes_keepdims/input_0.cairo index bb508695d..2de5818c3 100644 --- a/tests/nodes/reduce_sum_i32_2D_axis_1/input_0.cairo +++ b/tests/nodes/reduce_sum_default_axes_keepdims/input_0.cairo @@ -1,16 +1,26 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn input_0() -> Tensor { +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(0); 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()) } diff --git a/tests/nodes/reduce_sum_i32_1D/output_0.cairo b/tests/nodes/reduce_sum_default_axes_keepdims/output_0.cairo similarity index 57% rename from tests/nodes/reduce_sum_i32_1D/output_0.cairo rename to tests/nodes/reduce_sum_default_axes_keepdims/output_0.cairo index 286549beb..6cc93d6f7 100644 --- a/tests/nodes/reduce_sum_i32_1D/output_0.cairo +++ b/tests/nodes/reduce_sum_default_axes_keepdims/output_0.cairo @@ -1,12 +1,15 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(1); + shape.append(1); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(3); + data.append(78); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/reduce_sum_empty_axes_input_noop.cairo b/tests/nodes/reduce_sum_empty_axes_input_noop.cairo new file mode 100644 index 000000000..94c924e6f --- /dev/null +++ b/tests/nodes/reduce_sum_empty_axes_input_noop.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_sum_empty_axes_input_noop() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.reduce_sum(Option::None, Option::Some(true), Option::Some(true)); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/reduce_sum_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_sum_empty_axes_input_noop/input_0.cairo similarity index 50% rename from tests/nodes/reduce_sum_i32_2D_keepdims/input_0.cairo rename to tests/nodes/reduce_sum_empty_axes_input_noop/input_0.cairo index bb508695d..2de5818c3 100644 --- a/tests/nodes/reduce_sum_i32_2D_keepdims/input_0.cairo +++ b/tests/nodes/reduce_sum_empty_axes_input_noop/input_0.cairo @@ -1,16 +1,26 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn input_0() -> Tensor { +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(0); 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()) } diff --git a/tests/nodes/reduce_sum_empty_axes_input_noop/output_0.cairo b/tests/nodes/reduce_sum_empty_axes_input_noop/output_0.cairo new file mode 100644 index 000000000..d679605a0 --- /dev/null +++ b/tests/nodes/reduce_sum_empty_axes_input_noop/output_0.cairo @@ -0,0 +1,26 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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()) +} diff --git a/tests/nodes/reduce_sum_fp16x16_1D.cairo b/tests/nodes/reduce_sum_fp16x16_1D.cairo deleted file mode 100644 index 3f0522443..000000000 --- a/tests/nodes/reduce_sum_fp16x16_1D.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp16x16_1D() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_sum_fp16x16_1D/input_0.cairo deleted file mode 100644 index 38c052c06..000000000 --- a/tests/nodes/reduce_sum_fp16x16_1D/input_0.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -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_sum_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_sum_fp16x16_1D/output_0.cairo deleted file mode 100644 index a2e4a88f1..000000000 --- a/tests/nodes/reduce_sum_fp16x16_1D/output_0.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -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: 196608, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_sum_fp16x16_2D_axis_1.cairo deleted file mode 100644 index 6d0a4e86c..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_axis_1.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp16x16_2D_axis_1() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(1, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_axis_1/input_0.cairo deleted file mode 100644 index 00c61e821..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_axis_1/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -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_sum_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_axis_1/output_0.cairo deleted file mode 100644 index 2eb416252..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_axis_1/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::numbers::{FixedTrait, 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: 327680, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_default.cairo b/tests/nodes/reduce_sum_fp16x16_2D_default.cairo deleted file mode 100644 index 62fc72403..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_default.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp16x16_2D_default() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_default/input_0.cairo deleted file mode 100644 index 00c61e821..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_default/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -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_sum_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_default/output_0.cairo deleted file mode 100644 index bbd646932..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_default/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::numbers::{FixedTrait, FP16x16}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 262144, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_sum_fp16x16_2D_keepdims.cairo deleted file mode 100644 index 7de0e4085..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_keepdims.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp16x16_2D_keepdims() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, true); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_keepdims/input_0.cairo deleted file mode 100644 index 00c61e821..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_keepdims/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -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_sum_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_sum_fp16x16_2D_keepdims/output_0.cairo deleted file mode 100644 index 5d99577e2..000000000 --- a/tests/nodes/reduce_sum_fp16x16_2D_keepdims/output_0.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP16x16Tensor, FP16x16TensorMul}; -use orion::numbers::{FixedTrait, FP16x16}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 262144, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp8x23_1D.cairo b/tests/nodes/reduce_sum_fp8x23_1D.cairo deleted file mode 100644 index 1887e4cda..000000000 --- a/tests/nodes/reduce_sum_fp8x23_1D.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp8x23_1D() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_sum_fp8x23_1D/input_0.cairo deleted file mode 100644 index e050eac48..000000000 --- a/tests/nodes/reduce_sum_fp8x23_1D/input_0.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_sum_fp8x23_1D/output_0.cairo deleted file mode 100644 index a82fe159c..000000000 --- a/tests/nodes/reduce_sum_fp8x23_1D/output_0.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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: 25165824, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_sum_fp8x23_2D_axis_1.cairo deleted file mode 100644 index f8e1e9bd5..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_axis_1.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp8x23_2D_axis_1() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(1, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_sum_fp8x23_2D_axis_1/input_0.cairo deleted file mode 100644 index 29035e7f4..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_axis_1/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_sum_fp8x23_2D_axis_1/output_0.cairo deleted file mode 100644 index 74d4ee8e5..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_axis_1/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 41943040, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_default.cairo b/tests/nodes/reduce_sum_fp8x23_2D_default.cairo deleted file mode 100644 index 95ef60ba0..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_default.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp8x23_2D_default() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_sum_fp8x23_2D_default/input_0.cairo deleted file mode 100644 index 29035e7f4..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_default/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_sum_fp8x23_2D_default/output_0.cairo deleted file mode 100644 index 05c879685..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_default/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 33554432, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_sum_fp8x23_2D_keepdims.cairo deleted file mode 100644 index b81947c90..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_keepdims.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_fp8x23_2D_keepdims() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, true); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_sum_fp8x23_2D_keepdims/input_0.cairo deleted file mode 100644 index 29035e7f4..000000000 --- a/tests/nodes/reduce_sum_fp8x23_2D_keepdims/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_i32_1D.cairo b/tests/nodes/reduce_sum_i32_1D.cairo deleted file mode 100644 index 7a31579df..000000000 --- a/tests/nodes/reduce_sum_i32_1D.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i32_1D() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i32_1D/input_0.cairo b/tests/nodes/reduce_sum_i32_1D/input_0.cairo deleted file mode 100644 index 064a0d4e6..000000000 --- a/tests/nodes/reduce_sum_i32_1D/input_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -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_sum_i32_2D_axis_1.cairo b/tests/nodes/reduce_sum_i32_2D_axis_1.cairo deleted file mode 100644 index b67a7691d..000000000 --- a/tests/nodes/reduce_sum_i32_2D_axis_1.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i32_2D_axis_1() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(1, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_sum_i32_2D_axis_1/output_0.cairo deleted file mode 100644 index bb1a0e727..000000000 --- a/tests/nodes/reduce_sum_i32_2D_axis_1/output_0.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(1); - data.append(5); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_i32_2D_default.cairo b/tests/nodes/reduce_sum_i32_2D_default.cairo deleted file mode 100644 index a0428f46d..000000000 --- a/tests/nodes/reduce_sum_i32_2D_default.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i32_2D_default() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i32_2D_keepdims.cairo b/tests/nodes/reduce_sum_i32_2D_keepdims.cairo deleted file mode 100644 index acac6e0f5..000000000 --- a/tests/nodes/reduce_sum_i32_2D_keepdims.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i32_2D_keepdims() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, true); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i8_1D.cairo b/tests/nodes/reduce_sum_i8_1D.cairo deleted file mode 100644 index 0d8424333..000000000 --- a/tests/nodes/reduce_sum_i8_1D.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i8_1D() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i8_1D/input_0.cairo b/tests/nodes/reduce_sum_i8_1D/input_0.cairo deleted file mode 100644 index 3d963b8f3..000000000 --- a/tests/nodes/reduce_sum_i8_1D/input_0.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_i8_1D/output_0.cairo b/tests/nodes/reduce_sum_i8_1D/output_0.cairo deleted file mode 100644 index c2d0723f9..000000000 --- a/tests/nodes/reduce_sum_i8_1D/output_0.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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: 3, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_i8_2D_axis_1.cairo b/tests/nodes/reduce_sum_i8_2D_axis_1.cairo deleted file mode 100644 index 1d4fb2700..000000000 --- a/tests/nodes/reduce_sum_i8_2D_axis_1.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i8_2D_axis_1() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(1, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_sum_i8_2D_axis_1/input_0.cairo deleted file mode 100644 index 4c38e1659..000000000 --- a/tests/nodes/reduce_sum_i8_2D_axis_1/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_sum_i8_2D_axis_1/output_0.cairo deleted file mode 100644 index a9a7cd3ae..000000000 --- a/tests/nodes/reduce_sum_i8_2D_axis_1/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 1, sign: false }); - data.append(FP8x23 { mag: 5, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_i8_2D_default.cairo b/tests/nodes/reduce_sum_i8_2D_default.cairo deleted file mode 100644 index 4875dc77c..000000000 --- a/tests/nodes/reduce_sum_i8_2D_default.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i8_2D_default() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, false); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i8_2D_default/input_0.cairo b/tests/nodes/reduce_sum_i8_2D_default/input_0.cairo deleted file mode 100644 index 4c38e1659..000000000 --- a/tests/nodes/reduce_sum_i8_2D_default/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_i8_2D_default/output_0.cairo b/tests/nodes/reduce_sum_i8_2D_default/output_0.cairo deleted file mode 100644 index a517b5dca..000000000 --- a/tests/nodes/reduce_sum_i8_2D_default/output_0.cairo +++ /dev/null @@ -1,14 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 2, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_i8_2D_keepdims.cairo b/tests/nodes/reduce_sum_i8_2D_keepdims.cairo deleted file mode 100644 index 98172e256..000000000 --- a/tests/nodes/reduce_sum_i8_2D_keepdims.cairo +++ /dev/null @@ -1,20 +0,0 @@ -mod input_0; -mod output_0; - - -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; - -#[test] -#[available_gas(2000000000)] -fn test_reduce_sum_i8_2D_keepdims() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = input_0.reduce_sum(0, true); - - assert_eq(y, z); -} diff --git a/tests/nodes/reduce_sum_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_sum_i8_2D_keepdims/input_0.cairo deleted file mode 100644 index 4c38e1659..000000000 --- a/tests/nodes/reduce_sum_i8_2D_keepdims/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -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_sum_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_sum_i8_2D_keepdims/output_0.cairo deleted file mode 100644 index ef122111b..000000000 --- a/tests/nodes/reduce_sum_i8_2D_keepdims/output_0.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use core::array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 2, sign: false }); - data.append(FP8x23 { mag: 4, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/reduce_sum_keep_dims.cairo b/tests/nodes/reduce_sum_keep_dims.cairo new file mode 100644 index 000000000..19a37247a --- /dev/null +++ b/tests/nodes/reduce_sum_keep_dims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_sum_keep_dims() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.reduce_sum(Option::Some(array![1].span()), Option::Some(true), Option::None); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/reduce_sum_i32_2D_default/input_0.cairo b/tests/nodes/reduce_sum_keep_dims/input_0.cairo similarity index 50% rename from tests/nodes/reduce_sum_i32_2D_default/input_0.cairo rename to tests/nodes/reduce_sum_keep_dims/input_0.cairo index bb508695d..2de5818c3 100644 --- a/tests/nodes/reduce_sum_i32_2D_default/input_0.cairo +++ b/tests/nodes/reduce_sum_keep_dims/input_0.cairo @@ -1,16 +1,26 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn input_0() -> Tensor { +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(0); 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()) } diff --git a/tests/nodes/reduce_sum_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_sum_keep_dims/output_0.cairo similarity index 54% rename from tests/nodes/reduce_sum_i32_2D_keepdims/output_0.cairo rename to tests/nodes/reduce_sum_keep_dims/output_0.cairo index 704b7fd71..5326997d6 100644 --- a/tests/nodes/reduce_sum_i32_2D_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_keep_dims/output_0.cairo @@ -1,14 +1,20 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); + shape.append(3); shape.append(1); shape.append(2); let mut data = ArrayTrait::new(); - data.append(2); data.append(4); + data.append(6); + data.append(12); + data.append(14); + data.append(20); + data.append(22); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/reduce_sum_negative_axes_keepdims.cairo b/tests/nodes/reduce_sum_negative_axes_keepdims.cairo new file mode 100644 index 000000000..4c271c091 --- /dev/null +++ b/tests/nodes/reduce_sum_negative_axes_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_sum_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.reduce_sum(Option::Some(array![-2].span()), Option::Some(true), Option::None); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/reduce_sum_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_sum_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..2de5818c3 --- /dev/null +++ b/tests/nodes/reduce_sum_negative_axes_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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()) +} diff --git a/tests/nodes/reduce_sum_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_sum_negative_axes_keepdims/output_0.cairo similarity index 50% rename from tests/nodes/reduce_sum_fp8x23_2D_keepdims/output_0.cairo rename to tests/nodes/reduce_sum_negative_axes_keepdims/output_0.cairo index 216765e7b..5326997d6 100644 --- a/tests/nodes/reduce_sum_fp8x23_2D_keepdims/output_0.cairo +++ b/tests/nodes/reduce_sum_negative_axes_keepdims/output_0.cairo @@ -1,15 +1,20 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorMul}; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); + shape.append(3); shape.append(1); shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(4); + data.append(6); + data.append(12); + data.append(14); + data.append(20); + data.append(22); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/reduce_sum_no_keep_dims.cairo b/tests/nodes/reduce_sum_no_keep_dims.cairo new file mode 100644 index 000000000..78c1c0c66 --- /dev/null +++ b/tests/nodes/reduce_sum_no_keep_dims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_sum_no_keep_dims() { + let input_0 = input_0::input_0(); + let z_0 = output_0::output_0(); + + let y_0 = input_0.reduce_sum(Option::Some(array![1].span()), Option::Some(false), Option::None); + + assert_eq(y_0, z_0); +} diff --git a/tests/nodes/reduce_sum_no_keep_dims/input_0.cairo b/tests/nodes/reduce_sum_no_keep_dims/input_0.cairo new file mode 100644 index 000000000..2de5818c3 --- /dev/null +++ b/tests/nodes/reduce_sum_no_keep_dims/input_0.cairo @@ -0,0 +1,26 @@ +use core::array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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()) +} diff --git a/tests/nodes/reduce_sum_i32_2D_default/output_0.cairo b/tests/nodes/reduce_sum_no_keep_dims/output_0.cairo similarity index 52% rename from tests/nodes/reduce_sum_i32_2D_default/output_0.cairo rename to tests/nodes/reduce_sum_no_keep_dims/output_0.cairo index 925b8f6c2..72c71a185 100644 --- a/tests/nodes/reduce_sum_i32_2D_default/output_0.cairo +++ b/tests/nodes/reduce_sum_no_keep_dims/output_0.cairo @@ -1,13 +1,19 @@ use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::{I32Tensor, I32TensorMul}; +use orion::operators::tensor::{U32Tensor, U32TensorAdd}; +use orion::numbers::NumberTrait; -fn output_0() -> Tensor { +fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); - data.append(2); data.append(4); + data.append(6); + data.append(12); + data.append(14); + data.append(20); + data.append(22); TensorTrait::new(shape.span(), data.span()) }