From 8235d787568569fe93d863160ebddb35171d4446 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 6 Nov 2023 13:00:15 +0100 Subject: [PATCH 1/2] 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 8d96c2d1e7f220cc0512c840b3ead62c5f0e740d Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sat, 11 Nov 2023 23:23:38 +0200 Subject: [PATCH 2/2] 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,