diff --git a/.all-contributorsrc b/.all-contributorsrc index 6e798d849..84be25e8a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -188,6 +188,15 @@ "contributions": [ "code" ] + }, + { + "login": "andresmayorca", + "name": "Andres", + "avatar_url": "https://avatars.githubusercontent.com/u/70079260?v=4", + "profile": "http://andresmayorca.github.io", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/.gitignore b/.gitignore index b69dbeef7..5a0c79267 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ target __pycache__ neural_network/.venv + +Scarb.lock \ No newline at end of file diff --git a/README.md b/README.md index 9e547c851..a89893233 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -93,6 +93,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d 0xfulanito
0xfulanito

💻 0x73e
0x73e

💻 Thomas S. Bauer
Thomas S. Bauer

💻 + Andres
Andres

💻 diff --git a/Scarb.lock b/Scarb.lock deleted file mode 100644 index 85e5484e6..000000000 --- a/Scarb.lock +++ /dev/null @@ -1,20 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "alexandria_data_structures" -version = "0.1.0" -source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=f37d73d#f37d73d8a8248e4d8dc65de3949333e30bda022f" - -[[package]] -name = "cubit" -version = "1.2.0" -source = "git+https://github.com/raphaelDkhn/cubit.git#e6331ebf98c5d5f442a0e5edefe0b367c8e270d9" - -[[package]] -name = "orion" -version = "0.1.2" -dependencies = [ - "alexandria_data_structures", - "cubit", -] diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd3cfa146..be5423456 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,12 @@ 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-03 + +## Added +- Scatter Elements Operator. + ## [Unreleased] - 2023-09-27 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 409c1715e..f96dd7a6f 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -40,7 +40,9 @@ * [Tensor](framework/operators/tensor/README.md) * [tensor.new](framework/operators/tensor/tensor.new.md) * [tensor.at](framework/operators/tensor/tensor.at.md) + * [tensor.min_in_tensor](framework/operators/tensor/tensor.min_in_tensor.md) * [tensor.min](framework/operators/tensor/tensor.min.md) + * [tensor.max\_in\_tensor](framework/operators/tensor/tensor.max\_in\_tensor.md) * [tensor.max](framework/operators/tensor/tensor.max.md) * [tensor.stride](framework/operators/tensor/tensor.stride.md) * [tensor.ravel\_index](framework/operators/tensor/tensor.ravel\_index.md) @@ -82,6 +84,7 @@ * [tensor.gather](framework/operators/tensor/tensor.gather.md) * [tensor.quantize\_linear](framework/operators/tensor/tensor.quantize\_linear.md) * [tensor.dequantize\_linear](framework/operators/tensor/tensor.dequantize\_linear.md) + * [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md) * [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) * [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) * [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) @@ -90,6 +93,8 @@ * [tensor.identity](framework/operators/tensor/tensor.identity.md) * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) + * [tensor.round](framework/operators/tensor/tensor.round.md) + * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) * [Neural Network](framework/operators/neural-network/README.md) * [nn.relu](framework/operators/neural-network/nn.relu.md) * [nn.leaky\_relu](framework/operators/neural-network/nn.leaky\_relu.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 29d537ff6..e5f7f39cf 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -56,6 +56,7 @@ You can see below the list of current supported ONNX Operators: | [Gather](operators/tensor/tensor.gather.md) | :white\_check\_mark: | | [QuantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | | [DequantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | +| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: | | [Nonzero](operators/tensor/tensor.nonzero.md) | :white\_check\_mark: | | [Squeeze](operators/tensor/tensor.squeeze.md) | :white\_check\_mark: | | [Unsqueeze](operators/tensor/tensor.unsqueeze.md) | :white\_check\_mark: | @@ -66,6 +67,12 @@ You can see below the list of current supported ONNX Operators: | [Xor](operators/tensor/tensor.xor.md) | :white\_check\_mark: | | [Or](operators/tensor/tensor.or.md) | :white\_check\_mark: | | [Gemm](operators/neural-network/nn.gemm.md) | :white\_check\_mark: | +| [MinInTensor](operators/tensor/tensor.min\_in\_tensor.md) | :white\_check\_mark: | +| [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: | | [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: | +| [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: | -Current Operators support: **61/156 (39%)** +Current Operators support: **68/156 (43%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 361401570..369713044 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -50,6 +50,8 @@ use orion::operators::tensor::TensorTrait; | [`tensor.xor`](tensor.xor.md) | Computes the logical XOR of two tensors element-wise. | | [`tensor.stride`](tensor.stride.md) | Computes the stride of each dimension in the tensor. | | [`tensor.onehot`](tensor.onehot.md) | Produces one-hot tensor based on input. | +| [`tensor.max_in_tensor`](tensor.max\_in\_tensor.md) | Returns the maximum value in the tensor. | +| [`tensor.min_in_tensor`](tensor.min\_in\_tensor.md) | Returns the minimum value in the tensor. | | [`tensor.min`](tensor.min.md) | Returns the minimum value in the tensor. | | [`tensor.max`](tensor.max.md) | Returns the maximum value in the tensor. | | [`tensor.reduce_sum`](tensor.reduce\_sum.md) | Reduces a tensor by summing its elements along a specified axis. | @@ -77,6 +79,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.concat`](tensor.concat.md) | Concatenate a list of tensors into a single tensor. | | [`tensor.quantize_linear`](tensor.quantize\_linear.md) | Quantizes a Tensor to i8 using linear quantization. | | [`tensor.dequantize_linear`](tensor.dequantize\_linear.md) | Dequantizes an i8 Tensor using linear dequantization. | +| [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. | | [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. | | [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). | | [`tensor.squeeze`](tensor.squeeze.md) | Removes dimensions of size 1 from the shape of a tensor. | @@ -86,6 +89,8 @@ use orion::operators::tensor::TensorTrait; | [`tensor.and`](tensor.and.md) | Computes the logical AND of two tensors element-wise. | | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | +| [`tensor.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. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.max.md b/docs/framework/operators/tensor/tensor.max.md index e115cc559..966405862 100644 --- a/docs/framework/operators/tensor/tensor.max.md +++ b/docs/framework/operators/tensor/tensor.max.md @@ -1,33 +1,63 @@ # tensor.max ```rust - fn max(self: @Tensor) -> T; + fn max(tensors: Span>) -> Tensor; ``` -Returns the maximum value in the tensor. +Returns the element-wise maximum values from a list of input tensors +The input tensors must have either: +* Exactly the same shape +* The same number of dimensions and the length of each dimension is either a common length or 1. ## Args -* `self`(`@Tensor`) - The input tensor. +* `tensors`(` Span>,`) - Array of the input tensors -## Returns +## Returns -The maximum `T` value in the tensor. +A new `Tensor` containing the element-wise maximum values -Examples +## Panics + +* Panics if tensor array is empty +* Panics if the shapes are not equal or broadcastable + +## Examples + +Case 1: Process tensors with same shape ```rust use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; -fn max_example() -> u32 { - let tensor = TensorTrait::new( - shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), - ); +fn max_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 3, 1, 2].span(),); + let result = TensorTrait::max(tensors: array![tensor1, tensor2].span()); + return result; +} +>>> [0, 3, 2, 3] + + result.shape +>>> (2, 2) +``` + +Case 2: Process tensors with different shapes - // We can call `max` function as follows. - return tensor.max(); +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn max_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + let tensor2 = TensorTrait::new(shape: array![1, 2].span(), data: array![1, 4].span(),); + let result = TensorTrait::max(tensors: array![tensor1, tensor2].span()); + return result; } ->>> 7 +>>> [1, 4, 2, 4] + + result.shape +>>> (2, 2) ``` diff --git a/docs/framework/operators/tensor/tensor.max_in_tensor.md b/docs/framework/operators/tensor/tensor.max_in_tensor.md new file mode 100644 index 000000000..08ac0f82f --- /dev/null +++ b/docs/framework/operators/tensor/tensor.max_in_tensor.md @@ -0,0 +1,33 @@ +# tensor.max_in_tensor + +```rust + fn max_in_tensor(self: @Tensor) -> T; +``` + +Returns the maximum value in the tensor. + +## Args + +* `self`(`@Tensor`) - The input tensor. + +## Returns + +The maximum `T` value in the tensor. + +Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn max_in_tensor_example() -> u32 { + let tensor = TensorTrait::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `max_in_tensor` function as follows. + return tensor.max_in_tensor(); +} +>>> 7 +``` diff --git a/docs/framework/operators/tensor/tensor.min.md b/docs/framework/operators/tensor/tensor.min.md index 037c4067f..31157c2dc 100644 --- a/docs/framework/operators/tensor/tensor.min.md +++ b/docs/framework/operators/tensor/tensor.min.md @@ -1,34 +1,63 @@ # tensor.min ```rust - fn min(self: @Tensor) -> T; + fn min(tensors: Span>) -> Tensor; ``` -Returns the minimum value in the tensor. +Returns the element-wise minumum values from a list of input tensors +The input tensors must have either: +* Exactly the same shape +* The same number of dimensions and the length of each dimension is either a common length or 1. ## Args -* `self`(`@Tensor`) - The input tensor. +* `tensors`(` Span>,`) - Array of the input tensors -## Returns +## Returns -The minimum `T` value in the tensor. +A new `Tensor` containing the element-wise minimum values + +## Panics + +* Panics if tensor array is empty +* Panics if the shapes are not equal or broadcastable ## Examples +Case 1: Process tensors with same shape + ```rust use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; -fn min_example() -> u32 { - let tensor = TensorTrait::new( - shape: array![2, 2, 2].span(), - data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), - ); +fn min_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 3, 1, 2].span(),); + let result = TensorTrait::min(tensors: array![tensor1, tensor2].span()); + return result; +} +>>> [0, 1, 1, 2] + + result.shape +>>> (2, 2) +``` + +Case 2: Process tensors with different shapes - // We can call `min` function as follows. - return tensor.min(); +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn min_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + let tensor2 = TensorTrait::new(shape: array![1, 2].span(), data: array![1, 4].span(),); + let result = TensorTrait::min(tensors: array![tensor1, tensor2].span()); + return result; } ->>> 0 +>>> [0, 1, 1, 4] + + result.shape +>>> (2, 2) ``` diff --git a/docs/framework/operators/tensor/tensor.min_in_tensor.md b/docs/framework/operators/tensor/tensor.min_in_tensor.md new file mode 100644 index 000000000..65ac74034 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.min_in_tensor.md @@ -0,0 +1,34 @@ +# tensor.min_in_tensor + +```rust + fn min_in_tensor(self: @Tensor) -> T; +``` + +Returns the minimum value in the tensor. + +## Args + +* `self`(`@Tensor`) - The input tensor. + +## Returns + +The minimum `T` value in the tensor. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn min_in_tensor_example() -> u32 { + let tensor = TensorTrait::new( + shape: array![2, 2, 2].span(), + data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `min_in_tensor` function as follows. + return tensor.min_in_tensor(); +} +>>> 0 +``` diff --git a/docs/framework/operators/tensor/tensor.qlinear_matmul.md b/docs/framework/operators/tensor/tensor.qlinear_matmul.md new file mode 100644 index 000000000..df66f92e4 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.qlinear_matmul.md @@ -0,0 +1,95 @@ +# tensor.qlinear_matmul + +```rust + fn qlinear_matmul(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, b: @Tensor, b_scale: @Tensor, b_zero_point: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor) -> Tensor::; +``` + +Multiplies quantized Tensors + +It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. +The quantization formula is y = saturate((x / y_scale) + y_zero_point). +It perfoms the multiplication of the two vectors once dequantized. If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes. +Then return the quantization of the result of the multiplication. +Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). +Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + +## Args + +* `self`(`@Tensor`) - The first tensor to be multiplied (a). +* `a_scale`(`@Tensor`) - Scale for input `a`. +* `a_zero_point`(`@Tensor`) - Zero point for input `a`. +* `b`(`@Tensor`) - The second tensor to be multiplied +* `b_scale`(`@Tensor`) - Scale for input `b`. +* `b_zero_point`(`@Tensor`) - Zero point for input `b`. +* `y_scale`(`@Tensor`) - Scale for outut. +* `y_zero_point`(`@Tensor`) - Zero point for output. + +## Returns + +A new `Tensor`, containing the quantized result of the multiplication of the dequantized inputs. + +## Type Constraints + +u32 tensor, not supported. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; +use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; +fn qlinear_matmul_example() -> Tensor { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(3_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(3_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![3, 1].span(), + data: array![ + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(4_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(),); + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(),); + + return a + .qlinear_matmul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); +} +>>> [14, 13] +``` \ No newline at end of file diff --git a/docs/framework/operators/tensor/tensor.round.md b/docs/framework/operators/tensor/tensor.round.md new file mode 100644 index 000000000..9a6c949eb --- /dev/null +++ b/docs/framework/operators/tensor/tensor.round.md @@ -0,0 +1,39 @@ +#tensor.round + +```rust + fn round(self: @Tensor) -> Tensor; +``` + +Computes the round value of all elements in the input tensor. + +## Args + +* `self`(`@Tensor`) - The input tensor. + + +## Returns + +A new `Tensor` of the same shape as the input tensor with +the round value of all elements in the input tensor. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; +use orion::numbers::{FixedTrait, FP16x16}; + +fn round_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![3].span(), + data: array![ + FixedTrait::new(190054, false), // 2.9 + ] + .span(), + ); + + return tensor.round(); +} +>>> [3] +``` diff --git a/docs/framework/operators/tensor/tensor.scatter.md b/docs/framework/operators/tensor/tensor.scatter.md new file mode 100644 index 000000000..439e7ab0b --- /dev/null +++ b/docs/framework/operators/tensor/tensor.scatter.md @@ -0,0 +1,62 @@ +# tensor.scatter + +```rust + fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; +``` + +Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `updates`(`Tensor`) - The updates tensor. +* `indices`(`Tensor`) - Tensor of indices. +* `axis`(`Option`) - Axis to scatter on. Default: axis=0. +* `reduction`(`Option`) - Reduction operation. Default: reduction='none'. + +## Panics + +* Panics if index values are not within bounds [-s, s-1] along axis of size s. + +## Returns + +A new `Tensor` . + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn scatter_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![3, 5].span(), + data: array![[ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0], + [ 0, 0, 0, 0, 0]].span(), + ); + let updates = TensorTrait::::new( + shape: array![3, 3].span(), + data: array![[ 1, 2, 3], + [ 4, 5, 6], + [ 7, 8, 9]].span(), + ); + let indices = TensorTrait::::new( + shape: array![3, 3].span(), + data: array![[ 0, 1, 2], + [ 2, 0, 1], + [ 1, 0, 1]].span(), + ); + + return tensor.scatter( + updates: updates + indices: indices, + axis: Option::None(()), + reduction: Option::None(()), + ); +} +>>> [[ 1, 8, 0, 0, 0], + [ 7, 2, 9, 0, 0], + [ 4, 0, 3, 0, 0]] +``` diff --git a/docs/framework/operators/tensor/tensor.where.md b/docs/framework/operators/tensor/tensor.where.md index 02d3b0059..187f12ecb 100644 --- a/docs/framework/operators/tensor/tensor.where.md +++ b/docs/framework/operators/tensor/tensor.where.md @@ -37,7 +37,7 @@ fn where_example() -> Tensor { let tensor_x = TensorTrait::::new( shape: array![2, 2].span(), data: array![2, 4, 6, 8].span(), ); - + let tensor_y = TensorTrait::::new( shape: array![2, 2].span(), data: array![1, 3, 5, 9].span(), ); diff --git a/nodegen/node/max.py b/nodegen/node/max.py new file mode 100644 index 000000000..b1079a30c --- /dev/null +++ b/nodegen/node/max.py @@ -0,0 +1,364 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait + +class Max(RunAll): + + @staticmethod + def max_u32_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + z = np.maximum(x, y) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "max_u32_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) + y = np.random.randint(0, 6, (1, 2)).astype(np.uint32) + z = np.maximum(x, y) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "max_u32_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def max_i32_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + z = np.maximum(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "max_i32_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int32) + y = np.random.randint(0, 6, (1, 2)).astype(np.int32) + z = np.maximum(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "max_i32_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def max_i8_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + z = np.maximum(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + + name = "max_i8_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int8) + y = np.random.randint(0, 6, (1, 2)).astype(np.int8) + z = np.maximum(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + + name = "max_i8_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def max_fp8x23_two_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.maximum(x, y) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "max_fp8x23_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.maximum(x, y) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "max_fp8x23_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def max_fp16x16_two_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.maximum(x, y) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "max_fp16x16_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.maximum(x, y) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "max_fp16x16_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::max(array![input_0, input_1].span());", name) + + default() + broadcast() + + + @staticmethod + def max_u32_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + m = Tensor(Dtype.U32, m.shape, m.flatten()) + + name = "max_u32_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) + y = np.random.randint(0, 6, (1, 2)).astype(np.uint32) + z = np.random.randint(0, 6, (1, 1)).astype(np.uint32) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + m = Tensor(Dtype.U32, m.shape, m.flatten()) + + name = "max_u32_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def max_i32_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + m = Tensor(Dtype.I32, m.shape, m.flatten()) + + name = "max_i32_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int32) + y = np.random.randint(0, 6, (1, 2)).astype(np.int32) + z = np.random.randint(0, 6, (1, 1)).astype(np.int32) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + m = Tensor(Dtype.I32, m.shape, m.flatten()) + + name = "max_i32_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def max_i8_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + m = Tensor(Dtype.I8, m.shape, m.flatten()) + + name = "max_i8_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int8) + y = np.random.randint(0, 6, (1, 2)).astype(np.int8) + z = np.random.randint(0, 6, (1, 1)).astype(np.int8) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + m = Tensor(Dtype.I8, m.shape, m.flatten()) + + name = "max_i8_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def max_fp8x23_three_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + m = Tensor(Dtype.FP8x23, m.shape, to_fp( + m.flatten(), FixedImpl.FP8x23)) + + name = "max_fp8x23_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.random.randint(-3, 3, (1, 1)).astype(np.float64) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + m = Tensor(Dtype.FP8x23, m.shape, to_fp( + m.flatten(), FixedImpl.FP8x23)) + + name = "max_fp8x23_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def max_fp16x16_three_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + m = Tensor(Dtype.FP16x16, m.shape, to_fp( + m.flatten(), FixedImpl.FP16x16)) + + name = "max_fp16x16_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.random.randint(-3, 3, (1, 1)).astype(np.float64) + m = np.maximum(np.maximum(x, y), z) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + m = Tensor(Dtype.FP16x16, m.shape, to_fp( + m.flatten(), FixedImpl.FP16x16)) + + name = "max_fp16x16_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::max(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() \ No newline at end of file diff --git a/nodegen/node/min.py b/nodegen/node/min.py new file mode 100644 index 000000000..a6299cea0 --- /dev/null +++ b/nodegen/node/min.py @@ -0,0 +1,364 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait + +class Min(RunAll): + + @staticmethod + def min_u32_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + z = np.minimum(x, y) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "min_u32_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) + y = np.random.randint(0, 6, (1, 2)).astype(np.uint32) + z = np.minimum(x, y) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "min_u32_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def min_i32_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + z = np.minimum(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "min_i32_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int32) + y = np.random.randint(0, 6, (1, 2)).astype(np.int32) + z = np.minimum(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "min_i32_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def min_i8_two_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + z = np.minimum(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + + name = "min_i8_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int8) + y = np.random.randint(0, 6, (1, 2)).astype(np.int8) + z = np.minimum(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + + name = "min_i8_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def min_fp8x23_two_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.minimum(x, y) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "min_fp8x23_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.minimum(x, y) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "min_fp8x23_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + default() + broadcast() + + @staticmethod + def min_fp16x16_two_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.minimum(x, y) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "min_fp16x16_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.minimum(x, y) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "min_fp16x16_broadcast_two_tensors" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::min(array![input_0, input_1].span());", name) + + default() + broadcast() + + + @staticmethod + def min_u32_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + m = Tensor(Dtype.U32, m.shape, m.flatten()) + + name = "min_u32_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) + y = np.random.randint(0, 6, (1, 2)).astype(np.uint32) + z = np.random.randint(0, 6, (1, 1)).astype(np.uint32) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + m = Tensor(Dtype.U32, m.shape, m.flatten()) + + name = "min_u32_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def min_i32_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + m = Tensor(Dtype.I32, m.shape, m.flatten()) + + name = "min_i32_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int32) + y = np.random.randint(0, 6, (1, 2)).astype(np.int32) + z = np.random.randint(0, 6, (1, 1)).astype(np.int32) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + m = Tensor(Dtype.I32, m.shape, m.flatten()) + + name = "min_i32_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def min_i8_three_tensors(): + def default(): + x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + z = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + m = Tensor(Dtype.I8, m.shape, m.flatten()) + + name = "min_i8_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(0, 6, (2, 2)).astype(np.int8) + y = np.random.randint(0, 6, (1, 2)).astype(np.int8) + z = np.random.randint(0, 6, (1, 1)).astype(np.int8) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.I8, z.shape, z.flatten()) + m = Tensor(Dtype.I8, m.shape, m.flatten()) + + name = "min_i8_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def min_fp8x23_three_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + m = Tensor(Dtype.FP8x23, m.shape, to_fp( + m.flatten(), FixedImpl.FP8x23)) + + name = "min_fp8x23_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.random.randint(-3, 3, (1, 1)).astype(np.float64) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + m = Tensor(Dtype.FP8x23, m.shape, to_fp( + m.flatten(), FixedImpl.FP8x23)) + + name = "min_fp8x23_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() + + @staticmethod + def min_fp16x16_three_tensors(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + z = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + m = Tensor(Dtype.FP16x16, m.shape, to_fp( + m.flatten(), FixedImpl.FP16x16)) + + name = "min_fp16x16_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.random.randint(-3, 3, (1, 1)).astype(np.float64) + m = np.minimum(np.minimum(x, y), z) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + m = Tensor(Dtype.FP16x16, m.shape, to_fp( + m.flatten(), FixedImpl.FP16x16)) + + name = "min_fp16x16_broadcast_three_tensors" + make_node([x, y, z], [m], name) + make_test([x, y, z], m, "TensorTrait::min(array![input_0, input_1, input_2].span());", name) + + default() + broadcast() diff --git a/nodegen/node/round.py b/nodegen/node/round.py new file mode 100644 index 000000000..1d12c3fdc --- /dev/null +++ b/nodegen/node/round.py @@ -0,0 +1,29 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + +class Round(RunAll): + + @staticmethod + def round_fp8x23(): + x = np.array([0.1, 0.5, 0.9, 1.2, 1.5, 1.8, 2.3, 2.5, 2.7, -1.1, -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float64) + y = np.array([0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, -1.0, -2.0, -2.0, -2.0, -3.0, -3.0]).astype(np.float64) + + 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 = "round_fp8x23" + make_node([x], [y], name) + make_test([x], y, "input_0.round()", name) + + @staticmethod + def round_fp16x16(): + x = np.array([0.1, 0.5, 0.9, 1.2, 1.5, 1.8, 2.3, 2.5, 2.7, -1.1, -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float64) + y = np.array([0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, -1.0, -2.0, -2.0, -2.0, -3.0, -3.0]).astype(np.float64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp(x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) + + name = "round_fp16x16" + make_node([x], [y], name) + make_test([x], y, "input_0.round()", name) \ No newline at end of file diff --git a/nodegen/node/scatter.py b/nodegen/node/scatter.py new file mode 100644 index 000000000..3e833a840 --- /dev/null +++ b/nodegen/node/scatter.py @@ -0,0 +1,439 @@ +import numpy as np +import torch +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl, Trait + +# The below ScatterElements' numpy implementation is from https://stackoverflow.com/a/46204790/11767360 +def scatter_elements(data, indices, updates, axis=0, reduction="none"): # type: ignore + if axis < 0: + axis = data.ndim + axis + + idx_xsection_shape = indices.shape[:axis] + indices.shape[axis + 1 :] + + def make_slice(arr, axis, i): # type: ignore + slc = [slice(None)] * arr.ndim + slc[axis] = i + return slc + + def unpack(packed): # type: ignore + unpacked = packed[0] + for i in range(1, len(packed)): + unpacked = unpacked, packed[i] + return unpacked + + def make_indices_for_duplicate(idx): # type: ignore + final_idx = [] + for i in range(len(idx[0])): + final_idx.append(tuple(idx_element[i] for idx_element in idx)) + return list(final_idx) + + # We use indices and axis parameters to create idx + # idx is in a form that can be used as a NumPy advanced indices for scattering of updates param. in data + idx = [ + [ + unpack(np.indices(idx_xsection_shape).reshape(indices.ndim - 1, -1)), + indices[tuple(make_slice(indices, axis, i))].reshape(1, -1)[0], + ] + for i in range(indices.shape[axis]) + ] + idx = list(np.concatenate(idx, axis=1)) + idx.insert(axis, idx.pop()) + + # updates_idx is a NumPy advanced indices for indexing of elements in the updates + updates_idx = list(idx) + updates_idx.pop(axis) + updates_idx.insert( + axis, np.repeat(np.arange(indices.shape[axis]), np.prod(idx_xsection_shape)) + ) + + scattered = np.copy(data) + if reduction == "none": + scattered[tuple(idx)] = updates[tuple(updates_idx)] + else: + idx, updates_idx = make_indices_for_duplicate(idx), make_indices_for_duplicate( + updates_idx + ) + for iter, idx_set in enumerate(idx): + if reduction == "add": + scattered[idx_set] += updates[updates_idx[iter]] + elif reduction == "mul": + scattered[idx_set] *= updates[updates_idx[iter]] + elif reduction == "max": + scattered[idx_set] = np.maximum( + scattered[idx_set], updates[updates_idx[iter]] + ) + elif reduction == "min": + scattered[idx_set] = np.minimum( + scattered[idx_set], updates[updates_idx[iter]] + ) + return scattered + +class Scatter(RunAll): + + @staticmethod + def scatter_fp16x16(): + + def scatter(): + def default(): + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'none') + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.FP16x16, x2.shape, to_fp(x2.flatten(), FixedImpl.FP16x16)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "scatter_fp16x16_3d_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", + file_name= name) + + def axis_1(): + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'none') + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.FP16x16, x2.shape, to_fp(x2.flatten(), FixedImpl.FP16x16)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "scatter_fp16x16_3d_axis1" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", + file_name= name) + + def axis_1_add(): + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'add') + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.FP16x16, x2.shape, to_fp(x2.flatten(), FixedImpl.FP16x16)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "scatter_fp16x16_3d_axis1_add" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add'))", + file_name= name) + + default() + axis_1() + axis_1_add() + scatter() + + @staticmethod + def scatter_fp8x23(): + + def scatter(): + def default(): + + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'none') + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.FP8x23, x2.shape, to_fp(x2.flatten(), FixedImpl.FP8x23)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "scatter_fp8x23_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", + file_name= name) + + + def axis1(): + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'none') + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.FP8x23, x2.shape, to_fp(x2.flatten(), FixedImpl.FP8x23)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "scatter_fp8x23_axis1" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", + file_name= name) + + def axis1_mul(): + x1 = np.zeros((3, 3)).astype(np.int64) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'mul') + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.FP8x23, x2.shape, to_fp(x2.flatten(), FixedImpl.FP8x23)) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "scatter_fp8x23_mul" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul'))", + file_name= name) + + default() + axis1() + axis1_mul() + scatter() + + @staticmethod + def scatter_i8(): + + def scatter_3D(): + def default(): + x1 = np.zeros((3, 3)).astype(np.int8) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int8) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'none') + + x1 = Tensor(Dtype.I8, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I8, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "scatter_i8_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", + file_name= name) + + def axis1(): + x1 = np.zeros((3, 3)).astype(np.int8) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int8) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'none') + + x1 = Tensor(Dtype.I8, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I8, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "scatter_i8_axis1" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", + file_name= name) + + + def axis1_max(): + x1 = np.zeros((3, 3)).astype(np.int8) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int8) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'max') + + x1 = Tensor(Dtype.I8, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I8, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "scatter_i8_axis1_max" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max'))", + file_name= name) + + default() + axis1() + axis1_max() + scatter_3D() + + + @staticmethod + def scatter_i32(): + def scatter_3D(): + def default(): + x1 = np.zeros((3, 3)).astype(np.int32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'none') + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "scatter_i8_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", + file_name= name) + + def axis1(): + x1 = np.zeros((3, 3)).astype(np.int32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'none') + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "scatter_i8_axis1" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", + file_name= name) + + def axis_min(): + x1 = np.zeros((3, 3)).astype(np.int32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'min') + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.I32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "scatter_i8_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('min'))", + file_name= name) + + default() + axis1() + axis_min() + scatter_3D() + + + @staticmethod + def scatter_u32(): + + def scatter_3D(): + def default(): + x1 = np.zeros((3, 3)).astype(np.uint32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.uint32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'none') + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "scatter_u32_default" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", + file_name= name) + + + def axis1(): + x1 = np.zeros((3, 3)).astype(np.uint32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.uint32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 1, 'none') + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "scatter_u32_axis1" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", + file_name= name) + + def axis_add(): + x1 = np.zeros((3, 3)).astype(np.uint32) + x2 = np.arange(1, 10).reshape((3, 3)).astype(np.uint32) + x3 = np.array( + [[0,1,2], + [2,0,1], + [1,0,1]], + ) + y = scatter_elements(x1, x3, x2, 0, 'add') + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + x3 = Tensor(Dtype.U32, x3.shape, x3.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "scatter_u32_add" + make_node([x1, x2, x3], [y], name) + make_test( + inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add'))", + file_name= name) + + default() + axis1() + axis_add() + scatter_3D() \ No newline at end of file diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 976102b52..30403831f 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -12,6 +12,11 @@ use orion::operators::tensor::implementations::tensor_fp8x23::{ FP8x23TensorPartialEq, }; +use orion::operators::tensor::implementations::tensor_fp32x32::{ + FP32x32Tensor, FP32x32TensorAdd, FP32x32TensorSub, FP32x32TensorMul, FP32x32TensorDiv, + FP32x32TensorPartialEq, +}; + use orion::operators::tensor::implementations::tensor_fp16x16::{ FP16x16Tensor, FP16x16TensorAdd, FP16x16TensorSub, FP16x16TensorMul, FP16x16TensorDiv, FP16x16TensorPartialEq, diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 94a9baac7..8a3ae7e68 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -46,6 +46,8 @@ impl TensorSerde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -184,10 +188,10 @@ trait TensorTrait { /// ``` /// fn at(self: @Tensor, indices: Span) -> T; - /// # tensor.min + /// # tensor.min_in_tensor /// /// ```rust - /// fn min(self: @Tensor) -> T; + /// fn min_in_tensor(self: @Tensor) -> T; /// ``` /// /// Returns the minimum value in the tensor. @@ -207,23 +211,88 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn min_example() -> u32 { + /// fn min_in_tensor_example() -> u32 { /// let tensor = TensorTrait::new( /// shape: array![2, 2, 2].span(), /// data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), /// ); /// - /// // We can call `min` function as follows. - /// return tensor.min(); + /// // We can call `min_in_tensor` function as follows. + /// return tensor.min_in_tensor(); /// } /// >>> 0 /// ``` /// - fn min(self: @Tensor) -> T; - /// # tensor.max + fn min_in_tensor(self: @Tensor) -> T; + /// # tensor.min + /// + /// ```rust + /// fn min(tensors: Span>) -> Tensor; + /// ``` + /// + /// Returns the element-wise minumum values from a list of input tensors + /// The input tensors must have either: + /// * Exactly the same shape + /// * The same number of dimensions and the length of each dimension is either a common length or 1. + /// + /// ## Args + /// + /// * `tensors`(` Span>,`) - Array of the input tensors + /// + /// ## Returns + /// + /// A new `Tensor` containing the element-wise minimum values + /// + /// ## Panics + /// + /// * Panics if tensor array is empty + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Examples + /// + /// Case 1: Process tensors with same shape + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn min_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 3, 1, 2].span(),); + /// let result = TensorTrait::min(tensors: array![tensor1, tensor2].span()); + /// return result; + /// } + /// >>> [0, 1, 1, 2] + /// + /// result.shape + /// >>> (2, 2) + /// ``` + /// + /// Case 2: Process tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn min_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![1, 2].span(), data: array![1, 4].span(),); + /// let result = TensorTrait::min(tensors: array![tensor1, tensor2].span()); + /// return result; + /// } + /// >>> [0, 1, 1, 4] + /// + /// result.shape + /// >>> (2, 2) + /// ``` + /// + fn min(tensors: Span>) -> Tensor; + /// # tensor.max_in_tensor /// /// ```rust - /// fn max(self: @Tensor) -> T; + /// fn max_in_tensor(self: @Tensor) -> T; /// ``` /// /// Returns the maximum value in the tensor. @@ -243,18 +312,83 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn max_example() -> u32 { + /// fn max_in_tensor_example() -> u32 { /// let tensor = TensorTrait::new( /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), /// ); /// - /// // We can call `max` function as follows. - /// return tensor.max(); + /// // We can call `max_in_tensor` function as follows. + /// return tensor.max_in_tensor(); /// } /// >>> 7 /// ``` /// - fn max(self: @Tensor) -> T; + fn max_in_tensor(self: @Tensor) -> T; + /// # tensor.max + /// + /// ```rust + /// fn max(tensors: Span>) -> Tensor; + /// ``` + /// + /// Returns the element-wise maximum values from a list of input tensors + /// The input tensors must have either: + /// * Exactly the same shape + /// * The same number of dimensions and the length of each dimension is either a common length or 1. + /// + /// ## Args + /// + /// * `tensors`(` Span>,`) - Array of the input tensors + /// + /// ## Returns + /// + /// A new `Tensor` containing the element-wise maximum values + /// + /// ## Panics + /// + /// * Panics if tensor array is empty + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Examples + /// + /// Case 1: Process tensors with same shape + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn max_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 3, 1, 2].span(),); + /// let result = TensorTrait::max(tensors: array![tensor1, tensor2].span()); + /// return result; + /// } + /// >>> [0, 3, 2, 3] + /// + /// result.shape + /// >>> (2, 2) + /// ``` + /// + /// Case 2: Process tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn max_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![1, 2].span(), data: array![1, 4].span(),); + /// let result = TensorTrait::max(tensors: array![tensor1, tensor2].span()); + /// return result; + /// } + /// >>> [1, 4, 2, 4] + /// + /// result.shape + /// >>> (2, 2) + /// ``` + /// + fn max(tensors: Span>) -> Tensor; /// # tensor.stride /// /// ```rust @@ -2405,6 +2539,111 @@ trait TensorTrait { fn dequantize_linear( self: @Tensor, x_scale: @Tensor, x_zero_point: @Tensor ) -> Tensor::; + /// # tensor.qlinear_matmul + /// + /// ```rust + /// fn qlinear_matmul(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, b: @Tensor, b_scale: @Tensor, b_zero_point: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor) -> Tensor::; + /// ``` + /// + /// Multiplies quantized Tensors + /// + /// It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. + /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). + /// It perfoms the multiplication of the two vectors once dequantized. If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes. + /// Then return the quantization of the result of the multiplication. + /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). + /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `a_scale`(`@Tensor`) - Scale for input `a`. + /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. + /// * `b`(`@Tensor`) - The second tensor to be multiplied + /// * `b_scale`(`@Tensor`) - Scale for input `b`. + /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. + /// * `y_scale`(`@Tensor`) - Scale for outut. + /// * `y_zero_point`(`@Tensor`) - Zero point for output. + /// + /// ## Returns + /// + /// A new `Tensor`, containing the quantized result of the multiplication of the dequantized inputs. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// fn qlinear_matmul_example() -> Tensor { + /// let a = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 3].span(), + /// data: array![ + /// IntegerTrait::::new(3_u8, false), + /// IntegerTrait::::new(4_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(2_u8, false), + /// IntegerTrait::::new(4_u8, false), + /// IntegerTrait::::new(3_u8, false) + /// ] + /// .span(), + /// ); + /// let b = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![3, 1].span(), + /// data: array![ + /// IntegerTrait::::new(4_u8, false), + /// IntegerTrait::::new(8_u8, false), + /// IntegerTrait::::new(4_u8, false) + /// ] + /// .span(), + /// ); + /// + /// let a_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + /// let a_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + /// let b_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + /// let b_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + /// + /// let y_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(),); + /// let y_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(),); + /// + /// return a + /// .qlinear_matmul( + /// @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + /// ); + /// } + /// >>> [14, 13] + /// ``` + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor::; /// # tensor.slice /// /// ```rust @@ -2868,6 +3107,111 @@ trait TensorTrait { /// ``` /// fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor; + /// #tensor.round + /// + /// ```rust + /// fn round(self: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the round value of all elements in the input tensor. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// + /// + /// ## Returns + /// + /// A new `Tensor` of the same shape as the input tensor with + /// the round value of all elements in the input tensor. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; + /// use orion::numbers::{FixedTrait, FP16x16}; + /// + /// fn round_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![3].span(), + /// data: array![ + /// FixedTrait::new(190054, false), // 2.9 + /// ] + /// .span(), + /// ); + /// + /// return tensor.round(); + /// } + /// >>> [3] + /// ``` + /// + fn round(self: @Tensor) -> Tensor; + /// # tensor.scatter + /// + /// ```rust + /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// ``` + /// + /// Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `updates`(`Tensor`) - The updates tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// * `axis`(`Option`) - Axis to scatter on. Default: axis=0. + /// * `reduction`(`Option`) - Reduction operation. Default: reduction='none'. + /// + /// ## Panics + /// + /// * Panics if index values are not within bounds [-s, s-1] along axis of size s. + /// + /// ## Returns + /// + /// A new `Tensor` . + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn scatter_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![3, 5].span(), + /// data: array![[ 0, 0, 0, 0, 0], + /// [ 0, 0, 0, 0, 0], + /// [ 0, 0, 0, 0, 0]].span(), + /// ); + /// let updates = TensorTrait::::new( + /// shape: array![3, 3].span(), + /// data: array![[ 1, 2, 3], + /// [ 4, 5, 6], + /// [ 7, 8, 9]].span(), + /// ); + /// let indices = TensorTrait::::new( + /// shape: array![3, 3].span(), + /// data: array![[ 0, 1, 2], + /// [ 2, 0, 1], + /// [ 1, 0, 1]].span(), + /// ); + /// + /// return tensor.scatter( + /// updates: updates + /// indices: indices, + /// axis: Option::None(()), + /// reduction: Option::None(()), + /// ); + /// } + /// >>> [[ 1, 8, 0, 0, 0], + /// [ 7, 2, 9, 0, 0], + /// [ 4, 0, 3, 0, 0]] + /// ``` + /// + fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index f726c8d1e..508134a2f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -20,12 +20,20 @@ impl FP16x16Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP16x16 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP16x16 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP16x16 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP16x16 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -198,6 +206,30 @@ impl FP16x16Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, @@ -245,6 +277,17 @@ impl FP16x16Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c4f2de169..d87f6dd9d 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -20,12 +20,20 @@ impl FP16x16WTensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP16x16W { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP16x16W { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP16x16W { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP16x16W { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -204,6 +212,19 @@ impl FP16x16WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, @@ -255,6 +276,16 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 5f78a86f6..30b85b755 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -21,12 +21,20 @@ impl FP32x32Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP32x32 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP32x32 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP32x32 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP32x32 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -199,6 +207,30 @@ impl FP32x32Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, @@ -246,6 +278,16 @@ impl FP32x32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index d9e540293..c86420354 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -21,12 +21,20 @@ impl FP64x64Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP64x64 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP64x64 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP64x64 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP64x64 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -199,6 +207,30 @@ impl FP64x64Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, @@ -246,6 +278,17 @@ impl FP64x64Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 153f179ef..3ddcf0369 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -20,12 +20,20 @@ impl FP8x23Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP8x23 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP8x23 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP8x23 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP8x23 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -198,6 +206,30 @@ impl FP8x23Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, @@ -245,6 +277,16 @@ impl FP8x23Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index f594eec4d..3c36ee737 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -20,12 +20,20 @@ impl FP8x23WTensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> FP8x23W { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> FP8x23W { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> FP8x23W { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> FP8x23W { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -198,6 +206,19 @@ impl FP8x23WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, @@ -245,7 +266,18 @@ impl FP8x23WTensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } -} + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } + +} /// Implements addition for `Tensor` using the `Add` trait. impl FP8x23WTensorAdd< diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 057fb6853..bf0592c41 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -21,12 +21,20 @@ impl I32Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> i32 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> i32 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> i32 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> i32 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -199,6 +207,31 @@ impl I32Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + + fn slice( self: @Tensor, starts: Span, @@ -244,6 +277,16 @@ impl I32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index ae2662f0d..bfadc3be5 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -20,12 +20,20 @@ impl I8Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> i8 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> i8 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> i8 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> i8 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -198,6 +206,31 @@ impl I8Tensor of TensorTrait { quantization::dequantize_linear::dequantize_linear(self, x_scale, x_zero_point) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_matmul::qlinear_matmul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + + fn slice( self: @Tensor, starts: Span, @@ -243,6 +276,16 @@ impl I8Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index fc83d35c3..2faf21b0b 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -20,12 +20,20 @@ impl U32Tensor of TensorTrait { *at_tensor(self, indices) } - fn min(self: @Tensor) -> u32 { - math::min::min_in_tensor::(*self.data) + fn min_in_tensor(self: @Tensor) -> u32 { + math::min_in_tensor::min_in_tensor::(*self.data) } - fn max(self: @Tensor) -> u32 { - math::max::max_in_tensor(*self.data) + fn min(tensors: Span>) -> Tensor { + math::min::min(tensors) + } + + fn max_in_tensor(self: @Tensor) -> u32 { + math::max_in_tensor::max_in_tensor(*self.data) + } + + fn max(tensors: Span>) -> Tensor { + math::max::max(tensors) } fn stride(self: @Tensor) -> Span { @@ -192,6 +200,19 @@ impl U32Tensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_matmul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, @@ -237,6 +258,16 @@ impl U32Tensor of TensorTrait { fn where(self: @Tensor, x: @Tensor, y: @Tensor) -> Tensor { math::where::where(self, x, y) } + + fn round(self: @Tensor) -> Tensor { + math::round::round(*self) + } + + fn scatter( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) + -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index d8c5a56f4..79404dcd5 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -1,4 +1,6 @@ +mod min_in_tensor; mod min; +mod max_in_tensor; mod max; mod reduce_sum; mod argmax; @@ -35,3 +37,5 @@ mod sign; mod and; mod neg; mod where; +mod round; +mod scatter; \ No newline at end of file diff --git a/src/operators/tensor/math/max.cairo b/src/operators/tensor/math/max.cairo index 15580c7d7..5ed703408 100644 --- a/src/operators/tensor/math/max.cairo +++ b/src/operators/tensor/math/max.cairo @@ -1,32 +1,68 @@ -use array::SpanTrait; -use option::OptionTrait; +use array::{ArrayTrait, SpanTrait}; use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::helpers::{ + broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility +}; /// Cf: TensorTrait::max docstring -fn max_in_tensor< +fn max< T, MAG, + impl TTensorTrait: TensorTrait, impl TNumber: NumberTrait, - impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( - mut vec: Span:: -) -> T { - let mut max_value: T = NumberTrait::min_value(); + tensors: Span> +) -> Tensor { + + assert(tensors.len() >= 1, 'Input tensors must be >= 1'); + + let first_tensor = *tensors.at(0); + + if tensors.len() == 1 { + return first_tensor; + } + + let mut max_shape: Span = first_tensor.shape; + let mut max_data: Span = first_tensor.data; + + let mut tensor_counter: usize = 1; loop { - match vec.pop_front() { - Option::Some(item) => { - let check_max = max_value.max(*item); - if (max_value < check_max) { - max_value = check_max; - } - }, - Option::None(_) => { break; } + if tensor_counter > tensors.len() - 1 { + break; + } + + let mut new_max_data = ArrayTrait::::new(); + + let mut current_tensor = *tensors.at(tensor_counter); + + let mut broadcasted_shape = broadcast_shape(max_shape, current_tensor.shape); + + let num_elements = len_from_shape(broadcasted_shape); + let mut n: usize = 0; + loop { + let mut indices_broadcasted = unravel_index(n, broadcasted_shape); + + let mut indices_self = broadcast_index_mapping(max_shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + + let mut max_value = NumberTrait::max(*(max_data)[indices_self], *(current_tensor.data)[indices_other]); + new_max_data.append(max_value); + + n += 1; + if n == num_elements { + break (); + }; }; + + max_shape = broadcasted_shape; + max_data = new_max_data.span(); + tensor_counter += 1; }; - return max_value; -} + return TensorTrait::::new(max_shape, max_data); +} \ No newline at end of file diff --git a/src/operators/tensor/math/max_in_tensor.cairo b/src/operators/tensor/math/max_in_tensor.cairo new file mode 100644 index 000000000..1abaf5545 --- /dev/null +++ b/src/operators/tensor/math/max_in_tensor.cairo @@ -0,0 +1,32 @@ +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::max_in_tensor docstring +fn max_in_tensor< + T, + MAG, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut vec: Span:: +) -> T { + let mut max_value: T = NumberTrait::min_value(); + + loop { + match vec.pop_front() { + Option::Some(item) => { + let check_max = max_value.max(*item); + if (max_value < check_max) { + max_value = check_max; + } + }, + Option::None(_) => { break; } + }; + }; + + return max_value; +} diff --git a/src/operators/tensor/math/min.cairo b/src/operators/tensor/math/min.cairo index 100b173f0..3577e69c0 100644 --- a/src/operators/tensor/math/min.cairo +++ b/src/operators/tensor/math/min.cairo @@ -1,32 +1,68 @@ -use array::SpanTrait; -use option::OptionTrait; +use array::{ArrayTrait, SpanTrait}; use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::helpers::{ + broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility +}; /// Cf: TensorTrait::min docstring -fn min_in_tensor< +fn min< T, MAG, + impl TTensorTrait: TensorTrait, impl TNumber: NumberTrait, - impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( - mut vec: Span:: -) -> T { - let mut min_value: T = NumberTrait::max_value(); + tensors: Span> +) -> Tensor { + + assert(tensors.len() >= 1, 'Input tensors must be >= 1'); + + let first_tensor = *tensors.at(0); + + if tensors.len() == 1 { + return first_tensor; + } + + let mut min_shape: Span = first_tensor.shape; + let mut min_data: Span = first_tensor.data; + + let mut tensor_counter: usize = 1; loop { - match vec.pop_front() { - Option::Some(item) => { - let check_min = min_value.min(*item); - if (min_value > check_min) { - min_value = check_min; - } - }, - Option::None(_) => { break; } + if tensor_counter > tensors.len() - 1 { + break; + } + + let mut new_min_data = ArrayTrait::::new(); + + let mut current_tensor = *tensors.at(tensor_counter); + + let mut broadcasted_shape = broadcast_shape(min_shape, current_tensor.shape); + + let num_elements = len_from_shape(broadcasted_shape); + let mut n: usize = 0; + loop { + let mut indices_broadcasted = unravel_index(n, broadcasted_shape); + + let mut indices_self = broadcast_index_mapping(min_shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + + let mut min_value = NumberTrait::min(*(min_data)[indices_self], *(current_tensor.data)[indices_other]); + new_min_data.append(min_value); + + n += 1; + if n == num_elements { + break (); + }; }; + + min_shape = broadcasted_shape; + min_data = new_min_data.span(); + tensor_counter += 1; }; - return min_value; -} + return TensorTrait::::new(min_shape, min_data); +} \ No newline at end of file diff --git a/src/operators/tensor/math/min_in_tensor.cairo b/src/operators/tensor/math/min_in_tensor.cairo new file mode 100644 index 000000000..b9738db1f --- /dev/null +++ b/src/operators/tensor/math/min_in_tensor.cairo @@ -0,0 +1,34 @@ +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::min_in_tensor docstring +fn min_in_tensor< + T, + MAG, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut vec: Span:: +) -> T { + let mut min_value: T = NumberTrait::max_value(); + + loop { + match vec.pop_front() { + Option::Some(item) => { + let check_min = min_value.min(*item); + if (min_value > check_min) { + min_value = check_min; + } + }, + Option::None(_) => { + break; + } + }; + }; + + return min_value; +} diff --git a/src/operators/tensor/math/round.cairo b/src/operators/tensor/math/round.cairo new file mode 100644 index 000000000..9af729b17 --- /dev/null +++ b/src/operators/tensor/math/round.cairo @@ -0,0 +1,30 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; +use traits::Into; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; + + +fn round< + T, + MAG, + impl TNumberTrait: NumberTrait, + impl FTensor: TensorTrait, + impl FCopy: Copy, + impl FDrop: Drop +>( + mut self: Tensor +) -> Tensor { + let mut result = ArrayTrait::new(); + + loop { + match self.data.pop_front() { + Option::Some(item) => { result.append((*item).round()); }, + Option::None(_) => { break; } + }; + }; + + return TensorTrait::new(self.shape, result.span()); +} diff --git a/src/operators/tensor/math/scatter.cairo b/src/operators/tensor/math/scatter.cairo new file mode 100644 index 000000000..ea26f1b7e --- /dev/null +++ b/src/operators/tensor/math/scatter.cairo @@ -0,0 +1,275 @@ +use alexandria_data_structures::array_ext::SpanTraitExt; +use array::ArrayTrait; +use array::SpanTrait; + +use core::traits::Into; +use debug::PrintTrait; +use core::traits::TryInto; +use core::serde::Serde; +use core::traits::Destruct; +use option::OptionTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; +use dict::Felt252DictTrait; +use nullable::{nullable_from_box, match_nullable, FromNullableResult}; +/// Cf: TensorTrait::scatter docstring +fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDrop: Drop, impl TAddEq: AddEq, + impl TMulEq: MulEq, impl TPartialOrd: PartialOrd, impl TPartialEq: PartialEq,>( + self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option +) -> Tensor { + let mut axis = match axis { + Option::Some(val) => val, + Option::None(_) => 0 + }; + + let reduction = match reduction { + Option::Some(val) => val, + Option::None(_) => 'none' + }; + + let data_rank = (*self.shape).len(); + let indices_rank = (indices.shape).len(); + let updates_rank = (updates.shape).len(); + + assert((data_rank == updates_rank) & (updates_rank == indices_rank), 'must be same rank'); + let data_shape = *self.shape; + let ind_max = indices.data.max().unwrap(); + assert(ind_max < *data_shape.at(axis), 'index is out of bound'); + + let data_shape = *self.shape; + let mut indices_shape = indices.shape; + let updates_shape = updates.shape; + assert((*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), 'shape must be same'); + + let mut output_data = ArrayTrait::new(); + let mut data_indices = indices.data; + let mut data_updates = updates.data; + let mut indices_updates: Felt252Dict = Default::default(); + let mut indices_updates_reduction: Felt252Dict>> = Default::default(); + + let mut data_shape_copy = data_shape; + let mut indices_shape_copy = indices_shape; + + let data_loop_first = *data_shape_copy.pop_front().unwrap(); + let indices_loop_first = *indices_shape_copy.pop_front().unwrap(); + + let mut indices_loop: usize = 1; + let mut data_loop:usize = 1; + + if (axis == 0) { + loop { + match indices_shape_copy.pop_front() { + Option::Some(val) => { + let d = *val; + indices_loop *= *val; + }, + Option::None(_) => { + break; + } + }; + }; + + loop { + match data_shape_copy.pop_front() { + Option::Some(val) => { + let d = *val; + data_loop *= *val; + }, + Option::None(_) => { + break; + } + }; + }; + } + + let mut transpose = false; + if ((data_rank > 2) & (axis == 1)) { + let index = indices.transpose(axes: array![0, 2, 1].span()); + let update = updates.transpose(axes: array![0, 2, 1].span()); + data_indices = index.data; + data_updates = update.data; + indices_shape = index.shape; + axis = 2; + transpose = true; + } + + if (axis == (data_rank - 1) ){ + data_loop = *data_shape_copy.pop_back().unwrap(); + indices_loop = *indices_shape_copy.pop_back().unwrap(); + } + + let mut total_count: usize = 0; + let mut shift = 0; + + loop { + let mut i: usize = 0; + let mut result:usize = 0; + + match data_indices.pop_front() { + Option::Some(val) => { + let value = total_count+1; + + if (axis == 0) { + let column = total_count % indices_loop; + result = (*val * data_loop) + (column); + if ((result % *data_shape.at(data_rank -1)) != total_count % *indices_shape.at(data_rank -1)){ + result += (*data_shape.at(data_rank -1) - *indices_shape.at(data_rank -1)); + } + } + + if( axis == (data_rank - 1)) { + let mut row = total_count / indices_loop; + if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))){ + shift = ( *data_shape.at(1) - *indices_shape.at(1)); + } + + result = *val + (data_loop * (row + shift)); + } + + if (reduction == 'none') { + indices_updates.insert(result.into(), value.into()); + } + else { + let mut arr = ArrayTrait::new(); + + let val = indices_updates_reduction.get(result.into()); + let mut a = ArrayTrait::new(); + let mut span = match match_nullable(val) { + FromNullableResult::Null(()) => a.span(), + FromNullableResult::NotNull(val) => val.unbox(), + }; + + loop { + match span.pop_front() { + Option::Some(val) => { + arr.append(*val); + }, + Option::None(_) => { + break; + } + }; + }; + arr.append(total_count); + indices_updates_reduction.insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); + } + total_count += 1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut data = *self.data; + let mut i: usize = 0; + loop { + match data.pop_front() { + Option::Some(val) => { + if (reduction == 'none') { + let value = indices_updates.get(i.into()); + if (value == 0) { + output_data.append(*val); + } + else { + let data_value = data_updates[value-1]; + output_data.append(*data_value); + } + } + else { + let value = indices_updates_reduction.get(i.into()); + let mut a = ArrayTrait::new(); + let mut span = match match_nullable(value) { + FromNullableResult::Null(()) => a.span(), + FromNullableResult::NotNull(value) => value.unbox(), + }; + + if (span.len() == 0) { + output_data.append(*val); + } + + else { + // let mut result = *data_updates.at(*span.pop_front().unwrap()); + let mut result = *val; + + + if (reduction == 'add') { + loop { + match span.pop_front() { + Option::Some(val) => { + result += *data_updates[*val]; + }, + Option::None(_) => { + break; + } + }; + }; + output_data.append(result); + } + + if (reduction == 'mul') { + loop { + match span.pop_front() { + Option::Some(val) => { + result *= *data_updates[*val]; + }, + Option::None(_) => { + break; + } + }; + }; + output_data.append(result); + } + + if (reduction == 'max') { + loop { + match span.pop_front() { + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder > result){ + result = holder; + } + }, + Option::None(_) => { + break; + } + }; + }; + output_data.append(result); + } + + if (reduction == 'min') { + loop { + match span.pop_front() { + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder < result){ + result = holder; + } + }, + Option::None(_) => { + break; + } + }; + }; + output_data.append(result); + } + } + } + + i+=1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut output_tensor = TensorTrait::::new(*self.shape, output_data.span()); + + if (transpose == true) { + output_tensor = output_tensor.transpose(axes: array![0, 2, 1].span()) + } + + return output_tensor; +} diff --git a/src/operators/tensor/quantization.cairo b/src/operators/tensor/quantization.cairo index 0ed0c12d8..88baf9e3f 100644 --- a/src/operators/tensor/quantization.cairo +++ b/src/operators/tensor/quantization.cairo @@ -1,2 +1,3 @@ mod quantize_linear; mod dequantize_linear; +mod qlinear_matmul; diff --git a/src/operators/tensor/quantization/qlinear_matmul.cairo b/src/operators/tensor/quantization/qlinear_matmul.cairo new file mode 100644 index 000000000..b9d734a9b --- /dev/null +++ b/src/operators/tensor/quantization/qlinear_matmul.cairo @@ -0,0 +1,204 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::{NumberTrait}; +use orion::operators::tensor::quantization::dequantize_linear::dequantize_linear; +use orion::operators::tensor::quantization::quantize_linear::quantize_linear; +use orion::operators::tensor::{TensorTrait, Tensor}; + + +/// Cf: TensorTrait::qlinear_matmul docstring +fn qlinear_matmul< + T, + MAG, + Q, + impl TTensor: TensorTrait, + impl QTensor: TensorTrait, + impl QIntoT: Into, + impl QTensorIntoTTensor: Into, Tensor>, + impl TAdd: Add, + impl TSub: Sub, + impl TDiv: Div, + impl TMul: Mul, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl TTensorDiv: Div>, + impl TPartialOrd: PartialOrd, + impl TNumber: NumberTrait, + impl TTryInto: TryInto, + //impl TTensorTryInto: TryInto, Tensor>, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, + impl QCopy: Copy, + impl QDrop: Drop, +>( + a: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor, + min: T, + max: T +) -> Tensor { + let a_shape = *a.shape; + let b_shape = *b.shape; + + let a_ndim = (a_shape).len(); + let b_ndim = (b_shape).len(); + + //! Case: Both tensors are max 2-dimensional + if a_ndim <= 2 && b_ndim <= 2 { + let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); + let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); + + let mut x = dequantized_a.matmul(@dequantized_b); + + return quantize_linear(@x, y_scale, y_zero_point, min, max); + } + + // (D1, D2, M, K) * (D1, D2, K, N) -> (D1, D2, M, N) + assert(a_ndim == b_ndim, 'dim missmatch'); + let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); + let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); + let mut x_shape = ArrayTrait::::new(); + let mut x_data = ArrayTrait::::new(); + + assert(a_shape[a_ndim - 1] == b_shape[b_ndim - 2], 'incompatible dim for matmul'); + + let m = *a_shape[a_ndim - 2]; + let k = *a_shape[a_ndim - 1]; + let n = *b_shape[b_ndim - 1]; + + let mut a_shape_reduced = ArrayTrait::::new(); + a_shape_reduced.append(m); + a_shape_reduced.append(k); + + let mut b_shape_reduced = ArrayTrait::::new(); + b_shape_reduced.append(k); + b_shape_reduced.append(n); + + let mut i = 0; + loop { + if i == stride(a_shape) / (m * k) { + break; + }; + + result_updates( + @subtensor(@dequantized_a, i * (m * k), a_shape_reduced.span()), + @subtensor(@dequantized_b, i * (k * n), b_shape_reduced.span()), + ref x_data + ); + i += 1; + }; + x_shape(ref x_shape, a_shape, m, n); + let x = TensorTrait::new(x_shape.span(), x_data.span()); + return quantize_linear(@x, y_scale, y_zero_point, min, max); +} + +fn x_shape(ref x_data: Array, mut shape: Span, m: usize, n: usize) { + loop { + if shape.len() == 2 { + break; + } + match shape.pop_front() { + Option::Some(elem) => { x_data.append(*elem); }, + Option::None(_) => { break; } + }; + }; + x_data.append(m); + x_data.append(n); +} + +fn stride(mut shape: Span) -> usize { + let shape_len = shape.len(); + assert(shape_len > 0, 'shape cannot be empty'); + + let mut accumulated: usize = 1; + loop { + match shape.pop_back() { + Option::Some(i) => { accumulated *= *i; }, + Option::None(_) => { break; } + }; + }; + return accumulated; +} + +fn subtensor, impl TCopy: Copy, impl TDrop: Drop>( + x: @Tensor, start: usize, shape: Span +) -> Tensor:: { + let mut data = ArrayTrait::::new(); + let mut stride = stride(shape); + let mut i = 0; + + loop { + if i == stride { + break; + } + data.append(*x.data[start + i]); + i += 1; + }; + return TensorTrait::new(shape, data.span()); +} + + +fn result_updates< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TMul: Mul, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + mat1: @Tensor, mat2: @Tensor, ref result_data: Array +) { + let m = *mat1.shape[0]; + let n = *mat1.shape[1]; + let p = *mat2.shape[1]; + + let mat1 = *mat1.data; + let mat2 = *mat2.data; + + let mut result_shape = ArrayTrait::new(); + result_shape.append(m); + result_shape.append(p); + + let mut i = 0_usize; + loop { + if i == m { + break (); + } + + let mut j = 0_usize; + loop { + if j == p { + break (); + } + + let mut sum: T = NumberTrait::zero(); + let mut k = 0_usize; + loop { + if k == n { + break (); + } + + let mat1_index = i * n + k; + let mat2_index = k * p + j; + sum += *mat1[mat1_index] * *mat2[mat2_index]; + + k += 1; + }; + + result_data.append(sum); + j += 1; + }; + + i += 1; + }; +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index d867b2277..c0950a35f 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -448,22 +448,42 @@ mod identity_fP8x23; mod identity_i32; mod identity_i8; mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; mod where_fp16x16; mod where_fp16x16_broadcast; mod where_fp8x23; @@ -474,4 +494,37 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; - +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo new file mode 100644 index 000000000..2660e4676 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_fp16x16_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..fc8d87773 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,18 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..352adab6a --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..406f91365 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..b743e5482 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo new file mode 100644 index 000000000..b5ac6fdcd --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_fp16x16_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..92152cd37 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,18 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..4cc6309d7 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..37ead1117 --- /dev/null +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_three_tensors.cairo b/tests/nodes/max_fp16x16_three_tensors.cairo new file mode 100644 index 000000000..8ca7dfebe --- /dev/null +++ b/tests/nodes/max_fp16x16_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_fp16x16_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo new file mode 100644 index 000000000..bb6a7efe8 --- /dev/null +++ b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo new file mode 100644 index 000000000..71edb4da9 --- /dev/null +++ b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo new file mode 100644 index 000000000..9845fefbe --- /dev/null +++ b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo new file mode 100644 index 000000000..139ae932a --- /dev/null +++ b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_two_tensors.cairo b/tests/nodes/max_fp16x16_two_tensors.cairo new file mode 100644 index 000000000..98b522b3d --- /dev/null +++ b/tests/nodes/max_fp16x16_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_fp16x16_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo new file mode 100644 index 000000000..1e70f825c --- /dev/null +++ b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo new file mode 100644 index 000000000..c766b1157 --- /dev/null +++ b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo new file mode 100644 index 000000000..66b666290 --- /dev/null +++ b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo new file mode 100644 index 000000000..2fdd60ff2 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_fp8x23_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..2fa35f877 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..fdcd11d36 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..4a9a3a6e3 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..78bcbc1ed --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo new file mode 100644 index 000000000..b40477513 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_fp8x23_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..89cffdd5e --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..297233473 --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..0506f1c0f --- /dev/null +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_three_tensors.cairo b/tests/nodes/max_fp8x23_three_tensors.cairo new file mode 100644 index 000000000..d5cc6b030 --- /dev/null +++ b/tests/nodes/max_fp8x23_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_fp8x23_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo new file mode 100644 index 000000000..f0f1d9253 --- /dev/null +++ b/tests/nodes/max_fp8x23_three_tensors/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: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo new file mode 100644 index 000000000..f4611bf3c --- /dev/null +++ b/tests/nodes/max_fp8x23_three_tensors/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo new file mode 100644 index 000000000..6eeb29edb --- /dev/null +++ b/tests/nodes/max_fp8x23_three_tensors/input_2.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_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo new file mode 100644 index 000000000..e0318aad1 --- /dev/null +++ b/tests/nodes/max_fp8x23_three_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_two_tensors.cairo b/tests/nodes/max_fp8x23_two_tensors.cairo new file mode 100644 index 000000000..b54d193d6 --- /dev/null +++ b/tests/nodes/max_fp8x23_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_fp8x23_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo new file mode 100644 index 000000000..038c7c361 --- /dev/null +++ b/tests/nodes/max_fp8x23_two_tensors/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: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo new file mode 100644 index 000000000..da45b3378 --- /dev/null +++ b/tests/nodes/max_fp8x23_two_tensors/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo new file mode 100644 index 000000000..797bfa996 --- /dev/null +++ b/tests/nodes/max_fp8x23_two_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_three_tensors.cairo b/tests/nodes/max_i32_broadcast_three_tensors.cairo new file mode 100644 index 000000000..af4660c1d --- /dev/null +++ b/tests/nodes/max_i32_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_i32_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..1c894ed65 --- /dev/null +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..d4cfc3152 --- /dev/null +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..2573224ed --- /dev/null +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..5494fd3b3 --- /dev/null +++ b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_two_tensors.cairo b/tests/nodes/max_i32_broadcast_two_tensors.cairo new file mode 100644 index 000000000..25d864bba --- /dev/null +++ b/tests/nodes/max_i32_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_i32_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..65fc1651c --- /dev/null +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..b75480afa --- /dev/null +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..ffc6f4c24 --- /dev/null +++ b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_three_tensors.cairo b/tests/nodes/max_i32_three_tensors.cairo new file mode 100644 index 000000000..186d5e2c5 --- /dev/null +++ b/tests/nodes/max_i32_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_i32_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i32_three_tensors/input_0.cairo b/tests/nodes/max_i32_three_tensors/input_0.cairo new file mode 100644 index 000000000..e5fdee508 --- /dev/null +++ b/tests/nodes/max_i32_three_tensors/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: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_three_tensors/input_1.cairo b/tests/nodes/max_i32_three_tensors/input_1.cairo new file mode 100644 index 000000000..960743a74 --- /dev/null +++ b/tests/nodes/max_i32_three_tensors/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_three_tensors/input_2.cairo b/tests/nodes/max_i32_three_tensors/input_2.cairo new file mode 100644 index 000000000..f90517109 --- /dev/null +++ b/tests/nodes/max_i32_three_tensors/input_2.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_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, 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: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, 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: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_three_tensors/output_0.cairo b/tests/nodes/max_i32_three_tensors/output_0.cairo new file mode 100644 index 000000000..376bd0a58 --- /dev/null +++ b/tests/nodes/max_i32_three_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_two_tensors.cairo b/tests/nodes/max_i32_two_tensors.cairo new file mode 100644 index 000000000..18678b57e --- /dev/null +++ b/tests/nodes/max_i32_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_i32_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i32_two_tensors/input_0.cairo b/tests/nodes/max_i32_two_tensors/input_0.cairo new file mode 100644 index 000000000..59ba3b966 --- /dev/null +++ b/tests/nodes/max_i32_two_tensors/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: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, 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: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_two_tensors/input_1.cairo b/tests/nodes/max_i32_two_tensors/input_1.cairo new file mode 100644 index 000000000..6615ef39a --- /dev/null +++ b/tests/nodes/max_i32_two_tensors/input_1.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_1() -> 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: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, 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: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i32_two_tensors/output_0.cairo b/tests/nodes/max_i32_two_tensors/output_0.cairo new file mode 100644 index 000000000..7eded96da --- /dev/null +++ b/tests/nodes/max_i32_two_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, 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: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, 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: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_three_tensors.cairo b/tests/nodes/max_i8_broadcast_three_tensors.cairo new file mode 100644 index 000000000..65ea53cc9 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_i8_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..80c86eb24 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_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 input_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: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..e029fbc53 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..05fe8ff14 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..381efaf32 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_three_tensors/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: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_two_tensors.cairo b/tests/nodes/max_i8_broadcast_two_tensors.cairo new file mode 100644 index 000000000..6a2f8b42f --- /dev/null +++ b/tests/nodes/max_i8_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_i8_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..ea28aa087 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_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 input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..e029fbc53 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..273837ef7 --- /dev/null +++ b/tests/nodes/max_i8_broadcast_two_tensors/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: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_three_tensors.cairo b/tests/nodes/max_i8_three_tensors.cairo new file mode 100644 index 000000000..40b83fbcc --- /dev/null +++ b/tests/nodes/max_i8_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_i8_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i8_three_tensors/input_0.cairo b/tests/nodes/max_i8_three_tensors/input_0.cairo new file mode 100644 index 000000000..07fbd1690 --- /dev/null +++ b/tests/nodes/max_i8_three_tensors/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_three_tensors/input_1.cairo b/tests/nodes/max_i8_three_tensors/input_1.cairo new file mode 100644 index 000000000..47afadf00 --- /dev/null +++ b/tests/nodes/max_i8_three_tensors/input_1.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_three_tensors/input_2.cairo b/tests/nodes/max_i8_three_tensors/input_2.cairo new file mode 100644 index 000000000..e37ded791 --- /dev/null +++ b/tests/nodes/max_i8_three_tensors/input_2.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_three_tensors/output_0.cairo b/tests/nodes/max_i8_three_tensors/output_0.cairo new file mode 100644 index 000000000..5814fe790 --- /dev/null +++ b/tests/nodes/max_i8_three_tensors/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_two_tensors.cairo b/tests/nodes/max_i8_two_tensors.cairo new file mode 100644 index 000000000..9f6ee682d --- /dev/null +++ b/tests/nodes/max_i8_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_i8_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_i8_two_tensors/input_0.cairo b/tests/nodes/max_i8_two_tensors/input_0.cairo new file mode 100644 index 000000000..ec6c88799 --- /dev/null +++ b/tests/nodes/max_i8_two_tensors/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_two_tensors/input_1.cairo b/tests/nodes/max_i8_two_tensors/input_1.cairo new file mode 100644 index 000000000..bc48996a9 --- /dev/null +++ b/tests/nodes/max_i8_two_tensors/input_1.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_i8_two_tensors/output_0.cairo b/tests/nodes/max_i8_two_tensors/output_0.cairo new file mode 100644 index 000000000..889fc62c1 --- /dev/null +++ b/tests/nodes/max_i8_two_tensors/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_three_tensors.cairo b/tests/nodes/max_u32_broadcast_three_tensors.cairo new file mode 100644 index 000000000..a378bd9a7 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_u32_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..108d66672 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(5); + data.append(2); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..a904f4e58 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..ab0ca7fb6 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..0f21da101 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(4); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_two_tensors.cairo b/tests/nodes/max_u32_broadcast_two_tensors.cairo new file mode 100644 index 000000000..ddcd35e04 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_u32_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..e7dcaeaf3 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(5); + data.append(5); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..b09e9c973 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..8354b7151 --- /dev/null +++ b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(5); + data.append(5); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_three_tensors.cairo b/tests/nodes/max_u32_three_tensors.cairo new file mode 100644 index 000000000..655f2a713 --- /dev/null +++ b/tests/nodes/max_u32_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_max_u32_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_u32_three_tensors/input_0.cairo b/tests/nodes/max_u32_three_tensors/input_0.cairo new file mode 100644 index 000000000..e428995ce --- /dev/null +++ b/tests/nodes/max_u32_three_tensors/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(4); + data.append(1); + data.append(1); + data.append(4); + data.append(1); + data.append(1); + data.append(2); + data.append(3); + data.append(5); + data.append(5); + data.append(1); + data.append(1); + data.append(2); + data.append(5); + data.append(0); + data.append(4); + data.append(1); + data.append(1); + data.append(4); + data.append(4); + data.append(3); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_three_tensors/input_1.cairo b/tests/nodes/max_u32_three_tensors/input_1.cairo new file mode 100644 index 000000000..edb019a72 --- /dev/null +++ b/tests/nodes/max_u32_three_tensors/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(5); + data.append(5); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(3); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(5); + data.append(4); + data.append(5); + data.append(5); + data.append(5); + data.append(4); + data.append(2); + data.append(5); + data.append(1); + data.append(4); + data.append(4); + data.append(5); + data.append(0); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_three_tensors/input_2.cairo b/tests/nodes/max_u32_three_tensors/input_2.cairo new file mode 100644 index 000000000..cdd6dd700 --- /dev/null +++ b/tests/nodes/max_u32_three_tensors/input_2.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(5); + data.append(5); + data.append(1); + data.append(3); + data.append(5); + data.append(0); + data.append(2); + data.append(2); + data.append(4); + data.append(4); + data.append(5); + data.append(4); + data.append(2); + data.append(5); + data.append(5); + data.append(4); + data.append(4); + data.append(5); + data.append(1); + data.append(4); + data.append(5); + data.append(2); + data.append(5); + data.append(4); + data.append(4); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_three_tensors/output_0.cairo b/tests/nodes/max_u32_three_tensors/output_0.cairo new file mode 100644 index 000000000..b8b2b72aa --- /dev/null +++ b/tests/nodes/max_u32_three_tensors/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(5); + data.append(4); + data.append(3); + data.append(5); + data.append(2); + data.append(3); + data.append(5); + data.append(5); + data.append(4); + data.append(5); + data.append(4); + data.append(5); + data.append(5); + data.append(5); + data.append(5); + data.append(5); + data.append(5); + data.append(4); + data.append(5); + data.append(5); + data.append(4); + data.append(5); + data.append(5); + data.append(4); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_two_tensors.cairo b/tests/nodes/max_u32_two_tensors.cairo new file mode 100644 index 000000000..faed3d640 --- /dev/null +++ b/tests/nodes/max_u32_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_max_u32_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::max(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/max_u32_two_tensors/input_0.cairo b/tests/nodes/max_u32_two_tensors/input_0.cairo new file mode 100644 index 000000000..dde213565 --- /dev/null +++ b/tests/nodes/max_u32_two_tensors/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(3); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(4); + data.append(1); + data.append(1); + data.append(4); + data.append(4); + data.append(3); + data.append(2); + data.append(4); + data.append(2); + data.append(4); + data.append(5); + data.append(1); + data.append(3); + data.append(3); + data.append(3); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(5); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_two_tensors/input_1.cairo b/tests/nodes/max_u32_two_tensors/input_1.cairo new file mode 100644 index 000000000..bdd40bb01 --- /dev/null +++ b/tests/nodes/max_u32_two_tensors/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(5); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(4); + data.append(2); + data.append(1); + data.append(5); + data.append(1); + data.append(4); + data.append(3); + data.append(0); + data.append(3); + data.append(1); + data.append(1); + data.append(3); + data.append(5); + data.append(4); + data.append(4); + data.append(2); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/max_u32_two_tensors/output_0.cairo b/tests/nodes/max_u32_two_tensors/output_0.cairo new file mode 100644 index 000000000..e585ea8dc --- /dev/null +++ b/tests/nodes/max_u32_two_tensors/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(2); + data.append(0); + data.append(2); + data.append(5); + data.append(1); + data.append(4); + data.append(1); + data.append(2); + data.append(4); + data.append(4); + data.append(3); + data.append(2); + data.append(5); + data.append(2); + data.append(4); + data.append(5); + data.append(1); + data.append(3); + data.append(3); + data.append(3); + data.append(3); + data.append(5); + data.append(4); + data.append(4); + data.append(5); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo new file mode 100644 index 000000000..c71edce86 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_fp16x16_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..bf27fbdf0 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,18 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..d7359bc64 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..406f91365 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..98ef140fa --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo new file mode 100644 index 000000000..3b998ca1a --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_fp16x16_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..c1c0930a4 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,18 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..d7359bc64 --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..0e8b2aebb --- /dev/null +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_three_tensors.cairo b/tests/nodes/min_fp16x16_three_tensors.cairo new file mode 100644 index 000000000..8a5d60711 --- /dev/null +++ b/tests/nodes/min_fp16x16_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_fp16x16_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo new file mode 100644 index 000000000..747696a57 --- /dev/null +++ b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo new file mode 100644 index 000000000..22d5848ef --- /dev/null +++ b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo new file mode 100644 index 000000000..02084123c --- /dev/null +++ b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo new file mode 100644 index 000000000..6931f714a --- /dev/null +++ b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_two_tensors.cairo b/tests/nodes/min_fp16x16_two_tensors.cairo new file mode 100644 index 000000000..25adc490e --- /dev/null +++ b/tests/nodes/min_fp16x16_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_fp16x16_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo new file mode 100644 index 000000000..3cc3af9cb --- /dev/null +++ b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo new file mode 100644 index 000000000..230c3bfd0 --- /dev/null +++ b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo new file mode 100644 index 000000000..785211ceb --- /dev/null +++ b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo new file mode 100644 index 000000000..2596fabad --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_fp8x23_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..c5eee64f3 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..5ddfee383 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..87ac9a1aa --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..6a9b1f878 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo new file mode 100644 index 000000000..b231c5d76 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_fp8x23_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..06a77989a --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..538d00e70 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,16 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..dbb598ae0 --- /dev/null +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_three_tensors.cairo b/tests/nodes/min_fp8x23_three_tensors.cairo new file mode 100644 index 000000000..676f8f312 --- /dev/null +++ b/tests/nodes/min_fp8x23_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_fp8x23_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo new file mode 100644 index 000000000..9716ed3b9 --- /dev/null +++ b/tests/nodes/min_fp8x23_three_tensors/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: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo new file mode 100644 index 000000000..49311a2b0 --- /dev/null +++ b/tests/nodes/min_fp8x23_three_tensors/input_1.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_1() -> 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: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo new file mode 100644 index 000000000..9b8b0650e --- /dev/null +++ b/tests/nodes/min_fp8x23_three_tensors/input_2.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_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo new file mode 100644 index 000000000..af08ef421 --- /dev/null +++ b/tests/nodes/min_fp8x23_three_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_two_tensors.cairo b/tests/nodes/min_fp8x23_two_tensors.cairo new file mode 100644 index 000000000..01d2724ea --- /dev/null +++ b/tests/nodes/min_fp8x23_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_fp8x23_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo new file mode 100644 index 000000000..293eb3e83 --- /dev/null +++ b/tests/nodes/min_fp8x23_two_tensors/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: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo new file mode 100644 index 000000000..76f71b638 --- /dev/null +++ b/tests/nodes/min_fp8x23_two_tensors/input_1.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_1() -> 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: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo new file mode 100644 index 000000000..c0e8bbc56 --- /dev/null +++ b/tests/nodes/min_fp8x23_two_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_three_tensors.cairo b/tests/nodes/min_i32_broadcast_three_tensors.cairo new file mode 100644 index 000000000..74ad7c090 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_i32_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..3ffb54363 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..97515f83e --- /dev/null +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..2573224ed --- /dev/null +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..3031cb2bf --- /dev/null +++ b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_two_tensors.cairo b/tests/nodes/min_i32_broadcast_two_tensors.cairo new file mode 100644 index 000000000..43e5f99e0 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_i32_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..b9cd5f819 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..ab5754cf2 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..fa1f29299 --- /dev/null +++ b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_three_tensors.cairo b/tests/nodes/min_i32_three_tensors.cairo new file mode 100644 index 000000000..adb4350db --- /dev/null +++ b/tests/nodes/min_i32_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_i32_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i32_three_tensors/input_0.cairo b/tests/nodes/min_i32_three_tensors/input_0.cairo new file mode 100644 index 000000000..a255474d1 --- /dev/null +++ b/tests/nodes/min_i32_three_tensors/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: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_three_tensors/input_1.cairo b/tests/nodes/min_i32_three_tensors/input_1.cairo new file mode 100644 index 000000000..33568613e --- /dev/null +++ b/tests/nodes/min_i32_three_tensors/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_three_tensors/input_2.cairo b/tests/nodes/min_i32_three_tensors/input_2.cairo new file mode 100644 index 000000000..9b822fc6d --- /dev/null +++ b/tests/nodes/min_i32_three_tensors/input_2.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_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_three_tensors/output_0.cairo b/tests/nodes/min_i32_three_tensors/output_0.cairo new file mode 100644 index 000000000..9b0a9b23a --- /dev/null +++ b/tests/nodes/min_i32_three_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_two_tensors.cairo b/tests/nodes/min_i32_two_tensors.cairo new file mode 100644 index 000000000..ae444f6e7 --- /dev/null +++ b/tests/nodes/min_i32_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_i32_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i32_two_tensors/input_0.cairo b/tests/nodes/min_i32_two_tensors/input_0.cairo new file mode 100644 index 000000000..518ef5c24 --- /dev/null +++ b/tests/nodes/min_i32_two_tensors/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: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_two_tensors/input_1.cairo b/tests/nodes/min_i32_two_tensors/input_1.cairo new file mode 100644 index 000000000..42bdad0c9 --- /dev/null +++ b/tests/nodes/min_i32_two_tensors/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, 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: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i32_two_tensors/output_0.cairo b/tests/nodes/min_i32_two_tensors/output_0.cairo new file mode 100644 index 000000000..af1b203d5 --- /dev/null +++ b/tests/nodes/min_i32_two_tensors/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_three_tensors.cairo b/tests/nodes/min_i8_broadcast_three_tensors.cairo new file mode 100644 index 000000000..4b67ffc7d --- /dev/null +++ b/tests/nodes/min_i8_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_i8_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..254b04d0a --- /dev/null +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_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 input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..4fc8ae5a6 --- /dev/null +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..f472bb1d6 --- /dev/null +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..9e4345995 --- /dev/null +++ b/tests/nodes/min_i8_broadcast_three_tensors/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: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_two_tensors.cairo b/tests/nodes/min_i8_broadcast_two_tensors.cairo new file mode 100644 index 000000000..a533c5930 --- /dev/null +++ b/tests/nodes/min_i8_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_i8_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..563c07736 --- /dev/null +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_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 input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..060e0a9ec --- /dev/null +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..86ec9707b --- /dev/null +++ b/tests/nodes/min_i8_broadcast_two_tensors/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: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_three_tensors.cairo b/tests/nodes/min_i8_three_tensors.cairo new file mode 100644 index 000000000..cee72024b --- /dev/null +++ b/tests/nodes/min_i8_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_i8_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i8_three_tensors/input_0.cairo b/tests/nodes/min_i8_three_tensors/input_0.cairo new file mode 100644 index 000000000..92635527e --- /dev/null +++ b/tests/nodes/min_i8_three_tensors/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_three_tensors/input_1.cairo b/tests/nodes/min_i8_three_tensors/input_1.cairo new file mode 100644 index 000000000..09e7ab7d1 --- /dev/null +++ b/tests/nodes/min_i8_three_tensors/input_1.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + 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: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_three_tensors/input_2.cairo b/tests/nodes/min_i8_three_tensors/input_2.cairo new file mode 100644 index 000000000..6784429c8 --- /dev/null +++ b/tests/nodes/min_i8_three_tensors/input_2.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_three_tensors/output_0.cairo b/tests/nodes/min_i8_three_tensors/output_0.cairo new file mode 100644 index 000000000..86ccc411f --- /dev/null +++ b/tests/nodes/min_i8_three_tensors/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_two_tensors.cairo b/tests/nodes/min_i8_two_tensors.cairo new file mode 100644 index 000000000..8f13d360a --- /dev/null +++ b/tests/nodes/min_i8_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_i8_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_i8_two_tensors/input_0.cairo b/tests/nodes/min_i8_two_tensors/input_0.cairo new file mode 100644 index 000000000..edcba1f05 --- /dev/null +++ b/tests/nodes/min_i8_two_tensors/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + 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: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_two_tensors/input_1.cairo b/tests/nodes/min_i8_two_tensors/input_1.cairo new file mode 100644 index 000000000..805f2971a --- /dev/null +++ b/tests/nodes/min_i8_two_tensors/input_1.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_i8_two_tensors/output_0.cairo b/tests/nodes/min_i8_two_tensors/output_0.cairo new file mode 100644 index 000000000..4cfdc62b3 --- /dev/null +++ b/tests/nodes/min_i8_two_tensors/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_three_tensors.cairo b/tests/nodes/min_u32_broadcast_three_tensors.cairo new file mode 100644 index 000000000..b76ced612 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_u32_broadcast_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo new file mode 100644 index 000000000..e1fde6172 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(5); + data.append(4); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo new file mode 100644 index 000000000..4f6ed249f --- /dev/null +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo new file mode 100644 index 000000000..9b8b57621 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo new file mode 100644 index 000000000..5af544845 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(3); + data.append(3); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_two_tensors.cairo b/tests/nodes/min_u32_broadcast_two_tensors.cairo new file mode 100644 index 000000000..9fe666a9e --- /dev/null +++ b/tests/nodes/min_u32_broadcast_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_u32_broadcast_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo new file mode 100644 index 000000000..a173baaf1 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(4); + data.append(5); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo new file mode 100644 index 000000000..447f95446 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo new file mode 100644 index 000000000..51197a3e8 --- /dev/null +++ b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(3); + data.append(5); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_three_tensors.cairo b/tests/nodes/min_u32_three_tensors.cairo new file mode 100644 index 000000000..958888c62 --- /dev/null +++ b/tests/nodes/min_u32_three_tensors.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_min_u32_three_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1, input_2].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_u32_three_tensors/input_0.cairo b/tests/nodes/min_u32_three_tensors/input_0.cairo new file mode 100644 index 000000000..30bcab8cc --- /dev/null +++ b/tests/nodes/min_u32_three_tensors/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(0); + data.append(1); + data.append(4); + data.append(5); + data.append(1); + data.append(2); + data.append(4); + data.append(3); + data.append(1); + data.append(2); + data.append(3); + data.append(0); + data.append(0); + data.append(3); + data.append(3); + data.append(4); + data.append(1); + data.append(0); + data.append(5); + data.append(3); + data.append(4); + data.append(3); + data.append(0); + data.append(1); + data.append(3); + data.append(3); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_three_tensors/input_1.cairo b/tests/nodes/min_u32_three_tensors/input_1.cairo new file mode 100644 index 000000000..73f220714 --- /dev/null +++ b/tests/nodes/min_u32_three_tensors/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(3); + data.append(1); + data.append(5); + data.append(3); + data.append(4); + data.append(5); + data.append(2); + data.append(1); + data.append(5); + data.append(5); + data.append(2); + data.append(3); + data.append(3); + data.append(1); + data.append(3); + data.append(1); + data.append(4); + data.append(3); + data.append(2); + data.append(4); + data.append(2); + data.append(2); + data.append(0); + data.append(5); + data.append(5); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_three_tensors/input_2.cairo b/tests/nodes/min_u32_three_tensors/input_2.cairo new file mode 100644 index 000000000..1f682b4a7 --- /dev/null +++ b/tests/nodes/min_u32_three_tensors/input_2.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(1); + data.append(3); + data.append(4); + data.append(3); + data.append(5); + data.append(2); + data.append(4); + data.append(2); + data.append(3); + data.append(3); + data.append(1); + data.append(4); + data.append(5); + data.append(2); + data.append(3); + data.append(0); + data.append(1); + data.append(3); + data.append(1); + data.append(3); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_three_tensors/output_0.cairo b/tests/nodes/min_u32_three_tensors/output_0.cairo new file mode 100644 index 000000000..7a47c65c1 --- /dev/null +++ b/tests/nodes/min_u32_three_tensors/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(4); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(3); + data.append(0); + data.append(0); + data.append(3); + data.append(1); + data.append(3); + data.append(0); + data.append(0); + data.append(3); + data.append(1); + data.append(3); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_two_tensors.cairo b/tests/nodes/min_u32_two_tensors.cairo new file mode 100644 index 000000000..94ce36d7a --- /dev/null +++ b/tests/nodes/min_u32_two_tensors.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_min_u32_two_tensors() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::min(array![input_0, input_1].span()); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/min_u32_two_tensors/input_0.cairo b/tests/nodes/min_u32_two_tensors/input_0.cairo new file mode 100644 index 000000000..c20d52a0a --- /dev/null +++ b/tests/nodes/min_u32_two_tensors/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(5); + data.append(5); + data.append(4); + data.append(1); + data.append(2); + data.append(1); + data.append(4); + data.append(2); + data.append(2); + data.append(3); + data.append(2); + data.append(0); + data.append(5); + data.append(3); + data.append(5); + data.append(4); + data.append(3); + data.append(0); + data.append(5); + data.append(3); + data.append(2); + data.append(5); + data.append(5); + data.append(4); + data.append(4); + data.append(3); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_two_tensors/input_1.cairo b/tests/nodes/min_u32_two_tensors/input_1.cairo new file mode 100644 index 000000000..d4709f0df --- /dev/null +++ b/tests/nodes/min_u32_two_tensors/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(2); + data.append(4); + data.append(1); + data.append(3); + data.append(3); + data.append(0); + data.append(5); + data.append(1); + data.append(5); + data.append(4); + data.append(1); + data.append(2); + data.append(5); + data.append(5); + data.append(5); + data.append(5); + data.append(2); + data.append(1); + data.append(2); + data.append(3); + data.append(5); + data.append(0); + data.append(4); + data.append(3); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/min_u32_two_tensors/output_0.cairo b/tests/nodes/min_u32_two_tensors/output_0.cairo new file mode 100644 index 000000000..fc5f86d90 --- /dev/null +++ b/tests/nodes/min_u32_two_tensors/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(3); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(5); + data.append(4); + data.append(3); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(3); + data.append(5); + data.append(0); + data.append(4); + data.append(3); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/round_fp16x16.cairo b/tests/nodes/round_fp16x16.cairo new file mode 100644 index 000000000..02a279685 --- /dev/null +++ b/tests/nodes/round_fp16x16.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_round_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.round(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/round_fp16x16/input_0.cairo b/tests/nodes/round_fp16x16/input_0.cairo new file mode 100644 index 000000000..68229762b --- /dev/null +++ b/tests/nodes/round_fp16x16/input_0.cairo @@ -0,0 +1,28 @@ +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(15); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 6553, sign: false }); + data.append(FP16x16 { mag: 32768, sign: false }); + data.append(FP16x16 { mag: 58982, sign: false }); + data.append(FP16x16 { mag: 78643, sign: false }); + data.append(FP16x16 { mag: 98304, sign: false }); + data.append(FP16x16 { mag: 117964, sign: false }); + data.append(FP16x16 { mag: 150732, sign: false }); + data.append(FP16x16 { mag: 163840, sign: false }); + data.append(FP16x16 { mag: 176947, sign: false }); + data.append(FP16x16 { mag: 72089, sign: true }); + data.append(FP16x16 { mag: 98304, sign: true }); + data.append(FP16x16 { mag: 124518, sign: true }); + data.append(FP16x16 { mag: 144179, sign: true }); + data.append(FP16x16 { mag: 163840, sign: true }); + data.append(FP16x16 { mag: 183500, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/round_fp16x16/output_0.cairo b/tests/nodes/round_fp16x16/output_0.cairo new file mode 100644 index 000000000..e303e30e4 --- /dev/null +++ b/tests/nodes/round_fp16x16/output_0.cairo @@ -0,0 +1,28 @@ +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(15); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/round_fp8x23.cairo b/tests/nodes/round_fp8x23.cairo new file mode 100644 index 000000000..e09a76fd2 --- /dev/null +++ b/tests/nodes/round_fp8x23.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_round_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.round(); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/round_fp8x23/input_0.cairo b/tests/nodes/round_fp8x23/input_0.cairo new file mode 100644 index 000000000..d812ae1a2 --- /dev/null +++ b/tests/nodes/round_fp8x23/input_0.cairo @@ -0,0 +1,28 @@ +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(15); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 838860, sign: false }); + data.append(FP8x23 { mag: 4194304, sign: false }); + data.append(FP8x23 { mag: 7549747, sign: false }); + data.append(FP8x23 { mag: 10066329, sign: false }); + data.append(FP8x23 { mag: 12582912, sign: false }); + data.append(FP8x23 { mag: 15099494, sign: false }); + data.append(FP8x23 { mag: 19293798, sign: false }); + data.append(FP8x23 { mag: 20971520, sign: false }); + data.append(FP8x23 { mag: 22649241, sign: false }); + data.append(FP8x23 { mag: 9227468, sign: true }); + data.append(FP8x23 { mag: 12582912, sign: true }); + data.append(FP8x23 { mag: 15938355, sign: true }); + data.append(FP8x23 { mag: 18454937, sign: true }); + data.append(FP8x23 { mag: 20971520, sign: true }); + data.append(FP8x23 { mag: 23488102, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/round_fp8x23/output_0.cairo b/tests/nodes/round_fp8x23/output_0.cairo new file mode 100644 index 000000000..d5cc73f5f --- /dev/null +++ b/tests/nodes/round_fp8x23/output_0.cairo @@ -0,0 +1,28 @@ +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(15); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1.cairo new file mode 100644 index 000000000..ddd2ed77a --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp16x16_3d_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo new file mode 100644 index 000000000..90579e5d8 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo new file mode 100644 index 000000000..0b71e00bc --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo new file mode 100644 index 000000000..e450321a6 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo new file mode 100644 index 000000000..c8027a1a5 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp16x16_3d_axis1_add() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo new file mode 100644 index 000000000..90579e5d8 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo new file mode 100644 index 000000000..0b71e00bc --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo new file mode 100644 index 000000000..47d99b23f --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_default.cairo b/tests/nodes/scatter_fp16x16_3d_default.cairo new file mode 100644 index 000000000..ebc06014d --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp16x16_3d_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo new file mode 100644 index 000000000..90579e5d8 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_default/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo new file mode 100644 index 000000000..0b71e00bc --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_default/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo new file mode 100644 index 000000000..9edd74528 --- /dev/null +++ b/tests/nodes/scatter_fp16x16_3d_default/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_axis1.cairo b/tests/nodes/scatter_fp8x23_axis1.cairo new file mode 100644 index 000000000..31ec2ea7c --- /dev/null +++ b/tests/nodes/scatter_fp8x23_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp8x23_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo new file mode 100644 index 000000000..4b7c73dcb --- /dev/null +++ b/tests/nodes/scatter_fp8x23_axis1/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo new file mode 100644 index 000000000..a36342547 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo @@ -0,0 +1,23 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + 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 }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo new file mode 100644 index 000000000..888cee255 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_axis1/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + 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: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_default.cairo b/tests/nodes/scatter_fp8x23_default.cairo new file mode 100644 index 000000000..66e5a6064 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp8x23_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_default/input_0.cairo b/tests/nodes/scatter_fp8x23_default/input_0.cairo new file mode 100644 index 000000000..4b7c73dcb --- /dev/null +++ b/tests/nodes/scatter_fp8x23_default/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_default/input_1.cairo b/tests/nodes/scatter_fp8x23_default/input_1.cairo new file mode 100644 index 000000000..a36342547 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_default/input_1.cairo @@ -0,0 +1,23 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + 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 }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_default/input_2.cairo b/tests/nodes/scatter_fp8x23_default/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_default/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_default/output_0.cairo b/tests/nodes/scatter_fp8x23_default/output_0.cairo new file mode 100644 index 000000000..6c198c3af --- /dev/null +++ b/tests/nodes/scatter_fp8x23_default/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_mul.cairo b/tests/nodes/scatter_fp8x23_mul.cairo new file mode 100644 index 000000000..8f6a9e5ae --- /dev/null +++ b/tests/nodes/scatter_fp8x23_mul.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_fp8x23_mul() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_mul/input_0.cairo b/tests/nodes/scatter_fp8x23_mul/input_0.cairo new file mode 100644 index 000000000..4b7c73dcb --- /dev/null +++ b/tests/nodes/scatter_fp8x23_mul/input_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; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_mul/input_1.cairo b/tests/nodes/scatter_fp8x23_mul/input_1.cairo new file mode 100644 index 000000000..a36342547 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_mul/input_1.cairo @@ -0,0 +1,23 @@ +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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + 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 }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_mul/input_2.cairo b/tests/nodes/scatter_fp8x23_mul/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_mul/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_fp8x23_mul/output_0.cairo b/tests/nodes/scatter_fp8x23_mul/output_0.cairo new file mode 100644 index 000000000..73c873293 --- /dev/null +++ b/tests/nodes/scatter_fp8x23_mul/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; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1.cairo b/tests/nodes/scatter_i8_axis1.cairo new file mode 100644 index 000000000..aeed6cea2 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_i8_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1/input_0.cairo b/tests/nodes/scatter_i8_axis1/input_0.cairo new file mode 100644 index 000000000..abbf36d26 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1/input_1.cairo b/tests/nodes/scatter_i8_axis1/input_1.cairo new file mode 100644 index 000000000..13224f105 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1/input_2.cairo b/tests/nodes/scatter_i8_axis1/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1/output_0.cairo b/tests/nodes/scatter_i8_axis1/output_0.cairo new file mode 100644 index 000000000..173bb1617 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1_max.cairo b/tests/nodes/scatter_i8_axis1_max.cairo new file mode 100644 index 000000000..0b1cc537c --- /dev/null +++ b/tests/nodes/scatter_i8_axis1_max.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_i8_axis1_max() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1_max/input_0.cairo b/tests/nodes/scatter_i8_axis1_max/input_0.cairo new file mode 100644 index 000000000..abbf36d26 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1_max/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1_max/input_1.cairo b/tests/nodes/scatter_i8_axis1_max/input_1.cairo new file mode 100644 index 000000000..13224f105 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1_max/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1_max/input_2.cairo b/tests/nodes/scatter_i8_axis1_max/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1_max/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_axis1_max/output_0.cairo b/tests/nodes/scatter_i8_axis1_max/output_0.cairo new file mode 100644 index 000000000..173bb1617 --- /dev/null +++ b/tests/nodes/scatter_i8_axis1_max/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_default.cairo b/tests/nodes/scatter_i8_default.cairo new file mode 100644 index 000000000..b0d10c89d --- /dev/null +++ b/tests/nodes/scatter_i8_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_i8_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_default/input_0.cairo b/tests/nodes/scatter_i8_default/input_0.cairo new file mode 100644 index 000000000..abbf36d26 --- /dev/null +++ b/tests/nodes/scatter_i8_default/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(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_default/input_1.cairo b/tests/nodes/scatter_i8_default/input_1.cairo new file mode 100644 index 000000000..13224f105 --- /dev/null +++ b/tests/nodes/scatter_i8_default/input_1.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_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 9, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_default/input_2.cairo b/tests/nodes/scatter_i8_default/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_i8_default/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_i8_default/output_0.cairo b/tests/nodes/scatter_i8_default/output_0.cairo new file mode 100644 index 000000000..9f1cf79dd --- /dev/null +++ b/tests/nodes/scatter_i8_default/output_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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 9, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_add.cairo b/tests/nodes/scatter_u32_add.cairo new file mode 100644 index 000000000..5c28a9394 --- /dev/null +++ b/tests/nodes/scatter_u32_add.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_u32_add() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_add/input_0.cairo b/tests/nodes/scatter_u32_add/input_0.cairo new file mode 100644 index 000000000..13ba41a86 --- /dev/null +++ b/tests/nodes/scatter_u32_add/input_0.cairo @@ -0,0 +1,21 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_add/input_1.cairo b/tests/nodes/scatter_u32_add/input_1.cairo new file mode 100644 index 000000000..feb2dabc8 --- /dev/null +++ b/tests/nodes/scatter_u32_add/input_1.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_add/input_2.cairo b/tests/nodes/scatter_u32_add/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_u32_add/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_add/output_0.cairo b/tests/nodes/scatter_u32_add/output_0.cairo new file mode 100644 index 000000000..924837c12 --- /dev/null +++ b/tests/nodes/scatter_u32_add/output_0.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(13); + data.append(0); + data.append(7); + data.append(2); + data.append(15); + data.append(4); + data.append(0); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_axis1.cairo b/tests/nodes/scatter_u32_axis1.cairo new file mode 100644 index 000000000..784c28787 --- /dev/null +++ b/tests/nodes/scatter_u32_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_u32_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_axis1/input_0.cairo b/tests/nodes/scatter_u32_axis1/input_0.cairo new file mode 100644 index 000000000..13ba41a86 --- /dev/null +++ b/tests/nodes/scatter_u32_axis1/input_0.cairo @@ -0,0 +1,21 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_axis1/input_1.cairo b/tests/nodes/scatter_u32_axis1/input_1.cairo new file mode 100644 index 000000000..feb2dabc8 --- /dev/null +++ b/tests/nodes/scatter_u32_axis1/input_1.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_axis1/input_2.cairo b/tests/nodes/scatter_u32_axis1/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_u32_axis1/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_axis1/output_0.cairo b/tests/nodes/scatter_u32_axis1/output_0.cairo new file mode 100644 index 000000000..2a2d51eda --- /dev/null +++ b/tests/nodes/scatter_u32_axis1/output_0.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(5); + data.append(6); + data.append(4); + data.append(8); + data.append(9); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_default.cairo b/tests/nodes/scatter_u32_default.cairo new file mode 100644 index 000000000..fd2607de7 --- /dev/null +++ b/tests/nodes/scatter_u32_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +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_scatter_u32_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_default/input_0.cairo b/tests/nodes/scatter_u32_default/input_0.cairo new file mode 100644 index 000000000..13ba41a86 --- /dev/null +++ b/tests/nodes/scatter_u32_default/input_0.cairo @@ -0,0 +1,21 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_default/input_1.cairo b/tests/nodes/scatter_u32_default/input_1.cairo new file mode 100644 index 000000000..feb2dabc8 --- /dev/null +++ b/tests/nodes/scatter_u32_default/input_1.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(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); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_default/input_2.cairo b/tests/nodes/scatter_u32_default/input_2.cairo new file mode 100644 index 000000000..4fd383db2 --- /dev/null +++ b/tests/nodes/scatter_u32_default/input_2.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/scatter_u32_default/output_0.cairo b/tests/nodes/scatter_u32_default/output_0.cairo new file mode 100644 index 000000000..3bea6d3a7 --- /dev/null +++ b/tests/nodes/scatter_u32_default/output_0.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(8); + data.append(0); + data.append(7); + data.append(2); + data.append(9); + data.append(4); + data.append(0); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/operators.cairo b/tests/operators.cairo index d84e29548..7642e31f3 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -1 +1,2 @@ mod transpose_test; +mod qlinear_matmul_test; diff --git a/tests/operators/qlinear_matmul_test.cairo b/tests/operators/qlinear_matmul_test.cairo new file mode 100644 index 000000000..b666518a4 --- /dev/null +++ b/tests/operators/qlinear_matmul_test.cairo @@ -0,0 +1,237 @@ +use debug::PrintTrait; +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tensor, FP16x16Tensor, FP32x32Tensor +}; +use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; +use orion::numbers::{NumberTrait, IntegerTrait}; +use orion::numbers::{i8, i32}; + + +#[test] +#[available_gas(200000000000)] +fn qlinearmatmul_2D_test() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 4].span(), + data: array![ + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(3_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(7_u8, false), + IntegerTrait::::new(8_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![4, 3].span(), + data: array![ + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(12_u8, false), + IntegerTrait::::new(14_u8, false), + IntegerTrait::::new(16_u8, false), + IntegerTrait::::new(18_u8, false), + IntegerTrait::::new(20_u8, false), + IntegerTrait::::new(22_u8, false), + IntegerTrait::::new(24_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(2000, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(2500, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(3000, false)].span(),); + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = a + .qlinear_matmul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + + assert((*actual_output.data[0]).into() == 3, '*result[0] == 3'); + assert((*actual_output.data[1]).into() == 4, '*result[1] == 4'); + assert((*actual_output.data[2]).into() == 4, '*result[2] == 4'); + assert((*actual_output.data[3]).into() == 8, '*result[3] == 8'); + assert((*actual_output.data[4]).into() == 9, '*result[4] == 9'); + assert((*actual_output.data[5]).into() == 10, '*result[5] == 10'); +} + + +#[test] +#[available_gas(200000000000)] +fn qlinearmatmul_3D_test() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 2, 3].span(), + data: array![ + IntegerTrait::::new(1_u8, true), + IntegerTrait::::new(2_u8, true), + IntegerTrait::::new(2_u8, true), + IntegerTrait::::new(3_u8, true), + IntegerTrait::::new(4_u8, true), + IntegerTrait::::new(4_u8, true), + IntegerTrait::::new(5_u8, true), + IntegerTrait::::new(6_u8, true), + IntegerTrait::::new(6_u8, true), + IntegerTrait::::new(7_u8, true), + IntegerTrait::::new(8_u8, true), + IntegerTrait::::new(8_u8, true) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![2, 3, 2].span(), + data: array![ + IntegerTrait::::new(2_u8, true), + IntegerTrait::::new(4_u8, true), + IntegerTrait::::new(6_u8, true), + IntegerTrait::::new(8_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(12_u8, true), + IntegerTrait::::new(2_u8, true), + IntegerTrait::::new(4_u8, true), + IntegerTrait::::new(6_u8, true), + IntegerTrait::::new(8_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(12_u8, true) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(20000, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(25000, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(30000, false)].span(),); + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = a + .qlinear_matmul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + + assert((*actual_output.data[0]).into() == 8, '*result[0] == 8'); + assert((*actual_output.data[1]).into() == 11, '*result[1] == 11'); + assert((*actual_output.data[2]).into() == 17, '*result[2] == 17'); + assert((*actual_output.data[3]).into() == 23, '*result[3] == 23'); + assert((*actual_output.data[4]).into() == 26, '*result[4] == 26'); + assert((*actual_output.data[5]).into() == 35, '*result[5] == 35'); + assert((*actual_output.data[6]).into() == 36, '*result[6] == 36'); + assert((*actual_output.data[7]).into() == 47, '*result[7] == 47'); +} + + +#[test] +#[available_gas(200000000000)] +fn test_example_doc() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(3_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(3_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![3, 1].span(), + data: array![ + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(4_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(), + ); + let y_zero_point = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); + + let actual_output = a + .qlinear_matmul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + + assert((*actual_output.data[0]).into() == 14, '*result[0] == 14'); + assert((*actual_output.data[1]).into() == 13, '*result[1] == 13'); +} + +fn print_span(mut span: Span) { + loop { + match span.pop_front() { + Option::Some(i) => { (*i.mag).print(); }, + Option::None(_) => { break; } + }; + }; +} diff --git a/tests/tensor_core/max/max_fp_test/max_fp16x16_test.cairo b/tests/tensor_core/max/max_fp_test/max_fp16x16_test.cairo index 160fb29b7..8458d12fd 100644 --- a/tests/tensor_core/max/max_fp_test/max_fp16x16_test.cairo +++ b/tests/tensor_core/max/max_fp_test/max_fp16x16_test.cairo @@ -13,7 +13,7 @@ mod tensor_1D { fn tensor_max() { let tensor = fp_tensor_1x3_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(2, false).mag, 'tensor.max = 2'); } } @@ -34,7 +34,7 @@ mod tensor_2D { fn tensor_max() { let tensor = fp_tensor_2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(3, false).mag, 'tensor.max = 3'); } } @@ -55,7 +55,7 @@ mod tensor_3D { fn tensor_max() { let tensor = fp_tensor_2x2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(7, false).mag, 'tensor.max = 7'); } } diff --git a/tests/tensor_core/max/max_fp_test/max_fp8x23_test.cairo b/tests/tensor_core/max/max_fp_test/max_fp8x23_test.cairo index 2ff1b744c..f9facb1fc 100644 --- a/tests/tensor_core/max/max_fp_test/max_fp8x23_test.cairo +++ b/tests/tensor_core/max/max_fp_test/max_fp8x23_test.cairo @@ -13,7 +13,7 @@ mod tensor_1D { fn tensor_max() { let tensor = fp_tensor_1x3_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(2, false).mag, 'tensor.max = 2'); } } @@ -34,7 +34,7 @@ mod tensor_2D { fn tensor_max() { let tensor = fp_tensor_2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(3, false).mag, 'tensor.max = 3'); } } @@ -55,7 +55,7 @@ mod tensor_3D { fn tensor_max() { let tensor = fp_tensor_2x2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == FixedTrait::::new_unscaled(7, false).mag, 'tensor.max = 7'); } } diff --git a/tests/tensor_core/max/max_i32_test.cairo b/tests/tensor_core/max/max_i32_test.cairo index 3e67df42c..17f9fdc9b 100644 --- a/tests/tensor_core/max/max_i32_test.cairo +++ b/tests/tensor_core/max/max_i32_test.cairo @@ -11,7 +11,7 @@ mod tensor_1D { fn tensor_max() { let tensor = i32_tensor_1x3_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == 2, 'tensor.max = 2'); } } @@ -29,7 +29,7 @@ mod tensor_2D { fn tensor_max() { let tensor = i32_tensor_2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == 3, 'tensor.max = 3'); } } @@ -47,7 +47,7 @@ mod tensor_3D { fn tensor_max() { let tensor = i32_tensor_2x2x2_helper(); - let result = tensor.max().mag; + let result = tensor.max_in_tensor().mag; assert(result == 7, 'tensor.max = 7'); } } diff --git a/tests/tensor_core/max/max_u32_test.cairo b/tests/tensor_core/max/max_u32_test.cairo index a3ee99018..ddbb50280 100644 --- a/tests/tensor_core/max/max_u32_test.cairo +++ b/tests/tensor_core/max/max_u32_test.cairo @@ -11,7 +11,7 @@ mod tensor_1D { fn tensor_max() { let tensor = u32_tensor_1x3_helper(); - let result = tensor.max(); + let result = tensor.max_in_tensor(); assert(result == 2, 'tensor.max = 2'); } } @@ -29,7 +29,7 @@ mod tensor_2D { fn tensor_max() { let tensor = u32_tensor_2x2_helper(); - let result = tensor.max(); + let result = tensor.max_in_tensor(); assert(result == 3, 'tensor.max = 3'); } } @@ -47,7 +47,7 @@ mod tensor_3D { fn tensor_max() { let tensor = u32_tensor_2x2x2_helper(); - let result = tensor.max(); + let result = tensor.max_in_tensor(); assert(result == 7, 'tensor.max = 7'); } } diff --git a/tests/tensor_core/min/min_fp_test/min_fp16x16_test.cairo b/tests/tensor_core/min/min_fp_test/min_fp16x16_test.cairo index 80245e1aa..56d2d5ce6 100644 --- a/tests/tensor_core/min/min_fp_test/min_fp16x16_test.cairo +++ b/tests/tensor_core/min/min_fp_test/min_fp16x16_test.cairo @@ -13,7 +13,7 @@ mod tensor_1D { fn tensor_min() { let tensor = fp_tensor_1x3_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -34,7 +34,7 @@ mod tensor_2D { fn tensor_min() { let tensor = fp_tensor_2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -55,7 +55,7 @@ mod tensor_3D { fn tensor_min() { let tensor = fp_tensor_2x2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } diff --git a/tests/tensor_core/min/min_fp_test/min_fp8x23_test.cairo b/tests/tensor_core/min/min_fp_test/min_fp8x23_test.cairo index 31748f6b3..84335dfef 100644 --- a/tests/tensor_core/min/min_fp_test/min_fp8x23_test.cairo +++ b/tests/tensor_core/min/min_fp_test/min_fp8x23_test.cairo @@ -13,7 +13,7 @@ mod tensor_1D { fn tensor_min() { let tensor = fp_tensor_1x3_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -34,7 +34,7 @@ mod tensor_2D { fn tensor_min() { let tensor = fp_tensor_2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -55,7 +55,7 @@ mod tensor_3D { fn tensor_min() { let tensor = fp_tensor_2x2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } diff --git a/tests/tensor_core/min/min_i32_test.cairo b/tests/tensor_core/min/min_i32_test.cairo index 768a55ae4..c4438fa84 100644 --- a/tests/tensor_core/min/min_i32_test.cairo +++ b/tests/tensor_core/min/min_i32_test.cairo @@ -11,7 +11,7 @@ mod tensor_1D { fn tensor_min() { let tensor = i32_tensor_1x3_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -29,7 +29,7 @@ mod tensor_2D { fn tensor_min() { let tensor = i32_tensor_2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } @@ -47,7 +47,7 @@ mod tensor_3D { fn tensor_min() { let tensor = i32_tensor_2x2x2_helper(); - let result = tensor.min().mag; + let result = tensor.min_in_tensor().mag; assert(result == 0, 'tensor.min = 0'); } } diff --git a/tests/tensor_core/min/min_u32_test.cairo b/tests/tensor_core/min/min_u32_test.cairo index 16ec4ad99..e1103bc5d 100644 --- a/tests/tensor_core/min/min_u32_test.cairo +++ b/tests/tensor_core/min/min_u32_test.cairo @@ -11,7 +11,7 @@ mod tensor_1D { fn tensor_min() { let tensor = u32_tensor_1x3_helper(); - let result = tensor.min(); + let result = tensor.min_in_tensor(); assert(result == 0, 'tensor.min = 0'); } } @@ -29,7 +29,7 @@ mod tensor_2D { fn tensor_min() { let tensor = u32_tensor_2x2_helper(); - let result = tensor.min(); + let result = tensor.min_in_tensor(); assert(result == 0, 'tensor.min = 0'); } } @@ -47,7 +47,7 @@ mod tensor_3D { fn tensor_min() { let tensor = u32_tensor_2x2x2_helper(); - let result = tensor.min(); + let result = tensor.min_in_tensor(); assert(result == 0, 'tensor.min = 0'); } }