diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 477601b37..edf69b2a1 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -124,6 +124,7 @@ * [tensor.bitwise\_and](framework/operators/tensor/tensor.bitwise\_and.md) * [tensor.bitwise\_xor](framework/operators/tensor/tensor.bitwise\_xor.md) * [tensor.bitwise\_or](framework/operators/tensor/tensor.bitwise\_or.md) + * [tensor.bitwise\_not](framework/operators/tensor/tensor.bitwise\_not.md) * [tensor.resize](framework/operators/tensor/tensor.resize.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index f3f84ac3f..699ddafb5 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -82,6 +82,7 @@ You can see below the list of current supported ONNX Operators: | [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: | | [BitwiseOr](operators/tensor/tensor.bitwise_or.md) | :white\_check\_mark: | | [BitwiseXor](operators/tensor/tensor.bitwise_xor.md) | :white\_check\_mark: | +| [BitwiseNot](operators/tensor/tensor.bitwise_not.md) | :white\_check\_mark: | | [Resize](operators/tensor/tensor.resize.md) | :white\_check\_mark: | | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | @@ -127,4 +128,4 @@ You can see below the list of current supported ONNX Operators: | [RandomUniformLike](operators/tensor/tensor.tensor.random_uniform_like.md) | :white\_check\_mark: | | [LabelEncoder](operators/tensor/tensor.label_encoder.md) | :white\_check\_mark: | -Current Operators support: **118/156 (75%)** +Current Operators support: **119/156 (75%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index fe2995096..e5a877e22 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -98,6 +98,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.bitwise_and`](tensor.bitwise\_and.md) | Computes the bitwise AND of two tensors element-wise. | | [`tensor.bitwise_xor`](tensor.bitwise\_xor.md) | Computes the bitwise XOR of two tensors element-wise. | | [`tensor.bitwise_or`](tensor.bitwise\_or.md) | Computes the bitwise OR of two tensors element-wise. | +| [`tensor.bitwise_not`](tensor.bitwise\_not.md) | Computes the bitwise NOT of tensor element-wise. | | [`tensor.resize`](tensor.resize.md) | Resizes the input tensor. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. | diff --git a/docs/framework/operators/tensor/tensor.bitwise_not.md b/docs/framework/operators/tensor/tensor.bitwise_not.md new file mode 100644 index 000000000..cf38b79eb --- /dev/null +++ b/docs/framework/operators/tensor/tensor.bitwise_not.md @@ -0,0 +1,33 @@ +#tensor.bitwise_not + +```rust + fn bitwise_not(self: @Tensor) -> Tensor; +``` + +Computes the bitwise NOT of the tensor element-wise. + +## Args + +* `self`(`@Tensor`) - The the tensor to be bitwise NOTed + + +## Returns + +A new `Tensor` with the same shape as the broadcasted input. + +## Example + +```rust +use core::array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn bitwise_not_example() -> Tensor { + let tensor_1 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + ); + + return tensor_1.bitwise_not(); +} +>>> [4294967295,4294967294,4294967293,4294967292,4294967291,4294967290,4294967289,4294967288,4294967287] +``` diff --git a/src/numbers.cairo b/src/numbers.cairo index ddd95fa10..76a01f979 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -64,6 +64,7 @@ trait NumberTrait { fn bitwise_or(lhs: T, rhs: T) -> T; fn add(lhs: T, rhs: T) -> T; fn sub(lhs: T, rhs: T) -> T; + fn bitwise_not(self: T) -> T; } use orion::numbers::fixed_point::implementations::fp8x23::core::{ @@ -291,6 +292,10 @@ impl FP8x23Number of NumberTrait { fn sub(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { FP8x23Sub::sub(lhs, rhs) } + + fn bitwise_not(self: FP8x23) -> FP8x23 { + core_fp8x23::bitwise_not(self) + } } use orion::numbers::fixed_point::implementations::fp8x23wide::core::{ @@ -518,6 +523,10 @@ impl FP8x23WNumber of NumberTrait { fn sub(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { FP8x23WSub::sub(lhs, rhs) } + + fn bitwise_not(self: FP8x23W) -> FP8x23W { + core_fp8x23wide::bitwise_not(self) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{ @@ -745,6 +754,10 @@ impl FP16x16Number of NumberTrait { fn sub(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { FP16x16Sub::sub(lhs, rhs) } + + fn bitwise_not(self: FP16x16) -> FP16x16 { + core_fp16x16::bitwise_not(self) + } } use orion::numbers::fixed_point::implementations::fp16x16wide::core::{ @@ -972,6 +985,10 @@ impl FP16x16WNumber of NumberTrait { fn sub(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { FP16x16WSub::sub(lhs, rhs) } + + fn bitwise_not(self: FP16x16W) -> FP16x16W { + core_fp16x16wide::bitwise_not(self) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{ @@ -1200,6 +1217,10 @@ impl FP64x64Number of NumberTrait { fn sub(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { FP64x64Sub::sub(lhs, rhs) } + + fn bitwise_not(self: FP64x64) -> FP64x64 { + FP64x64Impl::bitwise_not(self) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{ @@ -1428,6 +1449,10 @@ impl FP32x32Number of NumberTrait { fn sub(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { FP32x32Sub::sub(lhs, rhs) } + + fn bitwise_not(self: FP32x32) -> FP32x32 { + FP32x32Impl::bitwise_not(self) + } } impl I8Number of NumberTrait { @@ -1687,6 +1712,10 @@ impl I8Number of NumberTrait { fn sub(lhs: i8, rhs: i8) -> i8 { lhs - rhs } + + fn bitwise_not(self: i8) -> i8 { + panic(array!['not supported!']) + } } impl I8Div of Div { @@ -2049,6 +2078,10 @@ impl I16Number of NumberTrait { fn sub(lhs: i16, rhs: i16) -> i16 { lhs - rhs } + + fn bitwise_not(self: i16) -> i16 { + panic(array!['not supported!']) + } } impl I16Div of Div { @@ -2347,6 +2380,10 @@ impl I32Number of NumberTrait { fn sub(lhs: i32, rhs: i32) -> i32 { lhs - rhs } + + fn bitwise_not(self: i32) -> i32 { + panic(array!['not supported!']) + } } impl I32Div of Div { @@ -2661,6 +2698,10 @@ impl I64Number of NumberTrait { fn sub(lhs: i64, rhs: i64) -> i64 { lhs - rhs } + + fn bitwise_not(self: i64) -> i64 { + panic(array!['not supported!']) + } } impl I64Div of Div { @@ -2960,6 +3001,10 @@ impl I128Number of NumberTrait { fn sub(lhs: i128, rhs: i128) -> i128 { lhs - rhs } + + fn bitwise_not(self: i128) -> i128 { + panic(array!['not supported!']) + } } impl I128Div of Div { @@ -3246,6 +3291,10 @@ impl u32Number of NumberTrait { fn sub(lhs: u32, rhs: u32) -> u32 { lhs - rhs } + + fn bitwise_not(self: u32) -> u32 { + ~self + } } @@ -3483,6 +3532,10 @@ impl Complex64Number of NumberTrait { fn sub(lhs: complex64, rhs: complex64) -> complex64 { Complex64Sub::sub(lhs, rhs) } + + fn bitwise_not(self: complex64) -> complex64 { + panic(array!['not supported!']) + } } impl U32IntoI32 of Into { diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index e35d8abdb..f874ff304 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1144,4 +1144,5 @@ trait FixedTrait { fn is_inf(self: T) -> bool; fn is_pos_inf(self: T) -> bool; fn is_neg_inf(self: T) -> bool; + fn bitwise_not(self: T) -> T; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index 8f77324aa..94010842b 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -218,6 +218,10 @@ impl FP16x16Impl of FixedTrait { fn erf(self: FP16x16) -> FP16x16 { erf::erf(self) } + + fn bitwise_not(self: FP16x16) -> FP16x16 { + FP16x16 { mag: ~self.mag, sign: !self.sign } + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/core.cairo index 0085d2639..bdf1bbd11 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/core.cairo @@ -283,6 +283,10 @@ fn sign(a: FP16x16) -> FP16x16 { } } +fn bitwise_not(a: FP16x16) -> FP16x16 { + FixedTrait::new(~a.mag, !a.sign) +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index 0a6c4795e..bb29b4c6a 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -218,6 +218,10 @@ impl FP16x16WImpl of FixedTrait { fn erf(self: FP16x16W) -> FP16x16W { erf::erf(self) } + + fn bitwise_not(self: FP16x16W) -> FP16x16W { + FP16x16W { mag: ~self.mag, sign: !self.sign } + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/core.cairo index cafc20e4d..77b638afd 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/core.cairo @@ -283,6 +283,10 @@ fn sign(a: FP16x16W) -> FP16x16W { } } +fn bitwise_not(a: FP16x16W) -> FP16x16W { + FixedTrait::new(~a.mag, !a.sign) +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index ee38799da..e806cf5c9 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -210,6 +210,10 @@ impl FP32x32Impl of FixedTrait { fn erf(self: FP32x32) -> FP32x32 { erf::erf(self) } + + fn bitwise_not(self: FP32x32) -> FP32x32 { + FP32x32 { mag: ~self.mag, sign: !self.sign } + } } impl FP32x32Print of PrintTrait { diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index e11fcd9a4..2eb92de3e 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -210,6 +210,10 @@ impl FP64x64Impl of FixedTrait { fn erf(self: FP64x64) -> FP64x64 { erf::erf(self) } + + fn bitwise_not(self: FP64x64) -> FP64x64 { + FP64x64 { mag: ~self.mag, sign: !self.sign } + } } impl FP64x64Print of PrintTrait { diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 7e44554dd..ea97b3250 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -217,6 +217,10 @@ impl FP8x23Impl of FixedTrait { fn erf(self: FP8x23) -> FP8x23 { erf::erf(self) } + + fn bitwise_not(self: FP8x23) -> FP8x23 { + FP8x23 { mag: ~self.mag, sign: !self.sign } + } } impl FP8x23Print of PrintTrait { diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/core.cairo index c347d9817..de05f975d 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/core.cairo @@ -284,6 +284,10 @@ fn sign(a: FP8x23) -> FP8x23 { } } +fn bitwise_not(a: FP8x23) -> FP8x23 { + FixedTrait::new(~a.mag, !a.sign) +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 4804e6fda..e826bdcb3 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -217,6 +217,10 @@ impl FP8x23WImpl of FixedTrait { fn erf(self: FP8x23W) -> FP8x23W { erf::erf(self) } + + fn bitwise_not(self: FP8x23W) -> FP8x23W { + FP8x23W { mag: ~self.mag, sign: !self.sign } + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/core.cairo index 54d23b9e2..1475c1f9c 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/core.cairo @@ -284,6 +284,10 @@ fn sign(a: FP8x23W) -> FP8x23W { } } +fn bitwise_not(a: FP8x23W) -> FP8x23W { + FixedTrait::new(~a.mag, !a.sign) +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 0d21a4de3..3f18c1837 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -96,6 +96,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ``` /// fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor; + /// #tensor.bitwise_not + /// + /// ```rust + /// fn bitwise_not(self: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the bitwise NOT of the tensor element-wise. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The the tensor to be bitwise NOTed + /// + /// + /// ## Returns + /// + /// A new `Tensor` with the same shape as the broadcasted input. + /// + /// ## Example + /// + /// ```rust + /// use core::array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn bitwise_not_example() -> Tensor { + /// let tensor_1 = TensorTrait::::new( + /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), + /// ); + /// + /// return tensor_1.bitwise_not(); + /// } + /// >>> [4294967295,4294967294,4294967293,4294967292,4294967291,4294967290,4294967289,4294967288,4294967287] + /// ``` + /// + fn bitwise_not(self: @Tensor) -> Tensor; /// ## tensor.reduce_l1 /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 612a397cc..719578e5f 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -352,6 +352,10 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn bitwise_not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_complex64.cairo b/src/operators/tensor/implementations/tensor_complex64.cairo index c9c31ae23..e2449477d 100644 --- a/src/operators/tensor/implementations/tensor_complex64.cairo +++ b/src/operators/tensor/implementations/tensor_complex64.cairo @@ -360,6 +360,10 @@ impl Complex64Tensor of TensorTrait { panic(array!['not supported!']) } + fn bitwise_not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } + fn round(self: @Tensor) -> Tensor { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index a37ed0442..67d208849 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -398,6 +398,10 @@ impl FP16x16Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 2003b28ff..76e29cc9e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -366,6 +366,10 @@ impl FP16x16WTensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 4870226a1..43c2eeedc 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -395,6 +395,10 @@ impl FP32x32Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 3a7214d18..d41bdeb5f 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -395,6 +395,10 @@ impl FP64x64Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index b4a26d749..5bfc93617 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -395,6 +395,10 @@ impl FP8x23Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 06a297b69..0e9271416 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -349,6 +349,10 @@ impl FP8x23WTensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 296876516..5f5f3660f 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -388,6 +388,10 @@ impl I32Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 42d807c68..46948ff56 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -391,6 +391,10 @@ impl I8Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index efb681a86..b7c79d3bb 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -335,6 +335,10 @@ impl U32Tensor of TensorTrait { math::bitwise_or::bitwise_or(self, other) } + fn bitwise_not(self: @Tensor) -> Tensor { + math::bitwise_not::bitwise_not(self) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index b73f6d102..f3c349f24 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -68,3 +68,4 @@ mod hann_window; mod hamming_window; mod blackman_window; mod scatter_nd; +mod bitwise_not; diff --git a/src/operators/tensor/math/bitwise_not.cairo b/src/operators/tensor/math/bitwise_not.cairo new file mode 100644 index 000000000..907a888c3 --- /dev/null +++ b/src/operators/tensor/math/bitwise_not.cairo @@ -0,0 +1,29 @@ +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 +}; + +/// Cf: TensorTrait::and docstring +fn bitwise_not< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor +) -> Tensor { + let mut result: Array = array![]; + let num_elements = len_from_shape(*self.shape); + let mut n: usize = 0; + while n != num_elements { + result.append(NumberTrait::bitwise_not(*(*self.data)[n])); + n += 1; + }; + + TensorTrait::::new(*self.shape, result.span()) + + +}