From 7f47daf4597362a229e063ecae72f03dd1f0db3e Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Fri, 1 Dec 2023 09:33:09 +0100 Subject: [PATCH 1/2] reduce log sum operator --- docs/CHANGELOG.md | 7 +- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 3 +- .../operators/tensor/tensor.reduce_log_sum.md | 45 +++++++ nodegen/node/reduce_log_sum.py | 117 ++++++++++++++++++ src/operators/tensor/core.cairo | 49 ++++++++ .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + .../tensor/math/reduce_log_sum.cairo | 28 +++++ tests/nodes.cairo | 7 ++ ...g_sum_fp16x16_export_do_not_keepdims.cairo | 20 +++ .../input_0.cairo | 26 ++++ .../output_0.cairo | 19 +++ ...duce_log_sum_fp16x16_export_keepdims.cairo | 20 +++ .../input_0.cairo | 26 ++++ .../output_0.cairo | 20 +++ ...p16x16_export_negative_axes_keepdims.cairo | 20 +++ .../input_0.cairo | 22 ++++ .../output_0.cairo | 18 +++ ...og_sum_fp8x23_export_do_not_keepdims.cairo | 20 +++ .../input_0.cairo | 26 ++++ .../output_0.cairo | 19 +++ ...educe_log_sum_fp8x23_export_keepdims.cairo | 20 +++ .../input_0.cairo | 26 ++++ .../output_0.cairo | 20 +++ ...fp8x23_export_negative_axes_keepdims.cairo | 20 +++ .../input_0.cairo | 41 ++++++ .../output_0.cairo | 23 ++++ 38 files changed, 703 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.reduce_log_sum.md create mode 100644 nodegen/node/reduce_log_sum.py create mode 100644 src/operators/tensor/math/reduce_log_sum.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fa13bee87..5d4eed017 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,11 +4,16 @@ 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-12-01 + +## Added +- Reduce LogSum Operator + ## [Unreleased] - 2023-11-27 ## Added - Reduce Prod Operator -- + ## [Unreleased] - 2023-11-20 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 2a7ded543..3d049a505 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -102,6 +102,7 @@ - [tensor.reduce_sum_square](framework/operators/tensor/tensor.reduce_sum_square.md) - [tensor.reduce_l2](framework/operators/tensor/tensor.reduce_l2.md) - [tensor.reduce_l1](framework/operators/tensor/tensor.reduce_l1.md) + - [tensor.reduce_log_sum](framework/operators/tensor/tensor.reduce_log_sum.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 14c0154bb..e5538b0fe 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -101,6 +101,7 @@ You can see below the list of current supported ONNX Operators: | [IsNaN](operators/tensor/tensor.is\_nan.md) | :white\_check\_mark: | | [IsInf](operators/tensor/tensor.is\_inf.md) | :white\_check\_mark: | | [Not](operators/tensor/tensor.not.md) | :white\_check\_mark: | +| [ReduceLogSum](operators/tensor/tensor.reduce\_log\_sum.md) | :white\_check\_mark: | Current Operators support: **83/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 574779ffe..b486502ac 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -65,7 +65,6 @@ use orion::operators::tensor::TensorTrait; | [`tensor.log`](tensor.log.md) | Computes the natural log of all elements of the input tensor. | | [`tensor.abs`](tensor.abs.md) | Computes the absolute value of all elements in the input tensor. | | [`tensor.neg`](tensor.neg.md) | Computes the negation of all elements in the input tensor. | -| [`tensor.not`](tensor.not.md) | Computes the logical negation of all elements in the input tensor. | | [`tensor.ceil`](tensor.ceil.md) | Rounds up the value of each element in the input tensor. | | [`tensor.sqrt`](tensor.sqrt.md) | Computes the square root of all elements of the input tensor. | | [`tensor.sin`](tensor.sin.md) | Computes the sine of all elements of the input tensor. | @@ -122,6 +121,8 @@ use orion::operators::tensor::TensorTrait; | [`tensor.concat_from_sequence`](tensor.concat\_from\_sequence.md) | Concatenate a sequence of tensors into a single tensor. | | [`tensor.is_nan`](tensor.is\_nan.md) | Returns which elements of the input are NaN. | | [`tensor.is_inf`](tensor.is\_inf.md) | Maps infinity to true and other values to false. | +| [`tensor.not`](tensor.not.md) | Computes the logical negation of all elements in the input tensor. | +| [`tensor.reduce_log_sum`](tensor.reduce\_log\_sum.md) | Computes the log sum of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.reduce_log_sum.md b/docs/framework/operators/tensor/tensor.reduce_log_sum.md new file mode 100644 index 000000000..f15bce4a9 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_log_sum.md @@ -0,0 +1,45 @@ +## tensor.reduce_log_sum + +```rust + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; +``` + +Computes the log sum 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_log_sum() -> Tensor { + + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(FixedTrait::new_unscaled(1, false)); + data.append(FixedTrait::new_unscaled(2, false)); + data.append(FixedTrait::new_unscaled(3, false)); + data.append(FixedTrait::new_unscaled(4, false)); + data.append(FixedTrait::new_unscaled(5, false)); + data.append(FixedTrait::new_unscaled(6, false)); + data.append(FixedTrait::new_unscaled(7, false)); + data.append(FixedTrait::new_unscaled(8, false)); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + We can call `reduce_log_sum` function as follows. + return tensor.reduce_log_sum(axis: 2, keepdims: false); +} +>>> [[0x11938, 0x1f203], [0x265d9, 0x2b540]] +``` diff --git a/nodegen/node/reduce_log_sum.py b/nodegen/node/reduce_log_sum.py new file mode 100644 index 000000000..259081f5a --- /dev/null +++ b/nodegen/node/reduce_log_sum.py @@ -0,0 +1,117 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl +import numpy as np + + +class Reduce_log_sum(RunAll): + @staticmethod + def reduce_log_sum_fp8x23(): + def reduce_log_sum_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) + y = np.log(np.sum(x, axis=tuple(axes), keepdims=False)) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp8x23_export_do_not_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(2, false)", name) + + def reduce_log_sum_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.log(np.sum(x, axis=tuple(axes), keepdims=True)) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp8x23_export_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(2, true)", name) + + def reduce_log_sum_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), shape) + y = np.log(np.sum(x, axis=tuple(axes), keepdims=True)) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp8x23_export_negative_axes_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(0, true)", name) + + + reduce_log_sum_export_do_not_keepdims() + reduce_log_sum_export_keepdims() + reduce_log_sum_axis_0() + + @staticmethod + def reduce_log_sum_fp16x16(): + def reduce_log_sum_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.log(np.sum(x, axis=tuple(axes), keepdims=False)) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp16x16_export_do_not_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(2, false)", name) + + def reduce_log_sum_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.log(np.sum(x, axis=tuple(axes), keepdims=True)) + + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp16x16_export_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(2, true)", name) + + def reduce_log_sum_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.log(np.sum(x, axis=tuple(axes), keepdims=True)) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_log_sum_fp16x16_export_negative_axes_keepdims" + make_test( + [x], y, "input_0.reduce_log_sum(0, true)", name) + + + reduce_log_sum_export_do_not_keepdims() + reduce_log_sum_export_keepdims() + reduce_log_sum_axis_0() \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 72d13f627..a8eb13cff 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -121,6 +121,8 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -4872,6 +4874,53 @@ trait TensorTrait { /// ``` /// fn not(self: @Tensor) -> Tensor; + /// ## tensor.reduce_log_sum + /// + /// ```rust + /// fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the log sum 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_log_sum() -> Tensor { + /// + /// let mut sizes = ArrayTrait::new(); + /// sizes.append(2); + /// sizes.append(2); + /// sizes.append(2); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(FixedTrait::new_unscaled(1, false)); + /// data.append(FixedTrait::new_unscaled(2, false)); + /// data.append(FixedTrait::new_unscaled(3, false)); + /// data.append(FixedTrait::new_unscaled(4, false)); + /// data.append(FixedTrait::new_unscaled(5, false)); + /// data.append(FixedTrait::new_unscaled(6, false)); + /// data.append(FixedTrait::new_unscaled(7, false)); + /// data.append(FixedTrait::new_unscaled(8, false)); + /// + /// let tensor = TensorTrait::::new(sizes.span(), data.span()); + /// + /// We can call `reduce_log_sum` function as follows. + /// return tensor.reduce_log_sum(axis: 2, keepdims: false); + /// } + /// >>> [[0x11938, 0x1f203], [0x265d9, 0x2b540]] + /// ``` + /// + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d9e7a8357..3e2371fa4 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -451,6 +451,10 @@ impl BoolTensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { panic(array!['not supported!']) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index c3e0986cc..7a5b1722c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -512,6 +512,10 @@ impl FP16x16Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 c993f960f..ec02e1181 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -478,6 +478,10 @@ impl FP16x16WTensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 a267451f0..55f7bc3b2 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -513,6 +513,10 @@ impl FP32x32Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 fea845ce4..825cb3a72 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -514,6 +514,10 @@ impl FP64x64Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 2d00eded0..1d44050c1 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -512,6 +512,10 @@ impl FP8x23Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 8f153c592..898217a1d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -465,6 +465,10 @@ impl FP8x23WTensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_log_sum::reduce_log_sum(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 6a41b927e..0a47f32c8 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -507,6 +507,10 @@ impl I32Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 9862907fd..1e6a01ecb 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -507,6 +507,10 @@ impl I8Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 05084e743..be6f77f06 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -450,6 +450,10 @@ impl U32Tensor of TensorTrait { fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } + + fn reduce_log_sum(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index d5a74322c..02aabaacc 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -62,3 +62,4 @@ mod sequence_insert; mod concat_from_sequence; mod is_nan; mod is_inf; +mod reduce_log_sum; diff --git a/src/operators/tensor/math/reduce_log_sum.cairo b/src/operators/tensor/math/reduce_log_sum.cairo new file mode 100644 index 000000000..4cbad2757 --- /dev/null +++ b/src/operators/tensor/math/reduce_log_sum.cairo @@ -0,0 +1,28 @@ +use core::option::OptionTrait; +use array::ArrayTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; + +/// Cf: TensorTrait::reduce_sum_square docstring +fn reduce_log_sum< + 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_sum = self.reduce_sum(axis: axis, keepdims: keepdims); + let tensor_square_sum_log = tensor_square_sum.log(); + + return tensor_square_sum_log; +} \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index f7986bb13..ada5b52ad 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -829,3 +829,10 @@ mod is_pos_inf_i32; mod is_neg_inf_i32; mod is_pos_inf_i8; mod is_neg_inf_i8; + +mod reduce_log_sum_fp8x23_export_do_not_keepdims; +mod reduce_log_sum_fp8x23_export_keepdims; +mod reduce_log_sum_fp8x23_export_negative_axes_keepdims; +mod reduce_log_sum_fp16x16_export_do_not_keepdims; +mod reduce_log_sum_fp16x16_export_keepdims; +mod reduce_log_sum_fp16x16_export_negative_axes_keepdims; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo new file mode 100644 index 000000000..63cf1f697 --- /dev/null +++ b/tests/nodes/reduce_log_sum_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, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp16x16_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(2, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..229ed5052 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, 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: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..5471215e8 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, 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: 9215827, sign: false }); + data.append(FP8x23 { mag: 16323477, sign: false }); + data.append(FP8x23 { mag: 20115003, sign: false }); + data.append(FP8x23 { mag: 22716771, sign: false }); + data.append(FP8x23 { mag: 24699744, sign: false }); + data.append(FP8x23 { mag: 26302431, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo new file mode 100644 index 000000000..a379fa384 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp16x16_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(2, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo new file mode 100644 index 000000000..229ed5052 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo new file mode 100644 index 000000000..a0ce84f07 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_export_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, 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: 9215827, sign: false }); + data.append(FP8x23 { mag: 16323477, sign: false }); + data.append(FP8x23 { mag: 20115003, sign: false }); + data.append(FP8x23 { mag: 22716771, sign: false }); + data.append(FP8x23 { mag: 24699744, sign: false }); + data.append(FP8x23 { mag: 26302431, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..df0308bac --- /dev/null +++ b/tests/nodes/reduce_log_sum_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, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp16x16_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..1ce7fdd4a --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +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(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..7b9b8ad94 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp16x16_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +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(FP8x23 { mag: 15030367, sign: false }); + data.append(FP8x23 { mag: 17443619, sign: false }); + data.append(FP8x23 { mag: 19315483, sign: false }); + data.append(FP8x23 { mag: 20844907, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo new file mode 100644 index 000000000..00f07b0ec --- /dev/null +++ b/tests/nodes/reduce_log_sum_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, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp8x23_export_do_not_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(2, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo new file mode 100644 index 000000000..229ed5052 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, 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: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo new file mode 100644 index 000000000..526e397bb --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, 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: 9215828, sign: false }); + data.append(FP8x23 { mag: 16323477, sign: false }); + data.append(FP8x23 { mag: 20115004, sign: false }); + data.append(FP8x23 { mag: 22716772, sign: false }); + data.append(FP8x23 { mag: 24699744, sign: false }); + data.append(FP8x23 { mag: 26302432, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo new file mode 100644 index 000000000..cda65628a --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp8x23_export_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(2, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo new file mode 100644 index 000000000..229ed5052 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo @@ -0,0 +1,26 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo new file mode 100644 index 000000000..a0ce84f07 --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_export_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, 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: 9215827, sign: false }); + data.append(FP8x23 { mag: 16323477, sign: false }); + data.append(FP8x23 { mag: 20115003, sign: false }); + data.append(FP8x23 { mag: 22716771, sign: false }); + data.append(FP8x23 { mag: 24699744, sign: false }); + data.append(FP8x23 { mag: 26302431, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo new file mode 100644 index 000000000..4068be608 --- /dev/null +++ b/tests/nodes/reduce_log_sum_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, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_log_sum_fp8x23_export_negative_axes_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_log_sum(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo new file mode 100644 index 000000000..38b225cdc --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 167772160, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + data.append(FP8x23 { mag: 226492416, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo new file mode 100644 index 000000000..1357edcdb --- /dev/null +++ b/tests/nodes/reduce_log_sum_fp8x23_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::FP8x23Tensor; +use orion::numbers::{FixedTrait, 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: 28531311, sign: false }); + data.append(FP8x23 { mag: 29330831, sign: false }); + data.append(FP8x23 { mag: 30060735, sign: false }); + data.append(FP8x23 { mag: 30732182, sign: false }); + data.append(FP8x23 { mag: 31353845, sign: false }); + data.append(FP8x23 { mag: 31932599, sign: false }); + data.append(FP8x23 { mag: 32473987, sign: false }); + data.append(FP8x23 { mag: 32982543, sign: false }); + data.append(FP8x23 { mag: 33462023, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} From 2b9f0eda46c11d772f3a66471d14a81d86fad9f7 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 10 Dec 2023 17:15:00 +0200 Subject: [PATCH 2/2] udpate imports --- src/operators/tensor/math/reduce_log_sum.cairo | 6 +++--- .../reduce_log_sum_fp16x16_export_do_not_keepdims.cairo | 2 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo | 2 +- .../reduce_log_sum_fp16x16_export_keepdims/input_0.cairo | 2 +- .../reduce_log_sum_fp16x16_export_keepdims/output_0.cairo | 2 +- ...duce_log_sum_fp16x16_export_negative_axes_keepdims.cairo | 2 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- .../reduce_log_sum_fp8x23_export_do_not_keepdims.cairo | 2 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo | 2 +- .../reduce_log_sum_fp8x23_export_keepdims/input_0.cairo | 2 +- .../reduce_log_sum_fp8x23_export_keepdims/output_0.cairo | 2 +- ...educe_log_sum_fp8x23_export_negative_axes_keepdims.cairo | 2 +- .../input_0.cairo | 2 +- .../output_0.cairo | 2 +- 19 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/operators/tensor/math/reduce_log_sum.cairo b/src/operators/tensor/math/reduce_log_sum.cairo index 4cbad2757..2aa0516f6 100644 --- a/src/operators/tensor/math/reduce_log_sum.cairo +++ b/src/operators/tensor/math/reduce_log_sum.cairo @@ -1,7 +1,7 @@ use core::option::OptionTrait; -use array::ArrayTrait; -use array::SpanTrait; -use debug::PrintTrait; +use core::array::ArrayTrait; +use core::array::SpanTrait; +use core::debug::PrintTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo index 63cf1f697..108ef328f 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo index 229ed5052..d8f5ac09d 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo index 5471215e8..4c5cd630b 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_do_not_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo index a379fa384..5ee464e1c 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo index 229ed5052..d8f5ac09d 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo index a0ce84f07..39127716e 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo index df0308bac..7f7fc7f98 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo index 1ce7fdd4a..068fe1a81 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo index 7b9b8ad94..0b3cda1be 100644 --- a/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp16x16_export_negative_axes_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo index 00f07b0ec..3f0adf3eb 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo index 229ed5052..d8f5ac09d 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo index 526e397bb..3ee433b31 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_do_not_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo index cda65628a..5662f1510 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo index 229ed5052..d8f5ac09d 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo index a0ce84f07..39127716e 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo index 4068be608..ec295a396 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims.cairo @@ -2,7 +2,7 @@ mod input_0; mod output_0; -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::operators::tensor::FP8x23TensorPartialEq; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo index 38b225cdc..7db081374 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/input_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23}; diff --git a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo index 1357edcdb..72c608c25 100644 --- a/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo +++ b/tests/nodes/reduce_log_sum_fp8x23_export_negative_axes_keepdims/output_0.cairo @@ -1,4 +1,4 @@ -use array::{ArrayTrait, SpanTrait}; +use core::array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; use orion::numbers::{FixedTrait, FP8x23};