From d2b4ed0934f685dd9955d32a9948d470306f66f9 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 24 Oct 2023 14:07:56 +0200 Subject: [PATCH 1/4] Implement 'and' operator --- src/numbers.cairo | 65 +++++++++++++++++++ .../implementations/fp16x16/math/comp.cairo | 9 +++ .../implementations/fp32x32/comp.cairo | 9 +++ .../implementations/fp64x64/comp.cairo | 9 +++ .../implementations/fp8x23/math/comp.cairo | 9 +++ src/operators/tensor/core.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/and.cairo | 46 +++++++++++++ 15 files changed, 177 insertions(+) create mode 100644 src/operators/tensor/math/and.cairo diff --git a/src/numbers.cairo b/src/numbers.cairo index 04ad6efa5..ee89ff4b1 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -46,6 +46,7 @@ trait NumberTrait { fn xor(lhs: T, rhs: T) -> bool; fn or(lhs: T, rhs: T) -> bool; fn sign(self: T) -> T; + fn and(lhs: T, rhs: T) -> bool; } use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; @@ -211,6 +212,10 @@ impl FP8x23Number of NumberTrait { fn sign(self: FP8x23) -> FP8x23 { core_fp8x23::sign(self) } + + fn and(lhs: FP8x23, rhs: FP8x23) -> bool { + comp_fp8x23::and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -376,6 +381,10 @@ impl FP16x16Number of NumberTrait { fn sign(self: FP16x16) -> FP16x16 { core_fp16x16::sign(self) } + + fn and(lhs: FP16x16, rhs: FP16x16) -> bool { + comp_fp16x16::and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; @@ -542,6 +551,10 @@ impl FP64x64Number of NumberTrait { fn sign(self: FP64x64) -> FP64x64 { FP64x64Impl::sign(self) } + + fn and(lhs: FP64x64, rhs: FP64x64) -> bool { + comp_fp64x64::and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; @@ -708,6 +721,10 @@ impl FP32x32Number of NumberTrait { fn sign(self: FP32x32) -> FP32x32 { FP32x32Impl::sign(self) } + + fn and(lhs: FP32x32, rhs: FP32x32) -> bool { + comp_fp32x32::and(lhs, rhs) + } } use orion::numbers::signed_integer::i8 as i8_core; @@ -880,6 +897,14 @@ impl I8Number of NumberTrait { fn sign(self: i8) -> i8 { i8_core::i8_sign(self) } + + fn and(lhs: i8, rhs: i8) -> bool { + if (lhs.mag == 0 || rhs.mag == 0) { + return false; + } else { + return true; + } + } } use orion::numbers::signed_integer::i16 as i16_core; @@ -1052,6 +1077,14 @@ impl i16Number of NumberTrait { fn sign(self: i16) -> i16 { i16_core::i16_sign(self) } + + fn and(lhs: i16, rhs: i16) -> bool { + if (lhs.mag == 0 || rhs.mag == 0) { + return false; + } else { + return true; + } + } } use orion::numbers::signed_integer::i32 as i32_core; @@ -1224,6 +1257,14 @@ impl i32Number of NumberTrait { fn sign(self: i32) -> i32 { i32_core::i32_sign(self) } + + fn and(lhs: i32, rhs: i32) -> bool { + if (lhs.mag == 0 || rhs.mag == 0) { + return false; + } else { + return true; + } + } } use orion::numbers::signed_integer::i64 as i64_core; @@ -1396,6 +1437,14 @@ impl i64Number of NumberTrait { fn sign(self: i64) -> i64 { i64_core::i64_sign(self) } + + fn and(lhs: i64, rhs: i64) -> bool { + if (lhs.mag == 0 || rhs.mag == 0) { + return false; + } else { + return true; + } + } } use orion::numbers::signed_integer::i128 as i128_core; @@ -1569,6 +1618,14 @@ impl i128Number of NumberTrait { fn sign(self: i128) -> i128 { i128_core::i128_sign(self) } + + fn and(lhs: i128, rhs: i128) -> bool { + if (lhs.mag == 0 || rhs.mag == 0) { + return false; + } else { + return true; + } + } } impl u32Number of NumberTrait { @@ -1747,4 +1804,12 @@ impl u32Number of NumberTrait { fn sign(self: u32) -> u32 { panic(array!['not supported!']) } + + fn and(lhs: u32, rhs: u32) -> bool { + if (lhs == 0 || rhs == 0) { + return false; + } else { + return true; + } + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 3aa3219b5..cf1e6ec08 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -35,6 +35,15 @@ fn or(a: FP16x16, b: FP16x16) -> bool { } } +fn and(a: FP16x16, b: FP16x16) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} + // Tests -------------------------------------------------------------------------------------------------------------- #[test] diff --git a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo index 60cae2ab3..de2b7d9a8 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo @@ -17,3 +17,12 @@ fn or(a: FP32x32, b: FP32x32) -> bool { return true; } } + +fn and(a: FP32x32, b: FP32x32) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} diff --git a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo index d26a3180f..9cae44352 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo @@ -17,3 +17,12 @@ fn or(a: FP64x64, b: FP64x64) -> bool { return true; } } + +fn and(a: FP64x64, b: FP64x64) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index 53b1f2e1d..c2158965a 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -35,6 +35,15 @@ fn or(a: FP8x23, b: FP8x23) -> bool { } } +fn and(a: FP8x23, b: FP8x23) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} + // Tests -------------------------------------------------------------------------------------------------------------- #[test] diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 535ed699c..a161087db 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -2669,6 +2669,7 @@ trait TensorTrait { /// ``` /// fn sign(self: @Tensor) -> Tensor; + fn and(self: @Tensor, other: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index ac803904e..c81b08bfc 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -229,6 +229,10 @@ impl FP16x16Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 19557eba1..45329dd74 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -230,6 +230,10 @@ impl FP32x32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 686d319b1..2a1e0a88f 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -230,6 +230,10 @@ impl FP64x64Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index f46e96fb5..0ea96041c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -229,6 +229,10 @@ impl FP8x23Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index dd6ae6f59..66d13c111 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -228,6 +228,10 @@ impl I32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index a4518cefb..d1dfa1cb0 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -227,6 +227,10 @@ impl I8Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 4d26a8634..e073086b1 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -221,6 +221,10 @@ impl U32Tensor of TensorTrait { fn clip(self: @Tensor, min: Option, max: Option) -> Tensor { core::clip(self, min, max) } + + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 5ac834280..cc101b696 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -32,3 +32,4 @@ mod sqrt; mod concat; mod gather; mod sign; +mod and; diff --git a/src/operators/tensor/math/and.cairo b/src/operators/tensor/math/and.cairo new file mode 100644 index 000000000..dba0b0b1d --- /dev/null +++ b/src/operators/tensor/math/and.cairo @@ -0,0 +1,46 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::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 +}; + +fn and< + T, + MAG, + impl TNumber: NumberTrait, + impl UsizeFTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + y: @Tensor, z: @Tensor +) -> Tensor { + let broadcasted_shape = broadcast_shape(*y.shape, *z.shape); + let mut result: Array = ArrayTrait::new(); + + let num_elements = len_from_shape(broadcasted_shape); + + let mut n: usize = 0; + loop { + let indices_broadcasted = unravel_index(n, broadcasted_shape); + + let indices_self = broadcast_index_mapping(*y.shape, indices_broadcasted); + let indices_other = broadcast_index_mapping(*z.shape, indices_broadcasted); + + if NumberTrait::and(*(*y.data)[indices_self], *(*z.data)[indices_other]) { + result.append(1); + } else { + result.append(0); + } + + n += 1; + if n == num_elements { + break (); + }; + }; + + return TensorTrait::new(broadcasted_shape, result.span()); +} From bbf9833c437b83c7b4dd1fd4dde194717321628a Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 24 Oct 2023 15:16:58 +0200 Subject: [PATCH 2/4] Add nodegen tests --- nodegen/node/and.py | 168 ++++++++++++++++++ tests/src/nodes.cairo | 10 ++ tests/src/nodes/and_fp16x16.cairo | 22 +++ tests/src/nodes/and_fp16x16/input_0.cairo | 42 +++++ tests/src/nodes/and_fp16x16/input_1.cairo | 42 +++++ tests/src/nodes/and_fp16x16/output_0.cairo | 40 +++++ tests/src/nodes/and_fp16x16_broadcast.cairo | 22 +++ .../nodes/and_fp16x16_broadcast/input_0.cairo | 18 ++ .../nodes/and_fp16x16_broadcast/input_1.cairo | 16 ++ .../and_fp16x16_broadcast/output_0.cairo | 16 ++ tests/src/nodes/and_fp8x23.cairo | 22 +++ tests/src/nodes/and_fp8x23/input_0.cairo | 42 +++++ tests/src/nodes/and_fp8x23/input_1.cairo | 42 +++++ tests/src/nodes/and_fp8x23/output_0.cairo | 40 +++++ tests/src/nodes/and_fp8x23_broadcast.cairo | 22 +++ .../nodes/and_fp8x23_broadcast/input_0.cairo | 18 ++ .../nodes/and_fp8x23_broadcast/input_1.cairo | 16 ++ .../nodes/and_fp8x23_broadcast/output_0.cairo | 16 ++ tests/src/nodes/and_i32.cairo | 22 +++ tests/src/nodes/and_i32/input_0.cairo | 41 +++++ tests/src/nodes/and_i32/input_1.cairo | 41 +++++ tests/src/nodes/and_i32/output_0.cairo | 40 +++++ tests/src/nodes/and_i32_broadcast.cairo | 22 +++ .../src/nodes/and_i32_broadcast/input_0.cairo | 17 ++ .../src/nodes/and_i32_broadcast/input_1.cairo | 15 ++ .../nodes/and_i32_broadcast/output_0.cairo | 16 ++ tests/src/nodes/and_i8.cairo | 22 +++ tests/src/nodes/and_i8/input_0.cairo | 41 +++++ tests/src/nodes/and_i8/input_1.cairo | 41 +++++ tests/src/nodes/and_i8/output_0.cairo | 40 +++++ tests/src/nodes/and_i8_broadcast.cairo | 22 +++ .../src/nodes/and_i8_broadcast/input_0.cairo | 17 ++ .../src/nodes/and_i8_broadcast/input_1.cairo | 15 ++ .../src/nodes/and_i8_broadcast/output_0.cairo | 16 ++ tests/src/nodes/and_u32.cairo | 22 +++ tests/src/nodes/and_u32/input_0.cairo | 40 +++++ tests/src/nodes/and_u32/input_1.cairo | 40 +++++ tests/src/nodes/and_u32/output_0.cairo | 40 +++++ tests/src/nodes/and_u32_broadcast.cairo | 22 +++ .../src/nodes/and_u32_broadcast/input_0.cairo | 16 ++ .../src/nodes/and_u32_broadcast/input_1.cairo | 14 ++ .../nodes/and_u32_broadcast/output_0.cairo | 16 ++ 42 files changed, 1252 insertions(+) create mode 100644 nodegen/node/and.py create mode 100644 tests/src/nodes/and_fp16x16.cairo create mode 100644 tests/src/nodes/and_fp16x16/input_0.cairo create mode 100644 tests/src/nodes/and_fp16x16/input_1.cairo create mode 100644 tests/src/nodes/and_fp16x16/output_0.cairo create mode 100644 tests/src/nodes/and_fp16x16_broadcast.cairo create mode 100644 tests/src/nodes/and_fp16x16_broadcast/input_0.cairo create mode 100644 tests/src/nodes/and_fp16x16_broadcast/input_1.cairo create mode 100644 tests/src/nodes/and_fp16x16_broadcast/output_0.cairo create mode 100644 tests/src/nodes/and_fp8x23.cairo create mode 100644 tests/src/nodes/and_fp8x23/input_0.cairo create mode 100644 tests/src/nodes/and_fp8x23/input_1.cairo create mode 100644 tests/src/nodes/and_fp8x23/output_0.cairo create mode 100644 tests/src/nodes/and_fp8x23_broadcast.cairo create mode 100644 tests/src/nodes/and_fp8x23_broadcast/input_0.cairo create mode 100644 tests/src/nodes/and_fp8x23_broadcast/input_1.cairo create mode 100644 tests/src/nodes/and_fp8x23_broadcast/output_0.cairo create mode 100644 tests/src/nodes/and_i32.cairo create mode 100644 tests/src/nodes/and_i32/input_0.cairo create mode 100644 tests/src/nodes/and_i32/input_1.cairo create mode 100644 tests/src/nodes/and_i32/output_0.cairo create mode 100644 tests/src/nodes/and_i32_broadcast.cairo create mode 100644 tests/src/nodes/and_i32_broadcast/input_0.cairo create mode 100644 tests/src/nodes/and_i32_broadcast/input_1.cairo create mode 100644 tests/src/nodes/and_i32_broadcast/output_0.cairo create mode 100644 tests/src/nodes/and_i8.cairo create mode 100644 tests/src/nodes/and_i8/input_0.cairo create mode 100644 tests/src/nodes/and_i8/input_1.cairo create mode 100644 tests/src/nodes/and_i8/output_0.cairo create mode 100644 tests/src/nodes/and_i8_broadcast.cairo create mode 100644 tests/src/nodes/and_i8_broadcast/input_0.cairo create mode 100644 tests/src/nodes/and_i8_broadcast/input_1.cairo create mode 100644 tests/src/nodes/and_i8_broadcast/output_0.cairo create mode 100644 tests/src/nodes/and_u32.cairo create mode 100644 tests/src/nodes/and_u32/input_0.cairo create mode 100644 tests/src/nodes/and_u32/input_1.cairo create mode 100644 tests/src/nodes/and_u32/output_0.cairo create mode 100644 tests/src/nodes/and_u32_broadcast.cairo create mode 100644 tests/src/nodes/and_u32_broadcast/input_0.cairo create mode 100644 tests/src/nodes/and_u32_broadcast/input_1.cairo create mode 100644 tests/src/nodes/and_u32_broadcast/output_0.cairo diff --git a/nodegen/node/and.py b/nodegen/node/and.py new file mode 100644 index 000000000..0a1741a21 --- /dev/null +++ b/nodegen/node/and.py @@ -0,0 +1,168 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class And(RunAll): + @staticmethod + def and_u32(): + 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.logical_and(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 = "and_u32" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", 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.logical_and(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 = "and_u32_broadcast" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + default() + broadcast() + + @staticmethod + def and_i32(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) + z = np.logical_and(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "and_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.int32) + y = np.random.randint(-3, 3, (1, 2)).astype(np.int32) + z = np.logical_and(x, y) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "and_i32_broadcast" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + default() + broadcast() + + @staticmethod + def and_i8(): + def default(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) + y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) + z = np.logical_and(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "and_i8" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.int8) + y = np.random.randint(-3, 3, (1, 2)).astype(np.int8) + z = np.logical_and(x, y) + + x = Tensor(Dtype.I8, x.shape, x.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + z = Tensor(Dtype.U32, z.shape, z.flatten()) + + name = "and_i8_broadcast" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + default() + broadcast() + + @staticmethod + def and_fp8x23(): + 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.logical_and(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.U32, z.shape, z.flatten()) + + name = "and_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.logical_and(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.U32, z.shape, z.flatten()) + + name = "and_fp8x23_broadcast" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + default() + broadcast() + + @staticmethod + def and_fp16x16(): + 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.logical_and(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.U32, z.shape, z.flatten()) + + name = "and_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + def broadcast(): + x = np.random.randint(-3, 3, (2, 2)).astype(np.float64) + y = np.random.randint(-3, 3, (1, 2)).astype(np.float64) + z = np.logical_and(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.U32, z.shape, z.flatten()) + + name = "and_fp16x16_broadcast" + make_node([x, y], [z], name) + make_test([x, y], z, "input_0.and(@input_1)", name) + + default() + broadcast() diff --git a/tests/src/nodes.cairo b/tests/src/nodes.cairo index 398edc4bf..a0c1c5781 100644 --- a/tests/src/nodes.cairo +++ b/tests/src/nodes.cairo @@ -433,3 +433,13 @@ mod clip_i8_2d; mod clip_i8_3d; mod clip_u32_2d; mod clip_u32_3d; +mod and_fp16x16; +mod and_fp16x16_broadcast; +mod and_fp8x23; +mod and_fp8x23_broadcast; +mod and_i32; +mod and_i32_broadcast; +mod and_i8; +mod and_i8_broadcast; +mod and_u32; +mod and_u32_broadcast; diff --git a/tests/src/nodes/and_fp16x16.cairo b/tests/src/nodes/and_fp16x16.cairo new file mode 100644 index 000000000..87b32da17 --- /dev/null +++ b/tests/src/nodes/and_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16/input_0.cairo b/tests/src/nodes/and_fp16x16/input_0.cairo new file mode 100644 index 000000000..05fb9a94d --- /dev/null +++ b/tests/src/nodes/and_fp16x16/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + 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: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16/input_1.cairo b/tests/src/nodes/and_fp16x16/input_1.cairo new file mode 100644 index 000000000..991a8f688 --- /dev/null +++ b/tests/src/nodes/and_fp16x16/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: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16/output_0.cairo b/tests/src/nodes/and_fp16x16/output_0.cairo new file mode 100644 index 000000000..75d7aed70 --- /dev/null +++ b/tests/src/nodes/and_fp16x16/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16_broadcast.cairo b/tests/src/nodes/and_fp16x16_broadcast.cairo new file mode 100644 index 000000000..3abd8c250 --- /dev/null +++ b/tests/src/nodes/and_fp16x16_broadcast.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::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_fp16x16_broadcast() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/src/nodes/and_fp16x16_broadcast/input_0.cairo new file mode 100644 index 000000000..a461be36c --- /dev/null +++ b/tests/src/nodes/and_fp16x16_broadcast/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: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/src/nodes/and_fp16x16_broadcast/input_1.cairo new file mode 100644 index 000000000..0bc098ab8 --- /dev/null +++ b/tests/src/nodes/and_fp16x16_broadcast/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: 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/src/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/src/nodes/and_fp16x16_broadcast/output_0.cairo new file mode 100644 index 000000000..2094003c4 --- /dev/null +++ b/tests/src/nodes/and_fp16x16_broadcast/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(0); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23.cairo b/tests/src/nodes/and_fp8x23.cairo new file mode 100644 index 000000000..17e9bdad0 --- /dev/null +++ b/tests/src/nodes/and_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23/input_0.cairo b/tests/src/nodes/and_fp8x23/input_0.cairo new file mode 100644 index 000000000..d43898dd1 --- /dev/null +++ b/tests/src/nodes/and_fp8x23/input_0.cairo @@ -0,0 +1,42 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, 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: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23/input_1.cairo b/tests/src/nodes/and_fp8x23/input_1.cairo new file mode 100644 index 000000000..d2d59fda5 --- /dev/null +++ b/tests/src/nodes/and_fp8x23/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: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23/output_0.cairo b/tests/src/nodes/and_fp8x23/output_0.cairo new file mode 100644 index 000000000..e2e18825c --- /dev/null +++ b/tests/src/nodes/and_fp8x23/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23_broadcast.cairo b/tests/src/nodes/and_fp8x23_broadcast.cairo new file mode 100644 index 000000000..d54fd4afe --- /dev/null +++ b/tests/src/nodes/and_fp8x23_broadcast.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::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_fp8x23_broadcast() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/src/nodes/and_fp8x23_broadcast/input_0.cairo new file mode 100644 index 000000000..4bcaf93cd --- /dev/null +++ b/tests/src/nodes/and_fp8x23_broadcast/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: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/src/nodes/and_fp8x23_broadcast/input_1.cairo new file mode 100644 index 000000000..538d00e70 --- /dev/null +++ b/tests/src/nodes/and_fp8x23_broadcast/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/src/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/src/nodes/and_fp8x23_broadcast/output_0.cairo new file mode 100644 index 000000000..e7b1da4b1 --- /dev/null +++ b/tests/src/nodes/and_fp8x23_broadcast/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(1); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32.cairo b/tests/src/nodes/and_i32.cairo new file mode 100644 index 000000000..6c85c1433 --- /dev/null +++ b/tests/src/nodes/and_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32/input_0.cairo b/tests/src/nodes/and_i32/input_0.cairo new file mode 100644 index 000000000..246a30bdf --- /dev/null +++ b/tests/src/nodes/and_i32/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32/input_1.cairo b/tests/src/nodes/and_i32/input_1.cairo new file mode 100644 index 000000000..2798d8bf5 --- /dev/null +++ b/tests/src/nodes/and_i32/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: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, 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: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32/output_0.cairo b/tests/src/nodes/and_i32/output_0.cairo new file mode 100644 index 000000000..5cfd192c9 --- /dev/null +++ b/tests/src/nodes/and_i32/output_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32_broadcast.cairo b/tests/src/nodes/and_i32_broadcast.cairo new file mode 100644 index 000000000..33f7abd02 --- /dev/null +++ b/tests/src/nodes/and_i32_broadcast.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::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_i32_broadcast() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32_broadcast/input_0.cairo b/tests/src/nodes/and_i32_broadcast/input_0.cairo new file mode 100644 index 000000000..8893b6d3b --- /dev/null +++ b/tests/src/nodes/and_i32_broadcast/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: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32_broadcast/input_1.cairo b/tests/src/nodes/and_i32_broadcast/input_1.cairo new file mode 100644 index 000000000..0e3bae4c3 --- /dev/null +++ b/tests/src/nodes/and_i32_broadcast/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: 3, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i32_broadcast/output_0.cairo b/tests/src/nodes/and_i32_broadcast/output_0.cairo new file mode 100644 index 000000000..386b678ef --- /dev/null +++ b/tests/src/nodes/and_i32_broadcast/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(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8.cairo b/tests/src/nodes/and_i8.cairo new file mode 100644 index 000000000..7d2e67c2d --- /dev/null +++ b/tests/src/nodes/and_i8.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::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_i8() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8/input_0.cairo b/tests/src/nodes/and_i8/input_0.cairo new file mode 100644 index 000000000..4271563b5 --- /dev/null +++ b/tests/src/nodes/and_i8/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: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8/input_1.cairo b/tests/src/nodes/and_i8/input_1.cairo new file mode 100644 index 000000000..ba15f89b4 --- /dev/null +++ b/tests/src/nodes/and_i8/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: 2, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8/output_0.cairo b/tests/src/nodes/and_i8/output_0.cairo new file mode 100644 index 000000000..3e2f5f3f3 --- /dev/null +++ b/tests/src/nodes/and_i8/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(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8_broadcast.cairo b/tests/src/nodes/and_i8_broadcast.cairo new file mode 100644 index 000000000..12d5f13e7 --- /dev/null +++ b/tests/src/nodes/and_i8_broadcast.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::U32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_and_i8_broadcast() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8_broadcast/input_0.cairo b/tests/src/nodes/and_i8_broadcast/input_0.cairo new file mode 100644 index 000000000..6de8ea3a8 --- /dev/null +++ b/tests/src/nodes/and_i8_broadcast/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: 1, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8_broadcast/input_1.cairo b/tests/src/nodes/and_i8_broadcast/input_1.cairo new file mode 100644 index 000000000..1bc1a2f2b --- /dev/null +++ b/tests/src/nodes/and_i8_broadcast/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: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_i8_broadcast/output_0.cairo b/tests/src/nodes/and_i8_broadcast/output_0.cairo new file mode 100644 index 000000000..328774a25 --- /dev/null +++ b/tests/src/nodes/and_i8_broadcast/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(0); + 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/src/nodes/and_u32.cairo b/tests/src/nodes/and_u32.cairo new file mode 100644 index 000000000..477f59981 --- /dev/null +++ b/tests/src/nodes/and_u32.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_and_u32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32/input_0.cairo b/tests/src/nodes/and_u32/input_0.cairo new file mode 100644 index 000000000..a1d822fcd --- /dev/null +++ b/tests/src/nodes/and_u32/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(2); + data.append(5); + data.append(2); + data.append(4); + data.append(3); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(4); + data.append(3); + data.append(0); + data.append(2); + data.append(5); + data.append(1); + data.append(3); + data.append(5); + data.append(0); + data.append(5); + data.append(1); + data.append(5); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32/input_1.cairo b/tests/src/nodes/and_u32/input_1.cairo new file mode 100644 index 000000000..37ce51b01 --- /dev/null +++ b/tests/src/nodes/and_u32/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(0); + data.append(3); + data.append(0); + data.append(4); + data.append(5); + data.append(2); + data.append(1); + data.append(3); + data.append(5); + data.append(0); + data.append(0); + data.append(0); + data.append(5); + data.append(2); + data.append(1); + data.append(2); + data.append(5); + data.append(1); + data.append(4); + data.append(1); + data.append(4); + data.append(4); + data.append(1); + data.append(1); + data.append(3); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32/output_0.cairo b/tests/src/nodes/and_u32/output_0.cairo new file mode 100644 index 000000000..0eced5867 --- /dev/null +++ b/tests/src/nodes/and_u32/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(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32_broadcast.cairo b/tests/src/nodes/and_u32_broadcast.cairo new file mode 100644 index 000000000..a98e806d9 --- /dev/null +++ b/tests/src/nodes/and_u32_broadcast.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_and_u32_broadcast() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.and(@input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32_broadcast/input_0.cairo b/tests/src/nodes/and_u32_broadcast/input_0.cairo new file mode 100644 index 000000000..afd5ea46c --- /dev/null +++ b/tests/src/nodes/and_u32_broadcast/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(2); + data.append(2); + data.append(5); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32_broadcast/input_1.cairo b/tests/src/nodes/and_u32_broadcast/input_1.cairo new file mode 100644 index 000000000..ea3e50244 --- /dev/null +++ b/tests/src/nodes/and_u32_broadcast/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(5); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/src/nodes/and_u32_broadcast/output_0.cairo b/tests/src/nodes/and_u32_broadcast/output_0.cairo new file mode 100644 index 000000000..e7b1da4b1 --- /dev/null +++ b/tests/src/nodes/and_u32_broadcast/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(1); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From eebe7345df48f289322a3452e3a7a74a4a9c2667 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 24 Oct 2023 16:12:54 +0200 Subject: [PATCH 3/4] Add docstring --- docs/framework/operators/tensor/README.md | 1 + docs/framework/operators/tensor/tensor.and.md | 67 ++++++++++++++++++ src/operators/tensor/core.cairo | 69 +++++++++++++++++++ src/operators/tensor/math/and.cairo | 1 + 4 files changed, 138 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.and.md diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index b33f330c7..7017e4056 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -82,6 +82,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.unsqueeze`](tensor.unsqueeze.md) | Inserts single-dimensional entries to the shape of an input tensor. | | [`tensor.sign`](tensor.sign.md) | Calculates the sign of the given input tensor element-wise. | | [`tensor.clip`](tensor.clip.md) | Clip operator limits the given input within an interval. | +| [`tensor.and`](tensor.and.md) | Computes the logical AND of two tensors element-wise. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.and.md b/docs/framework/operators/tensor/tensor.and.md new file mode 100644 index 000000000..94556ce0f --- /dev/null +++ b/docs/framework/operators/tensor/tensor.and.md @@ -0,0 +1,67 @@ +#tensor.and + +```rust + fn and(self: @Tensor, other: @Tensor) -> Tensor; +``` + +Computes the logical AND of two tensors element-wise. +The input tensors must have either: +* Exactly the same shape +* The same number of dimensions and the length of each dimension is either a common length or 1. + +## Args + +* `self`(`@Tensor`) - The first tensor to be compared +* `other`(`@Tensor`) - The second tensor to be compared + +## Panics + +* Panics if the shapes are not equal or broadcastable + +## Returns + +A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. + +## Examples + +Case 1: Compare tensors with same shape + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn and_example() -> Tensor { + let tensor_1 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + ); + + let tensor_2 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 0, 1, 2, 0, 1, 2].span(), + ); + + return tensor_1.and(@tensor_2); +} +>>> [0,1,1,0,1,1,0,1,1] +``` + +Case 2: Compare tensors with different shapes + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn and_example() -> Tensor { + let tensor_1 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + ); + + let tensor_2 = TensorTrait::::new( + shape: array![1, 3].span(), data: array![0, 1, 2].span(), + ); + + return tensor_1.and(@tensor_2); +} +>>> [0,1,1,0,1,1,0,1,1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index a161087db..b8f5a7fd0 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -78,6 +78,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new @@ -2669,6 +2670,74 @@ trait TensorTrait { /// ``` /// fn sign(self: @Tensor) -> Tensor; + /// #tensor.and + /// + /// ```rust + /// fn and(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the logical AND of two tensors element-wise. + /// The input tensors must have either: + /// * Exactly the same shape + /// * The same number of dimensions and the length of each dimension is either a common length or 1. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be compared + /// * `other`(`@Tensor`) - The second tensor to be compared + /// + /// ## Panics + /// + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Returns + /// + /// A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. + /// + /// ## Examples + /// + /// Case 1: Compare tensors with same shape + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn and_example() -> Tensor { + /// let tensor_1 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + /// ); + /// + /// let tensor_2 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 0, 1, 2, 0, 1, 2].span(), + /// ); + /// + /// return tensor_1.and(@tensor_2); + /// } + /// >>> [0,1,1,0,1,1,0,1,1] + /// ``` + /// + /// Case 2: Compare tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn and_example() -> Tensor { + /// let tensor_1 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + /// ); + /// + /// let tensor_2 = TensorTrait::::new( + /// shape: array![1, 3].span(), data: array![0, 1, 2].span(), + /// ); + /// + /// return tensor_1.and(@tensor_2); + /// } + /// >>> [0,1,1,0,1,1,0,1,1] + /// ``` + /// fn and(self: @Tensor, other: @Tensor) -> Tensor; } diff --git a/src/operators/tensor/math/and.cairo b/src/operators/tensor/math/and.cairo index dba0b0b1d..80872185e 100644 --- a/src/operators/tensor/math/and.cairo +++ b/src/operators/tensor/math/and.cairo @@ -8,6 +8,7 @@ use orion::operators::tensor::helpers::{ broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility }; +/// Cf: TensorTrait::and docstring fn and< T, MAG, From 1245027800bf39a45fc81583bf3c747b809e5f51 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 25 Oct 2023 11:01:10 +0300 Subject: [PATCH 4/4] add AND in fp16x16w and fp8x23w + missing doc --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 115 +++++++++--------- src/numbers.cairo | 8 ++ .../fp16x16wide/math/comp.cairo | 9 ++ .../fp8x23wide/math/comp.cairo | 9 ++ .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + 7 files changed, 93 insertions(+), 57 deletions(-) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index cc8fe91b1..f1543c5c6 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -88,6 +88,7 @@ * [tensor.sign](framework/operators/tensor/tensor.sign.md) * [tensor.clip](framework/operators/tensor/tensor.clip.md) * [tensor.identity](framework/operators/tensor/tensor.identity.md) + * [tensor.and](framework/operators/tensor/tensor.and.md) * [Neural Network](framework/operators/neural-network/README.md) * [nn.relu](framework/operators/neural-network/nn.relu.md) * [nn.leaky\_relu](framework/operators/neural-network/nn.leaky\_relu.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 35e2daf55..c2d49c2be 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -4,62 +4,63 @@ To see the full list of available ONNX Operators refer to [this table](https://g You can see below the list of current supported ONNX Operators: -| Operator | Implemented | -| :-------------------------------------------------------------: | :------------------: | -| [MatMul](operators/tensor/tensor.matmul.md) | :white\_check\_mark: | -| [MatMulInteger](operators/tensor/tensor.matmul.md) | :white\_check\_mark: | -| [Add](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | -| [Sub](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | -| [Mul](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | -| [Div](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | -| [Equal](operators/tensor/tensor.equal.md) | :white\_check\_mark: | -| [Greater](operators/tensor/tensor.greater.md) | :white\_check\_mark: | -| [GreaterOrEqual](operators/tensor/tensor.greater\_equal.md) | :white\_check\_mark: | -| [Less](operators/tensor/tensor.less.md) | :white\_check\_mark: | -| [LessOrEqual](operators/tensor/tensor.less\_equal.md) | :white\_check\_mark: | -| [Abs](operators/tensor/tensor.abs.md) | :white\_check\_mark: | -| [Neg](operators/tensor/tensor.neg.md) | :white\_check\_mark: | -| [Ceil](operators/tensor/tensor.ceil.md) | :white\_check\_mark: | -| [Exp](operators/tensor/tensor.exp.md) | :white\_check\_mark: | -| [Ln](operators/tensor/tensor.log.md) | :white\_check\_mark: | -| [Reshape](operators/tensor/tensor.reshape.md) | :white\_check\_mark: | -| [Transpose](operators/tensor/tensor.transpose.md) | :white\_check\_mark: | -| [ArgMax](operators/tensor/tensor.argmax.md) | :white\_check\_mark: | -| [ArgMin](operators/tensor/tensor.argmin.md) | :white\_check\_mark: | -| [ReduceSum](operators/tensor/tensor.reduce\_sum.md) | :white\_check\_mark: | -| [CumSum](operators/tensor/tensor.cumsum.md) | :white\_check\_mark: | -| [Cos](operators/tensor/tensor.cos.md) | :white\_check\_mark: | -| [Sin](operators/tensor/tensor.sin.md) | :white\_check\_mark: | -| [Asin](operators/tensor/tensor.asin.md) | :white\_check\_mark: | -| [Flatten](operators/tensor/tensor.flatten.md) | :white\_check\_mark: | -| [Relu](operators/neural-network/nn.relu.md) | :white\_check\_mark: | -| [LeakyRelu](operators/neural-network/nn.leaky\_relu.md) | :white\_check\_mark: | -|[ThresholdedRelu](operators/neural-network/nn.thresholded\_relu.md)| :white\_check\_mark: | -| [Sigmoid](operators/neural-network/nn.sigmoid.md) | :white\_check\_mark: | -| [Softmax](operators/neural-network/nn.softmax.md) | :white\_check\_mark: | -| [LogSoftmax](operators/neural-network/nn.logsoftmax.md) | :white\_check\_mark: | -| [Softsign](operators/neural-network/nn.softsign.md) | :white\_check\_mark: | -| [Softplus](operators/neural-network/nn.softplus.md) | :white\_check\_mark: | -| [Linear](operators/neural-network/nn.linear.md) | :white\_check\_mark: | -| [HardSigmoid](operators/neural-network/nn.hard\_sigmoid.md) | :white\_check\_mark: | -| [Sinh](operators/tensor/tensor.sinh.md) | :white\_check\_mark: | -| [Asinh](operators/tensor/tensor.asinh.md) | :white\_check\_mark: | -| [Cosh](operators/tensor/tensor.cosh.md) | :white\_check\_mark: | -| [ACosh](operators/tensor/tensor.acosh.md) | :white\_check\_mark: | -| [Tanh](operators/tensor/tensor.tanh.md) | :white\_check\_mark: | -| [Acos](operators/tensor/tensor.acos.md) | :white\_check\_mark: | -| [Sqrt](operators/tensor/tensor.sqrt.md) | :white\_check\_mark: | -| [Onehot](operators/tensor/tensor.onehot.md) | :white\_check\_mark: | -| [Slice](operators/tensor/tensor.slice.md) | :white\_check\_mark: | -| [Concat](operators/tensor/tensor.concat.md) | :white\_check\_mark: | -| [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: | -| [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: | -| [Sign](operators/tensor/tensor.sign.md) | :white\_check\_mark: | -| [Clip](operators/tensor/tensor.clip.md) | :white\_check\_mark: | -| [Identity](operators/tensor/tensor.identity.md) | :white\_check\_mark: | +| Operator | Implemented | +| :-----------------------------------------------------------------: | :------------------: | +| [MatMul](operators/tensor/tensor.matmul.md) | :white\_check\_mark: | +| [MatMulInteger](operators/tensor/tensor.matmul.md) | :white\_check\_mark: | +| [Add](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | +| [Sub](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | +| [Mul](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | +| [Div](operators/tensor/#arithmetic-operations) | :white\_check\_mark: | +| [Equal](operators/tensor/tensor.equal.md) | :white\_check\_mark: | +| [Greater](operators/tensor/tensor.greater.md) | :white\_check\_mark: | +| [GreaterOrEqual](operators/tensor/tensor.greater\_equal.md) | :white\_check\_mark: | +| [Less](operators/tensor/tensor.less.md) | :white\_check\_mark: | +| [LessOrEqual](operators/tensor/tensor.less\_equal.md) | :white\_check\_mark: | +| [Abs](operators/tensor/tensor.abs.md) | :white\_check\_mark: | +| [Neg](operators/tensor/tensor.neg.md) | :white\_check\_mark: | +| [Ceil](operators/tensor/tensor.ceil.md) | :white\_check\_mark: | +| [Exp](operators/tensor/tensor.exp.md) | :white\_check\_mark: | +| [Ln](operators/tensor/tensor.log.md) | :white\_check\_mark: | +| [Reshape](operators/tensor/tensor.reshape.md) | :white\_check\_mark: | +| [Transpose](operators/tensor/tensor.transpose.md) | :white\_check\_mark: | +| [ArgMax](operators/tensor/tensor.argmax.md) | :white\_check\_mark: | +| [ArgMin](operators/tensor/tensor.argmin.md) | :white\_check\_mark: | +| [ReduceSum](operators/tensor/tensor.reduce\_sum.md) | :white\_check\_mark: | +| [CumSum](operators/tensor/tensor.cumsum.md) | :white\_check\_mark: | +| [Cos](operators/tensor/tensor.cos.md) | :white\_check\_mark: | +| [Sin](operators/tensor/tensor.sin.md) | :white\_check\_mark: | +| [Asin](operators/tensor/tensor.asin.md) | :white\_check\_mark: | +| [Flatten](operators/tensor/tensor.flatten.md) | :white\_check\_mark: | +| [Relu](operators/neural-network/nn.relu.md) | :white\_check\_mark: | +| [LeakyRelu](operators/neural-network/nn.leaky\_relu.md) | :white\_check\_mark: | +| [ThresholdedRelu](operators/neural-network/nn.thresholded\_relu.md) | :white\_check\_mark: | +| [Sigmoid](operators/neural-network/nn.sigmoid.md) | :white\_check\_mark: | +| [Softmax](operators/neural-network/nn.softmax.md) | :white\_check\_mark: | +| [LogSoftmax](operators/neural-network/nn.logsoftmax.md) | :white\_check\_mark: | +| [Softsign](operators/neural-network/nn.softsign.md) | :white\_check\_mark: | +| [Softplus](operators/neural-network/nn.softplus.md) | :white\_check\_mark: | +| [Linear](operators/neural-network/nn.linear.md) | :white\_check\_mark: | +| [HardSigmoid](operators/neural-network/nn.hard\_sigmoid.md) | :white\_check\_mark: | +| [Sinh](operators/tensor/tensor.sinh.md) | :white\_check\_mark: | +| [Asinh](operators/tensor/tensor.asinh.md) | :white\_check\_mark: | +| [Cosh](operators/tensor/tensor.cosh.md) | :white\_check\_mark: | +| [ACosh](operators/tensor/tensor.acosh.md) | :white\_check\_mark: | +| [Tanh](operators/tensor/tensor.tanh.md) | :white\_check\_mark: | +| [Acos](operators/tensor/tensor.acos.md) | :white\_check\_mark: | +| [Sqrt](operators/tensor/tensor.sqrt.md) | :white\_check\_mark: | +| [Onehot](operators/tensor/tensor.onehot.md) | :white\_check\_mark: | +| [Slice](operators/tensor/tensor.slice.md) | :white\_check\_mark: | +| [Concat](operators/tensor/tensor.concat.md) | :white\_check\_mark: | +| [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: | +| [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: | +| [Sign](operators/tensor/tensor.sign.md) | :white\_check\_mark: | +| [Clip](operators/tensor/tensor.clip.md) | :white\_check\_mark: | +| [Identity](operators/tensor/tensor.identity.md) | :white\_check\_mark: | +| [And](operators/tensor/tensor.and.md) | :white\_check\_mark: | Current Operators support: **51/156 (33%)** diff --git a/src/numbers.cairo b/src/numbers.cairo index 821e68812..5432d67f8 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -390,6 +390,10 @@ impl FP8x23WNumber of NumberTrait { fn sign(self: FP8x23W) -> FP8x23W { core_fp8x23wide::sign(self) } + + fn and(lhs: FP8x23W, rhs: FP8x23W) -> bool { + comp_fp8x23wide::and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -732,6 +736,10 @@ impl FP16x16WNumber of NumberTrait { fn sign(self: FP16x16W) -> FP16x16W { core_fp16x16wide::sign(self) } + + fn and(lhs: FP16x16W, rhs: FP16x16W) -> bool { + comp_fp16x16wide::and(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 63a3e4855..4f815a124 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -35,6 +35,15 @@ fn or(a: FP16x16W, b: FP16x16W) -> bool { } } +fn and(a: FP16x16W, b: FP16x16W) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} + // Tests -------------------------------------------------------------------------------------------------------------- #[test] diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index 95b329109..5cacb7f0e 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -35,6 +35,15 @@ fn or(a: FP8x23W, b: FP8x23W) -> bool { } } +fn and(a: FP8x23W, b: FP8x23W) -> bool { + let zero = FixedTrait::new(0, false); + if a == zero || b == zero { + return false; + } else { + return true; + } +} + // Tests -------------------------------------------------------------------------------------------------------------- #[test] diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 2669c91e5..101ad4d21 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -242,6 +242,10 @@ impl FP16x16WTensor of TensorTrait { core::clip(self, min, max) } + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } + fn identity(self: @Tensor) -> Tensor { core::identity(self) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index a085c1f8b..e81beb028 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -234,6 +234,10 @@ impl FP8x23WTensor of TensorTrait { core::clip(self, min, max) } + fn and(self: @Tensor, other: @Tensor) -> Tensor { + math::and::and(self, other) + } + fn identity(self: @Tensor) -> Tensor { core::identity(self) }