From 062a5757f7bad6e8b6f9688b053f94a1c9fd1c90 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 09:09:51 +0200 Subject: [PATCH 001/160] set TreeEnsemble --- src/numbers/fixed_point/core.cairo | 1 + src/operators/ml.cairo | 1 + src/operators/ml/tree_ensemble.cairo | 1 + src/operators/ml/tree_ensemble/core.cairo | 57 ++ tests/nodes.cairo | 1036 ++++++++++----------- 5 files changed, 578 insertions(+), 518 deletions(-) create mode 100644 src/operators/ml/tree_ensemble.cairo create mode 100644 src/operators/ml/tree_ensemble/core.cairo diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 6581b018f..5490fc0de 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1102,4 +1102,5 @@ trait FixedTrait { fn ZERO() -> T; fn ONE() -> T; fn MAX() -> T; + // fn NaN() -> T; } diff --git a/src/operators/ml.cairo b/src/operators/ml.cairo index 96c1859dd..721751fdd 100644 --- a/src/operators/ml.cairo +++ b/src/operators/ml.cairo @@ -1,6 +1,7 @@ mod tree_regressor; mod tree_classifier; mod xgboost_regressor; +mod tree_ensemble; use orion::operators::ml::tree_regressor::core::{TreeRegressorTrait, TreeRegressor}; use orion::operators::ml::tree_regressor::implementations::tree_regressor_fp16x16::FP16x16TreeRegressor; diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo new file mode 100644 index 000000000..ef33ab296 --- /dev/null +++ b/src/operators/ml/tree_ensemble.cairo @@ -0,0 +1 @@ +mod core; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo new file mode 100644 index 000000000..63f0306e5 --- /dev/null +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -0,0 +1,57 @@ +use core::array::SpanTrait; +use core::dict::Felt252DictTrait; +use core::Felt252Dict; + +impl UsizeDictCopy of Copy>; +impl UsizeDictDrop of Drop>; + +#[derive(Copy, Drop)] +struct TreeEnsembleAttributes { + nodes_modes: Span, // Change to modes + nodes_featureids: Span, + nodes_missing_value_tracks_true: Span, + nodes_values: Span, + nodes_truenodeids: Span, + nodes_falsenodeids: Span, +} + +#[derive(Copy, Drop)] +struct TreeEnsemble { + atts: TreeEnsembleAttributes, + tree_ids: Span, + root_index: Felt252Dict, + node_index: Felt252Dict, // index is pedersen hash of tree_id and nid. +} + +#[derive(Copy, Drop)] +enum NODE_MODES { + BRANCH_LEQ, + BRANCH_LT, + BRANCH_GTE, + BRANCH_GT, + BRANCH_EQ, + BRANCH_NEQ, + LEAF +} + + +fn leaf_index_tree, +Copy>( + ref ensemble: TreeEnsemble, x: Span, tree_id: usize +) -> usize { + let mut index = ensemble.root_index.get(tree_id.into()); + + loop { + match *ensemble.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => { continue; }, + NODE_MODES::BRANCH_LT => { continue; }, + NODE_MODES::BRANCH_GTE => { continue; }, + NODE_MODES::BRANCH_GT => { continue; }, + NODE_MODES::BRANCH_EQ => { continue; }, + NODE_MODES::BRANCH_NEQ => { continue; }, + NODE_MODES::LEAF => { break; }, + }; + }; + + 1 +} + diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 4a6d7c8cb..4e34baff1 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,518 +1,518 @@ -mod abs_fp16x16; -mod abs_fp8x23; -mod abs_i32; -mod abs_i8; -mod acos_fp16x16; -mod acos_fp8x23; -mod acosh_fp16x16; -mod acosh_fp8x23; -mod add_fp16x16; -mod add_fp16x16_broadcast; -mod add_fp8x23; -mod add_fp8x23_broadcast; -mod add_i32; -mod add_i32_broadcast; -mod add_i8; -mod add_i8_broadcast; -mod add_u32; -mod add_u32_broadcast; -mod argmax_fp16x16_1D_default; -mod argmax_fp16x16_1D_keepdims_false; -mod argmax_fp16x16_1D_last_index; -mod argmax_fp16x16_2D_default; -mod argmax_fp16x16_2D_keepdims_false; -mod argmax_fp16x16_2D_last_index; -mod argmax_fp16x16_3D_default; -mod argmax_fp16x16_3D_keepdims_false; -mod argmax_fp16x16_3D_last_index; -mod argmax_fp8x23_1D_default; -mod argmax_fp8x23_1D_keepdims_false; -mod argmax_fp8x23_1D_last_index; -mod argmax_fp8x23_2D_default; -mod argmax_fp8x23_2D_keepdims_false; -mod argmax_fp8x23_2D_last_index; -mod argmax_fp8x23_3D_default; -mod argmax_fp8x23_3D_keepdims_false; -mod argmax_fp8x23_3D_last_index; -mod argmax_i32_1D_default; -mod argmax_i32_1D_keepdims_false; -mod argmax_i32_1D_last_index; -mod argmax_i32_2D_default; -mod argmax_i32_2D_keepdims_false; -mod argmax_i32_2D_last_index; -mod argmax_i32_3D_default; -mod argmax_i32_3D_keepdims_false; -mod argmax_i32_3D_last_index; -mod argmax_i8_1D_default; -mod argmax_i8_1D_keepdims_false; -mod argmax_i8_1D_last_index; -mod argmax_i8_2D_default; -mod argmax_i8_2D_keepdims_false; -mod argmax_i8_2D_last_index; -mod argmax_i8_3D_default; -mod argmax_i8_3D_keepdims_false; -mod argmax_i8_3D_last_index; -mod argmax_u32_1D_default; -mod argmax_u32_1D_keepdims_false; -mod argmax_u32_1D_last_index; -mod argmax_u32_2D_default; -mod argmax_u32_2D_keepdims_false; -mod argmax_u32_2D_last_index; -mod argmax_u32_3D_default; -mod argmax_u32_3D_keepdims_false; -mod argmax_u32_3D_last_index; -mod argmin_fp16x16_1D_default; -mod argmin_fp16x16_1D_keepdims_false; -mod argmin_fp16x16_1D_last_index; -mod argmin_fp16x16_2D_default; -mod argmin_fp16x16_2D_keepdims_false; -mod argmin_fp16x16_2D_last_index; -mod argmin_fp16x16_3D_default; -mod argmin_fp16x16_3D_keepdims_false; -mod argmin_fp16x16_3D_last_index; -mod argmin_fp8x23_1D_default; -mod argmin_fp8x23_1D_keepdims_false; -mod argmin_fp8x23_1D_last_index; -mod argmin_fp8x23_2D_default; -mod argmin_fp8x23_2D_keepdims_false; -mod argmin_fp8x23_2D_last_index; -mod argmin_fp8x23_3D_default; -mod argmin_fp8x23_3D_keepdims_false; -mod argmin_fp8x23_3D_last_index; -mod argmin_i32_1D_default; -mod argmin_i32_1D_keepdims_false; -mod argmin_i32_1D_last_index; -mod argmin_i32_2D_default; -mod argmin_i32_2D_keepdims_false; -mod argmin_i32_2D_last_index; -mod argmin_i32_3D_default; -mod argmin_i32_3D_keepdims_false; -mod argmin_i32_3D_last_index; -mod argmin_i8_1D_default; -mod argmin_i8_1D_keepdims_false; -mod argmin_i8_1D_last_index; -mod argmin_i8_2D_default; -mod argmin_i8_2D_keepdims_false; -mod argmin_i8_2D_last_index; -mod argmin_i8_3D_default; -mod argmin_i8_3D_keepdims_false; -mod argmin_i8_3D_last_index; -mod argmin_u32_1D_default; -mod argmin_u32_1D_keepdims_false; -mod argmin_u32_1D_last_index; -mod argmin_u32_2D_default; -mod argmin_u32_2D_keepdims_false; -mod argmin_u32_2D_last_index; -mod argmin_u32_3D_default; -mod argmin_u32_3D_keepdims_false; -mod argmin_u32_3D_last_index; -mod asin_fp16x16; -mod asin_fp8x23; -mod asinh_fp16x16; -mod asinh_fp8x23; -mod atan_fp16x16; -mod atan_fp8x23; -mod ceil_fp16x16; -mod ceil_fp8x23; -mod concat_fp16x16_1d; -mod concat_fp16x16_2d; -mod concat_fp16x16_3d_default; -mod concat_fp16x16_3d_axis_1; -mod concat_fp16x16_3d_axis_2; -mod concat_fp16x16_3d_three_tensors_axis_1; -mod concat_fp16x16_3d_three_tensors_axis_2; -mod concat_fp8x23_1d; -mod concat_fp8x23_2d; -mod concat_fp8x23_3d_default; -mod concat_fp8x23_3d_axis_1; -mod concat_fp8x23_3d_axis_2; -mod concat_fp8x23_3d_three_tensors_axis_1; -mod concat_fp8x23_3d_three_tensors_axis_2; -mod concat_i32_1d; -mod concat_i32_2d; -mod concat_i32_3d_default; -mod concat_i32_3d_axis_1; -mod concat_i32_3d_axis_2; -mod concat_i32_3d_three_tensors_axis_1; -mod concat_i32_3d_three_tensors_axis_2; -mod concat_i8_1d; -mod concat_i8_2d; -mod concat_i8_3d_default; -mod concat_i8_3d_axis_1; -mod concat_i8_3d_axis_2; -mod concat_i8_3d_three_tensors_axis_1; -mod concat_i8_3d_three_tensors_axis_2; -mod concat_u32_1d; -mod concat_u32_2d; -mod concat_u32_3d_default; -mod concat_u32_3d_axis_1; -mod concat_u32_3d_axis_2; -mod concat_u32_3d_three_tensors_axis_1; -mod concat_u32_3d_three_tensors_axis_2; -mod cos_fp16x16; -mod cos_fp8x23; -mod cosh_fp16x16; -mod cosh_fp8x23; -mod cumsum_fp16x16_1d_default; -mod cumsum_fp16x16_1d_exclusive; -mod cumsum_fp16x16_1d_reverse; -mod cumsum_fp16x16_1d_reverse_exclusive; -mod cumsum_fp16x16_2d_axis_0; -mod cumsum_fp16x16_2d_axis_1; -mod cumsum_fp8x23_1d_default; -mod cumsum_fp8x23_1d_exclusive; -mod cumsum_fp8x23_1d_reverse; -mod cumsum_fp8x23_1d_reverse_exclusive; -mod cumsum_fp8x23_2d_axis_0; -mod cumsum_fp8x23_2d_axis_1; -mod cumsum_i32_1d_default; -mod cumsum_i32_1d_exclusive; -mod cumsum_i32_1d_reverse; -mod cumsum_i32_1d_reverse_exclusive; -mod cumsum_i32_2d_axis_0; -mod cumsum_i32_2d_axis_1; -mod cumsum_i8_1d_default; -mod cumsum_i8_1d_exclusive; -mod cumsum_i8_1d_reverse; -mod cumsum_i8_1d_reverse_exclusive; -mod cumsum_i8_2d_axis_0; -mod cumsum_i8_2d_axis_1; -mod cumsum_u32_1d_default; -mod cumsum_u32_1d_exclusive; -mod cumsum_u32_1d_reverse; -mod cumsum_u32_1d_reverse_exclusive; -mod cumsum_u32_2d_axis_0; -mod cumsum_u32_2d_axis_1; -mod div_fp16x16; -mod div_fp16x16_broadcast; -mod div_fp8x23; -mod div_fp8x23_broadcast; -mod div_i32; -mod div_i32_broadcast; -mod div_i8; -mod div_i8_broadcast; -mod div_u32; -mod div_u32_broadcast; -mod equal_fp16x16; -mod equal_fp16x16_broadcast; -mod equal_fp8x23; -mod equal_fp8x23_broadcast; -mod equal_i32; -mod equal_i32_broadcast; -mod equal_i8; -mod equal_i8_broadcast; -mod equal_u32; -mod equal_u32_broadcast; -mod exp_fp16x16; -mod exp_fp8x23; -mod less_equal_fp16x16; -mod less_equal_fp16x16_broadcast; -mod less_equal_fp8x23; -mod less_equal_fp8x23_broadcast; -mod less_equal_i32; -mod less_equal_i32_broadcast; -mod less_equal_i8; -mod less_equal_i8_broadcast; -mod less_equal_u32; -mod less_equal_u32_broadcast; -mod greater_fp16x16; -mod greater_fp16x16_broadcast; -mod greater_fp8x23; -mod greater_fp8x23_broadcast; -mod greater_i32; -mod greater_i32_broadcast; -mod greater_i8; -mod greater_i8_broadcast; -mod greater_u32; -mod greater_u32_broadcast; -mod leaky_relu_fp16x16; -mod leaky_relu_fp8x23; -mod linear_fp16x16; -mod linear_fp8x23; -mod linear_i32; -mod linear_i8; -mod linear_u32; -mod log_fp16x16; -mod log_fp8x23; -mod logsoftmax_fp16x16_axis_0; -mod logsoftmax_fp16x16_axis_1; -mod logsoftmax_fp8x23_axis_0; -mod logsoftmax_fp8x23_axis_1; -mod matmul_fp16x16_1d; -mod matmul_fp16x16_2x2; -mod matmul_fp16x16_2x1; -mod matmul_fp16x16_1x2; -mod matmul_fp8x23_1d; -mod matmul_fp8x23_2x2; -mod matmul_fp8x23_2x1; -mod matmul_fp8x23_1x2; -mod matmul_i32_1d; -mod matmul_i32_2x2; -mod matmul_i32_2x1; -mod matmul_i32_1x2; -mod matmul_i8_1d; -mod matmul_i8_2x2; -mod matmul_i8_2x1; -mod matmul_i8_1x2; -mod matmul_u32_1d; -mod matmul_u32_2x2; -mod matmul_u32_2x1; -mod matmul_u32_1x2; -mod mul_fp16x16; -mod mul_fp16x16_broadcast; -mod mul_fp8x23; -mod mul_fp8x23_broadcast; -mod mul_i32; -mod mul_i32_broadcast; -mod mul_i8; -mod mul_i8_broadcast; -mod mul_u32; -mod mul_u32_broadcast; -mod or_fp16x16; -mod or_fp16x16_broadcast; -mod or_fp8x23; -mod or_fp8x23_broadcast; -mod or_i32; -mod or_i32_broadcast; -mod or_i8; -mod or_i8_broadcast; -mod or_u32; -mod or_u32_broadcast; -mod reduce_sum_fp16x16_1D; -mod reduce_sum_fp16x16_2D_default; -mod reduce_sum_fp16x16_2D_keepdims; -mod reduce_sum_fp16x16_2D_axis_1; -mod reduce_sum_fp8x23_1D; -mod reduce_sum_fp8x23_2D_default; -mod reduce_sum_fp8x23_2D_keepdims; -mod reduce_sum_fp8x23_2D_axis_1; -mod reduce_sum_i32_1D; -mod reduce_sum_i32_2D_default; -mod reduce_sum_i32_2D_keepdims; -mod reduce_sum_i32_2D_axis_1; -mod reduce_sum_i8_1D; -mod reduce_sum_i8_2D_default; -mod reduce_sum_i8_2D_keepdims; -mod reduce_sum_i8_2D_axis_1; -mod reduce_sum_u32_1D; -mod reduce_sum_u32_2D_default; -mod reduce_sum_u32_2D_keepdims; -mod reduce_sum_u32_2D_axis_1; -mod relu_fp16x16; -mod relu_fp8x23; -mod relu_i32; -mod relu_i8; -mod sigmoid_fp16x16; -mod sigmoid_fp8x23; -mod sin_fp16x16; -mod sin_fp8x23; -mod sinh_fp16x16; -mod sinh_fp8x23; -mod softmax_fp16x16; -mod softmax_fp8x23; -mod softplus_fp8x23; -mod softplus_fp16x16; -mod softsign_fp8x23; -mod softsign_fp16x16; -mod sqrt_fp16x16; -mod sqrt_fp8x23; -mod sub_fp16x16; -mod sub_fp16x16_broadcast; -mod sub_fp8x23; -mod sub_fp8x23_broadcast; -mod sub_i32; -mod sub_i32_broadcast; -mod sub_i8; -mod sub_i8_broadcast; -mod sub_u32; -mod sub_u32_broadcast; -mod tanh_fp16x16; -mod tanh_fp8x23; -mod transpose_fp16x16_2d; -mod transpose_fp16x16_3d; -mod transpose_fp8x23_2d; -mod transpose_fp8x23_3d; -mod transpose_i32_2d; -mod transpose_i32_3d; -mod transpose_i8_2d; -mod transpose_i8_3d; -mod transpose_u32_2d; -mod transpose_u32_3d; -mod xor_fp16x16; -mod xor_fp16x16_broadcast; -mod xor_fp8x23; -mod xor_fp8x23_broadcast; -mod xor_i32; -mod xor_i32_broadcast; -mod xor_i8; -mod xor_i8_broadcast; -mod xor_u32; -mod xor_u32_broadcast; -mod less_fp16x16; -mod less_fp16x16_broadcast; -mod less_fp8x23; -mod less_fp8x23_broadcast; -mod less_i32; -mod less_i32_broadcast; -mod less_i8; -mod less_i8_broadcast; -mod less_u32; -mod less_u32_broadcast; -mod greater_equal_fp16x16; -mod greater_equal_fp16x16_broadcast; -mod greater_equal_fp8x23; -mod greater_equal_fp8x23_broadcast; -mod greater_equal_i32; -mod greater_equal_i32_broadcast; -mod greater_equal_i8; -mod greater_equal_i8_broadcast; -mod greater_equal_u32; -mod greater_equal_u32_broadcast; -mod slice_fp16x16_2d; -mod slice_fp16x16_3d; -mod slice_fp8x23_2d; -mod slice_fp8x23_3d; -mod slice_i32_2d; -mod slice_i32_3d; -mod slice_i8_2d; -mod slice_i8_3d; -mod slice_u32_2d; -mod slice_u32_3d; -mod gather_fp8x23_3d_default; -mod gather_fp8x23_3d_axis1; -mod gather_fp8x23_3d_axis2; -mod gather_fp16x16_3d_default; -mod gather_fp16x16_3d_axis1; -mod gather_fp16x16_3d_axis2; -mod gather_i8_3d_default; -mod gather_i8_3d_axis1; -mod gather_i8_3d_axis2; -mod gather_i32_3d_default; -mod gather_i32_3d_axis1; -mod gather_i32_3d_axis2; -mod gather_u32_3d_default; -mod gather_u32_3d_axis1; -mod gather_u32_3d_axis2; -mod nonzero_fp16x16_2d; -mod nonzero_fp16x16_3d; -mod nonzero_fp8x23_2d; -mod nonzero_fp8x23_3d; -mod nonzero_i32_2d; -mod nonzero_i32_3d; -mod nonzero_i8_2d; -mod nonzero_i8_3d; -mod nonzero_u32_2d; -mod nonzero_u32_3d; -mod squeeze_fP16x16; -mod squeeze_fP8x23; -mod squeeze_i32; -mod squeeze_i8; -mod squeeze_u32; -mod unsqueeze_fp16x16_2d; -mod unsqueeze_fp16x16_3d; -mod unsqueeze_fp8x23_2d; -mod unsqueeze_fp8x23_3d; -mod unsqueeze_i32_2d; -mod unsqueeze_i32_3d; -mod unsqueeze_i8_2d; -mod unsqueeze_i8_3d; -mod unsqueeze_u32_2d; -mod unsqueeze_u32_3d; -mod sign_fP16x16; -mod sign_fP8x23; -mod sign_fail; -mod sign_i32; -mod sign_i8; -mod clip_fp16x16_2d; -mod clip_fp16x16_3d; -mod clip_fp8x23_2d; -mod clip_fp8x23_3d; -mod clip_i32_2d; -mod clip_i32_3d; -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; -mod identity_fP16x16; -mod identity_fP8x23; -mod identity_i32; -mod identity_i8; -mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; -mod where_fp16x16; -mod where_fp16x16_broadcast; -mod where_fp8x23; -mod where_fp8x23_broadcast; -mod where_i32; -mod where_i32_broadcast; -mod where_i8; -mod where_i8_broadcast; -mod where_u32; -mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; +// mod abs_fp16x16; +// mod abs_fp8x23; +// mod abs_i32; +// mod abs_i8; +// mod acos_fp16x16; +// mod acos_fp8x23; +// mod acosh_fp16x16; +// mod acosh_fp8x23; +// mod add_fp16x16; +// mod add_fp16x16_broadcast; +// mod add_fp8x23; +// mod add_fp8x23_broadcast; +// mod add_i32; +// mod add_i32_broadcast; +// mod add_i8; +// mod add_i8_broadcast; +// mod add_u32; +// mod add_u32_broadcast; +// mod argmax_fp16x16_1D_default; +// mod argmax_fp16x16_1D_keepdims_false; +// mod argmax_fp16x16_1D_last_index; +// mod argmax_fp16x16_2D_default; +// mod argmax_fp16x16_2D_keepdims_false; +// mod argmax_fp16x16_2D_last_index; +// mod argmax_fp16x16_3D_default; +// mod argmax_fp16x16_3D_keepdims_false; +// mod argmax_fp16x16_3D_last_index; +// mod argmax_fp8x23_1D_default; +// mod argmax_fp8x23_1D_keepdims_false; +// mod argmax_fp8x23_1D_last_index; +// mod argmax_fp8x23_2D_default; +// mod argmax_fp8x23_2D_keepdims_false; +// mod argmax_fp8x23_2D_last_index; +// mod argmax_fp8x23_3D_default; +// mod argmax_fp8x23_3D_keepdims_false; +// mod argmax_fp8x23_3D_last_index; +// mod argmax_i32_1D_default; +// mod argmax_i32_1D_keepdims_false; +// mod argmax_i32_1D_last_index; +// mod argmax_i32_2D_default; +// mod argmax_i32_2D_keepdims_false; +// mod argmax_i32_2D_last_index; +// mod argmax_i32_3D_default; +// mod argmax_i32_3D_keepdims_false; +// mod argmax_i32_3D_last_index; +// mod argmax_i8_1D_default; +// mod argmax_i8_1D_keepdims_false; +// mod argmax_i8_1D_last_index; +// mod argmax_i8_2D_default; +// mod argmax_i8_2D_keepdims_false; +// mod argmax_i8_2D_last_index; +// mod argmax_i8_3D_default; +// mod argmax_i8_3D_keepdims_false; +// mod argmax_i8_3D_last_index; +// mod argmax_u32_1D_default; +// mod argmax_u32_1D_keepdims_false; +// mod argmax_u32_1D_last_index; +// mod argmax_u32_2D_default; +// mod argmax_u32_2D_keepdims_false; +// mod argmax_u32_2D_last_index; +// mod argmax_u32_3D_default; +// mod argmax_u32_3D_keepdims_false; +// mod argmax_u32_3D_last_index; +// mod argmin_fp16x16_1D_default; +// mod argmin_fp16x16_1D_keepdims_false; +// mod argmin_fp16x16_1D_last_index; +// mod argmin_fp16x16_2D_default; +// mod argmin_fp16x16_2D_keepdims_false; +// mod argmin_fp16x16_2D_last_index; +// mod argmin_fp16x16_3D_default; +// mod argmin_fp16x16_3D_keepdims_false; +// mod argmin_fp16x16_3D_last_index; +// mod argmin_fp8x23_1D_default; +// mod argmin_fp8x23_1D_keepdims_false; +// mod argmin_fp8x23_1D_last_index; +// mod argmin_fp8x23_2D_default; +// mod argmin_fp8x23_2D_keepdims_false; +// mod argmin_fp8x23_2D_last_index; +// mod argmin_fp8x23_3D_default; +// mod argmin_fp8x23_3D_keepdims_false; +// mod argmin_fp8x23_3D_last_index; +// mod argmin_i32_1D_default; +// mod argmin_i32_1D_keepdims_false; +// mod argmin_i32_1D_last_index; +// mod argmin_i32_2D_default; +// mod argmin_i32_2D_keepdims_false; +// mod argmin_i32_2D_last_index; +// mod argmin_i32_3D_default; +// mod argmin_i32_3D_keepdims_false; +// mod argmin_i32_3D_last_index; +// mod argmin_i8_1D_default; +// mod argmin_i8_1D_keepdims_false; +// mod argmin_i8_1D_last_index; +// mod argmin_i8_2D_default; +// mod argmin_i8_2D_keepdims_false; +// mod argmin_i8_2D_last_index; +// mod argmin_i8_3D_default; +// mod argmin_i8_3D_keepdims_false; +// mod argmin_i8_3D_last_index; +// mod argmin_u32_1D_default; +// mod argmin_u32_1D_keepdims_false; +// mod argmin_u32_1D_last_index; +// mod argmin_u32_2D_default; +// mod argmin_u32_2D_keepdims_false; +// mod argmin_u32_2D_last_index; +// mod argmin_u32_3D_default; +// mod argmin_u32_3D_keepdims_false; +// mod argmin_u32_3D_last_index; +// mod asin_fp16x16; +// mod asin_fp8x23; +// mod asinh_fp16x16; +// mod asinh_fp8x23; +// mod atan_fp16x16; +// mod atan_fp8x23; +// mod ceil_fp16x16; +// mod ceil_fp8x23; +// mod concat_fp16x16_1d; +// mod concat_fp16x16_2d; +// mod concat_fp16x16_3d_default; +// mod concat_fp16x16_3d_axis_1; +// mod concat_fp16x16_3d_axis_2; +// mod concat_fp16x16_3d_three_tensors_axis_1; +// mod concat_fp16x16_3d_three_tensors_axis_2; +// mod concat_fp8x23_1d; +// mod concat_fp8x23_2d; +// mod concat_fp8x23_3d_default; +// mod concat_fp8x23_3d_axis_1; +// mod concat_fp8x23_3d_axis_2; +// mod concat_fp8x23_3d_three_tensors_axis_1; +// mod concat_fp8x23_3d_three_tensors_axis_2; +// mod concat_i32_1d; +// mod concat_i32_2d; +// mod concat_i32_3d_default; +// mod concat_i32_3d_axis_1; +// mod concat_i32_3d_axis_2; +// mod concat_i32_3d_three_tensors_axis_1; +// mod concat_i32_3d_three_tensors_axis_2; +// mod concat_i8_1d; +// mod concat_i8_2d; +// mod concat_i8_3d_default; +// mod concat_i8_3d_axis_1; +// mod concat_i8_3d_axis_2; +// mod concat_i8_3d_three_tensors_axis_1; +// mod concat_i8_3d_three_tensors_axis_2; +// mod concat_u32_1d; +// mod concat_u32_2d; +// mod concat_u32_3d_default; +// mod concat_u32_3d_axis_1; +// mod concat_u32_3d_axis_2; +// mod concat_u32_3d_three_tensors_axis_1; +// mod concat_u32_3d_three_tensors_axis_2; +// mod cos_fp16x16; +// mod cos_fp8x23; +// mod cosh_fp16x16; +// mod cosh_fp8x23; +// mod cumsum_fp16x16_1d_default; +// mod cumsum_fp16x16_1d_exclusive; +// mod cumsum_fp16x16_1d_reverse; +// mod cumsum_fp16x16_1d_reverse_exclusive; +// mod cumsum_fp16x16_2d_axis_0; +// mod cumsum_fp16x16_2d_axis_1; +// mod cumsum_fp8x23_1d_default; +// mod cumsum_fp8x23_1d_exclusive; +// mod cumsum_fp8x23_1d_reverse; +// mod cumsum_fp8x23_1d_reverse_exclusive; +// mod cumsum_fp8x23_2d_axis_0; +// mod cumsum_fp8x23_2d_axis_1; +// mod cumsum_i32_1d_default; +// mod cumsum_i32_1d_exclusive; +// mod cumsum_i32_1d_reverse; +// mod cumsum_i32_1d_reverse_exclusive; +// mod cumsum_i32_2d_axis_0; +// mod cumsum_i32_2d_axis_1; +// mod cumsum_i8_1d_default; +// mod cumsum_i8_1d_exclusive; +// mod cumsum_i8_1d_reverse; +// mod cumsum_i8_1d_reverse_exclusive; +// mod cumsum_i8_2d_axis_0; +// mod cumsum_i8_2d_axis_1; +// mod cumsum_u32_1d_default; +// mod cumsum_u32_1d_exclusive; +// mod cumsum_u32_1d_reverse; +// mod cumsum_u32_1d_reverse_exclusive; +// mod cumsum_u32_2d_axis_0; +// mod cumsum_u32_2d_axis_1; +// mod div_fp16x16; +// mod div_fp16x16_broadcast; +// mod div_fp8x23; +// mod div_fp8x23_broadcast; +// mod div_i32; +// mod div_i32_broadcast; +// mod div_i8; +// mod div_i8_broadcast; +// mod div_u32; +// mod div_u32_broadcast; +// mod equal_fp16x16; +// mod equal_fp16x16_broadcast; +// mod equal_fp8x23; +// mod equal_fp8x23_broadcast; +// mod equal_i32; +// mod equal_i32_broadcast; +// mod equal_i8; +// mod equal_i8_broadcast; +// mod equal_u32; +// mod equal_u32_broadcast; +// mod exp_fp16x16; +// mod exp_fp8x23; +// mod less_equal_fp16x16; +// mod less_equal_fp16x16_broadcast; +// mod less_equal_fp8x23; +// mod less_equal_fp8x23_broadcast; +// mod less_equal_i32; +// mod less_equal_i32_broadcast; +// mod less_equal_i8; +// mod less_equal_i8_broadcast; +// mod less_equal_u32; +// mod less_equal_u32_broadcast; +// mod greater_fp16x16; +// mod greater_fp16x16_broadcast; +// mod greater_fp8x23; +// mod greater_fp8x23_broadcast; +// mod greater_i32; +// mod greater_i32_broadcast; +// mod greater_i8; +// mod greater_i8_broadcast; +// mod greater_u32; +// mod greater_u32_broadcast; +// mod leaky_relu_fp16x16; +// mod leaky_relu_fp8x23; +// mod linear_fp16x16; +// mod linear_fp8x23; +// mod linear_i32; +// mod linear_i8; +// mod linear_u32; +// mod log_fp16x16; +// mod log_fp8x23; +// mod logsoftmax_fp16x16_axis_0; +// mod logsoftmax_fp16x16_axis_1; +// mod logsoftmax_fp8x23_axis_0; +// mod logsoftmax_fp8x23_axis_1; +// mod matmul_fp16x16_1d; +// mod matmul_fp16x16_2x2; +// mod matmul_fp16x16_2x1; +// mod matmul_fp16x16_1x2; +// mod matmul_fp8x23_1d; +// mod matmul_fp8x23_2x2; +// mod matmul_fp8x23_2x1; +// mod matmul_fp8x23_1x2; +// mod matmul_i32_1d; +// mod matmul_i32_2x2; +// mod matmul_i32_2x1; +// mod matmul_i32_1x2; +// mod matmul_i8_1d; +// mod matmul_i8_2x2; +// mod matmul_i8_2x1; +// mod matmul_i8_1x2; +// mod matmul_u32_1d; +// mod matmul_u32_2x2; +// mod matmul_u32_2x1; +// mod matmul_u32_1x2; +// mod mul_fp16x16; +// mod mul_fp16x16_broadcast; +// mod mul_fp8x23; +// mod mul_fp8x23_broadcast; +// mod mul_i32; +// mod mul_i32_broadcast; +// mod mul_i8; +// mod mul_i8_broadcast; +// mod mul_u32; +// mod mul_u32_broadcast; +// mod or_fp16x16; +// mod or_fp16x16_broadcast; +// mod or_fp8x23; +// mod or_fp8x23_broadcast; +// mod or_i32; +// mod or_i32_broadcast; +// mod or_i8; +// mod or_i8_broadcast; +// mod or_u32; +// mod or_u32_broadcast; +// mod reduce_sum_fp16x16_1D; +// mod reduce_sum_fp16x16_2D_default; +// mod reduce_sum_fp16x16_2D_keepdims; +// mod reduce_sum_fp16x16_2D_axis_1; +// mod reduce_sum_fp8x23_1D; +// mod reduce_sum_fp8x23_2D_default; +// mod reduce_sum_fp8x23_2D_keepdims; +// mod reduce_sum_fp8x23_2D_axis_1; +// mod reduce_sum_i32_1D; +// mod reduce_sum_i32_2D_default; +// mod reduce_sum_i32_2D_keepdims; +// mod reduce_sum_i32_2D_axis_1; +// mod reduce_sum_i8_1D; +// mod reduce_sum_i8_2D_default; +// mod reduce_sum_i8_2D_keepdims; +// mod reduce_sum_i8_2D_axis_1; +// mod reduce_sum_u32_1D; +// mod reduce_sum_u32_2D_default; +// mod reduce_sum_u32_2D_keepdims; +// mod reduce_sum_u32_2D_axis_1; +// mod relu_fp16x16; +// mod relu_fp8x23; +// mod relu_i32; +// mod relu_i8; +// mod sigmoid_fp16x16; +// mod sigmoid_fp8x23; +// mod sin_fp16x16; +// mod sin_fp8x23; +// mod sinh_fp16x16; +// mod sinh_fp8x23; +// mod softmax_fp16x16; +// mod softmax_fp8x23; +// mod softplus_fp8x23; +// mod softplus_fp16x16; +// mod softsign_fp8x23; +// mod softsign_fp16x16; +// mod sqrt_fp16x16; +// mod sqrt_fp8x23; +// mod sub_fp16x16; +// mod sub_fp16x16_broadcast; +// mod sub_fp8x23; +// mod sub_fp8x23_broadcast; +// mod sub_i32; +// mod sub_i32_broadcast; +// mod sub_i8; +// mod sub_i8_broadcast; +// mod sub_u32; +// mod sub_u32_broadcast; +// mod tanh_fp16x16; +// mod tanh_fp8x23; +// mod transpose_fp16x16_2d; +// mod transpose_fp16x16_3d; +// mod transpose_fp8x23_2d; +// mod transpose_fp8x23_3d; +// mod transpose_i32_2d; +// mod transpose_i32_3d; +// mod transpose_i8_2d; +// mod transpose_i8_3d; +// mod transpose_u32_2d; +// mod transpose_u32_3d; +// mod xor_fp16x16; +// mod xor_fp16x16_broadcast; +// mod xor_fp8x23; +// mod xor_fp8x23_broadcast; +// mod xor_i32; +// mod xor_i32_broadcast; +// mod xor_i8; +// mod xor_i8_broadcast; +// mod xor_u32; +// mod xor_u32_broadcast; +// mod less_fp16x16; +// mod less_fp16x16_broadcast; +// mod less_fp8x23; +// mod less_fp8x23_broadcast; +// mod less_i32; +// mod less_i32_broadcast; +// mod less_i8; +// mod less_i8_broadcast; +// mod less_u32; +// mod less_u32_broadcast; +// mod greater_equal_fp16x16; +// mod greater_equal_fp16x16_broadcast; +// mod greater_equal_fp8x23; +// mod greater_equal_fp8x23_broadcast; +// mod greater_equal_i32; +// mod greater_equal_i32_broadcast; +// mod greater_equal_i8; +// mod greater_equal_i8_broadcast; +// mod greater_equal_u32; +// mod greater_equal_u32_broadcast; +// mod slice_fp16x16_2d; +// mod slice_fp16x16_3d; +// mod slice_fp8x23_2d; +// mod slice_fp8x23_3d; +// mod slice_i32_2d; +// mod slice_i32_3d; +// mod slice_i8_2d; +// mod slice_i8_3d; +// mod slice_u32_2d; +// mod slice_u32_3d; +// mod gather_fp8x23_3d_default; +// mod gather_fp8x23_3d_axis1; +// mod gather_fp8x23_3d_axis2; +// mod gather_fp16x16_3d_default; +// mod gather_fp16x16_3d_axis1; +// mod gather_fp16x16_3d_axis2; +// mod gather_i8_3d_default; +// mod gather_i8_3d_axis1; +// mod gather_i8_3d_axis2; +// mod gather_i32_3d_default; +// mod gather_i32_3d_axis1; +// mod gather_i32_3d_axis2; +// mod gather_u32_3d_default; +// mod gather_u32_3d_axis1; +// mod gather_u32_3d_axis2; +// mod nonzero_fp16x16_2d; +// mod nonzero_fp16x16_3d; +// mod nonzero_fp8x23_2d; +// mod nonzero_fp8x23_3d; +// mod nonzero_i32_2d; +// mod nonzero_i32_3d; +// mod nonzero_i8_2d; +// mod nonzero_i8_3d; +// mod nonzero_u32_2d; +// mod nonzero_u32_3d; +// mod squeeze_fP16x16; +// mod squeeze_fP8x23; +// mod squeeze_i32; +// mod squeeze_i8; +// mod squeeze_u32; +// mod unsqueeze_fp16x16_2d; +// mod unsqueeze_fp16x16_3d; +// mod unsqueeze_fp8x23_2d; +// mod unsqueeze_fp8x23_3d; +// mod unsqueeze_i32_2d; +// mod unsqueeze_i32_3d; +// mod unsqueeze_i8_2d; +// mod unsqueeze_i8_3d; +// mod unsqueeze_u32_2d; +// mod unsqueeze_u32_3d; +// mod sign_fP16x16; +// mod sign_fP8x23; +// mod sign_fail; +// mod sign_i32; +// mod sign_i8; +// mod clip_fp16x16_2d; +// mod clip_fp16x16_3d; +// mod clip_fp8x23_2d; +// mod clip_fp8x23_3d; +// mod clip_i32_2d; +// mod clip_i32_3d; +// 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; +// mod identity_fP16x16; +// mod identity_fP8x23; +// mod identity_i32; +// mod identity_i8; +// mod identity_u32; +// mod thresholded_relu_fp16x16; +// mod thresholded_relu_fp8x23; +// mod hard_sigmoid_fp8x23; +// mod hard_sigmoid_fp16x16; +// mod neg_fp16x16; +// mod neg_fp8x23; +// mod neg_i32; +// mod neg_i8; +// mod gemm_all_attributes; +// mod gemm_alpha; +// mod gemm_beta; +// mod gemm_default_matrix_bias; +// mod gemm_default_vector_bias; +// mod gemm_default_no_bias; +// mod gemm_transposeA; +// mod gemm_transposeB; +// mod min_fp16x16_three_tensors; +// mod min_fp16x16_broadcast_three_tensors; +// mod min_fp16x16_two_tensors; +// mod min_fp16x16_broadcast_two_tensors; +// mod min_fp8x23_three_tensors; +// mod min_fp8x23_broadcast_three_tensors; +// mod min_fp8x23_two_tensors; +// mod min_fp8x23_broadcast_two_tensors; +// mod min_i32_three_tensors; +// mod min_i32_broadcast_three_tensors; +// mod min_i32_two_tensors; +// mod min_i32_broadcast_two_tensors; +// mod min_i8_three_tensors; +// mod min_i8_broadcast_three_tensors; +// mod min_i8_two_tensors; +// mod min_i8_broadcast_two_tensors; +// mod min_u32_three_tensors; +// mod min_u32_broadcast_three_tensors; +// mod min_u32_two_tensors; +// mod min_u32_broadcast_two_tensors; +// mod where_fp16x16; +// mod where_fp16x16_broadcast; +// mod where_fp8x23; +// mod where_fp8x23_broadcast; +// mod where_i32; +// mod where_i32_broadcast; +// mod where_i8; +// mod where_i8_broadcast; +// mod where_u32; +// mod where_u32_broadcast; +// mod round_fp16x16; +// mod round_fp8x23; +// mod max_fp16x16_three_tensors; +// mod max_fp16x16_broadcast_three_tensors; +// mod max_fp16x16_two_tensors; +// mod max_fp16x16_broadcast_two_tensors; +// mod max_fp8x23_three_tensors; +// mod max_fp8x23_broadcast_three_tensors; +// mod max_fp8x23_two_tensors; +// mod max_fp8x23_broadcast_two_tensors; +// mod max_i32_three_tensors; +// mod max_i32_broadcast_three_tensors; +// mod max_i32_two_tensors; +// mod max_i32_broadcast_two_tensors; +// mod max_i8_three_tensors; +// mod max_i8_broadcast_three_tensors; +// mod max_i8_two_tensors; +// mod max_i8_broadcast_two_tensors; +// mod max_u32_three_tensors; +// mod max_u32_broadcast_three_tensors; +// mod max_u32_two_tensors; +// mod max_u32_broadcast_two_tensors; From 05bc3deaed89b0a751bba57bbd2f61b98262144b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 09:30:58 +0200 Subject: [PATCH 002/160] implement NaN --- src/numbers.cairo | 99 +++++++++++++++++++ src/numbers/fixed_point/core.cairo | 3 +- .../implementations/fp16x16/core.cairo | 8 ++ .../implementations/fp16x16wide/core.cairo | 8 ++ .../implementations/fp32x32/core.cairo | 30 +++--- .../implementations/fp64x64/core.cairo | 30 +++--- .../implementations/fp8x23/core.cairo | 8 ++ .../implementations/fp8x23wide/core.cairo | 8 ++ src/numbers/signed_integer/i128.cairo | 8 ++ src/numbers/signed_integer/i16.cairo | 8 ++ src/numbers/signed_integer/i32.cairo | 8 ++ src/numbers/signed_integer/i64.cairo | 8 ++ src/numbers/signed_integer/i8.cairo | 8 ++ .../signed_integer/integer_trait.cairo | 3 + 14 files changed, 214 insertions(+), 23 deletions(-) diff --git a/src/numbers.cairo b/src/numbers.cairo index d81cefa33..5e27a4ed0 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -49,6 +49,8 @@ trait NumberTrait { fn sign(self: T) -> T; fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; + fn NaN() -> T; + fn is_nan(self: T) -> bool; } use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; @@ -226,6 +228,14 @@ impl FP8x23Number of NumberTrait { fn where(self: FP8x23, x: FP8x23, y: FP8x23) -> FP8x23 { comp_fp8x23::where(self, x, y) } + + fn NaN() -> FP8x23 { + FP8x23Impl::NaN() + } + + fn is_nan(self: FP8x23) -> bool { + FP8x23Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; @@ -403,6 +413,14 @@ impl FP8x23WNumber of NumberTrait { fn where(self: FP8x23W, x: FP8x23W, y: FP8x23W) -> FP8x23W { comp_fp8x23wide::where(self, x, y) } + + fn NaN() -> FP8x23W { + FP8x23WImpl::NaN() + } + + fn is_nan(self: FP8x23W) -> bool { + FP8x23WImpl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -580,6 +598,14 @@ impl FP16x16Number of NumberTrait { fn where(self: FP16x16, x: FP16x16, y: FP16x16) -> FP16x16 { comp_fp16x16::where(self, x, y) } + + fn NaN() -> FP16x16 { + FP16x16Impl::NaN() + } + + fn is_nan(self: FP16x16) -> bool { + FP16x16Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; @@ -757,6 +783,14 @@ impl FP16x16WNumber of NumberTrait { fn where(self: FP16x16W, x: FP16x16W, y: FP16x16W) -> FP16x16W { comp_fp16x16wide::where(self, x, y) } + + fn NaN() -> FP16x16W { + FP16x16WImpl::NaN() + } + + fn is_nan(self: FP16x16W) -> bool { + FP16x16WImpl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; @@ -935,6 +969,14 @@ impl FP64x64Number of NumberTrait { fn where(self: FP64x64, x: FP64x64, y: FP64x64) -> FP64x64 { comp_fp64x64::where(self, x, y) } + + fn NaN() -> FP64x64 { + FP64x64Impl::NaN() + } + + fn is_nan(self: FP64x64) -> bool { + FP64x64Impl::is_nan(self) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; @@ -1113,6 +1155,14 @@ impl FP32x32Number of NumberTrait { fn where(self: FP32x32, x: FP32x32, y: FP32x32) -> FP32x32 { comp_fp32x32::where(self, x, y) } + + fn NaN() -> FP32x32 { + FP32x32Impl::NaN() + } + + fn is_nan(self: FP32x32) -> bool { + FP32x32Impl::is_nan(self) + } } use orion::numbers::signed_integer::i8 as i8_core; @@ -1305,6 +1355,14 @@ impl I8Number of NumberTrait { return x; } } + + fn NaN() -> i8 { + IntegerTrait::NaN() + } + + fn is_nan(self: i8) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i16 as i16_core; @@ -1497,6 +1555,14 @@ impl i16Number of NumberTrait { return x; } } + + fn NaN() -> i16 { + IntegerTrait::NaN() + } + + fn is_nan(self: i16) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i32 as i32_core; @@ -1689,6 +1755,14 @@ impl i32Number of NumberTrait { return x; } } + + fn NaN() -> i32 { + IntegerTrait::NaN() + } + + fn is_nan(self: i32) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i64 as i64_core; @@ -1881,6 +1955,14 @@ impl i64Number of NumberTrait { return x; } } + + fn NaN() -> i64 { + IntegerTrait::NaN() + } + + fn is_nan(self: i64) -> bool { + IntegerTrait::is_nan(self) + } } use orion::numbers::signed_integer::i128 as i128_core; @@ -2074,6 +2156,15 @@ impl i128Number of NumberTrait { return x; } } + + + fn NaN() -> i128 { + IntegerTrait::NaN() + } + + fn is_nan(self: i128) -> bool { + IntegerTrait::is_nan(self) + } } impl u32Number of NumberTrait { @@ -2272,4 +2363,12 @@ impl u32Number of NumberTrait { return x; } } + + fn NaN() -> u32 { + 4242424242 + } + + fn is_nan(self: u32) -> bool { + self == 4242424242 + } } diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 5490fc0de..9daa862d2 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1102,5 +1102,6 @@ trait FixedTrait { fn ZERO() -> T; fn ONE() -> T; fn MAX() -> T; - // fn NaN() -> T; + fn NaN() -> T; + fn is_nan(self: T) -> bool; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index 10aed6e09..2ab47090f 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -182,6 +182,14 @@ impl FP16x16Impl of FixedTrait { fn sign(self: FP16x16) -> FP16x16 { return core::sign(self); } + + fn NaN() -> FP16x16 { + return FP16x16 { mag: 0, sign: true }; + } + + fn is_nan(self: FP16x16) -> bool { + self == FP16x16 { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index f04f4e690..98d45bda3 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -182,6 +182,14 @@ impl FP16x16WImpl of FixedTrait { fn sign(self: FP16x16W) -> FP16x16W { return core::sign(self); } + + fn NaN() -> FP16x16W { + return FP16x16W { mag: 0, sign: true }; + } + + fn is_nan(self: FP16x16W) -> bool { + self == FP16x16W { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index a84373883..f2ffe2012 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -173,6 +173,14 @@ impl FP32x32Impl of FixedTrait { fn sign(self: FP32x32) -> FP32x32 { panic(array!['not supported!']) } + + fn NaN() -> FP32x32 { + return FP32x32 { mag: 0, sign: true }; + } + + fn is_nan(self: FP32x32) -> bool { + self == FP32x32 { mag: 0, sign: true } + } } @@ -246,17 +254,17 @@ impl FP32x32TryIntoI8 of TryInto { } } -impl FP32x32PartialEq of PartialEq { - #[inline(always)] - fn eq(lhs: @FP32x32, rhs: @FP32x32) -> bool { - return fp32x32::core::eq(lhs, rhs); - } - - #[inline(always)] - fn ne(lhs: @FP32x32, rhs: @FP32x32) -> bool { - return fp32x32::core::ne(lhs, rhs); - } -} +// impl FP32x32PartialEq of PartialEq { +// #[inline(always)] +// fn eq(lhs: @FP32x32, rhs: @FP32x32) -> bool { +// return fp32x32::core::eq(lhs, rhs); +// } + +// #[inline(always)] +// fn ne(lhs: @FP32x32, rhs: @FP32x32) -> bool { +// return fp32x32::core::ne(lhs, rhs); +// } +// } impl FP32x32Add of Add { fn add(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index 706fe21a6..7d07211b8 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -171,6 +171,14 @@ impl FP64x64Impl of FixedTrait { fn sign(self: FP64x64) -> FP64x64 { panic(array!['not supported!']) } + + fn NaN() -> FP64x64 { + return FP64x64 { mag: 0, sign: true }; + } + + fn is_nan(self: FP64x64) -> bool { + self == FP64x64 { mag: 0, sign: true } + } } @@ -244,17 +252,17 @@ impl FP64x64TryIntoI8 of TryInto { } } -impl FP64x64PartialEq of PartialEq { - #[inline(always)] - fn eq(lhs: @FP64x64, rhs: @FP64x64) -> bool { - return fp64x64::core::eq(lhs, rhs); - } - - #[inline(always)] - fn ne(lhs: @FP64x64, rhs: @FP64x64) -> bool { - return fp64x64::core::ne(lhs, rhs); - } -} +// impl FP64x64PartialEq of PartialEq { +// #[inline(always)] +// fn eq(lhs: @FP64x64, rhs: @FP64x64) -> bool { +// return fp64x64::core::eq(lhs, rhs); +// } + +// #[inline(always)] +// fn ne(lhs: @FP64x64, rhs: @FP64x64) -> bool { +// return fp64x64::core::ne(lhs, rhs); +// } +// } impl FP64x64Add of Add { fn add(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 12ef49e24..b6cae31dd 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -182,6 +182,14 @@ impl FP8x23Impl of FixedTrait { fn sign(self: FP8x23) -> FP8x23 { return core::sign(self); } + + fn NaN() -> FP8x23 { + return FP8x23 { mag: 0, sign: true }; + } + + fn is_nan(self: FP8x23) -> bool { + self == FP8x23 { mag: 0, sign: true } + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 0243b56fc..76ebf6ed4 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -182,6 +182,14 @@ impl FP8x23WImpl of FixedTrait { fn sign(self: FP8x23W) -> FP8x23W { return core::sign(self); } + + fn NaN() -> FP8x23W { + return FP8x23W { mag: 0, sign: true }; + } + + fn is_nan(self: FP8x23W) -> bool { + self == FP8x23W { mag: 0, sign: true } + } } diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index 1c100ddc5..55d3a142d 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -37,6 +37,14 @@ impl i128Impl of IntegerTrait { fn sign(self: i128) -> i128 { i128_sign(self) } + + fn NaN() -> i128 { + return i128 { mag: 0, sign: true }; + } + + fn is_nan(self: i128) -> bool { + self == i128 { mag: 0, sign: true } + } } // Implements the Into trait for i128. diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index 5d6b04ffa..14f5269b9 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -37,6 +37,14 @@ impl i16Impl of IntegerTrait { fn sign(self: i16) -> i16 { i16_sign(self) } + + fn NaN() -> i16 { + return i16 { mag: 0, sign: true }; + } + + fn is_nan(self: i16) -> bool { + self == i16 { mag: 0, sign: true } + } } // Implements the Into trait for i16. diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index 0147ff0c3..b512d21a4 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -40,6 +40,14 @@ impl i32Impl of IntegerTrait { fn sign(self: i32) -> i32 { i32_sign(self) } + + fn NaN() -> i32 { + return i32 { mag: 0, sign: true }; + } + + fn is_nan(self: i32) -> bool { + self == i32 { mag: 0, sign: true } + } } // Implements the Into trait for i32. diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index 8bde7c0ee..d4f1853a3 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -37,6 +37,14 @@ impl i64Impl of IntegerTrait { fn sign(self: i64) -> i64 { i64_sign(self) } + + fn NaN() -> i64 { + return i64 { mag: 0, sign: true }; + } + + fn is_nan(self: i64) -> bool { + self == i64 { mag: 0, sign: true } + } } // Implements the Into trait for i64. diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 1acc60ecd..19f3eb918 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -43,6 +43,14 @@ impl i8Impl of IntegerTrait { fn sign(self: i8) -> i8 { i8_sign(self) } + + fn NaN() -> i8 { + return i8 { mag: 0, sign: true }; + } + + fn is_nan(self: i8) -> bool { + self == i8 { mag: 0, sign: true } + } } // Implements the Into trait for i8. diff --git a/src/numbers/signed_integer/integer_trait.cairo b/src/numbers/signed_integer/integer_trait.cairo index 85f7037d4..23aca9f8c 100644 --- a/src/numbers/signed_integer/integer_trait.cairo +++ b/src/numbers/signed_integer/integer_trait.cairo @@ -209,5 +209,8 @@ trait IntegerTrait { /// ``` /// fn sign(self: T) -> T; + + fn NaN() -> T; + fn is_nan(self: T) -> bool; } From ed2296966a78dcf78ec25c2110f0f8c6f0fc8e0f Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 11:56:59 +0200 Subject: [PATCH 003/160] implement TreeEnsembleImpl --- Scarb.toml | 2 +- src/operators/ml/tree_ensemble/core.cairo | 105 +++++++++++++++++----- src/utils.cairo | 12 +++ 3 files changed, 98 insertions(+), 21 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index 502513ba4..2b495e0bf 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -11,4 +11,4 @@ cubit = { git = "https://github.com/raphaelDkhn/cubit.git" } [scripts] sierra = "cairo-compile . -r" docgen = "cd docgen && cargo run" -nodegen = "python3 nodegen/node/__init__.py" \ No newline at end of file +nodegen = "python3 nodegen/node/__init__.py" diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 63f0306e5..ef33c5cbe 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -1,13 +1,17 @@ -use core::array::SpanTrait; -use core::dict::Felt252DictTrait; -use core::Felt252Dict; +use orion::numbers::NumberTrait; +use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::ArrayTraitExt; impl UsizeDictCopy of Copy>; impl UsizeDictDrop of Drop>; + #[derive(Copy, Drop)] struct TreeEnsembleAttributes { - nodes_modes: Span, // Change to modes + nodes_modes: Span, nodes_featureids: Span, nodes_missing_value_tracks_true: Span, nodes_values: Span, @@ -34,24 +38,85 @@ enum NODE_MODES { LEAF } +#[generate_trait] +impl TreeEnsembleImpl< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq +> of TreeEnsembleTrait { + fn leaf_index_tree(ref self: TreeEnsemble, x: Span, tree_id: usize) -> usize { + let mut index: usize = self.root_index.get(tree_id.into()); + + loop { + let x_value = *x.at(*(self.atts.nodes_missing_value_tracks_true).at(index)); + let r = if x_value.is_nan() { + *self.atts.nodes_missing_value_tracks_true.at(index) >= 1 + } else { + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => x_value <= *self.atts.nodes_values[index], + NODE_MODES::BRANCH_LT => x_value < *self.atts.nodes_values[index], + NODE_MODES::BRANCH_GTE => x_value >= *self.atts.nodes_values[index], + NODE_MODES::BRANCH_GT => x_value > *self.atts.nodes_values[index], + NODE_MODES::BRANCH_EQ => x_value == *self.atts.nodes_values[index], + NODE_MODES::BRANCH_NEQ => x_value != *self.atts.nodes_values[index], + NODE_MODES::LEAF => { + panic(array!['Unexpected rule for node index ', index.into()]) + }, + } + }; + + let nid = if r { + *self.atts.nodes_truenodeids[index] + } else { + *self.atts.nodes_falsenodeids[index] + }; + + // key of TreeEnsemble.node_index is pedersen hash of tree_id and nid. + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tree_id.into(), nid.into()); + + index = self.node_index.get(key); + + // Loop breaker + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => { continue; }, + NODE_MODES::BRANCH_LT => { continue; }, + NODE_MODES::BRANCH_GTE => { continue; }, + NODE_MODES::BRANCH_GT => { continue; }, + NODE_MODES::BRANCH_EQ => { continue; }, + NODE_MODES::BRANCH_NEQ => { continue; }, + NODE_MODES::LEAF => { break; }, + }; + }; + + index + } + fn leave_index_tree(ref self: TreeEnsemble, x: Tensor) -> Tensor { + let mut outputs = ArrayTrait::new(); + + let mut i: usize = 0; + let breaker: usize = *x.shape[0]; + loop { + if i == breaker { + break; + } -fn leaf_index_tree, +Copy>( - ref ensemble: TreeEnsemble, x: Span, tree_id: usize -) -> usize { - let mut index = ensemble.root_index.get(tree_id.into()); - - loop { - match *ensemble.atts.nodes_modes.at(index) { - NODE_MODES::BRANCH_LEQ => { continue; }, - NODE_MODES::BRANCH_LT => { continue; }, - NODE_MODES::BRANCH_GTE => { continue; }, - NODE_MODES::BRANCH_GT => { continue; }, - NODE_MODES::BRANCH_EQ => { continue; }, - NODE_MODES::BRANCH_NEQ => { continue; }, - NODE_MODES::LEAF => { break; }, + let row_data: Span = get_row(x, i); + let mut outs = ArrayTrait::new(); + let mut tree_ids = self.tree_ids; + loop { + match tree_ids.pop_front() { + Option::Some(tree_id) => { + outs + .append( + TreeEnsembleImpl::::leaf_index_tree(ref self, row_data, *tree_id) + ) + }, + Option::None(_) => { break; } + }; + }; + outputs.append_all(ref outs); }; - }; - 1 + TensorTrait::new(array![*x.shape[0], self.tree_ids.len()].span(), outputs.span()) + } } diff --git a/src/utils.cairo b/src/utils.cairo index b8062f733..dc2c35b0b 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -3,6 +3,8 @@ use option::OptionTrait; use array::ArrayTrait; use array::SpanTrait; +use orion::operators::tensor::{Tensor, TensorTrait}; + fn u32_max(a: u32, b: u32) -> u32 { if a > b { a @@ -28,3 +30,13 @@ fn assert_eq, impl TCopy: Copy, impl TDrop: ) { assert(lhs == rhs, 'should be equal'); } + +fn get_row, +Copy>(self: Tensor, row: usize) -> Span { + assert(self.shape.len() == 2, 'Expected a 2D tensor'); + + let row_length = *self.shape[1]; + let start = row * row_length; + let end = start + row_length; + + self.data.slice(start, end) +} From b3805308c729da92209b9ddb67b5a84f662a6cae Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 12:03:16 +0200 Subject: [PATCH 004/160] add missing loop incrementer --- src/operators/ml/tree_ensemble/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index ef33c5cbe..c07b31bba 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -114,6 +114,7 @@ impl TreeEnsembleImpl< }; }; outputs.append_all(ref outs); + i += 1; }; TensorTrait::new(array![*x.shape[0], self.tree_ids.len()].span(), outputs.span()) From 8783d5f72a8b2cccc1e2457c558ba523216a5351 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 1 Nov 2023 12:05:00 +0200 Subject: [PATCH 005/160] Update core.cairo --- src/operators/ml/tree_ensemble/core.cairo | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index c07b31bba..31508ab55 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -46,6 +46,17 @@ impl TreeEnsembleImpl< let mut index: usize = self.root_index.get(tree_id.into()); loop { + // Loop breaker + match *self.atts.nodes_modes.at(index) { + NODE_MODES::BRANCH_LEQ => {}, + NODE_MODES::BRANCH_LT => {}, + NODE_MODES::BRANCH_GTE => {}, + NODE_MODES::BRANCH_GT => {}, + NODE_MODES::BRANCH_EQ => {}, + NODE_MODES::BRANCH_NEQ => {}, + NODE_MODES::LEAF => { break; }, + }; + let x_value = *x.at(*(self.atts.nodes_missing_value_tracks_true).at(index)); let r = if x_value.is_nan() { *self.atts.nodes_missing_value_tracks_true.at(index) >= 1 @@ -74,17 +85,6 @@ impl TreeEnsembleImpl< let key: felt252 = key.hash(tree_id.into(), nid.into()); index = self.node_index.get(key); - - // Loop breaker - match *self.atts.nodes_modes.at(index) { - NODE_MODES::BRANCH_LEQ => { continue; }, - NODE_MODES::BRANCH_LT => { continue; }, - NODE_MODES::BRANCH_GTE => { continue; }, - NODE_MODES::BRANCH_GT => { continue; }, - NODE_MODES::BRANCH_EQ => { continue; }, - NODE_MODES::BRANCH_NEQ => { continue; }, - NODE_MODES::LEAF => { break; }, - }; }; index From 81c76d6eb3a732cc5f8d8ede7183b3100eea4cfd Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 3 Nov 2023 10:02:14 +0200 Subject: [PATCH 006/160] start treen ensemble classifier --- src/operators/ml/tree_ensemble.cairo | 3 +- src/operators/ml/tree_ensemble/core.cairo | 10 ++++-- .../tree_ensemble_classifier.cairo | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index ef33ab296..0f09fa8d1 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1 +1,2 @@ -mod core; \ No newline at end of file +mod core; +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 31508ab55..46a4762f5 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -11,12 +11,16 @@ impl UsizeDictDrop of Drop>; #[derive(Copy, Drop)] struct TreeEnsembleAttributes { - nodes_modes: Span, + base_values: Option>, + nodes_falsenodeids: Span, nodes_featureids: Span, + nodes_hitrates: Span, nodes_missing_value_tracks_true: Span, - nodes_values: Span, + nodes_modes: Span, + nodes_nodeids: Span, + nodes_treeids: Span, nodes_truenodeids: Span, - nodes_falsenodeids: Span, + nodes_values: Span, } #[derive(Copy, Drop)] diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo new file mode 100644 index 000000000..e2ea89176 --- /dev/null +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -0,0 +1,33 @@ +use orion::numbers::NumberTrait; +use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleTrait, TreeEnsembleImpl}; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::ArrayTraitExt; +use alexandria_data_structures::vec::{VecTrait, NullableVec}; + +#[derive(Copy, Drop)] +enum PostTransform { + None, + Logistic, + Softmax, + SoftmaxZero, + Probit, +} + +fn classify< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq, +Add, +// +Drop<(Felt252DictEntry::>, Nullable::)>, +// +Copy>> +>( + ref self: TreeEnsemble, + X: Tensor, + post_transform: PostTransform, + class_labels: Span +) { + let leaves_index = self.leave_index_tree(X); + let n_classes = class_labels.len(); + let res_shape: Span = array![*leaves_index.shape[0], n_classes].span(); +} + From 8fc75edad067cdf5d125c378235c2a9265e7092e Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 3 Nov 2023 10:23:58 +0200 Subject: [PATCH 007/160] implement mut matrix --- src/operators.cairo | 1 + src/operators/matrix.cairo | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/operators/matrix.cairo diff --git a/src/operators.cairo b/src/operators.cairo index e71b8e6dc..eee74cf89 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -1,3 +1,4 @@ mod tensor; mod nn; mod ml; +mod matrix; \ No newline at end of file diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo new file mode 100644 index 000000000..4baec91af --- /dev/null +++ b/src/operators/matrix.cairo @@ -0,0 +1,43 @@ +use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; + +impl VecCopy of Copy>; +impl NullCopy of Copy>>; +impl VecDrop of Drop>; +impl NullDrop of Drop>>; + +#[derive(Copy, Drop)] +struct MutMatrix { + data: NullableVec, + rows: usize, + cols: usize, +} + +#[generate_trait] +impl MutMatrixImpl, +Copy> of MutMatrixTrait { + // Constructor for the Matrix + fn new(rows: usize, cols: usize) -> MutMatrix { + MutMatrix { data: NullableVecImpl::new(), rows: rows, cols: cols } + } + + // Get the value at (row, col) + fn get(ref self: MutMatrix, row: usize, col: usize) -> Option { + if row >= self.rows || col >= self.cols { + Option::None + } else { + self.data.get(row * self.cols + col) + } + } + + // Set the value at (row, col) + fn set(ref self: MutMatrix, row: usize, col: usize, value: T) { + if row < self.rows && col < self.cols { + let index = row * self.cols + col; + self.data.set(index, value) + } + } + + // Returns the shape of the matrix as (rows, cols) + fn shape(self: MutMatrix) -> (usize, usize) { + (self.rows, self.cols) + } +} From f1c109d4be92bf739e1f6998715eab5f0e037640 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 5 Nov 2023 17:30:29 +0200 Subject: [PATCH 008/160] implement TreeEnsembleClassifierImpl --- .../tree_ensemble_classifier.cairo | 256 ++++++++++++++++-- 1 file changed, 239 insertions(+), 17 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index e2ea89176..7f0bb025e 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,33 +1,255 @@ +use core::dict::Felt252DictEntryTrait; +use nullable::{match_nullable, FromNullableResult}; + +use orion::operators::tensor::{Tensor, TensorTrait}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; use orion::numbers::NumberTrait; -use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleTrait, TreeEnsembleImpl}; -use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -use alexandria_data_structures::array_ext::ArrayTraitExt; -use alexandria_data_structures::vec::{VecTrait, NullableVec}; + +#[derive(Copy, Drop)] +struct TreeEnsembleClassifier { + ensemble: TreeEnsemble, + class_ids: Span, + class_nodeids: Span, + class_treeids: Span, + class_weights: Span, + class_labels: Span, + base_values: Option>, + post_transform: PostTransform, +} #[derive(Copy, Drop)] enum PostTransform { None, - Logistic, Softmax, + Logistic, SoftmaxZero, Probit, } +#[generate_trait] +impl TreeEnsembleClassifierImpl< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +Copy>>>, + +Copy>>, + +Copy>>, + +Drop<(Span::, Felt252Dict::>)> +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); + + (predictions, final_scores) + } +} + +fn compute_scores< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +Copy>>>, + +Copy>>, + +Copy>> +>( + ref self: TreeEnsembleClassifier, leaf_indices: Tensor +) -> (Span, Felt252Dict::>) { + // Initialize the scores array, either with base_values or zeros + let num_samples = *leaf_indices.shape[0]; + let num_classes = self.class_labels.len(); + let mut scores_shape = array![num_samples, num_classes].span(); + + // Store scores in dictionary because of immutability of array. + let mut scores_data: Felt252Dict> = Default::default(); + if self.base_values.is_some() { + // Repeat base values for each sample + let mut sample_index: usize = 0; + loop { + if sample_index == num_samples { + break; + } + + let mut class_index: usize = 0; + loop { + if class_index == num_classes { + break; + } + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(sample_index.into(), class_index.into()); + scores_data + .insert(key, NullableTrait::new(*self.base_values.unwrap().at(class_index))); + + class_index += 1; + }; + + sample_index += 1; + } + } + + // Compute class index mapping + let mut class_index: Felt252Dict>> = Default::default(); + let mut class_weights = self.class_weights; + let mut class_ids = self.class_ids; + let mut class_nodeids = self.class_nodeids; + let mut class_treeids = self.class_treeids; + loop { + match class_weights.pop_front() { + Option::Some(class_weight) => { + let mut class_id: usize = *class_ids.pop_front().unwrap(); + let mut node_id: usize = *class_nodeids.pop_front().unwrap(); + let mut tree_id: usize = *class_treeids.pop_front().unwrap(); + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tree_id.into(), node_id.into()); + + let (entry, _prev_value) = class_index.entry(key); + match match_nullable(_prev_value) { + FromNullableResult::Null(()) => { + entry.finalize(NullableTrait::new(array![])) + }, + FromNullableResult::NotNull(val) => { + let mut new_val = _prev_value.deref(); + new_val.append((class_id, *class_weight)); + entry.finalize(NullableTrait::new(new_val)) + }, + }; + }, + Option::None(_) => { break; } + }; + }; + + // Update scores based on class index mapping + let mut sample_index: usize = 0; + let mut leaf_indices_data = leaf_indices.data; + loop { + match leaf_indices_data.pop_front() { + Option::Some(leaf_index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), + (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() + ); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { continue; }, + FromNullableResult::NotNull(class_weight_pairs) => { + let mut class_weight_pairs_span = class_weight_pairs.unbox().span(); + loop { + match class_weight_pairs_span.pop_front() { + Option::Some(class_weight_pair) => { + let (class_id, class_weight) = *class_weight_pair; + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash((sample_index).into(), (class_id).into()); + + let (entry, value) = scores_data.entry(key); + let value = value.deref(); + entry.finalize(NullableTrait::new(value + class_weight)); + }, + Option::None(_) => { break; } + }; + } + }, + } + + sample_index += 1; + }, + Option::None(_) => { break; } + }; + }; + + // Apply post-transform to scores + match self.post_transform { + PostTransform::None => {}, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + } + + (scores_shape, scores_data) +} + fn classify< - T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq, +Add, -// +Drop<(Felt252DictEntry::>, Nullable::)>, -// +Copy>> + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +Copy>>>, + +Copy>>, + +Copy>>, + +Drop<(Span::, Felt252Dict::>)> >( - ref self: TreeEnsemble, - X: Tensor, - post_transform: PostTransform, - class_labels: Span -) { - let leaves_index = self.leave_index_tree(X); - let n_classes = class_labels.len(); - let res_shape: Span = array![*leaves_index.shape[0], n_classes].span(); + ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) +) -> (Tensor, Tensor) { + let (scores_shape, mut scores_data) = scores; + let num_samples = *scores_shape[0]; + let num_classes = *scores_shape[1]; + + let predictions_shape = array![num_samples].span(); + let mut final_scores_shape = scores_shape; + let mut predictions_data = ArrayTrait::new(); + let mut final_scores_data = ArrayTrait::new(); + + let mut sample_index: usize = 0; + loop { + if sample_index == num_samples { + break; + } + + // Placeholder for the minimum value for type T + let mut max_score = NumberTrait::::min_value(); + let mut max_class_index = 0; + + let mut class_index: usize = 0; + loop { + if class_index == num_classes { + break; + } + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash((sample_index).into(), (class_index).into()); + let score = scores_data[key].deref(); + + if score > max_score { + max_score = score; + max_class_index = class_index; + } + + class_index += 1; + }; + + final_scores_data.append(max_score); + predictions_data.append(max_class_index); + sample_index += 1; + }; + + ( + TensorTrait::new(predictions_shape, predictions_data.span()), + TensorTrait::new(final_scores_shape, final_scores_data.span()) + ) } From c41189e2637b19da98ccc6328502c80cc95b50b3 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Mon, 6 Nov 2023 16:02:28 +0200 Subject: [PATCH 009/160] replace drop with destruct --- src/operators/ml/tree_ensemble/core.cairo | 12 +- .../tree_ensemble_classifier.cairo | 8 +- tests/ml.cairo | 1 + tests/ml/tree_ensemble_classifier.cairo | 134 ++++++++++++++++++ 4 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 tests/ml/tree_ensemble_classifier.cairo diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index 46a4762f5..cd8992eb9 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -1,3 +1,5 @@ +use core::array::ArrayTrait; +use alexandria_data_structures::array_ext::SpanTraitExt; use orion::numbers::NumberTrait; use orion::operators::tensor::{Tensor, TensorTrait, U32Tensor}; use orion::utils::get_row; @@ -5,16 +7,11 @@ use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::ArrayTraitExt; -impl UsizeDictCopy of Copy>; -impl UsizeDictDrop of Drop>; - -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Destruct)] struct TreeEnsembleAttributes { - base_values: Option>, nodes_falsenodeids: Span, nodes_featureids: Span, - nodes_hitrates: Span, nodes_missing_value_tracks_true: Span, nodes_modes: Span, nodes_nodeids: Span, @@ -23,7 +20,7 @@ struct TreeEnsembleAttributes { nodes_values: Span, } -#[derive(Copy, Drop)] +#[derive(Destruct)] struct TreeEnsemble { atts: TreeEnsembleAttributes, tree_ids: Span, @@ -42,6 +39,7 @@ enum NODE_MODES { LEAF } + #[generate_trait] impl TreeEnsembleImpl< T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd, +PartialEq diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 7f0bb025e..ae3c50a33 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -7,7 +7,7 @@ use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -#[derive(Copy, Drop)] +#[derive(Destruct)] struct TreeEnsembleClassifier { ensemble: TreeEnsemble, class_ids: Span, @@ -43,7 +43,7 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)> + +Drop<(Span::, Felt252Dict::>)>, > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -65,7 +65,7 @@ fn compute_scores< +Add, +Copy>>>, +Copy>>, - +Copy>> + +Copy>>, >( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { @@ -201,7 +201,7 @@ fn classify< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)> + +Drop<(Span::, Felt252Dict::>)>, >( ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) ) -> (Tensor, Tensor) { diff --git a/tests/ml.cairo b/tests/ml.cairo index eca55a25b..f75954665 100644 --- a/tests/ml.cairo +++ b/tests/ml.cairo @@ -1 +1,2 @@ mod tree_regressor; +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo new file mode 100644 index 000000000..a4d6122be --- /dev/null +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -0,0 +1,134 @@ +use core::dict::Felt252DictTrait; +use orion::numbers::FP16x16; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor}; +use orion::operators::ml::tree_ensemble::core::{ + NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl +//TreeEnsembleHelperTrait +}; +// use orion::operators::ml::tree_ensemble::implementations::{FP16x16TreeEnsembleHelper}; + +#[test] +#[available_gas(2000000000)] +fn test_tree_ensemble_classifier_multi() { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let class_labels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts: atts, tree_ids: tree_ids, root_index: root_index, node_index: node_index + }; + + TreeEnsembleImpl::leave_index_tree( + ref ensemble, + TensorTrait::new(array![1].span(), array![FP16x16 { mag: 0, sign: false }].span()) + ); +} + From 36ba47da77ecda547b32a214953edb7a26c35a19 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Mon, 6 Nov 2023 18:50:25 +0200 Subject: [PATCH 010/160] fix get_row --- .../tree_ensemble_classifier.cairo | 9 ---- src/utils.cairo | 3 +- tests/ml/tree_ensemble_classifier.cairo | 43 ++++++++++++++++--- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index ae3c50a33..f4cbd7218 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -43,7 +43,6 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, - +Drop<(Span::, Felt252Dict::>)>, > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -60,8 +59,6 @@ fn compute_scores< +Drop, +Copy, +NumberTrait, - +PartialOrd, - +PartialEq, +Add, +Copy>>>, +Copy>>, @@ -194,14 +191,8 @@ fn classify< +Copy, +NumberTrait, +PartialOrd, - +PartialEq, - +Add, +TensorTrait, +TensorTrait, - +Copy>>>, - +Copy>>, - +Copy>>, - +Drop<(Span::, Felt252Dict::>)>, >( ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) ) -> (Tensor, Tensor) { diff --git a/src/utils.cairo b/src/utils.cairo index dc2c35b0b..ab48c3d7d 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -36,7 +36,6 @@ fn get_row, +Copy>(self: Tensor, row: usize) -> Span { let row_length = *self.shape[1]; let start = row * row_length; - let end = start + row_length; - self.data.slice(start, end) + self.data.slice(start, row_length) } diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index a4d6122be..e1cdfcecc 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,11 +1,12 @@ use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; -use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor}; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl -//TreeEnsembleHelperTrait }; -// use orion::operators::ml::tree_ensemble::implementations::{FP16x16TreeEnsembleHelper}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform +}; #[test] #[available_gas(2000000000)] @@ -123,12 +124,40 @@ fn test_tree_ensemble_classifier_multi() { }; let mut ensemble: TreeEnsemble = TreeEnsemble { - atts: atts, tree_ids: tree_ids, root_index: root_index, node_index: node_index + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let post_transform = PostTransform::None; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + class_labels, + base_values, + post_transform }; - TreeEnsembleImpl::leave_index_tree( - ref ensemble, - TensorTrait::new(array![1].span(), array![FP16x16 { mag: 0, sign: false }].span()) + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() ); + + TreeEnsembleClassifierImpl::predict(ref classifier, X); } From d37c07edf4e29c1310233759e5b0ef7d105ea8e6 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 7 Nov 2023 14:48:51 +0200 Subject: [PATCH 011/160] add implementation --- src/operators/ml/tree_ensemble.cairo | 3 ++- .../ml/tree_ensemble/implementations.cairo | 13 +++++++++++ .../tree_ensemble_classifier.cairo | 23 +++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/implementations.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 0f09fa8d1..194732749 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,2 +1,3 @@ mod core; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; +mod implementations; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/implementations.cairo b/src/operators/ml/tree_ensemble/implementations.cairo new file mode 100644 index 000000000..d5b018d6e --- /dev/null +++ b/src/operators/ml/tree_ensemble/implementations.cairo @@ -0,0 +1,13 @@ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifierTrait, TreeEnsembleClassifier, predict +}; +use orion::numbers::FP16x16; +use orion::operators::tensor::{FP16x16Tensor, U32Tensor, Tensor}; + +impl FP16x16TreeEnsembleClassifier of TreeEnsembleClassifierTrait { + fn predict( + ref self: TreeEnsembleClassifier, X: Tensor + ) -> (Tensor, Tensor) { + predict(ref self, X) + } +} diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index f4cbd7218..5b31eeef7 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -28,8 +28,12 @@ enum PostTransform { Probit, } -#[generate_trait] -impl TreeEnsembleClassifierImpl< + +trait TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor); +} + +fn predict< T, MAG, +Drop, @@ -43,16 +47,17 @@ impl TreeEnsembleClassifierImpl< +Copy>>>, +Copy>>, +Copy>>, -> of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); +>( + ref self: TreeEnsembleClassifier, X: Tensor +) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); - (predictions, final_scores) - } + (predictions, final_scores) } + fn compute_scores< T, MAG, From a163eb9928c1a0787824ab5ef04e7518a7d1a0aa Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 7 Nov 2023 15:40:14 +0200 Subject: [PATCH 012/160] fix compilation --- src/operators/ml/tree_ensemble.cairo | 3 +- .../ml/tree_ensemble/implementations.cairo | 13 ---- .../tree_ensemble_classifier.cairo | 66 ++++++++----------- tests/ml/tree_ensemble_classifier.cairo | 5 +- 4 files changed, 32 insertions(+), 55 deletions(-) delete mode 100644 src/operators/ml/tree_ensemble/implementations.cairo diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 194732749..0f09fa8d1 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,3 +1,2 @@ mod core; -mod tree_ensemble_classifier; -mod implementations; \ No newline at end of file +mod tree_ensemble_classifier; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/implementations.cairo b/src/operators/ml/tree_ensemble/implementations.cairo deleted file mode 100644 index d5b018d6e..000000000 --- a/src/operators/ml/tree_ensemble/implementations.cairo +++ /dev/null @@ -1,13 +0,0 @@ -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifierTrait, TreeEnsembleClassifier, predict -}; -use orion::numbers::FP16x16; -use orion::operators::tensor::{FP16x16Tensor, U32Tensor, Tensor}; - -impl FP16x16TreeEnsembleClassifier of TreeEnsembleClassifierTrait { - fn predict( - ref self: TreeEnsembleClassifier, X: Tensor - ) -> (Tensor, Tensor) { - predict(ref self, X) - } -} diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 5b31eeef7..5ac2cf43f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,5 @@ +use core::nullable::NullableTrait; +use core::dict::Felt252DictTrait; use core::dict::Felt252DictEntryTrait; use nullable::{match_nullable, FromNullableResult}; @@ -6,6 +8,7 @@ use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::{SpanTraitExt}; #[derive(Destruct)] struct TreeEnsembleClassifier { @@ -29,11 +32,8 @@ enum PostTransform { } -trait TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor); -} - -fn predict< +#[generate_trait] +impl TreeEnsembleClassifierImpl< T, MAG, +Drop, @@ -44,31 +44,18 @@ fn predict< +Add, +TensorTrait, +TensorTrait, - +Copy>>>, - +Copy>>, - +Copy>>, ->( - ref self: TreeEnsembleClassifier, X: Tensor -) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { + let leaf_indices = self.ensemble.leave_index_tree(X); + let scores = compute_scores(ref self, leaf_indices); + let (predictions, final_scores) = classify(ref self, scores); - (predictions, final_scores) + (predictions, final_scores) + } } -fn compute_scores< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +Add, - +Copy>>>, - +Copy>>, - +Copy>>, ->( +fn compute_scores, +Copy, +NumberTrait, +Add,>( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { // Initialize the scores array, either with base_values or zeros @@ -105,7 +92,7 @@ fn compute_scores< } // Compute class index mapping - let mut class_index: Felt252Dict>> = Default::default(); + let mut class_index: Felt252Dict>> = Default::default(); let mut class_weights = self.class_weights; let mut class_ids = self.class_ids; let mut class_nodeids = self.class_nodeids; @@ -120,15 +107,14 @@ fn compute_scores< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash(tree_id.into(), node_id.into()); - let (entry, _prev_value) = class_index.entry(key); - match match_nullable(_prev_value) { - FromNullableResult::Null(()) => { - entry.finalize(NullableTrait::new(array![])) + let prev_value = class_index.get(key); + match match_nullable(prev_value) { + FromNullableResult::Null(()) => { // entry.finalize(NullableTrait::new(array![])) }, FromNullableResult::NotNull(val) => { - let mut new_val = _prev_value.deref(); - new_val.append((class_id, *class_weight)); - entry.finalize(NullableTrait::new(new_val)) + let mut new_val = prev_value.deref(); + let new_va = new_val.concat(array![(class_id, *class_weight)].span()); + class_index.insert(key, nullable_from_box(BoxTrait::new(new_va))); }, }; }, @@ -148,10 +134,11 @@ fn compute_scores< (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() ); + match match_nullable(class_index.get(key)) { FromNullableResult::Null(()) => { continue; }, FromNullableResult::NotNull(class_weight_pairs) => { - let mut class_weight_pairs_span = class_weight_pairs.unbox().span(); + let mut class_weight_pairs_span = class_weight_pairs.unbox(); loop { match class_weight_pairs_span.pop_front() { Option::Some(class_weight_pair) => { @@ -161,9 +148,12 @@ fn compute_scores< let key: felt252 = key .hash((sample_index).into(), (class_id).into()); - let (entry, value) = scores_data.entry(key); - let value = value.deref(); - entry.finalize(NullableTrait::new(value + class_weight)); + let value = scores_data.get(key).deref(); + scores_data + .insert( + key, + nullable_from_box(BoxTrait::new(value + class_weight)) + ); }, Option::None(_) => { break; } }; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index e1cdfcecc..48497b267 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -5,7 +5,8 @@ use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform + //TreeEnsembleClassifierImpl, + TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; #[test] @@ -158,6 +159,6 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - TreeEnsembleClassifierImpl::predict(ref classifier, X); + TreeEnsembleClassifierTrait::predict(ref classifier, X); } From b023605660f182ab8e58ed5321c852415be9196b Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 7 Nov 2023 18:31:46 +0100 Subject: [PATCH 013/160] Implement binarizer operator --- src/operators/tensor/core.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 3 +- src/operators/tensor/math/binarizer.cairo | 38 +++++++++++++++++++ 12 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/math/binarizer.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 8a3ae7e68..74c6485b0 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 508134a2f..429e2cf8d 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,6 +288,10 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index d87f6dd9d..c9e5d9e61 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -286,6 +286,10 @@ impl FP16x16WTensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 30b85b755..bd73890cc 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -288,6 +288,10 @@ impl FP32x32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 c86420354..fd3c8afc2 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,6 +289,10 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// 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 3ddcf0369..c4db51e7f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -287,6 +287,10 @@ impl FP8x23Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 3c36ee737..82ffe8c55 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,6 +277,10 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } + } /// 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 bf0592c41..2accf79fb 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -287,6 +287,10 @@ impl I32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 bfadc3be5..d682114d8 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -286,6 +286,10 @@ impl I8Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// 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 2faf21b0b..7c18fb79d 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -268,6 +268,10 @@ impl U32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + math::binarizer::binarizer(*self, threshold) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 79404dcd5..2e761e4cd 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,4 +38,5 @@ mod and; mod neg; mod where; mod round; -mod scatter; \ No newline at end of file +mod scatter; +mod binarizer; \ No newline at end of file diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo new file mode 100644 index 000000000..d28be43d0 --- /dev/null +++ b/src/operators/tensor/math/binarizer.cairo @@ -0,0 +1,38 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::binarizer docstring +fn binarizer< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, threshold: @T +) -> Tensor { + let mut binarized_data: Array = ArrayTrait::new(); + + loop { + match self.data.pop_front() { + Option::Some(item) => { + if (*item) > (*threshold) { + binarized_data.append(1); + } else { + binarized_data.append(0); + } + }, + Option::None(_) => { + break; + } + }; + }; + + return TensorTrait::new(self.shape, binarized_data.span()); +} From 9f4e1bace6473249ef2c640f7ca832829404e066 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 8 Nov 2023 11:07:08 +0200 Subject: [PATCH 014/160] fix deref issue --- .../tree_ensemble_classifier.cairo | 41 +++++++++++++------ tests/ml/tree_ensemble_classifier.cairo | 1 - 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 5ac2cf43f..b7f9432f4 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -10,6 +10,8 @@ use orion::numbers::NumberTrait; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::{SpanTraitExt}; +use debug::PrintTrait; + #[derive(Destruct)] struct TreeEnsembleClassifier { ensemble: TreeEnsemble, @@ -107,14 +109,18 @@ fn compute_scores, +Copy, +NumberTrait, +Add,>( let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash(tree_id.into(), node_id.into()); - let prev_value = class_index.get(key); - match match_nullable(prev_value) { - FromNullableResult::Null(()) => { // entry.finalize(NullableTrait::new(array![])) + let value = class_index.get(key); + match match_nullable(value) { + FromNullableResult::Null(()) => { + class_index + .insert( + key, NullableTrait::new(array![(class_id, *class_weight)].span()) + ); }, FromNullableResult::NotNull(val) => { - let mut new_val = prev_value.deref(); - let new_va = new_val.concat(array![(class_id, *class_weight)].span()); - class_index.insert(key, nullable_from_box(BoxTrait::new(new_va))); + let mut new_val = value.deref(); + let new_val = new_val.concat(array![(class_id, *class_weight)].span()); + class_index.insert(key, NullableTrait::new(new_val)); }, }; }, @@ -148,12 +154,20 @@ fn compute_scores, +Copy, +NumberTrait, +Add,>( let key: felt252 = key .hash((sample_index).into(), (class_id).into()); - let value = scores_data.get(key).deref(); - scores_data - .insert( - key, - nullable_from_box(BoxTrait::new(value + class_weight)) - ); + let value = scores_data.get(key); + match match_nullable(value) { + FromNullableResult::Null(()) => { + scores_data + .insert(key, NullableTrait::new(class_weight)); + }, + FromNullableResult::NotNull(val) => { + scores_data + .insert( + key, + NullableTrait::new(value.deref() + class_weight) + ); + }, + } }, Option::None(_) => { break; } }; @@ -218,7 +232,8 @@ fn classify< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key].deref(); + let score = scores_data[key] + .deref(); // <-- PANICS HERE WITH 'Attempted to deref null value' if score > max_score { max_score = score; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 48497b267..66a8f44a4 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -5,7 +5,6 @@ use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - //TreeEnsembleClassifierImpl, TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; From a623f6bbdd2079b9e0944ba757f9cf8b0394aa5a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 8 Nov 2023 12:17:50 +0200 Subject: [PATCH 015/160] fix tensor wrong shape --- .../ml/tree_ensemble/tree_ensemble_classifier.cairo | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index b7f9432f4..10523ab11 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -232,8 +232,9 @@ fn classify< let mut key = PedersenHasherImpl::new(); let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key] - .deref(); // <-- PANICS HERE WITH 'Attempted to deref null value' + let score = scores_data[key].deref(); + + final_scores_data.append(score); if score > max_score { max_score = score; @@ -243,7 +244,6 @@ fn classify< class_index += 1; }; - final_scores_data.append(max_score); predictions_data.append(max_class_index); sample_index += 1; }; From b21b9310da2b2e4d3e8aa935c75dcc8b0b8abfe8 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 11:26:43 +0100 Subject: [PATCH 016/160] Add tests and adjust implementations --- nodegen/node/binarizer.py | 49 +++++++++++++++++++ .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- tests/nodes.cairo | 5 +- tests/nodes/binarizer_fp16x16.cairo | 21 ++++++++ tests/nodes/binarizer_fp16x16/input_0.cairo | 42 ++++++++++++++++ tests/nodes/binarizer_fp16x16/output_0.cairo | 40 +++++++++++++++ tests/nodes/binarizer_fp8x23.cairo | 21 ++++++++ tests/nodes/binarizer_fp8x23/input_0.cairo | 42 ++++++++++++++++ tests/nodes/binarizer_fp8x23/output_0.cairo | 40 +++++++++++++++ tests/nodes/binarizer_i32.cairo | 21 ++++++++ tests/nodes/binarizer_i32/input_0.cairo | 41 ++++++++++++++++ tests/nodes/binarizer_i32/output_0.cairo | 40 +++++++++++++++ 13 files changed, 363 insertions(+), 3 deletions(-) create mode 100644 nodegen/node/binarizer.py create mode 100644 tests/nodes/binarizer_fp16x16.cairo create mode 100644 tests/nodes/binarizer_fp16x16/input_0.cairo create mode 100644 tests/nodes/binarizer_fp16x16/output_0.cairo create mode 100644 tests/nodes/binarizer_fp8x23.cairo create mode 100644 tests/nodes/binarizer_fp8x23/input_0.cairo create mode 100644 tests/nodes/binarizer_fp8x23/output_0.cairo create mode 100644 tests/nodes/binarizer_i32.cairo create mode 100644 tests/nodes/binarizer_i32/input_0.cairo create mode 100644 tests/nodes/binarizer_i32/output_0.cairo diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py new file mode 100644 index 000000000..661fcf95a --- /dev/null +++ b/nodegen/node/binarizer.py @@ -0,0 +1,49 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Binarizer(RunAll): + + @staticmethod + def binarizer_i32(): + x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) + threshold = 1 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_i32" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false));", name) + + + @staticmethod + def binarizer_fp8x23(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + threshold = 1.0 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_fp8x23" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false));", name) + + + @staticmethod + def binarizer_fp16x16(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + threshold = 1.0 + y = (x > threshold).astype(np.uint32) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "binarizer_fp16x16" + make_node([x], [y], name) + make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false));", name) diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index d682114d8..cd7247aa9 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -288,7 +288,7 @@ impl I8Tensor of TensorTrait { } fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { - math::binarizer::binarizer(*self, threshold) + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 7c18fb79d..2fd0063f4 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -270,7 +270,7 @@ impl U32Tensor of TensorTrait { } fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { - math::binarizer::binarizer(*self, threshold) + panic(array!['not supported!']) } } diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..e841e15aa 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,4 +527,7 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod scatter_u32_add; +mod binarizer_fp16x16; +mod binarizer_fp8x23; +mod binarizer_i32; diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo new file mode 100644 index 000000000..258bfa8f1 --- /dev/null +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; +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_binarizer_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo new file mode 100644 index 000000000..2aaa53e2b --- /dev/null +++ b/tests/nodes/binarizer_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: 146027, sign: true }); + data.append(FP16x16 { mag: 29998, sign: false }); + data.append(FP16x16 { mag: 79381, sign: true }); + data.append(FP16x16 { mag: 52502, sign: true }); + data.append(FP16x16 { mag: 141943, sign: true }); + data.append(FP16x16 { mag: 77493, sign: true }); + data.append(FP16x16 { mag: 143847, sign: true }); + data.append(FP16x16 { mag: 40577, sign: true }); + data.append(FP16x16 { mag: 15396, sign: false }); + data.append(FP16x16 { mag: 194266, sign: true }); + data.append(FP16x16 { mag: 73878, sign: true }); + data.append(FP16x16 { mag: 123262, sign: true }); + data.append(FP16x16 { mag: 106458, sign: false }); + data.append(FP16x16 { mag: 173856, sign: false }); + data.append(FP16x16 { mag: 80438, sign: true }); + data.append(FP16x16 { mag: 164829, sign: true }); + data.append(FP16x16 { mag: 89224, sign: true }); + data.append(FP16x16 { mag: 2691, sign: false }); + data.append(FP16x16 { mag: 181152, sign: true }); + data.append(FP16x16 { mag: 128977, sign: false }); + data.append(FP16x16 { mag: 78823, sign: true }); + data.append(FP16x16 { mag: 65209, sign: true }); + data.append(FP16x16 { mag: 56918, sign: false }); + data.append(FP16x16 { mag: 118799, sign: true }); + data.append(FP16x16 { mag: 179883, sign: false }); + data.append(FP16x16 { mag: 114165, sign: true }); + data.append(FP16x16 { mag: 142, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo new file mode 100644 index 000000000..9499a7848 --- /dev/null +++ b/tests/nodes/binarizer_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(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + 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/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo new file mode 100644 index 000000000..4de3cbb7d --- /dev/null +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; +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_binarizer_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo new file mode 100644 index 000000000..39d12c3be --- /dev/null +++ b/tests/nodes/binarizer_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: 7205493, sign: true }); + data.append(FP8x23 { mag: 14503128, sign: false }); + data.append(FP8x23 { mag: 9682839, sign: false }); + data.append(FP8x23 { mag: 25030485, sign: false }); + data.append(FP8x23 { mag: 3669115, sign: true }); + data.append(FP8x23 { mag: 16376632, sign: true }); + data.append(FP8x23 { mag: 4670619, sign: false }); + data.append(FP8x23 { mag: 24976405, sign: true }); + data.append(FP8x23 { mag: 19811890, sign: false }); + data.append(FP8x23 { mag: 10781071, sign: true }); + data.append(FP8x23 { mag: 10216945, sign: false }); + data.append(FP8x23 { mag: 25004285, sign: false }); + data.append(FP8x23 { mag: 7482592, sign: false }); + data.append(FP8x23 { mag: 1360, sign: true }); + data.append(FP8x23 { mag: 10632602, sign: true }); + data.append(FP8x23 { mag: 275175, sign: true }); + data.append(FP8x23 { mag: 21731586, sign: true }); + data.append(FP8x23 { mag: 5638921, sign: true }); + data.append(FP8x23 { mag: 6096613, sign: false }); + data.append(FP8x23 { mag: 22105612, sign: false }); + data.append(FP8x23 { mag: 17084000, sign: true }); + data.append(FP8x23 { mag: 12627954, sign: true }); + data.append(FP8x23 { mag: 23194838, sign: false }); + data.append(FP8x23 { mag: 9012947, sign: false }); + data.append(FP8x23 { mag: 5163417, sign: true }); + data.append(FP8x23 { mag: 13580853, sign: false }); + data.append(FP8x23 { mag: 5624227, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo new file mode 100644 index 000000000..d5317e309 --- /dev/null +++ b/tests/nodes/binarizer_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(0); + 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(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo new file mode 100644 index 000000000..dc82a3bd1 --- /dev/null +++ b/tests/nodes/binarizer_i32.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::IntegerTrait; +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_binarizer_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false)); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo new file mode 100644 index 000000000..f4e25323a --- /dev/null +++ b/tests/nodes/binarizer_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: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + 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: true }); + data.append(i32 { mag: 2, sign: false }); + 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: 0, 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: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo new file mode 100644 index 000000000..23163214e --- /dev/null +++ b/tests/nodes/binarizer_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(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From 4c65e78686fb61a3ad92dce12cb82a28b2094b39 Mon Sep 17 00:00:00 2001 From: chachaleo Date: Wed, 8 Nov 2023 21:04:39 +0700 Subject: [PATCH 017/160] feat: qlinearmal --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + src/operators/tensor/core.cairo | 132 +++++++++- .../implementations/tensor_fp16x16.cairo | 24 ++ .../implementations/tensor_fp16x16wide.cairo | 13 + .../implementations/tensor_fp32x32.cairo | 24 ++ .../implementations/tensor_fp64x64.cairo | 24 ++ .../implementations/tensor_fp8x23.cairo | 24 ++ .../implementations/tensor_fp8x23wide.cairo | 13 + .../tensor/implementations/tensor_i32.cairo | 24 ++ .../tensor/implementations/tensor_i8.cairo | 24 ++ .../tensor/implementations/tensor_u32.cairo | 13 + src/operators/tensor/quantization.cairo | 1 + .../tensor/quantization/qlinear_mul.cairo | 58 +++++ tests/operators.cairo | 1 + tests/operators/qlinear_mul_test.cairo | 230 ++++++++++++++++++ 16 files changed, 604 insertions(+), 3 deletions(-) create mode 100644 src/operators/tensor/quantization/qlinear_mul.cairo create mode 100644 tests/operators/qlinear_mul_test.cairo diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 4b3c18068..aab339a60 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -85,6 +85,7 @@ * [tensor.quantize\_linear](framework/operators/tensor/tensor.quantize\_linear.md) * [tensor.dequantize\_linear](framework/operators/tensor/tensor.dequantize\_linear.md) * [tensor.qlinear\_add](framework/operators/tensor/tensor.qlinear\_add.md) + * [tensor.qlinear\_mul](framework/operators/tensor/tensor.qlinear\_mul.md) * [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md) * [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) * [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 98bfca62a..68b11e8c2 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -57,6 +57,7 @@ You can see below the list of current supported ONNX Operators: | [QuantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | | [DequantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | | [QlinearAdd](operators/tensor/tensor.qlinear\_add.md) | :white\_check\_mark: | +| [QlinearMul](operators/tensor/tensor.qlinear\_mul.md) | :white\_check\_mark: | | [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: | | [Nonzero](operators/tensor/tensor.nonzero.md) | :white\_check\_mark: | | [Squeeze](operators/tensor/tensor.squeeze.md) | :white\_check\_mark: | diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 1e1758cd7..233d2fca3 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -76,6 +76,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Examples /// @@ -2550,17 +2553,17 @@ trait TensorTrait { /// /// It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). - /// It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the multiplication. + /// It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the addition. /// The broadcasting is supported /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. /// /// ## Args /// - /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `self`(`@Tensor`) - The first tensor to be additionned (a). /// * `a_scale`(`@Tensor`) - Scale for input `a`. /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. - /// * `b`(`@Tensor`) - The second tensor to be multiplied + /// * `b`(`@Tensor`) - The second tensor to be additionned /// * `b_scale`(`@Tensor`) - Scale for input `b`. /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. /// * `y_scale`(`@Tensor`) - Scale for outut. @@ -2573,6 +2576,8 @@ trait TensorTrait { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Example /// @@ -2651,6 +2656,125 @@ trait TensorTrait { y_scale: @Tensor, y_zero_point: @Tensor ) -> Tensor::; + /// # tensor.qlinear_mul + /// + /// ```rust + /// fn qlinear_mul(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, b: @Tensor, b_scale: @Tensor, b_zero_point: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor) -> Tensor::; + /// ``` + /// + /// Performs the element-wise multiplication of quantized Tensors + /// + /// It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. + /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). + /// It perfoms the element-wise multiplication of the two vectors once dequantized, then return the quantization of the result of the multiplication. + /// The broadcasting is supported + /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). + /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `a_scale`(`@Tensor`) - Scale for input `a`. + /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. + /// * `b`(`@Tensor`) - The second tensor to be multiplied + /// * `b_scale`(`@Tensor`) - Scale for input `b`. + /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. + /// * `y_scale`(`@Tensor`) - Scale for outut. + /// * `y_zero_point`(`@Tensor`) - Zero point for output. + /// + /// ## Returns + /// + /// A new `Tensor`, containing the quantized result of the element-wise multiplication of the dequantized inputs. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// + /// ## Example + /// + /// + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// ```rust + /// #[test] + /// #[available_gas(200000000000)] + /// fn qlinear_mul_example() -> Tensor{ + /// let a = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 3].span(), + /// data: array![ + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(41_u8, false), + /// IntegerTrait::::new(41_u8, false), + /// IntegerTrait::::new(41_u8, false) + /// ] + /// .span(), + /// ); + /// let b = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![1, 3].span(), + /// data: array![ + /// IntegerTrait::::new(4_u8, false), + /// IntegerTrait::::new(8_u8, false), + /// IntegerTrait::::new(12_u8, false) + /// ] + /// .span(), + /// ); + /// + /// let a_scale = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + /// ); + /// let a_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + /// let b_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + /// let b_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + /// + /// let y_scale = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(), + /// ); + /// let y_zero_point = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + /// ); + /// + /// return = a + /// .qlinear_mul( + /// @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + /// ); + /// + /// } + /// + /// >>> [[16, 23, 30], [23, 36, 50]] + /// ``` + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor::; /// # tensor.qlinear_matmul /// /// ```rust @@ -2684,6 +2808,8 @@ trait TensorTrait { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Example /// diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 6142420a8..0c0bd44d2 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -230,6 +230,30 @@ impl FP16x16Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1064c90c6..2660138f5 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -225,6 +225,19 @@ impl FP16x16WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 076d217cb..fcb717f1f 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -231,6 +231,30 @@ impl FP32x32Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 1dca0598a..0cf7a0a50 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -231,6 +231,30 @@ impl FP64x64Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 3ac08cb58..47c7a25b5 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -230,6 +230,30 @@ impl FP8x23Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index e707a4a55..39c7225cb 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -219,6 +219,19 @@ impl FP8x23WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index e0f9480e0..4173cdd6d 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -231,6 +231,30 @@ impl I32Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 9b179a93f..372d03faa 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -230,6 +230,30 @@ impl I8Tensor of TensorTrait { ) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + quantization::qlinear_mul::qlinear_mul( + self, + a_scale, + a_zero_point, + b, + b_scale, + b_zero_point, + y_scale, + y_zero_point, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index a150846ef..d3f8d0729 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -213,6 +213,19 @@ impl U32Tensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, diff --git a/src/operators/tensor/quantization.cairo b/src/operators/tensor/quantization.cairo index d27b0eccb..fcb0b57de 100644 --- a/src/operators/tensor/quantization.cairo +++ b/src/operators/tensor/quantization.cairo @@ -2,3 +2,4 @@ mod quantize_linear; mod dequantize_linear; mod qlinear_matmul; mod qlinear_add; +mod qlinear_mul; \ No newline at end of file diff --git a/src/operators/tensor/quantization/qlinear_mul.cairo b/src/operators/tensor/quantization/qlinear_mul.cairo new file mode 100644 index 000000000..d7f2cd483 --- /dev/null +++ b/src/operators/tensor/quantization/qlinear_mul.cairo @@ -0,0 +1,58 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::{NumberTrait}; +use orion::operators::tensor::quantization::dequantize_linear::dequantize_linear; +use orion::operators::tensor::quantization::quantize_linear::quantize_linear; +use orion::operators::tensor::{TensorTrait, Tensor}; + + + + +fn qlinear_mul< + T, + MAG, + Q, + impl TTensor: TensorTrait, + impl QTensor: TensorTrait, + impl QIntoT: Into, + impl QTensorIntoTTensor: Into, Tensor>, + impl TAdd: Add, + impl TSub: Sub, + impl TDiv: Div, + impl TMul: Mul, + impl TTensorAdd: Add>, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl TTensorDiv: Div>, + impl TPartialOrd: PartialOrd, + impl TNumber: NumberTrait, + impl TTryInto: TryInto, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, + impl QCopy: Copy, + impl QDrop: Drop, +>( + a: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor, + min: T, + max: T +) -> Tensor { + + let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); + let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); + + let mut x = (dequantized_a * dequantized_b).into(); + + return quantize_linear(@x, y_scale, y_zero_point, min, max); +} + + diff --git a/tests/operators.cairo b/tests/operators.cairo index 687bd30ea..514c9f878 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -1,3 +1,4 @@ mod transpose_test; mod qlinear_matmul_test; mod qlinear_add_test; +mod qlinear_mul_test; diff --git a/tests/operators/qlinear_mul_test.cairo b/tests/operators/qlinear_mul_test.cairo new file mode 100644 index 000000000..6f913dc79 --- /dev/null +++ b/tests/operators/qlinear_mul_test.cairo @@ -0,0 +1,230 @@ +use debug::PrintTrait; +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tensor, FP16x16Tensor, FP32x32Tensor +}; +use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; +use orion::numbers::{NumberTrait, IntegerTrait}; +use orion::numbers::{i8, i32}; + +#[test] +#[available_gas(200000000000)] +fn qlinearmul_test() { + let a = TensorTrait::< + i8 + >::new( + shape: array![4, 3].span(), + data: array![ + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(3_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(7_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(9_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(11_u8, false), + IntegerTrait::::new(12_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![4, 3].span(), + data: array![ + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(12_u8, false), + IntegerTrait::::new(14_u8, false), + IntegerTrait::::new(16_u8, false), + IntegerTrait::::new(18_u8, false), + IntegerTrait::::new(20_u8, false), + IntegerTrait::::new(22_u8, false), + IntegerTrait::::new(24_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(2000, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(2500, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(3000, false)].span(),); + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = a + .qlinear_mul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + + assert((*actual_output.data[0]).into() == 0, '*result[0] == 0'); + assert((*actual_output.data[1]).into() == 0, '*result[1] == 0'); + assert((*actual_output.data[2]).into() == 0, '*result[2] == 0'); + assert((*actual_output.data[3]).into() == 0, '*result[3] == 0'); + assert((*actual_output.data[4]).into() == 1, '*result[4] == 1'); + assert((*actual_output.data[5]).into() == 1, '*result[5] == 1'); + assert((*actual_output.data[6]).into() == 2, '*result[6] == 2'); + assert((*actual_output.data[7]).into() == 3, '*result[7] == 3'); + assert((*actual_output.data[8]).into() == 4, '*result[8] == 4'); + assert((*actual_output.data[9]).into() == 5, '*result[9] == 5'); + assert((*actual_output.data[10]).into() == 6, '*result[10] == 6'); + assert((*actual_output.data[11]).into() == 7, '*result[11] == 7'); + +} + + +#[test] +#[available_gas(200000000000)] +fn qlinear_mul_broadcast_test() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 4].span(), + data: array![ + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(3_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(7_u8, false), + IntegerTrait::::new(8_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![1, 4].span(), + data: array![ + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(6_u8, false), + IntegerTrait::::new(8_u8, false), + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(20000, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(25000, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(30000, false)].span(),); + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = a + .qlinear_mul(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); + + assert((*actual_output.data[0]).into() == 0, '*result[0] == 0'); + assert((*actual_output.data[1]).into() == 2, '*result[1] == 2'); + assert((*actual_output.data[2]).into() == 4, '*result[2] == 4'); + assert((*actual_output.data[3]).into() == 8, '*result[3] == 8'); + assert((*actual_output.data[4]).into() == 2, '*result[4] == 2'); + assert((*actual_output.data[5]).into() == 6, '*result[5] == 6'); + assert((*actual_output.data[6]).into() == 10, '*result[6] == 10'); + assert((*actual_output.data[7]).into() == 16, '*result[7] == 16'); +} + + +#[test] +#[available_gas(200000000000)] +fn test_example_doc() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(41_u8, false), + IntegerTrait::::new(41_u8, false), + IntegerTrait::::new(41_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![1, 3].span(), + data: array![ + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(12_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(), + ); + let y_zero_point = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); + + let actual_output = a + .qlinear_mul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + + assert((*actual_output.data[0]).into() == 16, '*result[0] == 16'); + assert((*actual_output.data[1]).into() == 23, '*result[1] == 23'); + assert((*actual_output.data[2]).into() == 30, '*result[2] == 30'); + assert((*actual_output.data[3]).into() == 23, '*result[3] == 23'); + assert((*actual_output.data[4]).into() == 36, '*result[4] == 36'); + assert((*actual_output.data[5]).into() == 50, '*result[5] == 50'); + +} + From d660f0e548d884f545254b67b782dcbe59ea042a Mon Sep 17 00:00:00 2001 From: chachaleo Date: Wed, 8 Nov 2023 21:11:59 +0700 Subject: [PATCH 018/160] feat: qlinearmal --- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.dequantize_linear.md | 2 + .../operators/tensor/tensor.qlinear_add.md | 8 +- .../operators/tensor/tensor.qlinear_matmul.md | 2 + .../operators/tensor/tensor.qlinear_mul.md | 109 ++++++++++++ src/operators/tensor/core.cairo | 10 +- .../implementations/tensor_fp16x16.cairo | 9 +- .../implementations/tensor_fp16x16wide.cairo | 10 +- .../implementations/tensor_fp32x32.cairo | 10 +- .../implementations/tensor_fp64x64.cairo | 9 +- .../implementations/tensor_fp8x23.cairo | 10 +- .../implementations/tensor_fp8x23wide.cairo | 13 +- .../tensor/implementations/tensor_i32.cairo | 8 +- .../tensor/implementations/tensor_i8.cairo | 10 +- .../tensor/implementations/tensor_u32.cairo | 8 +- src/operators/tensor/math.cairo | 2 +- src/operators/tensor/math/max.cairo | 11 +- src/operators/tensor/math/min.cairo | 11 +- src/operators/tensor/math/min_in_tensor.cairo | 4 +- src/operators/tensor/math/scatter.cairo | 156 ++++++++---------- src/operators/tensor/quantization.cairo | 2 +- .../tensor/quantization/qlinear_add.cairo | 3 - .../tensor/quantization/qlinear_mul.cairo | 4 - tests/nodes.cairo | 140 ++++++++-------- .../max_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp16x16_three_tensors.cairo | 10 +- .../max_fp16x16_three_tensors/input_0.cairo | 2 +- .../max_fp16x16_three_tensors/input_1.cairo | 2 +- .../max_fp16x16_three_tensors/input_2.cairo | 2 +- .../max_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp16x16_two_tensors.cairo | 8 +- .../max_fp16x16_two_tensors/input_0.cairo | 2 +- .../max_fp16x16_two_tensors/input_1.cairo | 2 +- .../max_fp16x16_two_tensors/output_0.cairo | 2 +- .../max_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../max_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_fp8x23_three_tensors.cairo | 10 +- .../max_fp8x23_three_tensors/input_0.cairo | 2 +- .../max_fp8x23_three_tensors/input_1.cairo | 2 +- .../max_fp8x23_three_tensors/input_2.cairo | 2 +- .../max_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/max_fp8x23_two_tensors.cairo | 8 +- .../max_fp8x23_two_tensors/input_0.cairo | 2 +- .../max_fp8x23_two_tensors/input_1.cairo | 2 +- .../max_fp8x23_two_tensors/output_0.cairo | 2 +- .../max_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i32_three_tensors.cairo | 10 +- .../nodes/max_i32_three_tensors/input_0.cairo | 2 +- .../nodes/max_i32_three_tensors/input_1.cairo | 2 +- .../nodes/max_i32_three_tensors/input_2.cairo | 2 +- .../max_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i32_two_tensors.cairo | 8 +- tests/nodes/max_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i32_two_tensors/input_1.cairo | 2 +- .../nodes/max_i32_two_tensors/output_0.cairo | 2 +- .../max_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_i8_three_tensors.cairo | 10 +- .../nodes/max_i8_three_tensors/input_0.cairo | 2 +- .../nodes/max_i8_three_tensors/input_1.cairo | 2 +- .../nodes/max_i8_three_tensors/input_2.cairo | 2 +- .../nodes/max_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/max_i8_two_tensors.cairo | 8 +- tests/nodes/max_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/max_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/max_i8_two_tensors/output_0.cairo | 2 +- .../max_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/max_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/max_u32_three_tensors.cairo | 10 +- .../nodes/max_u32_three_tensors/input_0.cairo | 2 +- .../nodes/max_u32_three_tensors/input_1.cairo | 2 +- .../nodes/max_u32_three_tensors/input_2.cairo | 2 +- .../max_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/max_u32_two_tensors.cairo | 8 +- tests/nodes/max_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/max_u32_two_tensors/input_1.cairo | 2 +- .../nodes/max_u32_two_tensors/output_0.cairo | 2 +- .../min_fp16x16_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp16x16_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp16x16_three_tensors.cairo | 10 +- .../min_fp16x16_three_tensors/input_0.cairo | 2 +- .../min_fp16x16_three_tensors/input_1.cairo | 2 +- .../min_fp16x16_three_tensors/input_2.cairo | 2 +- .../min_fp16x16_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp16x16_two_tensors.cairo | 8 +- .../min_fp16x16_two_tensors/input_0.cairo | 2 +- .../min_fp16x16_two_tensors/input_1.cairo | 2 +- .../min_fp16x16_two_tensors/output_0.cairo | 2 +- .../min_fp8x23_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../min_fp8x23_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_fp8x23_three_tensors.cairo | 10 +- .../min_fp8x23_three_tensors/input_0.cairo | 2 +- .../min_fp8x23_three_tensors/input_1.cairo | 2 +- .../min_fp8x23_three_tensors/input_2.cairo | 2 +- .../min_fp8x23_three_tensors/output_0.cairo | 2 +- tests/nodes/min_fp8x23_two_tensors.cairo | 8 +- .../min_fp8x23_two_tensors/input_0.cairo | 2 +- .../min_fp8x23_two_tensors/input_1.cairo | 2 +- .../min_fp8x23_two_tensors/output_0.cairo | 2 +- .../min_i32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i32_three_tensors.cairo | 10 +- .../nodes/min_i32_three_tensors/input_0.cairo | 2 +- .../nodes/min_i32_three_tensors/input_1.cairo | 2 +- .../nodes/min_i32_three_tensors/input_2.cairo | 2 +- .../min_i32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i32_two_tensors.cairo | 8 +- tests/nodes/min_i32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i32_two_tensors/input_1.cairo | 2 +- .../nodes/min_i32_two_tensors/output_0.cairo | 2 +- .../min_i8_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_i8_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_i8_three_tensors.cairo | 10 +- .../nodes/min_i8_three_tensors/input_0.cairo | 2 +- .../nodes/min_i8_three_tensors/input_1.cairo | 2 +- .../nodes/min_i8_three_tensors/input_2.cairo | 2 +- .../nodes/min_i8_three_tensors/output_0.cairo | 2 +- tests/nodes/min_i8_two_tensors.cairo | 8 +- tests/nodes/min_i8_two_tensors/input_0.cairo | 2 +- tests/nodes/min_i8_two_tensors/input_1.cairo | 2 +- tests/nodes/min_i8_two_tensors/output_0.cairo | 2 +- .../min_u32_broadcast_three_tensors.cairo | 10 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- .../nodes/min_u32_broadcast_two_tensors.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/min_u32_three_tensors.cairo | 10 +- .../nodes/min_u32_three_tensors/input_0.cairo | 2 +- .../nodes/min_u32_three_tensors/input_1.cairo | 2 +- .../nodes/min_u32_three_tensors/input_2.cairo | 2 +- .../min_u32_three_tensors/output_0.cairo | 2 +- tests/nodes/min_u32_two_tensors.cairo | 8 +- tests/nodes/min_u32_two_tensors/input_0.cairo | 2 +- tests/nodes/min_u32_two_tensors/input_1.cairo | 2 +- .../nodes/min_u32_two_tensors/output_0.cairo | 2 +- tests/nodes/round_fp16x16.cairo | 6 +- tests/nodes/round_fp16x16/input_0.cairo | 2 +- tests/nodes/round_fp16x16/output_0.cairo | 2 +- tests/nodes/round_fp8x23.cairo | 6 +- tests/nodes/round_fp8x23/input_0.cairo | 2 +- tests/nodes/round_fp8x23/output_0.cairo | 2 +- tests/nodes/scatter_fp16x16_3d_axis1.cairo | 18 +- .../scatter_fp16x16_3d_axis1/input_0.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_1.cairo | 2 +- .../scatter_fp16x16_3d_axis1/input_2.cairo | 2 +- .../scatter_fp16x16_3d_axis1/output_0.cairo | 2 +- .../nodes/scatter_fp16x16_3d_axis1_add.cairo | 18 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../input_2.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/scatter_fp16x16_3d_default.cairo | 18 +- .../scatter_fp16x16_3d_default/input_0.cairo | 2 +- .../scatter_fp16x16_3d_default/input_1.cairo | 2 +- .../scatter_fp16x16_3d_default/input_2.cairo | 2 +- .../scatter_fp16x16_3d_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_axis1.cairo | 18 +- .../nodes/scatter_fp8x23_axis1/input_0.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_1.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/input_2.cairo | 2 +- .../nodes/scatter_fp8x23_axis1/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_default.cairo | 18 +- .../scatter_fp8x23_default/input_0.cairo | 2 +- .../scatter_fp8x23_default/input_1.cairo | 2 +- .../scatter_fp8x23_default/input_2.cairo | 2 +- .../scatter_fp8x23_default/output_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul.cairo | 18 +- tests/nodes/scatter_fp8x23_mul/input_0.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_1.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/input_2.cairo | 2 +- tests/nodes/scatter_fp8x23_mul/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1.cairo | 18 +- tests/nodes/scatter_i8_axis1/input_0.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_1.cairo | 2 +- tests/nodes/scatter_i8_axis1/input_2.cairo | 2 +- tests/nodes/scatter_i8_axis1/output_0.cairo | 2 +- tests/nodes/scatter_i8_axis1_max.cairo | 18 +- .../nodes/scatter_i8_axis1_max/input_0.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_1.cairo | 2 +- .../nodes/scatter_i8_axis1_max/input_2.cairo | 2 +- .../nodes/scatter_i8_axis1_max/output_0.cairo | 2 +- tests/nodes/scatter_i8_default.cairo | 18 +- tests/nodes/scatter_i8_default/input_0.cairo | 2 +- tests/nodes/scatter_i8_default/input_1.cairo | 2 +- tests/nodes/scatter_i8_default/input_2.cairo | 2 +- tests/nodes/scatter_i8_default/output_0.cairo | 2 +- tests/nodes/scatter_u32_add.cairo | 18 +- tests/nodes/scatter_u32_add/input_0.cairo | 2 +- tests/nodes/scatter_u32_add/input_1.cairo | 2 +- tests/nodes/scatter_u32_add/input_2.cairo | 2 +- tests/nodes/scatter_u32_add/output_0.cairo | 2 +- tests/nodes/scatter_u32_axis1.cairo | 18 +- tests/nodes/scatter_u32_axis1/input_0.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_1.cairo | 2 +- tests/nodes/scatter_u32_axis1/input_2.cairo | 2 +- tests/nodes/scatter_u32_axis1/output_0.cairo | 2 +- tests/nodes/scatter_u32_default.cairo | 18 +- tests/nodes/scatter_u32_default/input_0.cairo | 2 +- tests/nodes/scatter_u32_default/input_1.cairo | 2 +- tests/nodes/scatter_u32_default/input_2.cairo | 2 +- .../nodes/scatter_u32_default/output_0.cairo | 2 +- tests/operators/qlinear_add_test.cairo | 20 ++- tests/operators/qlinear_mul_test.cairo | 12 +- 272 files changed, 882 insertions(+), 674 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.qlinear_mul.md diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 1a343debd..ad50c3dac 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -80,6 +80,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.quantize_linear`](tensor.quantize\_linear.md) | Quantizes a Tensor to i8 using linear quantization. | | [`tensor.dequantize_linear`](tensor.dequantize\_linear.md) | Dequantizes an i8 Tensor using linear dequantization. | | [`tensor.qlinear_add`](tensor.qlinear\_add.md) | Performs the sum of two quantized i8 Tensors. | +| [`tensor.qlinear_mul`](tensor.qlinear\_mul.md) | Performs the element-wise multiplication of two quantized i8 Tensors. | | [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. | | [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. | | [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). | diff --git a/docs/framework/operators/tensor/tensor.dequantize_linear.md b/docs/framework/operators/tensor/tensor.dequantize_linear.md index c3476f9c2..38635349b 100644 --- a/docs/framework/operators/tensor/tensor.dequantize_linear.md +++ b/docs/framework/operators/tensor/tensor.dequantize_linear.md @@ -24,6 +24,8 @@ A new `Tensor` with the same shape as the input tensor, containing the dequan ## Type Constraints u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. ## Examples diff --git a/docs/framework/operators/tensor/tensor.qlinear_add.md b/docs/framework/operators/tensor/tensor.qlinear_add.md index b65eab60a..998ddd214 100644 --- a/docs/framework/operators/tensor/tensor.qlinear_add.md +++ b/docs/framework/operators/tensor/tensor.qlinear_add.md @@ -8,17 +8,17 @@ Performs the sum of quantized Tensors It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. The quantization formula is y = saturate((x / y_scale) + y_zero_point). -It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the multiplication. +It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the addition. The broadcasting is supported Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. ## Args -* `self`(`@Tensor`) - The first tensor to be multiplied (a). +* `self`(`@Tensor`) - The first tensor to be additionned (a). * `a_scale`(`@Tensor`) - Scale for input `a`. * `a_zero_point`(`@Tensor`) - Zero point for input `a`. -* `b`(`@Tensor`) - The second tensor to be multiplied +* `b`(`@Tensor`) - The second tensor to be additionned * `b_scale`(`@Tensor`) - Scale for input `b`. * `b_zero_point`(`@Tensor`) - Zero point for input `b`. * `y_scale`(`@Tensor`) - Scale for outut. @@ -31,6 +31,8 @@ A new `Tensor`, containing the quantized result of the addition of the dequa ## Type Constraints u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. ## Example diff --git a/docs/framework/operators/tensor/tensor.qlinear_matmul.md b/docs/framework/operators/tensor/tensor.qlinear_matmul.md index df66f92e4..1ab4853f9 100644 --- a/docs/framework/operators/tensor/tensor.qlinear_matmul.md +++ b/docs/framework/operators/tensor/tensor.qlinear_matmul.md @@ -31,6 +31,8 @@ A new `Tensor`, containing the quantized result of the multiplication of the ## Type Constraints u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. ## Example diff --git a/docs/framework/operators/tensor/tensor.qlinear_mul.md b/docs/framework/operators/tensor/tensor.qlinear_mul.md new file mode 100644 index 000000000..d773b9b19 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.qlinear_mul.md @@ -0,0 +1,109 @@ +# tensor.qlinear_mul + +```rust + fn qlinear_mul(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, b: @Tensor, b_scale: @Tensor, b_zero_point: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor) -> Tensor::; +``` + +Performs the element-wise multiplication of quantized Tensors + +It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. +The quantization formula is y = saturate((x / y_scale) + y_zero_point). +It perfoms the element-wise multiplication of the two vectors once dequantized, then return the quantization of the result of the multiplication. +The broadcasting is supported +Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). +Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + +## Args + +* `self`(`@Tensor`) - The first tensor to be multiplied (a). +* `a_scale`(`@Tensor`) - Scale for input `a`. +* `a_zero_point`(`@Tensor`) - Zero point for input `a`. +* `b`(`@Tensor`) - The second tensor to be multiplied +* `b_scale`(`@Tensor`) - Scale for input `b`. +* `b_zero_point`(`@Tensor`) - Zero point for input `b`. +* `y_scale`(`@Tensor`) - Scale for outut. +* `y_zero_point`(`@Tensor`) - Zero point for output. + +## Returns + +A new `Tensor`, containing the quantized result of the element-wise multiplication of the dequantized inputs. + +## Type Constraints + +u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. + +## Example + + +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; +use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + +```rust +#[test] +#[available_gas(200000000000)] +fn qlinear_mul_example() -> Tensor{ + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(21_u8, false), + IntegerTrait::::new(41_u8, false), + IntegerTrait::::new(41_u8, false), + IntegerTrait::::new(41_u8, false) + ] + .span(), + ); + let b = TensorTrait::< + i8 + >::new( + shape: array![1, 3].span(), + data: array![ + IntegerTrait::::new(4_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(12_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let b_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + let b_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let y_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(), + ); + let y_zero_point = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); + + return = a + .qlinear_mul( + @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + ); + +} + +>>> [[16, 23, 30], [23, 36, 50]] +``` \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 233d2fca3..b3853b47f 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3365,7 +3365,7 @@ trait TensorTrait { /// /// ## Example /// - /// ```rust + /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// /// use orion::operators::tensor::{TensorTrait, Tensor, FP16x16Tensor}; @@ -3449,7 +3449,13 @@ trait TensorTrait { /// [ 4, 0, 3, 0, 0]] /// ``` /// - fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 0c0bd44d2..b816c0e88 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -331,11 +331,14 @@ impl FP16x16Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 2660138f5..f3d2afe98 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -307,9 +307,13 @@ impl FP16x16WTensor of TensorTrait { math::round::round(*self) } - fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + fn scatter( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index fcb717f1f..a58c9df80 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -329,11 +329,15 @@ impl FP32x32Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 0cf7a0a50..f5c9a63d0 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -332,11 +332,14 @@ impl FP64x64Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 47c7a25b5..f34f40506 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -331,9 +331,13 @@ impl FP8x23Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { - math::scatter::scatter(self, updates, indices, axis, reduction) + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { + math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 39c7225cb..380b9393e 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -293,17 +293,20 @@ impl FP8x23WTensor of TensorTrait { math::where::where(self, x, y) } - fn round(self: @Tensor) -> Tensor { + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } - -} +} /// Implements addition for `Tensor` using the `Add` trait. impl FP8x23WTensorAdd< diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 4173cdd6d..6eb4e95b8 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -331,8 +331,12 @@ impl I32Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 372d03faa..4b1c16116 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -327,11 +327,15 @@ impl I8Tensor of TensorTrait { fn round(self: @Tensor) -> Tensor { math::round::round(*self) - } + } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index d3f8d0729..adaa19957 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -290,8 +290,12 @@ impl U32Tensor of TensorTrait { } fn scatter( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) - -> Tensor { + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option + ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 79404dcd5..0aaa3f459 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -38,4 +38,4 @@ mod and; mod neg; mod where; mod round; -mod scatter; \ No newline at end of file +mod scatter; diff --git a/src/operators/tensor/math/max.cairo b/src/operators/tensor/math/max.cairo index 5ed703408..8052733d7 100644 --- a/src/operators/tensor/math/max.cairo +++ b/src/operators/tensor/math/max.cairo @@ -17,7 +17,6 @@ fn max< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn max< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(max_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut max_value = NumberTrait::max(*(max_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut max_value = NumberTrait::max( + *(max_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_max_data.append(max_value); n += 1; @@ -65,4 +68,4 @@ fn max< }; return TensorTrait::::new(max_shape, max_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min.cairo b/src/operators/tensor/math/min.cairo index 3577e69c0..61140f89d 100644 --- a/src/operators/tensor/math/min.cairo +++ b/src/operators/tensor/math/min.cairo @@ -17,7 +17,6 @@ fn min< >( tensors: Span> ) -> Tensor { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); let first_tensor = *tensors.at(0); @@ -48,9 +47,13 @@ fn min< let mut indices_broadcasted = unravel_index(n, broadcasted_shape); let mut indices_self = broadcast_index_mapping(min_shape, indices_broadcasted); - let mut indices_other = broadcast_index_mapping(current_tensor.shape, indices_broadcasted); + let mut indices_other = broadcast_index_mapping( + current_tensor.shape, indices_broadcasted + ); - let mut min_value = NumberTrait::min(*(min_data)[indices_self], *(current_tensor.data)[indices_other]); + let mut min_value = NumberTrait::min( + *(min_data)[indices_self], *(current_tensor.data)[indices_other] + ); new_min_data.append(min_value); n += 1; @@ -65,4 +68,4 @@ fn min< }; return TensorTrait::::new(min_shape, min_data); -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/min_in_tensor.cairo b/src/operators/tensor/math/min_in_tensor.cairo index b9738db1f..e52f4a227 100644 --- a/src/operators/tensor/math/min_in_tensor.cairo +++ b/src/operators/tensor/math/min_in_tensor.cairo @@ -24,9 +24,7 @@ fn min_in_tensor< min_value = check_min; } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/scatter.cairo b/src/operators/tensor/math/scatter.cairo index ea26f1b7e..bcd15c36d 100644 --- a/src/operators/tensor/math/scatter.cairo +++ b/src/operators/tensor/math/scatter.cairo @@ -14,9 +14,21 @@ use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; use dict::Felt252DictTrait; use nullable::{nullable_from_box, match_nullable, FromNullableResult}; /// Cf: TensorTrait::scatter docstring -fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDrop: Drop, impl TAddEq: AddEq, - impl TMulEq: MulEq, impl TPartialOrd: PartialOrd, impl TPartialEq: PartialEq,>( - self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option +fn scatter< + T, + impl TTensorTrait: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop, + impl TAddEq: AddEq, + impl TMulEq: MulEq, + impl TPartialOrd: PartialOrd, + impl TPartialEq: PartialEq, +>( + self: @Tensor, + updates: Tensor, + indices: Tensor, + axis: Option, + reduction: Option ) -> Tensor { let mut axis = match axis { Option::Some(val) => val, @@ -40,7 +52,10 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_shape = *self.shape; let mut indices_shape = indices.shape; let updates_shape = updates.shape; - assert((*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), 'shape must be same'); + assert( + (*indices_shape[0] == *updates_shape[0]) & (*indices_shape[1] == *updates_shape[1]), + 'shape must be same' + ); let mut output_data = ArrayTrait::new(); let mut data_indices = indices.data; @@ -54,31 +69,27 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let data_loop_first = *data_shape_copy.pop_front().unwrap(); let indices_loop_first = *indices_shape_copy.pop_front().unwrap(); - let mut indices_loop: usize = 1; - let mut data_loop:usize = 1; + let mut indices_loop: usize = 1; + let mut data_loop: usize = 1; if (axis == 0) { loop { match indices_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - indices_loop *= *val; + Option::Some(val) => { + let d = *val; + indices_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - loop { + loop { match data_shape_copy.pop_front() { - Option::Some(val) => { - let d = *val; - data_loop *= *val; + Option::Some(val) => { + let d = *val; + data_loop *= *val; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; } @@ -93,8 +104,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro axis = 2; transpose = true; } - - if (axis == (data_rank - 1) ){ + + if (axis == (data_rank - 1)) { data_loop = *data_shape_copy.pop_back().unwrap(); indices_loop = *indices_shape_copy.pop_back().unwrap(); } @@ -104,24 +115,26 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { let mut i: usize = 0; - let mut result:usize = 0; + let mut result: usize = 0; match data_indices.pop_front() { Option::Some(val) => { - let value = total_count+1; + let value = total_count + 1; if (axis == 0) { let column = total_count % indices_loop; result = (*val * data_loop) + (column); - if ((result % *data_shape.at(data_rank -1)) != total_count % *indices_shape.at(data_rank -1)){ - result += (*data_shape.at(data_rank -1) - *indices_shape.at(data_rank -1)); + if ((result % *data_shape.at(data_rank - 1)) != total_count % *indices_shape + .at(data_rank - 1)) { + result += + (*data_shape.at(data_rank - 1) - *indices_shape.at(data_rank - 1)); } } - if( axis == (data_rank - 1)) { + if (axis == (data_rank - 1)) { let mut row = total_count / indices_loop; - if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))){ - shift = ( *data_shape.at(1) - *indices_shape.at(1)); + if ((data_rank > 2) & (row % *data_shape.at(1) >= *indices_shape.at(1))) { + shift = (*data_shape.at(1) - *indices_shape.at(1)); } result = *val + (data_loop * (row + shift)); @@ -129,8 +142,7 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'none') { indices_updates.insert(result.into(), value.into()); - } - else { + } else { let mut arr = ArrayTrait::new(); let val = indices_updates_reduction.get(result.into()); @@ -142,22 +154,17 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro loop { match span.pop_front() { - Option::Some(val) => { - arr.append(*val); - }, - Option::None(_) => { - break; - } + Option::Some(val) => { arr.append(*val); }, + Option::None(_) => { break; } }; }; arr.append(total_count); - indices_updates_reduction.insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); + indices_updates_reduction + .insert(result.into(), nullable_from_box(BoxTrait::new(arr.span()))); } total_count += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; @@ -170,13 +177,11 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro let value = indices_updates.get(i.into()); if (value == 0) { output_data.append(*val); - } - else { - let data_value = data_updates[value-1]; + } else { + let data_value = data_updates[value - 1]; output_data.append(*data_value); } - } - else { + } else { let value = indices_updates_reduction.get(i.into()); let mut a = ArrayTrait::new(); let mut span = match match_nullable(value) { @@ -186,22 +191,15 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (span.len() == 0) { output_data.append(*val); - } - - else { + } else { // let mut result = *data_updates.at(*span.pop_front().unwrap()); let mut result = *val; - if (reduction == 'add') { loop { match span.pop_front() { - Option::Some(val) => { - result += *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result += *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -210,12 +208,8 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'mul') { loop { match span.pop_front() { - Option::Some(val) => { - result *= *data_updates[*val]; - }, - Option::None(_) => { - break; - } + Option::Some(val) => { result *= *data_updates[*val]; }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -224,15 +218,13 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'max') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder > result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder > result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); @@ -241,27 +233,23 @@ fn scatter< T, impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDro if (reduction == 'min') { loop { match span.pop_front() { - Option::Some(val) => { - let holder = *data_updates[*val]; - if (holder < result){ - result = holder; - } - }, - Option::None(_) => { - break; - } + Option::Some(val) => { + let holder = *data_updates[*val]; + if (holder < result) { + result = holder; + } + }, + Option::None(_) => { break; } }; }; output_data.append(result); } } } - - i+=1; + + i += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/quantization.cairo b/src/operators/tensor/quantization.cairo index fcb0b57de..d0fa3963b 100644 --- a/src/operators/tensor/quantization.cairo +++ b/src/operators/tensor/quantization.cairo @@ -2,4 +2,4 @@ mod quantize_linear; mod dequantize_linear; mod qlinear_matmul; mod qlinear_add; -mod qlinear_mul; \ No newline at end of file +mod qlinear_mul; diff --git a/src/operators/tensor/quantization/qlinear_add.cairo b/src/operators/tensor/quantization/qlinear_add.cairo index 7f9f3eaa1..1574e8fd8 100644 --- a/src/operators/tensor/quantization/qlinear_add.cairo +++ b/src/operators/tensor/quantization/qlinear_add.cairo @@ -8,8 +8,6 @@ use orion::operators::tensor::quantization::quantize_linear::quantize_linear; use orion::operators::tensor::{TensorTrait, Tensor}; - - fn qlinear_add< T, MAG, @@ -46,7 +44,6 @@ fn qlinear_add< min: T, max: T ) -> Tensor { - let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); diff --git a/src/operators/tensor/quantization/qlinear_mul.cairo b/src/operators/tensor/quantization/qlinear_mul.cairo index d7f2cd483..fcd005218 100644 --- a/src/operators/tensor/quantization/qlinear_mul.cairo +++ b/src/operators/tensor/quantization/qlinear_mul.cairo @@ -8,8 +8,6 @@ use orion::operators::tensor::quantization::quantize_linear::quantize_linear; use orion::operators::tensor::{TensorTrait, Tensor}; - - fn qlinear_mul< T, MAG, @@ -46,7 +44,6 @@ fn qlinear_mul< min: T, max: T ) -> Tensor { - let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); let mut dequantized_b = dequantize_linear(@(*b), b_scale, b_zero_point); @@ -55,4 +52,3 @@ fn qlinear_mul< return quantize_linear(@x, y_scale, y_zero_point, min, max); } - diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..f68cfac54 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -448,42 +448,42 @@ mod identity_fP8x23; mod identity_i32; mod identity_i8; mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; mod where_fp16x16; mod where_fp16x16_broadcast; mod where_fp8x23; @@ -494,37 +494,37 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo index 2660e4676..e6a9a5db0 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo index fc8d87773..15950d596 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo index 352adab6a..ad2c130c9 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo index b743e5482..2a9d359fe 100644 --- a/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo index b5ac6fdcd..b738aeee5 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo index 92152cd37..8caad904d 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo index 4cc6309d7..369a5c13f 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo index 37ead1117..e47fcecfe 100644 --- a/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors.cairo b/tests/nodes/max_fp16x16_three_tensors.cairo index 8ca7dfebe..c81211037 100644 --- a/tests/nodes/max_fp16x16_three_tensors.cairo +++ b/tests/nodes/max_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp16x16_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo index bb6a7efe8..33bfc9dac 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo index 71edb4da9..4690905db 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo index 9845fefbe..51a6c9f52 100644 --- a/tests/nodes/max_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo index 139ae932a..d8b8ce390 100644 --- a/tests/nodes/max_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors.cairo b/tests/nodes/max_fp16x16_two_tensors.cairo index 98b522b3d..cdf7e83e6 100644 --- a/tests/nodes/max_fp16x16_two_tensors.cairo +++ b/tests/nodes/max_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp16x16_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo index 1e70f825c..368a064d7 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo index c766b1157..fe6280643 100644 --- a/tests/nodes/max_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo index 66b666290..07fd7443c 100644 --- a/tests/nodes/max_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo index 2fdd60ff2..ab1082160 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo index 2fa35f877..1de6875da 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo index fdcd11d36..3941d2b7e 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo index 4a9a3a6e3..e17548190 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo index 78bcbc1ed..10e0960d6 100644 --- a/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo index b40477513..b77fbfbf6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo index 89cffdd5e..132278138 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo index 297233473..27a35e3b1 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo index 0506f1c0f..e7d95b6f6 100644 --- a/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors.cairo b/tests/nodes/max_fp8x23_three_tensors.cairo index d5cc6b030..b503bf177 100644 --- a/tests/nodes/max_fp8x23_three_tensors.cairo +++ b/tests/nodes/max_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_fp8x23_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo index f0f1d9253..5d8539d1d 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo index f4611bf3c..2e4abdf49 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo index 6eeb29edb..b51cf0f13 100644 --- a/tests/nodes/max_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo index e0318aad1..ebb70503a 100644 --- a/tests/nodes/max_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors.cairo b/tests/nodes/max_fp8x23_two_tensors.cairo index b54d193d6..8d5ca3c74 100644 --- a/tests/nodes/max_fp8x23_two_tensors.cairo +++ b/tests/nodes/max_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_fp8x23_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo index 038c7c361..d16c6a053 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo index da45b3378..a766fbb91 100644 --- a/tests/nodes/max_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo index 797bfa996..86eaeb478 100644 --- a/tests/nodes/max_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/max_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors.cairo b/tests/nodes/max_i32_broadcast_three_tensors.cairo index af4660c1d..91476cad9 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo index 1c894ed65..36c7bbba6 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo index d4cfc3152..f8f8fbca4 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo index 5494fd3b3..f997397d7 100644 --- a/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors.cairo b/tests/nodes/max_i32_broadcast_two_tensors.cairo index 25d864bba..63f46ff9f 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo index 65fc1651c..47591a648 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo index b75480afa..f2b5abec2 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo index ffc6f4c24..5fa192944 100644 --- a/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors.cairo b/tests/nodes/max_i32_three_tensors.cairo index 186d5e2c5..c72a56cdf 100644 --- a/tests/nodes/max_i32_three_tensors.cairo +++ b/tests/nodes/max_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_0.cairo b/tests/nodes/max_i32_three_tensors/input_0.cairo index e5fdee508..be1f3c151 100644 --- a/tests/nodes/max_i32_three_tensors/input_0.cairo +++ b/tests/nodes/max_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_1.cairo b/tests/nodes/max_i32_three_tensors/input_1.cairo index 960743a74..778aba1a0 100644 --- a/tests/nodes/max_i32_three_tensors/input_1.cairo +++ b/tests/nodes/max_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/input_2.cairo b/tests/nodes/max_i32_three_tensors/input_2.cairo index f90517109..00a20e43b 100644 --- a/tests/nodes/max_i32_three_tensors/input_2.cairo +++ b/tests/nodes/max_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_three_tensors/output_0.cairo b/tests/nodes/max_i32_three_tensors/output_0.cairo index 376bd0a58..10d697501 100644 --- a/tests/nodes/max_i32_three_tensors/output_0.cairo +++ b/tests/nodes/max_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors.cairo b/tests/nodes/max_i32_two_tensors.cairo index 18678b57e..c2ddc1b51 100644 --- a/tests/nodes/max_i32_two_tensors.cairo +++ b/tests/nodes/max_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/input_0.cairo b/tests/nodes/max_i32_two_tensors/input_0.cairo index 59ba3b966..0c5e37593 100644 --- a/tests/nodes/max_i32_two_tensors/input_0.cairo +++ b/tests/nodes/max_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/input_1.cairo b/tests/nodes/max_i32_two_tensors/input_1.cairo index 6615ef39a..efd1ec5a2 100644 --- a/tests/nodes/max_i32_two_tensors/input_1.cairo +++ b/tests/nodes/max_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i32_two_tensors/output_0.cairo b/tests/nodes/max_i32_two_tensors/output_0.cairo index 7eded96da..31eca8b5f 100644 --- a/tests/nodes/max_i32_two_tensors/output_0.cairo +++ b/tests/nodes/max_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors.cairo b/tests/nodes/max_i8_broadcast_three_tensors.cairo index 65ea53cc9..d73af1f9e 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo index 80c86eb24..6569361bf 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo index 05fe8ff14..4f71b1d6f 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo index 381efaf32..ba14221ab 100644 --- a/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 1, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors.cairo b/tests/nodes/max_i8_broadcast_two_tensors.cairo index 6a2f8b42f..af4a99d9f 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo index ea28aa087..ab27c2d6a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo index e029fbc53..7ddca8ad7 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo index 273837ef7..11068ef7a 100644 --- a/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors.cairo b/tests/nodes/max_i8_three_tensors.cairo index 40b83fbcc..b88c9459b 100644 --- a/tests/nodes/max_i8_three_tensors.cairo +++ b/tests/nodes/max_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_i8_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_0.cairo b/tests/nodes/max_i8_three_tensors/input_0.cairo index 07fbd1690..69d671087 100644 --- a/tests/nodes/max_i8_three_tensors/input_0.cairo +++ b/tests/nodes/max_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_1.cairo b/tests/nodes/max_i8_three_tensors/input_1.cairo index 47afadf00..67ba2e3ed 100644 --- a/tests/nodes/max_i8_three_tensors/input_1.cairo +++ b/tests/nodes/max_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/input_2.cairo b/tests/nodes/max_i8_three_tensors/input_2.cairo index e37ded791..ab0f01d88 100644 --- a/tests/nodes/max_i8_three_tensors/input_2.cairo +++ b/tests/nodes/max_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_three_tensors/output_0.cairo b/tests/nodes/max_i8_three_tensors/output_0.cairo index 5814fe790..4f7334f20 100644 --- a/tests/nodes/max_i8_three_tensors/output_0.cairo +++ b/tests/nodes/max_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors.cairo b/tests/nodes/max_i8_two_tensors.cairo index 9f6ee682d..d3ad09730 100644 --- a/tests/nodes/max_i8_two_tensors.cairo +++ b/tests/nodes/max_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_i8_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_0.cairo b/tests/nodes/max_i8_two_tensors/input_0.cairo index ec6c88799..0d4c5397e 100644 --- a/tests/nodes/max_i8_two_tensors/input_0.cairo +++ b/tests/nodes/max_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/input_1.cairo b/tests/nodes/max_i8_two_tensors/input_1.cairo index bc48996a9..55509fb6d 100644 --- a/tests/nodes/max_i8_two_tensors/input_1.cairo +++ b/tests/nodes/max_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_i8_two_tensors/output_0.cairo b/tests/nodes/max_i8_two_tensors/output_0.cairo index 889fc62c1..4025af717 100644 --- a/tests/nodes/max_i8_two_tensors/output_0.cairo +++ b/tests/nodes/max_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors.cairo b/tests/nodes/max_u32_broadcast_three_tensors.cairo index a378bd9a7..241a2fc8f 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_broadcast_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo index 108d66672..6c083ffa7 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(2); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo index a904f4e58..ea8734bae 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo index ab0ca7fb6..68dfae000 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo index 0f21da101..a0bd55df8 100644 --- a/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors.cairo b/tests/nodes/max_u32_broadcast_two_tensors.cairo index ddcd35e04..b32369429 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_broadcast_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo index e7dcaeaf3..9e24dfb3b 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo index b09e9c973..19d7a2a17 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo index 8354b7151..71b7b07b4 100644 --- a/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors.cairo b/tests/nodes/max_u32_three_tensors.cairo index 655f2a713..c8fb9dfe1 100644 --- a/tests/nodes/max_u32_three_tensors.cairo +++ b/tests/nodes/max_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_max_u32_three_tensors() { let y = TensorTrait::max(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_0.cairo b/tests/nodes/max_u32_three_tensors/input_0.cairo index e428995ce..15d5eb226 100644 --- a/tests/nodes/max_u32_three_tensors/input_0.cairo +++ b/tests/nodes/max_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(0); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_1.cairo b/tests/nodes/max_u32_three_tensors/input_1.cairo index edb019a72..5e8843449 100644 --- a/tests/nodes/max_u32_three_tensors/input_1.cairo +++ b/tests/nodes/max_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/input_2.cairo b/tests/nodes/max_u32_three_tensors/input_2.cairo index cdd6dd700..220491901 100644 --- a/tests/nodes/max_u32_three_tensors/input_2.cairo +++ b/tests/nodes/max_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_three_tensors/output_0.cairo b/tests/nodes/max_u32_three_tensors/output_0.cairo index b8b2b72aa..75fb08e26 100644 --- a/tests/nodes/max_u32_three_tensors/output_0.cairo +++ b/tests/nodes/max_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(4); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors.cairo b/tests/nodes/max_u32_two_tensors.cairo index faed3d640..b4fbf9e02 100644 --- a/tests/nodes/max_u32_two_tensors.cairo +++ b/tests/nodes/max_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_max_u32_two_tensors() { let y = TensorTrait::max(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_0.cairo b/tests/nodes/max_u32_two_tensors/input_0.cairo index dde213565..6f1f617cd 100644 --- a/tests/nodes/max_u32_two_tensors/input_0.cairo +++ b/tests/nodes/max_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/input_1.cairo b/tests/nodes/max_u32_two_tensors/input_1.cairo index bdd40bb01..131ad4f0f 100644 --- a/tests/nodes/max_u32_two_tensors/input_1.cairo +++ b/tests/nodes/max_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(2); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/max_u32_two_tensors/output_0.cairo b/tests/nodes/max_u32_two_tensors/output_0.cairo index e585ea8dc..4e935e3ea 100644 --- a/tests/nodes/max_u32_two_tensors/output_0.cairo +++ b/tests/nodes/max_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo index c71edce86..220395f62 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo index bf27fbdf0..4589ab5de 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo index 406f91365..903d76d4d 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo index 98ef140fa..8bb4c575b 100644 --- a/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo index 3b998ca1a..9a2d7a980 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo index c1c0930a4..2cccefb8a 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo index d7359bc64..fc6569745 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo index 0e8b2aebb..e6fd1bcce 100644 --- a/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors.cairo b/tests/nodes/min_fp16x16_three_tensors.cairo index 8a5d60711..5501d9f70 100644 --- a/tests/nodes/min_fp16x16_three_tensors.cairo +++ b/tests/nodes/min_fp16x16_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp16x16_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo index 747696a57..b5db9e4f1 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo index 22d5848ef..4aa7ab102 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo index 02084123c..1488424a5 100644 --- a/tests/nodes/min_fp16x16_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo index 6931f714a..6db8c5c68 100644 --- a/tests/nodes/min_fp16x16_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors.cairo b/tests/nodes/min_fp16x16_two_tensors.cairo index 25adc490e..a0c99e5a5 100644 --- a/tests/nodes/min_fp16x16_two_tensors.cairo +++ b/tests/nodes/min_fp16x16_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp16x16_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo index 3cc3af9cb..c827d6229 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo index 230c3bfd0..9f62c5305 100644 --- a/tests/nodes/min_fp16x16_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo index 785211ceb..9e4c65919 100644 --- a/tests/nodes/min_fp16x16_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp16x16_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo index 2596fabad..7a66521a5 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo index c5eee64f3..f45ededce 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo index 5ddfee383..709d521a4 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo index 87ac9a1aa..5759d134b 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/input_2.cairo @@ -12,4 +12,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo index 6a9b1f878..3b2410704 100644 --- a/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_three_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo index b231c5d76..babc5664d 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo index 06a77989a..764036b1c 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_0.cairo @@ -15,4 +15,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo index 538d00e70..35cf05e4e 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/input_1.cairo @@ -13,4 +13,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo index dbb598ae0..6279adb4a 100644 --- a/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_broadcast_two_tensors/output_0.cairo @@ -15,4 +15,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors.cairo b/tests/nodes/min_fp8x23_three_tensors.cairo index 676f8f312..9a4880f3e 100644 --- a/tests/nodes/min_fp8x23_three_tensors.cairo +++ b/tests/nodes/min_fp8x23_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_fp8x23_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo index 9716ed3b9..1a1046aa6 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo index 49311a2b0..a90022ac9 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo index 9b8b0650e..87a644d4e 100644 --- a/tests/nodes/min_fp8x23_three_tensors/input_2.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/input_2.cairo @@ -39,4 +39,4 @@ fn input_2() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo index af08ef421..15f4b94ea 100644 --- a/tests/nodes/min_fp8x23_three_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_three_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors.cairo b/tests/nodes/min_fp8x23_two_tensors.cairo index 01d2724ea..dbc7345e4 100644 --- a/tests/nodes/min_fp8x23_two_tensors.cairo +++ b/tests/nodes/min_fp8x23_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_fp8x23_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo index 293eb3e83..e0caca041 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo index 76f71b638..3eb98567d 100644 --- a/tests/nodes/min_fp8x23_two_tensors/input_1.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/input_1.cairo @@ -39,4 +39,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo index c0e8bbc56..89214df41 100644 --- a/tests/nodes/min_fp8x23_two_tensors/output_0.cairo +++ b/tests/nodes/min_fp8x23_two_tensors/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors.cairo b/tests/nodes/min_i32_broadcast_three_tensors.cairo index 74ad7c090..e1eb8036b 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo index 3ffb54363..df439f61e 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo index 97515f83e..b1b65261f 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo index 2573224ed..edb64de85 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo index 3031cb2bf..a81378685 100644 --- a/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors.cairo b/tests/nodes/min_i32_broadcast_two_tensors.cairo index 43e5f99e0..56f474b6d 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo index b9cd5f819..324736c63 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo index ab5754cf2..bf2fecba4 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo index fa1f29299..9728ec700 100644 --- a/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors.cairo b/tests/nodes/min_i32_three_tensors.cairo index adb4350db..332b00c62 100644 --- a/tests/nodes/min_i32_three_tensors.cairo +++ b/tests/nodes/min_i32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_0.cairo b/tests/nodes/min_i32_three_tensors/input_0.cairo index a255474d1..d7c51ab8d 100644 --- a/tests/nodes/min_i32_three_tensors/input_0.cairo +++ b/tests/nodes/min_i32_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_1.cairo b/tests/nodes/min_i32_three_tensors/input_1.cairo index 33568613e..0c25e152d 100644 --- a/tests/nodes/min_i32_three_tensors/input_1.cairo +++ b/tests/nodes/min_i32_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/input_2.cairo b/tests/nodes/min_i32_three_tensors/input_2.cairo index 9b822fc6d..f8d3071be 100644 --- a/tests/nodes/min_i32_three_tensors/input_2.cairo +++ b/tests/nodes/min_i32_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_three_tensors/output_0.cairo b/tests/nodes/min_i32_three_tensors/output_0.cairo index 9b0a9b23a..3f93c789b 100644 --- a/tests/nodes/min_i32_three_tensors/output_0.cairo +++ b/tests/nodes/min_i32_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors.cairo b/tests/nodes/min_i32_two_tensors.cairo index ae444f6e7..36bff1cd3 100644 --- a/tests/nodes/min_i32_two_tensors.cairo +++ b/tests/nodes/min_i32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_0.cairo b/tests/nodes/min_i32_two_tensors/input_0.cairo index 518ef5c24..53c2fcaa5 100644 --- a/tests/nodes/min_i32_two_tensors/input_0.cairo +++ b/tests/nodes/min_i32_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 5, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/input_1.cairo b/tests/nodes/min_i32_two_tensors/input_1.cairo index 42bdad0c9..92a12ff67 100644 --- a/tests/nodes/min_i32_two_tensors/input_1.cairo +++ b/tests/nodes/min_i32_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i32_two_tensors/output_0.cairo b/tests/nodes/min_i32_two_tensors/output_0.cairo index af1b203d5..d3e493a26 100644 --- a/tests/nodes/min_i32_two_tensors/output_0.cairo +++ b/tests/nodes/min_i32_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors.cairo b/tests/nodes/min_i8_broadcast_three_tensors.cairo index 4b67ffc7d..2256c0b62 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo index 254b04d0a..031cd3791 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo index 4fc8ae5a6..b7f890f64 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo index f472bb1d6..72888bf4c 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/input_2.cairo @@ -11,4 +11,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 4, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo index 9e4345995..289d4ad87 100644 --- a/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_three_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors.cairo b/tests/nodes/min_i8_broadcast_two_tensors.cairo index a533c5930..d6344af77 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo index 563c07736..0966277be 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo index 060e0a9ec..1748d763f 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/input_1.cairo @@ -12,4 +12,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo index 86ec9707b..8bedae7e1 100644 --- a/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_broadcast_two_tensors/output_0.cairo @@ -14,4 +14,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors.cairo b/tests/nodes/min_i8_three_tensors.cairo index cee72024b..5d41e2551 100644 --- a/tests/nodes/min_i8_three_tensors.cairo +++ b/tests/nodes/min_i8_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_i8_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_0.cairo b/tests/nodes/min_i8_three_tensors/input_0.cairo index 92635527e..d29670a9f 100644 --- a/tests/nodes/min_i8_three_tensors/input_0.cairo +++ b/tests/nodes/min_i8_three_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 5, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_1.cairo b/tests/nodes/min_i8_three_tensors/input_1.cairo index 09e7ab7d1..d33e241c1 100644 --- a/tests/nodes/min_i8_three_tensors/input_1.cairo +++ b/tests/nodes/min_i8_three_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/input_2.cairo b/tests/nodes/min_i8_three_tensors/input_2.cairo index 6784429c8..9f66c1a8c 100644 --- a/tests/nodes/min_i8_three_tensors/input_2.cairo +++ b/tests/nodes/min_i8_three_tensors/input_2.cairo @@ -38,4 +38,4 @@ fn input_2() -> Tensor { data.append(i8 { mag: 5, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_three_tensors/output_0.cairo b/tests/nodes/min_i8_three_tensors/output_0.cairo index 86ccc411f..729e61ba1 100644 --- a/tests/nodes/min_i8_three_tensors/output_0.cairo +++ b/tests/nodes/min_i8_three_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors.cairo b/tests/nodes/min_i8_two_tensors.cairo index 8f13d360a..ffb3dd382 100644 --- a/tests/nodes/min_i8_two_tensors.cairo +++ b/tests/nodes/min_i8_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_i8_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_0.cairo b/tests/nodes/min_i8_two_tensors/input_0.cairo index edcba1f05..dfb122bf3 100644 --- a/tests/nodes/min_i8_two_tensors/input_0.cairo +++ b/tests/nodes/min_i8_two_tensors/input_0.cairo @@ -38,4 +38,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/input_1.cairo b/tests/nodes/min_i8_two_tensors/input_1.cairo index 805f2971a..9a088d52a 100644 --- a/tests/nodes/min_i8_two_tensors/input_1.cairo +++ b/tests/nodes/min_i8_two_tensors/input_1.cairo @@ -38,4 +38,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 4, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_i8_two_tensors/output_0.cairo b/tests/nodes/min_i8_two_tensors/output_0.cairo index 4cfdc62b3..35e0b1112 100644 --- a/tests/nodes/min_i8_two_tensors/output_0.cairo +++ b/tests/nodes/min_i8_two_tensors/output_0.cairo @@ -38,4 +38,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 3, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors.cairo b/tests/nodes/min_u32_broadcast_three_tensors.cairo index b76ced612..3f90de3a0 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_broadcast_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo index e1fde6172..ab5743e17 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(4); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo index 4f6ed249f..eb67448d2 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(4); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo index 9b8b57621..9ffbb5a5c 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/input_2.cairo @@ -10,4 +10,4 @@ fn input_2() -> Tensor { let mut data = ArrayTrait::new(); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo index 5af544845..5586a7f29 100644 --- a/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_three_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors.cairo b/tests/nodes/min_u32_broadcast_two_tensors.cairo index 9fe666a9e..ead761837 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_broadcast_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo index a173baaf1..79e203e76 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo index 447f95446..8f2990dec 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/input_1.cairo @@ -11,4 +11,4 @@ fn input_1() -> Tensor { data.append(5); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo index 51197a3e8..67ba1889c 100644 --- a/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_broadcast_two_tensors/output_0.cairo @@ -13,4 +13,4 @@ fn output_0() -> Tensor { data.append(5); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors.cairo b/tests/nodes/min_u32_three_tensors.cairo index 958888c62..82983386f 100644 --- a/tests/nodes/min_u32_three_tensors.cairo +++ b/tests/nodes/min_u32_three_tensors.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -21,4 +21,4 @@ fn test_min_u32_three_tensors() { let y = TensorTrait::min(array![input_0, input_1, input_2].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_0.cairo b/tests/nodes/min_u32_three_tensors/input_0.cairo index 30bcab8cc..408871093 100644 --- a/tests/nodes/min_u32_three_tensors/input_0.cairo +++ b/tests/nodes/min_u32_three_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_1.cairo b/tests/nodes/min_u32_three_tensors/input_1.cairo index 73f220714..cbbfc75c3 100644 --- a/tests/nodes/min_u32_three_tensors/input_1.cairo +++ b/tests/nodes/min_u32_three_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/input_2.cairo b/tests/nodes/min_u32_three_tensors/input_2.cairo index 1f682b4a7..8e8027f01 100644 --- a/tests/nodes/min_u32_three_tensors/input_2.cairo +++ b/tests/nodes/min_u32_three_tensors/input_2.cairo @@ -37,4 +37,4 @@ fn input_2() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_three_tensors/output_0.cairo b/tests/nodes/min_u32_three_tensors/output_0.cairo index 7a47c65c1..7e844ee1a 100644 --- a/tests/nodes/min_u32_three_tensors/output_0.cairo +++ b/tests/nodes/min_u32_three_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(1); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors.cairo b/tests/nodes/min_u32_two_tensors.cairo index 94ce36d7a..4b06824b8 100644 --- a/tests/nodes/min_u32_two_tensors.cairo +++ b/tests/nodes/min_u32_two_tensors.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_min_u32_two_tensors() { let y = TensorTrait::min(array![input_0, input_1].span()); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_0.cairo b/tests/nodes/min_u32_two_tensors/input_0.cairo index c20d52a0a..b4de32a93 100644 --- a/tests/nodes/min_u32_two_tensors/input_0.cairo +++ b/tests/nodes/min_u32_two_tensors/input_0.cairo @@ -37,4 +37,4 @@ fn input_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/input_1.cairo b/tests/nodes/min_u32_two_tensors/input_1.cairo index d4709f0df..375910cbf 100644 --- a/tests/nodes/min_u32_two_tensors/input_1.cairo +++ b/tests/nodes/min_u32_two_tensors/input_1.cairo @@ -37,4 +37,4 @@ fn input_1() -> Tensor { data.append(3); data.append(5); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/min_u32_two_tensors/output_0.cairo b/tests/nodes/min_u32_two_tensors/output_0.cairo index fc5f86d90..8fe8219a3 100644 --- a/tests/nodes/min_u32_two_tensors/output_0.cairo +++ b/tests/nodes/min_u32_two_tensors/output_0.cairo @@ -37,4 +37,4 @@ fn output_0() -> Tensor { data.append(3); data.append(2); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16.cairo b/tests/nodes/round_fp16x16.cairo index 02a279685..504ab435d 100644 --- a/tests/nodes/round_fp16x16.cairo +++ b/tests/nodes/round_fp16x16.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp16x16() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/input_0.cairo b/tests/nodes/round_fp16x16/input_0.cairo index 68229762b..711f27428 100644 --- a/tests/nodes/round_fp16x16/input_0.cairo +++ b/tests/nodes/round_fp16x16/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 163840, sign: true }); data.append(FP16x16 { mag: 183500, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp16x16/output_0.cairo b/tests/nodes/round_fp16x16/output_0.cairo index e303e30e4..0a920a6c2 100644 --- a/tests/nodes/round_fp16x16/output_0.cairo +++ b/tests/nodes/round_fp16x16/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23.cairo b/tests/nodes/round_fp8x23.cairo index e09a76fd2..8be8ed312 100644 --- a/tests/nodes/round_fp8x23.cairo +++ b/tests/nodes/round_fp8x23.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -17,4 +17,4 @@ fn test_round_fp8x23() { let y = input_0.round(); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/input_0.cairo b/tests/nodes/round_fp8x23/input_0.cairo index d812ae1a2..386404257 100644 --- a/tests/nodes/round_fp8x23/input_0.cairo +++ b/tests/nodes/round_fp8x23/input_0.cairo @@ -25,4 +25,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 20971520, sign: true }); data.append(FP8x23 { mag: 23488102, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/round_fp8x23/output_0.cairo b/tests/nodes/round_fp8x23/output_0.cairo index d5cc73f5f..b984ecfe6 100644 --- a/tests/nodes/round_fp8x23/output_0.cairo +++ b/tests/nodes/round_fp8x23/output_0.cairo @@ -25,4 +25,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 25165824, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1.cairo index ddd2ed77a..10838d6e7 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo index e450321a6..cfa417414 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 589824, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo index c8027a1a5..87045d082 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_axis1_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo index 47d99b23f..1b2e7a743 100644 --- a/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_axis1_add/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 1048576, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default.cairo b/tests/nodes/scatter_fp16x16_3d_default.cairo index ebc06014d..06cfd4fdd 100644 --- a/tests/nodes/scatter_fp16x16_3d_default.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp16x16_3d_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo index 90579e5d8..a11329495 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo index 0b71e00bc..b51facdab 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP16x16 { mag: 524288, sign: false }); data.append(FP16x16 { mag: 589824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo index 9edd74528..fa9f6a8b6 100644 --- a/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo +++ b/tests/nodes/scatter_fp16x16_3d_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1.cairo b/tests/nodes/scatter_fp8x23_axis1.cairo index 31ec2ea7c..ef903f3ad 100644 --- a/tests/nodes/scatter_fp8x23_axis1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_axis1/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo index 888cee255..46d23fbd5 100644 --- a/tests/nodes/scatter_fp8x23_axis1/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_axis1/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 75497472, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default.cairo b/tests/nodes/scatter_fp8x23_default.cairo index 66e5a6064..0ffd910b4 100644 --- a/tests/nodes/scatter_fp8x23_default.cairo +++ b/tests/nodes/scatter_fp8x23_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_0.cairo b/tests/nodes/scatter_fp8x23_default/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_default/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_1.cairo b/tests/nodes/scatter_fp8x23_default/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_default/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/input_2.cairo b/tests/nodes/scatter_fp8x23_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_default/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_default/output_0.cairo b/tests/nodes/scatter_fp8x23_default/output_0.cairo index 6c198c3af..c2011e04b 100644 --- a/tests/nodes/scatter_fp8x23_default/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_default/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul.cairo b/tests/nodes/scatter_fp8x23_mul.cairo index 8f6a9e5ae..dc90cfcbe 100644 --- a/tests/nodes/scatter_fp8x23_mul.cairo +++ b/tests/nodes/scatter_fp8x23_mul.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_fp8x23_mul() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('mul') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_0.cairo b/tests/nodes/scatter_fp8x23_mul/input_0.cairo index 4b7c73dcb..331c6cf88 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_0.cairo @@ -20,4 +20,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_1.cairo b/tests/nodes/scatter_fp8x23_mul/input_1.cairo index a36342547..738d5cfaa 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_1.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_1.cairo @@ -20,4 +20,4 @@ fn input_1() -> Tensor { data.append(FP8x23 { mag: 67108864, sign: false }); data.append(FP8x23 { mag: 75497472, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/input_2.cairo b/tests/nodes/scatter_fp8x23_mul/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_fp8x23_mul/input_2.cairo +++ b/tests/nodes/scatter_fp8x23_mul/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_fp8x23_mul/output_0.cairo b/tests/nodes/scatter_fp8x23_mul/output_0.cairo index 73c873293..b0b7353cc 100644 --- a/tests/nodes/scatter_fp8x23_mul/output_0.cairo +++ b/tests/nodes/scatter_fp8x23_mul/output_0.cairo @@ -20,4 +20,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1.cairo b/tests/nodes/scatter_i8_axis1.cairo index aeed6cea2..2374e89c5 100644 --- a/tests/nodes/scatter_i8_axis1.cairo +++ b/tests/nodes/scatter_i8_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_0.cairo b/tests/nodes/scatter_i8_axis1/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_1.cairo b/tests/nodes/scatter_i8_axis1/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/input_2.cairo b/tests/nodes/scatter_i8_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1/output_0.cairo b/tests/nodes/scatter_i8_axis1/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max.cairo b/tests/nodes/scatter_i8_axis1_max.cairo index 0b1cc537c..b4d1a8799 100644 --- a/tests/nodes/scatter_i8_axis1_max.cairo +++ b/tests/nodes/scatter_i8_axis1_max.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_axis1_max() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('max')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('max') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_0.cairo b/tests/nodes/scatter_i8_axis1_max/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_1.cairo b/tests/nodes/scatter_i8_axis1_max/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_1.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/input_2.cairo b/tests/nodes/scatter_i8_axis1_max/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_axis1_max/input_2.cairo +++ b/tests/nodes/scatter_i8_axis1_max/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_axis1_max/output_0.cairo b/tests/nodes/scatter_i8_axis1_max/output_0.cairo index 173bb1617..bcbb7d7d0 100644 --- a/tests/nodes/scatter_i8_axis1_max/output_0.cairo +++ b/tests/nodes/scatter_i8_axis1_max/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 9, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default.cairo b/tests/nodes/scatter_i8_default.cairo index b0d10c89d..e28a0549c 100644 --- a/tests/nodes/scatter_i8_default.cairo +++ b/tests/nodes/scatter_i8_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_i8_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_0.cairo b/tests/nodes/scatter_i8_default/input_0.cairo index abbf36d26..f5fad9150 100644 --- a/tests/nodes/scatter_i8_default/input_0.cairo +++ b/tests/nodes/scatter_i8_default/input_0.cairo @@ -19,4 +19,4 @@ fn input_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_1.cairo b/tests/nodes/scatter_i8_default/input_1.cairo index 13224f105..997d08467 100644 --- a/tests/nodes/scatter_i8_default/input_1.cairo +++ b/tests/nodes/scatter_i8_default/input_1.cairo @@ -19,4 +19,4 @@ fn input_1() -> Tensor { data.append(i8 { mag: 8, sign: false }); data.append(i8 { mag: 9, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/input_2.cairo b/tests/nodes/scatter_i8_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_i8_default/input_2.cairo +++ b/tests/nodes/scatter_i8_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_i8_default/output_0.cairo b/tests/nodes/scatter_i8_default/output_0.cairo index 9f1cf79dd..dfc02ca20 100644 --- a/tests/nodes/scatter_i8_default/output_0.cairo +++ b/tests/nodes/scatter_i8_default/output_0.cairo @@ -19,4 +19,4 @@ fn output_0() -> Tensor { data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 3, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add.cairo b/tests/nodes/scatter_u32_add.cairo index 5c28a9394..3d1a8a0a9 100644 --- a/tests/nodes/scatter_u32_add.cairo +++ b/tests/nodes/scatter_u32_add.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_add() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('add')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('add') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_0.cairo b/tests/nodes/scatter_u32_add/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_add/input_0.cairo +++ b/tests/nodes/scatter_u32_add/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_1.cairo b/tests/nodes/scatter_u32_add/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_add/input_1.cairo +++ b/tests/nodes/scatter_u32_add/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/input_2.cairo b/tests/nodes/scatter_u32_add/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_add/input_2.cairo +++ b/tests/nodes/scatter_u32_add/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_add/output_0.cairo b/tests/nodes/scatter_u32_add/output_0.cairo index 924837c12..e892f73f8 100644 --- a/tests/nodes/scatter_u32_add/output_0.cairo +++ b/tests/nodes/scatter_u32_add/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1.cairo b/tests/nodes/scatter_u32_axis1.cairo index 784c28787..da79a252c 100644 --- a/tests/nodes/scatter_u32_axis1.cairo +++ b/tests/nodes/scatter_u32_axis1.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_axis1() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(1), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(1), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_0.cairo b/tests/nodes/scatter_u32_axis1/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_axis1/input_0.cairo +++ b/tests/nodes/scatter_u32_axis1/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_1.cairo b/tests/nodes/scatter_u32_axis1/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_axis1/input_1.cairo +++ b/tests/nodes/scatter_u32_axis1/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/input_2.cairo b/tests/nodes/scatter_u32_axis1/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_axis1/input_2.cairo +++ b/tests/nodes/scatter_u32_axis1/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_axis1/output_0.cairo b/tests/nodes/scatter_u32_axis1/output_0.cairo index 2a2d51eda..85db8a36f 100644 --- a/tests/nodes/scatter_u32_axis1/output_0.cairo +++ b/tests/nodes/scatter_u32_axis1/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(9); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default.cairo b/tests/nodes/scatter_u32_default.cairo index fd2607de7..5cf0e53d7 100644 --- a/tests/nodes/scatter_u32_default.cairo +++ b/tests/nodes/scatter_u32_default.cairo @@ -1,7 +1,7 @@ -mod input_0; -mod input_1; -mod input_2; -mod output_0; +mod input_0; +mod input_1; +mod input_2; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,7 +18,13 @@ fn test_scatter_u32_default() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none')); + let y = input_0 + .scatter( + updates: input_1, + indices: input_2, + axis: Option::Some(0), + reduction: Option::Some('none') + ); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_0.cairo b/tests/nodes/scatter_u32_default/input_0.cairo index 13ba41a86..27b0af6c3 100644 --- a/tests/nodes/scatter_u32_default/input_0.cairo +++ b/tests/nodes/scatter_u32_default/input_0.cairo @@ -18,4 +18,4 @@ fn input_0() -> Tensor { data.append(0); data.append(0); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_1.cairo b/tests/nodes/scatter_u32_default/input_1.cairo index feb2dabc8..07fea4098 100644 --- a/tests/nodes/scatter_u32_default/input_1.cairo +++ b/tests/nodes/scatter_u32_default/input_1.cairo @@ -18,4 +18,4 @@ fn input_1() -> Tensor { data.append(8); data.append(9); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/input_2.cairo b/tests/nodes/scatter_u32_default/input_2.cairo index 4fd383db2..cbe1322a6 100644 --- a/tests/nodes/scatter_u32_default/input_2.cairo +++ b/tests/nodes/scatter_u32_default/input_2.cairo @@ -18,4 +18,4 @@ fn input_2() -> Tensor { data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/scatter_u32_default/output_0.cairo b/tests/nodes/scatter_u32_default/output_0.cairo index 3bea6d3a7..09bc154f4 100644 --- a/tests/nodes/scatter_u32_default/output_0.cairo +++ b/tests/nodes/scatter_u32_default/output_0.cairo @@ -18,4 +18,4 @@ fn output_0() -> Tensor { data.append(0); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/operators/qlinear_add_test.cairo b/tests/operators/qlinear_add_test.cairo index 4c08a77ea..667d64411 100644 --- a/tests/operators/qlinear_add_test.cairo +++ b/tests/operators/qlinear_add_test.cairo @@ -5,7 +5,7 @@ use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tens use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; use orion::numbers::{NumberTrait, IntegerTrait}; use orion::numbers::{i8, i32}; - + #[test] #[available_gas(200000000000)] @@ -144,7 +144,7 @@ fn qlinearadd_broadcast_test() { #[test] #[available_gas(200000000000)] -fn test_example_doc() { +fn test_example_doc() { let a = TensorTrait::< i8 >::new( @@ -173,7 +173,9 @@ fn test_example_doc() { let a_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); let a_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); @@ -186,19 +188,19 @@ fn test_example_doc() { let y_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + ); let y_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, true)].span(),); let actual_output = a - .qlinear_add( - @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point - ); + .qlinear_add(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); assert((*actual_output.data[0]).into() == 1, '*result[0] == 1'); assert((*actual_output.data[1]).into() == 1, '*result[1] == 1'); assert((*actual_output.data[2]).into() == 1, '*result[2] == 1'); assert((*actual_output.data[3]).into() == 2, '*result[3] == 2'); assert((*actual_output.data[4]).into() == 2, '*result[4] == 2'); - assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); -} + assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); +} diff --git a/tests/operators/qlinear_mul_test.cairo b/tests/operators/qlinear_mul_test.cairo index 6f913dc79..9981528c1 100644 --- a/tests/operators/qlinear_mul_test.cairo +++ b/tests/operators/qlinear_mul_test.cairo @@ -73,9 +73,7 @@ fn qlinearmul_test() { >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); let actual_output = a - .qlinear_mul( - @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point - ); + .qlinear_mul(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); assert((*actual_output.data[0]).into() == 0, '*result[0] == 0'); assert((*actual_output.data[1]).into() == 0, '*result[1] == 0'); @@ -89,7 +87,6 @@ fn qlinearmul_test() { assert((*actual_output.data[9]).into() == 5, '*result[9] == 5'); assert((*actual_output.data[10]).into() == 6, '*result[10] == 6'); assert((*actual_output.data[11]).into() == 7, '*result[11] == 7'); - } @@ -147,7 +144,7 @@ fn qlinear_mul_broadcast_test() { let actual_output = a .qlinear_mul(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); - + assert((*actual_output.data[0]).into() == 0, '*result[0] == 0'); assert((*actual_output.data[1]).into() == 2, '*result[1] == 2'); assert((*actual_output.data[2]).into() == 4, '*result[2] == 4'); @@ -215,9 +212,7 @@ fn test_example_doc() { ); let actual_output = a - .qlinear_mul( - @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point - ); + .qlinear_mul(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point); assert((*actual_output.data[0]).into() == 16, '*result[0] == 16'); assert((*actual_output.data[1]).into() == 23, '*result[1] == 23'); @@ -225,6 +220,5 @@ fn test_example_doc() { assert((*actual_output.data[3]).into() == 23, '*result[3] == 23'); assert((*actual_output.data[4]).into() == 36, '*result[4] == 36'); assert((*actual_output.data[5]).into() == 50, '*result[5] == 50'); - } From f50f9f773fe8e25f40b6b84c857d43e7905fabfc Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 16:03:26 +0100 Subject: [PATCH 019/160] Refactor output tensor type and adjust tests --- nodegen/node/binarizer.py | 20 ++++--- src/operators/tensor/core.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 2 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- src/operators/tensor/math/binarizer.cairo | 10 ++-- tests/nodes/binarizer_fp16x16.cairo | 2 +- tests/nodes/binarizer_fp16x16/input_0.cairo | 54 ++++++++--------- tests/nodes/binarizer_fp16x16/output_0.cairo | 60 ++++++++++--------- tests/nodes/binarizer_fp8x23.cairo | 2 +- tests/nodes/binarizer_fp8x23/input_0.cairo | 54 ++++++++--------- tests/nodes/binarizer_fp8x23/output_0.cairo | 60 ++++++++++--------- tests/nodes/binarizer_i32.cairo | 2 +- tests/nodes/binarizer_i32/input_0.cairo | 28 ++++----- tests/nodes/binarizer_i32/output_0.cairo | 59 +++++++++--------- 21 files changed, 189 insertions(+), 182 deletions(-) diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py index 661fcf95a..f1a07d07a 100644 --- a/nodegen/node/binarizer.py +++ b/nodegen/node/binarizer.py @@ -8,11 +8,11 @@ class Binarizer(RunAll): @staticmethod def binarizer_i32(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) - threshold = 1 - y = (x > threshold).astype(np.uint32) + threshold = np.int32(1) + y = (x > threshold).astype(np.int32) x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "binarizer_i32" make_node([x], [y], name) @@ -22,12 +22,13 @@ def binarizer_i32(): @staticmethod def binarizer_fp8x23(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) - threshold = 1.0 - y = (x > threshold).astype(np.uint32) + threshold = np.float64(1) + y = (x > threshold).astype(np.float64) x = Tensor(Dtype.FP8x23, x.shape, to_fp( x.flatten(), FixedImpl.FP8x23)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) name = "binarizer_fp8x23" make_node([x], [y], name) @@ -37,12 +38,13 @@ def binarizer_fp8x23(): @staticmethod def binarizer_fp16x16(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) - threshold = 1.0 - y = (x > threshold).astype(np.uint32) + threshold = np.float64(1) + y = (x > threshold).astype(np.float64) x = Tensor(Dtype.FP16x16, x.shape, to_fp( x.flatten(), FixedImpl.FP16x16)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) name = "binarizer_fp16x16" make_node([x], [y], name) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 74c6485b0..92d93fcc8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,7 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; - fn binarizer(self: @Tensor, threshold: @T) -> Tensor; + fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 429e2cf8d..16c3d178a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,7 +288,7 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c9e5d9e61..5d7ac3908 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -287,7 +287,7 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index bd73890cc..8bd01a0e3 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -289,7 +289,7 @@ impl FP32x32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index fd3c8afc2..6c094b827 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,7 +289,7 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index c4db51e7f..01455b675 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -288,7 +288,7 @@ impl FP8x23Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 82ffe8c55..5a15a7cd2 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,7 +277,7 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 2accf79fb..dbfac85d5 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -288,7 +288,7 @@ impl I32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index cd7247aa9..65a0e5081 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -287,7 +287,7 @@ impl I8Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2fd0063f4..ed3903921 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -269,7 +269,7 @@ impl U32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index d28be43d0..697c4e293 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -9,23 +9,23 @@ use orion::numbers::NumberTrait; fn binarizer< T, MAG, - impl TTensor: TensorTrait, + impl TTensor: TensorTrait, impl TNumber: NumberTrait, impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( mut self: Tensor, threshold: @T -) -> Tensor { - let mut binarized_data: Array = ArrayTrait::new(); +) -> Tensor { + let mut binarized_data = ArrayTrait::::new(); loop { match self.data.pop_front() { Option::Some(item) => { if (*item) > (*threshold) { - binarized_data.append(1); + binarized_data.append(NumberTrait::one()); } else { - binarized_data.append(0); + binarized_data.append(NumberTrait::zero()); } }, Option::None(_) => { diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 258bfa8f1..5ddd92826 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::FixedTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo index 2aaa53e2b..597143f74 100644 --- a/tests/nodes/binarizer_fp16x16/input_0.cairo +++ b/tests/nodes/binarizer_fp16x16/input_0.cairo @@ -11,32 +11,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 146027, sign: true }); - data.append(FP16x16 { mag: 29998, sign: false }); - data.append(FP16x16 { mag: 79381, sign: true }); - data.append(FP16x16 { mag: 52502, sign: true }); - data.append(FP16x16 { mag: 141943, sign: true }); - data.append(FP16x16 { mag: 77493, sign: true }); - data.append(FP16x16 { mag: 143847, sign: true }); - data.append(FP16x16 { mag: 40577, sign: true }); - data.append(FP16x16 { mag: 15396, sign: false }); - data.append(FP16x16 { mag: 194266, sign: true }); - data.append(FP16x16 { mag: 73878, sign: true }); - data.append(FP16x16 { mag: 123262, sign: true }); - data.append(FP16x16 { mag: 106458, sign: false }); - data.append(FP16x16 { mag: 173856, sign: false }); - data.append(FP16x16 { mag: 80438, sign: true }); - data.append(FP16x16 { mag: 164829, sign: true }); - data.append(FP16x16 { mag: 89224, sign: true }); - data.append(FP16x16 { mag: 2691, sign: false }); - data.append(FP16x16 { mag: 181152, sign: true }); - data.append(FP16x16 { mag: 128977, sign: false }); - data.append(FP16x16 { mag: 78823, sign: true }); - data.append(FP16x16 { mag: 65209, sign: true }); - data.append(FP16x16 { mag: 56918, sign: false }); - data.append(FP16x16 { mag: 118799, sign: true }); - data.append(FP16x16 { mag: 179883, sign: false }); - data.append(FP16x16 { mag: 114165, sign: true }); - data.append(FP16x16 { mag: 142, sign: false }); + data.append(FP16x16 { mag: 116651, sign: true }); + data.append(FP16x16 { mag: 45255, sign: false }); + data.append(FP16x16 { mag: 132067, sign: true }); + data.append(FP16x16 { mag: 83631, sign: true }); + data.append(FP16x16 { mag: 151971, sign: false }); + data.append(FP16x16 { mag: 46816, sign: true }); + data.append(FP16x16 { mag: 4353, sign: false }); + data.append(FP16x16 { mag: 188531, sign: false }); + data.append(FP16x16 { mag: 104593, sign: false }); + data.append(FP16x16 { mag: 41997, sign: true }); + data.append(FP16x16 { mag: 127090, sign: false }); + data.append(FP16x16 { mag: 79053, sign: false }); + data.append(FP16x16 { mag: 139184, sign: true }); + data.append(FP16x16 { mag: 439, sign: false }); + data.append(FP16x16 { mag: 115688, sign: false }); + data.append(FP16x16 { mag: 184428, sign: true }); + data.append(FP16x16 { mag: 161855, sign: true }); + data.append(FP16x16 { mag: 42551, sign: true }); + data.append(FP16x16 { mag: 40207, sign: false }); + data.append(FP16x16 { mag: 72062, sign: false }); + data.append(FP16x16 { mag: 195673, sign: false }); + data.append(FP16x16 { mag: 27413, sign: true }); + data.append(FP16x16 { mag: 173891, sign: true }); + data.append(FP16x16 { mag: 69697, sign: true }); + data.append(FP16x16 { mag: 162632, sign: false }); + data.append(FP16x16 { mag: 53852, sign: true }); + data.append(FP16x16 { mag: 93775, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo index 9499a7848..b4bbbde98 100644 --- a/tests/nodes/binarizer_fp16x16/output_0.cairo +++ b/tests/nodes/binarizer_fp16x16/output_0.cairo @@ -1,40 +1,42 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; -fn output_0() -> Tensor { +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(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 4de3cbb7d..62d6f3ee4 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::FixedTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo index 39d12c3be..e11d8a9f4 100644 --- a/tests/nodes/binarizer_fp8x23/input_0.cairo +++ b/tests/nodes/binarizer_fp8x23/input_0.cairo @@ -11,32 +11,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 7205493, sign: true }); - data.append(FP8x23 { mag: 14503128, sign: false }); - data.append(FP8x23 { mag: 9682839, sign: false }); - data.append(FP8x23 { mag: 25030485, sign: false }); - data.append(FP8x23 { mag: 3669115, sign: true }); - data.append(FP8x23 { mag: 16376632, sign: true }); - data.append(FP8x23 { mag: 4670619, sign: false }); - data.append(FP8x23 { mag: 24976405, sign: true }); - data.append(FP8x23 { mag: 19811890, sign: false }); - data.append(FP8x23 { mag: 10781071, sign: true }); - data.append(FP8x23 { mag: 10216945, sign: false }); - data.append(FP8x23 { mag: 25004285, sign: false }); - data.append(FP8x23 { mag: 7482592, sign: false }); - data.append(FP8x23 { mag: 1360, sign: true }); - data.append(FP8x23 { mag: 10632602, sign: true }); - data.append(FP8x23 { mag: 275175, sign: true }); - data.append(FP8x23 { mag: 21731586, sign: true }); - data.append(FP8x23 { mag: 5638921, sign: true }); - data.append(FP8x23 { mag: 6096613, sign: false }); - data.append(FP8x23 { mag: 22105612, sign: false }); - data.append(FP8x23 { mag: 17084000, sign: true }); - data.append(FP8x23 { mag: 12627954, sign: true }); - data.append(FP8x23 { mag: 23194838, sign: false }); - data.append(FP8x23 { mag: 9012947, sign: false }); - data.append(FP8x23 { mag: 5163417, sign: true }); - data.append(FP8x23 { mag: 13580853, sign: false }); - data.append(FP8x23 { mag: 5624227, sign: false }); + data.append(FP8x23 { mag: 19910639, sign: true }); + data.append(FP8x23 { mag: 16200109, sign: false }); + data.append(FP8x23 { mag: 7318221, sign: false }); + data.append(FP8x23 { mag: 3839710, sign: true }); + data.append(FP8x23 { mag: 5198439, sign: true }); + data.append(FP8x23 { mag: 13440550, sign: false }); + data.append(FP8x23 { mag: 3475736, sign: false }); + data.append(FP8x23 { mag: 12659448, sign: false }); + data.append(FP8x23 { mag: 22040361, sign: true }); + data.append(FP8x23 { mag: 16960032, sign: true }); + data.append(FP8x23 { mag: 20980250, sign: false }); + data.append(FP8x23 { mag: 19528339, sign: true }); + data.append(FP8x23 { mag: 24567413, sign: true }); + data.append(FP8x23 { mag: 3374986, sign: true }); + data.append(FP8x23 { mag: 5428617, sign: false }); + data.append(FP8x23 { mag: 16499249, sign: true }); + data.append(FP8x23 { mag: 14111693, sign: false }); + data.append(FP8x23 { mag: 22806062, sign: false }); + data.append(FP8x23 { mag: 5020958, sign: false }); + data.append(FP8x23 { mag: 20749322, sign: false }); + data.append(FP8x23 { mag: 7503709, sign: true }); + data.append(FP8x23 { mag: 24435895, sign: false }); + data.append(FP8x23 { mag: 12933406, sign: true }); + data.append(FP8x23 { mag: 11401085, sign: true }); + data.append(FP8x23 { mag: 97331, sign: false }); + data.append(FP8x23 { mag: 21216642, sign: true }); + data.append(FP8x23 { mag: 2018862, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo index d5317e309..8ec654745 100644 --- a/tests/nodes/binarizer_fp8x23/output_0.cairo +++ b/tests/nodes/binarizer_fp8x23/output_0.cairo @@ -1,40 +1,42 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; -fn output_0() -> Tensor { +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(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(0); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo index dc82a3bd1..7793b74ae 100644 --- a/tests/nodes/binarizer_i32.cairo +++ b/tests/nodes/binarizer_i32.cairo @@ -6,7 +6,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::numbers::IntegerTrait; use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::I32TensorPartialEq; use orion::utils::assert_eq; #[test] diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo index f4e25323a..3059b3649 100644 --- a/tests/nodes/binarizer_i32/input_0.cairo +++ b/tests/nodes/binarizer_i32/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - 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: true }); - data.append(i32 { mag: 2, sign: false }); 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: true }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, 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: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); + 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: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + 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: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo index 23163214e..3adef88e2 100644 --- a/tests/nodes/binarizer_i32/output_0.cairo +++ b/tests/nodes/binarizer_i32/output_0.cairo @@ -1,40 +1,41 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; -fn output_0() -> Tensor { +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(0); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From 6cebe286db4bd84a70d217b05c577c9342152f3c Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 8 Nov 2023 16:38:12 +0100 Subject: [PATCH 020/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.binarizer.md | 44 ++++++++++++++++++ src/operators/tensor/core.cairo | 46 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.binarizer.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f96dd7a6f..c24d92ce5 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -95,6 +95,7 @@ * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + * [tensor.binarizer](framework/operators/tensor/tensor.binarizer.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 e5f7f39cf..28b2624df 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,5 +74,6 @@ You can see below the list of current supported ONNX Operators: | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | | [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [Binarizer](operators/tensor/tensor.binarizer.md) | :white\_check\_mark: | -Current Operators support: **68/156 (43%)** +Current Operators support: **69/156 (44%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 369713044..42282fb8f 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -91,6 +91,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | +| [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md new file mode 100644 index 000000000..14cac3d65 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -0,0 +1,44 @@ +# tensor.binarizer + +```rust + fn binarizer(self: @Tensor, threshold: @T) -> Tensor +``` + +Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + +## Args +* `self`(`@Tensor`) - The input tensor to be binarized. +* `threshold`(`@T`) - The threshold for the binarization operation. + +## Returns +A new `Tensor` of the same shape as the input tensor with binarized values. + +## Type Constraints + +Constrain input and output types to fixed point and int32 tensors. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn binarizer_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::new(1, true), + IntegerTrait::new(0, false), + IntegerTrait::new(1, false), + IntegerTrait::new(2, false), + ] + .span(), + ); + let threshold = IntegerTrait::::new(1, false) + + return tensor.binarizer(@tensor, @threshold); +} +>>> [0, 0, 0, 1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 92d93fcc8..c1d1271bb 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -87,6 +87,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3212,6 +3213,51 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// # tensor.binarizer + /// + /// ```rust + /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor + /// ``` + /// + /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be binarized. + /// * `threshold`(`@T`) - The threshold for the binarization operation. + /// + /// ## Returns + /// A new `Tensor` of the same shape as the input tensor with binarized values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point and int32 tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn binarizer_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::new(1, true), + /// IntegerTrait::new(0, false), + /// IntegerTrait::new(1, false), + /// IntegerTrait::new(2, false), + /// ] + /// .span(), + /// ); + /// let threshold = IntegerTrait::::new(1, false) + /// + /// return tensor.binarizer(@tensor, @threshold); + /// } + /// >>> [0, 0, 0, 1] + /// ``` + /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor; } From d6c8fd263ddfe7b1d6c1a770075d585fbd439b55 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 9 Nov 2023 13:25:49 +0200 Subject: [PATCH 021/160] implement other version --- src/operators/matrix.cairo | 102 ++++++++- src/operators/ml/tree_ensemble.cairo | 3 +- src/operators/ml/tree_ensemble/core.cairo | 2 +- .../tree_ensemble_classifier.cairo | 4 +- .../tree_ensemble_classifier2.cairo | 197 ++++++++++++++++++ src/utils.cairo | 6 +- tests/ml/tree_ensemble_classifier.cairo | 15 +- 7 files changed, 314 insertions(+), 15 deletions(-) create mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 4baec91af..5f49c2b7e 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,5 +1,9 @@ +use core::array::ArrayTrait; +use core::option::OptionTrait; use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; +use orion::numbers::NumberTrait; + impl VecCopy of Copy>; impl NullCopy of Copy>>; impl VecDrop of Drop>; @@ -13,13 +17,15 @@ struct MutMatrix { } #[generate_trait] -impl MutMatrixImpl, +Copy> of MutMatrixTrait { - // Constructor for the Matrix +impl MutMatrixImpl< + T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd +> of MutMatrixTrait { + /// Constructor for the Matrix fn new(rows: usize, cols: usize) -> MutMatrix { MutMatrix { data: NullableVecImpl::new(), rows: rows, cols: cols } } - // Get the value at (row, col) + /// Get the value at (row, col) fn get(ref self: MutMatrix, row: usize, col: usize) -> Option { if row >= self.rows || col >= self.cols { Option::None @@ -28,7 +34,7 @@ impl MutMatrixImpl, +Copy> of MutMatrixTrait { } } - // Set the value at (row, col) + /// Set the value at (row, col) fn set(ref self: MutMatrix, row: usize, col: usize, value: T) { if row < self.rows && col < self.cols { let index = row * self.cols + col; @@ -36,8 +42,94 @@ impl MutMatrixImpl, +Copy> of MutMatrixTrait { } } - // Returns the shape of the matrix as (rows, cols) + /// Returns the shape of the matrix as (rows, cols) fn shape(self: MutMatrix) -> (usize, usize) { (self.rows, self.cols) } + + /// Returns the index of the maximum value along the specified axis + fn argmax(ref self: MutMatrix, axis: usize) -> Span { + assert(axis < 2, 'Invalid axis'); + + let mut result: Array = ArrayTrait::new(); + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut max_value = self.get(0, col); + let mut max_value = match max_value { + Option::Some => { max_value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + let mut max_index = 0; + + let mut row: usize = 1; + loop { + if row == self.rows { + break; + } + + let mut value = self.get(row, col); + let mut value = match value { + Option::Some => { value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + if value > max_value { + max_value = value; + max_index = row; + } + + row += 1; + }; + + result.append(max_index); + + col += 1; + }; + + return result.span(); + } + + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut max_value = self.get(row, 0); + let mut max_value = match max_value { + Option::Some => { max_value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + let mut max_index = 0; + + let mut col: usize = 1; + loop { + if col == self.cols { + break; + } + + let mut value = self.get(row, col); + let mut value = match value { + Option::Some => { value.unwrap() }, + Option::None => { NumberTrait::min_value() } + }; + if value > max_value { + max_value = value; + max_index = col; + } + + col += 1; + }; + + result.append(max_index); + + row += 1; + }; + + return result.span(); + } } diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 0f09fa8d1..32177e813 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,2 +1,3 @@ mod core; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; +mod tree_ensemble_classifier2; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index cd8992eb9..a54295822 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -101,7 +101,7 @@ impl TreeEnsembleImpl< break; } - let row_data: Span = get_row(x, i); + let row_data: Span = get_row(@x, i); let mut outs = ArrayTrait::new(); let mut tree_ids = self.tree_ids; loop { diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 10523ab11..4d7723d8e 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,4 @@ +use core::array::SpanTrait; use core::nullable::NullableTrait; use core::dict::Felt252DictTrait; use core::dict::Felt252DictEntryTrait; @@ -46,6 +47,7 @@ impl TreeEnsembleClassifierImpl< +Add, +TensorTrait, +TensorTrait, + +PrintTrait > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { let leaf_indices = self.ensemble.leave_index_tree(X); @@ -57,7 +59,7 @@ impl TreeEnsembleClassifierImpl< } -fn compute_scores, +Copy, +NumberTrait, +Add,>( +fn compute_scores, +Copy, +NumberTrait, +Add, +PrintTrait>( ref self: TreeEnsembleClassifier, leaf_indices: Tensor ) -> (Span, Felt252Dict::>) { // Initialize the scores array, either with base_values or zeros diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo new file mode 100644 index 000000000..cc6b5f4a0 --- /dev/null +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo @@ -0,0 +1,197 @@ +use core::array::ArrayTrait; +use core::clone::Clone; +use core::box::BoxTrait; +use core::traits::Into; +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; +use core::array::SpanTrait; +use core::nullable::NullableTrait; +use core::dict::Felt252DictTrait; +use core::dict::Felt252DictEntryTrait; +use nullable::{match_nullable, FromNullableResult}; + +use orion::operators::tensor::{Tensor, TensorTrait}; +use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; +use orion::numbers::NumberTrait; +use orion::utils::get_row; + +use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + +use debug::PrintTrait; + +#[derive(Destruct)] +struct TreeEnsembleClassifier { + ensemble: TreeEnsemble, + class_ids: Span, + class_nodeids: Span, + class_treeids: Span, + class_weights: Span, + classlabels: Span, + base_values: Option>, + post_transform: PostTransform, +} + +#[derive(Copy, Drop)] +enum PostTransform { + None, + Softmax, + Logistic, + SoftmaxZero, + Probit, +} + +#[generate_trait] +impl TreeEnsembleClassifierImpl< + T, + MAG, + +Drop, + +Copy, + +NumberTrait, + +PartialOrd, + +PartialEq, + +Add, + +TensorTrait, + +TensorTrait, + +PrintTrait +> of TreeEnsembleClassifierTrait { + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { + let leaves_index = self.ensemble.leave_index_tree(X); + let n_classes = self.classlabels.len(); + let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); + + // Set base values + if self.base_values.is_some() { + let mut base_values = self.base_values.unwrap(); + let mut row: usize = 0; + loop { + if row == res.rows { + break; + } + + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } + + let value = *base_values.pop_front().unwrap(); + res.set(row, col, value); + + col += 1 + }; + + row += 1; + } + } + + let mut class_index: Felt252Dict>> = Default::default(); + let mut i: usize = 0; + loop { + if i == self.class_treeids.len() { + break; + } + + let tid = *self.class_treeids[i]; + let nid = *self.class_nodeids[i]; + + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tid.into(), nid.into()); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { continue; }, + FromNullableResult::NotNull(val) => { + let mut new_val = val.unbox(); + let new_val = new_val.concat(array![i].span()); + class_index.insert(key, NullableTrait::new(new_val)); + }, + } + + i += 1; + }; + let mut i: usize = 0; + loop { + if i == res.rows { + break; + } + + let mut indices = get_row(@leaves_index, i); + let mut t_index: Array> = ArrayTrait::new(); + loop { + match indices.pop_front() { + Option::Some(index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*index]).into(), + (*self.ensemble.atts.nodes_treeids[*index]).into() + ); + t_index.append(class_index.get(key).deref()); + }, + Option::None(_) => { break; } + }; + }; + let mut t_index = t_index.span(); + loop { + match t_index.pop_front() { + Option::Some(its) => { + loop { + let mut its = *its; + match its.pop_front() { + Option::Some(it) => { + let prev_val = res.get(i, *self.class_ids[*it]); + match prev_val { + Option::Some(prev) => { + res + .set( + i, + *self.class_ids[*it], + prev + *self.class_weights[*it] + ); + }, + Option::None => { + res + .set( + i, + *self.class_ids[*it], + *self.class_weights[*it] + ); + } + } + }, + Option::None(_) => { break; } + }; + }; + }, + Option::None(_) => { break; } + }; + }; + i += 1; + }; + + // TODO: Binary case + + // Post Transform + let mut new_scores = match self.post_transform { + PostTransform::None => { res }, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + }; + + // Labels + let mut labels = new_scores.argmax(1); + let mut labels_list = ArrayTrait::new(); + loop { + match labels.pop_front() { + Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, + Option::None(_) => { break; } + }; + }; + + return (labels, new_scores); + } +} + diff --git a/src/utils.cairo b/src/utils.cairo index ab48c3d7d..2e66a093d 100644 --- a/src/utils.cairo +++ b/src/utils.cairo @@ -31,11 +31,11 @@ fn assert_eq, impl TCopy: Copy, impl TDrop: assert(lhs == rhs, 'should be equal'); } -fn get_row, +Copy>(self: Tensor, row: usize) -> Span { - assert(self.shape.len() == 2, 'Expected a 2D tensor'); +fn get_row, +Copy>(self: @Tensor, row: usize) -> Span { + assert((*self).shape.len() == 2, 'Expected a 2D tensor'); let row_length = *self.shape[1]; let start = row * row_length; - self.data.slice(start, row_length) + (*self).data.slice(start, row_length) } diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 66a8f44a4..c5b24601a 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,13 +1,16 @@ +use core::array::SpanTrait; use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier2::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; +use debug::PrintTrait; + #[test] #[available_gas(2000000000)] fn test_tree_ensemble_classifier_multi() { @@ -42,7 +45,7 @@ fn test_tree_ensemble_classifier_multi() { ] .span(); - let class_labels: Span = array![0, 1, 2].span(); + let classlabels: Span = array![0, 1, 2].span(); let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); @@ -137,7 +140,7 @@ fn test_tree_ensemble_classifier_multi() { class_nodeids, class_treeids, class_weights, - class_labels, + classlabels, base_values, post_transform }; @@ -158,6 +161,10 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - TreeEnsembleClassifierTrait::predict(ref classifier, X); + let (prediction, score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // (*score.data.at(0)).print(); + // (*score.data.at(1)).print(); + // (*score.data.at(2)).print(); } From dc1d2528ff6d85d441fff3016bdd7148a1b7ea7c Mon Sep 17 00:00:00 2001 From: chachaleo Date: Thu, 9 Nov 2023 22:16:31 +0700 Subject: [PATCH 022/160] feat: qlinear_concat --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.qlinear_concat.md | 99 ++++++++ .../operators/tensor/tensor.qlinear_matmul.md | 4 +- src/operators/tensor/core.cairo | 112 ++++++++- .../implementations/tensor_fp16x16.cairo | 20 ++ .../implementations/tensor_fp16x16wide.cairo | 11 + .../implementations/tensor_fp32x32.cairo | 20 ++ .../implementations/tensor_fp64x64.cairo | 20 ++ .../implementations/tensor_fp8x23.cairo | 20 ++ .../implementations/tensor_fp8x23wide.cairo | 11 + .../tensor/implementations/tensor_i32.cairo | 20 ++ .../tensor/implementations/tensor_i8.cairo | 20 ++ .../tensor/implementations/tensor_u32.cairo | 11 + src/operators/tensor/quantization.cairo | 1 + .../tensor/quantization/qlinear_concat.cairo | 187 ++++++++++++++ tests/lib.cairo | 10 +- tests/operators.cairo | 5 +- tests/operators/qlinear_concat_test.cairo | 229 ++++++++++++++++++ 20 files changed, 794 insertions(+), 11 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.qlinear_concat.md create mode 100644 src/operators/tensor/quantization/qlinear_concat.cairo create mode 100644 tests/operators/qlinear_concat_test.cairo diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f96dd7a6f..6925eb9b9 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -85,6 +85,7 @@ * [tensor.quantize\_linear](framework/operators/tensor/tensor.quantize\_linear.md) * [tensor.dequantize\_linear](framework/operators/tensor/tensor.dequantize\_linear.md) * [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md) + * [tensor.qlinear\_concat](framework/operators/tensor/tensor.qlinear\_concat.md) * [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) * [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) * [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index e5f7f39cf..e8eb1fb03 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -56,7 +56,8 @@ You can see below the list of current supported ONNX Operators: | [Gather](operators/tensor/tensor.gather.md) | :white\_check\_mark: | | [QuantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | | [DequantizeLinear](operators/tensor/tensor.quantize\_linear.md) | :white\_check\_mark: | -| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: | +| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: | +| [QLinearConcat](operators/tensor/tensor.qlinear\_concat.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: | diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 369713044..81a35da9a 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -80,6 +80,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.quantize_linear`](tensor.quantize\_linear.md) | Quantizes a Tensor to i8 using linear quantization. | | [`tensor.dequantize_linear`](tensor.dequantize\_linear.md) | Dequantizes an i8 Tensor using linear dequantization. | | [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. | +| [`tensor.qlinear_concat`](tensor.qlinear\_concat.md) | Performs the concatenation of a list of quantized i8 Tensors. | | [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. | | [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). | | [`tensor.squeeze`](tensor.squeeze.md) | Removes dimensions of size 1 from the shape of a tensor. | diff --git a/docs/framework/operators/tensor/tensor.qlinear_concat.md b/docs/framework/operators/tensor/tensor.qlinear_concat.md new file mode 100644 index 000000000..1eda056fe --- /dev/null +++ b/docs/framework/operators/tensor/tensor.qlinear_concat.md @@ -0,0 +1,99 @@ +# tensor.qlinear_concat + +```rust + qlinear_concat(tensors: Span>, scales: Span>, zero_points: Span>, y_scale: @Tensor, y_zero_point: @Tensor, axis: usize) -> Tensor::; +``` + +Concatenate a list of tensors after dequantizing them with their respective scales and zero_points and returns the quantized result. + +## Args + +* `tensors`(` Span>,`) - Array of the quantized input tensors. +* `scales`(` Span>,`) - Array of the scales of the quantized input tensors. +* `zero_points`(` Span>,`) - Arrayof the zero_points of the quantized input tensors. +* `y_scale`(`@Tensor`) - Scale for output. +* `y_zero_point`(`@Tensor`) - Zero point for output. +* `axis`(`usize`) - Axis to concat on. + +## Panics + +* Panic if tensor length is not greater than 1. +* Panics if dimension is not greater than axis. + +## Type Constraints + +u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. + +## Returns + +A new `Tensor` concatenated quantized tensor of the dequantized input tensors. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; +use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + +fn qlinear_concat_example() -> Tensor { + let tensor1 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + ] + .span(), + ); + let tensor2 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + ] + .span(), + ); + + let tensors = array![tensor1, tensor2].span(); + + let tensor1_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + let tensor2_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + + let scales = array![tensor1_scale, tensor2_scale].span(); + + let tensor1_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + let tensor2_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let zero_points = array![tensor1_zero_point, tensor2_zero_point].span(); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + + return TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); +} + +>>> [[1, 1, 1, 1], [2, 2, 2, 2]] +``` diff --git a/docs/framework/operators/tensor/tensor.qlinear_matmul.md b/docs/framework/operators/tensor/tensor.qlinear_matmul.md index df66f92e4..16e32958b 100644 --- a/docs/framework/operators/tensor/tensor.qlinear_matmul.md +++ b/docs/framework/operators/tensor/tensor.qlinear_matmul.md @@ -21,7 +21,7 @@ Scalar refers to per tensor quantization whereas N-D refers to per row or per co * `b`(`@Tensor`) - The second tensor to be multiplied * `b_scale`(`@Tensor`) - Scale for input `b`. * `b_zero_point`(`@Tensor`) - Zero point for input `b`. -* `y_scale`(`@Tensor`) - Scale for outut. +* `y_scale`(`@Tensor`) - Scale for output. * `y_zero_point`(`@Tensor`) - Zero point for output. ## Returns @@ -92,4 +92,4 @@ fn qlinear_matmul_example() -> Tensor { ); } >>> [14, 13] -``` \ No newline at end of file +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 8a3ae7e68..f94bbee5a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -76,6 +76,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// * `b`(`@Tensor`) - The second tensor to be multiplied /// * `b_scale`(`@Tensor`) - Scale for input `b`. /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. - /// * `y_scale`(`@Tensor`) - Scale for outut. + /// * `y_scale`(`@Tensor`) - Scale for output. /// * `y_zero_point`(`@Tensor`) - Zero point for output. /// /// ## Returns @@ -2634,6 +2635,7 @@ trait TensorTrait { /// } /// >>> [14, 13] /// ``` + /// fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, @@ -2644,6 +2646,114 @@ trait TensorTrait { y_scale: @Tensor, y_zero_point: @Tensor ) -> Tensor::; + /// # tensor.qlinear_concat + /// + /// ```rust + /// qlinear_concat(tensors: Span>, scales: Span>, zero_points: Span>, y_scale: @Tensor, y_zero_point: @Tensor, axis: usize) -> Tensor::; + /// ``` + /// + /// Concatenate a list of tensors after dequantizing them with their respective scales and zero_points and returns the quantized result. + /// + /// ## Args + /// + /// * `tensors`(` Span>,`) - Array of the quantized input tensors. + /// * `scales`(` Span>,`) - Array of the scales of the quantized input tensors. + /// * `zero_points`(` Span>,`) - Arrayof the zero_points of the quantized input tensors. + /// * `y_scale`(`@Tensor`) - Scale for output. + /// * `y_zero_point`(`@Tensor`) - Zero point for output. + /// * `axis`(`usize`) - Axis to concat on. + /// + /// ## Panics + /// + /// * Panic if tensor length is not greater than 1. + /// * Panics if dimension is not greater than axis. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// + /// ## Returns + /// + /// A new `Tensor` concatenated quantized tensor of the dequantized input tensors. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// fn qlinear_concat_example() -> Tensor { + /// let tensor1 = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// ] + /// .span(), + /// ); + /// let tensor2 = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// ] + /// .span(), + /// ); + /// + /// let tensors = array![tensor1, tensor2].span(); + /// + /// let tensor1_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + /// let tensor2_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + /// + /// let scales = array![tensor1_scale, tensor2_scale].span(); + /// + /// let tensor1_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + /// let tensor2_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + /// + /// let zero_points = array![tensor1_zero_point, tensor2_zero_point].span(); + /// + /// let y_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + /// + /// let y_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + /// + /// return TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + /// } + /// + /// >>> [[1, 1, 1, 1], [2, 2, 2, 2]] + /// ``` + /// + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor::; /// # tensor.slice /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 508134a2f..38e2f1735 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -230,6 +230,26 @@ impl FP16x16Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index d87f6dd9d..5070db0b5 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -225,6 +225,17 @@ impl FP16x16WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 30b85b755..5189577d3 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -231,6 +231,26 @@ impl FP32x32Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index c86420354..51034dada 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -231,6 +231,26 @@ impl FP64x64Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 3ddcf0369..63521a277 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -230,6 +230,26 @@ impl FP8x23Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 3c36ee737..8b253c924 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -219,6 +219,17 @@ impl FP8x23WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index bf0592c41..8ab3dd228 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -231,6 +231,26 @@ impl I32Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index bfadc3be5..cecaf6dd1 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -230,6 +230,26 @@ impl I8Tensor of TensorTrait { ) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + quantization::qlinear_concat::qlinear_concat( + tensors, + scales, + zero_points, + y_scale, + y_zero_point, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2faf21b0b..4a70c810f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -213,6 +213,17 @@ impl U32Tensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize, + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/quantization.cairo b/src/operators/tensor/quantization.cairo index 88baf9e3f..d1de3efe8 100644 --- a/src/operators/tensor/quantization.cairo +++ b/src/operators/tensor/quantization.cairo @@ -1,3 +1,4 @@ mod quantize_linear; mod dequantize_linear; mod qlinear_matmul; +mod qlinear_concat; \ No newline at end of file diff --git a/src/operators/tensor/quantization/qlinear_concat.cairo b/src/operators/tensor/quantization/qlinear_concat.cairo new file mode 100644 index 000000000..7147dd936 --- /dev/null +++ b/src/operators/tensor/quantization/qlinear_concat.cairo @@ -0,0 +1,187 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::{NumberTrait}; +use orion::operators::tensor::quantization::dequantize_linear::dequantize_linear; +use orion::operators::tensor::quantization::quantize_linear::quantize_linear; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::math::concat::{validate_shapes, compute_output_size, concatenate_data}; + +fn qlinear_concat< + T, + MAG, + Q, + impl TTensor: TensorTrait, + impl QTensor: TensorTrait, + impl QIntoT: Into, + impl QTensorIntoTTensor: Into, Tensor>, + impl TAdd: Add, + impl TSub: Sub, + impl TDiv: Div, + impl TMul: Mul, + impl TTensorAdd: Add>, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl TTensorDiv: Div>, + impl TPartialOrd: PartialOrd, + impl TNumber: NumberTrait, + impl TTryInto: TryInto, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, + impl QCopy: Copy, + impl QDrop: Drop, +>( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize, + min: T, + max: T +) -> Tensor { + assert(tensors.len() == scales.len(), 'Each Tensors must have a scale'); + assert(tensors.len() == zero_points.len(), 'Each Tensors must have a scale'); + + //let mut x = TensorTrait::concat(tensors: array![dequantized_a, dequantized_b].span(), axis: axis); + let mut x = concat_dequantize(tensors, scales, zero_points, axis, min, max); + + return quantize_linear(@x, y_scale, y_zero_point, min, max); +} + + +fn concat_dequantize< + T, + MAG, + Q, + impl TTensor: TensorTrait, + impl QTensor: TensorTrait, + impl QIntoT: Into, + impl QTensorIntoTTensor: Into, Tensor>, + impl TSub: Sub, + impl TMul: Mul, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl TPartialOrd: PartialOrd, + impl TNumber: NumberTrait, + impl TTryInto: TryInto, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, + impl QCopy: Copy, + impl QDrop: Drop, +>( + tensors: Span>, + scales: Span>, + zero_points: Span>, + axis: usize, + min: T, + max: T +) -> Tensor { + assert(tensors.len() >= 2, 'Input tensors must be > 1'); + let base_tensor = *tensors.at(0); + let base_shape = base_tensor.shape; + let dimension = base_shape.len(); + assert(dimension > axis, 'Out of bounds for dimension'); + + // Validate shapes of tensors + validate_shapes(tensors, base_shape, axis); + + // Calculate output size + let output_size = compute_output_size(base_shape, tensors, axis); + + // Dequantize tensors + let tensors = dequantize_tensors(tensors, scales, zero_points, min, max); + + // Concatenate tensor data + let output_data: Array = concatenate_data(tensors, axis, base_shape); + + TensorTrait::::new(output_size.span(), output_data.span()) +} + +fn dequantize_tensors< + Q, + T, + impl TTensor: TensorTrait, + impl QIntoT: Into, + impl TSub: Sub, + impl TMul: Mul, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl QTensorIntoTTensor: Into, Tensor>, + impl TDrop: Drop, + impl TCopy: Copy, + impl QCopy: Copy, + impl QDrop: Drop + //MAybe numberTRait +>(mut tensors: Span>, scales: Span>, zero_points: Span>, min: T, max: T) -> Span> { + let mut array = ArrayTrait::>::new(); + let mut i = 0; + loop { + match tensors.pop_front() { + Option::Some(tensor) => { + array.append(dequantize_linear(@(*tensor), @(*scales.at(i)), @(*zero_points.at(i)))); + }, + Option::None(_) => { break; } + }; + i += 1; + }; + return array.span(); +} + + /// # tensor.concat + /// + /// ```rust + /// fn concat(tensors: Span>, axis: usize, ) -> Tensor; + /// ``` + /// + /// Concatenate a list of tensors into a single tensor. + /// + /// ## Args + /// + /// * `tensors`(` Span>,`) - Array of the input tensors. + /// * `axis`(`usize`) - Axis to concat on. + /// + /// ## Panics + /// + /// * Panic if tensor length is not greater than 1. + /// * Panics if dimension is not greater than axis. + /// + /// ## Returns + /// + /// A new `Tensor` concatenated tensor of the input tensors. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn concat_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 0); + /// return result; + /// } + /// >>> [[0. 1.] + /// [2. 3.], + /// [0. 1.] + /// [2. 3.]] + /// + /// result.shape + /// >>> (4, 2) + /// + /// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 1); + /// return result; + /// } + /// >>> [[0. 1., 0., 1.] + /// [2. 3., 2., 3.]] + /// + /// result.shape + /// >>> (2, 4 ) + /// ``` + /// + ///fn concat(tensors: Span>, axis: usize,) -> Tensor; \ No newline at end of file diff --git a/tests/lib.cairo b/tests/lib.cairo index b8f3c9b96..a8b090d8d 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -1,6 +1,6 @@ -mod numbers; -mod performance; -mod tensor_core; -mod nodes; -mod ml; +//mod numbers; +//mod performance; +//mod tensor_core; +//mod nodes; +//mod ml; mod operators; diff --git a/tests/operators.cairo b/tests/operators.cairo index 7642e31f3..d1fe988d9 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -1,2 +1,3 @@ -mod transpose_test; -mod qlinear_matmul_test; +//mod transpose_test; +//mod qlinear_matmul_test; +mod qlinear_concat_test; diff --git a/tests/operators/qlinear_concat_test.cairo b/tests/operators/qlinear_concat_test.cairo new file mode 100644 index 000000000..8132694ba --- /dev/null +++ b/tests/operators/qlinear_concat_test.cairo @@ -0,0 +1,229 @@ +use debug::PrintTrait; +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tensor, FP16x16Tensor}; +use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; +use orion::numbers::{NumberTrait, IntegerTrait}; +use orion::numbers::{i8, i32}; + +#[test] +#[available_gas(200000000000)] +fn qlinear_concat_test() { + let tensor1 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(20_u8, false), + IntegerTrait::::new(30_u8, false), + IntegerTrait::::new(40_u8, false), + ] + .span(), + ); + let tensor2 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(20_u8, false), + IntegerTrait::::new(40_u8, false), + IntegerTrait::::new(60_u8, false), + IntegerTrait::::new(80_u8, false), + ] + .span(), + ); + + let tensors = array![tensor1, tensor2].span(); + + let tensor1_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(20000, false)].span(),); + let tensor2_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(25000, false)].span(),); + + let scales = array![tensor1_scale, tensor2_scale].span(); + + let tensor1_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + let tensor2_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let zero_points = array![tensor1_zero_point, tensor2_zero_point].span(); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + + assert((*actual_output.data[0]).into() == 3, '*result[0] == 3'); + assert((*actual_output.data[1]).into() == 6, '*result[1] == 6'); + assert((*actual_output.data[2]).into() == 9, '*result[2] == 9'); + assert((*actual_output.data[3]).into() == 12, '*result[3] == 12'); + assert((*actual_output.data[4]).into() == 7, '*result[4] == 8'); + assert((*actual_output.data[5]).into() == 15, '*result[5] == 15'); + assert((*actual_output.data[6]).into() == 24, '*result[6] == 24'); + assert((*actual_output.data[7]).into() == 40, '*result[7] == 40'); +} + + + +#[test] +#[available_gas(200000000000)] +fn qlinear_concat_test_shape() { + let tensor1 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(2_u8, false), + IntegerTrait::::new(2_u8, false), + ] + .span(), + ); + let tensor2 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(8_u8, false), + IntegerTrait::::new(8_u8, false), + ] + .span(), + ); + let tensor3 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false), + ] + .span(), + ); + + + let tensors = array![tensor1, tensor2, tensor3].span(); + + let tensor1_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + let tensor2_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + let tensor3_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + + let scales = array![tensor1_scale, tensor2_scale, tensor3_scale].span(); + + let tensor1_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let tensor2_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + let tensor3_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + + let zero_points = array![tensor1_zero_point, tensor2_zero_point, tensor3_zero_point].span(); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(30000, false)].span(),); + + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + + assert((*actual_output.shape[0]).into() == 6, '*result.shape[0] == 6'); + assert((*actual_output.shape[1]).into() == 2, '*result.shape[1] == 2'); + +} + + + +#[test] +#[available_gas(200000000000)] +fn qlinear_concat_example_doc() { + let tensor1 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + IntegerTrait::::new(5_u8, false), + ] + .span(), + ); + let tensor2 = TensorTrait::< + i8 + >::new( + shape: array![2, 2].span(), + data: array![ + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + IntegerTrait::::new(1_u8, false), + ] + .span(), + ); + + let tensors = array![tensor1, tensor2].span(); + + let tensor1_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + let tensor2_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + + let scales = array![tensor1_scale, tensor2_scale].span(); + + let tensor1_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + let tensor2_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + + let zero_points = array![tensor1_zero_point, tensor2_zero_point].span(); + + let y_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + + let y_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + + let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + + assert((*actual_output.data[0]).into() == 1, '*result[0] == 1'); + assert((*actual_output.data[1]).into() == 1, '*result[1] == 1'); + assert((*actual_output.data[2]).into() == 1, '*result[2] == 1'); + assert((*actual_output.data[3]).into() == 1, '*result[3] == 1'); + assert((*actual_output.data[4]).into() == 2, '*result[4] == 2'); + assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); + assert((*actual_output.data[6]).into() == 2, '*result[4] == 2'); + assert((*actual_output.data[7]).into() == 2, '*result[5] == 2'); +} \ No newline at end of file From f973736bcc72b791fc9be386dc7d8e9923ee0f50 Mon Sep 17 00:00:00 2001 From: chachaleo Date: Thu, 9 Nov 2023 22:18:12 +0700 Subject: [PATCH 023/160] feat: qlinear_concat --- tests/lib.cairo | 10 +++++----- tests/operators.cairo | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/lib.cairo b/tests/lib.cairo index a8b090d8d..b8f3c9b96 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -1,6 +1,6 @@ -//mod numbers; -//mod performance; -//mod tensor_core; -//mod nodes; -//mod ml; +mod numbers; +mod performance; +mod tensor_core; +mod nodes; +mod ml; mod operators; diff --git a/tests/operators.cairo b/tests/operators.cairo index d1fe988d9..50063d9c0 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -1,3 +1,3 @@ -//mod transpose_test; -//mod qlinear_matmul_test; +mod transpose_test; +mod qlinear_matmul_test; mod qlinear_concat_test; From c2ac349e5583db5936f944da36b68e89f908552a Mon Sep 17 00:00:00 2001 From: chachaleo Date: Thu, 9 Nov 2023 22:29:42 +0700 Subject: [PATCH 024/160] feat: qlinear_concat --- tests/operators/qlinear_concat_test.cairo | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/operators/qlinear_concat_test.cairo b/tests/operators/qlinear_concat_test.cairo index 8132694ba..c2d18ee28 100644 --- a/tests/operators/qlinear_concat_test.cairo +++ b/tests/operators/qlinear_concat_test.cairo @@ -5,6 +5,15 @@ use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tens use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; use orion::numbers::{NumberTrait, IntegerTrait}; use orion::numbers::{i8, i32}; +fn print_span(mut span: Span) { + loop { + match span.pop_front() { + Option::Some(i) => { (*i.mag).print(); }, + Option::None(_) => { break; } + }; + }; +} + #[test] #[available_gas(200000000000)] @@ -64,14 +73,15 @@ fn qlinear_concat_test() { let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + print_span(actual_output.data); assert((*actual_output.data[0]).into() == 3, '*result[0] == 3'); assert((*actual_output.data[1]).into() == 6, '*result[1] == 6'); assert((*actual_output.data[2]).into() == 9, '*result[2] == 9'); assert((*actual_output.data[3]).into() == 12, '*result[3] == 12'); assert((*actual_output.data[4]).into() == 7, '*result[4] == 8'); assert((*actual_output.data[5]).into() == 15, '*result[5] == 15'); - assert((*actual_output.data[6]).into() == 24, '*result[6] == 24'); - assert((*actual_output.data[7]).into() == 40, '*result[7] == 40'); + assert((*actual_output.data[6]).into() == 22, '*result[6] == 22'); + assert((*actual_output.data[7]).into() == 30, '*result[7] == 30'); } From 82daa218d0d95deb45ddad6c6c1c8ee5c1d2fe6a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 09:18:45 +0200 Subject: [PATCH 025/160] fix classifier --- src/operators.cairo | 3 +- src/operators/matrix.cairo | 15 +- src/operators/ml/tree_ensemble.cairo | 1 - .../tree_ensemble_classifier.cairo | 310 ++++++++---------- .../tree_ensemble_classifier2.cairo | 197 ----------- src/operators/vec.cairo | 60 ++++ tests/ml/tree_ensemble_classifier.cairo | 17 +- 7 files changed, 216 insertions(+), 387 deletions(-) delete mode 100644 src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo create mode 100644 src/operators/vec.cairo diff --git a/src/operators.cairo b/src/operators.cairo index eee74cf89..9f8628255 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -1,4 +1,5 @@ mod tensor; mod nn; mod ml; -mod matrix; \ No newline at end of file +mod matrix; +mod vec; \ No newline at end of file diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 5f49c2b7e..1e19e0bc2 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,21 +1,22 @@ use core::array::ArrayTrait; use core::option::OptionTrait; -use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; +// use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; use orion::numbers::NumberTrait; +use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; -impl VecCopy of Copy>; -impl NullCopy of Copy>>; -impl VecDrop of Drop>; -impl NullDrop of Drop>>; - -#[derive(Copy, Drop)] struct MutMatrix { data: NullableVec, rows: usize, cols: usize, } +impl MutMatrixDestruct> of Destruct> { + fn destruct(self: MutMatrix) nopanic { + self.data.destruct() + } +} + #[generate_trait] impl MutMatrixImpl< T, MAG, +Drop, +Copy, +NumberTrait, +PartialOrd diff --git a/src/operators/ml/tree_ensemble.cairo b/src/operators/ml/tree_ensemble.cairo index 32177e813..b02ddeb4d 100644 --- a/src/operators/ml/tree_ensemble.cairo +++ b/src/operators/ml/tree_ensemble.cairo @@ -1,3 +1,2 @@ mod core; mod tree_ensemble_classifier; -mod tree_ensemble_classifier2; \ No newline at end of file diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 4d7723d8e..f4e9aac2f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -1,3 +1,9 @@ +use core::array::ArrayTrait; +use core::clone::Clone; +use core::box::BoxTrait; +use core::traits::Into; +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; use core::array::SpanTrait; use core::nullable::NullableTrait; use core::dict::Felt252DictTrait; @@ -7,10 +13,14 @@ use nullable::{match_nullable, FromNullableResult}; use orion::operators::tensor::{Tensor, TensorTrait}; use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; use orion::numbers::NumberTrait; +use orion::utils::get_row; use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; use alexandria_data_structures::array_ext::{SpanTraitExt}; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; +use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; + use debug::PrintTrait; #[derive(Destruct)] @@ -20,7 +30,7 @@ struct TreeEnsembleClassifier { class_nodeids: Span, class_treeids: Span, class_weights: Span, - class_labels: Span, + classlabels: Span, base_values: Option>, post_transform: PostTransform, } @@ -34,7 +44,6 @@ enum PostTransform { Probit, } - #[generate_trait] impl TreeEnsembleClassifierImpl< T, @@ -47,212 +56,163 @@ impl TreeEnsembleClassifierImpl< +Add, +TensorTrait, +TensorTrait, - +PrintTrait + +PrintTrait, > of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Tensor, Tensor) { - let leaf_indices = self.ensemble.leave_index_tree(X); - let scores = compute_scores(ref self, leaf_indices); - let (predictions, final_scores) = classify(ref self, scores); + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { + let leaves_index = self.ensemble.leave_index_tree(X); + let n_classes = self.classlabels.len(); + let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); + + // Set base values + if self.base_values.is_some() { + let mut base_values = self.base_values.unwrap(); + let mut row: usize = 0; + loop { + if row == res.rows { + break; + } - (predictions, final_scores) - } -} + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } + let value = *base_values.pop_front().unwrap(); + res.set(row, col, value); -fn compute_scores, +Copy, +NumberTrait, +Add, +PrintTrait>( - ref self: TreeEnsembleClassifier, leaf_indices: Tensor -) -> (Span, Felt252Dict::>) { - // Initialize the scores array, either with base_values or zeros - let num_samples = *leaf_indices.shape[0]; - let num_classes = self.class_labels.len(); - let mut scores_shape = array![num_samples, num_classes].span(); + col += 1 + }; - // Store scores in dictionary because of immutability of array. - let mut scores_data: Felt252Dict> = Default::default(); - if self.base_values.is_some() { - // Repeat base values for each sample - let mut sample_index: usize = 0; - loop { - if sample_index == num_samples { - break; + row += 1; } - - let mut class_index: usize = 0; + } else { + let mut row: usize = 0; loop { - if class_index == num_classes { + if row == res.rows { break; } - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(sample_index.into(), class_index.into()); - scores_data - .insert(key, NullableTrait::new(*self.base_values.unwrap().at(class_index))); + let mut col: usize = 0; + loop { + if col == res.cols { + break; + } - class_index += 1; - }; + res.set(row, col, NumberTrait::zero()); + + col += 1 + }; - sample_index += 1; + row += 1; + } } - } - // Compute class index mapping - let mut class_index: Felt252Dict>> = Default::default(); - let mut class_weights = self.class_weights; - let mut class_ids = self.class_ids; - let mut class_nodeids = self.class_nodeids; - let mut class_treeids = self.class_treeids; - loop { - match class_weights.pop_front() { - Option::Some(class_weight) => { - let mut class_id: usize = *class_ids.pop_front().unwrap(); - let mut node_id: usize = *class_nodeids.pop_front().unwrap(); - let mut tree_id: usize = *class_treeids.pop_front().unwrap(); + let mut class_index: Felt252Dict>> = Default::default(); + let mut i: usize = 0; + loop { + if i == self.class_treeids.len() { + break; + } + + let tid = *self.class_treeids[i]; + let nid = *self.class_nodeids[i]; - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(tree_id.into(), node_id.into()); + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key.hash(tid.into(), nid.into()); + match match_nullable(class_index.get(key)) { + FromNullableResult::Null(()) => { + class_index.insert(key, NullableTrait::new(array![i].span())); + }, + FromNullableResult::NotNull(val) => { + let mut new_val = val.unbox(); + let new_val = new_val.concat(array![i].span()); + class_index.insert(key, NullableTrait::new(new_val)); + }, + } - let value = class_index.get(key); - match match_nullable(value) { - FromNullableResult::Null(()) => { - class_index - .insert( - key, NullableTrait::new(array![(class_id, *class_weight)].span()) + i += 1; + }; + let mut i: usize = 0; + loop { + if i == res.rows { + break; + } + + let mut indices = get_row(@leaves_index, i); + let mut t_index: Array> = ArrayTrait::new(); + loop { + match indices.pop_front() { + Option::Some(index) => { + let mut key = PedersenHasherImpl::new(); + let key: felt252 = key + .hash( + (*self.ensemble.atts.nodes_treeids[*index]).into(), + (*self.ensemble.atts.nodes_nodeids[*index]).into() ); + t_index.append(class_index.get(key).deref()); }, - FromNullableResult::NotNull(val) => { - let mut new_val = value.deref(); - let new_val = new_val.concat(array![(class_id, *class_weight)].span()); - class_index.insert(key, NullableTrait::new(new_val)); - }, + Option::None(_) => { break; } }; - }, - Option::None(_) => { break; } - }; - }; - - // Update scores based on class index mapping - let mut sample_index: usize = 0; - let mut leaf_indices_data = leaf_indices.data; - loop { - match leaf_indices_data.pop_front() { - Option::Some(leaf_index) => { - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash( - (*self.ensemble.atts.nodes_treeids[*leaf_index]).into(), - (*self.ensemble.atts.nodes_nodeids[*leaf_index]).into() - ); - - match match_nullable(class_index.get(key)) { - FromNullableResult::Null(()) => { continue; }, - FromNullableResult::NotNull(class_weight_pairs) => { - let mut class_weight_pairs_span = class_weight_pairs.unbox(); + }; + let mut t_index = t_index.span(); + loop { + match t_index.pop_front() { + Option::Some(its) => { + let mut its = *its; loop { - match class_weight_pairs_span.pop_front() { - Option::Some(class_weight_pair) => { - let (class_id, class_weight) = *class_weight_pair; - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash((sample_index).into(), (class_id).into()); - - let value = scores_data.get(key); - match match_nullable(value) { - FromNullableResult::Null(()) => { - scores_data - .insert(key, NullableTrait::new(class_weight)); + match its.pop_front() { + Option::Some(it) => { + let prev_val = match res.get(i, *self.class_ids[*it]) { + Option::Some(val) => { + res + .set( + i, + *self.class_ids[*it], + val + *self.class_weights[*it] + ); }, - FromNullableResult::NotNull(val) => { - scores_data - .insert( - key, - NullableTrait::new(value.deref() + class_weight) + Option::None => { + res + .set( + i, + *self.class_ids[*it], + *self.class_weights[*it] ); }, - } + }; }, Option::None(_) => { break; } }; - } + }; }, - } - - sample_index += 1; - }, - Option::None(_) => { break; } + Option::None(_) => { break; } + }; + }; + i += 1; }; - }; - - // Apply post-transform to scores - match self.post_transform { - PostTransform::None => {}, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), - } - - (scores_shape, scores_data) -} - -fn classify< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +PartialOrd, - +TensorTrait, - +TensorTrait, ->( - ref self: TreeEnsembleClassifier, scores: (Span, Felt252Dict::>) -) -> (Tensor, Tensor) { - let (scores_shape, mut scores_data) = scores; - let num_samples = *scores_shape[0]; - let num_classes = *scores_shape[1]; - let predictions_shape = array![num_samples].span(); - let mut final_scores_shape = scores_shape; - let mut predictions_data = ArrayTrait::new(); - let mut final_scores_data = ArrayTrait::new(); - - let mut sample_index: usize = 0; - loop { - if sample_index == num_samples { - break; - } + // Post Transform + let mut new_scores = match self.post_transform { + PostTransform::None => { res }, // No action required + PostTransform::Softmax => panic_with_felt252(''), + PostTransform::Logistic => panic_with_felt252(''), + PostTransform::SoftmaxZero => panic_with_felt252(''), + PostTransform::Probit => panic_with_felt252(''), + }; - // Placeholder for the minimum value for type T - let mut max_score = NumberTrait::::min_value(); - let mut max_class_index = 0; + // Labels + let mut labels = new_scores.argmax(1); - let mut class_index: usize = 0; + let mut labels_list = ArrayTrait::new(); loop { - if class_index == num_classes { - break; - } - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash((sample_index).into(), (class_index).into()); - let score = scores_data[key].deref(); - - final_scores_data.append(score); - - if score > max_score { - max_score = score; - max_class_index = class_index; - } - - class_index += 1; + match labels.pop_front() { + Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, + Option::None(_) => { break; } + }; }; - predictions_data.append(max_class_index); - sample_index += 1; - }; - - ( - TensorTrait::new(predictions_shape, predictions_data.span()), - TensorTrait::new(final_scores_shape, final_scores_data.span()) - ) + return (labels_list.span(), new_scores); + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo deleted file mode 100644 index cc6b5f4a0..000000000 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier2.cairo +++ /dev/null @@ -1,197 +0,0 @@ -use core::array::ArrayTrait; -use core::clone::Clone; -use core::box::BoxTrait; -use core::traits::Into; -use core::option::OptionTrait; -use orion::operators::matrix::MutMatrixTrait; -use core::array::SpanTrait; -use core::nullable::NullableTrait; -use core::dict::Felt252DictTrait; -use core::dict::Felt252DictEntryTrait; -use nullable::{match_nullable, FromNullableResult}; - -use orion::operators::tensor::{Tensor, TensorTrait}; -use orion::operators::ml::tree_ensemble::core::{TreeEnsemble, TreeEnsembleImpl, TreeEnsembleTrait}; -use orion::numbers::NumberTrait; -use orion::utils::get_row; - -use alexandria_data_structures::merkle_tree::{pedersen::PedersenHasherImpl}; -use alexandria_data_structures::array_ext::{SpanTraitExt}; - -use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; - -use debug::PrintTrait; - -#[derive(Destruct)] -struct TreeEnsembleClassifier { - ensemble: TreeEnsemble, - class_ids: Span, - class_nodeids: Span, - class_treeids: Span, - class_weights: Span, - classlabels: Span, - base_values: Option>, - post_transform: PostTransform, -} - -#[derive(Copy, Drop)] -enum PostTransform { - None, - Softmax, - Logistic, - SoftmaxZero, - Probit, -} - -#[generate_trait] -impl TreeEnsembleClassifierImpl< - T, - MAG, - +Drop, - +Copy, - +NumberTrait, - +PartialOrd, - +PartialEq, - +Add, - +TensorTrait, - +TensorTrait, - +PrintTrait -> of TreeEnsembleClassifierTrait { - fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { - let leaves_index = self.ensemble.leave_index_tree(X); - let n_classes = self.classlabels.len(); - let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); - - // Set base values - if self.base_values.is_some() { - let mut base_values = self.base_values.unwrap(); - let mut row: usize = 0; - loop { - if row == res.rows { - break; - } - - let mut col: usize = 0; - loop { - if col == res.cols { - break; - } - - let value = *base_values.pop_front().unwrap(); - res.set(row, col, value); - - col += 1 - }; - - row += 1; - } - } - - let mut class_index: Felt252Dict>> = Default::default(); - let mut i: usize = 0; - loop { - if i == self.class_treeids.len() { - break; - } - - let tid = *self.class_treeids[i]; - let nid = *self.class_nodeids[i]; - - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key.hash(tid.into(), nid.into()); - match match_nullable(class_index.get(key)) { - FromNullableResult::Null(()) => { continue; }, - FromNullableResult::NotNull(val) => { - let mut new_val = val.unbox(); - let new_val = new_val.concat(array![i].span()); - class_index.insert(key, NullableTrait::new(new_val)); - }, - } - - i += 1; - }; - let mut i: usize = 0; - loop { - if i == res.rows { - break; - } - - let mut indices = get_row(@leaves_index, i); - let mut t_index: Array> = ArrayTrait::new(); - loop { - match indices.pop_front() { - Option::Some(index) => { - let mut key = PedersenHasherImpl::new(); - let key: felt252 = key - .hash( - (*self.ensemble.atts.nodes_treeids[*index]).into(), - (*self.ensemble.atts.nodes_treeids[*index]).into() - ); - t_index.append(class_index.get(key).deref()); - }, - Option::None(_) => { break; } - }; - }; - let mut t_index = t_index.span(); - loop { - match t_index.pop_front() { - Option::Some(its) => { - loop { - let mut its = *its; - match its.pop_front() { - Option::Some(it) => { - let prev_val = res.get(i, *self.class_ids[*it]); - match prev_val { - Option::Some(prev) => { - res - .set( - i, - *self.class_ids[*it], - prev + *self.class_weights[*it] - ); - }, - Option::None => { - res - .set( - i, - *self.class_ids[*it], - *self.class_weights[*it] - ); - } - } - }, - Option::None(_) => { break; } - }; - }; - }, - Option::None(_) => { break; } - }; - }; - i += 1; - }; - - // TODO: Binary case - - // Post Transform - let mut new_scores = match self.post_transform { - PostTransform::None => { res }, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), - }; - - // Labels - let mut labels = new_scores.argmax(1); - let mut labels_list = ArrayTrait::new(); - loop { - match labels.pop_front() { - Option::Some(i) => { labels_list.append(*self.classlabels[*i]); }, - Option::None(_) => { break; } - }; - }; - - return (labels, new_scores); - } -} - diff --git a/src/operators/vec.cairo b/src/operators/vec.cairo new file mode 100644 index 000000000..6fb43b6db --- /dev/null +++ b/src/operators/vec.cairo @@ -0,0 +1,60 @@ +use core::box::BoxTrait; +use core::traits::Into; +use alexandria_data_structures::vec::{VecTrait}; +use core::nullable::{Nullable, match_nullable, FromNullableResult}; +use orion::numbers::NumberTrait; + +struct NullableVec { + items: Felt252Dict>, + len: usize, +} + +impl DestructNullableVec> of Destruct> { + fn destruct(self: NullableVec) nopanic { + self.items.squash(); + } +} + +impl NullableVecImpl< + T, MAG, impl TDrop: Drop, impl TCopy: Copy, +NumberTrait +> of VecTrait, T> { + fn new() -> NullableVec { + NullableVec { items: Default::default(), len: 0 } + } + + fn get(ref self: NullableVec, index: usize) -> Option { + if (index < self.len()) { + return match match_nullable(self.items.get(index.into())) { + FromNullableResult::Null(()) => { Option::Some(NumberTrait::zero()) }, + FromNullableResult::NotNull(val) => { Option::Some(val.unbox()) }, + }; + } else { + Option::::None + } + } + + fn at(ref self: NullableVec, index: usize) -> T { + assert(index < self.len(), 'Index out of bounds'); + + return match self.get(index) { + Option::Some(val) => val, + Option::None => NumberTrait::zero(), + }; + } + + fn push(ref self: NullableVec, value: T) -> () { + self.items.insert(self.len.into(), nullable_from_box(BoxTrait::new(value))); + self.len = integer::u32_wrapping_add(self.len, 1_usize); + } + + fn set(ref self: NullableVec, index: usize, value: T) { + if index >= self.len() { + self.len = index + 1; + } + self.items.insert(index.into(), nullable_from_box(BoxTrait::new(value))); + } + + fn len(self: @NullableVec) -> usize { + *self.len + } +} diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index c5b24601a..a18811be0 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,3 +1,5 @@ +use core::option::OptionTrait; +use orion::operators::matrix::MutMatrixTrait; use core::array::SpanTrait; use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; @@ -5,14 +7,16 @@ use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{ NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl }; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier2::{ +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + use debug::PrintTrait; #[test] -#[available_gas(2000000000)] +#[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi() { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -161,10 +165,11 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - let (prediction, score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + let (labels, mut score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + // (*labels.at(0)).print(); + // (*labels.at(1)).print(); + // (*labels.at(2)).print(); - // (*score.data.at(0)).print(); - // (*score.data.at(1)).print(); - // (*score.data.at(2)).print(); + score.get(0, 0).unwrap().print(); } From e58f6dec391649cd50591b3b23d66372ca3c6f2c Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 09:39:35 +0200 Subject: [PATCH 026/160] test none post transform case --- tests/ml/tree_ensemble_classifier.cairo | 51 ++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index a18811be0..9caaec039 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -10,7 +10,7 @@ use orion::operators::ml::tree_ensemble::core::{ use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; - +use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; use debug::PrintTrait; @@ -165,11 +165,50 @@ fn test_tree_ensemble_classifier_multi() { .span() ); - let (labels, mut score) = TreeEnsembleClassifierTrait::predict(ref classifier, X); - // (*labels.at(0)).print(); - // (*labels.at(1)).print(); - // (*labels.at(2)).print(); + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); - score.get(0, 0).unwrap().print(); + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 60075, sign: false }) == true, + 'score[0, 0] == 0.9166666' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, + 'score[0, 1] == 0' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 5461, sign: false }) == true, + 'score[0, 2] == 0.08333334' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 37329, sign: false }) == true, + 'score[1, 0] == 0.56960785' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 12528, sign: false }) == true, + 'score[1, 1] == 0.19117647' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 15677, sign: false }) == true, + 'score[1, 2] == 0.23921569' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, + 'score[2, 0] == 0.30294117' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 28257, sign: false }) == true, + 'score[2, 1] == 0.43117648' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 17424, sign: false }) == true, + 'score[2, 2] == 0.26588234' + ); } From 523c09b8a12f723db93f2f0a63b18f1d4ab5e17b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 10:09:29 +0200 Subject: [PATCH 027/160] add softmax postr transform --- src/operators/matrix.cairo | 83 +++++++- .../tree_ensemble_classifier.cairo | 10 +- tests/ml/tree_ensemble_classifier.cairo | 199 +++++++++++++++++- 3 files changed, 286 insertions(+), 6 deletions(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 1e19e0bc2..3de48a7e8 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -1,6 +1,5 @@ use core::array::ArrayTrait; use core::option::OptionTrait; -// use alexandria_data_structures::vec::{VecTrait, NullableVec, NullableVecImpl}; use orion::numbers::NumberTrait; use orion::operators::vec::{VecTrait, NullableVec, NullableVecImpl}; @@ -133,4 +132,86 @@ impl MutMatrixImpl< return result.span(); } + + /// Apply softmax to the matrix along the specified axis + /// Apply softmax to the matrix along the specified axis + fn softmax<+AddEq, +Div>(ref self: MutMatrix, axis: usize) -> MutMatrix { + assert(axis < 2, 'Invalid axis'); + + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + sum_exp += value.exp(); + + row += 1; + }; + + row = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + + row += 1; + }; + + col += 1; + }; + } else { + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + sum_exp += value.exp(); + + col += 1; + }; + + col = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + + col += 1; + }; + + row += 1; + }; + } + + result + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index f4e9aac2f..e9ac8a5c6 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -57,6 +57,8 @@ impl TreeEnsembleClassifierImpl< +TensorTrait, +TensorTrait, +PrintTrait, + +AddEq, + +Div > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); @@ -195,10 +197,10 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { PostTransform::None => { res }, // No action required - PostTransform::Softmax => panic_with_felt252(''), - PostTransform::Logistic => panic_with_felt252(''), - PostTransform::SoftmaxZero => panic_with_felt252(''), - PostTransform::Probit => panic_with_felt252(''), + PostTransform::Softmax => { res.softmax(1) }, + PostTransform::Logistic => panic_with_felt252('Logistic not supported yet'), + PostTransform::SoftmaxZero => panic_with_felt252('SoftmaxZero not supported yet'), + PostTransform::Probit => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 9caaec039..3428a2fd5 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -17,7 +17,7 @@ use debug::PrintTrait; #[test] #[available_gas(200000000000)] -fn test_tree_ensemble_classifier_multi() { +fn test_tree_ensemble_classifier_multi_pt_none() { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -212,3 +212,200 @@ fn test_tree_ensemble_classifier_multi() { ); } +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_softmax() { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let classlabels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let post_transform = PostTransform::Softmax; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + classlabels, + base_values, + post_transform + }; + + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() + ); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, + 'score[0, 0] == 0.545123' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, + 'score[0, 1] == 0.217967' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, + 'score[0, 2] == 0.23691' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0] == 0.416047' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1] == 0.284965' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2] == 0.298988' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0] == 0.322535' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1] == 0.366664' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2] == 0.310801' + ); +} + From 7775465d707bdb4d1194dda9a148ffe5d2d6316a Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 10 Nov 2023 16:12:59 +0200 Subject: [PATCH 028/160] rename post transform --- .../tree_ensemble_classifier.cairo | 20 +++++++++---------- tests/ml/tree_ensemble_classifier.cairo | 14 +++---------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index e9ac8a5c6..850a28d94 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -37,11 +37,11 @@ struct TreeEnsembleClassifier { #[derive(Copy, Drop)] enum PostTransform { - None, - Softmax, - Logistic, - SoftmaxZero, - Probit, + NONE, + SOFTMAX, + LOGISTIC, + SOFTMAXZERO, + PROBIT, } #[generate_trait] @@ -196,11 +196,11 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { - PostTransform::None => { res }, // No action required - PostTransform::Softmax => { res.softmax(1) }, - PostTransform::Logistic => panic_with_felt252('Logistic not supported yet'), - PostTransform::SoftmaxZero => panic_with_felt252('SoftmaxZero not supported yet'), - PostTransform::Probit => panic_with_felt252('Probit not supported yet'), + PostTransform::NONE => { res }, // No action required + PostTransform::SOFTMAX => { res.softmax(1) }, + PostTransform::LOGISTIC => panic_with_felt252('Logistic not supported yet'), + PostTransform::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + PostTransform::PROBIT => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 3428a2fd5..18e6d99bf 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -1,20 +1,12 @@ -use core::option::OptionTrait; -use orion::operators::matrix::MutMatrixTrait; -use core::array::SpanTrait; -use core::dict::Felt252DictTrait; use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{ - NODE_MODES, TreeEnsembleAttributes, TreeEnsemble, TreeEnsembleImpl -}; +use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait }; use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; -use debug::PrintTrait; - #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_none() { @@ -136,7 +128,7 @@ fn test_tree_ensemble_classifier_multi_pt_none() { let base_values: Option> = Option::None; - let post_transform = PostTransform::None; + let post_transform = PostTransform::NONE; let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, @@ -333,7 +325,7 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { let base_values: Option> = Option::None; - let post_transform = PostTransform::Softmax; + let post_transform = PostTransform::SOFTMAX; let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, From 5d78374d3f25b9163750067f3f0136782c25a52a Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Fri, 10 Nov 2023 13:32:43 +0100 Subject: [PATCH 029/160] Implement operator --- src/operators/tensor.cairo | 1 + src/operators/tensor/core.cairo | 1 + .../implementations/tensor_fp16x16.cairo | 6 +- .../implementations/tensor_fp16x16wide.cairo | 6 +- .../implementations/tensor_fp32x32.cairo | 6 +- .../implementations/tensor_fp64x64.cairo | 6 +- .../implementations/tensor_fp8x23.cairo | 6 +- .../implementations/tensor_fp8x23wide.cairo | 6 +- .../tensor/implementations/tensor_i32.cairo | 6 +- .../tensor/implementations/tensor_i8.cairo | 6 +- .../tensor/implementations/tensor_u32.cairo | 6 +- src/operators/tensor/ml.cairo | 1 + .../tensor/ml/array_feature_extractor.cairo | 87 +++++++++++++++++++ 13 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/operators/tensor/ml.cairo create mode 100644 src/operators/tensor/ml/array_feature_extractor.cairo diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index 30403831f..612ec8c11 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -4,6 +4,7 @@ mod math; mod linalg; mod quantization; mod implementations; +mod ml; use orion::operators::tensor::core::{Tensor, TensorSerde, TensorTrait}; diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 8a3ae7e68..17ee93256 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,7 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + fn array_feature_extractor(self: @Tensor, indices: 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 508134a2f..78628105c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -288,6 +288,10 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index d87f6dd9d..e15eaeb90 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16W}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -286,6 +286,10 @@ impl FP16x16WTensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 30b85b755..58089059a 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP32x32, FP32x32Impl}; use orion::numbers::fixed_point::implementations::fp32x32::core::ONE; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -288,6 +288,10 @@ impl FP32x32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 c86420354..c09844e13 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP64x64, FP64x64Impl}; use orion::numbers::fixed_point::implementations::fp64x64::core::ONE; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -289,6 +289,10 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// 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 3ddcf0369..f043bdd5a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -287,6 +287,10 @@ impl FP8x23Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 3c36ee737..802fb078c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23W}; use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; @@ -277,6 +277,10 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } + } /// 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 bf0592c41..acbab214e 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i32, i8, NumberTrait}; use orion::operators::tensor::implementations::{tensor_u32::U32Tensor, tensor_i8::I8Tensor}; @@ -287,6 +287,10 @@ impl I32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// 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 bfadc3be5..c370543c6 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; @@ -286,6 +286,10 @@ impl I8Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2faf21b0b..667057ad3 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -7,7 +7,7 @@ use orion::numbers::fixed_point::core::FixedTrait; use orion::operators::tensor::core::{ new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_i8::I8Tensor; @@ -268,6 +268,10 @@ impl U32Tensor of TensorTrait { -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/ml.cairo b/src/operators/tensor/ml.cairo new file mode 100644 index 000000000..e9c3faa09 --- /dev/null +++ b/src/operators/tensor/ml.cairo @@ -0,0 +1 @@ +mod array_feature_extractor; \ No newline at end of file diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo new file mode 100644 index 000000000..c3918e859 --- /dev/null +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -0,0 +1,87 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::array_feature_extractor docstring +fn array_feature_extractor< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, indices: Tensor +) -> Tensor { + + assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); + + let input_shape: Span = self.shape; + let input_data: Span = self.data; + let mut last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + + let mut input_shape_counter: usize = 0; + + let mut total_elements: usize = 1; + + let mut output_shape: Array = ArrayTrait::new(); + + loop { + if input_shape_counter > input_shape.len() - 2 { + break; + } + + let mut current_shape_value = *input_shape.at(input_shape_counter); + + output_shape.append(current_shape_value); + + total_elements = total_elements * current_shape_value; + + input_shape_counter += 1; + + }; + + output_shape.append(indices.data.len()); + + let mut output_data = ArrayTrait::::new(); + + let strides: Span = TensorTrait::stride(@self); + + let mut element_counter: usize = 0; + + loop { + if element_counter > total_elements - 1 { + break; + } + + let mut base_index = element_counter * (*strides.at(strides.len() - 2)); + + let mut indices_counter: usize = 0; + + loop { + if indices_counter > indices.data.len() - 1 { + break; + } + + let mut current_indices_value = *indices.data.at(indices_counter); + + let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); + + let mut current_data_value = *input_data.at(flat_index); + + output_data.append(current_data_value); + + indices_counter += 1; + + }; + + element_counter += 1; + }; + + return TensorTrait::new(output_shape.span(), output_data.span()); + +} \ No newline at end of file From f1f60a7bc89368b17b51740ba3a107ecc12cecf3 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sat, 11 Nov 2023 00:54:30 +0100 Subject: [PATCH 030/160] Add tests --- nodegen/node/array_feature_extractor.py | 54 +++++++++++++++++++ tests/nodes.cairo | 5 +- .../array_feature_extractor_fp16x16.cairo | 22 ++++++++ .../input_0.cairo | 39 ++++++++++++++ .../input_1.cairo | 13 +++++ .../output_0.cairo | 27 ++++++++++ .../array_feature_extractor_fp8x23.cairo | 22 ++++++++ .../input_0.cairo | 39 ++++++++++++++ .../input_1.cairo | 13 +++++ .../output_0.cairo | 27 ++++++++++ tests/nodes/array_feature_extractor_i32.cairo | 22 ++++++++ .../array_feature_extractor_i32/input_0.cairo | 38 +++++++++++++ .../array_feature_extractor_i32/input_1.cairo | 13 +++++ .../output_0.cairo | 26 +++++++++ 14 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 nodegen/node/array_feature_extractor.py create mode 100644 tests/nodes/array_feature_extractor_fp16x16.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_fp16x16/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_i32.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_i32/output_0.cairo diff --git a/nodegen/node/array_feature_extractor.py b/nodegen/node/array_feature_extractor.py new file mode 100644 index 000000000..7055dc05c --- /dev/null +++ b/nodegen/node/array_feature_extractor.py @@ -0,0 +1,54 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Array_feature_extractor(RunAll): + + @staticmethod + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + @staticmethod + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + @staticmethod + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index c0950a35f..12ee077cd 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,4 +527,7 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; \ No newline at end of file +mod scatter_u32_add; +mod array_feature_extractor_fp16x16; +mod array_feature_extractor_fp8x23; +mod array_feature_extractor_i32; diff --git a/tests/nodes/array_feature_extractor_fp16x16.cairo b/tests/nodes/array_feature_extractor_fp16x16.cairo new file mode 100644 index 000000000..9dfcd177e --- /dev/null +++ b/tests/nodes/array_feature_extractor_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::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo new file mode 100644 index 000000000..a32b3a3a2 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo @@ -0,0 +1,39 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + 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: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo new file mode 100644 index 000000000..b72170ad1 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo @@ -0,0 +1,27 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + 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: 131072, 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: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, 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/nodes/array_feature_extractor_fp8x23.cairo b/tests/nodes/array_feature_extractor_fp8x23.cairo new file mode 100644 index 000000000..a249ced57 --- /dev/null +++ b/tests/nodes/array_feature_extractor_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::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo new file mode 100644 index 000000000..e92d71a5a --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo @@ -0,0 +1,39 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, 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 }); + 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: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo new file mode 100644 index 000000000..268e7335d --- /dev/null +++ b/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo @@ -0,0 +1,27 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32.cairo b/tests/nodes/array_feature_extractor_i32.cairo new file mode 100644 index 000000000..987cd02f6 --- /dev/null +++ b/tests/nodes/array_feature_extractor_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::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_0.cairo b/tests/nodes/array_feature_extractor_i32/input_0.cairo new file mode 100644 index 000000000..a922d8f8e --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/input_0.cairo @@ -0,0 +1,38 @@ +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(3); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, 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: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_1.cairo b/tests/nodes/array_feature_extractor_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/output_0.cairo b/tests/nodes/array_feature_extractor_i32/output_0.cairo new file mode 100644 index 000000000..4e64044fa --- /dev/null +++ b/tests/nodes/array_feature_extractor_i32/output_0.cairo @@ -0,0 +1,26 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From 1744d7598ccea4ccf6233218109da9c8c974de8c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 09:05:40 +0000 Subject: [PATCH 031/160] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3631dc7cc..28d6d66bd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -99,6 +99,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Ephraim Chukwu
Ephraim Chukwu

💻 Bal7hazar
Bal7hazar

🐛 Tony Stark
Tony Stark

📖 + Bilgin Koçak
Bilgin Koçak

💻 From 951ecbb8c422916185683643c2ec0b044bc3d6c6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 09:05:41 +0000 Subject: [PATCH 032/160] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b282fc04..07d81f637 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -224,6 +224,15 @@ "contributions": [ "doc" ] + }, + { + "login": "bilgin-kocak", + "name": "Bilgin Koçak", + "avatar_url": "https://avatars.githubusercontent.com/u/30844607?v=4", + "profile": "https://www.bilginkocak.com/", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, From c849d67899b6c7ceae248124d2bc945bb42cf3d9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn <113879115+raphaelDkhn@users.noreply.github.com> Date: Sun, 12 Nov 2023 11:06:59 +0200 Subject: [PATCH 033/160] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28d6d66bd..a84cbc4b8 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ See [LICENSE](https://github.com/franalgaba/onnx-cairo/blob/main/LICENSE/README. ## Contributors ✨ -Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): +Thanks goes to these wonderful people: From 61fd0d150b294d18a23e26fba8a110954c3e7070 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 16:25:57 +0100 Subject: [PATCH 034/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.array_feature_extractor.md | 50 ++++++++++++++++++ src/operators/tensor/core.cairo | 51 +++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.array_feature_extractor.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f96dd7a6f..ae7052c9a 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -95,6 +95,7 @@ * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + * [tensor.array_feature_extractor](framework/operators/tensor/tensor.array\_feature\_extractor.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 e5f7f39cf..9e024779b 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,5 +74,6 @@ You can see below the list of current supported ONNX Operators: | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | | [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | +| [ArrayFeatureExtractor](operators/tensor/tensor.array\_feature\_extractor.md) | :white\_check\_mark: | -Current Operators support: **68/156 (43%)** +Current Operators support: **69/156 (44%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 369713044..402971f7c 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -91,6 +91,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.round`](tensor.round.md) | Computes the round value of all elements in the input tensor. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | +| [`tensor.array_feature_extractor`](tensor.array_feature_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.array_feature_extractor.md b/docs/framework/operators/tensor/tensor.array_feature_extractor.md new file mode 100644 index 000000000..a852239d4 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.array_feature_extractor.md @@ -0,0 +1,50 @@ +# tensor.array_feature_extractor + +```rust + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; +``` + +Selects elements of the input tensor based on the indices passed applied to the last tensor axis. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `indices`(`Tensor`) - Tensor of indices. + +## Panics + +* Panics if indices tensor is not 1-dimensional. + +## Returns + +A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn array_feature_extractor_example() -> Tensor { + let input_tensor = TensorTrait::new( + shape: array![3, 4].span(), + data: array![ + IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), + IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), + IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) + ] + .span(), + ); + + let indices = TensorTrait::::new( + shape: array![2].span(), data: array![1, 3].span(), + ); + + return tensor.array_feature_extractor(@input_tensor, @indices); +} +>>> [[1, 3] + [5, 7] + [9, 11]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 17ee93256..47aa8ba2c 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3212,6 +3212,57 @@ trait TensorTrait { /// ``` /// fn scatter(self: @Tensor, updates: Tensor, indices: Tensor, axis: Option, reduction: Option) -> Tensor; + /// # tensor.array_feature_extractor + /// + /// ```rust + /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// ``` + /// + /// Selects elements of the input tensor based on the indices passed applied to the last tensor axis. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// + /// ## Panics + /// + /// * Panics if indices tensor is not 1-dimensional. + /// + /// ## Returns + /// + /// A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn array_feature_extractor_example() -> Tensor { + /// let input_tensor = TensorTrait::new( + /// shape: array![3, 4].span(), + /// data: array![ + /// IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), + /// IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), + /// IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) + /// ] + /// .span(), + /// ); + /// + /// let indices = TensorTrait::::new( + /// shape: array![2].span(), data: array![1, 3].span(), + /// ); + /// + /// return tensor.array_feature_extractor(@input_tensor, @indices); + /// } + /// >>> [[1, 3] + /// [5, 7] + /// [9, 11]] + /// ``` + /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; } From e2e81174a754283731466a66f3074ae15297a8a0 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 17:34:40 +0200 Subject: [PATCH 035/160] implement logistic post transform --- src/operators/matrix.cairo | 34 +- .../tree_ensemble_classifier.cairo | 17 +- tests/ml/tree_ensemble_classifier.cairo | 331 +++++++----------- 3 files changed, 165 insertions(+), 217 deletions(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index 3de48a7e8..a9a381a20 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -133,7 +133,6 @@ impl MutMatrixImpl< return result.span(); } - /// Apply softmax to the matrix along the specified axis /// Apply softmax to the matrix along the specified axis fn softmax<+AddEq, +Div>(ref self: MutMatrix, axis: usize) -> MutMatrix { assert(axis < 2, 'Invalid axis'); @@ -214,4 +213,37 @@ impl MutMatrixImpl< result } + + /// Apply the sigmoid function to each element of the matrix + fn sigmoid<+Mul, +Add, +Div>(ref self: MutMatrix) -> MutMatrix { + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col); + if value.is_some() { + let value = NumberTrait::one() + / (NumberTrait::one() + (value.unwrap() * NumberTrait::neg_one()).exp()); + + result.set(row, col, value); + } + + col += 1; + }; + + row += 1; + }; + + result + } } diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 850a28d94..d6898b961 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -32,11 +32,11 @@ struct TreeEnsembleClassifier { class_weights: Span, classlabels: Span, base_values: Option>, - post_transform: PostTransform, + post_transform: POST_TRANSFORM, } #[derive(Copy, Drop)] -enum PostTransform { +enum POST_TRANSFORM { NONE, SOFTMAX, LOGISTIC, @@ -58,7 +58,8 @@ impl TreeEnsembleClassifierImpl< +TensorTrait, +PrintTrait, +AddEq, - +Div + +Div, + +Mul > of TreeEnsembleClassifierTrait { fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); @@ -196,11 +197,11 @@ impl TreeEnsembleClassifierImpl< // Post Transform let mut new_scores = match self.post_transform { - PostTransform::NONE => { res }, // No action required - PostTransform::SOFTMAX => { res.softmax(1) }, - PostTransform::LOGISTIC => panic_with_felt252('Logistic not supported yet'), - PostTransform::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), - PostTransform::PROBIT => panic_with_felt252('Probit not supported yet'), + POST_TRANSFORM::NONE => res, // No action required + POST_TRANSFORM::SOFTMAX => res.softmax(1), + POST_TRANSFORM::LOGISTIC => res.sigmoid(), + POST_TRANSFORM::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + POST_TRANSFORM::PROBIT => panic_with_felt252('Probit not supported yet'), }; // Labels diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 18e6d99bf..12d19cd26 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -2,7 +2,7 @@ use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ - TreeEnsembleClassifier, PostTransform, TreeEnsembleClassifierTrait + TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait }; use orion::operators::tensor::implementations::tensor_fp16x16::relative_eq; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; @@ -10,203 +10,165 @@ use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_none() { - let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] - .span(); - - let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] - .span(); - - let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] - .span(); - - let class_weights: Span = array![ - FP16x16 { mag: 30583, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 2185, sign: false }, - FP16x16 { mag: 13107, sign: false }, - FP16x16 { mag: 15729, sign: false }, - FP16x16 { mag: 3932, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 32768, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 32768, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 29491, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 3277, sign: false }, - FP16x16 { mag: 6746, sign: false }, - FP16x16 { mag: 12529, sign: false }, - FP16x16 { mag: 13493, sign: false }, - ] - .span(); - - let classlabels: Span = array![0, 1, 2].span(); - - let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); - - let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); - - let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); - - let nodes_modes: Span = array![ - NODE_MODES::BRANCH_LEQ, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::BRANCH_LEQ, - NODE_MODES::LEAF, - NODE_MODES::LEAF, - ] - .span(); - - let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); - - let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); - - let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); - - let nodes_values: Span = array![ - FP16x16 { mag: 81892, sign: false }, - FP16x16 { mag: 19992, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 110300, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 44245, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 0, sign: false }, - ] - .span(); - - let tree_ids: Span = array![0, 1].span(); - - let mut root_index: Felt252Dict = Default::default(); - root_index.insert(0, 0); - root_index.insert(1, 5); - - let mut node_index: Felt252Dict = Default::default(); - node_index - .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); - node_index - .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); - node_index - .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); - node_index - .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); - node_index - .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); - node_index - .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); - node_index - .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); - node_index - .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); - node_index - .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); - node_index - .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); - - let atts = TreeEnsembleAttributes { - nodes_falsenodeids, - nodes_featureids, - nodes_missing_value_tracks_true, - nodes_modes, - nodes_nodeids, - nodes_treeids, - nodes_truenodeids, - nodes_values - }; - - let mut ensemble: TreeEnsemble = TreeEnsemble { - atts, tree_ids, root_index, node_index - }; - - let base_values: Option> = Option::None; - - let post_transform = PostTransform::NONE; - - let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { - ensemble, - class_ids, - class_nodeids, - class_treeids, - class_weights, - classlabels, - base_values, - post_transform - }; - - let mut X: Tensor = TensorTrait::new( - array![3, 3].span(), - array![ - FP16x16 { mag: 65536, sign: true }, - FP16x16 { mag: 52429, sign: true }, - FP16x16 { mag: 39322, sign: true }, - FP16x16 { mag: 26214, sign: true }, - FP16x16 { mag: 13107, sign: true }, - FP16x16 { mag: 0, sign: false }, - FP16x16 { mag: 13107, sign: false }, - FP16x16 { mag: 26214, sign: false }, - FP16x16 { mag: 39322, sign: false }, - ] - .span() - ); + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::NONE); let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); // ASSERT LABELS - assert(*labels[0] == 0, 'labels[0] == 0'); - assert(*labels[1] == 0, 'labels[1] == 0'); - assert(*labels[2] == 1, 'labels[2] == 1'); - assert(labels.len() == 3, 'len(labels) == 3'); + assert(*labels[0] == 0, 'labels[0]'); + assert(*labels[1] == 0, 'labels[1]'); + assert(*labels[2] == 1, 'labels[2]'); + assert(labels.len() == 3, 'len(labels)'); // ASSERT SCORES assert( relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 60075, sign: false }) == true, - 'score[0, 0] == 0.9166666' + 'score[0, 0]' ); assert( relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, - 'score[0, 1] == 0' + 'score[0, 1]' ); assert( relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 5461, sign: false }) == true, - 'score[0, 2] == 0.08333334' + 'score[0, 2]' ); assert( relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 37329, sign: false }) == true, - 'score[1, 0] == 0.56960785' + 'score[1, 0]' ); assert( relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 12528, sign: false }) == true, - 'score[1, 1] == 0.19117647' + 'score[1, 1]' ); assert( relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 15677, sign: false }) == true, - 'score[1, 2] == 0.23921569' + 'score[1, 2]' ); assert( relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, - 'score[2, 0] == 0.30294117' + 'score[2, 0]' ); assert( relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 28257, sign: false }) == true, - 'score[2, 1] == 0.43117648' + 'score[2, 1]' ); assert( relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 17424, sign: false }) == true, - 'score[2, 2] == 0.26588234' + 'score[2, 2]' ); } #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_softmax() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0]'); + assert(*labels[1] == 0, 'labels[1]'); + assert(*labels[2] == 1, 'labels[2]'); + assert(labels.len() == 3, 'len(labels)'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2]' + ); +} + +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_logistic() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::LOGISTIC); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 46816, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 32768, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 34132, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 41856, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 35890, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 36668, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 37693, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 39724, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 37098, sign: false }) == true, + 'score[2, 2]' + ); +} + + +// ============ HELPER ============ // + +fn tree_ensemble_classifier_helper( + post_transform: POST_TRANSFORM +) -> (TreeEnsembleClassifier, Tensor) { let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] .span(); @@ -325,8 +287,6 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { let base_values: Option> = Option::None; - let post_transform = PostTransform::SOFTMAX; - let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { ensemble, class_ids, @@ -354,50 +314,5 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { .span() ); - let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); - - // ASSERT LABELS - assert(*labels[0] == 0, 'labels[0] == 0'); - assert(*labels[1] == 0, 'labels[1] == 0'); - assert(*labels[2] == 1, 'labels[2] == 1'); - assert(labels.len() == 3, 'len(labels) == 3'); - - // ASSERT SCORES - assert( - relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 35725, sign: false }) == true, - 'score[0, 0] == 0.545123' - ); - assert( - relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 14284, sign: false }) == true, - 'score[0, 1] == 0.217967' - ); - assert( - relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 15526, sign: false }) == true, - 'score[0, 2] == 0.23691' - ); - assert( - relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, - 'score[1, 0] == 0.416047' - ); - assert( - relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, - 'score[1, 1] == 0.284965' - ); - assert( - relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, - 'score[1, 2] == 0.298988' - ); - assert( - relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, - 'score[2, 0] == 0.322535' - ); - assert( - relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, - 'score[2, 1] == 0.366664' - ); - assert( - relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, - 'score[2, 2] == 0.310801' - ); + (classifier, X) } - From 19ef9ee45d80edb0baede8980f5fe32a848adebf Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 17:54:31 +0200 Subject: [PATCH 036/160] add softmax_zero pt --- src/operators/matrix.cairo | 94 +++++++++++++++++++ .../tree_ensemble_classifier.cairo | 2 +- tests/ml/tree_ensemble_classifier.cairo | 53 +++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) diff --git a/src/operators/matrix.cairo b/src/operators/matrix.cairo index a9a381a20..0d19a7a4d 100644 --- a/src/operators/matrix.cairo +++ b/src/operators/matrix.cairo @@ -214,6 +214,100 @@ impl MutMatrixImpl< result } + /// Apply softmax to the matrix along the specified axis, treating zeros as neutral + fn softmax_zero<+AddEq, +Div, +PartialEq>( + ref self: MutMatrix, axis: usize + ) -> MutMatrix { + assert(axis < 2, 'Invalid axis'); + + let mut result = MutMatrixImpl::new(self.rows, self.cols); + + if axis == 0 { + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + sum_exp += value.exp(); + } + row += 1; + }; + + row = 0; + loop { + if row == self.rows { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + } else { + result.set(row, col, NumberTrait::zero()); + } + + row += 1; + }; + + col += 1; + }; + } else { + let mut row: usize = 0; + loop { + if row == self.rows { + break; + } + + let mut sum_exp = NumberTrait::zero(); + let mut col: usize = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + if value != NumberTrait::zero() { + sum_exp += value.exp(); + } + col += 1; + }; + + col = 0; + loop { + if col == self.cols { + break; + } + + let value = self.get(row, col).unwrap().into(); + + if value != NumberTrait::zero() { + let softmax_value = (value.exp() / sum_exp).into(); + result.set(row, col, softmax_value); + } else { + result.set(row, col, NumberTrait::zero()); + } + + col += 1; + }; + + row += 1; + }; + } + + result + } + /// Apply the sigmoid function to each element of the matrix fn sigmoid<+Mul, +Add, +Div>(ref self: MutMatrix) -> MutMatrix { let mut result = MutMatrixImpl::new(self.rows, self.cols); diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index d6898b961..75e82df4f 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -200,7 +200,7 @@ impl TreeEnsembleClassifierImpl< POST_TRANSFORM::NONE => res, // No action required POST_TRANSFORM::SOFTMAX => res.softmax(1), POST_TRANSFORM::LOGISTIC => res.sigmoid(), - POST_TRANSFORM::SOFTMAXZERO => panic_with_felt252('SoftmaxZero not supported yet'), + POST_TRANSFORM::SOFTMAXZERO => res.softmax_zero(1), POST_TRANSFORM::PROBIT => panic_with_felt252('Probit not supported yet'), }; diff --git a/tests/ml/tree_ensemble_classifier.cairo b/tests/ml/tree_ensemble_classifier.cairo index 12d19cd26..cee9ee80d 100644 --- a/tests/ml/tree_ensemble_classifier.cairo +++ b/tests/ml/tree_ensemble_classifier.cairo @@ -111,6 +111,59 @@ fn test_tree_ensemble_classifier_multi_pt_softmax() { ); } +#[test] +#[available_gas(200000000000)] +fn test_tree_ensemble_classifier_multi_pt_softmax_zero() { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAXZERO); + + let (labels, mut scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + + // ASSERT LABELS + assert(*labels[0] == 0, 'labels[0] == 0'); + assert(*labels[1] == 0, 'labels[1] == 0'); + assert(*labels[2] == 1, 'labels[2] == 1'); + assert(labels.len() == 3, 'len(labels) == 3'); + + // ASSERT SCORES + assert( + relative_eq(@scores.get(0, 0).unwrap(), @FP16x16 { mag: 45682, sign: false }) == true, + 'score[0, 0]' + ); + assert( + relative_eq(@scores.get(0, 1).unwrap(), @FP16x16 { mag: 0, sign: false }) == true, + 'score[0, 1]' + ); + assert( + relative_eq(@scores.get(0, 2).unwrap(), @FP16x16 { mag: 19853, sign: false }) == true, + 'score[0, 2]' + ); + assert( + relative_eq(@scores.get(1, 0).unwrap(), @FP16x16 { mag: 27266, sign: false }) == true, + 'score[1, 0]' + ); + assert( + relative_eq(@scores.get(1, 1).unwrap(), @FP16x16 { mag: 18675, sign: false }) == true, + 'score[1, 1]' + ); + assert( + relative_eq(@scores.get(1, 2).unwrap(), @FP16x16 { mag: 19594, sign: false }) == true, + 'score[1, 2]' + ); + assert( + relative_eq(@scores.get(2, 0).unwrap(), @FP16x16 { mag: 21137, sign: false }) == true, + 'score[2, 0]' + ); + assert( + relative_eq(@scores.get(2, 1).unwrap(), @FP16x16 { mag: 24029, sign: false }) == true, + 'score[2, 1]' + ); + assert( + relative_eq(@scores.get(2, 2).unwrap(), @FP16x16 { mag: 20368, sign: false }) == true, + 'score[2, 2]' + ); +} + + #[test] #[available_gas(200000000000)] fn test_tree_ensemble_classifier_multi_pt_logistic() { From dedb48ace675684530824d84c445a35e672e56a9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 18:17:34 +0200 Subject: [PATCH 037/160] Update tree_ensemble_classifier.cairo --- src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 75e82df4f..badaa549d 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -64,6 +64,7 @@ impl TreeEnsembleClassifierImpl< fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::) { let leaves_index = self.ensemble.leave_index_tree(X); let n_classes = self.classlabels.len(); + assert(n_classes > 1, 'binary class not supported yet'); let mut res: MutMatrix = MutMatrixImpl::new(*leaves_index.shape.at(0), n_classes); // Set base values From 8316c47d25db54ab20b15206fb0e7689719c0def Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 18:49:40 +0200 Subject: [PATCH 038/160] generate doc --- docgen/src/main.rs | 8 + docs/SUMMARY.md | 2 + .../tree-ensemble-classifier/README.md | 27 +++ .../tree_ensemble_classifier.predict.md | 199 +++++++++++++++++ .../tree_ensemble_classifier.cairo | 208 +++++++++++++++++- 5 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md create mode 100644 docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md diff --git a/docgen/src/main.rs b/docgen/src/main.rs index 54a8e9fcc..97d11b112 100644 --- a/docgen/src/main.rs +++ b/docgen/src/main.rs @@ -58,6 +58,14 @@ fn main() { let trait_name: &str = "XGBoostRegressorTrait"; doc_trait(trait_path, doc_path, label); doc_functions(trait_path, doc_path, trait_name, label); + + // TREE ENSEMBLE CLASSIFIER DOC + let trait_path = "src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo"; + let doc_path = "docs/framework/operators/machine-learning/tree-ensemble-classifier"; + let label = "tree_ensemble_classifier"; + let trait_name: &str = "TreeEnsembleClassifierTrait"; + doc_trait(trait_path, doc_path, label); + doc_functions(trait_path, doc_path, trait_name, label); } fn doc_trait(trait_path: &str, doc_path: &str, label: &str) { diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index ea9613ce3..2de1306f5 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -106,6 +106,8 @@ * [nn.thresholded\_relu](framework/operators/neural-network/nn.thresholded_relu.md) * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) + * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) + * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md new file mode 100644 index 000000000..a3028a8be --- /dev/null +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md @@ -0,0 +1,27 @@ +# Tree Ensemble Classifier + +`TreeEnsembleClassifierTrait` provides a trait definition for tree ensemble classification problem. + +```rust +use orion::operators::ml::TreeEnsembleClassifierTrait; +``` + +### Data types + +Orion supports currently only fixed point data types for `TreeEnsembleClassifierTrait`. + +| Data type | dtype | +| -------------------- | ------------------------------------------------------------- | +| Fixed point (signed) | `TreeRegressorTrait` | + +### How to construct `TreeEnsembleClassifier` + +You can utilize [this notebook](https://colab.research.google.com/drive/1qem56rUKJcNongXsLZ16_869q8395prz#scrollTo=V3qGW_kfXudk) to translate parameters from your ONNX TreeEnsembleClassifier model into Cairo code. Efforts are underway to integrate this functionality into Giza-CLI, aiming to enhance the user experience. + + +*** + +| function | description | +| ------------------------------------------------------------------------- | ------------------------------------------- | +| [`tree_ensemble_classifier.predict`](tree_ensemble_classifier.predict.md) | Returns the top class for each of N inputs. | + diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md new file mode 100644 index 000000000..8998fcfb7 --- /dev/null +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md @@ -0,0 +1,199 @@ +# TreeEnsembleClassifier::predict + +```rust + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); +``` + +Tree Ensemble classifier. Returns the top class for each of N inputs. + +## Args + +* `self`: TreeEnsembleClassifier - A TreeEnsembleClassifier object. +* `X`: Input 2D tensor. + +## Returns + +* N Top class for each point +* The class score Matrix for each class, for each point. + +## Type Constraints + +`TreeEnsembleClassifier` and `X` must be fixed points + +## Examples + +```rust +use orion::numbers::FP16x16; +use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; +use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait +}; +use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + +fn tree_ensemble_classifier_helper( + post_transform: POST_TRANSFORM +) -> (TreeEnsembleClassifier, Tensor) { + let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + .span(); + + let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + .span(); + + let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + .span(); + + let class_weights: Span = array![ + FP16x16 { mag: 30583, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 2185, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 15729, sign: false }, + FP16x16 { mag: 3932, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 32768, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 29491, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 3277, sign: false }, + FP16x16 { mag: 6746, sign: false }, + FP16x16 { mag: 12529, sign: false }, + FP16x16 { mag: 13493, sign: false }, + ] + .span(); + + let classlabels: Span = array![0, 1, 2].span(); + + let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + + let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + + let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + + let nodes_modes: Span = array![ + NODE_MODES::BRANCH_LEQ, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::BRANCH_LEQ, + NODE_MODES::LEAF, + NODE_MODES::LEAF, + ] + .span(); + + let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + + let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + + let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + + let nodes_values: Span = array![ + FP16x16 { mag: 81892, sign: false }, + FP16x16 { mag: 19992, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 110300, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 44245, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 0, sign: false }, + ] + .span(); + + let tree_ids: Span = array![0, 1].span(); + + let mut root_index: Felt252Dict = Default::default(); + root_index.insert(0, 0); + root_index.insert(1, 5); + + let mut node_index: Felt252Dict = Default::default(); + node_index + .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + node_index + .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + node_index + .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + node_index + .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + node_index + .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + node_index + .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + node_index + .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + node_index + .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + node_index + .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + node_index + .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + + let atts = TreeEnsembleAttributes { + nodes_falsenodeids, + nodes_featureids, + nodes_missing_value_tracks_true, + nodes_modes, + nodes_nodeids, + nodes_treeids, + nodes_truenodeids, + nodes_values + }; + + let mut ensemble: TreeEnsemble = TreeEnsemble { + atts, tree_ids, root_index, node_index + }; + + let base_values: Option> = Option::None; + + let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + ensemble, + class_ids, + class_nodeids, + class_treeids, + class_weights, + classlabels, + base_values, + post_transform + }; + + let mut X: Tensor = TensorTrait::new( + array![3, 3].span(), + array![ + FP16x16 { mag: 65536, sign: true }, + FP16x16 { mag: 52429, sign: true }, + FP16x16 { mag: 39322, sign: true }, + FP16x16 { mag: 26214, sign: true }, + FP16x16 { mag: 13107, sign: true }, + FP16x16 { mag: 0, sign: false }, + FP16x16 { mag: 13107, sign: false }, + FP16x16 { mag: 26214, sign: false }, + FP16x16 { mag: 39322, sign: false }, + ] + .span() + ); + + (classifier, X) +} + +fn test_tree_ensemble_classifier_multi_pt_softmax() -> (Span, MutMatrix::) { + let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + + let (labels, scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + (labels, scores) +} + +>>> +([0, 0, 1], + [ + [0.545123, 0.217967, 0.23691], + [0.416047, 0.284965, 0.298988], + [0.322535, 0.366664, 0.310801], + ]) +``` diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index badaa549d..0adb8a638 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -44,7 +44,213 @@ enum POST_TRANSFORM { PROBIT, } -#[generate_trait] +/// Trait +/// +/// predict - Returns the top class for each of N inputs. +trait TreeEnsembleClassifierTrait { + /// # TreeEnsembleClassifier::predict + /// + /// ```rust + /// fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); + /// ``` + /// + /// Tree Ensemble classifier. Returns the top class for each of N inputs. + /// + /// ## Args + /// + /// * `self`: TreeEnsembleClassifier - A TreeEnsembleClassifier object. + /// * `X`: Input 2D tensor. + /// + /// ## Returns + /// + /// * N Top class for each point + /// * The class score Matrix for each class, for each point. + /// + /// ## Type Constraints + /// + /// `TreeEnsembleClassifier` and `X` must be fixed points + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::FP16x16; + /// use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; + /// use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; + /// use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + /// TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait + /// }; + /// use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; + /// + /// fn tree_ensemble_classifier_helper( + /// post_transform: POST_TRANSFORM + ///) -> (TreeEnsembleClassifier, Tensor) { + /// let class_ids: Span = array![0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] + /// .span(); + /// + /// let class_nodeids: Span = array![2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 3, 3, 3, 4, 4, 4] + /// .span(); + /// + /// let class_treeids: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + /// .span(); + /// + /// let class_weights: Span = array![ + /// FP16x16 { mag: 30583, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 2185, sign: false }, + /// FP16x16 { mag: 13107, sign: false }, + /// FP16x16 { mag: 15729, sign: false }, + /// FP16x16 { mag: 3932, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 32768, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 32768, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 29491, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 3277, sign: false }, + /// FP16x16 { mag: 6746, sign: false }, + /// FP16x16 { mag: 12529, sign: false }, + /// FP16x16 { mag: 13493, sign: false }, + /// ] + /// .span(); + /// + /// let classlabels: Span = array![0, 1, 2].span(); + /// + /// let nodes_falsenodeids: Span = array![4, 3, 0, 0, 0, 2, 0, 4, 0, 0].span(); + /// + /// let nodes_featureids: Span = array![1, 0, 0, 0, 0, 1, 0, 0, 0, 0].span(); + /// + /// let nodes_missing_value_tracks_true: Span = array![0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(); + /// + /// let nodes_modes: Span = array![ + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::BRANCH_LEQ, + /// NODE_MODES::LEAF, + /// NODE_MODES::LEAF, + /// ] + /// .span(); + /// + /// let nodes_nodeids: Span = array![0, 1, 2, 3, 4, 0, 1, 2, 3, 4].span(); + /// + /// let nodes_treeids: Span = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1].span(); + /// + /// let nodes_truenodeids: Span = array![1, 2, 0, 0, 0, 1, 0, 3, 0, 0].span(); + /// + /// let nodes_values: Span = array![ + /// FP16x16 { mag: 81892, sign: false }, + /// FP16x16 { mag: 19992, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 110300, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 44245, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 0, sign: false }, + /// ] + /// .span(); + /// + /// let tree_ids: Span = array![0, 1].span(); + /// + /// let mut root_index: Felt252Dict = Default::default(); + /// root_index.insert(0, 0); + /// root_index.insert(1, 5); + /// + /// let mut node_index: Felt252Dict = Default::default(); + /// node_index + /// .insert(2089986280348253421170679821480865132823066470938446095505822317253594081284, 0); + /// node_index + /// .insert(2001140082530619239661729809084578298299223810202097622761632384561112390979, 1); + /// node_index + /// .insert(2592670241084192212354027440049085852792506518781954896144296316131790403900, 2); + /// node_index + /// .insert(2960591271376829378356567803618548672034867345123727178628869426548453833420, 3); + /// node_index + /// .insert(458933264452572171106695256465341160654132084710250671055261382009315664425, 4); + /// node_index + /// .insert(1089549915800264549621536909767699778745926517555586332772759280702396009108, 5); + /// node_index + /// .insert(1321142004022994845681377299801403567378503530250467610343381590909832171180, 6); + /// node_index + /// .insert(2592987851775965742543459319508348457290966253241455514226127639100457844774, 7); + /// node_index + /// .insert(2492755623019086109032247218615964389726368532160653497039005814484393419348, 8); + /// node_index + /// .insert(1323616023845704258113538348000047149470450086307731200728039607710316625916, 9); + /// + /// let atts = TreeEnsembleAttributes { + /// nodes_falsenodeids, + /// nodes_featureids, + /// nodes_missing_value_tracks_true, + /// nodes_modes, + /// nodes_nodeids, + /// nodes_treeids, + /// nodes_truenodeids, + /// nodes_values + /// }; + /// + /// let mut ensemble: TreeEnsemble = TreeEnsemble { + /// atts, tree_ids, root_index, node_index + /// }; + /// + /// let base_values: Option> = Option::None; + /// + /// let mut classifier: TreeEnsembleClassifier = TreeEnsembleClassifier { + /// ensemble, + /// class_ids, + /// class_nodeids, + /// class_treeids, + /// class_weights, + /// classlabels, + /// base_values, + /// post_transform + /// }; + /// + /// let mut X: Tensor = TensorTrait::new( + /// array![3, 3].span(), + /// array![ + /// FP16x16 { mag: 65536, sign: true }, + /// FP16x16 { mag: 52429, sign: true }, + /// FP16x16 { mag: 39322, sign: true }, + /// FP16x16 { mag: 26214, sign: true }, + /// FP16x16 { mag: 13107, sign: true }, + /// FP16x16 { mag: 0, sign: false }, + /// FP16x16 { mag: 13107, sign: false }, + /// FP16x16 { mag: 26214, sign: false }, + /// FP16x16 { mag: 39322, sign: false }, + /// ] + /// .span() + /// ); + /// + /// (classifier, X) + /// } + /// + /// fn test_tree_ensemble_classifier_multi_pt_softmax() -> (Span, MutMatrix::) { + /// let (mut classifier, X) = tree_ensemble_classifier_helper(POST_TRANSFORM::SOFTMAX); + /// + /// let (labels, scores) = TreeEnsembleClassifierTrait::predict(ref classifier, X); + /// (labels, scores) + /// } + /// + /// >>> + /// ([0, 0, 1], + /// [ + /// [0.545123, 0.217967, 0.23691], + /// [0.416047, 0.284965, 0.298988], + /// [0.322535, 0.366664, 0.310801], + /// ]) + /// ``` + /// + fn predict(ref self: TreeEnsembleClassifier, X: Tensor) -> (Span, MutMatrix::); +} + impl TreeEnsembleClassifierImpl< T, MAG, From 18ab7831bfb606864efc01573ec184ddd7f2ef37 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 19:05:00 +0200 Subject: [PATCH 039/160] fix doc --- docs/SUMMARY.md | 2 +- .../machine-learning/tree-ensemble-classifier/README.md | 4 ++-- .../tree_ensemble_classifier.predict.md | 4 ++-- src/operators/ml.cairo | 7 +++++++ .../ml/tree_ensemble/tree_ensemble_classifier.cairo | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b1265951a..a5d4b59c3 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,7 +114,7 @@ * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) - * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) + * [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md index a3028a8be..d3baaad57 100644 --- a/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/README.md @@ -21,7 +21,7 @@ You can utilize [this notebook](https://colab.research.google.com/drive/1qem56rU *** -| function | description | -| ------------------------------------------------------------------------- | ------------------------------------------- | +| function | description | +| --- | --- | | [`tree_ensemble_classifier.predict`](tree_ensemble_classifier.predict.md) | Returns the top class for each of N inputs. | diff --git a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md index 8998fcfb7..6d839e873 100644 --- a/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md +++ b/docs/framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md @@ -25,8 +25,8 @@ Tree Ensemble classifier. Returns the top class for each of N inputs. ```rust use orion::numbers::FP16x16; use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; -use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; -use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ +use orion::operators::ml::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; +use orion::operators::ml::{ TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait }; use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; diff --git a/src/operators/ml.cairo b/src/operators/ml.cairo index 721751fdd..826f51f51 100644 --- a/src/operators/ml.cairo +++ b/src/operators/ml.cairo @@ -20,3 +20,10 @@ use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_ use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp8x23::FP8x23XGBoostRegressor; use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp32x32::FP32x32XGBoostRegressor; use orion::operators::ml::xgboost_regressor::implementations::xgboost_regressor_fp64x64::FP64x64XGBoostRegressor; + +use orion::operators::ml::tree_ensemble::core::{ + TreeEnsemble, TreeEnsembleAttributes, TreeEnsembleImpl, NODE_MODES +}; +use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + TreeEnsembleClassifier, TreeEnsembleClassifierImpl, TreeEnsembleClassifierTrait, POST_TRANSFORM +}; diff --git a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo index 0adb8a638..8925cb560 100644 --- a/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo +++ b/src/operators/ml/tree_ensemble/tree_ensemble_classifier.cairo @@ -75,8 +75,8 @@ trait TreeEnsembleClassifierTrait { /// ```rust /// use orion::numbers::FP16x16; /// use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor, U32Tensor}; - /// use orion::operators::ml::tree_ensemble::core::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; - /// use orion::operators::ml::tree_ensemble::tree_ensemble_classifier::{ + /// use orion::operators::ml::{NODE_MODES, TreeEnsembleAttributes, TreeEnsemble}; + /// use orion::operators::ml::{ /// TreeEnsembleClassifier, POST_TRANSFORM, TreeEnsembleClassifierTrait /// }; /// use orion::operators::matrix::{MutMatrix, MutMatrixImpl}; From b2de055f8e23fdc83973e2985d403d84884e64cf Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Sun, 12 Nov 2023 19:08:59 +0200 Subject: [PATCH 040/160] Update SUMMARY.md --- docs/SUMMARY.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b1265951a..580ccf1dc 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,7 +114,11 @@ * [nn.gemm](framework/operators/neural-network/nn.gemm.md) * [Machine Learning](framework/operators/machine-learning/README.md) * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) +<<<<<<< Updated upstream * [tree.predict](framework/operators/machine-learning/tree-regressor/tree_ensemble_classifier.predict.md) +======= + * [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md) +>>>>>>> Stashed changes * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) From 5bf67a9b4d447070e0dce7a1ceac8fcaa2dc8e8b Mon Sep 17 00:00:00 2001 From: Raphael Doukhan Date: Sun, 12 Nov 2023 17:14:31 +0000 Subject: [PATCH 041/160] GITBOOK-39: change request with no subject merged in GitBook --- docs/framework/get-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/get-started.md b/docs/framework/get-started.md index adad08a5a..972ecc2e4 100644 --- a/docs/framework/get-started.md +++ b/docs/framework/get-started.md @@ -14,7 +14,7 @@ Orion supports **Cairo and Scarb v2.3.0** **Step 1: Install Cairo** -There are different ways to install Cairo. Use the one that suits you best: [Cairo installer](https://cairo-book.github.io/ch01-01-installation.html). +There are different ways to install Cairo. Use the one that suits you best: [Cairo installer.](https://book.cairo-lang.org/ch01-01-installation.html) **Step 2: Setup Language Server** From 4cb5ae71d6adff51b03850f939338558e227d847 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 20:21:26 +0100 Subject: [PATCH 042/160] Fix bug and add tests for 1D/2D tensors --- nodegen/node/array_feature_extractor.py | 187 ++++++++++++++---- .../tensor/ml/array_feature_extractor.cairo | 30 ++- tests/nodes.cairo | 14 +- ... array_feature_extractor_1D_fp16x16.cairo} | 2 +- .../input_0.cairo | 17 ++ .../input_1.cairo | 0 .../output_0.cairo | 15 ++ ...> array_feature_extractor_1D_fp8x23.cairo} | 2 +- .../input_0.cairo | 17 ++ .../input_1.cairo | 0 .../output_0.cairo | 15 ++ ...o => array_feature_extractor_1D_i32.cairo} | 2 +- .../input_0.cairo | 16 ++ .../input_1.cairo | 0 .../output_0.cairo | 14 ++ .../array_feature_extractor_2D_fp16x16.cairo | 22 +++ .../input_0.cairo | 26 +++ .../input_1.cairo | 13 ++ .../output_0.cairo | 20 ++ .../array_feature_extractor_2D_fp8x23.cairo | 22 +++ .../input_0.cairo} | 17 +- .../input_1.cairo | 13 ++ .../output_0.cairo | 20 ++ .../array_feature_extractor_2D_i32.cairo | 22 +++ .../input_0.cairo | 25 +++ .../input_1.cairo | 13 ++ .../output_0.cairo | 19 ++ .../array_feature_extractor_3D_fp16x16.cairo | 22 +++ .../input_0.cairo | 30 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 14 +- .../array_feature_extractor_3D_fp8x23.cairo | 22 +++ .../input_0.cairo | 24 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 27 +++ .../array_feature_extractor_3D_i32.cairo | 22 +++ .../input_0.cairo | 28 +-- .../input_1.cairo | 13 ++ .../output_0.cairo | 12 +- 39 files changed, 691 insertions(+), 112 deletions(-) rename tests/nodes/{array_feature_extractor_fp16x16.cairo => array_feature_extractor_1D_fp16x16.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_1D_fp16x16}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo rename tests/nodes/{array_feature_extractor_fp8x23.cairo => array_feature_extractor_1D_fp8x23.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo rename tests/nodes/{array_feature_extractor_fp8x23 => array_feature_extractor_1D_fp8x23}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo rename tests/nodes/{array_feature_extractor_i32.cairo => array_feature_extractor_1D_i32.cairo} (91%) create mode 100644 tests/nodes/array_feature_extractor_1D_i32/input_0.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_1D_i32}/input_1.cairo (100%) create mode 100644 tests/nodes/array_feature_extractor_1D_i32/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23.cairo rename tests/nodes/{array_feature_extractor_fp8x23/output_0.cairo => array_feature_extractor_2D_fp8x23/input_0.cairo} (72%) create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/input_0.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_2D_i32/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_fp16x16.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_3D_fp16x16}/input_0.cairo (81%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo rename tests/nodes/{array_feature_extractor_fp16x16 => array_feature_extractor_3D_fp16x16}/output_0.cairo (74%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23.cairo rename tests/nodes/{array_feature_extractor_fp8x23 => array_feature_extractor_3D_fp8x23}/input_0.cairo (77%) create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo create mode 100644 tests/nodes/array_feature_extractor_3D_i32.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_3D_i32}/input_0.cairo (81%) create mode 100644 tests/nodes/array_feature_extractor_3D_i32/input_1.cairo rename tests/nodes/{array_feature_extractor_i32 => array_feature_extractor_3D_i32}/output_0.cairo (90%) diff --git a/nodegen/node/array_feature_extractor.py b/nodegen/node/array_feature_extractor.py index 7055dc05c..bf8071e60 100644 --- a/nodegen/node/array_feature_extractor.py +++ b/nodegen/node/array_feature_extractor.py @@ -6,49 +6,156 @@ class Array_feature_extractor(RunAll): @staticmethod - def array_feature_extractor_i32(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) + def array_feature_extractor_3D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.I32, z.shape, z.flatten()) + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) - name = "array_feature_extractor_i32" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + name = "array_feature_extractor_3D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_3D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_3D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() @staticmethod - def array_feature_extractor_fp8x23(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) - - x = Tensor(Dtype.FP8x23, x.shape, to_fp( - x.flatten(), FixedImpl.FP8x23)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.FP8x23, z.shape, to_fp( - z.flatten(), FixedImpl.FP8x23)) - - name = "array_feature_extractor_fp8x23" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) - - + def array_feature_extractor_2D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_2D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_2D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (3, 4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_2D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() + + @staticmethod - def array_feature_extractor_fp16x16(): - x = np.random.randint(-3, 3, (2, 3, 4)).astype(np.float64) - y = np.array([1, 3]).astype(np.uint32) - z = (x[..., y]) - - x = Tensor(Dtype.FP16x16, x.shape, to_fp( - x.flatten(), FixedImpl.FP16x16)) - y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.FP16x16, z.shape, to_fp( - z.flatten(), FixedImpl.FP16x16)) - - name = "array_feature_extractor_fp16x16" - make_node([x, y], [z], name) - make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) \ No newline at end of file + def array_feature_extractor_1D(): + def array_feature_extractor_i32(): + x = np.random.randint(-3, 3, (4)).astype(np.int32) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.I32, z.shape, z.flatten()) + + name = "array_feature_extractor_1D_i32" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp8x23(): + x = np.random.randint(-3, 3, (4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "array_feature_extractor_1D_fp8x23" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + + def array_feature_extractor_fp16x16(): + x = np.random.randint(-3, 3, (4)).astype(np.float64) + y = np.array([1, 3]).astype(np.uint32) + z = (x[..., y]) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "array_feature_extractor_1D_fp16x16" + make_node([x, y], [z], name) + make_test([x, y], z, "TensorTrait::array_feature_extractor(@input_0, input_1);", name) + + array_feature_extractor_i32() + array_feature_extractor_fp8x23() + array_feature_extractor_fp16x16() \ No newline at end of file diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index c3918e859..31b8a24aa 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -22,7 +22,29 @@ fn array_feature_extractor< let input_shape: Span = self.shape; let input_data: Span = self.data; - let mut last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + + if input_shape.len() == 1 { + + let mut output_data = ArrayTrait::::new(); + + let mut indices_counter: usize = 0; + + loop { + if indices_counter > indices.data.len() - 1 { + break; + } + + let mut current_indices_value = *indices.data.at(indices_counter); + + let mut current_data_value = *input_data.at(current_indices_value); + + output_data.append(current_data_value); + + indices_counter += 1; + }; + + return TensorTrait::new(indices.shape, output_data.span()); + } let mut input_shape_counter: usize = 0; @@ -58,7 +80,11 @@ fn array_feature_extractor< break; } - let mut base_index = element_counter * (*strides.at(strides.len() - 2)); + let mut base_index = if strides.len() > 1 { + element_counter * (*strides.at(strides.len() - 2)) + } else { + 0 + }; let mut indices_counter: usize = 0; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 12ee077cd..342d8c6e8 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -527,7 +527,13 @@ mod scatter_i8_axis1; mod scatter_i8_axis1_max; mod scatter_u32_default; mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_fp16x16; -mod array_feature_extractor_fp8x23; -mod array_feature_extractor_i32; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; diff --git a/tests/nodes/array_feature_extractor_fp16x16.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_fp16x16.cairo rename to tests/nodes/array_feature_extractor_1D_fp16x16.cairo index 9dfcd177e..a24571c9d 100644 --- a/tests/nodes/array_feature_extractor_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_fp16x16() { +fn test_array_feature_extractor_1D_fp16x16() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo new file mode 100644 index 000000000..e9eefbabf --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo @@ -0,0 +1,17 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_fp16x16/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo new file mode 100644 index 000000000..2472bf84b --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_fp8x23.cairo rename to tests/nodes/array_feature_extractor_1D_fp8x23.cairo index a249ced57..72ccfa9fc 100644 --- a/tests/nodes/array_feature_extractor_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_fp8x23() { +fn test_array_feature_extractor_1D_fp8x23() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo new file mode 100644 index 000000000..e3f37db08 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo @@ -0,0 +1,17 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_fp8x23/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo new file mode 100644 index 000000000..26340a8b6 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32.cairo b/tests/nodes/array_feature_extractor_1D_i32.cairo similarity index 91% rename from tests/nodes/array_feature_extractor_i32.cairo rename to tests/nodes/array_feature_extractor_1D_i32.cairo index 987cd02f6..0d8dde9d8 100644 --- a/tests/nodes/array_feature_extractor_i32.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32.cairo @@ -11,7 +11,7 @@ use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] -fn test_array_feature_extractor_i32() { +fn test_array_feature_extractor_1D_i32() { let input_0 = input_0::input_0(); let input_1 = input_1::input_1(); let z = output_0::output_0(); diff --git a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo new file mode 100644 index 000000000..761aa81c4 --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo @@ -0,0 +1,16 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_1.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo similarity index 100% rename from tests/nodes/array_feature_extractor_i32/input_1.cairo rename to tests/nodes/array_feature_extractor_1D_i32/input_1.cairo diff --git a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo new file mode 100644 index 000000000..b5a56f1ff --- /dev/null +++ b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo new file mode 100644 index 000000000..7023d621a --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_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::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_2D_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo new file mode 100644 index 000000000..4742c7e7d --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo @@ -0,0 +1,26 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo new file mode 100644 index 000000000..c2ebb541a --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo @@ -0,0 +1,20 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo new file mode 100644 index 000000000..06608774f --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_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::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_2D_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo similarity index 72% rename from tests/nodes/array_feature_extractor_fp8x23/output_0.cairo rename to tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo index 268e7335d..8b577178a 100644 --- a/tests/nodes/array_feature_extractor_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo @@ -4,23 +4,22 @@ use orion::operators::tensor::FP8x23Tensor; use orion::numbers::FixedTrait; use orion::numbers::FP8x23; -fn output_0() -> Tensor { +fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); shape.append(3); - shape.append(2); + shape.append(4); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 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: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo new file mode 100644 index 000000000..91bd19d12 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo @@ -0,0 +1,20 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32.cairo b/tests/nodes/array_feature_extractor_2D_i32.cairo new file mode 100644 index 000000000..29368f5f3 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_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::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_2D_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo new file mode 100644 index 000000000..c7b027450 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo @@ -0,0 +1,25 @@ +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(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + 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: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, 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/nodes/array_feature_extractor_2D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo new file mode 100644 index 000000000..c9d6cedf5 --- /dev/null +++ b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo new file mode 100644 index 000000000..eab071c49 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_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::FP16x16TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_3D_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo similarity index 81% rename from tests/nodes/array_feature_extractor_fp16x16/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo index a32b3a3a2..559a6ec9b 100644 --- a/tests/nodes/array_feature_extractor_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo @@ -11,29 +11,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo similarity index 74% rename from tests/nodes/array_feature_extractor_fp16x16/output_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo index b72170ad1..dc974161d 100644 --- a/tests/nodes/array_feature_extractor_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo @@ -11,17 +11,17 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - 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: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo new file mode 100644 index 000000000..8315e0caf --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_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::FP8x23TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_3D_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo similarity index 77% rename from tests/nodes/array_feature_extractor_fp8x23/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo index e92d71a5a..b74c32e6e 100644 --- a/tests/nodes/array_feature_extractor_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo @@ -11,29 +11,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo new file mode 100644 index 000000000..093210ec7 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo @@ -0,0 +1,27 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_i32.cairo b/tests/nodes/array_feature_extractor_3D_i32.cairo new file mode 100644 index 000000000..e8688a4e9 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_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::I32TensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_array_feature_extractor_3D_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::array_feature_extractor(@input_0, input_1); + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/input_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo similarity index 81% rename from tests/nodes/array_feature_extractor_i32/input_0.cairo rename to tests/nodes/array_feature_extractor_3D_i32/input_0.cairo index a922d8f8e..e53f9a696 100644 --- a/tests/nodes/array_feature_extractor_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo @@ -10,29 +10,29 @@ fn input_0() -> Tensor { shape.append(4); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 2, sign: true }); + 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: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, 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: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, 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: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo new file mode 100644 index 000000000..c575ffe22 --- /dev/null +++ b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo @@ -0,0 +1,13 @@ +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(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/array_feature_extractor_i32/output_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo similarity index 90% rename from tests/nodes/array_feature_extractor_i32/output_0.cairo rename to tests/nodes/array_feature_extractor_3D_i32/output_0.cairo index 4e64044fa..56e50441e 100644 --- a/tests/nodes/array_feature_extractor_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo @@ -11,16 +11,16 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + 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: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From b5ec8c0169ec5290be2b3c5b8636059963faa02f Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sun, 12 Nov 2023 21:01:03 +0100 Subject: [PATCH 043/160] Add assertion for indices range --- src/operators/tensor/ml/array_feature_extractor.cairo | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 31b8a24aa..0ad7942a8 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -36,6 +36,8 @@ fn array_feature_extractor< let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < *input_shape.at(0), 'Indices out of range'); + let mut current_data_value = *input_data.at(current_indices_value); output_data.append(current_data_value); @@ -46,6 +48,8 @@ fn array_feature_extractor< return TensorTrait::new(indices.shape, output_data.span()); } + let last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + let mut input_shape_counter: usize = 0; let mut total_elements: usize = 1; @@ -95,6 +99,8 @@ fn array_feature_extractor< let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < last_tensor_axis, 'Indices out of range'); + let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); let mut current_data_value = *input_data.at(flat_index); From 4b0b52998cc3fe218cc4cdd49c9a0c4137710802 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Mon, 13 Nov 2023 02:43:13 +0100 Subject: [PATCH 044/160] Feat: not operator added --- nodegen/helpers.py | 21 ++++++++++++++++++- nodegen/node/not.py | 17 +++++++++++++++ src/operators/tensor.cairo | 2 +- .../tensor/implementations/tensor_bool.cairo | 12 +++++------ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/not.cairo | 8 +++---- tests/nodes.cairo | 2 ++ tests/nodes/not_bool.cairo | 20 ++++++++++++++++++ tests/nodes/not_bool/input_0.cairo | 13 ++++++++++++ tests/nodes/not_bool/output_0.cairo | 13 ++++++++++++ 10 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 nodegen/node/not.py create mode 100644 tests/nodes/not_bool.cairo create mode 100644 tests/nodes/not_bool/input_0.cairo create mode 100644 tests/nodes/not_bool/output_0.cairo diff --git a/nodegen/helpers.py b/nodegen/helpers.py index c5b7e7de1..cdcd12d4a 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -15,6 +15,7 @@ class Dtype(Enum): I8 = 'I8' I32 = 'I32' U32 = 'U32' + Bool = "Bool" class FixedImpl(Enum): @@ -62,6 +63,10 @@ def make_test(inputs: [Tensor], output: Tensor, func_sig: str, file_name: str, t code.append("\n\nuse array::{ArrayTrait, SpanTrait};\n") code.append("use orion::operators::tensor::TensorTrait;\n") match type_of_first_input: + case Dtype.Bool: + code.append( + "use orion::operators::tensor::BoolTensor;\n" + ) case Dtype.U32: code.append( "use orion::operators::tensor::U32Tensor;\n") @@ -78,6 +83,9 @@ def make_test(inputs: [Tensor], output: Tensor, func_sig: str, file_name: str, t code.append( "use orion::operators::tensor::FP16x16Tensor;\n") match type_of_output: + case Dtype.Bool: + code.append( + "use orion::operators::tensor::BoolTensorPartialEq;\n") case Dtype.U32: code.append( "use orion::operators::tensor::U32TensorPartialEq;\n") @@ -169,6 +177,9 @@ def __build_tensor_code(tensor: Tensor, name: str, type_string: str, is_fixed: b ] match tensor.dtype: + case Dtype.Bool: + result.append( + "use orion::operators::tensor::BoolTensor;\n") case Dtype.U32: result.append( "use orion::operators::tensor::U32Tensor;\n") @@ -198,7 +209,10 @@ def __build_tensor_code(tensor: Tensor, name: str, type_string: str, is_fixed: b "use orion::numbers::FP16x16;\n") result.append(f"\nfn {name}() -> Tensor<{type_string}> {{\n") - result.append(" let mut shape = ArrayTrait::::new();\n") + if Dtype.Bool: + result.append(" let mut shape = ArrayTrait::new();\n") + else: + result.append(" let mut shape = ArrayTrait::::new();\n") for dim in tensor.shape: result.append(f" shape.append({dim});\n") result.append("\n let mut data = ArrayTrait::new();\n") @@ -206,6 +220,10 @@ def __build_tensor_code(tensor: Tensor, name: str, type_string: str, is_fixed: b for val in tensor.data: result.append( f" data.append({type_string} {{ mag: {abs(int(val))}, sign: {str(val < 0).lower()} }});\n") + elif ((is_signed_int== False) & (is_fixed == False)): + for val in tensor.data: + result.append( + f" data.append({str(val < 0).lower()});\n") else: for val in tensor.data: result.append(f" data.append({abs(int(val))});\n") @@ -222,6 +240,7 @@ def __convert_tensor_to_cairo(tensor: Tensor, name: str) -> []: Dtype.I32: ('i32', False, True), Dtype.I8: ('i8', False, True), Dtype.U32: ('u32', False, False), + Dtype.Bool: ('bool', False, False), } dtype_info = dtype_mapping.get(tensor.dtype) diff --git a/nodegen/node/not.py b/nodegen/node/not.py new file mode 100644 index 000000000..6a0f44d65 --- /dev/null +++ b/nodegen/node/not.py @@ -0,0 +1,17 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_node, make_test, Tensor, Dtype + +class Not(RunAll): + @staticmethod + def not_bool(): + x = np.random.uniform(True, False, (1, 1)).astype(bool) + y = ~(x) + + x = Tensor(Dtype.Bool, x.shape, x.flatten()) + y = Tensor(Dtype.Bool, y.shape, y.flatten()) + + + name = "not_bool" + make_node([x], [y], name) + make_test([x], y, "input_0", name) \ No newline at end of file diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index e5b767975..72359ce26 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -31,6 +31,6 @@ use orion::operators::tensor::implementations::tensor_u32::{ }; use orion::operators::tensor::implementations::tensor_bool::{ - BoolTensor + BoolTensor, BoolTensorAdd, BoolTensorSub, BoolTensorMul, BoolTensorDiv, BoolTensorPartialEq }; diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 5b0ee08b9..833de5b8c 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -240,7 +240,7 @@ impl BoolTensor of TensorTrait { } /// Implements addition for `Tensor` using the `Add` trait. -impl boolTensorAdd of Add> { +impl BoolTensorAdd of Add> { /// Adds two `Tensor` instances element-wise. /// /// # Arguments @@ -255,7 +255,7 @@ impl boolTensorAdd of Add> { } /// Implements subtraction for `Tensor` using the `Sub` trait. -impl boolTensorSub of Sub> { +impl BoolTensorSub of Sub> { /// Subtracts two `Tensor` instances element-wise. /// /// # Arguments @@ -270,7 +270,7 @@ impl boolTensorSub of Sub> { } /// Implements multiplication for `Tensor` using the `Mul` trait. -impl boolTensorMul of Mul> { +impl BoolTensorMul of Mul> { /// Multiplies two `Tensor` instances element-wise. /// /// # Arguments @@ -285,7 +285,7 @@ impl boolTensorMul of Mul> { } /// Implements division for `Tensor` using the `Div` trait. -impl boolTensorDiv of Div> { +impl BoolTensorDiv of Div> { /// Divides two `Tensor` instances element-wise. /// /// # Arguments @@ -300,7 +300,7 @@ impl boolTensorDiv of Div> { } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. -impl boolTensorPartialEq of PartialEq> { +impl BoolTensorPartialEq of PartialEq> { fn eq(lhs: @Tensor, rhs: @Tensor) -> bool { tensor_eq(*lhs, *rhs) } @@ -310,7 +310,7 @@ impl boolTensorPartialEq of PartialEq> { } } -impl boolTryIntobool of TryInto { +impl BoolTryIntobool of TryInto { fn try_into(self: bool) -> Option { Option::Some(self) } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index d8c5a56f4..fe756f373 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -35,3 +35,4 @@ mod sign; mod and; mod neg; mod where; +mod not; diff --git a/src/operators/tensor/math/not.cairo b/src/operators/tensor/math/not.cairo index a727de4e5..9e9659e6d 100644 --- a/src/operators/tensor/math/not.cairo +++ b/src/operators/tensor/math/not.cairo @@ -4,10 +4,10 @@ use option::OptionTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::operators::tensor::implementations::{tensor_bool::BoolTensor}; // Cf TensorTrait::not docstring - fn not < T, MAG, @@ -16,13 +16,13 @@ fn not < impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop -> (mut z: Tensor) -> Tensor { - let mut data_result = ArrayTrait::::new(); +> (mut z: Tensor) -> Tensor { + let mut data_result = ArrayTrait::::new(); loop { match z.data.pop_front() { Option::Some(item) => { - data_result.append(!*item); + data_result.append((!*item)); }, Option::None(_) => { diff --git a/tests/nodes.cairo b/tests/nodes.cairo index d867b2277..96a5d8152 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -474,4 +474,6 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; +mod not_bool; + diff --git a/tests/nodes/not_bool.cairo b/tests/nodes/not_bool.cairo new file mode 100644 index 000000000..1c5489895 --- /dev/null +++ b/tests/nodes/not_bool.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::BoolTensor; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::utils::assert_eq; + +#[test] +#[available_gas(2000000000)] +fn test_not_bool() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0; + + assert_eq(y, z); +} \ No newline at end of file diff --git a/tests/nodes/not_bool/input_0.cairo b/tests/nodes/not_bool/input_0.cairo new file mode 100644 index 000000000..2b0e42256 --- /dev/null +++ b/tests/nodes/not_bool/input_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file diff --git a/tests/nodes/not_bool/output_0.cairo b/tests/nodes/not_bool/output_0.cairo new file mode 100644 index 000000000..73de3117f --- /dev/null +++ b/tests/nodes/not_bool/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} \ No newline at end of file From 33ae8dead1b06796869b547444ce2d874f2cbe8f Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 15:59:40 +0100 Subject: [PATCH 045/160] Add nodegen script --- nodegen/node/sequence_empty.py | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 nodegen/node/sequence_empty.py diff --git a/nodegen/node/sequence_empty.py b/nodegen/node/sequence_empty.py new file mode 100644 index 000000000..91dc78dbc --- /dev/null +++ b/nodegen/node/sequence_empty.py @@ -0,0 +1,81 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, Dtype, Tensor + + +class Sequence_empty(RunAll): + + @staticmethod + def sequence_empty_u32(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.uint32) + t = Tensor(Dtype.U32, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_u32", + ) + + default() + + @staticmethod + def sequence_empty_i32(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.int32) + t = Tensor(Dtype.I32, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_i32", + ) + + default() + + @staticmethod + def sequence_empty_i8(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.int8) + t = Tensor(Dtype.I8, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_i8", + ) + + default() + + @staticmethod + def sequence_empty_fp8x23(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.float64) + t = Tensor(Dtype.FP8x23, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_fp8x23", + ) + + default() + + @staticmethod + def sequence_empty_fp16x16(): + def default(): + shape=(0,) + x = np.zeros(shape, dtype=np.float64) + t = Tensor(Dtype.FP16x16, shape, x.flatten()) + make_test( + inputs=[], + output=[t], + func_sig="TensorTrait::sequence_empty()", + name="sequence_empty_fp16x16", + ) + + default() From 49e04edc46bc4cd4ca536e30e16da82cdf36c4a5 Mon Sep 17 00:00:00 2001 From: Dincer Guner Date: Mon, 13 Nov 2023 20:32:14 +0300 Subject: [PATCH 046/160] implement reduce_mean --- Scarb.toml | 1 + docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.reduce_mean.md | 42 +++ nodegen/node/reduce_mean.py | 288 ++++++++++++++++++ src/operators/tensor/core.cairo | 45 +++ src/operators/tensor/helpers.cairo | 24 ++ .../tensor/implementations/tensor_bool.cairo | 9 + .../implementations/tensor_fp16x16.cairo | 9 + .../implementations/tensor_fp16x16wide.cairo | 9 + .../implementations/tensor_fp32x32.cairo | 9 + .../implementations/tensor_fp64x64.cairo | 9 + .../implementations/tensor_fp8x23.cairo | 9 + .../implementations/tensor_fp8x23wide.cairo | 9 + .../tensor/implementations/tensor_i32.cairo | 9 + .../tensor/implementations/tensor_i8.cairo | 9 + .../tensor/implementations/tensor_u32.cairo | 9 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/reduce_mean.cairo | 192 ++++++++++++ tests/nodes.cairo | 20 ++ tests/nodes/reduce_mean_fp16x16_1D.cairo | 20 ++ .../reduce_mean_fp16x16_1D/input_0.cairo | 15 + .../reduce_mean_fp16x16_1D/output_0.cairo | 13 + .../nodes/reduce_mean_fp16x16_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../reduce_mean_fp16x16_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_mean_fp16x16_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_fp8x23_1D.cairo | 20 ++ .../nodes/reduce_mean_fp8x23_1D/input_0.cairo | 15 + .../reduce_mean_fp8x23_1D/output_0.cairo | 13 + .../nodes/reduce_mean_fp8x23_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_mean_fp8x23_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_mean_fp8x23_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_i32_1D.cairo | 20 ++ tests/nodes/reduce_mean_i32_1D/input_0.cairo | 15 + tests/nodes/reduce_mean_i32_1D/output_0.cairo | 13 + tests/nodes/reduce_mean_i32_2D_axis_1.cairo | 20 ++ .../reduce_mean_i32_2D_axis_1/input_0.cairo | 17 ++ .../reduce_mean_i32_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_mean_i32_2D_default.cairo | 20 ++ .../reduce_mean_i32_2D_default/input_0.cairo | 17 ++ .../reduce_mean_i32_2D_default/output_0.cairo | 14 + tests/nodes/reduce_mean_i32_2D_keepdims.cairo | 20 ++ .../reduce_mean_i32_2D_keepdims/input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_mean_i8_1D.cairo | 20 ++ tests/nodes/reduce_mean_i8_1D/input_0.cairo | 15 + tests/nodes/reduce_mean_i8_1D/output_0.cairo | 13 + tests/nodes/reduce_mean_i8_2D_axis_1.cairo | 20 ++ .../reduce_mean_i8_2D_axis_1/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_mean_i8_2D_default.cairo | 20 ++ .../reduce_mean_i8_2D_default/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_default/output_0.cairo | 14 + tests/nodes/reduce_mean_i8_2D_keepdims.cairo | 20 ++ .../reduce_mean_i8_2D_keepdims/input_0.cairo | 17 ++ .../reduce_mean_i8_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_mean_u32_1D.cairo | 20 ++ tests/nodes/reduce_mean_u32_1D/input_0.cairo | 14 + tests/nodes/reduce_mean_u32_1D/output_0.cairo | 12 + tests/nodes/reduce_mean_u32_2D_axis_1.cairo | 20 ++ .../reduce_mean_u32_2D_axis_1/input_0.cairo | 16 + .../reduce_mean_u32_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_mean_u32_2D_default.cairo | 20 ++ .../reduce_mean_u32_2D_default/input_0.cairo | 16 + .../reduce_mean_u32_2D_default/output_0.cairo | 13 + tests/nodes/reduce_mean_u32_2D_keepdims.cairo | 20 ++ .../reduce_mean_u32_2D_keepdims/input_0.cairo | 16 + .../output_0.cairo | 11 + 80 files changed, 1697 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.reduce_mean.md create mode 100644 nodegen/node/reduce_mean.py create mode 100644 src/operators/tensor/math/reduce_mean.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo diff --git a/Scarb.toml b/Scarb.toml index 84f1195c9..f28aa8bd1 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,6 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion" [dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } +alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" } [scripts] diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..8afe831e4 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.reduce_mean](framework/operators/tensor/tensor.reduce\_mean.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..324cc244d 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.reduce_mean.md b/docs/framework/operators/tensor/tensor.reduce_mean.md new file mode 100644 index 000000000..633f8ab00 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_mean.md @@ -0,0 +1,42 @@ +## tensor.reduce_mean + +```rust + fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; +``` + +Computes the mean of the input tensor's elements along the provided axes. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. +* `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. +* `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axes reduced by meaning its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_mean_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_mean` function as follows. + return tensor.reduce_mean(axes: array![1].span(), + keepdims: Option::None(()), + noop_with_empty_axes: Option::None(())); +} +>>> [[1,2],[5,6]] +``` diff --git a/nodegen/node/reduce_mean.py b/nodegen/node/reduce_mean.py new file mode 100644 index 000000000..6f1119323 --- /dev/null +++ b/nodegen/node/reduce_mean.py @@ -0,0 +1,288 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Reduce_mean(RunAll): + @staticmethod + def reduce_mean_u32(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.uint32) + y = np.mean(x, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_mean_u32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_i32(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int32) + y = np.mean(x, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_mean_i32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_i8(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int8) + y = np.mean(x, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, keepdims=False).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_mean_i8_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_fp8x23(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.mean(x, keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_mean_fp8x23_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_mean_fp8x23_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=False) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_mean_fp8x23_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_mean_fp8x23_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_mean_1D() + reduce_mean_2D() + + @staticmethod + def reduce_mean_fp16x16(): + def reduce_mean_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.mean(x, keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_mean_fp16x16_1D" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_mean_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_mean_fp16x16_2D_default" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, keepdims=False) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_mean_fp16x16_2D_keepdims" + make_test( + [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.mean(x, axis=(1), keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_mean_fp16x16_2D_axis_1" + make_test( + [x], y, "input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_mean_1D() + reduce_mean_2D() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..f48407807 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,50 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.reduce_mean + /// + /// ```rust + /// fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the mean of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by meaning its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_mean_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_mean(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[1,2],[5,6]] + /// ``` + /// + fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 0aad721d7..6b65eb736 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -317,3 +317,27 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. +fn get_all_axes(shape: Span) -> Span{ + let mut ret: Array = ArrayTrait::new(); + let mut i: usize = 0; + let stop_i = shape.len() - 1; + loop { + ret.append(i); + if i == stop_i { + break (); + } + i += 1; + }; + ret.span() +} \ No newline at end of file diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..26351c601 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,15 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..90cfbcf64 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,15 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..d0ec261b7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,15 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 f764b1920..f77fb80ec 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,15 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 6cded29b3..1ef4b2693 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,15 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 fdcdac1eb..28ba13668 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,15 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..4d61e066e 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,15 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 8017ab300..5e799c9bd 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,15 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 4f2731b80..88f814937 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,15 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 2f3c3a2ef..e293bc52f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,15 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..ad6ed146e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod reduce_mean; diff --git a/src/operators/tensor/math/reduce_mean.cairo b/src/operators/tensor/math/reduce_mean.cairo new file mode 100644 index 000000000..7d64d85b5 --- /dev/null +++ b/src/operators/tensor/math/reduce_mean.cairo @@ -0,0 +1,192 @@ +use core::option::OptionTrait; +use core::traits::Div; +use core::traits::TryInto; +use core::traits::Into; + +use array::ArrayTrait; +use array::SpanTrait; + +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; + +use alexandria_sorting::bubble_sort; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + + +/// Cf: TensorTrait::reduce_mean docstring +fn reduce_mean< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TDiv: Div, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option +) -> Tensor { + let noop_with_empty_axes = match noop_with_empty_axes { + Option::Some(noop_with_empty_axes) => noop_with_empty_axes, + Option::None(_) => { + false + }, + }; + let axes = match axes { + Option::Some(axes) => { + if(axes.len() == 0) { + get_all_axes(*self.shape) + } + else { + assert(axes.len() == axes.unique().len(), 'duplicated axis.'); + let mut axes_arr = ArrayTrait::new(); + let mut copy_axes = axes; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + axes_arr.append(*axis); + }, + Option::None(_) => { + break; + } + }; + }; + let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); + sorted_axes + } + }, + Option::None(_) => { + if (noop_with_empty_axes == true) { + return *self; + } + get_all_axes(*self.shape) + }, + }; + let keepdims = match keepdims { + Option::Some(keepdims) => keepdims, + Option::None(_) => { + true + }, + }; + + let mut axis_c = 0; + let mut copy_axes = axes; + let mut shape = *self.shape; + let mut data = *self.data; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + if (shape.len() == 1) { + let current_mean = accumulate_mean::(data, shape, shape, 0); + shape = array![].span(); + data = array![current_mean].span(); + break(); + } + let mut temp_data = ArrayTrait::new(); + let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let data_len = len_from_shape(temp_shape); + let mut index: usize = 0; + loop { + let indices = unravel_index(index, temp_shape); + let current_mean = accumulate_mean::(data, shape, indices, *axis-axis_c); + + temp_data.append(current_mean); + + index += 1; + if index == data_len { + break (); + }; + }; + shape = temp_shape; + data = temp_data.span(); + axis_c += 1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut axes_copy = axes; + if keepdims == true { + shape = *self.shape; + loop { + match axes_copy.pop_front() { + Option::Some(axis) => { + shape = reduce_output_shape(shape, *axis, true); + }, + Option::None(_) => { + break; + } + }; + }; + return TensorTrait::::new(shape, data); + } else { + return TensorTrait::::new(shape, data); + } +} + +/// Helper function that accumulates the mean of elements along a specific axis. +/// +/// # Arguments +/// * `input_data` - The input's data. +/// * `input_shape` - The input's shape. +/// * `output_indices` - A span of output indices. +/// * `axis` - The axis along which to accumulate the mean. +/// +/// # Panics +/// * Panics if gas limit is exceeded during execution. +/// +/// # Returns +/// * A value representing the accumulated mean along the specified axis. +fn accumulate_mean< + T, + MAG, + impl TNumber: NumberTrait, + impl TDiv: Div, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut input_data: Span, input_shape: Span, output_indices: Span, axis: usize +) -> T { + let axis_len = *(input_shape)[axis]; + let mut acc: T = NumberTrait::zero(); + + let mut axis_index: T = NumberTrait::zero(); + let mut axis_indexu32 = 0; + + if (input_shape).len() > 1 { + loop { + if axis_indexu32 == axis_len { + break (); + } + + let input_indices = combine_indices(output_indices, axis_indexu32, axis); + let input_index = ravel_index(input_shape, input_indices); + let ele = *(input_data)[input_index]; + acc += ele; + axis_index += NumberTrait::one(); + axis_indexu32 +=1; + }; + } else { + loop { + match input_data.pop_front() { + Option::Some(item) => { + acc += *item; + axis_index += NumberTrait::one(); + axis_indexu32 +=1; + }, + Option::None(_) => { break; } + }; + }; + } + // let axis_index: T = NumberTrait::::new(axis_index.try_into().unwrap(), false); + return acc/axis_index; +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..7df444889 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,23 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_mean_fp16x16_1D; +mod reduce_mean_fp16x16_2D_default; +mod reduce_mean_fp16x16_2D_keepdims; +mod reduce_mean_fp16x16_2D_axis_1; +mod reduce_mean_fp8x23_1D; +mod reduce_mean_fp8x23_2D_default; +mod reduce_mean_fp8x23_2D_keepdims; +mod reduce_mean_fp8x23_2D_axis_1; +mod reduce_mean_i32_1D; +mod reduce_mean_i32_2D_default; +mod reduce_mean_i32_2D_keepdims; +mod reduce_mean_i32_2D_axis_1; +mod reduce_mean_i8_1D; +mod reduce_mean_i8_2D_default; +mod reduce_mean_i8_2D_keepdims; +mod reduce_mean_i8_2D_axis_1; +mod reduce_mean_u32_1D; +mod reduce_mean_u32_2D_default; +mod reduce_mean_u32_2D_keepdims; +mod reduce_mean_u32_2D_axis_1; diff --git a/tests/nodes/reduce_mean_fp16x16_1D.cairo b/tests/nodes/reduce_mean_fp16x16_1D.cairo new file mode 100644 index 000000000..fff2a717f --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo new file mode 100644 index 000000000..4ce1ac478 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo new file mode 100644 index 000000000..c1a241ef9 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo new file mode 100644 index 000000000..d7ac8e7cc --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..c5e778de8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 32768, sign: false }); + data.append(FP16x16 { mag: 163840, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default.cairo new file mode 100644 index 000000000..4daa61cb0 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo new file mode 100644 index 000000000..cb0b45c75 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 98304, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo new file mode 100644 index 000000000..aadf6ca8d --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp16x16_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..f49fbed25 --- /dev/null +++ b/tests/nodes/reduce_mean_fp16x16_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 98304, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D.cairo b/tests/nodes/reduce_mean_fp8x23_1D.cairo new file mode 100644 index 000000000..6f0b2fce3 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo new file mode 100644 index 000000000..e0b0864ea --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo new file mode 100644 index 000000000..ce0d44c93 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo new file mode 100644 index 000000000..4eb932a74 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..11d2f60eb --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 4194304, sign: false }); + data.append(FP8x23 { mag: 20971520, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default.cairo new file mode 100644 index 000000000..aba87b8ed --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo new file mode 100644 index 000000000..b0971092f --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 12582912, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo new file mode 100644 index 000000000..9aa5ebf31 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_fp8x23_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..7d6a238a0 --- /dev/null +++ b/tests/nodes/reduce_mean_fp8x23_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 12582912, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_1D.cairo b/tests/nodes/reduce_mean_i32_1D.cairo new file mode 100644 index 000000000..1a3ee408f --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_1D/input_0.cairo b/tests/nodes/reduce_mean_i32_1D/input_0.cairo new file mode 100644 index 000000000..0f01c1e62 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D/input_0.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_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_1D/output_0.cairo b/tests/nodes/reduce_mean_i32_1D/output_0.cairo new file mode 100644 index 000000000..8f879b6fd --- /dev/null +++ b/tests/nodes/reduce_mean_i32_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1.cairo new file mode 100644 index 000000000..c0f26b36e --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..33f9f46e3 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_axis_1/output_0.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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_default.cairo b/tests/nodes/reduce_mean_i32_2D_default.cairo new file mode 100644 index 000000000..60c974c13 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_default/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_default/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo new file mode 100644 index 000000000..a2da83559 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims.cairo new file mode 100644 index 000000000..fa68cbd94 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..15657a928 --- /dev/null +++ b/tests/nodes/reduce_mean_i32_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_1D.cairo b/tests/nodes/reduce_mean_i8_1D.cairo new file mode 100644 index 000000000..283a41dac --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_1D/input_0.cairo b/tests/nodes/reduce_mean_i8_1D/input_0.cairo new file mode 100644 index 000000000..1d76655fb --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_1D/output_0.cairo b/tests/nodes/reduce_mean_i8_1D/output_0.cairo new file mode 100644 index 000000000..7e87c24f4 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1.cairo new file mode 100644 index 000000000..0cc13fcd0 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..9689a7aa4 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_default.cairo b/tests/nodes/reduce_mean_i8_2D_default.cairo new file mode 100644 index 000000000..88b0c9080 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo new file mode 100644 index 000000000..47c647ea8 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims.cairo new file mode 100644 index 000000000..f46833611 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_i8_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..3b2ebf796 --- /dev/null +++ b/tests/nodes/reduce_mean_i8_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_1D.cairo b/tests/nodes/reduce_mean_u32_1D.cairo new file mode 100644 index 000000000..02df97953 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_1D/input_0.cairo b/tests/nodes/reduce_mean_u32_1D/input_0.cairo new file mode 100644 index 000000000..60317db10 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D/input_0.cairo @@ -0,0 +1,14 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_1D/output_0.cairo b/tests/nodes/reduce_mean_u32_1D/output_0.cairo new file mode 100644 index 000000000..35f3cdfce --- /dev/null +++ b/tests/nodes/reduce_mean_u32_1D/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1.cairo new file mode 100644 index 000000000..6a5790d28 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..8e871bbfd --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_default.cairo b/tests/nodes/reduce_mean_u32_2D_default.cairo new file mode 100644 index 000000000..33ea58412 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_default/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_default/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo new file mode 100644 index 000000000..54c4dbbc0 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_default/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims.cairo new file mode 100644 index 000000000..82a019f4c --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_mean_u32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..abdf2e9d5 --- /dev/null +++ b/tests/nodes/reduce_mean_u32_2D_keepdims/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} From 617c8815ea83f7521994dbe8c51970f36abec8d4 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 19:46:05 +0100 Subject: [PATCH 047/160] Add tests and implementation --- src/operators/tensor/core.cairo | 4 ++++ .../tensor/implementations/tensor_bool.cairo | 5 ++++- .../implementations/tensor_fp16x16.cairo | 4 ++++ .../implementations/tensor_fp16x16wide.cairo | 4 ++++ .../implementations/tensor_fp32x32.cairo | 4 ++++ .../implementations/tensor_fp64x64.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23.cairo | 4 ++++ .../implementations/tensor_fp8x23wide.cairo | 4 ++++ .../tensor/implementations/tensor_i32.cairo | 4 ++++ .../tensor/implementations/tensor_i8.cairo | 4 ++++ .../tensor/implementations/tensor_u32.cairo | 4 ++++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/sequence_empty.cairo | 18 ++++++++++++++++++ tests/nodes.cairo | 5 +++++ tests/nodes/sequence_empty_fp16x16.cairo | 18 ++++++++++++++++++ .../sequence_empty_fp16x16/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_fp8x23.cairo | 18 ++++++++++++++++++ .../nodes/sequence_empty_fp8x23/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_i32.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_i32/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_i8.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_i8/output_0.cairo | 17 +++++++++++++++++ tests/nodes/sequence_empty_u32.cairo | 18 ++++++++++++++++++ tests/nodes/sequence_empty_u32/output_0.cairo | 16 ++++++++++++++++ 24 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/math/sequence_empty.cairo create mode 100644 tests/nodes/sequence_empty_fp16x16.cairo create mode 100644 tests/nodes/sequence_empty_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_empty_fp8x23.cairo create mode 100644 tests/nodes/sequence_empty_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_empty_i32.cairo create mode 100644 tests/nodes/sequence_empty_i32/output_0.cairo create mode 100644 tests/nodes/sequence_empty_i8.cairo create mode 100644 tests/nodes/sequence_empty_i8/output_0.cairo create mode 100644 tests/nodes/sequence_empty_u32.cairo create mode 100644 tests/nodes/sequence_empty_u32/output_0.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..c364213e1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,9 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// # tensor.sequence_empty + /// TODO + fn sequence_empty() -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..88e59599e 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -308,10 +308,13 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } - fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..40e86a42b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..2e5938c71 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 f764b1920..bc4a15ebe 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 6cded29b3..90a6d6383 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 fdcdac1eb..da8c8b15a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..45f6939d5 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 8017ab300..6a8eb9803 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 4f2731b80..d87c51a92 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// 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 2f3c3a2ef..d830a3499 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_empty() -> Array> { + math::sequence_empty::sequence_empty::() + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..8926f3db3 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_empty; diff --git a/src/operators/tensor/math/sequence_empty.cairo b/src/operators/tensor/math/sequence_empty.cairo new file mode 100644 index 000000000..4e32a0429 --- /dev/null +++ b/src/operators/tensor/math/sequence_empty.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; + + +fn sequence_empty, impl TDrop: Drop>() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + let tensor = TensorTrait::new(shape.span(), data.span()); + + sequence.append(tensor); + + sequence +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..3aa54bd4c 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,8 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_empty_fp16x16; +mod sequence_empty_fp8x23; +mod sequence_empty_i32; +mod sequence_empty_i8; +mod sequence_empty_u32; diff --git a/tests/nodes/sequence_empty_fp16x16.cairo b/tests/nodes/sequence_empty_fp16x16.cairo new file mode 100644 index 000000000..745c52c01 --- /dev/null +++ b/tests/nodes/sequence_empty_fp16x16.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_fp16x16() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_fp16x16/output_0.cairo b/tests/nodes/sequence_empty_fp16x16/output_0.cairo new file mode 100644 index 000000000..afa31e131 --- /dev/null +++ b/tests/nodes/sequence_empty_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_fp8x23.cairo b/tests/nodes/sequence_empty_fp8x23.cairo new file mode 100644 index 000000000..8d8e3f047 --- /dev/null +++ b/tests/nodes/sequence_empty_fp8x23.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_fp8x23() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_fp8x23/output_0.cairo b/tests/nodes/sequence_empty_fp8x23/output_0.cairo new file mode 100644 index 000000000..68ec1797b --- /dev/null +++ b/tests/nodes/sequence_empty_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_i32.cairo b/tests/nodes/sequence_empty_i32.cairo new file mode 100644 index 000000000..68b8f1f5e --- /dev/null +++ b/tests/nodes/sequence_empty_i32.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_i32() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_i32/output_0.cairo b/tests/nodes/sequence_empty_i32/output_0.cairo new file mode 100644 index 000000000..9a3cb338b --- /dev/null +++ b/tests/nodes/sequence_empty_i32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_i8.cairo b/tests/nodes/sequence_empty_i8.cairo new file mode 100644 index 000000000..c08a9bf45 --- /dev/null +++ b/tests/nodes/sequence_empty_i8.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_i8() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_i8/output_0.cairo b/tests/nodes/sequence_empty_i8/output_0.cairo new file mode 100644 index 000000000..123ac1980 --- /dev/null +++ b/tests/nodes/sequence_empty_i8/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_empty_u32.cairo b/tests/nodes/sequence_empty_u32.cairo new file mode 100644 index 000000000..0b20e2c65 --- /dev/null +++ b/tests/nodes/sequence_empty_u32.cairo @@ -0,0 +1,18 @@ +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_empty_u32() { + let z = output_0::output_0(); + + let y = TensorTrait::sequence_empty(); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_empty_u32/output_0.cairo b/tests/nodes/sequence_empty_u32/output_0.cairo new file mode 100644 index 000000000..e2bdd6e71 --- /dev/null +++ b/tests/nodes/sequence_empty_u32/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() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(0); + + let mut data = ArrayTrait::new(); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From 9d394daa915a6a35b069817c0bd7029c01b94c9e Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 14:01:17 +0100 Subject: [PATCH 048/160] Implement shrink operator --- src/numbers.cairo | 164 +++++++++++++++++- src/numbers/fixed_point/core.cairo | 1 + .../implementations/fp16x16/core.cairo | 4 + .../implementations/fp16x16wide/core.cairo | 4 + .../implementations/fp32x32/core.cairo | 6 +- .../implementations/fp64x64/core.cairo | 6 + .../implementations/fp8x23/core.cairo | 4 + .../implementations/fp8x23wide/core.cairo | 4 + src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/shrink.cairo | 55 ++++++ 21 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 src/operators/tensor/math/shrink.cairo diff --git a/src/numbers.cairo b/src/numbers.cairo index 6c6a06c86..1471c09f0 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -35,6 +35,7 @@ trait NumberTrait { fn tanh(self: T) -> T; fn zero() -> T; fn is_zero(self: T) -> bool; + fn half() -> T; fn one() -> T; fn is_one(self: T) -> bool; fn neg_one() -> T; @@ -50,9 +51,11 @@ trait NumberTrait { fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; fn bitwise_and(lhs: T, rhs: T) -> T; + fn add(lhs: T, rhs: T) -> T; + fn sub(lhs: T, rhs: T) -> T; } -use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; +use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub}; use orion::numbers::fixed_point::implementations::fp8x23::math::core as core_fp8x23; use orion::numbers::fixed_point::implementations::fp8x23::math::comp as comp_fp8x23; @@ -164,6 +167,10 @@ impl FP8x23Number of NumberTrait { core_fp8x23::eq(@self, @FP8x23Impl::ZERO()) } + fn half() -> FP8x23 { + FP8x23Impl::HALF() + } + fn one() -> FP8x23 { FP8x23Impl::ONE() } @@ -231,9 +238,17 @@ impl FP8x23Number of NumberTrait { fn bitwise_and(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { comp_fp8x23::bitwise_and(lhs, rhs) } + + fn add(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + FP8x23Add::add(lhs, rhs) + } + + fn sub(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + FP8x23Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; +use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub}; use orion::numbers::fixed_point::implementations::fp8x23wide::math::core as core_fp8x23wide; use orion::numbers::fixed_point::implementations::fp8x23wide::math::comp as comp_fp8x23wide; @@ -345,6 +360,10 @@ impl FP8x23WNumber of NumberTrait { core_fp8x23wide::eq(@self, @FP8x23WImpl::ZERO()) } + fn half() -> FP8x23W { + FP8x23WImpl::HALF() + } + fn one() -> FP8x23W { FP8x23WImpl::ONE() } @@ -412,9 +431,17 @@ impl FP8x23WNumber of NumberTrait { fn bitwise_and(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { comp_fp8x23wide::bitwise_and(lhs, rhs) } + + fn add(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + FP8x23WAdd::add(lhs, rhs) + } + + fn sub(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + FP8x23WSub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; +use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub}; use orion::numbers::fixed_point::implementations::fp16x16::math::core as core_fp16x16; use orion::numbers::fixed_point::implementations::fp16x16::math::comp as comp_fp16x16; @@ -526,6 +553,10 @@ impl FP16x16Number of NumberTrait { core_fp16x16::eq(@self, @FP16x16Impl::ZERO()) } + fn half() -> FP16x16 { + FP16x16Impl::HALF() + } + fn one() -> FP16x16 { FP16x16Impl::ONE() } @@ -593,9 +624,17 @@ impl FP16x16Number of NumberTrait { fn bitwise_and(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { comp_fp16x16::bitwise_and(lhs, rhs) } + + fn add(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + FP16x16Add::add(lhs, rhs) + } + + fn sub(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + FP16x16Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; +use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub}; use orion::numbers::fixed_point::implementations::fp16x16wide::math::core as core_fp16x16wide; use orion::numbers::fixed_point::implementations::fp16x16wide::math::comp as comp_fp16x16wide; @@ -707,6 +746,10 @@ impl FP16x16WNumber of NumberTrait { core_fp16x16wide::eq(@self, @FP16x16WImpl::ZERO()) } + fn half() -> FP16x16W { + FP16x16WImpl::HALF() + } + fn one() -> FP16x16W { FP16x16WImpl::ONE() } @@ -774,9 +817,17 @@ impl FP16x16WNumber of NumberTrait { fn bitwise_and(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { comp_fp16x16wide::bitwise_and(lhs, rhs) } + + fn add(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + FP16x16WAdd::add(lhs, rhs) + } + + fn sub(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + FP16x16WSub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; +use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub}; use orion::numbers::fixed_point::implementations::fp64x64::core as core_fp64x64; use orion::numbers::fixed_point::implementations::fp64x64::comp as comp_fp64x64; use cubit::f128 as fp64x64; @@ -889,6 +940,10 @@ impl FP64x64Number of NumberTrait { fp64x64::core::eq(@self, @FP64x64Impl::ZERO()) } + fn half() -> FP64x64 { + FP64x64Impl::HALF() + } + fn one() -> FP64x64 { FP64x64Impl::ONE() } @@ -956,9 +1011,17 @@ impl FP64x64Number of NumberTrait { fn bitwise_and(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { comp_fp64x64::bitwise_and(lhs, rhs) } + + fn add(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + FP64x64Add::add(lhs, rhs) + } + + fn sub(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + FP64x64Sub::sub(lhs, rhs) + } } -use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; +use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub}; use orion::numbers::fixed_point::implementations::fp32x32::core as core_fp32x32; use orion::numbers::fixed_point::implementations::fp32x32::comp as comp_fp32x32; use cubit::f64 as fp32x32; @@ -1071,6 +1134,10 @@ impl FP32x32Number of NumberTrait { fp32x32::core::eq(@self, @FP32x32Impl::ZERO()) } + fn half() -> FP32x32 { + FP32x32Impl::HALF() + } + fn one() -> FP32x32 { FP32x32Impl::ONE() } @@ -1138,10 +1205,19 @@ impl FP32x32Number of NumberTrait { fn bitwise_and(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { comp_fp32x32::bitwise_and(lhs, rhs) } + + fn add(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + FP32x32Add::add(lhs, rhs) + } + + fn sub(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + FP32x32Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i8 as i8_core; use orion::numbers::signed_integer::i8::i8; +use orion::numbers::signed_integer::i8::{i8Add, i8Sub}; impl I8Number of NumberTrait { fn new(mag: u8, sign: bool) -> i8 { @@ -1251,6 +1327,10 @@ impl I8Number of NumberTrait { i8_core::i8_eq(self, i8 { mag: 0, sign: false }) } + fn half() -> i8 { + panic(array!['not supported!']) + } + fn one() -> i8 { i8 { mag: 1, sign: false } } @@ -1334,10 +1414,19 @@ impl I8Number of NumberTrait { fn bitwise_and(lhs: i8, rhs: i8) -> i8 { i8_core::i8_bitwise_and(lhs, rhs) } + + fn add(lhs: i8, rhs: i8) -> i8 { + i8Add::add(lhs, rhs) + } + + fn sub(lhs: i8, rhs: i8) -> i8 { + i8Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i16 as i16_core; use orion::numbers::signed_integer::i16::i16; +use orion::numbers::signed_integer::i16::{i16Add, i16Sub}; impl i16Number of NumberTrait { fn new(mag: u16, sign: bool) -> i16 { @@ -1447,6 +1536,10 @@ impl i16Number of NumberTrait { i16_core::i16_eq(self, i16 { mag: 0, sign: false }) } + fn half() -> i16 { + panic(array!['not supported!']) + } + fn one() -> i16 { i16 { mag: 1, sign: false } } @@ -1530,10 +1623,19 @@ impl i16Number of NumberTrait { fn bitwise_and(lhs: i16, rhs: i16) -> i16 { i16_core::i16_bitwise_and(lhs, rhs) } + + fn add(lhs: i16, rhs: i16) -> i16 { + i16Add::add(lhs, rhs) + } + + fn sub(lhs: i16, rhs: i16) -> i16 { + i16Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i32 as i32_core; use orion::numbers::signed_integer::i32::i32; +use orion::numbers::signed_integer::i32::{i32Add, i32Sub}; impl i32Number of NumberTrait { fn new(mag: u32, sign: bool) -> i32 { @@ -1643,6 +1745,10 @@ impl i32Number of NumberTrait { i32_core::i32_eq(self, i32 { mag: 0, sign: false }) } + fn half() -> i32 { + panic(array!['not supported!']) + } + fn one() -> i32 { i32 { mag: 1, sign: false } } @@ -1726,10 +1832,19 @@ impl i32Number of NumberTrait { fn bitwise_and(lhs: i32, rhs: i32) -> i32 { i32_core::i32_bitwise_and(lhs, rhs) } + + fn add(lhs: i32, rhs: i32) -> i32 { + i32Add::add(lhs, rhs) + } + + fn sub(lhs: i32, rhs: i32) -> i32 { + i32Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i64 as i64_core; use orion::numbers::signed_integer::i64::i64; +use orion::numbers::signed_integer::i64::{i64Add, i64Sub}; impl i64Number of NumberTrait { fn new(mag: u64, sign: bool) -> i64 { @@ -1839,6 +1954,10 @@ impl i64Number of NumberTrait { i64_core::i64_eq(self, i64 { mag: 0, sign: false }) } + fn half() -> i64 { + panic(array!['not supported!']) + } + fn one() -> i64 { i64 { mag: 1, sign: false } } @@ -1922,10 +2041,19 @@ impl i64Number of NumberTrait { fn bitwise_and(lhs: i64, rhs: i64) -> i64 { i64_core::i64_bitwise_and(lhs, rhs) } + + fn add(lhs: i64, rhs: i64) -> i64 { + i64Add::add(lhs, rhs) + } + + fn sub(lhs: i64, rhs: i64) -> i64 { + i64Sub::sub(lhs, rhs) + } } use orion::numbers::signed_integer::i128 as i128_core; use orion::numbers::signed_integer::i128::i128; +use orion::numbers::signed_integer::i128::{i128Add, i128Sub}; impl i128Number of NumberTrait { fn new(mag: u128, sign: bool) -> i128 { @@ -2036,6 +2164,10 @@ impl i128Number of NumberTrait { i128_core::i128_eq(self, i128 { mag: 0, sign: false }) } + fn half() -> i128 { + panic(array!['not supported!']) + } + fn one() -> i128 { i128 { mag: 1, sign: false } } @@ -2119,6 +2251,14 @@ impl i128Number of NumberTrait { fn bitwise_and(lhs: i128, rhs: i128) -> i128 { i128_core::i128_bitwise_and(lhs, rhs) } + + fn add(lhs: i128, rhs: i128) -> i128 { + i128Add::add(lhs, rhs) + } + + fn sub(lhs: i128, rhs: i128) -> i128 { + i128Sub::sub(lhs, rhs) + } } impl u32Number of NumberTrait { @@ -2230,6 +2370,10 @@ impl u32Number of NumberTrait { self == 0 } + fn half() -> u32 { + panic(array!['not supported!']) + } + fn one() -> u32 { 1 } @@ -2321,4 +2465,12 @@ impl u32Number of NumberTrait { fn bitwise_and(lhs: u32, rhs: u32) -> u32 { lhs & rhs } + + fn add(lhs: u32, rhs: u32) -> u32 { + lhs + rhs + } + + fn sub(lhs: u32, rhs: u32) -> u32 { + lhs - rhs + } } diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 6581b018f..b7afc3ee1 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1100,6 +1100,7 @@ trait FixedTrait { fn sign(self: T) -> T; fn ZERO() -> T; + fn HALF() -> T; fn ONE() -> T; fn MAX() -> T; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index 10aed6e09..f34f1ef63 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -29,6 +29,10 @@ impl FP16x16Impl of FixedTrait { return FP16x16 { mag: 0, sign: false }; } + fn HALF() -> FP16x16 { + return FP16x16 { mag: HALF, sign: false }; + } + fn ONE() -> FP16x16 { return FP16x16 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index f04f4e690..ebcf9c999 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -29,6 +29,10 @@ impl FP16x16WImpl of FixedTrait { return FP16x16W { mag: 0, sign: false }; } + fn HALF() -> FP16x16W { + return FP16x16W { mag: HALF, sign: false }; + } + fn ONE() -> FP16x16W { return FP16x16W { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index a84373883..506c04dbb 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -6,7 +6,7 @@ use traits::{TryInto, Into}; use cubit::f64 as fp32x32; use cubit::f64::Fixed as FP32x32; -use cubit::f64::ONE; +use cubit::f64::{ONE, HALF}; use cubit::f64::types::fixed; use orion::numbers::fixed_point::core::{FixedTrait}; @@ -20,6 +20,10 @@ impl FP32x32Impl of FixedTrait { return FP32x32 { mag: 0, sign: false }; } + fn HALF() -> FP32x32 { + return FP32x32 { mag: HALF, sign: false }; + } + fn ONE() -> FP32x32 { return FP32x32 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index 706fe21a6..d42a6747d 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -13,11 +13,17 @@ use orion::numbers::fixed_point::core::{FixedTrait}; use orion::numbers::fixed_point::utils; use orion::numbers::{i32, i8}; +const HALF: u128 = 9223372036854775808_u128; // 2 ** 63 + impl FP64x64Impl of FixedTrait { fn ZERO() -> FP64x64 { return FP64x64 { mag: 0, sign: false }; } + fn HALF() -> FP64x64 { + return FP64x64 { mag: HALF, sign: false }; + } + fn ONE() -> FP64x64 { return FP64x64 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 12ef49e24..a4b4311e1 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -29,6 +29,10 @@ impl FP8x23Impl of FixedTrait { return FP8x23 { mag: 0, sign: false }; } + fn HALF() -> FP8x23 { + return FP8x23 { mag: HALF, sign: false }; + } + fn ONE() -> FP8x23 { return FP8x23 { mag: ONE, sign: false }; } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 0243b56fc..cafafd6b0 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -29,6 +29,10 @@ impl FP8x23WImpl of FixedTrait { return FP8x23W { mag: 0, sign: false }; } + fn HALF() -> FP8x23W { + return FP8x23W { mag: HALF, sign: false }; + } + fn ONE() -> FP8x23W { return FP8x23W { mag: ONE, sign: false }; } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..dfbc2acb4 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..df9f15077 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..8de4ea892 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..38d6da67a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 f764b1920..51d7f3f79 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 6cded29b3..cc04b49a1 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 fdcdac1eb..320206b7d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..e462be25d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + math::shrink::shrink(self, bias, lambd) + } } /// 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 8017ab300..9e3c61860 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 4f2731b80..0c3ac82dd 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2f3c3a2ef..b5d22686f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..a82a8befa 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod shrink; diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo new file mode 100644 index 000000000..7c8c90e6a --- /dev/null +++ b/src/operators/tensor/math/shrink.cairo @@ -0,0 +1,55 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; + +/// Cf: TensorTrait::shrink docstring +fn shrink< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut self: Tensor, bias: Option, lambd: Option +) -> Tensor { + + let bias: T = if bias.is_some() { + bias.unwrap() + } else { + NumberTrait::one() + }; + + let lambd: T = if lambd.is_some() { + lambd.unwrap() + } else { + NumberTrait::half() + }; + + let mut data_result = ArrayTrait::::new(); + + loop { + match self.data.pop_front() { + Option::Some(item) => { + if (*item) < lambd.neg() { + let mut y = NumberTrait::add(*item, bias); + data_result.append(y); + } else if (*item) > lambd { + let mut y = NumberTrait::sub(*item, bias); + data_result.append(y); + } else { + data_result.append(NumberTrait::zero()); + } + }, + Option::None(_) => { + break; + } + }; + }; + + return TensorTrait::new(self.shape, data_result.span()); +} From d767924c41edd19fb7acfd71240d4ec360e88e86 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 16:09:16 +0100 Subject: [PATCH 049/160] Adjust for optional attribute and limit to fixed point --- nodegen/node/binarizer.py | 18 +------- src/operators/tensor/core.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 4 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- src/operators/tensor/math/binarizer.cairo | 11 ++++- tests/nodes.cairo | 3 +- tests/nodes/binarizer_fp16x16.cairo | 2 +- tests/nodes/binarizer_fp8x23.cairo | 2 +- tests/nodes/binarizer_i32.cairo | 21 ---------- tests/nodes/binarizer_i32/input_0.cairo | 41 ------------------- tests/nodes/binarizer_i32/output_0.cairo | 41 ------------------- 18 files changed, 25 insertions(+), 136 deletions(-) delete mode 100644 tests/nodes/binarizer_i32.cairo delete mode 100644 tests/nodes/binarizer_i32/input_0.cairo delete mode 100644 tests/nodes/binarizer_i32/output_0.cairo diff --git a/nodegen/node/binarizer.py b/nodegen/node/binarizer.py index f1a07d07a..47930aaf4 100644 --- a/nodegen/node/binarizer.py +++ b/nodegen/node/binarizer.py @@ -5,20 +5,6 @@ class Binarizer(RunAll): - @staticmethod - def binarizer_i32(): - x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int32) - threshold = np.int32(1) - y = (x > threshold).astype(np.int32) - - x = Tensor(Dtype.I32, x.shape, x.flatten()) - y = Tensor(Dtype.I32, y.shape, y.flatten()) - - name = "binarizer_i32" - make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false));", name) - - @staticmethod def binarizer_fp8x23(): x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) @@ -32,7 +18,7 @@ def binarizer_fp8x23(): name = "binarizer_fp8x23" make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false));", name) + make_test([x], y, "TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false));", name) @staticmethod @@ -48,4 +34,4 @@ def binarizer_fp16x16(): name = "binarizer_fp16x16" make_node([x], [y], name) - make_test([x], y, "TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false));", name) + make_test([x], y, "TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false));", name) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index c1d1271bb..b76142d13 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3258,7 +3258,7 @@ trait TensorTrait { /// >>> [0, 0, 0, 1] /// ``` /// - fn binarizer(self: @Tensor, threshold: @T) -> Tensor; + fn binarizer(self: @Tensor, threshold: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 16c3d178a..71470e379 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -288,7 +288,7 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 5d7ac3908..964a98250 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -287,7 +287,7 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP16x16W) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 8bd01a0e3..7a8d19111 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -289,7 +289,7 @@ impl FP32x32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP32x32) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 6c094b827..ed6c3f86c 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -289,7 +289,7 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP64x64) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 01455b675..df2416684 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -288,7 +288,7 @@ impl FP8x23Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 5a15a7cd2..1a4a32f12 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -277,7 +277,7 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @FP8x23W) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index dbfac85d5..3be767db6 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -288,8 +288,8 @@ impl I32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i32) -> Tensor { - math::binarizer::binarizer(*self, threshold) + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 65a0e5081..bbed5ed3c 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -287,7 +287,7 @@ impl I8Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @i8) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index ed3903921..b55c3b9d3 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -269,7 +269,7 @@ impl U32Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn binarizer(self: @Tensor, threshold: @u32) -> Tensor { + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index 697c4e293..9b37a98ef 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -15,14 +15,21 @@ fn binarizer< impl TCopy: Copy, impl TDrop: Drop >( - mut self: Tensor, threshold: @T + mut self: Tensor, threshold: Option ) -> Tensor { + + let threshold: T = if threshold.is_some() { + threshold.unwrap() + } else { + NumberTrait::zero() + }; + let mut binarized_data = ArrayTrait::::new(); loop { match self.data.pop_front() { Option::Some(item) => { - if (*item) > (*threshold) { + if (*item) > threshold { binarized_data.append(NumberTrait::one()); } else { binarized_data.append(NumberTrait::zero()); diff --git a/tests/nodes.cairo b/tests/nodes.cairo index e841e15aa..19469328f 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -529,5 +529,4 @@ mod scatter_u32_default; mod scatter_u32_axis1; mod scatter_u32_add; mod binarizer_fp16x16; -mod binarizer_fp8x23; -mod binarizer_i32; +mod binarizer_fp8x23; diff --git a/tests/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 5ddd92826..87306959b 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -15,7 +15,7 @@ fn test_binarizer_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(65536, false)); + let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false))); assert_eq(y, z); } \ No newline at end of file diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 62d6f3ee4..91b481fa3 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -15,7 +15,7 @@ fn test_binarizer_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::binarizer(@input_0, @FixedTrait::new(8388608, false)); + let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false))); assert_eq(y, z); } \ No newline at end of file diff --git a/tests/nodes/binarizer_i32.cairo b/tests/nodes/binarizer_i32.cairo deleted file mode 100644 index 7793b74ae..000000000 --- a/tests/nodes/binarizer_i32.cairo +++ /dev/null @@ -1,21 +0,0 @@ -mod input_0; -mod output_0; - - -use array::{ArrayTrait, SpanTrait}; -use orion::numbers::IntegerTrait; -use orion::operators::tensor::TensorTrait; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::assert_eq; - -#[test] -#[available_gas(2000000000)] -fn test_binarizer_i32() { - let input_0 = input_0::input_0(); - let z = output_0::output_0(); - - let y = TensorTrait::binarizer(@input_0, @IntegerTrait::new(1, false)); - - assert_eq(y, z); -} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/input_0.cairo b/tests/nodes/binarizer_i32/input_0.cairo deleted file mode 100644 index 3059b3649..000000000 --- a/tests/nodes/binarizer_i32/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -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: 0, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, 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: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, 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: 0, sign: false }); - 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: 0, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - 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: 3, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file diff --git a/tests/nodes/binarizer_i32/output_0.cairo b/tests/nodes/binarizer_i32/output_0.cairo deleted file mode 100644 index 3adef88e2..000000000 --- a/tests/nodes/binarizer_i32/output_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I32Tensor; -use orion::numbers::{IntegerTrait, i32}; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file From cd9227d4be8a826b54fafb8f8908c69b615920b7 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 16:14:17 +0100 Subject: [PATCH 050/160] Fix generating tests for sequence output --- nodegen/file_manager.py | 40 ++++++++++++++++++++++++++++++++++++++-- nodegen/helpers.py | 22 ++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/nodegen/file_manager.py b/nodegen/file_manager.py index 215bacbcc..b1020f0c7 100644 --- a/nodegen/file_manager.py +++ b/nodegen/file_manager.py @@ -72,9 +72,9 @@ def __init__(self, file: str): super().__init__(os.path.join(BASE_PATH, file)) @classmethod - def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + def base_template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: """ - Create a template for a Cairo test function. + Create a template for a Cairo test function which expects a tensor output. Args: name (str): Name of the test function. @@ -107,6 +107,42 @@ def template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> li *[ "}"], ] + @classmethod + def sequence_template(cls, name: str, arg_cnt: int, refs: list[str], func_sig: str) -> list[str]: + """ + Create a template for a Cairo test function which expects a tensor sequence. + + Args: + name (str): Name of the test function. + arg_cnt (int): Number of arguments for the function. + refs (list[str]): List of references (modules) to be used in the function. + func_sig (str): The function signature. + + Returns: + list[str]: A list of strings that together form the template of a Cairo test function. + + This method generates a list of strings that form the template of a Cairo test function, + including module imports, function definition, and assertions. + """ + return [ + *[f"mod input_{i};" for i in range(arg_cnt)], + *[ "mod output_0;"], + *[ ""], + *[ ""], + *[f"use {ref};" for ref in refs], + *[ ""], + *[ "#[test]"], + *[ "#[available_gas(2000000000)]"], + *[f"fn test_{name}()"+" {"], + *[f" let input_{i} = input_{i}::input_{i}();" for i in range(arg_cnt)], + *[ " let z = output_0::output_0();"], + *[ ""], + *[f" let y = {func_sig};"], + *[ ""], + *[ " assert_seq_eq(y, z);"], + *[ "}"], + ] + class CairoData(File): def __init__(self, file: str): diff --git a/nodegen/helpers.py b/nodegen/helpers.py index d027a7ec5..6eac7a003 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -100,12 +100,22 @@ def make_test(inputs: list[Tensor | Sequence], output: Tensor | Sequence, func_s output_data.dump() test_file = CairoTest(f"{name}.cairo") - test_file.buffer = CairoTest.template( - name=name, - arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, output]), trait, isinstance(output, list)), - func_sig=func_sig, - ) + match output: + case list(): + test_file.buffer = CairoTest.sequence_template( + name=name, + arg_cnt=len(inputs), + refs=get_all_test_refs(find_all_types([*inputs, *output]), trait, True), + func_sig=func_sig, + ) + case Tensor(): + test_file.buffer = CairoTest.base_template( + name=name, + arg_cnt=len(inputs), + refs=get_all_test_refs(find_all_types([*inputs, output]), trait, False), + func_sig=func_sig, + ) + test_file.dump() From 0cc9d4d89807a253d74a53a6c9efa42e01712999 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 16:31:15 +0100 Subject: [PATCH 051/160] Remove redundant `is_sequence` argument --- nodegen/helpers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 6eac7a003..a9290362d 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -105,14 +105,14 @@ def make_test(inputs: list[Tensor | Sequence], output: Tensor | Sequence, func_s test_file.buffer = CairoTest.sequence_template( name=name, arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, *output]), trait, True), + refs=get_all_test_refs(find_all_types([*inputs, *output]), trait), func_sig=func_sig, ) case Tensor(): test_file.buffer = CairoTest.base_template( name=name, arg_cnt=len(inputs), - refs=get_all_test_refs(find_all_types([*inputs, output]), trait, False), + refs=get_all_test_refs(find_all_types([*inputs, output]), trait), func_sig=func_sig, ) @@ -147,15 +147,15 @@ def get_data_statement_for_sequences(data: Sequence, dtype: Dtype) -> list[list[ return [get_data_statement(x.data, dtype) for x in data] -def get_all_test_refs(dtypes: list[Dtype], trait: Trait, is_sequence: bool) -> list[str]: +def get_all_test_refs(dtypes: list[Dtype], trait: Trait) -> list[str]: refs = [] for dtype in dtypes: - refs += get_test_refs(dtype, trait, is_sequence) + refs += get_test_refs(dtype, trait) return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: dtype_ref = dtype_to_nn[dtype] if trait == Trait.NN else dtype_to_tensor[dtype] refs = [ *trait_to_ref[trait], From 6e3cea97f957471e70c7da00cde1b3a5d6d8e7f9 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 16:41:47 +0100 Subject: [PATCH 052/160] Adjust docstring --- .../operators/tensor/tensor.binarizer.md | 28 ++++++++++--------- src/operators/tensor/core.cairo | 28 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md index 14cac3d65..01e24e58e 100644 --- a/docs/framework/operators/tensor/tensor.binarizer.md +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -8,37 +8,39 @@ Maps the values of a tensor element-wise to 0 or 1 based on the comparison again ## Args * `self`(`@Tensor`) - The input tensor to be binarized. -* `threshold`(`@T`) - The threshold for the binarization operation. +* `threshold`(`Option`) - The threshold for the binarization operation. ## Returns A new `Tensor` of the same shape as the input tensor with binarized values. ## Type Constraints -Constrain input and output types to fixed point and int32 tensors. +Constrain input and output types to fixed point numbers. ## Examples ```rust use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; -use orion::numbers::{i32, IntegerTrait}; +use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; +use orion::numbers::{FixedTrait, FP8x23}; -fn binarizer_example() -> Tensor { - let tensor = TensorTrait::::new( +fn binarizer_example() -> Tensor { + let tensor = TensorTrait::::new( shape: array![2, 2].span(), data: array![ - IntegerTrait::new(1, true), - IntegerTrait::new(0, false), - IntegerTrait::new(1, false), - IntegerTrait::new(2, false), + FixedTrait::new(0, false), + FixedTrait::new(1, false), + FixedTrait::new(2, false), + FixedTrait::new(3, false) ] .span(), ); - let threshold = IntegerTrait::::new(1, false) + let threshold = Option::Some(FixedTrait::new(1, false)) - return tensor.binarizer(@tensor, @threshold); + return tensor.binarizer(@tensor, threshold); } ->>> [0, 0, 0, 1] +>>> [0, 0, 8388608, 8388608] + // The fixed point representation of + [0, 0, 1, 1] ``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index b76142d13..931b42564 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3223,39 +3223,41 @@ trait TensorTrait { /// /// ## Args /// * `self`(`@Tensor`) - The input tensor to be binarized. - /// * `threshold`(`@T`) - The threshold for the binarization operation. + /// * `threshold`(`Option`) - The threshold for the binarization operation. /// /// ## Returns /// A new `Tensor` of the same shape as the input tensor with binarized values. /// /// ## Type Constraints /// - /// Constrain input and output types to fixed point and int32 tensors. + /// Constrain input and output types to fixed point numbers. /// /// ## Examples /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// - /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor}; - /// use orion::numbers::{i32, IntegerTrait}; + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; /// - /// fn binarizer_example() -> Tensor { - /// let tensor = TensorTrait::::new( + /// fn binarizer_example() -> Tensor { + /// let tensor = TensorTrait::::new( /// shape: array![2, 2].span(), /// data: array![ - /// IntegerTrait::new(1, true), - /// IntegerTrait::new(0, false), - /// IntegerTrait::new(1, false), - /// IntegerTrait::new(2, false), + /// FixedTrait::new(0, false), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false), + /// FixedTrait::new(3, false) /// ] /// .span(), /// ); - /// let threshold = IntegerTrait::::new(1, false) + /// let threshold = Option::Some(FixedTrait::new(1, false)) /// - /// return tensor.binarizer(@tensor, @threshold); + /// return tensor.binarizer(@tensor, threshold); /// } - /// >>> [0, 0, 0, 1] + /// >>> [0, 0, 8388608, 8388608] + /// // The fixed point representation of + /// [0, 0, 1, 1] /// ``` /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor; From 908a82070d0b844976603e45fd2b8bbdb6a6a614 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Tue, 14 Nov 2023 19:05:16 +0100 Subject: [PATCH 053/160] Add support for boolean tensors --- nodegen/helpers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index d027a7ec5..821a4944a 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -26,6 +26,7 @@ class Dtype(Enum): I8 = 'i8' I32 = 'i32' U32 = 'u32' + BOOL = 'bool' class Tensor: @@ -131,6 +132,8 @@ def get_data_statement(data: np.ndarray, dtype: Dtype) -> list[str]: return ["FP8x23 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] case Dtype.FP16x16: return ["FP16x16 { "+f"mag: {abs(int(x))}, sign: {str(x < 0).lower()} "+"}" for x in data.flatten()] + case Dtype.BOOL: + return [str(x).lower() for x in data.flatten()] def get_data_statement_for_sequences(data: Sequence, dtype: Dtype) -> list[list[str]]: @@ -146,6 +149,9 @@ def get_all_test_refs(dtypes: list[Dtype], trait: Trait, is_sequence: bool) -> l def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: + if trait == Trait.NN and dtype == Dtype.BOOL: + raise Exception("NN trait does not support bool dtype") + dtype_ref = dtype_to_nn[dtype] if trait == Trait.NN else dtype_to_tensor[dtype] refs = [ *trait_to_ref[trait], @@ -186,6 +192,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::operators::tensor::I8Tensor",], Dtype.FP8x23: ["orion::operators::tensor::FP8x23Tensor",], Dtype.FP16x16: ["orion::operators::tensor::FP16x16Tensor",], + Dtype.BOOL: ["orion::operators::tensor::BoolTensor",], } @@ -204,6 +211,7 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::operators::tensor::I8TensorPartialEq",], Dtype.FP8x23: ["orion::operators::tensor::FP8x23TensorPartialEq",], Dtype.FP16x16: ["orion::operators::tensor::FP16x16TensorPartialEq",], + Dtype.BOOL: ["orion::operators::tensor::BoolTensorPartialEq",], } @@ -213,4 +221,5 @@ def find_all_types(tensors: list[Tensor | Sequence]) -> list[Dtype]: Dtype.I8: ["orion::numbers::{IntegerTrait, i8}",], Dtype.FP8x23: ["orion::numbers::{FixedTrait, FP8x23}",], Dtype.FP16x16: ["orion::numbers::{FixedTrait, FP16x16}",], + Dtype.BOOL: [], } From ef774119af9cdf89c8de87457c1df40bba6f95ae Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 19:45:13 +0100 Subject: [PATCH 054/160] Add tests and fix bug in operator --- nodegen/node/shrink.py | 79 +++++++++++++++++++ src/operators/tensor/math/shrink.cairo | 2 +- tests/nodes.cairo | 4 + tests/nodes/shrink_hard_fp16x16.cairo | 21 +++++ tests/nodes/shrink_hard_fp16x16/input_0.cairo | 41 ++++++++++ .../nodes/shrink_hard_fp16x16/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_hard_fp8x23.cairo | 21 +++++ tests/nodes/shrink_hard_fp8x23/input_0.cairo | 41 ++++++++++ tests/nodes/shrink_hard_fp8x23/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp16x16.cairo | 21 +++++ tests/nodes/shrink_soft_fp16x16/input_0.cairo | 41 ++++++++++ .../nodes/shrink_soft_fp16x16/output_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp8x23.cairo | 21 +++++ tests/nodes/shrink_soft_fp8x23/input_0.cairo | 41 ++++++++++ tests/nodes/shrink_soft_fp8x23/output_0.cairo | 41 ++++++++++ 15 files changed, 496 insertions(+), 1 deletion(-) create mode 100644 nodegen/node/shrink.py create mode 100644 tests/nodes/shrink_hard_fp16x16.cairo create mode 100644 tests/nodes/shrink_hard_fp16x16/input_0.cairo create mode 100644 tests/nodes/shrink_hard_fp16x16/output_0.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23/input_0.cairo create mode 100644 tests/nodes/shrink_hard_fp8x23/output_0.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16/input_0.cairo create mode 100644 tests/nodes/shrink_soft_fp16x16/output_0.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23/input_0.cairo create mode 100644 tests/nodes/shrink_soft_fp8x23/output_0.cairo diff --git a/nodegen/node/shrink.py b/nodegen/node/shrink.py new file mode 100644 index 000000000..8e6556226 --- /dev/null +++ b/nodegen/node/shrink.py @@ -0,0 +1,79 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +def shrink(input_array: np.ndarray, bias: float, lambd: float) -> np.ndarray: + output_array = np.where(input_array > lambd, input_array - bias, + np.where(input_array < -lambd, input_array + bias, 0)) + return output_array + + +class Shrink(RunAll): + + @staticmethod + def shrink_fp8x23(): + def shrink_hard(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(0) # Default value + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "shrink_hard_fp8x23" + make_test([x], y, "TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false)))", name) + + def shrink_soft(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(1) + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "shrink_soft_fp8x23" + make_test([x], y, "TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false)))", name) + + shrink_hard() + shrink_soft() + + + @staticmethod + def shrink_fp16x16(): + def shrink_hard(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(0) # Default value + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "shrink_hard_fp16x16" + make_test([x], y, "TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false)))", name) + + def shrink_soft(): + x = np.random.uniform(-3, 3, (3, 3, 3)).astype(np.float64) + bias = np.float64(1) + lambd = np.float64(1) + y = shrink(x, bias, lambd) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "shrink_soft_fp16x16" + make_test([x], y, "TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false)))", name) + + shrink_hard() + shrink_soft() \ No newline at end of file diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo index 7c8c90e6a..90c010f85 100644 --- a/src/operators/tensor/math/shrink.cairo +++ b/src/operators/tensor/math/shrink.cairo @@ -21,7 +21,7 @@ fn shrink< let bias: T = if bias.is_some() { bias.unwrap() } else { - NumberTrait::one() + NumberTrait::zero() }; let lambd: T = if lambd.is_some() { diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..03fc9bc94 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,7 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod shrink_hard_fp16x16; +mod shrink_soft_fp16x16; +mod shrink_hard_fp8x23; +mod shrink_soft_fp8x23; diff --git a/tests/nodes/shrink_hard_fp16x16.cairo b/tests/nodes/shrink_hard_fp16x16.cairo new file mode 100644 index 000000000..2272fd758 --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_hard_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_hard_fp16x16/input_0.cairo b/tests/nodes/shrink_hard_fp16x16/input_0.cairo new file mode 100644 index 000000000..1c0d4c303 --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 53724, sign: false }); + data.append(FP16x16 { mag: 100114, sign: true }); + data.append(FP16x16 { mag: 105707, sign: true }); + data.append(FP16x16 { mag: 172713, sign: false }); + data.append(FP16x16 { mag: 117489, sign: true }); + data.append(FP16x16 { mag: 131055, sign: false }); + data.append(FP16x16 { mag: 136968, sign: true }); + data.append(FP16x16 { mag: 139039, sign: true }); + data.append(FP16x16 { mag: 179765, sign: false }); + data.append(FP16x16 { mag: 116549, sign: false }); + data.append(FP16x16 { mag: 86012, sign: true }); + data.append(FP16x16 { mag: 42842, sign: false }); + data.append(FP16x16 { mag: 102196, sign: false }); + data.append(FP16x16 { mag: 91319, sign: true }); + data.append(FP16x16 { mag: 154563, sign: true }); + data.append(FP16x16 { mag: 148265, sign: false }); + data.append(FP16x16 { mag: 147485, sign: false }); + data.append(FP16x16 { mag: 18844, sign: true }); + data.append(FP16x16 { mag: 87916, sign: true }); + data.append(FP16x16 { mag: 53116, sign: false }); + data.append(FP16x16 { mag: 189184, sign: false }); + data.append(FP16x16 { mag: 172959, sign: true }); + data.append(FP16x16 { mag: 24790, sign: false }); + data.append(FP16x16 { mag: 141694, sign: false }); + data.append(FP16x16 { mag: 142845, sign: false }); + data.append(FP16x16 { mag: 88179, sign: false }); + data.append(FP16x16 { mag: 76572, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp16x16/output_0.cairo b/tests/nodes/shrink_hard_fp16x16/output_0.cairo new file mode 100644 index 000000000..056cb881d --- /dev/null +++ b/tests/nodes/shrink_hard_fp16x16/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 100114, sign: true }); + data.append(FP16x16 { mag: 105707, sign: true }); + data.append(FP16x16 { mag: 172713, sign: false }); + data.append(FP16x16 { mag: 117489, sign: true }); + data.append(FP16x16 { mag: 131055, sign: false }); + data.append(FP16x16 { mag: 136968, sign: true }); + data.append(FP16x16 { mag: 139039, sign: true }); + data.append(FP16x16 { mag: 179765, sign: false }); + data.append(FP16x16 { mag: 116549, sign: false }); + data.append(FP16x16 { mag: 86012, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 102196, sign: false }); + data.append(FP16x16 { mag: 91319, sign: true }); + data.append(FP16x16 { mag: 154563, sign: true }); + data.append(FP16x16 { mag: 148265, sign: false }); + data.append(FP16x16 { mag: 147485, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 87916, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 189184, sign: false }); + data.append(FP16x16 { mag: 172959, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 141694, sign: false }); + data.append(FP16x16 { mag: 142845, sign: false }); + data.append(FP16x16 { mag: 88179, sign: false }); + data.append(FP16x16 { mag: 76572, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp8x23.cairo b/tests/nodes/shrink_hard_fp8x23.cairo new file mode 100644 index 000000000..d9294c755 --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_hard_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_hard_fp8x23/input_0.cairo b/tests/nodes/shrink_hard_fp8x23/input_0.cairo new file mode 100644 index 000000000..9148dbd07 --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16287022, sign: true }); + data.append(FP8x23 { mag: 10799553, sign: false }); + data.append(FP8x23 { mag: 2484402, sign: true }); + data.append(FP8x23 { mag: 17585288, sign: true }); + data.append(FP8x23 { mag: 6428, sign: false }); + data.append(FP8x23 { mag: 22747410, sign: false }); + data.append(FP8x23 { mag: 7024249, sign: false }); + data.append(FP8x23 { mag: 1080111, sign: false }); + data.append(FP8x23 { mag: 21293057, sign: true }); + data.append(FP8x23 { mag: 1501238, sign: true }); + data.append(FP8x23 { mag: 8554184, sign: true }); + data.append(FP8x23 { mag: 12577394, sign: false }); + data.append(FP8x23 { mag: 14241673, sign: true }); + data.append(FP8x23 { mag: 316469, sign: true }); + data.append(FP8x23 { mag: 16672164, sign: false }); + data.append(FP8x23 { mag: 23534429, sign: false }); + data.append(FP8x23 { mag: 22979924, sign: false }); + data.append(FP8x23 { mag: 12554544, sign: true }); + data.append(FP8x23 { mag: 8831121, sign: false }); + data.append(FP8x23 { mag: 12310986, sign: false }); + data.append(FP8x23 { mag: 16220051, sign: false }); + data.append(FP8x23 { mag: 1096465, sign: true }); + data.append(FP8x23 { mag: 1158077, sign: false }); + data.append(FP8x23 { mag: 7755965, sign: false }); + data.append(FP8x23 { mag: 24795265, sign: false }); + data.append(FP8x23 { mag: 1285412, sign: true }); + data.append(FP8x23 { mag: 12210140, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_hard_fp8x23/output_0.cairo b/tests/nodes/shrink_hard_fp8x23/output_0.cairo new file mode 100644 index 000000000..68f66101f --- /dev/null +++ b/tests/nodes/shrink_hard_fp8x23/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16287022, sign: true }); + data.append(FP8x23 { mag: 10799553, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 17585288, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 22747410, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 21293057, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8554184, sign: true }); + data.append(FP8x23 { mag: 12577394, sign: false }); + data.append(FP8x23 { mag: 14241673, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16672164, sign: false }); + data.append(FP8x23 { mag: 23534429, sign: false }); + data.append(FP8x23 { mag: 22979924, sign: false }); + data.append(FP8x23 { mag: 12554544, sign: true }); + data.append(FP8x23 { mag: 8831121, sign: false }); + data.append(FP8x23 { mag: 12310986, sign: false }); + data.append(FP8x23 { mag: 16220051, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 24795265, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 12210140, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp16x16.cairo b/tests/nodes/shrink_soft_fp16x16.cairo new file mode 100644 index 000000000..e5a8ef066 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_soft_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_soft_fp16x16/input_0.cairo b/tests/nodes/shrink_soft_fp16x16/input_0.cairo new file mode 100644 index 000000000..5c4f4a480 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 78056, sign: true }); + data.append(FP16x16 { mag: 31456, sign: true }); + data.append(FP16x16 { mag: 172639, sign: true }); + data.append(FP16x16 { mag: 78597, sign: false }); + data.append(FP16x16 { mag: 62154, sign: false }); + data.append(FP16x16 { mag: 171656, sign: false }); + data.append(FP16x16 { mag: 157535, sign: false }); + data.append(FP16x16 { mag: 49284, sign: false }); + data.append(FP16x16 { mag: 97008, sign: false }); + data.append(FP16x16 { mag: 123759, sign: true }); + data.append(FP16x16 { mag: 190267, sign: false }); + data.append(FP16x16 { mag: 107363, sign: false }); + data.append(FP16x16 { mag: 7956, sign: true }); + data.append(FP16x16 { mag: 68542, sign: false }); + data.append(FP16x16 { mag: 116678, sign: false }); + data.append(FP16x16 { mag: 85597, sign: false }); + data.append(FP16x16 { mag: 19210, sign: true }); + data.append(FP16x16 { mag: 99774, sign: false }); + data.append(FP16x16 { mag: 173484, sign: false }); + data.append(FP16x16 { mag: 127017, sign: true }); + data.append(FP16x16 { mag: 83696, sign: false }); + data.append(FP16x16 { mag: 16087, sign: true }); + data.append(FP16x16 { mag: 80426, sign: false }); + data.append(FP16x16 { mag: 187986, sign: false }); + data.append(FP16x16 { mag: 45262, sign: true }); + data.append(FP16x16 { mag: 46955, sign: false }); + data.append(FP16x16 { mag: 38631, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp16x16/output_0.cairo b/tests/nodes/shrink_soft_fp16x16/output_0.cairo new file mode 100644 index 000000000..6132122d8 --- /dev/null +++ b/tests/nodes/shrink_soft_fp16x16/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 12520, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 107103, sign: true }); + data.append(FP16x16 { mag: 13061, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 106120, sign: false }); + data.append(FP16x16 { mag: 91999, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 31472, sign: false }); + data.append(FP16x16 { mag: 58223, sign: true }); + data.append(FP16x16 { mag: 124731, sign: false }); + data.append(FP16x16 { mag: 41827, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 3006, sign: false }); + data.append(FP16x16 { mag: 51142, sign: false }); + data.append(FP16x16 { mag: 20061, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 34238, sign: false }); + data.append(FP16x16 { mag: 107948, sign: false }); + data.append(FP16x16 { mag: 61481, sign: true }); + data.append(FP16x16 { mag: 18160, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 14890, sign: false }); + data.append(FP16x16 { mag: 122450, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp8x23.cairo b/tests/nodes/shrink_soft_fp8x23.cairo new file mode 100644 index 000000000..66884de9f --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::numbers::FixedTrait; + +#[test] +#[available_gas(2000000000)] +fn test_shrink_soft_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false))); + + assert_eq(y, z); +} diff --git a/tests/nodes/shrink_soft_fp8x23/input_0.cairo b/tests/nodes/shrink_soft_fp8x23/input_0.cairo new file mode 100644 index 000000000..0189876bb --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 13404706, sign: true }); + data.append(FP8x23 { mag: 1642563, sign: true }); + data.append(FP8x23 { mag: 16689459, sign: false }); + data.append(FP8x23 { mag: 2347829, sign: false }); + data.append(FP8x23 { mag: 3467112, sign: false }); + data.append(FP8x23 { mag: 592703, sign: true }); + data.append(FP8x23 { mag: 1941576, sign: false }); + data.append(FP8x23 { mag: 4972, sign: true }); + data.append(FP8x23 { mag: 21738998, sign: false }); + data.append(FP8x23 { mag: 11513586, sign: true }); + data.append(FP8x23 { mag: 23646070, sign: false }); + data.append(FP8x23 { mag: 13206001, sign: true }); + data.append(FP8x23 { mag: 10769444, sign: false }); + data.append(FP8x23 { mag: 10345798, sign: false }); + data.append(FP8x23 { mag: 1337911, sign: true }); + data.append(FP8x23 { mag: 23240711, sign: false }); + data.append(FP8x23 { mag: 3398664, sign: false }); + data.append(FP8x23 { mag: 13332160, sign: true }); + data.append(FP8x23 { mag: 2545195, sign: false }); + data.append(FP8x23 { mag: 21250720, sign: true }); + data.append(FP8x23 { mag: 16789138, sign: true }); + data.append(FP8x23 { mag: 23029037, sign: true }); + data.append(FP8x23 { mag: 19022158, sign: false }); + data.append(FP8x23 { mag: 20748602, sign: false }); + data.append(FP8x23 { mag: 21590667, sign: false }); + data.append(FP8x23 { mag: 1180061, sign: false }); + data.append(FP8x23 { mag: 8043052, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/shrink_soft_fp8x23/output_0.cairo b/tests/nodes/shrink_soft_fp8x23/output_0.cairo new file mode 100644 index 000000000..72dde7a12 --- /dev/null +++ b/tests/nodes/shrink_soft_fp8x23/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 5016098, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8300851, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 13350390, sign: false }); + data.append(FP8x23 { mag: 3124978, sign: true }); + data.append(FP8x23 { mag: 15257462, sign: false }); + data.append(FP8x23 { mag: 4817393, sign: true }); + data.append(FP8x23 { mag: 2380836, sign: false }); + data.append(FP8x23 { mag: 1957190, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 14852103, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 4943552, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 12862112, sign: true }); + data.append(FP8x23 { mag: 8400530, sign: true }); + data.append(FP8x23 { mag: 14640429, sign: true }); + data.append(FP8x23 { mag: 10633550, sign: false }); + data.append(FP8x23 { mag: 12359994, sign: false }); + data.append(FP8x23 { mag: 13202059, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} From 1270e1feb0e5e2cb123e5fb876121cdb87cdf054 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 22:02:37 +0100 Subject: [PATCH 055/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.shrink.md | 49 ++++++++++++++++++ src/operators/tensor/core.cairo | 50 +++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.shrink.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..1a2942a23 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.shrink](framework/operators/tensor/tensor.shrink.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 ebc50ad77..2395d35a1 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [Shrink](operators/tensor/tensor.shrink.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..670436ead 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.shrink.md b/docs/framework/operators/tensor/tensor.shrink.md new file mode 100644 index 000000000..37c2e74aa --- /dev/null +++ b/docs/framework/operators/tensor/tensor.shrink.md @@ -0,0 +1,49 @@ +# tensor.shrink + +```rust + fn shrink(self: @Tensor, bias: Option, lambd: Option) -> Tensor +``` + +Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on the following formula: +If x < -lambd: y = x + bias; If x > lambd: y = x - bias; Otherwise: y = 0. + +## Args +* `self`(`@Tensor`) - The input tensor to be shrinked. +* `bias`(`Option`) - The bias value added to or subtracted from input tensor values. +* `lambd`(`Option`) - The lambd value defining the shrink condition. + +## Returns +A new `Tensor` of the same datatype and shape as the input tensor with shrinked values. + +## Type Constraints + +Constrain input and output types to fixed point numbers. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; +use orion::numbers::{FixedTrait, FP8x23}; + +fn shrink_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2].span(), + data: array![ + FixedTrait::new(2, true), + FixedTrait::new(1, true), + FixedTrait::new(1, false), + FixedTrait::new(2, false) + ] + .span(), + ); + let bias = Option::Some(FixedTrait::new(1, false)) + let lambd = Option::Some(FixedTrait::new(1, false)) + + return tensor.shrink(tensor, bias, lambd); +} +>>> [-8388608, 0, 0, 8388608] + // The fixed point representation of + [-1, 0, 0, 1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index dfbc2acb4..81ab443c9 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,56 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// # tensor.shrink + /// + /// ```rust + /// fn shrink(self: @Tensor, bias: Option, lambd: Option) -> Tensor + /// ``` + /// + /// Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on the following formula: + /// If x < -lambd: y = x + bias; If x > lambd: y = x - bias; Otherwise: y = 0. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be shrinked. + /// * `bias`(`Option`) - The bias value added to or subtracted from input tensor values. + /// * `lambd`(`Option`) - The lambd value defining the shrink condition. + /// + /// ## Returns + /// A new `Tensor` of the same datatype and shape as the input tensor with shrinked values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point numbers. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// fn shrink_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// FixedTrait::new(2, true), + /// FixedTrait::new(1, true), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false) + /// ] + /// .span(), + /// ); + /// let bias = Option::Some(FixedTrait::new(1, false)) + /// let lambd = Option::Some(FixedTrait::new(1, false)) + /// + /// return tensor.shrink(tensor, bias, lambd); + /// } + /// >>> [-8388608, 0, 0, 8388608] + /// // The fixed point representation of + /// [-1, 0, 0, 1] + /// ``` + /// fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; } From c3b486fb980f95abe51f0bc439c4e70f2c62b043 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Tue, 14 Nov 2023 22:11:51 +0100 Subject: [PATCH 056/160] Fix docstring --- docs/framework/operators/tensor/tensor.binarizer.md | 2 +- src/operators/tensor/core.cairo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/framework/operators/tensor/tensor.binarizer.md b/docs/framework/operators/tensor/tensor.binarizer.md index 01e24e58e..f97dcd446 100644 --- a/docs/framework/operators/tensor/tensor.binarizer.md +++ b/docs/framework/operators/tensor/tensor.binarizer.md @@ -1,7 +1,7 @@ # tensor.binarizer ```rust - fn binarizer(self: @Tensor, threshold: @T) -> Tensor + fn binarizer(self: @Tensor, threshold: Option) -> Tensor ``` Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 931b42564..0f36a83c8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3216,7 +3216,7 @@ trait TensorTrait { /// # tensor.binarizer /// /// ```rust - /// fn binarizer(self: @Tensor, threshold: @T) -> Tensor + /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor /// ``` /// /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. From c8dca89672de50cb0a24633b704405a9f7408489 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 15 Nov 2023 11:40:46 +0200 Subject: [PATCH 057/160] datasource generator --- tests/nodes/and_fp16x16.cairo | 6 ++- tests/nodes/and_fp16x16/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp16x16/input_1.cairo | 33 ++++++++--------- tests/nodes/and_fp16x16/output_0.cairo | 14 +++---- tests/nodes/and_fp16x16_broadcast.cairo | 6 ++- .../nodes/and_fp16x16_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp16x16_broadcast/input_1.cairo | 7 ++-- .../and_fp16x16_broadcast/output_0.cairo | 6 +-- tests/nodes/and_fp8x23.cairo | 6 ++- tests/nodes/and_fp8x23/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp8x23/input_1.cairo | 37 +++++++++---------- tests/nodes/and_fp8x23/output_0.cairo | 8 ++-- tests/nodes/and_fp8x23_broadcast.cairo | 6 ++- .../nodes/and_fp8x23_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp8x23_broadcast/input_1.cairo | 5 +-- .../nodes/and_fp8x23_broadcast/output_0.cairo | 4 +- tests/nodes/and_i32.cairo | 6 ++- tests/nodes/and_i32/input_0.cairo | 26 ++++++------- tests/nodes/and_i32/input_1.cairo | 30 +++++++-------- tests/nodes/and_i32/output_0.cairo | 8 ++-- tests/nodes/and_i32_broadcast.cairo | 6 ++- tests/nodes/and_i32_broadcast/input_0.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_1.cairo | 2 +- tests/nodes/and_i32_broadcast/output_0.cairo | 4 +- tests/nodes/and_i8.cairo | 8 ++-- tests/nodes/and_i8/input_0.cairo | 28 +++++++------- tests/nodes/and_i8/input_1.cairo | 28 +++++++------- tests/nodes/and_i8/output_0.cairo | 14 +++---- tests/nodes/and_i8_broadcast.cairo | 8 ++-- tests/nodes/and_i8_broadcast/input_0.cairo | 4 +- tests/nodes/and_i8_broadcast/input_1.cairo | 2 +- tests/nodes/and_u32.cairo | 4 +- tests/nodes/and_u32/input_0.cairo | 28 +++++++------- tests/nodes/and_u32/input_1.cairo | 30 +++++++-------- tests/nodes/and_u32/output_0.cairo | 10 ++--- tests/nodes/and_u32_broadcast.cairo | 4 +- tests/nodes/and_u32_broadcast/input_0.cairo | 4 +- tests/nodes/and_u32_broadcast/input_1.cairo | 4 +- tests/nodes/and_u32_broadcast/output_0.cairo | 4 +- 39 files changed, 245 insertions(+), 237 deletions(-) diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo index dcd53ea37..4dc2ad9f6 100644 --- a/tests/nodes/and_fp16x16.cairo +++ b/tests/nodes/and_fp16x16.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::FP16x16TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo index b32a5f0b6..60341e471 100644 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ b/tests/nodes/and_fp16x16/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_0() -> Tensor { 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: false }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 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: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + 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: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo index 2b2036fce..0fa0aab56 100644 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ b/tests/nodes/and_fp16x16/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_1() -> Tensor { 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: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); 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: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 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 }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo index 8a754463f..f33e1f678 100644 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ b/tests/nodes/and_fp16x16/output_0.cairo @@ -12,29 +12,29 @@ fn output_0() -> Tensor { 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(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); + data.append(0); + data.append(1); + data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo index 0f0a979da..a94e21b2c 100644 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ b/tests/nodes/and_fp16x16_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::FP16x16TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo index 2554de21d..50048a641 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo index 019f2f532..a92003169 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_fp16x16_broadcast/output_0.cairo index 12e081541..486b39f3d 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); data.append(0); - data.append(1); - data.append(1); + data.append(0); + data.append(0); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo index 373cfadaf..70b96f1d5 100644 --- a/tests/nodes/and_fp8x23.cairo +++ b/tests/nodes/and_fp8x23.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo index b093e4c53..95ee20a11 100644 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ b/tests/nodes/and_fp8x23/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); 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: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 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: true }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 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: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo index 0553e0019..e689e6c06 100644 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ b/tests/nodes/and_fp8x23/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_1() -> Tensor { 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: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); 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: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo index fa2a76b74..6a3748b94 100644 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ b/tests/nodes/and_fp8x23/output_0.cairo @@ -10,7 +10,6 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); - data.append(0); data.append(1); data.append(1); data.append(1); @@ -18,23 +17,24 @@ fn output_0() -> Tensor { 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(0); 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(1); data.append(0); data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo index ad50264f8..12ef3a56f 100644 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ b/tests/nodes/and_fp8x23_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::U32Tensor; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo index f7cb3a134..bd881a8c8 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,8 +10,8 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); 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: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo index 35cf05e4e..ab5b373e8 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_fp8x23_broadcast/output_0.cairo index 3883dcaf3..f90728ddd 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(0); data.append(1); - data.append(1); - data.append(1); + data.append(0); data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_i32.cairo index fd56fd1bb..c33b4b693 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_i32.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32TensorPartialEq; use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo index bb190dea5..f24395659 100644 --- a/tests/nodes/and_i32/input_0.cairo +++ b/tests/nodes/and_i32/input_0.cairo @@ -11,31 +11,31 @@ fn input_0() -> Tensor { 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: 1, 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: 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: true }); 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: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 1, sign: true }); + 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: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); 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 }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo index 45d38f5a8..e9e10b011 100644 --- a/tests/nodes/and_i32/input_1.cairo +++ b/tests/nodes/and_i32/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 1, 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: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + 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: 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: 0, 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: 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: 2, sign: true }); data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo index bb81daa72..b4d327559 100644 --- a/tests/nodes/and_i32/output_0.cairo +++ b/tests/nodes/and_i32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); 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(1); 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(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()) } diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo index 761e4e147..261a9f678 100644 --- a/tests/nodes/and_i32_broadcast.cairo +++ b/tests/nodes/and_i32_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I32TensorPartialEq; use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo index 2d6775e4b..8c1a32e15 100644 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ b/tests/nodes/and_i32_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); 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 }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo index 07dcdc4f2..f254b84b0 100644 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ b/tests/nodes/and_i32_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_i32_broadcast/output_0.cairo index f7205c752..3883dcaf3 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_i32_broadcast/output_0.cairo @@ -10,7 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); data.append(1); - data.append(0); - data.append(0); + data.append(1); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_i8.cairo index 5f03b69eb..8d0033616 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_i8.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo index 0c3934de7..5455e41fe 100644 --- a/tests/nodes/and_i8/input_0.cairo +++ b/tests/nodes/and_i8/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { 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: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, 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: 2, sign: true }); 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: 0, 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: 2, 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: 2, sign: false }); + data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, 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: 1, sign: true }); + 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: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo index 43c7fdb27..d1795b1f2 100644 --- a/tests/nodes/and_i8/input_1.cairo +++ b/tests/nodes/and_i8/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { 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: 1, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); + 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: 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: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); 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: false }); + data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); 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: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo index f3a1ad29a..2c1e28acc 100644 --- a/tests/nodes/and_i8/output_0.cairo +++ b/tests/nodes/and_i8/output_0.cairo @@ -9,30 +9,30 @@ fn output_0() -> Tensor { 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(0); 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(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(0); data.append(1); diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo index d2da45ca6..3083033b0 100644 --- a/tests/nodes/and_i8_broadcast.cairo +++ b/tests/nodes/and_i8_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo index 542c0c702..795d54aa9 100644 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ b/tests/nodes/and_i8_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); 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 }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo index e9b39b561..6b11828c4 100644 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ b/tests/nodes/and_i8_broadcast/input_1.cairo @@ -10,6 +10,6 @@ fn input_1() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo index f5c996719..bcaaa3bed 100644 --- a/tests/nodes/and_u32.cairo +++ b/tests/nodes/and_u32.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo index f04e9df2f..77c92fd0c 100644 --- a/tests/nodes/and_u32/input_0.cairo +++ b/tests/nodes/and_u32/input_0.cairo @@ -9,32 +9,32 @@ fn input_0() -> Tensor { 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(1); data.append(0); + data.append(1); 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(1); data.append(0); data.append(2); + data.append(2); + data.append(1); data.append(0); data.append(0); + data.append(3); + data.append(1); + data.append(4); + data.append(3); + data.append(3); + data.append(2); + data.append(3); data.append(1); + data.append(2); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo index 3b2fcb9c1..a213c91a6 100644 --- a/tests/nodes/and_u32/input_1.cairo +++ b/tests/nodes/and_u32/input_1.cairo @@ -9,32 +9,32 @@ fn input_1() -> Tensor { 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(5); + data.append(4); + data.append(3); + data.append(1); data.append(0); data.append(0); + data.append(1); + data.append(3); 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(3); + data.append(5); + data.append(5); data.append(4); + data.append(5); + data.append(3); data.append(1); - data.append(1); + data.append(0); data.append(3); + data.append(2); + data.append(0); + data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo index 576401ac8..88f761904 100644 --- a/tests/nodes/and_u32/output_0.cairo +++ b/tests/nodes/and_u32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { 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(0); 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(0); + data.append(1); + data.append(1); data.append(0); data.append(1); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo index cf022d7e5..301f481ed 100644 --- a/tests/nodes/and_u32_broadcast.cairo +++ b/tests/nodes/and_u32_broadcast.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo index 17f01780b..2b490c8f6 100644 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ b/tests/nodes/and_u32_broadcast/input_0.cairo @@ -8,9 +8,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); data.append(2); - data.append(2); - data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo index a11f0a16e..4e6f9c12f 100644 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ b/tests/nodes/and_u32_broadcast/input_1.cairo @@ -8,7 +8,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(5); - data.append(5); + data.append(2); + data.append(3); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo index 3883dcaf3..745afb892 100644 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ b/tests/nodes/and_u32_broadcast/output_0.cairo @@ -8,8 +8,8 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); + data.append(0); + data.append(0); data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) From 8687ee92ee6277cf6d891bc91a4e5a0143802503 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 15 Nov 2023 11:43:20 +0200 Subject: [PATCH 058/160] Revert "datasource generator" This reverts commit c8dca89672de50cb0a24633b704405a9f7408489. --- tests/nodes/and_fp16x16.cairo | 6 +-- tests/nodes/and_fp16x16/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp16x16/input_1.cairo | 33 +++++++++-------- tests/nodes/and_fp16x16/output_0.cairo | 14 +++---- tests/nodes/and_fp16x16_broadcast.cairo | 6 +-- .../nodes/and_fp16x16_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp16x16_broadcast/input_1.cairo | 7 ++-- .../and_fp16x16_broadcast/output_0.cairo | 6 +-- tests/nodes/and_fp8x23.cairo | 6 +-- tests/nodes/and_fp8x23/input_0.cairo | 31 ++++++++-------- tests/nodes/and_fp8x23/input_1.cairo | 37 ++++++++++--------- tests/nodes/and_fp8x23/output_0.cairo | 8 ++-- tests/nodes/and_fp8x23_broadcast.cairo | 6 +-- .../nodes/and_fp8x23_broadcast/input_0.cairo | 7 ++-- .../nodes/and_fp8x23_broadcast/input_1.cairo | 5 ++- .../nodes/and_fp8x23_broadcast/output_0.cairo | 4 +- tests/nodes/and_i32.cairo | 6 +-- tests/nodes/and_i32/input_0.cairo | 26 ++++++------- tests/nodes/and_i32/input_1.cairo | 30 +++++++-------- tests/nodes/and_i32/output_0.cairo | 8 ++-- tests/nodes/and_i32_broadcast.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_0.cairo | 6 +-- tests/nodes/and_i32_broadcast/input_1.cairo | 2 +- tests/nodes/and_i32_broadcast/output_0.cairo | 4 +- tests/nodes/and_i8.cairo | 8 ++-- tests/nodes/and_i8/input_0.cairo | 28 +++++++------- tests/nodes/and_i8/input_1.cairo | 28 +++++++------- tests/nodes/and_i8/output_0.cairo | 14 +++---- tests/nodes/and_i8_broadcast.cairo | 8 ++-- tests/nodes/and_i8_broadcast/input_0.cairo | 4 +- tests/nodes/and_i8_broadcast/input_1.cairo | 2 +- tests/nodes/and_u32.cairo | 4 +- tests/nodes/and_u32/input_0.cairo | 28 +++++++------- tests/nodes/and_u32/input_1.cairo | 30 +++++++-------- tests/nodes/and_u32/output_0.cairo | 10 ++--- tests/nodes/and_u32_broadcast.cairo | 4 +- tests/nodes/and_u32_broadcast/input_0.cairo | 4 +- tests/nodes/and_u32_broadcast/input_1.cairo | 4 +- tests/nodes/and_u32_broadcast/output_0.cairo | 4 +- 39 files changed, 237 insertions(+), 245 deletions(-) diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo index 4dc2ad9f6..dcd53ea37 100644 --- a/tests/nodes/and_fp16x16.cairo +++ b/tests/nodes/and_fp16x16.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo index 60341e471..b32a5f0b6 100644 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ b/tests/nodes/and_fp16x16/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,31 +12,31 @@ fn input_0() -> Tensor { 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: 65536, sign: false }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 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: 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: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, 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()) } diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo index 0fa0aab56..2b2036fce 100644 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ b/tests/nodes/and_fp16x16/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,32 +11,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - 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: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 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: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 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()) } diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo index f33e1f678..8a754463f 100644 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ b/tests/nodes/and_fp16x16/output_0.cairo @@ -12,29 +12,29 @@ fn output_0() -> Tensor { 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(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(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(0); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo index a94e21b2c..0f0a979da 100644 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ b/tests/nodes/and_fp16x16_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP16x16Tensor; use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo index 50048a641..2554de21d 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,9 +10,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo index a92003169..019f2f532 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; +use orion::numbers::FixedTrait; +use orion::numbers::FP16x16; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,7 +10,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_fp16x16_broadcast/output_0.cairo index 486b39f3d..12e081541 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(1); data.append(0); - data.append(0); - data.append(0); - data.append(0); + data.append(1); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo index 70b96f1d5..373cfadaf 100644 --- a/tests/nodes/and_fp8x23.cairo +++ b/tests/nodes/and_fp8x23.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo index 95ee20a11..b093e4c53 100644 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ b/tests/nodes/and_fp8x23/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,31 +12,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); 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: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 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: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo index e689e6c06..0553e0019 100644 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ b/tests/nodes/and_fp8x23/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,32 +11,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, 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: 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()) } diff --git a/tests/nodes/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo index 6a3748b94..fa2a76b74 100644 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ b/tests/nodes/and_fp8x23/output_0.cairo @@ -10,6 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); + data.append(0); data.append(1); data.append(1); data.append(1); @@ -17,24 +18,23 @@ fn output_0() -> Tensor { 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(0); 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(1); data.append(0); data.append(1); - data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo index 12ef3a56f..ad50264f8 100644 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ b/tests/nodes/and_fp8x23_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo index bd881a8c8..f7cb3a134 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_0.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,8 +11,8 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo index ab5b373e8..35cf05e4e 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_1.cairo @@ -1,7 +1,8 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; +use orion::numbers::FixedTrait; +use orion::numbers::FP8x23; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,7 +10,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_fp8x23_broadcast/output_0.cairo index f90728ddd..3883dcaf3 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/output_0.cairo @@ -8,9 +8,9 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); data.append(1); - data.append(0); + data.append(1); + data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_i32.cairo index c33b4b693..fd56fd1bb 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_i32.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo index f24395659..bb190dea5 100644 --- a/tests/nodes/and_i32/input_0.cairo +++ b/tests/nodes/and_i32/input_0.cairo @@ -11,31 +11,31 @@ fn input_0() -> Tensor { 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: 1, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, 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: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: true }); 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: true }); - data.append(i32 { mag: 3, 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: 1, sign: false }); - 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()) } diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo index e9e10b011..45d38f5a8 100644 --- a/tests/nodes/and_i32/input_1.cairo +++ b/tests/nodes/and_i32/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); 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: 0, sign: false }); - 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: 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: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, 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: 2, sign: false }); data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, 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: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 3, sign: true }); + 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()) } diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo index b4d327559..bb81daa72 100644 --- a/tests/nodes/and_i32/output_0.cairo +++ b/tests/nodes/and_i32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); 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(1); 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(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()) } diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo index 261a9f678..761e4e147 100644 --- a/tests/nodes/and_i32_broadcast.cairo +++ b/tests/nodes/and_i32_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo index 8c1a32e15..2d6775e4b 100644 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ b/tests/nodes/and_i32_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, 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()) } diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo index f254b84b0..07dcdc4f2 100644 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ b/tests/nodes/and_i32_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_i32_broadcast/output_0.cairo index 3883dcaf3..f7205c752 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_i32_broadcast/output_0.cairo @@ -10,7 +10,7 @@ fn output_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); data.append(1); - data.append(1); - data.append(1); + data.append(0); + data.append(0); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_i8.cairo index 8d0033616..5f03b69eb 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_i8.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo index 5455e41fe..0c3934de7 100644 --- a/tests/nodes/and_i8/input_0.cairo +++ b/tests/nodes/and_i8/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, 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: 1, sign: true }); - data.append(i8 { mag: 1, 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: 2, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, 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: 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: 2, 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()) } diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo index d1795b1f2..43c7fdb27 100644 --- a/tests/nodes/and_i8/input_1.cairo +++ b/tests/nodes/and_i8/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); + 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: 0, 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: 1, sign: true }); - 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: 0, 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: 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: false }); 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: 2, sign: false }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); + 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()) } diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo index 2c1e28acc..f3a1ad29a 100644 --- a/tests/nodes/and_i8/output_0.cairo +++ b/tests/nodes/and_i8/output_0.cairo @@ -9,30 +9,30 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - 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(0); - 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(0); data.append(0); 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(0); + data.append(0); data.append(1); data.append(0); data.append(1); diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo index 3083033b0..d2da45ca6 100644 --- a/tests/nodes/and_i8_broadcast.cairo +++ b/tests/nodes/and_i8_broadcast.cairo @@ -3,13 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::I8Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo index 795d54aa9..542c0c702 100644 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ b/tests/nodes/and_i8_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo index 6b11828c4..e9b39b561 100644 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ b/tests/nodes/and_i8_broadcast/input_1.cairo @@ -10,6 +10,6 @@ fn input_1() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo index bcaaa3bed..f5c996719 100644 --- a/tests/nodes/and_u32.cairo +++ b/tests/nodes/and_u32.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo index 77c92fd0c..f04e9df2f 100644 --- a/tests/nodes/and_u32/input_0.cairo +++ b/tests/nodes/and_u32/input_0.cairo @@ -9,32 +9,32 @@ fn input_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(2); - data.append(4); - data.append(5); data.append(5); - data.append(5); - data.append(1); - data.append(1); - data.append(0); 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(3); - data.append(1); data.append(4); data.append(3); - 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()) } diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo index a213c91a6..3b2fcb9c1 100644 --- a/tests/nodes/and_u32/input_1.cairo +++ b/tests/nodes/and_u32/input_1.cairo @@ -9,32 +9,32 @@ fn input_1() -> Tensor { 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(5); - data.append(5); - data.append(4); - data.append(3); + data.append(2); data.append(1); + data.append(3); + data.append(5); data.append(0); data.append(0); - data.append(1); - data.append(3); data.append(0); - data.append(1); - data.append(5); - data.append(3); data.append(5); + data.append(2); + data.append(1); + data.append(2); data.append(5); + data.append(1); data.append(4); - data.append(5); - data.append(3); data.append(1); - data.append(0); + data.append(4); + data.append(4); + data.append(1); + data.append(1); data.append(3); - data.append(2); - data.append(0); - data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo index 88f761904..576401ac8 100644 --- a/tests/nodes/and_u32/output_0.cairo +++ b/tests/nodes/and_u32/output_0.cairo @@ -10,31 +10,31 @@ fn output_0() -> Tensor { 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(0); 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(1); data.append(0); data.append(1); - data.append(1); data.append(0); - data.append(1); data.append(0); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo index 301f481ed..cf022d7e5 100644 --- a/tests/nodes/and_u32_broadcast.cairo +++ b/tests/nodes/and_u32_broadcast.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::TensorTrait; use orion::operators::tensor::U32Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo index 2b490c8f6..17f01780b 100644 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ b/tests/nodes/and_u32_broadcast/input_0.cairo @@ -8,9 +8,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); - data.append(0); data.append(2); + data.append(2); + data.append(5); data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo index 4e6f9c12f..a11f0a16e 100644 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ b/tests/nodes/and_u32_broadcast/input_1.cairo @@ -8,7 +8,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(2); - data.append(3); + data.append(5); + data.append(5); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo index 745afb892..3883dcaf3 100644 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ b/tests/nodes/and_u32_broadcast/output_0.cairo @@ -8,8 +8,8 @@ fn output_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); - data.append(0); + data.append(1); + data.append(1); data.append(1); data.append(1); TensorTrait::new(shape.span(), data.span()) From d00fec9ece23c3eabfea1a3d17ba84bafbf5a3b3 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 12:18:56 +0100 Subject: [PATCH 059/160] Refactor operator with subfunctions --- .../tensor/ml/array_feature_extractor.cairo | 101 ++++++++++++------ 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 0ad7942a8..4aee41f7e 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -11,74 +11,110 @@ fn array_feature_extractor< MAG, impl TTensor: TensorTrait, impl TNumber: NumberTrait, - impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop >( - mut self: Tensor, indices: Tensor + self: Tensor, indices: Tensor ) -> Tensor { assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); - let input_shape: Span = self.shape; - let input_data: Span = self.data; - - if input_shape.len() == 1 { + if self.shape.len() == 1 { + return process_1D_tensor(self, indices); + } - let mut output_data = ArrayTrait::::new(); + let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); - let mut indices_counter: usize = 0; + let output_data = calculate_output_data::(self, indices, total_elements); - loop { - if indices_counter > indices.data.len() - 1 { - break; - } + return TensorTrait::new(output_shape.span(), output_data.span()); +} - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < *input_shape.at(0), 'Indices out of range'); +fn process_1D_tensor< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: Tensor, indices: Tensor +) -> Tensor { - let mut current_data_value = *input_data.at(current_indices_value); + let mut output_data = ArrayTrait::::new(); - output_data.append(current_data_value); - - indices_counter += 1; - }; + let mut indices_counter: usize = 0; + loop { + if indices_counter > indices.data.len() - 1 { + break; + } - return TensorTrait::new(indices.shape, output_data.span()); - } + let mut current_indices_value = *indices.data.at(indices_counter); + assert(current_indices_value < *self.shape.at(0), 'Indices out of range'); - let last_tensor_axis: usize = *input_shape.at(input_shape.len() - 1); + let mut current_data_value = *self.data.at(current_indices_value); + output_data.append(current_data_value); + + indices_counter += 1; + }; - let mut input_shape_counter: usize = 0; + return TensorTrait::new(indices.shape, output_data.span()); +} - let mut total_elements: usize = 1; +fn calculate_output_shape< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + input_shape: Span, indices: Tensor +) -> (Array, usize) { + + let mut total_elements: usize = 1; let mut output_shape: Array = ArrayTrait::new(); + let mut input_shape_counter: usize = 0; loop { if input_shape_counter > input_shape.len() - 2 { break; } let mut current_shape_value = *input_shape.at(input_shape_counter); - output_shape.append(current_shape_value); total_elements = total_elements * current_shape_value; input_shape_counter += 1; - }; output_shape.append(indices.data.len()); + return (output_shape, total_elements); +} + + +fn calculate_output_data< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: Tensor, indices: Tensor, total_elements: usize +) -> Array { + + let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); + let mut output_data = ArrayTrait::::new(); let strides: Span = TensorTrait::stride(@self); let mut element_counter: usize = 0; - loop { if element_counter > total_elements - 1 { break; @@ -91,29 +127,24 @@ fn array_feature_extractor< }; let mut indices_counter: usize = 0; - loop { if indices_counter > indices.data.len() - 1 { break; } let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < last_tensor_axis, 'Indices out of range'); let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); - let mut current_data_value = *input_data.at(flat_index); - + let mut current_data_value = *self.data.at(flat_index); output_data.append(current_data_value); indices_counter += 1; - }; element_counter += 1; }; - return TensorTrait::new(output_shape.span(), output_data.span()); - -} \ No newline at end of file + return output_data; +} From f0a6613718f724305cc99ee1186bfe33a55652ae Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 15 Nov 2023 11:45:45 +0100 Subject: [PATCH 060/160] Add nodegen script --- nodegen/node/sequence_length.py | 173 ++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 nodegen/node/sequence_length.py diff --git a/nodegen/node/sequence_length.py b/nodegen/node/sequence_length.py new file mode 100644 index 000000000..87f0dcd01 --- /dev/null +++ b/nodegen/node/sequence_length.py @@ -0,0 +1,173 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +scalar = lambda x: Tensor(Dtype.U32, (), np.array([x]).astype(np.uint32).flatten()) + + +class Sequence_length(RunAll): + @staticmethod + def sequence_length_u32(): + def default(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_u32" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + def broadcast(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + + for _ in range(tensor_cnt): + shape = np.random.randint(1, 4, 2) + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_u32_broadcast" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + default() + broadcast() + + @staticmethod + def sequence_length_i32(): + def default(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_i32" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + def broadcast(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + + for _ in range(tensor_cnt): + shape = np.random.randint(1, 4, 2) + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_i32_broadcast" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + default() + broadcast() + + @staticmethod + def sequence_length_i8(): + def default(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_i8" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + def broadcast(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + + for _ in range(tensor_cnt): + shape = np.random.randint(1, 4, 2) + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_length_i8_broadcast" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + default() + broadcast() + + @staticmethod + def sequence_length_fp8x23(): + def default(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + name = "sequence_length_fp8x23" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + def broadcast(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + + for _ in range(tensor_cnt): + shape = np.random.randint(1, 4, 2) + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + name = "sequence_length_fp8x23_broadcast" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + default() + broadcast() + + @staticmethod + def sequence_length_fp16x16(): + def default(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + name = "sequence_length_fp16x16" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + def broadcast(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + + for _ in range(tensor_cnt): + shape = np.random.randint(1, 4, 2) + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + name = "sequence_length_fp16x16_broadcast" + make_test([sequence], scalar(len(sequence)), "input_0.sequence_length()", name) + + default() + broadcast() From cc5abb93c7cbae5239d91fe5705cf1902d472fce Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 15 Nov 2023 13:27:03 +0100 Subject: [PATCH 061/160] Add tests and implementation --- src/operators/tensor/core.cairo | 3 + .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + .../tensor/math/sequence_length.cairo | 15 +++ tests/nodes.cairo | 10 ++ tests/nodes/sequence_length_fp16x16.cairo | 22 ++++ .../sequence_length_fp16x16/input_0.cairo | 109 ++++++++++++++++++ .../sequence_length_fp16x16/output_0.cairo | 11 ++ .../sequence_length_fp16x16_broadcast.cairo | 22 ++++ .../input_0.cairo | 88 ++++++++++++++ .../output_0.cairo | 11 ++ tests/nodes/sequence_length_fp8x23.cairo | 22 ++++ .../sequence_length_fp8x23/input_0.cairo | 70 +++++++++++ .../sequence_length_fp8x23/output_0.cairo | 11 ++ .../sequence_length_fp8x23_broadcast.cairo | 22 ++++ .../input_0.cairo | 20 ++++ .../output_0.cairo | 11 ++ tests/nodes/sequence_length_i32.cairo | 22 ++++ tests/nodes/sequence_length_i32/input_0.cairo | 30 +++++ .../nodes/sequence_length_i32/output_0.cairo | 11 ++ .../nodes/sequence_length_i32_broadcast.cairo | 22 ++++ .../input_0.cairo | 56 +++++++++ .../output_0.cairo | 11 ++ tests/nodes/sequence_length_i8.cairo | 22 ++++ tests/nodes/sequence_length_i8/input_0.cairo | 52 +++++++++ tests/nodes/sequence_length_i8/output_0.cairo | 11 ++ .../nodes/sequence_length_i8_broadcast.cairo | 22 ++++ .../input_0.cairo | 62 ++++++++++ .../output_0.cairo | 11 ++ tests/nodes/sequence_length_u32.cairo | 20 ++++ tests/nodes/sequence_length_u32/input_0.cairo | 26 +++++ .../nodes/sequence_length_u32/output_0.cairo | 11 ++ .../nodes/sequence_length_u32_broadcast.cairo | 20 ++++ .../input_0.cairo | 19 +++ .../output_0.cairo | 11 ++ 44 files changed, 927 insertions(+) create mode 100644 src/operators/tensor/math/sequence_length.cairo create mode 100644 tests/nodes/sequence_length_fp16x16.cairo create mode 100644 tests/nodes/sequence_length_fp16x16/input_0.cairo create mode 100644 tests/nodes/sequence_length_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_length_fp16x16_broadcast.cairo create mode 100644 tests/nodes/sequence_length_fp16x16_broadcast/input_0.cairo create mode 100644 tests/nodes/sequence_length_fp16x16_broadcast/output_0.cairo create mode 100644 tests/nodes/sequence_length_fp8x23.cairo create mode 100644 tests/nodes/sequence_length_fp8x23/input_0.cairo create mode 100644 tests/nodes/sequence_length_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_length_fp8x23_broadcast.cairo create mode 100644 tests/nodes/sequence_length_fp8x23_broadcast/input_0.cairo create mode 100644 tests/nodes/sequence_length_fp8x23_broadcast/output_0.cairo create mode 100644 tests/nodes/sequence_length_i32.cairo create mode 100644 tests/nodes/sequence_length_i32/input_0.cairo create mode 100644 tests/nodes/sequence_length_i32/output_0.cairo create mode 100644 tests/nodes/sequence_length_i32_broadcast.cairo create mode 100644 tests/nodes/sequence_length_i32_broadcast/input_0.cairo create mode 100644 tests/nodes/sequence_length_i32_broadcast/output_0.cairo create mode 100644 tests/nodes/sequence_length_i8.cairo create mode 100644 tests/nodes/sequence_length_i8/input_0.cairo create mode 100644 tests/nodes/sequence_length_i8/output_0.cairo create mode 100644 tests/nodes/sequence_length_i8_broadcast.cairo create mode 100644 tests/nodes/sequence_length_i8_broadcast/input_0.cairo create mode 100644 tests/nodes/sequence_length_i8_broadcast/output_0.cairo create mode 100644 tests/nodes/sequence_length_u32.cairo create mode 100644 tests/nodes/sequence_length_u32/input_0.cairo create mode 100644 tests/nodes/sequence_length_u32/output_0.cairo create mode 100644 tests/nodes/sequence_length_u32_broadcast.cairo create mode 100644 tests/nodes/sequence_length_u32_broadcast/input_0.cairo create mode 100644 tests/nodes/sequence_length_u32_broadcast/output_0.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..872117142 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,8 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// TODO + fn sequence_length(self: Array>) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..118fdf4fb 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..07f736f90 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..6877bf431 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 f764b1920..f836082f2 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 6cded29b3..7f0c2a0c9 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 fdcdac1eb..2629e9076 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..202db085f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 8017ab300..af8994a03 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 4f2731b80..5fcb5f635 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// 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 2f3c3a2ef..ed28b5872 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_length(self: Array>) -> Tensor { + math::sequence_length::sequence_length(self) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..856a73f1d 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_length; diff --git a/src/operators/tensor/math/sequence_length.cairo b/src/operators/tensor/math/sequence_length.cairo new file mode 100644 index 000000000..36aacae5a --- /dev/null +++ b/src/operators/tensor/math/sequence_length.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; + + +fn sequence_length>(self: Array>) -> Tensor { + let mut shape = ArrayTrait::::new(); + let mut result = ArrayTrait::new(); + result.append(self.len()); + + Tensor:: { + shape: shape.span(), + data: result.span(), + } +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..69d3bfcbf 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,13 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_length_fp16x16; +mod sequence_length_fp16x16_broadcast; +mod sequence_length_fp8x23; +mod sequence_length_fp8x23_broadcast; +mod sequence_length_i32; +mod sequence_length_i32_broadcast; +mod sequence_length_i8; +mod sequence_length_i8_broadcast; +mod sequence_length_u32; +mod sequence_length_u32_broadcast; diff --git a/tests/nodes/sequence_length_fp16x16.cairo b/tests/nodes/sequence_length_fp16x16.cairo new file mode 100644 index 000000000..44d9cf8b7 --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_fp16x16/input_0.cairo b/tests/nodes/sequence_length_fp16x16/input_0.cairo new file mode 100644 index 000000000..1943f2e3a --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16/input_0.cairo @@ -0,0 +1,109 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_fp16x16/output_0.cairo b/tests/nodes/sequence_length_fp16x16/output_0.cairo new file mode 100644 index 000000000..cc6040e61 --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(9); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_fp16x16_broadcast.cairo b/tests/nodes/sequence_length_fp16x16_broadcast.cairo new file mode 100644 index 000000000..9c3996555 --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_fp16x16_broadcast() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_fp16x16_broadcast/input_0.cairo b/tests/nodes/sequence_length_fp16x16_broadcast/input_0.cairo new file mode 100644 index 000000000..c15af2315 --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16_broadcast/input_0.cairo @@ -0,0 +1,88 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_fp16x16_broadcast/output_0.cairo b/tests/nodes/sequence_length_fp16x16_broadcast/output_0.cairo new file mode 100644 index 000000000..df7dfed8b --- /dev/null +++ b/tests/nodes/sequence_length_fp16x16_broadcast/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(6); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_fp8x23.cairo b/tests/nodes/sequence_length_fp8x23.cairo new file mode 100644 index 000000000..232dda071 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_fp8x23/input_0.cairo b/tests/nodes/sequence_length_fp8x23/input_0.cairo new file mode 100644 index 000000000..5a57eb8e7 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_fp8x23/output_0.cairo b/tests/nodes/sequence_length_fp8x23/output_0.cairo new file mode 100644 index 000000000..fa5db15f8 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(5); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_fp8x23_broadcast.cairo b/tests/nodes/sequence_length_fp8x23_broadcast.cairo new file mode 100644 index 000000000..9e8340e55 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_fp8x23_broadcast() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_fp8x23_broadcast/input_0.cairo b/tests/nodes/sequence_length_fp8x23_broadcast/input_0.cairo new file mode 100644 index 000000000..86c579ca0 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23_broadcast/input_0.cairo @@ -0,0 +1,20 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_fp8x23_broadcast/output_0.cairo b/tests/nodes/sequence_length_fp8x23_broadcast/output_0.cairo new file mode 100644 index 000000000..abdf2e9d5 --- /dev/null +++ b/tests/nodes/sequence_length_fp8x23_broadcast/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_i32.cairo b/tests/nodes/sequence_length_i32.cairo new file mode 100644 index 000000000..005bbc313 --- /dev/null +++ b/tests/nodes/sequence_length_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_i32/input_0.cairo b/tests/nodes/sequence_length_i32/input_0.cairo new file mode 100644 index 000000000..970397961 --- /dev/null +++ b/tests/nodes/sequence_length_i32/input_0.cairo @@ -0,0 +1,30 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_i32/output_0.cairo b/tests/nodes/sequence_length_i32/output_0.cairo new file mode 100644 index 000000000..8df327a8b --- /dev/null +++ b/tests/nodes/sequence_length_i32/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_i32_broadcast.cairo b/tests/nodes/sequence_length_i32_broadcast.cairo new file mode 100644 index 000000000..5af2cb7af --- /dev/null +++ b/tests/nodes/sequence_length_i32_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_i32_broadcast() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_i32_broadcast/input_0.cairo b/tests/nodes/sequence_length_i32_broadcast/input_0.cairo new file mode 100644 index 000000000..4588ce948 --- /dev/null +++ b/tests/nodes/sequence_length_i32_broadcast/input_0.cairo @@ -0,0 +1,56 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_i32_broadcast/output_0.cairo b/tests/nodes/sequence_length_i32_broadcast/output_0.cairo new file mode 100644 index 000000000..0e770ce74 --- /dev/null +++ b/tests/nodes/sequence_length_i32_broadcast/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_i8.cairo b/tests/nodes/sequence_length_i8.cairo new file mode 100644 index 000000000..db9b7fbe6 --- /dev/null +++ b/tests/nodes/sequence_length_i8.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::I8Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_i8/input_0.cairo b/tests/nodes/sequence_length_i8/input_0.cairo new file mode 100644 index 000000000..5a91461ac --- /dev/null +++ b/tests/nodes/sequence_length_i8/input_0.cairo @@ -0,0 +1,52 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_i8/output_0.cairo b/tests/nodes/sequence_length_i8/output_0.cairo new file mode 100644 index 000000000..08a3d1576 --- /dev/null +++ b/tests/nodes/sequence_length_i8/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_i8_broadcast.cairo b/tests/nodes/sequence_length_i8_broadcast.cairo new file mode 100644 index 000000000..a67bc0c0f --- /dev/null +++ b/tests/nodes/sequence_length_i8_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::I8Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_i8_broadcast() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_i8_broadcast/input_0.cairo b/tests/nodes/sequence_length_i8_broadcast/input_0.cairo new file mode 100644 index 000000000..71aca8901 --- /dev/null +++ b/tests/nodes/sequence_length_i8_broadcast/input_0.cairo @@ -0,0 +1,62 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_i8_broadcast/output_0.cairo b/tests/nodes/sequence_length_i8_broadcast/output_0.cairo new file mode 100644 index 000000000..0e770ce74 --- /dev/null +++ b/tests/nodes/sequence_length_i8_broadcast/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_u32.cairo b/tests/nodes/sequence_length_u32.cairo new file mode 100644 index 000000000..0ba4c2b79 --- /dev/null +++ b/tests/nodes/sequence_length_u32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_u32/input_0.cairo b/tests/nodes/sequence_length_u32/input_0.cairo new file mode 100644 index 000000000..f0a5cf3c2 --- /dev/null +++ b/tests/nodes/sequence_length_u32/input_0.cairo @@ -0,0 +1,26 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(1); + data.append(4); + data.append(0); + data.append(2); + data.append(4); + data.append(1); + data.append(3); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_u32/output_0.cairo b/tests/nodes/sequence_length_u32/output_0.cairo new file mode 100644 index 000000000..abdf2e9d5 --- /dev/null +++ b/tests/nodes/sequence_length_u32/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_length_u32_broadcast.cairo b/tests/nodes/sequence_length_u32_broadcast.cairo new file mode 100644 index 000000000..17f8f3474 --- /dev/null +++ b/tests/nodes/sequence_length_u32_broadcast.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_length_u32_broadcast() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.sequence_length(); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_length_u32_broadcast/input_0.cairo b/tests/nodes/sequence_length_u32_broadcast/input_0.cairo new file mode 100644 index 000000000..a1ff2ed88 --- /dev/null +++ b/tests/nodes/sequence_length_u32_broadcast/input_0.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_length_u32_broadcast/output_0.cairo b/tests/nodes/sequence_length_u32_broadcast/output_0.cairo new file mode 100644 index 000000000..abdf2e9d5 --- /dev/null +++ b/tests/nodes/sequence_length_u32_broadcast/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} From 9a72346c56989194dc9fe70da82487515b1270f2 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Mon, 13 Nov 2023 20:24:55 +0100 Subject: [PATCH 062/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.sequence_empty.md | 35 ++++++++++++++++++ src/operators/tensor/core.cairo | 36 ++++++++++++++++++- .../tensor/math/sequence_empty.cairo | 1 + 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_empty.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..234ff7acd 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_empty](framework/operators/tensor/tensor.sequence\_empty.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 ebc50ad77..0042cdcc4 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..6a58898ff 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_empty.md b/docs/framework/operators/tensor/tensor.sequence_empty.md new file mode 100644 index 000000000..a95f952b9 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_empty.md @@ -0,0 +1,35 @@ +# tensor.sequence_empty + +```rust + fn sequence_empty() -> Array>; +``` + +Returns an empty tensor sequence. + +## Args + +## Returns + +An empty `Array>` instance. + +## Examples + +Let's create a new empty sequence. + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, // we import the trait + Tensor, // we import the type + U32Tensor // we import the implementation. +}; + +fn sequence_empty_example() -> Array> { + let sequence = TensorTrait::sequence_empty(); + + return sequence; +} + +>>> [] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index c364213e1..4a262b919 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3586,7 +3586,41 @@ trait TensorTrait { /// fn constant_of_shape(shape: Span, value: T) -> Tensor; /// # tensor.sequence_empty - /// TODO + /// + /// ```rust + /// fn sequence_empty() -> Array>; + /// ``` + /// + /// Returns an empty tensor sequence. + /// + /// ## Args + /// + /// ## Returns + /// + /// An empty `Array>` instance. + /// + /// ## Examples + /// + /// Let's create a new empty sequence. + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{ + /// TensorTrait, // we import the trait + /// Tensor, // we import the type + /// U32Tensor // we import the implementation. + /// }; + /// + /// fn sequence_empty_example() -> Array> { + /// let sequence = TensorTrait::sequence_empty(); + /// + /// return sequence; + /// } + /// + /// >>> [] + /// ``` + /// fn sequence_empty() -> Array>; } diff --git a/src/operators/tensor/math/sequence_empty.cairo b/src/operators/tensor/math/sequence_empty.cairo index 4e32a0429..c823cabe8 100644 --- a/src/operators/tensor/math/sequence_empty.cairo +++ b/src/operators/tensor/math/sequence_empty.cairo @@ -3,6 +3,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; +/// Cf: TensorTrait::sequence_empty docstring fn sequence_empty, impl TDrop: Drop>() -> Array> { let mut sequence = ArrayTrait::new(); From a791f4673561f0362a82f8164abbb802160aa252 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 15 Nov 2023 13:55:17 +0100 Subject: [PATCH 063/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.sequence_length.md | 36 ++++++++++++++++++ src/operators/tensor/core.cairo | 38 ++++++++++++++++++- .../tensor/math/sequence_length.cairo | 1 + 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_length.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..2649a0abc 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_length](framework/operators/tensor/tensor.sequence\_length.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 ebc50ad77..1111f0e11 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceLength](operators/tensor/tensor.sequence\_length.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..25ed8dcc6 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_length`](tensor.sequence\_length.md) | Returns the length of the input sequence. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_length.md b/docs/framework/operators/tensor/tensor.sequence_length.md new file mode 100644 index 000000000..8a18c14ff --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_length.md @@ -0,0 +1,36 @@ +# tensor.sequence_length + +```rust + fn sequence_length(self: Array>) -> Tensor; +``` + +Returns the length of the input sequence. + +## Args + +* `self`(`Array>`) - The input sequence. + +## Returns + +The length of the sequence as scalar, i.e. a tensor of shape []. + +## Examples + +Let's create new u32 Tensor with constant 42. + +```rust +let mut sequence = ArrayTrait::new(); + +let mut shape = ArrayTrait::::new(); +shape.append(1); +shape.append(2); + +let mut data = ArrayTrait::new(); +data.append(3); +data.append(1); + +sequence.append(TensorTrait::new(shape.span(), data.span())); + +sequence.sequence_length() +>>> [1] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 872117142..61ed62742 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3585,7 +3585,43 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; - /// TODO + /// # tensor.sequence_length + /// + /// ```rust + /// fn sequence_length(self: Array>) -> Tensor; + /// ``` + /// + /// Returns the length of the input sequence. + /// + /// ## Args + /// + /// * `self`(`Array>`) - The input sequence. + /// + /// ## Returns + /// + /// The length of the sequence as scalar, i.e. a tensor of shape []. + /// + /// ## Examples + /// + /// Let's create new u32 Tensor with constant 42. + /// + /// ```rust + /// let mut sequence = ArrayTrait::new(); + /// + /// let mut shape = ArrayTrait::::new(); + /// shape.append(1); + /// shape.append(2); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(3); + /// data.append(1); + /// + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// + /// sequence.sequence_length() + /// >>> [1] + /// ``` + /// fn sequence_length(self: Array>) -> Tensor; } diff --git a/src/operators/tensor/math/sequence_length.cairo b/src/operators/tensor/math/sequence_length.cairo index 36aacae5a..65feeab43 100644 --- a/src/operators/tensor/math/sequence_length.cairo +++ b/src/operators/tensor/math/sequence_length.cairo @@ -3,6 +3,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; +/// Cf: TensorTrait::sequence_length docstring fn sequence_length>(self: Array>) -> Tensor { let mut shape = ArrayTrait::::new(); let mut result = ArrayTrait::new(); From 5d3400f37796a169feedf0d3b966b44623563593 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:31:13 +0100 Subject: [PATCH 064/160] Implement operator --- src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 ++++ .../tensor/implementations/tensor_fp16x16.cairo | 4 ++++ .../tensor/implementations/tensor_fp16x16wide.cairo | 4 ++++ .../tensor/implementations/tensor_fp32x32.cairo | 4 ++++ .../tensor/implementations/tensor_fp64x64.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23.cairo | 4 ++++ .../tensor/implementations/tensor_fp8x23wide.cairo | 4 ++++ .../tensor/implementations/tensor_i32.cairo | 4 ++++ src/operators/tensor/implementations/tensor_i8.cairo | 4 ++++ .../tensor/implementations/tensor_u32.cairo | 4 ++++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/sequence_construct.cairo | 12 ++++++++++++ 13 files changed, 54 insertions(+) create mode 100644 src/operators/tensor/math/sequence_construct.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..04b6d5db1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + fn sequence_construct(tensors: Array>) -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..64997045a 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..6c529f9d1 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..b4667be75 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 f764b1920..f1ef49bb6 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 6cded29b3..56c42bdd4 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 fdcdac1eb..33a8144ae 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..95b19e98d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 8017ab300..521d92fa2 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 4f2731b80..3816d8da4 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// 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 2f3c3a2ef..72c1f4f77 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_construct(tensors: Array>) -> Array> { + math::sequence_construct::sequence_construct(tensors) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..bb4384da1 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_construct; diff --git a/src/operators/tensor/math/sequence_construct.cairo b/src/operators/tensor/math/sequence_construct.cairo new file mode 100644 index 000000000..7bf0d1a54 --- /dev/null +++ b/src/operators/tensor/math/sequence_construct.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; + + +/// Cf: TensorTrait::sequence_construct docstring +fn sequence_construct>(tensors: Array>) -> Array> { + + assert(tensors.len() >= 1, 'Input tensors must be >= 1'); + + return tensors; +} \ No newline at end of file From 195781a3329172bac794a3376b36f9e86afd39ac Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:39:31 +0100 Subject: [PATCH 065/160] Fix docstring --- src/operators/tensor/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 47aa8ba2c..220fa90b5 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -87,6 +87,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// From a2d44994f27a8307bf3a040e20b421cab27ca6b2 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 16:43:21 +0100 Subject: [PATCH 066/160] Fix docstring --- src/operators/tensor/core.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 81ab443c9..b4bb2208a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// From 00378a04186306593d021533381dcb1b12fbae00 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 17:25:09 +0100 Subject: [PATCH 067/160] Add tests --- nodegen/node/sequence_construct.py | 85 ++++++++++++++++++ tests/nodes.cairo | 5 ++ tests/nodes/sequence_construct_fp16x16.cairo | 20 +++++ .../sequence_construct_fp16x16/input_0.cairo | 76 ++++++++++++++++ .../sequence_construct_fp16x16/output_0.cairo | 76 ++++++++++++++++ tests/nodes/sequence_construct_fp8x23.cairo | 20 +++++ .../sequence_construct_fp8x23/input_0.cairo | 90 +++++++++++++++++++ .../sequence_construct_fp8x23/output_0.cairo | 90 +++++++++++++++++++ tests/nodes/sequence_construct_i32.cairo | 20 +++++ .../sequence_construct_i32/input_0.cairo | 30 +++++++ .../sequence_construct_i32/output_0.cairo | 30 +++++++ tests/nodes/sequence_construct_i8.cairo | 20 +++++ .../nodes/sequence_construct_i8/input_0.cairo | 43 +++++++++ .../sequence_construct_i8/output_0.cairo | 43 +++++++++ tests/nodes/sequence_construct_u32.cairo | 20 +++++ .../sequence_construct_u32/input_0.cairo | 90 +++++++++++++++++++ .../sequence_construct_u32/output_0.cairo | 90 +++++++++++++++++++ 17 files changed, 848 insertions(+) create mode 100644 nodegen/node/sequence_construct.py create mode 100644 tests/nodes/sequence_construct_fp16x16.cairo create mode 100644 tests/nodes/sequence_construct_fp16x16/input_0.cairo create mode 100644 tests/nodes/sequence_construct_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23/input_0.cairo create mode 100644 tests/nodes/sequence_construct_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_construct_i32.cairo create mode 100644 tests/nodes/sequence_construct_i32/input_0.cairo create mode 100644 tests/nodes/sequence_construct_i32/output_0.cairo create mode 100644 tests/nodes/sequence_construct_i8.cairo create mode 100644 tests/nodes/sequence_construct_i8/input_0.cairo create mode 100644 tests/nodes/sequence_construct_i8/output_0.cairo create mode 100644 tests/nodes/sequence_construct_u32.cairo create mode 100644 tests/nodes/sequence_construct_u32/input_0.cairo create mode 100644 tests/nodes/sequence_construct_u32/output_0.cairo diff --git a/nodegen/node/sequence_construct.py b/nodegen/node/sequence_construct.py new file mode 100644 index 000000000..7c76d1532 --- /dev/null +++ b/nodegen/node/sequence_construct.py @@ -0,0 +1,85 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Sequence_construct(RunAll): + + @staticmethod + def sequence_construct_u32(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_u32" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_i32(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_i32" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_i8(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + name = "sequence_construct_i8" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_fp8x23(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + name = "sequence_construct_fp8x23" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) + + + @staticmethod + def sequence_construct_fp16x16(): + sequence = [] + tensor_cnt = np.random.randint(1, 10) + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + name = "sequence_construct_fp16x16" + make_test([sequence], sequence, "TensorTrait::sequence_construct(input_0)", name) diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..1c35ea8f6 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,8 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_construct_fp16x16; +mod sequence_construct_fp8x23; +mod sequence_construct_i32; +mod sequence_construct_i8; +mod sequence_construct_u32; diff --git a/tests/nodes/sequence_construct_fp16x16.cairo b/tests/nodes/sequence_construct_fp16x16.cairo new file mode 100644 index 000000000..926a57fe2 --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_fp16x16/input_0.cairo b/tests/nodes/sequence_construct_fp16x16/input_0.cairo new file mode 100644 index 000000000..770942e5b --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16/input_0.cairo @@ -0,0 +1,76 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp16x16/output_0.cairo b/tests/nodes/sequence_construct_fp16x16/output_0.cairo new file mode 100644 index 000000000..1de556154 --- /dev/null +++ b/tests/nodes/sequence_construct_fp16x16/output_0.cairo @@ -0,0 +1,76 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp8x23.cairo b/tests/nodes/sequence_construct_fp8x23.cairo new file mode 100644 index 000000000..9a024885d --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_fp8x23/input_0.cairo b/tests/nodes/sequence_construct_fp8x23/input_0.cairo new file mode 100644 index 000000000..37fb75902 --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23/input_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_fp8x23/output_0.cairo b/tests/nodes/sequence_construct_fp8x23/output_0.cairo new file mode 100644 index 000000000..8bae335fe --- /dev/null +++ b/tests/nodes/sequence_construct_fp8x23/output_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i32.cairo b/tests/nodes/sequence_construct_i32.cairo new file mode 100644 index 000000000..8c4f6a19f --- /dev/null +++ b/tests/nodes/sequence_construct_i32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_i32/input_0.cairo b/tests/nodes/sequence_construct_i32/input_0.cairo new file mode 100644 index 000000000..872cd3195 --- /dev/null +++ b/tests/nodes/sequence_construct_i32/input_0.cairo @@ -0,0 +1,30 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + 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: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i32/output_0.cairo b/tests/nodes/sequence_construct_i32/output_0.cairo new file mode 100644 index 000000000..4f246f2d1 --- /dev/null +++ b/tests/nodes/sequence_construct_i32/output_0.cairo @@ -0,0 +1,30 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + 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: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i8.cairo b/tests/nodes/sequence_construct_i8.cairo new file mode 100644 index 000000000..0c0dda805 --- /dev/null +++ b/tests/nodes/sequence_construct_i8.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_i8/input_0.cairo b/tests/nodes/sequence_construct_i8/input_0.cairo new file mode 100644 index 000000000..b66c72889 --- /dev/null +++ b/tests/nodes/sequence_construct_i8/input_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_i8/output_0.cairo b/tests/nodes/sequence_construct_i8/output_0.cairo new file mode 100644 index 000000000..e048ee27a --- /dev/null +++ b/tests/nodes/sequence_construct_i8/output_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_u32.cairo b/tests/nodes/sequence_construct_u32.cairo new file mode 100644 index 000000000..9301350d7 --- /dev/null +++ b/tests/nodes/sequence_construct_u32.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_construct_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_construct(input_0); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_construct_u32/input_0.cairo b/tests/nodes/sequence_construct_u32/input_0.cairo new file mode 100644 index 000000000..6fa9b512b --- /dev/null +++ b/tests/nodes/sequence_construct_u32/input_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_construct_u32/output_0.cairo b/tests/nodes/sequence_construct_u32/output_0.cairo new file mode 100644 index 000000000..78e4ce013 --- /dev/null +++ b/tests/nodes/sequence_construct_u32/output_0.cairo @@ -0,0 +1,90 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From 8a1671a14e8e3d733ae1e4e78352cc17ba660d25 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 19:56:10 +0100 Subject: [PATCH 068/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.sequence_construct.md | 35 ++++++++++++++++++ src/operators/tensor/core.cairo | 37 +++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_construct.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..a01af8f4e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_construct](framework/operators/tensor/tensor.sequence\_construct.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 ebc50ad77..9889027a8 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceConstruct](operators/tensor/tensor.sequence\_construct.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..01ba367bd 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_construct`](tensor.sequence\_construct.md) | Constructs a tensor sequence containing the input tensors. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_construct.md b/docs/framework/operators/tensor/tensor.sequence_construct.md new file mode 100644 index 000000000..fea30780d --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_construct.md @@ -0,0 +1,35 @@ +## tensor.sequence_construct + +```rust + fn sequence_construct(tensors: Array>) -> Array>; +``` + +Constructs a tensor sequence containing the input tensors. + +## Args + +* `tensors`(`Array>`) - The array of input tensors. + +## Panics + +* Panics if input tensor array is empty. + +## Returns + +A tensor sequence `Array>` containing the input tensors. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn sequence_construct_example() -> Array> { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + return result; +} +>>> [[0, 1, 2, 3], [4, 5, 6, 7]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 04b6d5db1..feddd2267 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,42 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.sequence_construct + /// + /// ```rust + /// fn sequence_construct(tensors: Array>) -> Array>; + /// ``` + /// + /// Constructs a tensor sequence containing the input tensors. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The array of input tensors. + /// + /// ## Panics + /// + /// * Panics if input tensor array is empty. + /// + /// ## Returns + /// + /// A tensor sequence `Array>` containing the input tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn sequence_construct_example() -> Array> { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [4, 5, 6, 7]] + /// ``` + /// fn sequence_construct(tensors: Array>) -> Array>; } From 90ebd0b49df56a75b8e04ea37cf6056a5dd04d71 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 15 Nov 2023 23:09:16 +0100 Subject: [PATCH 069/160] Implement operator --- src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/sequence_at.cairo | 37 +++++++++++++++++++ 13 files changed, 79 insertions(+) create mode 100644 src/operators/tensor/math/sequence_at.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..47414a718 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,6 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..efe03fe0c 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..31ccb2fd0 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..4d4940229 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 f764b1920..8994ba199 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 6cded29b3..2e6a07d5c 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 fdcdac1eb..be3f4eba0 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,10 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..c47629cd1 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 8017ab300..e605675a6 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 4f2731b80..b8a082bae 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,10 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// 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 2f3c3a2ef..e675eed0f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, index) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..99b6666d4 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod sequence_at; \ No newline at end of file diff --git a/src/operators/tensor/math/sequence_at.cairo b/src/operators/tensor/math/sequence_at.cairo new file mode 100644 index 000000000..18ad2c8f7 --- /dev/null +++ b/src/operators/tensor/math/sequence_at.cairo @@ -0,0 +1,37 @@ +use array::{ArrayTrait, SpanTrait}; +use option::OptionTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; +use orion::numbers::signed_integer::i32::i32; + +/// Cf: TensorTrait::sequence_at docstring +fn sequence_at< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + sequence: Array>, index: Tensor +) -> Tensor { + + assert(index.shape.len() == 1 && *index.shape.at(0) == 1, 'Index must be a scalar'); + + let index_value_i32: i32 = *index.data.at(0); + + let is_negative: bool = index_value_i32.sign; + let index_value = index_value_i32.mag; + + assert((is_negative == false && index_value < sequence.len() - 1) || (is_negative == true && index_value < sequence.len()), 'Index out of bounds'); + + if is_negative == false { + let output_tensor = *sequence.at(index_value); + return output_tensor; + } else { + let reverted_index_value = sequence.len() - index_value; + let output_tensor = *sequence.at(reverted_index_value); + return output_tensor; + } +} \ No newline at end of file From 0bb3c460628abaa426110d0073584b52e2894c00 Mon Sep 17 00:00:00 2001 From: Dincer Guner Date: Thu, 16 Nov 2023 02:41:44 +0300 Subject: [PATCH 070/160] implement reduce_min --- Scarb.toml | 1 + docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.reduce_min.md | 42 +++ nodegen/node/reduce_min.py | 288 ++++++++++++++++++ src/operators/tensor/core.cairo | 45 +++ src/operators/tensor/helpers.cairo | 24 ++ .../tensor/implementations/tensor_bool.cairo | 9 + .../implementations/tensor_fp16x16.cairo | 9 + .../implementations/tensor_fp16x16wide.cairo | 9 + .../implementations/tensor_fp32x32.cairo | 9 + .../implementations/tensor_fp64x64.cairo | 9 + .../implementations/tensor_fp8x23.cairo | 9 + .../implementations/tensor_fp8x23wide.cairo | 9 + .../tensor/implementations/tensor_i32.cairo | 9 + .../tensor/implementations/tensor_i8.cairo | 9 + .../tensor/implementations/tensor_u32.cairo | 9 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/reduce_min.cairo | 189 ++++++++++++ tests/nodes.cairo | 20 ++ tests/nodes/reduce_min_fp16x16_1D.cairo | 20 ++ .../nodes/reduce_min_fp16x16_1D/input_0.cairo | 15 + .../reduce_min_fp16x16_1D/output_0.cairo | 13 + .../nodes/reduce_min_fp16x16_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_min_fp16x16_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_min_fp16x16_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_min_fp8x23_1D.cairo | 20 ++ .../nodes/reduce_min_fp8x23_1D/input_0.cairo | 15 + .../nodes/reduce_min_fp8x23_1D/output_0.cairo | 13 + tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo | 20 ++ .../reduce_min_fp8x23_2D_axis_1/input_0.cairo | 17 ++ .../output_0.cairo | 15 + .../nodes/reduce_min_fp8x23_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../nodes/reduce_min_fp8x23_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 12 + tests/nodes/reduce_min_i32_1D.cairo | 20 ++ tests/nodes/reduce_min_i32_1D/input_0.cairo | 15 + tests/nodes/reduce_min_i32_1D/output_0.cairo | 13 + tests/nodes/reduce_min_i32_2D_axis_1.cairo | 20 ++ .../reduce_min_i32_2D_axis_1/input_0.cairo | 17 ++ .../reduce_min_i32_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_min_i32_2D_default.cairo | 20 ++ .../reduce_min_i32_2D_default/input_0.cairo | 17 ++ .../reduce_min_i32_2D_default/output_0.cairo | 14 + tests/nodes/reduce_min_i32_2D_keepdims.cairo | 20 ++ .../reduce_min_i32_2D_keepdims/input_0.cairo | 17 ++ .../reduce_min_i32_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_min_i8_1D.cairo | 20 ++ tests/nodes/reduce_min_i8_1D/input_0.cairo | 15 + tests/nodes/reduce_min_i8_1D/output_0.cairo | 13 + tests/nodes/reduce_min_i8_2D_axis_1.cairo | 20 ++ .../reduce_min_i8_2D_axis_1/input_0.cairo | 17 ++ .../reduce_min_i8_2D_axis_1/output_0.cairo | 15 + tests/nodes/reduce_min_i8_2D_default.cairo | 20 ++ .../reduce_min_i8_2D_default/input_0.cairo | 17 ++ .../reduce_min_i8_2D_default/output_0.cairo | 14 + tests/nodes/reduce_min_i8_2D_keepdims.cairo | 20 ++ .../reduce_min_i8_2D_keepdims/input_0.cairo | 17 ++ .../reduce_min_i8_2D_keepdims/output_0.cairo | 12 + tests/nodes/reduce_min_u32_1D.cairo | 20 ++ tests/nodes/reduce_min_u32_1D/input_0.cairo | 14 + tests/nodes/reduce_min_u32_1D/output_0.cairo | 12 + tests/nodes/reduce_min_u32_2D_axis_1.cairo | 20 ++ .../reduce_min_u32_2D_axis_1/input_0.cairo | 16 + .../reduce_min_u32_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_min_u32_2D_default.cairo | 20 ++ .../reduce_min_u32_2D_default/input_0.cairo | 16 + .../reduce_min_u32_2D_default/output_0.cairo | 13 + tests/nodes/reduce_min_u32_2D_keepdims.cairo | 20 ++ .../reduce_min_u32_2D_keepdims/input_0.cairo | 16 + .../reduce_min_u32_2D_keepdims/output_0.cairo | 11 + 80 files changed, 1694 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.reduce_min.md create mode 100644 nodegen/node/reduce_min.py create mode 100644 src/operators/tensor/math/reduce_min.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_1D.cairo create mode 100644 tests/nodes/reduce_min_i32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_1D.cairo create mode 100644 tests/nodes/reduce_min_i8_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_1D.cairo create mode 100644 tests/nodes/reduce_min_u32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo diff --git a/Scarb.toml b/Scarb.toml index b05876e7b..bcbb9f9c1 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,6 +6,7 @@ homepage = "https://github.com/gizatechxyz/orion" [dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } +alexandria_sorting = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } cubit = { git = "https://github.com/influenceth/cubit.git", rev = "b459053" } [scripts] diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..b45341d37 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.reduce\_min](framework/operators/tensor/tensor.reduce\_min.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..5da2c1e51 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.reduce_min.md b/docs/framework/operators/tensor/tensor.reduce_min.md new file mode 100644 index 000000000..611324be3 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_min.md @@ -0,0 +1,42 @@ +## tensor.reduce_min + +```rust + fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; +``` + +Computes the min of the input tensor's elements along the provided axes. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. +* `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. +* `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axes reduced by minimum of its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_min_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_mean` function as follows. + return tensor.reduce_min(axes: array![1].span(), + keepdims: Option::None(()), + noop_with_empty_axes: Option::None(())); +} +>>> [[0,1],[4,5]] +``` diff --git a/nodegen/node/reduce_min.py b/nodegen/node/reduce_min.py new file mode 100644 index 000000000..b9d27eeaa --- /dev/null +++ b/nodegen/node/reduce_min.py @@ -0,0 +1,288 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Reduce_min(RunAll): + @staticmethod + def reduce_min_u32(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.uint32) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_min_u32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_i32(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int32) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_min_i32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_i8(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int8) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_min_i8_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_fp8x23(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_min_fp8x23_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_min_fp8x23_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_min_fp8x23_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_min_fp8x23_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_min_1D() + reduce_min_2D() + + @staticmethod + def reduce_min_fp16x16(): + def reduce_min_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_min_fp16x16_1D" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def reduce_min_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_min_fp16x16_2D_default" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::None(()), Option::None(()))", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=None, keepdims=False) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_min_fp16x16_2D_keepdims" + make_test( + [x], y, "input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(()))", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.minimum.reduce(x, axis=(1), keepdims=True) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_min_fp16x16_2D_axis_1" + make_test( + [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) + + default() + keepdims() + axis_1() + + reduce_min_1D() + reduce_min_2D() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..e9ae9d9f4 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,50 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.reduce_min + /// + /// ```rust + /// fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the min of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by minimum of its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_min_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_min(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[0,1],[4,5]] + /// ``` + /// + fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 0aad721d7..6b65eb736 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -317,3 +317,27 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. +fn get_all_axes(shape: Span) -> Span{ + let mut ret: Array = ArrayTrait::new(); + let mut i: usize = 0; + let stop_i = shape.len() - 1; + loop { + ret.append(i); + if i == stop_i { + break (); + } + i += 1; + }; + ret.span() +} \ No newline at end of file diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..595389e76 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,15 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..9b014178c 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,15 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..4bf9a335a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,15 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 f764b1920..62abbaa81 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,15 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 6cded29b3..42fc24636 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,15 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 fdcdac1eb..6bd8aadab 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,15 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..0af5e926b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,15 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 8017ab300..5ea4d37cd 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,15 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 4f2731b80..c6bdb6ff4 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,15 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// 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 2f3c3a2ef..a0af0c021 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,15 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor { + math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..9fd72ba9e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod reduce_min; \ No newline at end of file diff --git a/src/operators/tensor/math/reduce_min.cairo b/src/operators/tensor/math/reduce_min.cairo new file mode 100644 index 000000000..7299d9384 --- /dev/null +++ b/src/operators/tensor/math/reduce_min.cairo @@ -0,0 +1,189 @@ +use core::option::OptionTrait; +use core::traits::TryInto; +use core::traits::Into; + +use array::ArrayTrait; +use array::SpanTrait; + +use orion::numbers::signed_integer::integer_trait::IntegerTrait; +use orion::numbers::fixed_point::core::FixedTrait; +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; + +use alexandria_sorting::bubble_sort; +use alexandria_data_structures::array_ext::{SpanTraitExt}; + + +/// Cf: TensorTrait::reduce_min docstring +fn reduce_min< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option +) -> Tensor { + let noop_with_empty_axes = match noop_with_empty_axes { + Option::Some(noop_with_empty_axes) => noop_with_empty_axes, + Option::None(_) => { + false + }, + }; + let axes = match axes { + Option::Some(axes) => { + if(axes.len() == 0) { + get_all_axes(*self.shape) + } + else { + assert(axes.len() == axes.unique().len(), 'duplicated axis.'); + let mut axes_arr = ArrayTrait::new(); + let mut copy_axes = axes; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + axes_arr.append(*axis); + }, + Option::None(_) => { + break; + } + }; + }; + let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); + sorted_axes + } + }, + Option::None(_) => { + if (noop_with_empty_axes == true) { + return *self; + } + get_all_axes(*self.shape) + }, + }; + let keepdims = match keepdims { + Option::Some(keepdims) => keepdims, + Option::None(_) => { + true + }, + }; + + let mut axis_c = 0; + let mut copy_axes = axes; + let mut shape = *self.shape; + let mut data = *self.data; + loop { + match copy_axes.pop_front() { + Option::Some(axis) => { + if (shape.len() == 1) { + let current_min = accumulate_min::(data, shape, shape, 0); + shape = array![].span(); + data = array![current_min].span(); + break(); + } + let mut temp_data = ArrayTrait::new(); + let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let data_len = len_from_shape(temp_shape); + let mut index: usize = 0; + loop { + let indices = unravel_index(index, temp_shape); + let current_min = accumulate_min::(data, shape, indices, *axis-axis_c); + + temp_data.append(current_min); + + index += 1; + if index == data_len { + break (); + }; + }; + shape = temp_shape; + data = temp_data.span(); + axis_c += 1; + }, + Option::None(_) => { + break; + } + }; + }; + + let mut axes_copy = axes; + if keepdims == true { + shape = *self.shape; + loop { + match axes_copy.pop_front() { + Option::Some(axis) => { + shape = reduce_output_shape(shape, *axis, true); + }, + Option::None(_) => { + break; + } + }; + }; + return TensorTrait::::new(shape, data); + } else { + return TensorTrait::::new(shape, data); + } +} + +/// Helper function that accumulates the minimum of elements along a specific axis. +/// +/// # Arguments +/// * `input_data` - The input's data. +/// * `input_shape` - The input's shape. +/// * `output_indices` - A span of output indices. +/// * `axis` - The axis along which to accumulate the minimum. +/// +/// # Panics +/// * Panics if gas limit is exceeded during execution. +/// +/// # Returns +/// * A value representing the accumulated minimum along the specified axis. +fn accumulate_min< + T, + MAG, + impl TNumber: NumberTrait, + impl TPartialOrd: PartialOrd, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut input_data: Span, input_shape: Span, output_indices: Span, axis: usize +) -> T { + let axis_len = *(input_shape)[axis]; + let mut min: T = NumberTrait::max_value(); + + let mut axis_index = 0; + + if (input_shape).len() > 1 { + loop { + if axis_index == axis_len { + break (); + } + + let input_indices = combine_indices(output_indices, axis_index, axis); + let input_index = ravel_index(input_shape, input_indices); + let ele = *(input_data)[input_index]; + if (ele < min) { + min = ele; + } + + axis_index += 1; + }; + } else { + loop { + match input_data.pop_front() { + Option::Some(item) => { + if (*item < min) { + min = *item; + } + }, + Option::None(_) => { break; } + }; + }; + } + return min; +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..9ca9f8af1 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,23 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_min_fp16x16_1D; +mod reduce_min_fp16x16_2D_default; +mod reduce_min_fp16x16_2D_keepdims; +mod reduce_min_fp16x16_2D_axis_1; +mod reduce_min_fp8x23_1D; +mod reduce_min_fp8x23_2D_default; +mod reduce_min_fp8x23_2D_keepdims; +mod reduce_min_fp8x23_2D_axis_1; +mod reduce_min_i32_1D; +mod reduce_min_i32_2D_default; +mod reduce_min_i32_2D_keepdims; +mod reduce_min_i32_2D_axis_1; +mod reduce_min_i8_1D; +mod reduce_min_i8_2D_default; +mod reduce_min_i8_2D_keepdims; +mod reduce_min_i8_2D_axis_1; +mod reduce_min_u32_1D; +mod reduce_min_u32_2D_default; +mod reduce_min_u32_2D_keepdims; +mod reduce_min_u32_2D_axis_1; diff --git a/tests/nodes/reduce_min_fp16x16_1D.cairo b/tests/nodes/reduce_min_fp16x16_1D.cairo new file mode 100644 index 000000000..2fe04eab0 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo new file mode 100644 index 000000000..4ce1ac478 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo new file mode 100644 index 000000000..b6702d88e --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo new file mode 100644 index 000000000..c2b02de4f --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..3a7987ad7 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default.cairo b/tests/nodes/reduce_min_fp16x16_2D_default.cairo new file mode 100644 index 000000000..e09a43e6b --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo new file mode 100644 index 000000000..e0814d34d --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo new file mode 100644 index 000000000..f5c70c06b --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp16x16_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..2f6936ccb --- /dev/null +++ b/tests/nodes/reduce_min_fp16x16_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_1D.cairo b/tests/nodes/reduce_min_fp8x23_1D.cairo new file mode 100644 index 000000000..362f99aca --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo new file mode 100644 index 000000000..e0b0864ea --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo new file mode 100644 index 000000000..cc23ecd7d --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..5379c89de --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default.cairo b/tests/nodes/reduce_min_fp8x23_2D_default.cairo new file mode 100644 index 000000000..f4440ca3b --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo new file mode 100644 index 000000000..4bbff30a2 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo new file mode 100644 index 000000000..0164304a4 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_fp8x23_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..a1e9688f6 --- /dev/null +++ b/tests/nodes/reduce_min_fp8x23_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_1D.cairo b/tests/nodes/reduce_min_i32_1D.cairo new file mode 100644 index 000000000..b4ef5b675 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_1D/input_0.cairo b/tests/nodes/reduce_min_i32_1D/input_0.cairo new file mode 100644 index 000000000..0f01c1e62 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D/input_0.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_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_1D/output_0.cairo b/tests/nodes/reduce_min_i32_1D/output_0.cairo new file mode 100644 index 000000000..cc24fe978 --- /dev/null +++ b/tests/nodes/reduce_min_i32_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1.cairo b/tests/nodes/reduce_min_i32_2D_axis_1.cairo new file mode 100644 index 000000000..18aac7c13 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_i32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..33f9f46e3 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_axis_1/output_0.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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_default.cairo b/tests/nodes/reduce_min_i32_2D_default.cairo new file mode 100644 index 000000000..5f6673bb4 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_default/input_0.cairo b/tests/nodes/reduce_min_i32_2D_default/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_default/output_0.cairo b/tests/nodes/reduce_min_i32_2D_default/output_0.cairo new file mode 100644 index 000000000..e8178c3ce --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims.cairo b/tests/nodes/reduce_min_i32_2D_keepdims.cairo new file mode 100644 index 000000000..680c38f7b --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..905606cf2 --- /dev/null +++ b/tests/nodes/reduce_min_i32_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_1D.cairo b/tests/nodes/reduce_min_i8_1D.cairo new file mode 100644 index 000000000..a10609e44 --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_1D/input_0.cairo b/tests/nodes/reduce_min_i8_1D/input_0.cairo new file mode 100644 index 000000000..1d76655fb --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_1D/output_0.cairo b/tests/nodes/reduce_min_i8_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_min_i8_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1.cairo b/tests/nodes/reduce_min_i8_2D_axis_1.cairo new file mode 100644 index 000000000..afc054a84 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..9689a7aa4 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_axis_1/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_default.cairo b/tests/nodes/reduce_min_i8_2D_default.cairo new file mode 100644 index 000000000..ef9103279 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_default/input_0.cairo b/tests/nodes/reduce_min_i8_2D_default/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_default/output_0.cairo b/tests/nodes/reduce_min_i8_2D_default/output_0.cairo new file mode 100644 index 000000000..4bbff30a2 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims.cairo b/tests/nodes/reduce_min_i8_2D_keepdims.cairo new file mode 100644 index 000000000..7e879c2cb --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_i8_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..a1e9688f6 --- /dev/null +++ b/tests/nodes/reduce_min_i8_2D_keepdims/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_1D.cairo b/tests/nodes/reduce_min_u32_1D.cairo new file mode 100644 index 000000000..4f5051e52 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_1D/input_0.cairo b/tests/nodes/reduce_min_u32_1D/input_0.cairo new file mode 100644 index 000000000..60317db10 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D/input_0.cairo @@ -0,0 +1,14 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_1D/output_0.cairo b/tests/nodes/reduce_min_u32_1D/output_0.cairo new file mode 100644 index 000000000..2374279b0 --- /dev/null +++ b/tests/nodes/reduce_min_u32_1D/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1.cairo b/tests/nodes/reduce_min_u32_2D_axis_1.cairo new file mode 100644 index 000000000..d3a6e895f --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..8e871bbfd --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +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(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_default.cairo b/tests/nodes/reduce_min_u32_2D_default.cairo new file mode 100644 index 000000000..40e69e302 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::None(()), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_default/input_0.cairo b/tests/nodes/reduce_min_u32_2D_default/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_default/output_0.cairo b/tests/nodes/reduce_min_u32_2D_default/output_0.cairo new file mode 100644 index 000000000..962f113cb --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_default/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims.cairo b/tests/nodes/reduce_min_u32_2D_keepdims.cairo new file mode 100644 index 000000000..f107c14f4 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_min_u32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_min(Option::None(()), Option::Some(false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..8b3006d47 --- /dev/null +++ b/tests/nodes/reduce_min_u32_2D_keepdims/output_0.cairo @@ -0,0 +1,11 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} From 833b86e0f9e3e2245a17657afb9b8186863daeab Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 09:59:58 +0200 Subject: [PATCH 071/160] add tensor_bool implementation --- src/operators/tensor/implementations/tensor_bool.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..eba4483f7 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. From 91721138dc1df5c65fede38418524c1aa13ddb7c Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 10:41:53 +0200 Subject: [PATCH 072/160] refactor loops --- .../tensor/ml/array_feature_extractor.cairo | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 4aee41f7e..5da16fc77 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -16,9 +16,8 @@ fn array_feature_extractor< >( self: Tensor, indices: Tensor ) -> Tensor { - assert(indices.shape.len() == 1, 'Indices must be a 1D tensor'); - + if self.shape.len() == 1 { return process_1D_tensor(self, indices); } @@ -41,22 +40,21 @@ fn process_1D_tensor< >( self: Tensor, indices: Tensor ) -> Tensor { - let mut output_data = ArrayTrait::::new(); let mut indices_counter: usize = 0; - loop { - if indices_counter > indices.data.len() - 1 { - break; - } - - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < *self.shape.at(0), 'Indices out of range'); - let mut current_data_value = *self.data.at(current_indices_value); - output_data.append(current_data_value); - - indices_counter += 1; + let mut indices_values: Span = indices.data; + let self_len = *self.shape.at(0); + loop { + match indices_values.pop_front() { + Option::Some(current_indices_value) => { + assert(*current_indices_value < self_len, 'Indices out of range'); + let mut current_data_value = *self.data.at(*current_indices_value); + output_data.append(current_data_value); + }, + Option::None(_) => { break; } + }; }; return TensorTrait::new(indices.shape, output_data.span()); @@ -73,22 +71,25 @@ fn calculate_output_shape< >( input_shape: Span, indices: Tensor ) -> (Array, usize) { - let mut total_elements: usize = 1; let mut output_shape: Array = ArrayTrait::new(); + let mut input_shape_copy = input_shape; let mut input_shape_counter: usize = 0; + let breaker = input_shape.len() - 2; loop { - if input_shape_counter > input_shape.len() - 2 { - break; - } - - let mut current_shape_value = *input_shape.at(input_shape_counter); - output_shape.append(current_shape_value); - - total_elements = total_elements * current_shape_value; - - input_shape_counter += 1; + match input_shape_copy.pop_front() { + Option::Some(current_shape_value) => { + if input_shape_counter > breaker { + break; + } + output_shape.append(*current_shape_value); + total_elements = total_elements * *current_shape_value; + + input_shape_counter += 1; + }, + Option::None(_) => { break; } + }; }; output_shape.append(indices.data.len()); @@ -107,7 +108,6 @@ fn calculate_output_data< >( self: Tensor, indices: Tensor, total_elements: usize ) -> Array { - let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); let mut output_data = ArrayTrait::::new(); @@ -115,32 +115,31 @@ fn calculate_output_data< let strides: Span = TensorTrait::stride(@self); let mut element_counter: usize = 0; + let mut stride_l2 = *strides.at(strides.len() - 2); + let mut stride_l1 = *strides.at(strides.len() - 1); loop { if element_counter > total_elements - 1 { break; } let mut base_index = if strides.len() > 1 { - element_counter * (*strides.at(strides.len() - 2)) + element_counter * stride_l2 } else { - 0 + 0 }; - let mut indices_counter: usize = 0; + let mut indices_values = indices.data; loop { - if indices_counter > indices.data.len() - 1 { - break; - } - - let mut current_indices_value = *indices.data.at(indices_counter); - assert(current_indices_value < last_tensor_axis, 'Indices out of range'); - - let mut flat_index = base_index + current_indices_value * (*strides.at(strides.len() - 1)); - - let mut current_data_value = *self.data.at(flat_index); - output_data.append(current_data_value); - - indices_counter += 1; + match indices_values.pop_front() { + Option::Some(current_indices_value) => { + assert(*current_indices_value < last_tensor_axis, 'Indices out of range'); + let mut flat_index = base_index + *current_indices_value * (stride_l1); + + let mut current_data_value = *self.data.at(flat_index); + output_data.append(current_data_value); + }, + Option::None(_) => { break; } + }; }; element_counter += 1; From 53bb27dc015eb80dd10b69567d8160dcad7314ad Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 11:02:08 +0200 Subject: [PATCH 073/160] implement feature to tensor bool --- .../tensor/implementations/tensor_bool.cairo | 6 +++++- .../tensor/ml/array_feature_extractor.cairo | 12 ++---------- tests/nodes.cairo | 1 - 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index eba4483f7..5fa0ca992 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -8,7 +8,7 @@ use orion::operators::tensor::core::{ constant_of_shape, new_tensor, stride, Tensor, TensorTrait, ravel_index, unravel_index, reshape, at_tensor, }; -use orion::operators::tensor::{math, linalg, quantization, core}; +use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; use orion::operators::tensor::implementations::tensor_u32::U32Tensor; @@ -316,6 +316,10 @@ impl BoolTensor of TensorTrait { fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } + + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + ml::array_feature_extractor::array_feature_extractor(*self, indices) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 5da16fc77..25e0aac16 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -8,9 +8,7 @@ use orion::numbers::NumberTrait; /// Cf: TensorTrait::array_feature_extractor docstring fn array_feature_extractor< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -22,9 +20,9 @@ fn array_feature_extractor< return process_1D_tensor(self, indices); } - let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); + let (output_shape, total_elements) = calculate_output_shape::(self.shape, indices); - let output_data = calculate_output_data::(self, indices, total_elements); + let output_data = calculate_output_data::(self, indices, total_elements); return TensorTrait::new(output_shape.span(), output_data.span()); } @@ -32,9 +30,7 @@ fn array_feature_extractor< fn process_1D_tensor< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -63,9 +59,7 @@ fn process_1D_tensor< fn calculate_output_shape< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( @@ -100,9 +94,7 @@ fn calculate_output_shape< fn calculate_output_data< T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TCopy: Copy, impl TDrop: Drop >( diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 0f60c10aa..147a88d67 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -537,7 +537,6 @@ mod array_feature_extractor_2D_fp16x16; mod array_feature_extractor_3D_i32; mod array_feature_extractor_3D_fp8x23; mod array_feature_extractor_3D_fp16x16; -mod scatter_u32_add; mod binarizer_fp16x16; mod binarizer_fp8x23; mod tril_fp16x16; From fac7886acf855ea89dd86b40be38505de0483563 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 11:23:15 +0200 Subject: [PATCH 074/160] Update tensor.cairo --- src/operators/tensor.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operators/tensor.cairo b/src/operators/tensor.cairo index deaa81e7c..b8fc7a91f 100644 --- a/src/operators/tensor.cairo +++ b/src/operators/tensor.cairo @@ -37,6 +37,6 @@ use orion::operators::tensor::implementations::tensor_u32::{ }; use orion::operators::tensor::implementations::tensor_bool::{ - BoolTensor, BoolTensorAdd, BoolTensorSub, BoolTensorMul, BoolTensorDiv, BoolTensorPartialEq + BoolTensor, BoolTensorPartialEq }; From 4719dd826159663eb853d06d388d3ccdb44bf6fd Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 12:23:13 +0200 Subject: [PATCH 075/160] Update core.cairo --- src/operators/tensor/core.cairo | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 1701feee0..9b1ffbf5d 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3822,6 +3822,43 @@ trait TensorTrait { /// ``` /// fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; + /// ## tensor.sequence_construct + /// + /// ```rust + /// fn sequence_construct(tensors: Array>) -> Array>; + /// ``` + /// + /// Constructs a tensor sequence containing the input tensors. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The array of input tensors. + /// + /// ## Panics + /// + /// * Panics if input tensor array is empty. + /// + /// ## Returns + /// + /// A tensor sequence `Array>` containing the input tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn sequence_construct_example() -> Array> { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [4, 5, 6, 7]] + /// ``` + /// + fn sequence_construct(tensors: Array>) -> Array>; } /// Cf: TensorTrait::new docstring From 5b9204bdb16e3f769fc4402d92821bb23df3b225 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Thu, 16 Nov 2023 11:36:16 +0100 Subject: [PATCH 076/160] Add tests and fix bug --- nodegen/node/sequence_at.py | 188 ++++++++++++++++++ src/operators/tensor/math/sequence_at.cairo | 11 +- tests/nodes.cairo | 10 + .../nodes/sequence_at_fp16x16_negative.cairo | 24 +++ .../input_0.cairo | 65 ++++++ .../input_1.cairo | 12 ++ .../output_0.cairo | 16 ++ .../nodes/sequence_at_fp16x16_positive.cairo | 24 +++ .../input_0.cairo | 65 ++++++ .../input_1.cairo | 12 ++ .../output_0.cairo | 16 ++ tests/nodes/sequence_at_fp8x23_negative.cairo | 24 +++ .../sequence_at_fp8x23_negative/input_0.cairo | 70 +++++++ .../sequence_at_fp8x23_negative/input_1.cairo | 12 ++ .../output_0.cairo | 17 ++ tests/nodes/sequence_at_fp8x23_positive.cairo | 24 +++ .../sequence_at_fp8x23_positive/input_0.cairo | 80 ++++++++ .../sequence_at_fp8x23_positive/input_1.cairo | 12 ++ .../output_0.cairo | 19 ++ tests/nodes/sequence_at_i32_negative.cairo | 22 ++ .../sequence_at_i32_negative/input_0.cairo | 65 ++++++ .../sequence_at_i32_negative/input_1.cairo | 12 ++ .../sequence_at_i32_negative/output_0.cairo | 16 ++ tests/nodes/sequence_at_i32_positive.cairo | 22 ++ .../sequence_at_i32_positive/input_0.cairo | 60 ++++++ .../sequence_at_i32_positive/input_1.cairo | 12 ++ .../sequence_at_i32_positive/output_0.cairo | 15 ++ tests/nodes/sequence_at_i8_negative.cairo | 24 +++ .../sequence_at_i8_negative/input_0.cairo | 70 +++++++ .../sequence_at_i8_negative/input_1.cairo | 12 ++ .../sequence_at_i8_negative/output_0.cairo | 17 ++ tests/nodes/sequence_at_i8_positive.cairo | 24 +++ .../sequence_at_i8_positive/input_0.cairo | 95 +++++++++ .../sequence_at_i8_positive/input_1.cairo | 12 ++ .../sequence_at_i8_positive/output_0.cairo | 22 ++ tests/nodes/sequence_at_u32_negative.cairo | 24 +++ .../sequence_at_u32_negative/input_0.cairo | 69 +++++++ .../sequence_at_u32_negative/input_1.cairo | 12 ++ .../sequence_at_u32_negative/output_0.cairo | 16 ++ tests/nodes/sequence_at_u32_positive.cairo | 24 +++ .../sequence_at_u32_positive/input_0.cairo | 64 ++++++ .../sequence_at_u32_positive/input_1.cairo | 12 ++ .../sequence_at_u32_positive/output_0.cairo | 15 ++ 43 files changed, 1430 insertions(+), 7 deletions(-) create mode 100644 nodegen/node/sequence_at.py create mode 100644 tests/nodes/sequence_at_fp16x16_negative.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_negative/input_0.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_negative/input_1.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_negative/output_0.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_positive.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_positive/input_0.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_positive/input_1.cairo create mode 100644 tests/nodes/sequence_at_fp16x16_positive/output_0.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_negative.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_negative/input_0.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_negative/input_1.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_negative/output_0.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_positive.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_positive/input_0.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_positive/input_1.cairo create mode 100644 tests/nodes/sequence_at_fp8x23_positive/output_0.cairo create mode 100644 tests/nodes/sequence_at_i32_negative.cairo create mode 100644 tests/nodes/sequence_at_i32_negative/input_0.cairo create mode 100644 tests/nodes/sequence_at_i32_negative/input_1.cairo create mode 100644 tests/nodes/sequence_at_i32_negative/output_0.cairo create mode 100644 tests/nodes/sequence_at_i32_positive.cairo create mode 100644 tests/nodes/sequence_at_i32_positive/input_0.cairo create mode 100644 tests/nodes/sequence_at_i32_positive/input_1.cairo create mode 100644 tests/nodes/sequence_at_i32_positive/output_0.cairo create mode 100644 tests/nodes/sequence_at_i8_negative.cairo create mode 100644 tests/nodes/sequence_at_i8_negative/input_0.cairo create mode 100644 tests/nodes/sequence_at_i8_negative/input_1.cairo create mode 100644 tests/nodes/sequence_at_i8_negative/output_0.cairo create mode 100644 tests/nodes/sequence_at_i8_positive.cairo create mode 100644 tests/nodes/sequence_at_i8_positive/input_0.cairo create mode 100644 tests/nodes/sequence_at_i8_positive/input_1.cairo create mode 100644 tests/nodes/sequence_at_i8_positive/output_0.cairo create mode 100644 tests/nodes/sequence_at_u32_negative.cairo create mode 100644 tests/nodes/sequence_at_u32_negative/input_0.cairo create mode 100644 tests/nodes/sequence_at_u32_negative/input_1.cairo create mode 100644 tests/nodes/sequence_at_u32_negative/output_0.cairo create mode 100644 tests/nodes/sequence_at_u32_positive.cairo create mode 100644 tests/nodes/sequence_at_u32_positive/input_0.cairo create mode 100644 tests/nodes/sequence_at_u32_positive/input_1.cairo create mode 100644 tests/nodes/sequence_at_u32_positive/output_0.cairo diff --git a/nodegen/node/sequence_at.py b/nodegen/node/sequence_at.py new file mode 100644 index 000000000..ed5c9ac07 --- /dev/null +++ b/nodegen/node/sequence_at.py @@ -0,0 +1,188 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +scalar = lambda x: Tensor(Dtype.I32, (), np.array([x]).astype(np.int32).flatten()) + + +class Sequence_at(RunAll): + + @staticmethod + def sequence_at_u32(): + def positive_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(2) + + name = "sequence_at_u32_positive" + make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + + def negative_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(-2) + + name = "sequence_at_u32_negative" + make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + + positive_index() + negative_index() + + + @staticmethod + def sequence_at_i32(): + def positive_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(2) + + name = "sequence_at_i32_positive" + make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + + def negative_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(-2) + + name = "sequence_at_i32_negative" + make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + + positive_index() + negative_index() + + + @staticmethod + def sequence_at_i8(): + def positive_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(2) + + name = "sequence_at_i8_positive" + make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + + def negative_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + index = scalar(-2) + + name = "sequence_at_i8_negative" + make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + + positive_index() + negative_index() + + + @staticmethod + def sequence_at_fp8x23(): + def positive_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + index = scalar(2) + + name = "sequence_at_fp8x23_positive" + make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + + def negative_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + index = scalar(-2) + + name = "sequence_at_fp8x23_negative" + make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + + positive_index() + negative_index() + + + @staticmethod + def sequence_at_fp16x16(): + def positive_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + index = scalar(2) + + name = "sequence_at_fp16x16_positive" + make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + + def negative_index(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + index = scalar(-2) + + name = "sequence_at_fp16x16_negative" + make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + + positive_index() + negative_index() diff --git a/src/operators/tensor/math/sequence_at.cairo b/src/operators/tensor/math/sequence_at.cairo index 18ad2c8f7..161312110 100644 --- a/src/operators/tensor/math/sequence_at.cairo +++ b/src/operators/tensor/math/sequence_at.cairo @@ -17,21 +17,18 @@ fn sequence_at< sequence: Array>, index: Tensor ) -> Tensor { - assert(index.shape.len() == 1 && *index.shape.at(0) == 1, 'Index must be a scalar'); + assert(index.shape.len() == 0 && index.data.len() == 1, 'Index must be a scalar'); let index_value_i32: i32 = *index.data.at(0); - let is_negative: bool = index_value_i32.sign; let index_value = index_value_i32.mag; - assert((is_negative == false && index_value < sequence.len() - 1) || (is_negative == true && index_value < sequence.len()), 'Index out of bounds'); + assert((is_negative == false && index_value <= sequence.len() - 1) || (is_negative == true && index_value <= sequence.len()), 'Index out of bounds'); if is_negative == false { - let output_tensor = *sequence.at(index_value); - return output_tensor; + return *sequence.at(index_value); } else { let reverted_index_value = sequence.len() - index_value; - let output_tensor = *sequence.at(reverted_index_value); - return output_tensor; + return *sequence.at(reverted_index_value); } } \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..99f3fb348 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,13 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod sequence_at_u32_positive; +mod sequence_at_u32_negative; +mod sequence_at_fp16x16_positive; +mod sequence_at_fp16x16_negative; +mod sequence_at_fp8x23_positive; +mod sequence_at_fp8x23_negative; +mod sequence_at_i32_positive; +mod sequence_at_i32_negative; +mod sequence_at_i8_positive; +mod sequence_at_i8_negative; diff --git a/tests/nodes/sequence_at_fp16x16_negative.cairo b/tests/nodes/sequence_at_fp16x16_negative.cairo new file mode 100644 index 000000000..8defc6845 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_fp16x16_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo b/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo new file mode 100644 index 000000000..1f24f1522 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_fp16x16_negative/input_1.cairo b/tests/nodes/sequence_at_fp16x16_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo b/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo new file mode 100644 index 000000000..2e1afeb10 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp16x16_positive.cairo b/tests/nodes/sequence_at_fp16x16_positive.cairo new file mode 100644 index 000000000..a2f991b86 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_fp16x16_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo b/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo new file mode 100644 index 000000000..2f696be97 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_fp16x16_positive/input_1.cairo b/tests/nodes/sequence_at_fp16x16_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo b/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo new file mode 100644 index 000000000..29bb4ade6 --- /dev/null +++ b/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp8x23_negative.cairo b/tests/nodes/sequence_at_fp8x23_negative.cairo new file mode 100644 index 000000000..23d8badd5 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_fp8x23_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo b/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo new file mode 100644 index 000000000..927150f50 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_fp8x23_negative/input_1.cairo b/tests/nodes/sequence_at_fp8x23_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo b/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo new file mode 100644 index 000000000..ad35ea60d --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp8x23_positive.cairo b/tests/nodes/sequence_at_fp8x23_positive.cairo new file mode 100644 index 000000000..d671067a7 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_fp8x23_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo b/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo new file mode 100644 index 000000000..cf2a22092 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_fp8x23_positive/input_1.cairo b/tests/nodes/sequence_at_fp8x23_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo b/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo new file mode 100644 index 000000000..8bbaa2a70 --- /dev/null +++ b/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i32_negative.cairo b/tests/nodes/sequence_at_i32_negative.cairo new file mode 100644 index 000000000..acc116127 --- /dev/null +++ b/tests/nodes/sequence_at_i32_negative.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_i32_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_i32_negative/input_0.cairo b/tests/nodes/sequence_at_i32_negative/input_0.cairo new file mode 100644 index 000000000..f43b21e0b --- /dev/null +++ b/tests/nodes/sequence_at_i32_negative/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_i32_negative/input_1.cairo b/tests/nodes/sequence_at_i32_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_at_i32_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i32_negative/output_0.cairo b/tests/nodes/sequence_at_i32_negative/output_0.cairo new file mode 100644 index 000000000..f5cea646b --- /dev/null +++ b/tests/nodes/sequence_at_i32_negative/output_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i32_positive.cairo b/tests/nodes/sequence_at_i32_positive.cairo new file mode 100644 index 000000000..47bed6a34 --- /dev/null +++ b/tests/nodes/sequence_at_i32_positive.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_i32_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_i32_positive/input_0.cairo b/tests/nodes/sequence_at_i32_positive/input_0.cairo new file mode 100644 index 000000000..eb6201988 --- /dev/null +++ b/tests/nodes/sequence_at_i32_positive/input_0.cairo @@ -0,0 +1,60 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_i32_positive/input_1.cairo b/tests/nodes/sequence_at_i32_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_at_i32_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i32_positive/output_0.cairo b/tests/nodes/sequence_at_i32_positive/output_0.cairo new file mode 100644 index 000000000..76cd6f356 --- /dev/null +++ b/tests/nodes/sequence_at_i32_positive/output_0.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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i8_negative.cairo b/tests/nodes/sequence_at_i8_negative.cairo new file mode 100644 index 000000000..305322425 --- /dev/null +++ b/tests/nodes/sequence_at_i8_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_i8_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_i8_negative/input_0.cairo b/tests/nodes/sequence_at_i8_negative/input_0.cairo new file mode 100644 index 000000000..fa86cbabd --- /dev/null +++ b/tests/nodes/sequence_at_i8_negative/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_i8_negative/input_1.cairo b/tests/nodes/sequence_at_i8_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_at_i8_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i8_negative/output_0.cairo b/tests/nodes/sequence_at_i8_negative/output_0.cairo new file mode 100644 index 000000000..37306188b --- /dev/null +++ b/tests/nodes/sequence_at_i8_negative/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i8_positive.cairo b/tests/nodes/sequence_at_i8_positive.cairo new file mode 100644 index 000000000..74f6b4323 --- /dev/null +++ b/tests/nodes/sequence_at_i8_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_i8_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_i8_positive/input_0.cairo b/tests/nodes/sequence_at_i8_positive/input_0.cairo new file mode 100644 index 000000000..f9c7f2ed6 --- /dev/null +++ b/tests/nodes/sequence_at_i8_positive/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_i8_positive/input_1.cairo b/tests/nodes/sequence_at_i8_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_at_i8_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_i8_positive/output_0.cairo b/tests/nodes/sequence_at_i8_positive/output_0.cairo new file mode 100644 index 000000000..f479a7998 --- /dev/null +++ b/tests/nodes/sequence_at_i8_positive/output_0.cairo @@ -0,0 +1,22 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_u32_negative.cairo b/tests/nodes/sequence_at_u32_negative.cairo new file mode 100644 index 000000000..712de30e1 --- /dev/null +++ b/tests/nodes/sequence_at_u32_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_u32_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_u32_negative/input_0.cairo b/tests/nodes/sequence_at_u32_negative/input_0.cairo new file mode 100644 index 000000000..e68d3cdb3 --- /dev/null +++ b/tests/nodes/sequence_at_u32_negative/input_0.cairo @@ -0,0 +1,69 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(4); + data.append(3); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(2); + data.append(4); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(3); + data.append(0); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(0); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_u32_negative/input_1.cairo b/tests/nodes/sequence_at_u32_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_at_u32_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_u32_negative/output_0.cairo b/tests/nodes/sequence_at_u32_negative/output_0.cairo new file mode 100644 index 000000000..b3180e186 --- /dev/null +++ b/tests/nodes/sequence_at_u32_negative/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(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_u32_positive.cairo b/tests/nodes/sequence_at_u32_positive.cairo new file mode 100644 index 000000000..f721dbf43 --- /dev/null +++ b/tests/nodes/sequence_at_u32_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_at_u32_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_at(input_0, input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/sequence_at_u32_positive/input_0.cairo b/tests/nodes/sequence_at_u32_positive/input_0.cairo new file mode 100644 index 000000000..9a80cc816 --- /dev/null +++ b/tests/nodes/sequence_at_u32_positive/input_0.cairo @@ -0,0 +1,64 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(3); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(0); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(5); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(3); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(2); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_at_u32_positive/input_1.cairo b/tests/nodes/sequence_at_u32_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_at_u32_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_at_u32_positive/output_0.cairo b/tests/nodes/sequence_at_u32_positive/output_0.cairo new file mode 100644 index 000000000..98a00dc92 --- /dev/null +++ b/tests/nodes/sequence_at_u32_positive/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(5); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} From 0299f2be4c02394c72a5c8a472ccc184912fabf1 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 16 Nov 2023 12:48:40 +0200 Subject: [PATCH 077/160] format code --- docs/framework/compatibility.md | 2 +- src/numbers.cairo | 24 +++-- src/operators.cairo | 2 +- src/operators/tensor/core.cairo | 14 ++- src/operators/tensor/helpers.cairo | 4 +- .../tensor/implementations/tensor_bool.cairo | 9 +- .../implementations/tensor_fp16x16.cairo | 10 ++- .../implementations/tensor_fp16x16wide.cairo | 16 ++-- .../implementations/tensor_fp32x32.cairo | 14 +-- .../implementations/tensor_fp64x64.cairo | 12 +-- .../implementations/tensor_fp8x23.cairo | 12 ++- .../implementations/tensor_fp8x23wide.cairo | 16 ++-- .../tensor/implementations/tensor_i32.cairo | 10 +-- .../tensor/implementations/tensor_i8.cairo | 13 ++- .../tensor/implementations/tensor_u32.cairo | 12 +-- src/operators/tensor/math/binarizer.cairo | 5 +- src/operators/tensor/math/reduce_mean.cairo | 55 +++++------- src/operators/tensor/math/reduce_min.cairo | 55 +++++------- .../tensor/math/sequence_construct.cairo | 3 +- src/operators/tensor/math/shrink.cairo | 5 +- src/operators/tensor/ml.cairo | 2 +- .../tensor/ml/array_feature_extractor.cairo | 24 +---- tests/ml.cairo | 2 +- tests/nodes.cairo | 90 +++++++++---------- .../array_feature_extractor_1D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_1D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_1D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_2D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_fp16x16.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_fp8x23.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- .../array_feature_extractor_3D_i32.cairo | 8 +- .../input_0.cairo | 2 +- .../input_1.cairo | 2 +- .../output_0.cairo | 2 +- tests/nodes/binarizer_fp16x16.cairo | 6 +- tests/nodes/binarizer_fp16x16/input_0.cairo | 2 +- tests/nodes/binarizer_fp16x16/output_0.cairo | 2 +- tests/nodes/binarizer_fp8x23.cairo | 6 +- tests/nodes/binarizer_fp8x23/input_0.cairo | 2 +- tests/nodes/binarizer_fp8x23/output_0.cairo | 2 +- tests/nodes/shrink_hard_fp16x16.cairo | 4 +- tests/nodes/shrink_hard_fp8x23.cairo | 4 +- tests/nodes/shrink_soft_fp16x16.cairo | 6 +- tests/nodes/shrink_soft_fp8x23.cairo | 6 +- 70 files changed, 283 insertions(+), 294 deletions(-) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 770049261..7cd555358 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -88,4 +88,4 @@ You can see below the list of current supported ONNX Operators: | [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | -Current Operators support: **76/156 (49%)** +Current Operators support: **81/156 (52%)** diff --git a/src/numbers.cairo b/src/numbers.cairo index 95573ae7a..bb781afb3 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -57,7 +57,9 @@ trait NumberTrait { fn sub(lhs: T, rhs: T) -> T; } -use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub}; +use orion::numbers::fixed_point::implementations::fp8x23::core::{ + FP8x23Impl, FP8x23, FP8x23Add, FP8x23Sub +}; use orion::numbers::fixed_point::implementations::fp8x23::math::core as core_fp8x23; use orion::numbers::fixed_point::implementations::fp8x23::math::comp as comp_fp8x23; @@ -258,7 +260,9 @@ impl FP8x23Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub}; +use orion::numbers::fixed_point::implementations::fp8x23wide::core::{ + FP8x23WImpl, FP8x23W, FP8x23WAdd, FP8x23WSub +}; use orion::numbers::fixed_point::implementations::fp8x23wide::math::core as core_fp8x23wide; use orion::numbers::fixed_point::implementations::fp8x23wide::math::comp as comp_fp8x23wide; @@ -459,7 +463,9 @@ impl FP8x23WNumber of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub}; +use orion::numbers::fixed_point::implementations::fp16x16::core::{ + FP16x16Impl, FP16x16, FP16x16Add, FP16x16Sub +}; use orion::numbers::fixed_point::implementations::fp16x16::math::core as core_fp16x16; use orion::numbers::fixed_point::implementations::fp16x16::math::comp as comp_fp16x16; @@ -660,7 +666,9 @@ impl FP16x16Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub}; +use orion::numbers::fixed_point::implementations::fp16x16wide::core::{ + FP16x16WImpl, FP16x16W, FP16x16WAdd, FP16x16WSub +}; use orion::numbers::fixed_point::implementations::fp16x16wide::math::core as core_fp16x16wide; use orion::numbers::fixed_point::implementations::fp16x16wide::math::comp as comp_fp16x16wide; @@ -861,7 +869,9 @@ impl FP16x16WNumber of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub}; +use orion::numbers::fixed_point::implementations::fp64x64::core::{ + FP64x64Impl, FP64x64, FP64x64Add, FP64x64Sub +}; use orion::numbers::fixed_point::implementations::fp64x64::core as core_fp64x64; use orion::numbers::fixed_point::implementations::fp64x64::comp as comp_fp64x64; use cubit::f128 as fp64x64; @@ -1063,7 +1073,9 @@ impl FP64x64Number of NumberTrait { } } -use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub}; +use orion::numbers::fixed_point::implementations::fp32x32::core::{ + FP32x32Impl, FP32x32, FP32x32Add, FP32x32Sub +}; use orion::numbers::fixed_point::implementations::fp32x32::core as core_fp32x32; use orion::numbers::fixed_point::implementations::fp32x32::comp as comp_fp32x32; use cubit::f64 as fp32x32; diff --git a/src/operators.cairo b/src/operators.cairo index 9f8628255..1ca6cdee2 100644 --- a/src/operators.cairo +++ b/src/operators.cairo @@ -2,4 +2,4 @@ mod tensor; mod nn; mod ml; mod matrix; -mod vec; \ No newline at end of file +mod vec; diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 7e7c44d7d..6e7c728e3 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3734,7 +3734,12 @@ trait TensorTrait { /// >>> [[1,2],[5,6]] /// ``` /// - fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; /// # tensor.sequence_empty /// /// ```rust @@ -3903,7 +3908,12 @@ trait TensorTrait { /// >>> [[0,1],[4,5]] /// ``` /// - fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/helpers.cairo b/src/operators/tensor/helpers.cairo index 6b65eb736..e55701dd6 100644 --- a/src/operators/tensor/helpers.cairo +++ b/src/operators/tensor/helpers.cairo @@ -328,7 +328,7 @@ fn replace_index(mut shape: Span, index: usize, value: usize) -> Span` - A span containing the usize elements representing the axes. -fn get_all_axes(shape: Span) -> Span{ +fn get_all_axes(shape: Span) -> Span { let mut ret: Array = ArrayTrait::new(); let mut i: usize = 0; let stop_i = shape.len() - 1; @@ -340,4 +340,4 @@ fn get_all_axes(shape: Span) -> Span{ i += 1; }; ret.span() -} \ No newline at end of file +} diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d4ec7d2ee..d24d9a88b 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -315,15 +315,15 @@ impl BoolTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -332,7 +332,7 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } @@ -349,7 +349,6 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } - } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 889234c13..610ffba1e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -352,15 +352,17 @@ impl FP16x16Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 7d5373839..3a9873570 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -321,7 +321,9 @@ impl FP16x16WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { + fn array_feature_extractor( + self: @Tensor, indices: Tensor + ) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } @@ -340,15 +342,17 @@ impl FP16x16WTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 03a8f5e26..6b50b1074 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -337,11 +337,11 @@ impl FP32x32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -353,15 +353,17 @@ impl FP32x32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index b5b0be29d..9931dd661 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -353,15 +353,17 @@ impl FP64x64Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index c7863d82c..5d5e2e06a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -344,15 +344,15 @@ impl FP8x23Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -361,7 +361,7 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_mean::reduce_mean(self, axes, keepdims, noop_with_empty_axes) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } @@ -378,8 +378,6 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - - } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 5e41c45c1..8fd044343 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -305,7 +305,7 @@ impl FP8x23WTensor of TensorTrait { fn binarizer(self: @Tensor, threshold: Option) -> Tensor { math::binarizer::binarizer(*self, threshold) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -331,15 +331,17 @@ impl FP8x23WTensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, @@ -357,8 +359,6 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - - } /// 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 6aefcdf96..9c7c2dc3b 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -336,7 +336,7 @@ impl I32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } @@ -352,15 +352,15 @@ impl I32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 49ff938e2..2d8b7ab4c 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -335,10 +335,9 @@ impl I8Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - - fn binarizer(self: @Tensor, threshold: Option) -> Tensor { - panic(array!['not supported!']) + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { + panic(array!['not supported!']) } fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { @@ -352,15 +351,15 @@ impl I8Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index ed885913e..d5ec1bd4b 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -306,11 +306,11 @@ impl U32Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } - + fn binarizer(self: @Tensor, threshold: Option) -> Tensor { panic(array!['not supported!']) } - + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_sum_square::reduce_sum_square(self, axis, keepdims) } @@ -322,15 +322,15 @@ impl U32Tensor of TensorTrait { fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } - + fn reduce_mean( self: @Tensor, axes: Option>, diff --git a/src/operators/tensor/math/binarizer.cairo b/src/operators/tensor/math/binarizer.cairo index 9b37a98ef..a75013d16 100644 --- a/src/operators/tensor/math/binarizer.cairo +++ b/src/operators/tensor/math/binarizer.cairo @@ -17,7 +17,6 @@ fn binarizer< >( mut self: Tensor, threshold: Option ) -> Tensor { - let threshold: T = if threshold.is_some() { threshold.unwrap() } else { @@ -35,9 +34,7 @@ fn binarizer< binarized_data.append(NumberTrait::zero()); } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/reduce_mean.cairo b/src/operators/tensor/math/reduce_mean.cairo index 7d64d85b5..23abf4840 100644 --- a/src/operators/tensor/math/reduce_mean.cairo +++ b/src/operators/tensor/math/reduce_mean.cairo @@ -10,7 +10,9 @@ use orion::numbers::signed_integer::integer_trait::IntegerTrait; use orion::numbers::fixed_point::core::FixedTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; -use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; +use orion::operators::tensor::helpers::{ + reduce_output_shape, len_from_shape, combine_indices, get_all_axes +}; use alexandria_sorting::bubble_sort; use alexandria_data_structures::array_ext::{SpanTraitExt}; @@ -34,27 +36,20 @@ fn reduce_mean< ) -> Tensor { let noop_with_empty_axes = match noop_with_empty_axes { Option::Some(noop_with_empty_axes) => noop_with_empty_axes, - Option::None(_) => { - false - }, + Option::None(_) => { false }, }; let axes = match axes { Option::Some(axes) => { - if(axes.len() == 0) { + if (axes.len() == 0) { get_all_axes(*self.shape) - } - else { + } else { assert(axes.len() == axes.unique().len(), 'duplicated axis.'); let mut axes_arr = ArrayTrait::new(); let mut copy_axes = axes; loop { match copy_axes.pop_front() { - Option::Some(axis) => { - axes_arr.append(*axis); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { axes_arr.append(*axis); }, + Option::None(_) => { break; } }; }; let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); @@ -70,11 +65,9 @@ fn reduce_mean< }; let keepdims = match keepdims { Option::Some(keepdims) => keepdims, - Option::None(_) => { - true - }, + Option::None(_) => { true }, }; - + let mut axis_c = 0; let mut copy_axes = axes; let mut shape = *self.shape; @@ -86,15 +79,15 @@ fn reduce_mean< let current_mean = accumulate_mean::(data, shape, shape, 0); shape = array![].span(); data = array![current_mean].span(); - break(); + break (); } let mut temp_data = ArrayTrait::new(); - let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let mut temp_shape = reduce_output_shape(shape, *axis - axis_c, false); let data_len = len_from_shape(temp_shape); let mut index: usize = 0; loop { let indices = unravel_index(index, temp_shape); - let current_mean = accumulate_mean::(data, shape, indices, *axis-axis_c); + let current_mean = accumulate_mean::(data, shape, indices, *axis - axis_c); temp_data.append(current_mean); @@ -107,23 +100,17 @@ fn reduce_mean< data = temp_data.span(); axis_c += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - + let mut axes_copy = axes; if keepdims == true { shape = *self.shape; loop { match axes_copy.pop_front() { - Option::Some(axis) => { - shape = reduce_output_shape(shape, *axis, true); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { shape = reduce_output_shape(shape, *axis, true); }, + Option::None(_) => { break; } }; }; return TensorTrait::::new(shape, data); @@ -173,20 +160,20 @@ fn accumulate_mean< let ele = *(input_data)[input_index]; acc += ele; axis_index += NumberTrait::one(); - axis_indexu32 +=1; + axis_indexu32 += 1; }; } else { loop { match input_data.pop_front() { - Option::Some(item) => { + Option::Some(item) => { acc += *item; axis_index += NumberTrait::one(); - axis_indexu32 +=1; + axis_indexu32 += 1; }, Option::None(_) => { break; } }; }; } // let axis_index: T = NumberTrait::::new(axis_index.try_into().unwrap(), false); - return acc/axis_index; + return acc / axis_index; } diff --git a/src/operators/tensor/math/reduce_min.cairo b/src/operators/tensor/math/reduce_min.cairo index 7299d9384..00568012f 100644 --- a/src/operators/tensor/math/reduce_min.cairo +++ b/src/operators/tensor/math/reduce_min.cairo @@ -9,7 +9,9 @@ use orion::numbers::signed_integer::integer_trait::IntegerTrait; use orion::numbers::fixed_point::core::FixedTrait; use orion::numbers::NumberTrait; use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; -use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices, get_all_axes}; +use orion::operators::tensor::helpers::{ + reduce_output_shape, len_from_shape, combine_indices, get_all_axes +}; use alexandria_sorting::bubble_sort; use alexandria_data_structures::array_ext::{SpanTraitExt}; @@ -32,27 +34,20 @@ fn reduce_min< ) -> Tensor { let noop_with_empty_axes = match noop_with_empty_axes { Option::Some(noop_with_empty_axes) => noop_with_empty_axes, - Option::None(_) => { - false - }, + Option::None(_) => { false }, }; let axes = match axes { Option::Some(axes) => { - if(axes.len() == 0) { + if (axes.len() == 0) { get_all_axes(*self.shape) - } - else { + } else { assert(axes.len() == axes.unique().len(), 'duplicated axis.'); let mut axes_arr = ArrayTrait::new(); let mut copy_axes = axes; loop { match copy_axes.pop_front() { - Option::Some(axis) => { - axes_arr.append(*axis); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { axes_arr.append(*axis); }, + Option::None(_) => { break; } }; }; let sorted_axes = bubble_sort::bubble_sort_elements(axes_arr).span(); @@ -68,11 +63,9 @@ fn reduce_min< }; let keepdims = match keepdims { Option::Some(keepdims) => keepdims, - Option::None(_) => { - true - }, + Option::None(_) => { true }, }; - + let mut axis_c = 0; let mut copy_axes = axes; let mut shape = *self.shape; @@ -84,15 +77,15 @@ fn reduce_min< let current_min = accumulate_min::(data, shape, shape, 0); shape = array![].span(); data = array![current_min].span(); - break(); + break (); } let mut temp_data = ArrayTrait::new(); - let mut temp_shape = reduce_output_shape(shape, *axis-axis_c, false); + let mut temp_shape = reduce_output_shape(shape, *axis - axis_c, false); let data_len = len_from_shape(temp_shape); let mut index: usize = 0; loop { let indices = unravel_index(index, temp_shape); - let current_min = accumulate_min::(data, shape, indices, *axis-axis_c); + let current_min = accumulate_min::(data, shape, indices, *axis - axis_c); temp_data.append(current_min); @@ -105,23 +98,17 @@ fn reduce_min< data = temp_data.span(); axis_c += 1; }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; - + let mut axes_copy = axes; if keepdims == true { shape = *self.shape; loop { match axes_copy.pop_front() { - Option::Some(axis) => { - shape = reduce_output_shape(shape, *axis, true); - }, - Option::None(_) => { - break; - } + Option::Some(axis) => { shape = reduce_output_shape(shape, *axis, true); }, + Option::None(_) => { break; } }; }; return TensorTrait::::new(shape, data); @@ -176,11 +163,9 @@ fn accumulate_min< } else { loop { match input_data.pop_front() { - Option::Some(item) => { - if (*item < min) { - min = *item; - } - }, + Option::Some(item) => { if (*item < min) { + min = *item; + } }, Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/math/sequence_construct.cairo b/src/operators/tensor/math/sequence_construct.cairo index 7bf0d1a54..dd8ff3101 100644 --- a/src/operators/tensor/math/sequence_construct.cairo +++ b/src/operators/tensor/math/sequence_construct.cairo @@ -5,8 +5,7 @@ use orion::operators::tensor::{TensorTrait, Tensor}; /// Cf: TensorTrait::sequence_construct docstring fn sequence_construct>(tensors: Array>) -> Array> { - assert(tensors.len() >= 1, 'Input tensors must be >= 1'); return tensors; -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/shrink.cairo b/src/operators/tensor/math/shrink.cairo index 90c010f85..194fc18dc 100644 --- a/src/operators/tensor/math/shrink.cairo +++ b/src/operators/tensor/math/shrink.cairo @@ -17,7 +17,6 @@ fn shrink< >( mut self: Tensor, bias: Option, lambd: Option ) -> Tensor { - let bias: T = if bias.is_some() { bias.unwrap() } else { @@ -45,9 +44,7 @@ fn shrink< data_result.append(NumberTrait::zero()); } }, - Option::None(_) => { - break; - } + Option::None(_) => { break; } }; }; diff --git a/src/operators/tensor/ml.cairo b/src/operators/tensor/ml.cairo index e9c3faa09..f47deeffd 100644 --- a/src/operators/tensor/ml.cairo +++ b/src/operators/tensor/ml.cairo @@ -1 +1 @@ -mod array_feature_extractor; \ No newline at end of file +mod array_feature_extractor; diff --git a/src/operators/tensor/ml/array_feature_extractor.cairo b/src/operators/tensor/ml/array_feature_extractor.cairo index 25e0aac16..240a69b43 100644 --- a/src/operators/tensor/ml/array_feature_extractor.cairo +++ b/src/operators/tensor/ml/array_feature_extractor.cairo @@ -7,10 +7,7 @@ use orion::numbers::NumberTrait; /// Cf: TensorTrait::array_feature_extractor docstring fn array_feature_extractor< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( self: Tensor, indices: Tensor ) -> Tensor { @@ -28,12 +25,7 @@ fn array_feature_extractor< } -fn process_1D_tensor< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop ->( +fn process_1D_tensor, impl TCopy: Copy, impl TDrop: Drop>( self: Tensor, indices: Tensor ) -> Tensor { let mut output_data = ArrayTrait::::new(); @@ -58,10 +50,7 @@ fn process_1D_tensor< fn calculate_output_shape< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( input_shape: Span, indices: Tensor ) -> (Array, usize) { @@ -92,12 +81,7 @@ fn calculate_output_shape< } -fn calculate_output_data< - T, - impl TTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop ->( +fn calculate_output_data, impl TCopy: Copy, impl TDrop: Drop>( self: Tensor, indices: Tensor, total_elements: usize ) -> Array { let last_tensor_axis: usize = *self.shape.at(self.shape.len() - 1); diff --git a/tests/ml.cairo b/tests/ml.cairo index f75954665..411cc99b2 100644 --- a/tests/ml.cairo +++ b/tests/ml.cairo @@ -1,2 +1,2 @@ mod tree_regressor; -mod tree_ensemble_classifier; \ No newline at end of file +mod tree_ensemble_classifier; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5bf6366d6..5270a5048 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -494,51 +494,51 @@ mod where_i8; mod where_i8_broadcast; mod where_u32; mod where_u32_broadcast; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_1D_i32; -mod array_feature_extractor_1D_fp8x23; -mod array_feature_extractor_1D_fp16x16; -mod array_feature_extractor_2D_i32; -mod array_feature_extractor_2D_fp8x23; -mod array_feature_extractor_2D_fp16x16; -mod array_feature_extractor_3D_i32; -mod array_feature_extractor_3D_fp8x23; -mod array_feature_extractor_3D_fp16x16; -mod binarizer_fp16x16; -mod binarizer_fp8x23; +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; +mod binarizer_fp16x16; +mod binarizer_fp8x23; mod tril_fp16x16; mod tril_fp16x16_neg; mod tril_fp16x16_one_row; diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo index a24571c9d..0dd7c5316 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo index e9eefbabf..f9acf6ef4 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo index 2472bf84b..85c53d04f 100644 --- a/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp16x16/output_0.cairo @@ -12,4 +12,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo index 72ccfa9fc..324db7177 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo index e3f37db08..bd7c3dccd 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_0.cairo @@ -14,4 +14,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo index 26340a8b6..da4e8d825 100644 --- a/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_fp8x23/output_0.cairo @@ -12,4 +12,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32.cairo b/tests/nodes/array_feature_extractor_1D_i32.cairo index 0d8dde9d8..15b7d39c3 100644 --- a/tests/nodes/array_feature_extractor_1D_i32.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_1D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo index 761aa81c4..780a73780 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/input_0.cairo @@ -13,4 +13,4 @@ fn input_0() -> Tensor { 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/nodes/array_feature_extractor_1D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo index b5a56f1ff..e503408e9 100644 --- a/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_1D_i32/output_0.cairo @@ -11,4 +11,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo index 7023d621a..94cfa0009 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo index 4742c7e7d..f9dd3a2ed 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo index c2ebb541a..239df58be 100644 --- a/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp16x16/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo index 06608774f..923418064 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo index 8b577178a..a00ffaaa6 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_0.cairo @@ -23,4 +23,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo index 91bd19d12..c782ae873 100644 --- a/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_fp8x23/output_0.cairo @@ -17,4 +17,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32.cairo b/tests/nodes/array_feature_extractor_2D_i32.cairo index 29368f5f3..ccbeb10dc 100644 --- a/tests/nodes/array_feature_extractor_2D_i32.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_2D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo index c7b027450..8ebfdd9d7 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/input_0.cairo @@ -22,4 +22,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, 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/nodes/array_feature_extractor_2D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo index c9d6cedf5..944dd7e3b 100644 --- a/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_2D_i32/output_0.cairo @@ -16,4 +16,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 3, sign: true }); data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo index eab071c49..eb9efd824 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_fp16x16() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo index 559a6ec9b..5424be3ef 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_0.cairo @@ -36,4 +36,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo index dc974161d..30519ac61 100644 --- a/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp16x16/output_0.cairo @@ -24,4 +24,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo index 8315e0caf..07dbf6383 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_fp8x23() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo index b74c32e6e..ad209c9a9 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_0.cairo @@ -36,4 +36,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo index 093210ec7..59aac2329 100644 --- a/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_fp8x23/output_0.cairo @@ -24,4 +24,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32.cairo b/tests/nodes/array_feature_extractor_3D_i32.cairo index e8688a4e9..092b5ff9d 100644 --- a/tests/nodes/array_feature_extractor_3D_i32.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32.cairo @@ -1,6 +1,6 @@ -mod input_0; -mod input_1; -mod output_0; +mod input_0; +mod input_1; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -19,4 +19,4 @@ fn test_array_feature_extractor_3D_i32() { let y = TensorTrait::array_feature_extractor(@input_0, input_1); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo index e53f9a696..6c37cf5af 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_0.cairo @@ -35,4 +35,4 @@ fn input_0() -> Tensor { data.append(i32 { mag: 1, 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/nodes/array_feature_extractor_3D_i32/input_1.cairo b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo index c575ffe22..1f8166137 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/input_1.cairo @@ -10,4 +10,4 @@ fn input_1() -> Tensor { data.append(1); data.append(3); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo index 56e50441e..6e25fdfd9 100644 --- a/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo +++ b/tests/nodes/array_feature_extractor_3D_i32/output_0.cairo @@ -23,4 +23,4 @@ fn output_0() -> Tensor { data.append(i32 { mag: 0, 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/nodes/binarizer_fp16x16.cairo b/tests/nodes/binarizer_fp16x16.cairo index 87306959b..d23d27c3e 100644 --- a/tests/nodes/binarizer_fp16x16.cairo +++ b/tests/nodes/binarizer_fp16x16.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,4 +18,4 @@ fn test_binarizer_fp16x16() { let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(65536, false))); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp16x16/input_0.cairo b/tests/nodes/binarizer_fp16x16/input_0.cairo index 597143f74..9fac068e6 100644 --- a/tests/nodes/binarizer_fp16x16/input_0.cairo +++ b/tests/nodes/binarizer_fp16x16/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP16x16 { mag: 53852, sign: true }); data.append(FP16x16 { mag: 93775, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp16x16/output_0.cairo b/tests/nodes/binarizer_fp16x16/output_0.cairo index b4bbbde98..d3f54efb4 100644 --- a/tests/nodes/binarizer_fp16x16/output_0.cairo +++ b/tests/nodes/binarizer_fp16x16/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP16x16 { mag: 0, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23.cairo b/tests/nodes/binarizer_fp8x23.cairo index 91b481fa3..c5d1190dd 100644 --- a/tests/nodes/binarizer_fp8x23.cairo +++ b/tests/nodes/binarizer_fp8x23.cairo @@ -1,5 +1,5 @@ -mod input_0; -mod output_0; +mod input_0; +mod output_0; use array::{ArrayTrait, SpanTrait}; @@ -18,4 +18,4 @@ fn test_binarizer_fp8x23() { let y = TensorTrait::binarizer(@input_0, Option::Some(FixedTrait::new(8388608, false))); assert_eq(y, z); -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23/input_0.cairo b/tests/nodes/binarizer_fp8x23/input_0.cairo index e11d8a9f4..680882f20 100644 --- a/tests/nodes/binarizer_fp8x23/input_0.cairo +++ b/tests/nodes/binarizer_fp8x23/input_0.cairo @@ -39,4 +39,4 @@ fn input_0() -> Tensor { data.append(FP8x23 { mag: 21216642, sign: true }); data.append(FP8x23 { mag: 2018862, sign: true }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/binarizer_fp8x23/output_0.cairo b/tests/nodes/binarizer_fp8x23/output_0.cairo index 8ec654745..a6c5e5513 100644 --- a/tests/nodes/binarizer_fp8x23/output_0.cairo +++ b/tests/nodes/binarizer_fp8x23/output_0.cairo @@ -39,4 +39,4 @@ fn output_0() -> Tensor { data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) -} \ No newline at end of file +} diff --git a/tests/nodes/shrink_hard_fp16x16.cairo b/tests/nodes/shrink_hard_fp16x16.cairo index 2272fd758..bd5635a2f 100644 --- a/tests/nodes/shrink_hard_fp16x16.cairo +++ b/tests/nodes/shrink_hard_fp16x16.cairo @@ -15,7 +15,9 @@ fn test_shrink_hard_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false))); + let y = TensorTrait::shrink( + input_0, Option::None(()), Option::Some(FixedTrait::new(65536, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_hard_fp8x23.cairo b/tests/nodes/shrink_hard_fp8x23.cairo index d9294c755..45b743bbd 100644 --- a/tests/nodes/shrink_hard_fp8x23.cairo +++ b/tests/nodes/shrink_hard_fp8x23.cairo @@ -15,7 +15,9 @@ fn test_shrink_hard_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false))); + let y = TensorTrait::shrink( + input_0, Option::None(()), Option::Some(FixedTrait::new(8388608, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_soft_fp16x16.cairo b/tests/nodes/shrink_soft_fp16x16.cairo index e5a8ef066..5c90ef120 100644 --- a/tests/nodes/shrink_soft_fp16x16.cairo +++ b/tests/nodes/shrink_soft_fp16x16.cairo @@ -15,7 +15,11 @@ fn test_shrink_soft_fp16x16() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(65536, false)), Option::Some(FixedTrait::new(65536, false))); + let y = TensorTrait::shrink( + input_0, + Option::Some(FixedTrait::new(65536, false)), + Option::Some(FixedTrait::new(65536, false)) + ); assert_eq(y, z); } diff --git a/tests/nodes/shrink_soft_fp8x23.cairo b/tests/nodes/shrink_soft_fp8x23.cairo index 66884de9f..3ee05b53d 100644 --- a/tests/nodes/shrink_soft_fp8x23.cairo +++ b/tests/nodes/shrink_soft_fp8x23.cairo @@ -15,7 +15,11 @@ fn test_shrink_soft_fp8x23() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = TensorTrait::shrink(input_0, Option::Some(FixedTrait::new(8388608, false)), Option::Some(FixedTrait::new(8388608, false))); + let y = TensorTrait::shrink( + input_0, + Option::Some(FixedTrait::new(8388608, false)), + Option::Some(FixedTrait::new(8388608, false)) + ); assert_eq(y, z); } From 7f43a6dd1c0d127f24fd4d9e340965f994ebbc16 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Thu, 16 Nov 2023 12:43:22 +0100 Subject: [PATCH 078/160] Refactor argument names --- nodegen/node/sequence_at.py | 80 +++++++++---------- src/operators/tensor/core.cairo | 2 +- .../tensor/implementations/tensor_bool.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 4 +- .../implementations/tensor_fp16x16wide.cairo | 4 +- .../implementations/tensor_fp32x32.cairo | 4 +- .../implementations/tensor_fp64x64.cairo | 4 +- .../implementations/tensor_fp8x23.cairo | 4 +- .../implementations/tensor_fp8x23wide.cairo | 4 +- .../tensor/implementations/tensor_i32.cairo | 4 +- .../tensor/implementations/tensor_i8.cairo | 4 +- .../tensor/implementations/tensor_u32.cairo | 4 +- src/operators/tensor/math/sequence_at.cairo | 25 +++--- .../nodes/sequence_at_fp16x16_negative.cairo | 8 +- .../input_0.cairo | 26 ++---- .../output_0.cairo | 6 +- .../nodes/sequence_at_fp16x16_positive.cairo | 8 +- .../input_0.cairo | 41 +++++++--- .../output_0.cairo | 7 +- tests/nodes/sequence_at_fp8x23_negative.cairo | 8 +- .../sequence_at_fp8x23_negative/input_0.cairo | 50 +++++++----- .../output_0.cairo | 8 +- tests/nodes/sequence_at_fp8x23_positive.cairo | 8 +- .../sequence_at_fp8x23_positive/input_0.cairo | 41 +++------- .../output_0.cairo | 9 +-- tests/nodes/sequence_at_i32_negative.cairo | 6 +- .../sequence_at_i32_negative/input_0.cairo | 41 +++++++--- .../sequence_at_i32_negative/output_0.cairo | 7 +- tests/nodes/sequence_at_i32_positive.cairo | 6 +- .../sequence_at_i32_positive/input_0.cairo | 67 ++++++++++++---- .../sequence_at_i32_positive/output_0.cairo | 15 +++- tests/nodes/sequence_at_i8_negative.cairo | 6 +- .../sequence_at_i8_negative/input_0.cairo | 32 +++----- .../sequence_at_i8_negative/output_0.cairo | 8 +- tests/nodes/sequence_at_i8_positive.cairo | 6 +- .../sequence_at_i8_positive/input_0.cairo | 64 ++++----------- .../sequence_at_i8_positive/output_0.cairo | 14 +--- tests/nodes/sequence_at_u32_negative.cairo | 10 +-- .../sequence_at_u32_negative/input_0.cairo | 38 +++++---- .../sequence_at_u32_negative/output_0.cairo | 8 +- tests/nodes/sequence_at_u32_positive.cairo | 10 +-- .../sequence_at_u32_positive/input_0.cairo | 16 ++-- .../sequence_at_u32_positive/output_0.cairo | 4 +- 43 files changed, 371 insertions(+), 352 deletions(-) diff --git a/nodegen/node/sequence_at.py b/nodegen/node/sequence_at.py index ed5c9ac07..b65ac5dae 100644 --- a/nodegen/node/sequence_at.py +++ b/nodegen/node/sequence_at.py @@ -10,7 +10,7 @@ class Sequence_at(RunAll): @staticmethod def sequence_at_u32(): - def positive_index(): + def positive_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -20,12 +20,12 @@ def positive_index(): sequence.append(tensor) - index = scalar(2) + position = scalar(2) name = "sequence_at_u32_positive" - make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) - def negative_index(): + def negative_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -35,18 +35,18 @@ def negative_index(): sequence.append(tensor) - index = scalar(-2) + position = scalar(-2) name = "sequence_at_u32_negative" - make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) - positive_index() - negative_index() + positive_position() + negative_position() @staticmethod def sequence_at_i32(): - def positive_index(): + def positive_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -56,12 +56,12 @@ def positive_index(): sequence.append(tensor) - index = scalar(2) + position = scalar(2) name = "sequence_at_i32_positive" - make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) - def negative_index(): + def negative_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -71,18 +71,18 @@ def negative_index(): sequence.append(tensor) - index = scalar(-2) + position = scalar(-2) name = "sequence_at_i32_negative" - make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) - positive_index() - negative_index() + positive_position() + negative_position() @staticmethod def sequence_at_i8(): - def positive_index(): + def positive_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -92,12 +92,12 @@ def positive_index(): sequence.append(tensor) - index = scalar(2) + position = scalar(2) name = "sequence_at_i8_positive" - make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) - def negative_index(): + def negative_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -107,18 +107,18 @@ def negative_index(): sequence.append(tensor) - index = scalar(-2) + position = scalar(-2) name = "sequence_at_i8_negative" - make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) - positive_index() - negative_index() + positive_position() + negative_position() @staticmethod def sequence_at_fp8x23(): - def positive_index(): + def positive_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -128,12 +128,12 @@ def positive_index(): sequence.append(tensor) - index = scalar(2) + position = scalar(2) name = "sequence_at_fp8x23_positive" - make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) - def negative_index(): + def negative_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -143,18 +143,18 @@ def negative_index(): sequence.append(tensor) - index = scalar(-2) + position = scalar(-2) name = "sequence_at_fp8x23_negative" - make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) - positive_index() - negative_index() + positive_position() + negative_position() @staticmethod def sequence_at_fp16x16(): - def positive_index(): + def positive_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -164,12 +164,12 @@ def positive_index(): sequence.append(tensor) - index = scalar(2) + position = scalar(2) name = "sequence_at_fp16x16_positive" - make_test([sequence, index], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[2], "TensorTrait::sequence_at(input_0, input_1)", name) - def negative_index(): + def negative_position(): sequence = [] shape = np.random.randint(1, 4, 2) @@ -179,10 +179,10 @@ def negative_index(): sequence.append(tensor) - index = scalar(-2) + position = scalar(-2) name = "sequence_at_fp16x16_negative" - make_test([sequence, index], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) + make_test([sequence, position], sequence[-2], "TensorTrait::sequence_at(input_0, input_1)", name) - positive_index() - negative_index() + positive_position() + negative_position() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 47414a718..f488ea1aa 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3584,7 +3584,7 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor; + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index efe03fe0c..5823edd71 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -313,7 +313,7 @@ impl BoolTensor of TensorTrait { constant_of_shape(shape, value) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { + fn sequence_at(sequence: Array>, position: 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 31ccb2fd0..fc987dbc7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -341,8 +341,8 @@ impl FP16x16Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 4d4940229..9bbe3625b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -329,8 +329,8 @@ impl FP16x16WTensor of TensorTrait { math::reduce_l2::reduce_l2(self, axis, keepdims) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 8994ba199..513f32a5a 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -342,8 +342,8 @@ impl FP32x32Tensor of TensorTrait { math::reduce_l2::reduce_l2(self, axis, keepdims) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 2e6a07d5c..5977bc8c1 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -342,8 +342,8 @@ impl FP64x64Tensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index be3f4eba0..57686bd45 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -341,8 +341,8 @@ impl FP8x23Tensor of TensorTrait { math::reduce_l2::reduce_l2(self, axis, keepdims) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index c47629cd1..11b925c2f 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -319,8 +319,8 @@ impl FP8x23WTensor of TensorTrait { math::scatter::scatter(self, updates, indices, axis, reduction) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index e605675a6..2ff763d99 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -341,8 +341,8 @@ impl I32Tensor of TensorTrait { panic(array!['not supported!']) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index b8a082bae..742e2fa7b 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -340,8 +340,8 @@ impl I8Tensor of TensorTrait { panic(array!['not supported!']) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index e675eed0f..22ed6c068 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -311,8 +311,8 @@ impl U32Tensor of TensorTrait { panic(array!['not supported!']) } - fn sequence_at(sequence: Array>, index: Tensor) -> Tensor { - math::sequence_at::sequence_at(sequence, index) + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { + math::sequence_at::sequence_at(sequence, position) } } diff --git a/src/operators/tensor/math/sequence_at.cairo b/src/operators/tensor/math/sequence_at.cairo index 161312110..6680bdec7 100644 --- a/src/operators/tensor/math/sequence_at.cairo +++ b/src/operators/tensor/math/sequence_at.cairo @@ -7,28 +7,23 @@ use orion::numbers::signed_integer::i32::i32; /// Cf: TensorTrait::sequence_at docstring fn sequence_at< - T, - MAG, - impl TTensor: TensorTrait, - impl TNumber: NumberTrait, - impl TCopy: Copy, - impl TDrop: Drop + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( - sequence: Array>, index: Tensor + sequence: Array>, position: Tensor ) -> Tensor { - assert(index.shape.len() == 0 && index.data.len() == 1, 'Index must be a scalar'); + assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); - let index_value_i32: i32 = *index.data.at(0); - let is_negative: bool = index_value_i32.sign; - let index_value = index_value_i32.mag; + let position_value_i32: i32 = *position.data.at(0); + let is_negative: bool = position_value_i32.sign; + let position_value = position_value_i32.mag; - assert((is_negative == false && index_value <= sequence.len() - 1) || (is_negative == true && index_value <= sequence.len()), 'Index out of bounds'); + assert((is_negative == false && position_value <= sequence.len() - 1) || (is_negative == true && position_value <= sequence.len()), 'Position out of bounds'); if is_negative == false { - return *sequence.at(index_value); + return *sequence.at(position_value); } else { - let reverted_index_value = sequence.len() - index_value; - return *sequence.at(reverted_index_value); + let normalized_position_value = sequence.len() - position_value; + return *sequence.at(normalized_position_value); } } \ No newline at end of file diff --git a/tests/nodes/sequence_at_fp16x16_negative.cairo b/tests/nodes/sequence_at_fp16x16_negative.cairo index 8defc6845..2532340c1 100644 --- a/tests/nodes/sequence_at_fp16x16_negative.cairo +++ b/tests/nodes/sequence_at_fp16x16_negative.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo b/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo index 1f24f1522..10cb3190b 100644 --- a/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo +++ b/tests/nodes/sequence_at_fp16x16_negative/input_0.cairo @@ -7,57 +7,47 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 327680, sign: false }); - data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 262144, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 393216, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 196608, sign: false }); - data.append(FP16x16 { mag: 262144, sign: false }); - data.append(FP16x16 { mag: 327680, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 393216, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo b/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo index 2e1afeb10..1b31e8b1a 100644 --- a/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo +++ b/tests/nodes/sequence_at_fp16x16_negative/output_0.cairo @@ -5,12 +5,10 @@ use orion::numbers::{FixedTrait, FP16x16}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(1); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 393216, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_fp16x16_positive.cairo b/tests/nodes/sequence_at_fp16x16_positive.cairo index a2f991b86..6fae1ca87 100644 --- a/tests/nodes/sequence_at_fp16x16_positive.cairo +++ b/tests/nodes/sequence_at_fp16x16_positive.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo b/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo index 2f696be97..d088467fc 100644 --- a/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo +++ b/tests/nodes/sequence_at_fp16x16_positive/input_0.cairo @@ -7,57 +7,72 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); data.append(FP16x16 { mag: 262144, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 262144, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 327680, sign: false }); - data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 327680, sign: false }); - data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 262144, sign: true }); data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo b/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo index 29bb4ade6..b019cfdcf 100644 --- a/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo +++ b/tests/nodes/sequence_at_fp16x16_positive/output_0.cairo @@ -5,12 +5,15 @@ use orion::numbers::{FixedTrait, FP16x16}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(1); shape.append(3); + shape.append(2); let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 327680, sign: false }); - data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_fp8x23_negative.cairo b/tests/nodes/sequence_at_fp8x23_negative.cairo index 23d8badd5..5fd377633 100644 --- a/tests/nodes/sequence_at_fp8x23_negative.cairo +++ b/tests/nodes/sequence_at_fp8x23_negative.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::FP8x23TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo b/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo index 927150f50..f1011dd19 100644 --- a/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo +++ b/tests/nodes/sequence_at_fp8x23_negative/input_0.cairo @@ -8,61 +8,71 @@ fn input_0() -> Array> { let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 33554432, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: false }); - data.append(FP8x23 { mag: 41943040, sign: true }); data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); - 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: 33554432, sign: true }); data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo b/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo index ad35ea60d..2931ad2cf 100644 --- a/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo +++ b/tests/nodes/sequence_at_fp8x23_negative/output_0.cairo @@ -6,12 +6,14 @@ use orion::numbers::{FixedTrait, FP8x23}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(3); let mut data = ArrayTrait::new(); - 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: 33554432, sign: true }); data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_fp8x23_positive.cairo b/tests/nodes/sequence_at_fp8x23_positive.cairo index d671067a7..6eda4298d 100644 --- a/tests/nodes/sequence_at_fp8x23_positive.cairo +++ b/tests/nodes/sequence_at_fp8x23_positive.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use orion::operators::tensor::FP8x23TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo b/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo index cf2a22092..acfa9f0cb 100644 --- a/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo +++ b/tests/nodes/sequence_at_fp8x23_positive/input_0.cairo @@ -7,72 +7,57 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: false }); data.append(FP8x23 { mag: 41943040, sign: false }); - data.append(FP8x23 { mag: 50331648, sign: true }); - data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 41943040, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 50331648, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 41943040, sign: false }); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 41943040, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 33554432, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 41943040, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 41943040, sign: false }); - data.append(FP8x23 { mag: 41943040, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo b/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo index 8bbaa2a70..52363bc8f 100644 --- a/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo +++ b/tests/nodes/sequence_at_fp8x23_positive/output_0.cairo @@ -5,15 +5,12 @@ use orion::numbers::{FixedTrait, FP8x23}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); + shape.append(1); shape.append(3); - shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 41943040, sign: false }); - data.append(FP8x23 { mag: 33554432, sign: true }); - data.append(FP8x23 { mag: 33554432, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_i32_negative.cairo b/tests/nodes/sequence_at_i32_negative.cairo index acc116127..0b76101b9 100644 --- a/tests/nodes/sequence_at_i32_negative.cairo +++ b/tests/nodes/sequence_at_i32_negative.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_i32_negative/input_0.cairo b/tests/nodes/sequence_at_i32_negative/input_0.cairo index f43b21e0b..043154542 100644 --- a/tests/nodes/sequence_at_i32_negative/input_0.cairo +++ b/tests/nodes/sequence_at_i32_negative/input_0.cairo @@ -7,57 +7,72 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 5, sign: false }); - data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 6, sign: true }); - data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 3, sign: false }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 4, sign: false }); data.append(i32 { mag: 6, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 6, sign: true }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 3, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_i32_negative/output_0.cairo b/tests/nodes/sequence_at_i32_negative/output_0.cairo index f5cea646b..d9972a6c4 100644 --- a/tests/nodes/sequence_at_i32_negative/output_0.cairo +++ b/tests/nodes/sequence_at_i32_negative/output_0.cairo @@ -5,12 +5,15 @@ use orion::numbers::{IntegerTrait, i32}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(1); + shape.append(2); shape.append(3); let mut data = ArrayTrait::new(); data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 6, sign: true }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_i32_positive.cairo b/tests/nodes/sequence_at_i32_positive.cairo index 47bed6a34..ae9c83772 100644 --- a/tests/nodes/sequence_at_i32_positive.cairo +++ b/tests/nodes/sequence_at_i32_positive.cairo @@ -3,11 +3,11 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_i32_positive/input_0.cairo b/tests/nodes/sequence_at_i32_positive/input_0.cairo index eb6201988..733b2e7f0 100644 --- a/tests/nodes/sequence_at_i32_positive/input_0.cairo +++ b/tests/nodes/sequence_at_i32_positive/input_0.cairo @@ -7,52 +7,87 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 5, sign: true }); - data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 6, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 2, sign: true }); data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 3, sign: false }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 5, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); + 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: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 5, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_i32_positive/output_0.cairo b/tests/nodes/sequence_at_i32_positive/output_0.cairo index 76cd6f356..a95f1e572 100644 --- a/tests/nodes/sequence_at_i32_positive/output_0.cairo +++ b/tests/nodes/sequence_at_i32_positive/output_0.cairo @@ -5,11 +5,18 @@ use orion::numbers::{IntegerTrait, i32}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(1); - shape.append(2); + shape.append(3); + shape.append(3); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_i8_negative.cairo b/tests/nodes/sequence_at_i8_negative.cairo index 305322425..d0e63feaf 100644 --- a/tests/nodes/sequence_at_i8_negative.cairo +++ b/tests/nodes/sequence_at_i8_negative.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; use orion::operators::tensor::I32TensorPartialEq; use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_i8_negative/input_0.cairo b/tests/nodes/sequence_at_i8_negative/input_0.cairo index fa86cbabd..02483ad10 100644 --- a/tests/nodes/sequence_at_i8_negative/input_0.cairo +++ b/tests/nodes/sequence_at_i8_negative/input_0.cairo @@ -8,61 +8,51 @@ fn input_0() -> Array> { let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 4, sign: false }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 6, sign: true }); data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 3, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 5, sign: false }); - data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 5, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 6, sign: true }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_i8_negative/output_0.cairo b/tests/nodes/sequence_at_i8_negative/output_0.cairo index 37306188b..2bbe5f9d8 100644 --- a/tests/nodes/sequence_at_i8_negative/output_0.cairo +++ b/tests/nodes/sequence_at_i8_negative/output_0.cairo @@ -6,12 +6,10 @@ use orion::numbers::{IntegerTrait, i8}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); shape.append(2); - shape.append(2); + shape.append(1); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 6, sign: true }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_i8_positive.cairo b/tests/nodes/sequence_at_i8_positive.cairo index 74f6b4323..c8d94c4be 100644 --- a/tests/nodes/sequence_at_i8_positive.cairo +++ b/tests/nodes/sequence_at_i8_positive.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; use orion::operators::tensor::I32TensorPartialEq; use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I8TensorPartialEq; use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_i8_positive/input_0.cairo b/tests/nodes/sequence_at_i8_positive/input_0.cairo index f9c7f2ed6..ac6c7dcb6 100644 --- a/tests/nodes/sequence_at_i8_positive/input_0.cairo +++ b/tests/nodes/sequence_at_i8_positive/input_0.cairo @@ -7,87 +7,57 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 4, sign: false }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 6, sign: true }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 3, 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: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 5, sign: false }); - data.append(i8 { mag: 5, sign: true }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 6, sign: true }); - data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 4, sign: false }); - data.append(i8 { mag: 4, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 5, sign: true }); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_i8_positive/output_0.cairo b/tests/nodes/sequence_at_i8_positive/output_0.cairo index f479a7998..0cc51dfce 100644 --- a/tests/nodes/sequence_at_i8_positive/output_0.cairo +++ b/tests/nodes/sequence_at_i8_positive/output_0.cairo @@ -5,18 +5,12 @@ use orion::numbers::{IntegerTrait, i8}; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(3); + shape.append(1); shape.append(3); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 4, sign: false }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 3, sign: false }); - data.append(i8 { mag: 6, sign: true }); - data.append(i8 { mag: 4, sign: true }); - data.append(i8 { mag: 3, 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: 0, sign: false }); + data.append(i8 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_u32_negative.cairo b/tests/nodes/sequence_at_u32_negative.cairo index 712de30e1..7046b99dc 100644 --- a/tests/nodes/sequence_at_u32_negative.cairo +++ b/tests/nodes/sequence_at_u32_negative.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_u32_negative/input_0.cairo b/tests/nodes/sequence_at_u32_negative/input_0.cairo index e68d3cdb3..c332e8cda 100644 --- a/tests/nodes/sequence_at_u32_negative/input_0.cairo +++ b/tests/nodes/sequence_at_u32_negative/input_0.cairo @@ -6,62 +6,72 @@ fn input_0() -> Array> { let mut sequence = ArrayTrait::new(); let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); - data.append(0); - data.append(4); + data.append(5); + data.append(2); data.append(3); + data.append(4); data.append(0); + data.append(3); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); - data.append(2); - data.append(2); + data.append(1); + data.append(3); + data.append(3); data.append(4); data.append(2); + data.append(2); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); + data.append(5); + data.append(1); data.append(3); - data.append(3); - data.append(0); data.append(2); + data.append(3); + data.append(3); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); data.append(0); data.append(1); + data.append(3); + data.append(0); + data.append(5); + data.append(3); sequence.append(TensorTrait::new(shape.span(), data.span())); let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); data.append(4); data.append(2); + data.append(1); data.append(0); - data.append(3); + data.append(4); + data.append(2); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_u32_negative/output_0.cairo b/tests/nodes/sequence_at_u32_negative/output_0.cairo index b3180e186..82b5c7003 100644 --- a/tests/nodes/sequence_at_u32_negative/output_0.cairo +++ b/tests/nodes/sequence_at_u32_negative/output_0.cairo @@ -4,13 +4,15 @@ use orion::operators::tensor::U32Tensor; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); + shape.append(3); shape.append(2); let mut data = ArrayTrait::new(); - data.append(1); - data.append(1); data.append(0); data.append(1); + data.append(3); + data.append(0); + data.append(5); + data.append(3); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/sequence_at_u32_positive.cairo b/tests/nodes/sequence_at_u32_positive.cairo index f721dbf43..0eca97a5c 100644 --- a/tests/nodes/sequence_at_u32_positive.cairo +++ b/tests/nodes/sequence_at_u32_positive.cairo @@ -3,13 +3,13 @@ mod input_1; mod output_0; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32Tensor; use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32Tensor; use orion::operators::tensor::U32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32TensorPartialEq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/sequence_at_u32_positive/input_0.cairo b/tests/nodes/sequence_at_u32_positive/input_0.cairo index 9a80cc816..a4f060c30 100644 --- a/tests/nodes/sequence_at_u32_positive/input_0.cairo +++ b/tests/nodes/sequence_at_u32_positive/input_0.cairo @@ -10,8 +10,8 @@ fn input_0() -> Array> { shape.append(3); let mut data = ArrayTrait::new(); - data.append(5); data.append(3); + data.append(1); data.append(4); sequence.append(TensorTrait::new(shape.span(), data.span())); @@ -22,8 +22,8 @@ fn input_0() -> Array> { let mut data = ArrayTrait::new(); data.append(4); - data.append(0); data.append(1); + data.append(3); sequence.append(TensorTrait::new(shape.span(), data.span())); @@ -32,9 +32,9 @@ fn input_0() -> Array> { shape.append(3); let mut data = ArrayTrait::new(); - data.append(0); data.append(5); - data.append(2); + data.append(5); + data.append(0); sequence.append(TensorTrait::new(shape.span(), data.span())); @@ -43,9 +43,9 @@ fn input_0() -> Array> { shape.append(3); let mut data = ArrayTrait::new(); + data.append(1); + data.append(4); data.append(0); - data.append(3); - data.append(5); sequence.append(TensorTrait::new(shape.span(), data.span())); @@ -55,8 +55,8 @@ fn input_0() -> Array> { let mut data = ArrayTrait::new(); data.append(5); - data.append(2); - data.append(2); + data.append(5); + data.append(3); sequence.append(TensorTrait::new(shape.span(), data.span())); diff --git a/tests/nodes/sequence_at_u32_positive/output_0.cairo b/tests/nodes/sequence_at_u32_positive/output_0.cairo index 98a00dc92..f1da37367 100644 --- a/tests/nodes/sequence_at_u32_positive/output_0.cairo +++ b/tests/nodes/sequence_at_u32_positive/output_0.cairo @@ -8,8 +8,8 @@ fn output_0() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(0); data.append(5); - data.append(2); + data.append(5); + data.append(0); TensorTrait::new(shape.span(), data.span()) } From a6f3a45343661b65ab34f20f8330f296abf4594a Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Thu, 16 Nov 2023 12:57:33 +0100 Subject: [PATCH 079/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.sequence_at.md | 45 ++++++++++++++++++ src/operators/tensor/core.cairo | 47 +++++++++++++++++++ src/operators/tensor/math/sequence_at.cairo | 2 +- 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_at.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..7bcd24069 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.sequence\_at](framework/operators/tensor/tensor.sequence\_at.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 ebc50ad77..e4032e9b3 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceAt](operators/tensor/tensor.sequence\_at.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (49%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..9b9e4d1a7 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_at`](tensor.sequence\_at.md) | Outputs the tensor at the specified position in the input sequence. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_at.md b/docs/framework/operators/tensor/tensor.sequence_at.md new file mode 100644 index 000000000..e0a9535f9 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_at.md @@ -0,0 +1,45 @@ +## tensor.sequence_at + +```rust + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; +``` + +Outputs the tensor at the specified position in the input sequence. + +## Args + +* `tensors`(`Array>`) - The tensor sequence. +* `position`(`Tensor`) - The position tensor. + +## Panics + +* Panics if position is not a scalar +* Panics if position is out of bounds [-n, n - 1] + +## Returns + +The tensor `Tensor` from the sequence at the specified position. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn sequence_at_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + + let mut sequence = ArrayTrait::new(); + sequence.append(tensor1); + sequence.append(tensor2); + + let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + + let result = TensorTrait::sequence_at(sequence, position); + return result; +} +>>> [4, 5, 6, 7] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index f488ea1aa..c1c6ff81e 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3585,52 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.sequence_at + /// + /// ```rust + /// fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; + /// ``` + /// + /// Outputs the tensor at the specified position in the input sequence. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The tensor sequence. + /// * `position`(`Tensor`) - The position tensor. + /// + /// ## Panics + /// + /// * Panics if position is not a scalar + /// * Panics if position is out of bounds [-n, n - 1] + /// + /// ## Returns + /// + /// The tensor `Tensor` from the sequence at the specified position. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn sequence_at_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// + /// let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + /// + /// let result = TensorTrait::sequence_at(sequence, position); + /// return result; + /// } + /// >>> [4, 5, 6, 7] + /// ``` + /// fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; } diff --git a/src/operators/tensor/math/sequence_at.cairo b/src/operators/tensor/math/sequence_at.cairo index 6680bdec7..c819afdab 100644 --- a/src/operators/tensor/math/sequence_at.cairo +++ b/src/operators/tensor/math/sequence_at.cairo @@ -16,7 +16,7 @@ fn sequence_at< let position_value_i32: i32 = *position.data.at(0); let is_negative: bool = position_value_i32.sign; - let position_value = position_value_i32.mag; + let position_value: u32 = position_value_i32.mag; assert((is_negative == false && position_value <= sequence.len() - 1) || (is_negative == true && position_value <= sequence.len()), 'Position out of bounds'); From 61c20d5415cb140f5f58167a34bc49be9a3fe1fa Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Thu, 16 Nov 2023 15:30:17 +0100 Subject: [PATCH 080/160] Implement operator --- src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + .../tensor/math/sequence_erase.cairo | 55 +++++++++++++++++++ 13 files changed, 97 insertions(+) create mode 100644 src/operators/tensor/math/sequence_erase.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 6e7c728e3..445654ec1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3914,6 +3914,7 @@ trait TensorTrait { keepdims: Option, noop_with_empty_axes: Option ) -> Tensor; + fn sequence_erase(sequence: Array>, position: Option>) -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d24d9a88b..43b160047 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -349,6 +349,10 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 610ffba1e..a41fa3bd7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -380,6 +380,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 3a9873570..d6d6bffc2 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -370,6 +370,10 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 6b50b1074..06cb20f47 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -381,6 +381,10 @@ impl FP32x32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 9931dd661..9037ed65b 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -381,6 +381,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 5d5e2e06a..2253c0e40 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -378,6 +378,10 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8fd044343..23a7fe51b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -359,6 +359,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 9c7c2dc3b..81911435f 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -378,6 +378,10 @@ impl I32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 2d8b7ab4c..fab509c2d 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -377,6 +377,10 @@ impl I8Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// 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 d5ec1bd4b..89e7faafb 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -348,6 +348,10 @@ impl U32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + math::sequence_erase::sequence_erase(sequence, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 14625600c..6af1fb403 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -49,3 +49,4 @@ mod sequence_construct; mod shrink; mod sequence_empty; mod reduce_mean; +mod sequence_erase; diff --git a/src/operators/tensor/math/sequence_erase.cairo b/src/operators/tensor/math/sequence_erase.cairo new file mode 100644 index 000000000..ed6ce6719 --- /dev/null +++ b/src/operators/tensor/math/sequence_erase.cairo @@ -0,0 +1,55 @@ +use array::{ArrayTrait, SpanTrait}; +use option::OptionTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::NumberTrait; +use orion::numbers::signed_integer::i32::i32; + +/// Cf: TensorTrait::sequence_erase docstring +fn sequence_erase< + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop +>( + sequence: Array>, position: Option> +) -> Array> { + + let position: Tensor = if position.is_some() { + position.unwrap() + } else { + let mut shape = ArrayTrait::::new(); + let mut data = ArrayTrait::::new(); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::::new(shape.span(), data.span()) + }; + + assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); + + let position_value_i32: i32 = *position.data.at(0); + let is_negative: bool = position_value_i32.sign; + let mut position_value: u32 = position_value_i32.mag; + + assert((is_negative == false && position_value <= sequence.len() - 1) || (is_negative == true && position_value <= sequence.len()), 'Position out of bounds'); + + if is_negative == true { + position_value = sequence.len() - position_value; + } + + let mut output_sequence = ArrayTrait::new(); + + let mut tensor_counter: usize = 0; + loop { + if tensor_counter > sequence.len() - 1 { + break; + } + + if tensor_counter == position_value { + continue; + } + + output_sequence.append(*sequence.at(tensor_counter)); + + tensor_counter += 1; + }; + + return output_sequence; +} \ No newline at end of file From aee4d5c9b48d25c3c89c7a40d46e7572e37d0a12 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Thu, 16 Nov 2023 17:48:33 +0100 Subject: [PATCH 081/160] Refactor loops --- .../tensor/math/sequence_erase.cairo | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/operators/tensor/math/sequence_erase.cairo b/src/operators/tensor/math/sequence_erase.cairo index ed6ce6719..cb8be22ed 100644 --- a/src/operators/tensor/math/sequence_erase.cairo +++ b/src/operators/tensor/math/sequence_erase.cairo @@ -13,13 +13,16 @@ fn sequence_erase< sequence: Array>, position: Option> ) -> Array> { - let position: Tensor = if position.is_some() { - position.unwrap() - } else { - let mut shape = ArrayTrait::::new(); - let mut data = ArrayTrait::::new(); - data.append(i32 { mag: 1, sign: true }); - TensorTrait::::new(shape.span(), data.span()) + let position: Tensor = match position { + Option::Some(value) => { + position.unwrap() + }, + Option::None(_) => { + let mut shape = ArrayTrait::::new(); + let mut data = ArrayTrait::::new(); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::::new(shape.span(), data.span()) + } }; assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); @@ -34,21 +37,21 @@ fn sequence_erase< position_value = sequence.len() - position_value; } + let mut input_sequence_copy = sequence; let mut output_sequence = ArrayTrait::new(); - let mut tensor_counter: usize = 0; loop { - if tensor_counter > sequence.len() - 1 { - break; - } - - if tensor_counter == position_value { - continue; - } - - output_sequence.append(*sequence.at(tensor_counter)); - - tensor_counter += 1; + match input_sequence_copy.pop_front() { + Option::Some(input_sequence_value) => { + if tensor_counter == position_value { + continue; + } + output_sequence.append(input_sequence_value); + + tensor_counter += 1; + }, + Option::None(_) => { break; } + }; }; return output_sequence; From d756df5495e53156ab610426717deee4fc93b663 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 15 Nov 2023 17:31:51 +0100 Subject: [PATCH 082/160] Add nodegen script --- nodegen/node/sequence_insert.py | 143 ++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 nodegen/node/sequence_insert.py diff --git a/nodegen/node/sequence_insert.py b/nodegen/node/sequence_insert.py new file mode 100644 index 000000000..2dec7af1f --- /dev/null +++ b/nodegen/node/sequence_insert.py @@ -0,0 +1,143 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +scalar = lambda x: Tensor(Dtype.I32, (), np.array([x]).astype(np.int32).flatten()) + + +class Sequence_insert(RunAll): + + @staticmethod + def sequence_insert_u32(): + def default(): + sequence = [] + tensor_cnt = 3 + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + val = np.random.randint(0, 6, shape).astype(np.uint32) + t = Tensor(Dtype.U32, val.shape, val.flatten()) + + sequence.append(t) + + val = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, val.shape, val.flatten()) + + position = np.random.randint(-2, 2) + + expected_sequence = sequence.copy() + expected_sequence.insert(position, tensor) + + name = "sequence_insert_u32" + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + + default() + + @staticmethod + def sequence_insert_i32(): + def default(): + sequence = [] + tensor_cnt = 3 + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + val = np.random.randint(0, 6, shape).astype(np.int32) + t = Tensor(Dtype.I32, val.shape, val.flatten()) + + sequence.append(t) + + val = np.random.randint(0, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, val.shape, val.flatten()) + + position = np.random.randint(-2, 2) + + expected_sequence = sequence.copy() + expected_sequence.insert(position, tensor) + + name = "sequence_insert_i32" + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + + default() + + @staticmethod + def sequence_insert_i8(): + def default(): + sequence = [] + tensor_cnt = 3 + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + val = np.random.randint(0, 6, shape).astype(np.int8) + t = Tensor(Dtype.I8, val.shape, val.flatten()) + + sequence.append(t) + + val = np.random.randint(0, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, val.shape, val.flatten()) + + position = np.random.randint(-2, 2) + + expected_sequence = sequence.copy() + expected_sequence.insert(position, tensor) + + name = "sequence_insert_i8" + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + + default() + + @staticmethod + def sequence_insert_fp8x23(): + def default(): + sequence = [] + tensor_cnt = 3 + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + val = np.random.randint(0, 6, shape).astype(np.float64) + t = Tensor(Dtype.FP8x23, val.shape, to_fp( + val.flatten(), FixedImpl.FP8x23)) + + sequence.append(t) + + val = np.random.randint(0, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, val.shape, to_fp( + val.flatten(), FixedImpl.FP8x23)) + + position = np.random.randint(-2, 2) + + expected_sequence = sequence.copy() + expected_sequence.insert(position, tensor) + + name = "sequence_insert_fp8x23" + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + + default() + + @staticmethod + def sequence_insert_fp16x16(): + def default(): + sequence = [] + tensor_cnt = 3 + shape = np.random.randint(1, 4, 2) + + for _ in range(tensor_cnt): + val = np.random.randint(0, 6, shape).astype(np.float64) + t = Tensor(Dtype.FP16x16, val.shape, to_fp( + val.flatten(), FixedImpl.FP16x16)) + + sequence.append(t) + + val = np.random.randint(0, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, val.shape, to_fp( + val.flatten(), FixedImpl.FP16x16)) + + position = np.random.randint(-2, 2) + + expected_sequence = sequence.copy() + expected_sequence.insert(position, tensor) + + name = "sequence_insert_fp16x16" + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + + default() From 04bd4234a23a6857f496e32ecab3523bf9079bfc Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Wed, 15 Nov 2023 18:57:03 +0100 Subject: [PATCH 083/160] Add tests --- nodegen/node/sequence_insert.py | 10 +-- src/operators/tensor/core.cairo | 6 ++ .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + .../tensor/math/sequence_insert.cairo | 10 +++ tests/nodes.cairo | 5 ++ tests/nodes/sequence_insert_fp16x16.cairo | 26 ++++++++ .../sequence_insert_fp16x16/input_0.cairo | 52 +++++++++++++++ .../sequence_insert_fp16x16/input_1.cairo | 19 ++++++ .../sequence_insert_fp16x16/input_2.cairo | 12 ++++ .../sequence_insert_fp16x16/output_0.cairo | 66 +++++++++++++++++++ tests/nodes/sequence_insert_fp8x23.cairo | 26 ++++++++ .../sequence_insert_fp8x23/input_0.cairo | 52 +++++++++++++++ .../sequence_insert_fp8x23/input_1.cairo | 19 ++++++ .../sequence_insert_fp8x23/input_2.cairo | 12 ++++ .../sequence_insert_fp8x23/output_0.cairo | 66 +++++++++++++++++++ tests/nodes/sequence_insert_i32.cairo | 24 +++++++ tests/nodes/sequence_insert_i32/input_0.cairo | 40 +++++++++++ tests/nodes/sequence_insert_i32/input_1.cairo | 15 +++++ tests/nodes/sequence_insert_i32/input_2.cairo | 12 ++++ .../nodes/sequence_insert_i32/output_0.cairo | 50 ++++++++++++++ tests/nodes/sequence_insert_i8.cairo | 26 ++++++++ tests/nodes/sequence_insert_i8/input_0.cairo | 40 +++++++++++ tests/nodes/sequence_insert_i8/input_1.cairo | 15 +++++ tests/nodes/sequence_insert_i8/input_2.cairo | 12 ++++ tests/nodes/sequence_insert_i8/output_0.cairo | 50 ++++++++++++++ tests/nodes/sequence_insert_u32.cairo | 26 ++++++++ tests/nodes/sequence_insert_u32/input_0.cairo | 45 +++++++++++++ tests/nodes/sequence_insert_u32/input_1.cairo | 16 +++++ tests/nodes/sequence_insert_u32/input_2.cairo | 12 ++++ .../nodes/sequence_insert_u32/output_0.cairo | 57 ++++++++++++++++ 40 files changed, 857 insertions(+), 5 deletions(-) create mode 100644 src/operators/tensor/math/sequence_insert.cairo create mode 100644 tests/nodes/sequence_insert_fp16x16.cairo create mode 100644 tests/nodes/sequence_insert_fp16x16/input_0.cairo create mode 100644 tests/nodes/sequence_insert_fp16x16/input_1.cairo create mode 100644 tests/nodes/sequence_insert_fp16x16/input_2.cairo create mode 100644 tests/nodes/sequence_insert_fp16x16/output_0.cairo create mode 100644 tests/nodes/sequence_insert_fp8x23.cairo create mode 100644 tests/nodes/sequence_insert_fp8x23/input_0.cairo create mode 100644 tests/nodes/sequence_insert_fp8x23/input_1.cairo create mode 100644 tests/nodes/sequence_insert_fp8x23/input_2.cairo create mode 100644 tests/nodes/sequence_insert_fp8x23/output_0.cairo create mode 100644 tests/nodes/sequence_insert_i32.cairo create mode 100644 tests/nodes/sequence_insert_i32/input_0.cairo create mode 100644 tests/nodes/sequence_insert_i32/input_1.cairo create mode 100644 tests/nodes/sequence_insert_i32/input_2.cairo create mode 100644 tests/nodes/sequence_insert_i32/output_0.cairo create mode 100644 tests/nodes/sequence_insert_i8.cairo create mode 100644 tests/nodes/sequence_insert_i8/input_0.cairo create mode 100644 tests/nodes/sequence_insert_i8/input_1.cairo create mode 100644 tests/nodes/sequence_insert_i8/input_2.cairo create mode 100644 tests/nodes/sequence_insert_i8/output_0.cairo create mode 100644 tests/nodes/sequence_insert_u32.cairo create mode 100644 tests/nodes/sequence_insert_u32/input_0.cairo create mode 100644 tests/nodes/sequence_insert_u32/input_1.cairo create mode 100644 tests/nodes/sequence_insert_u32/input_2.cairo create mode 100644 tests/nodes/sequence_insert_u32/output_0.cairo diff --git a/nodegen/node/sequence_insert.py b/nodegen/node/sequence_insert.py index 2dec7af1f..ac0a2c79c 100644 --- a/nodegen/node/sequence_insert.py +++ b/nodegen/node/sequence_insert.py @@ -30,7 +30,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_u32" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) default() @@ -56,7 +56,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_i32" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) default() @@ -82,7 +82,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_i8" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) default() @@ -110,7 +110,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_fp8x23" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) default() @@ -138,6 +138,6 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_fp16x16" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(input_1,input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) default() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 6e7c728e3..fa6c25dd1 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -96,11 +96,15 @@ impl TensorSerde, impl TDrop: Drop> of Serde>>>>>> a3286e87 (Add tests) trait TensorTrait { /// # tensor.new /// @@ -3914,6 +3918,8 @@ trait TensorTrait { keepdims: Option, noop_with_empty_axes: Option ) -> Tensor; + /// TODO + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d24d9a88b..513dbdd2d 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -349,6 +349,10 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 610ffba1e..ae4c8c8b7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -380,6 +380,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 3a9873570..c215a47a1 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -370,6 +370,10 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 6b50b1074..37071210b 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -381,6 +381,10 @@ impl FP32x32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 9931dd661..dc9635719 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -381,6 +381,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 5d5e2e06a..9080fc6be 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -378,6 +378,10 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8fd044343..4666eac53 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -359,6 +359,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 9c7c2dc3b..a057a0dec 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -378,6 +378,10 @@ impl I32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 2d8b7ab4c..bbfb9e722 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -377,6 +377,10 @@ impl I8Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// 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 d5ec1bd4b..08d3af782 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -348,6 +348,10 @@ impl U32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 14625600c..5120e918a 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -49,3 +49,4 @@ mod sequence_construct; mod shrink; mod sequence_empty; mod reduce_mean; +mod sequence_insert; diff --git a/src/operators/tensor/math/sequence_insert.cairo b/src/operators/tensor/math/sequence_insert.cairo new file mode 100644 index 000000000..df6682f30 --- /dev/null +++ b/src/operators/tensor/math/sequence_insert.cairo @@ -0,0 +1,10 @@ +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::numbers::i32; + + +/// Cf: TensorTrait::sequence_insert docstring +fn sequence_insert>(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + self +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5270a5048..bb8fa0170 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -719,3 +719,8 @@ mod reduce_mean_u32_1D; mod reduce_mean_u32_2D_default; mod reduce_mean_u32_2D_keepdims; mod reduce_mean_u32_2D_axis_1; +mod sequence_insert_fp16x16; +mod sequence_insert_fp8x23; +mod sequence_insert_i32; +mod sequence_insert_i8; +mod sequence_insert_u32; diff --git a/tests/nodes/sequence_insert_fp16x16.cairo b/tests/nodes/sequence_insert_fp16x16.cairo new file mode 100644 index 000000000..2f5e11e93 --- /dev/null +++ b/tests/nodes/sequence_insert_fp16x16.cairo @@ -0,0 +1,26 @@ +mod input_0; +mod input_1; +mod input_2; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_insert_fp16x16() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.sequence_insert(@input_1,@input_2); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_insert_fp16x16/input_0.cairo b/tests/nodes/sequence_insert_fp16x16/input_0.cairo new file mode 100644 index 000000000..1b815e972 --- /dev/null +++ b/tests/nodes/sequence_insert_fp16x16/input_0.cairo @@ -0,0 +1,52 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_fp16x16/input_1.cairo b/tests/nodes/sequence_insert_fp16x16/input_1.cairo new file mode 100644 index 000000000..002eea182 --- /dev/null +++ b/tests/nodes/sequence_insert_fp16x16/input_1.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_fp16x16/input_2.cairo b/tests/nodes/sequence_insert_fp16x16/input_2.cairo new file mode 100644 index 000000000..b52094dc8 --- /dev/null +++ b/tests/nodes/sequence_insert_fp16x16/input_2.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_fp16x16/output_0.cairo b/tests/nodes/sequence_insert_fp16x16/output_0.cairo new file mode 100644 index 000000000..9c738ca10 --- /dev/null +++ b/tests/nodes/sequence_insert_fp16x16/output_0.cairo @@ -0,0 +1,66 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_fp8x23.cairo b/tests/nodes/sequence_insert_fp8x23.cairo new file mode 100644 index 000000000..bcd54ab3e --- /dev/null +++ b/tests/nodes/sequence_insert_fp8x23.cairo @@ -0,0 +1,26 @@ +mod input_0; +mod input_1; +mod input_2; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_insert_fp8x23() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.sequence_insert(@input_1,@input_2); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_insert_fp8x23/input_0.cairo b/tests/nodes/sequence_insert_fp8x23/input_0.cairo new file mode 100644 index 000000000..93a63e3f6 --- /dev/null +++ b/tests/nodes/sequence_insert_fp8x23/input_0.cairo @@ -0,0 +1,52 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_fp8x23/input_1.cairo b/tests/nodes/sequence_insert_fp8x23/input_1.cairo new file mode 100644 index 000000000..5f0641594 --- /dev/null +++ b/tests/nodes/sequence_insert_fp8x23/input_1.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_fp8x23/input_2.cairo b/tests/nodes/sequence_insert_fp8x23/input_2.cairo new file mode 100644 index 000000000..14092dfde --- /dev/null +++ b/tests/nodes/sequence_insert_fp8x23/input_2.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_fp8x23/output_0.cairo b/tests/nodes/sequence_insert_fp8x23/output_0.cairo new file mode 100644 index 000000000..6df1190b7 --- /dev/null +++ b/tests/nodes/sequence_insert_fp8x23/output_0.cairo @@ -0,0 +1,66 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_i32.cairo b/tests/nodes/sequence_insert_i32.cairo new file mode 100644 index 000000000..123f8ee72 --- /dev/null +++ b/tests/nodes/sequence_insert_i32.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod input_2; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_insert_i32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.sequence_insert(@input_1,@input_2); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_insert_i32/input_0.cairo b/tests/nodes/sequence_insert_i32/input_0.cairo new file mode 100644 index 000000000..d3bb45364 --- /dev/null +++ b/tests/nodes/sequence_insert_i32/input_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_i32/input_1.cairo b/tests/nodes/sequence_insert_i32/input_1.cairo new file mode 100644 index 000000000..6acea527d --- /dev/null +++ b/tests/nodes/sequence_insert_i32/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: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_i32/input_2.cairo b/tests/nodes/sequence_insert_i32/input_2.cairo new file mode 100644 index 000000000..b52094dc8 --- /dev/null +++ b/tests/nodes/sequence_insert_i32/input_2.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_i32/output_0.cairo b/tests/nodes/sequence_insert_i32/output_0.cairo new file mode 100644 index 000000000..aa2a62558 --- /dev/null +++ b/tests/nodes/sequence_insert_i32/output_0.cairo @@ -0,0 +1,50 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_i8.cairo b/tests/nodes/sequence_insert_i8.cairo new file mode 100644 index 000000000..edf7027d1 --- /dev/null +++ b/tests/nodes/sequence_insert_i8.cairo @@ -0,0 +1,26 @@ +mod input_0; +mod input_1; +mod input_2; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I8Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_insert_i8() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.sequence_insert(@input_1,@input_2); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_insert_i8/input_0.cairo b/tests/nodes/sequence_insert_i8/input_0.cairo new file mode 100644 index 000000000..88a8670c5 --- /dev/null +++ b/tests/nodes/sequence_insert_i8/input_0.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_i8/input_1.cairo b/tests/nodes/sequence_insert_i8/input_1.cairo new file mode 100644 index 000000000..1b48f29bb --- /dev/null +++ b/tests/nodes/sequence_insert_i8/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(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_i8/input_2.cairo b/tests/nodes/sequence_insert_i8/input_2.cairo new file mode 100644 index 000000000..14092dfde --- /dev/null +++ b/tests/nodes/sequence_insert_i8/input_2.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_i8/output_0.cairo b/tests/nodes/sequence_insert_i8/output_0.cairo new file mode 100644 index 000000000..62dd7ff26 --- /dev/null +++ b/tests/nodes/sequence_insert_i8/output_0.cairo @@ -0,0 +1,50 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_u32.cairo b/tests/nodes/sequence_insert_u32.cairo new file mode 100644 index 000000000..2f0b4b639 --- /dev/null +++ b/tests/nodes/sequence_insert_u32.cairo @@ -0,0 +1,26 @@ +mod input_0; +mod input_1; +mod input_2; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_insert_u32() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let input_2 = input_2::input_2(); + let z = output_0::output_0(); + + let y = input_0.sequence_insert(@input_1,@input_2); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_insert_u32/input_0.cairo b/tests/nodes/sequence_insert_u32/input_0.cairo new file mode 100644 index 000000000..3dd2ac9af --- /dev/null +++ b/tests/nodes/sequence_insert_u32/input_0.cairo @@ -0,0 +1,45 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(5); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(3); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_insert_u32/input_1.cairo b/tests/nodes/sequence_insert_u32/input_1.cairo new file mode 100644 index 000000000..c83ba864e --- /dev/null +++ b/tests/nodes/sequence_insert_u32/input_1.cairo @@ -0,0 +1,16 @@ +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(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(1); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_u32/input_2.cairo b/tests/nodes/sequence_insert_u32/input_2.cairo new file mode 100644 index 000000000..b52094dc8 --- /dev/null +++ b/tests/nodes/sequence_insert_u32/input_2.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_2() -> Tensor { + let mut shape = ArrayTrait::::new(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_insert_u32/output_0.cairo b/tests/nodes/sequence_insert_u32/output_0.cairo new file mode 100644 index 000000000..148d80c2b --- /dev/null +++ b/tests/nodes/sequence_insert_u32/output_0.cairo @@ -0,0 +1,57 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(5); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(1); + data.append(0); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(3); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From 9cced2144af2580ca28aa112d1e3564734802b6a Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Thu, 16 Nov 2023 15:51:40 +0100 Subject: [PATCH 084/160] Make tests pass --- src/operators/tensor/core.cairo | 5 +- .../tensor/implementations/tensor_bool.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 2 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 2 +- .../tensor/math/sequence_insert.cairo | 57 +++++++++++++++++-- tests/nodes/sequence_insert_fp16x16.cairo | 2 +- tests/nodes/sequence_insert_fp8x23.cairo | 2 +- tests/nodes/sequence_insert_i32.cairo | 2 +- tests/nodes/sequence_insert_i8.cairo | 2 +- tests/nodes/sequence_insert_u32.cairo | 2 +- 17 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index fa6c25dd1..82d0e091e 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -96,15 +96,12 @@ impl TensorSerde, impl TDrop: Drop> of Serde>>>>>> a3286e87 (Add tests) trait TensorTrait { /// # tensor.new /// @@ -3919,7 +3916,7 @@ trait TensorTrait { noop_with_empty_axes: Option ) -> Tensor; /// TODO - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array>; + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 513dbdd2d..86b31fd2b 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -350,7 +350,7 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index ae4c8c8b7..27d3b4014 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -381,7 +381,7 @@ impl FP16x16Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c215a47a1..b74668865 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -371,7 +371,7 @@ impl FP16x16WTensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 37071210b..22ff326aa 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -382,7 +382,7 @@ impl FP32x32Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index dc9635719..bd912370f 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -382,7 +382,7 @@ impl FP64x64Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 9080fc6be..5a303d1d2 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -379,7 +379,7 @@ impl FP8x23Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 4666eac53..10a3c421d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -360,7 +360,7 @@ impl FP8x23WTensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index a057a0dec..787905f11 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -379,7 +379,7 @@ impl I32Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index bbfb9e722..1e212ea1a 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -378,7 +378,7 @@ impl I8Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 08d3af782..50de0eb46 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -349,7 +349,7 @@ impl U32Tensor of TensorTrait { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } - fn sequence_insert(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/math/sequence_insert.cairo b/src/operators/tensor/math/sequence_insert.cairo index df6682f30..0ece08928 100644 --- a/src/operators/tensor/math/sequence_insert.cairo +++ b/src/operators/tensor/math/sequence_insert.cairo @@ -1,10 +1,57 @@ use array::{ArrayTrait, SpanTrait}; +use option::OptionTrait; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::numbers::i32; - +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::NumberTrait; +use orion::numbers::signed_integer::i32::i32; /// Cf: TensorTrait::sequence_insert docstring -fn sequence_insert>(self: Array>, tensor: @Tensor, position: @Tensor) -> Array> { - self +fn sequence_insert< + T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop +>( + self: Array>, tensor: @Tensor, position: Option> +) -> Array> { + let position: Tensor = match position { + Option::Some(p) => p, + Option::None(_) => { + let mut shape = ArrayTrait::::new(); + let mut data = ArrayTrait::::new(); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::::new(shape.span(), data.span()) + }, + }; + + assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); + + let position_value_i32: i32 = *position.data.at(0); + let is_negative: bool = position_value_i32.sign; + let mut position_value: u32 = position_value_i32.mag; + + assert((is_negative == false && position_value <= self.len() - 1) || (is_negative == true && position_value <= self.len()), 'Position out of bounds'); + + if is_negative == true { + position_value = self.len() - position_value; + } + + let mut new_sequence = ArrayTrait::>::new(); + let mut inserted = false; + let mut self_copy = self; + loop { + match self_copy.pop_front() { + Option::Some(t) => { + if position_value == 0 && inserted == false { + new_sequence.append(*tensor); + inserted = true; + } + new_sequence.append(t); + if inserted == false { + position_value -= 1; + } + }, + Option::None(_) => { break; }, + }; + }; + + return new_sequence; } diff --git a/tests/nodes/sequence_insert_fp16x16.cairo b/tests/nodes/sequence_insert_fp16x16.cairo index 2f5e11e93..04a6b29cf 100644 --- a/tests/nodes/sequence_insert_fp16x16.cairo +++ b/tests/nodes/sequence_insert_fp16x16.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_fp16x16() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,@input_2); + let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_fp8x23.cairo b/tests/nodes/sequence_insert_fp8x23.cairo index bcd54ab3e..e531a5cbb 100644 --- a/tests/nodes/sequence_insert_fp8x23.cairo +++ b/tests/nodes/sequence_insert_fp8x23.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_fp8x23() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,@input_2); + let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_i32.cairo b/tests/nodes/sequence_insert_i32.cairo index 123f8ee72..1b61242c7 100644 --- a/tests/nodes/sequence_insert_i32.cairo +++ b/tests/nodes/sequence_insert_i32.cairo @@ -18,7 +18,7 @@ fn test_sequence_insert_i32() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,@input_2); + let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_i8.cairo b/tests/nodes/sequence_insert_i8.cairo index edf7027d1..7d0b59401 100644 --- a/tests/nodes/sequence_insert_i8.cairo +++ b/tests/nodes/sequence_insert_i8.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_i8() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,@input_2); + let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_u32.cairo b/tests/nodes/sequence_insert_u32.cairo index 2f0b4b639..9c9a79717 100644 --- a/tests/nodes/sequence_insert_u32.cairo +++ b/tests/nodes/sequence_insert_u32.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_u32() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,@input_2); + let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); assert_seq_eq(y, z); } From df9c5d944614403fd282041302ed959a56820e12 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Thu, 16 Nov 2023 19:23:12 +0100 Subject: [PATCH 085/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + src/operators/tensor/core.cairo | 57 ++++++++++++++++++++++- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index c33854677..ceef9076f 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -107,6 +107,7 @@ * [tensor.shrink](framework/operators/tensor/tensor.shrink.md) * [tensor.sequence\_empty](framework/operators/tensor/tensor.sequence\_empty.md) * [tensor.reduce_mean](framework/operators/tensor/tensor.reduce\_mean.md) + * [tensor.sequence\_insert](framework/operators/tensor/tensor.sequence\_insert.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 7cd555358..0c48949d5 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -87,5 +87,6 @@ You can see below the list of current supported ONNX Operators: | [Shrink](operators/tensor/tensor.shrink.md) | :white\_check\_mark: | | [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceInsert](operators/tensor/tensor.sequence\_insert.md) | :white\_check\_mark: | -Current Operators support: **81/156 (52%)** +Current Operators support: **82/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index dbb70e15b..231f4fc61 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -105,6 +105,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | | [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | +| [`tensor.sequence_insert`](tensor.sequence\_insert.md) | Insert a tensor into a sequence. | ## Arithmetic Operations diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 82d0e091e..1a61d989d 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3915,7 +3915,62 @@ trait TensorTrait { keepdims: Option, noop_with_empty_axes: Option ) -> Tensor; - /// TODO + /// # tensor.sequence_insert + /// + /// ```rust + /// fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; + /// ``` + /// + /// Returns a tensor sequence that inserts 'tensor' into 'self' at 'position'. + /// + /// ## Args + /// + /// * `self`(`Array>`) - input sequence. + /// * `tensor` (`@Tensor`) - the tensor to insert. + /// * `position` (`@Tensor`) - the index for insertion (default: -1). + /// + /// ## Returns + /// + /// Tensor sequence containing 'tensor' inserted into 'self' at 'position'. + /// + /// ## Examples + /// + /// Let's insert the tensor [2] into the sequence [[1], [3]] at position 1. + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + /// + /// fn sequence_insert_example() -> Array> { + /// // Prepare sequence + /// let mut sequence = ArrayTrait::new(); + /// let mut shape = ArrayTrait::::new(); + /// shape.append(1); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(1); + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// let mut data = ArrayTrait::new(); + /// data.append(3); + /// + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// + /// // Prepare input tensor + /// let mut data = ArrayTrait::new(); + /// data.append(2); + /// let tensor = TensorTrait::new(shape.span(), data.span()); + /// + /// // Prepare position + /// let mut shape = ArrayTrait::::new(); + /// let mut data = ArrayTrait::::new(); + /// data.append(i32 { mag: 1, sign: false }); + /// let position = TensorTrait::::new(shape.span(), data.span()) + /// + /// let sequence = self.sequence_insert(tensor, Option::Some(position)); + /// + /// return sequence; + /// } + /// + /// >>> [[1], [2], [3]] + /// ``` + /// fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; } From 4c647118bc6b6bb8bea50fa43ffaa14ed7c56de1 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Fri, 17 Nov 2023 10:52:23 +0100 Subject: [PATCH 086/160] Add tests and fix bug --- nodegen/node/sequence_erase.py | 303 ++++++++++++++++++ .../tensor/math/sequence_erase.cairo | 7 +- tests/nodes.cairo | 15 + .../nodes/sequence_erase_fp16x16_empty.cairo | 20 ++ .../input_0.cairo | 95 ++++++ .../output_0.cairo | 78 +++++ .../sequence_erase_fp16x16_negative.cairo | 24 ++ .../input_0.cairo | 65 ++++ .../input_1.cairo | 12 + .../output_0.cairo | 54 ++++ .../sequence_erase_fp16x16_positive.cairo | 24 ++ .../input_0.cairo | 95 ++++++ .../input_1.cairo | 12 + .../output_0.cairo | 78 +++++ tests/nodes/sequence_erase_fp8x23_empty.cairo | 20 ++ .../sequence_erase_fp8x23_empty/input_0.cairo | 95 ++++++ .../output_0.cairo | 78 +++++ .../sequence_erase_fp8x23_negative.cairo | 24 ++ .../input_0.cairo | 95 ++++++ .../input_1.cairo | 12 + .../output_0.cairo | 78 +++++ .../sequence_erase_fp8x23_positive.cairo | 24 ++ .../input_0.cairo | 70 ++++ .../input_1.cairo | 12 + .../output_0.cairo | 58 ++++ tests/nodes/sequence_erase_i32_empty.cairo | 20 ++ .../sequence_erase_i32_empty/input_0.cairo | 80 +++++ .../sequence_erase_i32_empty/output_0.cairo | 66 ++++ tests/nodes/sequence_erase_i32_negative.cairo | 22 ++ .../sequence_erase_i32_negative/input_0.cairo | 55 ++++ .../sequence_erase_i32_negative/input_1.cairo | 12 + .../output_0.cairo | 46 +++ tests/nodes/sequence_erase_i32_positive.cairo | 22 ++ .../sequence_erase_i32_positive/input_0.cairo | 70 ++++ .../sequence_erase_i32_positive/input_1.cairo | 12 + .../output_0.cairo | 58 ++++ tests/nodes/sequence_erase_i8_empty.cairo | 20 ++ .../sequence_erase_i8_empty/input_0.cairo | 60 ++++ .../sequence_erase_i8_empty/output_0.cairo | 50 +++ tests/nodes/sequence_erase_i8_negative.cairo | 24 ++ .../sequence_erase_i8_negative/input_0.cairo | 95 ++++++ .../sequence_erase_i8_negative/input_1.cairo | 12 + .../sequence_erase_i8_negative/output_0.cairo | 78 +++++ tests/nodes/sequence_erase_i8_positive.cairo | 24 ++ .../sequence_erase_i8_positive/input_0.cairo | 55 ++++ .../sequence_erase_i8_positive/input_1.cairo | 12 + .../sequence_erase_i8_positive/output_0.cairo | 46 +++ tests/nodes/sequence_erase_u32_empty.cairo | 20 ++ .../sequence_erase_u32_empty/input_0.cairo | 69 ++++ .../sequence_erase_u32_empty/output_0.cairo | 57 ++++ tests/nodes/sequence_erase_u32_negative.cairo | 24 ++ .../sequence_erase_u32_negative/input_0.cairo | 69 ++++ .../sequence_erase_u32_negative/input_1.cairo | 12 + .../output_0.cairo | 57 ++++ tests/nodes/sequence_erase_u32_positive.cairo | 24 ++ .../sequence_erase_u32_positive/input_0.cairo | 54 ++++ .../sequence_erase_u32_positive/input_1.cairo | 12 + .../output_0.cairo | 45 +++ 58 files changed, 2826 insertions(+), 4 deletions(-) create mode 100644 nodegen/node/sequence_erase.py create mode 100644 tests/nodes/sequence_erase_fp16x16_empty.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_empty/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_empty/output_0.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_negative.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_negative/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_negative/input_1.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_negative/output_0.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_positive.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_positive/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_positive/input_1.cairo create mode 100644 tests/nodes/sequence_erase_fp16x16_positive/output_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_empty.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_empty/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_empty/output_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_negative.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_negative/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_negative/input_1.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_negative/output_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_positive.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_positive/input_0.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_positive/input_1.cairo create mode 100644 tests/nodes/sequence_erase_fp8x23_positive/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_empty.cairo create mode 100644 tests/nodes/sequence_erase_i32_empty/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_empty/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_negative.cairo create mode 100644 tests/nodes/sequence_erase_i32_negative/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_negative/input_1.cairo create mode 100644 tests/nodes/sequence_erase_i32_negative/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_positive.cairo create mode 100644 tests/nodes/sequence_erase_i32_positive/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i32_positive/input_1.cairo create mode 100644 tests/nodes/sequence_erase_i32_positive/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_empty.cairo create mode 100644 tests/nodes/sequence_erase_i8_empty/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_empty/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_negative.cairo create mode 100644 tests/nodes/sequence_erase_i8_negative/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_negative/input_1.cairo create mode 100644 tests/nodes/sequence_erase_i8_negative/output_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_positive.cairo create mode 100644 tests/nodes/sequence_erase_i8_positive/input_0.cairo create mode 100644 tests/nodes/sequence_erase_i8_positive/input_1.cairo create mode 100644 tests/nodes/sequence_erase_i8_positive/output_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_empty.cairo create mode 100644 tests/nodes/sequence_erase_u32_empty/input_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_empty/output_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_negative.cairo create mode 100644 tests/nodes/sequence_erase_u32_negative/input_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_negative/input_1.cairo create mode 100644 tests/nodes/sequence_erase_u32_negative/output_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_positive.cairo create mode 100644 tests/nodes/sequence_erase_u32_positive/input_0.cairo create mode 100644 tests/nodes/sequence_erase_u32_positive/input_1.cairo create mode 100644 tests/nodes/sequence_erase_u32_positive/output_0.cairo diff --git a/nodegen/node/sequence_erase.py b/nodegen/node/sequence_erase.py new file mode 100644 index 000000000..8f8f07c46 --- /dev/null +++ b/nodegen/node/sequence_erase.py @@ -0,0 +1,303 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +scalar = lambda x: Tensor(Dtype.I32, (), np.array([x]).astype(np.int32).flatten()) + + +class Sequence_erase(RunAll): + + @staticmethod + def sequence_erase_u32(): + def positive_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(2) + + output_sequence = sequence.copy() + output_sequence.pop(2) + + name = "sequence_erase_u32_positive" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def negative_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(-2) + + output_sequence = sequence.copy() + output_sequence.pop(-2) + + name = "sequence_erase_u32_negative" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def empty_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + + sequence.append(tensor) + + output_sequence = sequence.copy() + output_sequence.pop(-1) + + name = "sequence_erase_u32_empty" + make_test([sequence], output_sequence, "TensorTrait::sequence_erase(input_0, Option::None(()))", name) + + positive_position() + negative_position() + empty_position() + + + @staticmethod + def sequence_erase_i32(): + def positive_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(2) + + output_sequence = sequence.copy() + output_sequence.pop(2) + + name = "sequence_erase_i32_positive" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def negative_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(-2) + + output_sequence = sequence.copy() + output_sequence.pop(-2) + + name = "sequence_erase_i32_negative" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def empty_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + + sequence.append(tensor) + + output_sequence = sequence.copy() + output_sequence.pop(-1) + + name = "sequence_erase_i32_empty" + make_test([sequence], output_sequence, "TensorTrait::sequence_erase(input_0, Option::None(()))", name) + + positive_position() + negative_position() + empty_position() + + + @staticmethod + def sequence_erase_i8(): + def positive_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(2) + + output_sequence = sequence.copy() + output_sequence.pop(2) + + name = "sequence_erase_i8_positive" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def negative_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + position = scalar(-2) + + output_sequence = sequence.copy() + output_sequence.pop(-2) + + name = "sequence_erase_i8_negative" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def empty_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + + sequence.append(tensor) + + output_sequence = sequence.copy() + output_sequence.pop(-1) + + name = "sequence_erase_i8_empty" + make_test([sequence], output_sequence, "TensorTrait::sequence_erase(input_0, Option::None(()))", name) + + positive_position() + negative_position() + empty_position() + + + @staticmethod + def sequence_erase_fp8x23(): + def positive_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + position = scalar(2) + + output_sequence = sequence.copy() + output_sequence.pop(2) + + name = "sequence_erase_fp8x23_positive" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def negative_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + position = scalar(-2) + + output_sequence = sequence.copy() + output_sequence.pop(-2) + + name = "sequence_erase_fp8x23_negative" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def empty_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + + sequence.append(tensor) + + output_sequence = sequence.copy() + output_sequence.pop(-1) + + name = "sequence_erase_fp8x23_empty" + make_test([sequence], output_sequence, "TensorTrait::sequence_erase(input_0, Option::None(()))", name) + + positive_position() + negative_position() + empty_position() + + + @staticmethod + def sequence_erase_fp16x16(): + def positive_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + position = scalar(2) + + output_sequence = sequence.copy() + output_sequence.pop(2) + + name = "sequence_erase_fp16x16_positive" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def negative_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + position = scalar(-2) + + output_sequence = sequence.copy() + output_sequence.pop(-2) + + name = "sequence_erase_fp16x16_negative" + make_test([sequence, position], output_sequence, "TensorTrait::sequence_erase(input_0, Option::Some(input_1))", name) + + def empty_position(): + sequence = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + + sequence.append(tensor) + + output_sequence = sequence.copy() + output_sequence.pop(-1) + + name = "sequence_erase_fp16x16_empty" + make_test([sequence], output_sequence, "TensorTrait::sequence_erase(input_0, Option::None(()))", name) + + positive_position() + negative_position() + empty_position() \ No newline at end of file diff --git a/src/operators/tensor/math/sequence_erase.cairo b/src/operators/tensor/math/sequence_erase.cairo index cb8be22ed..252ce777f 100644 --- a/src/operators/tensor/math/sequence_erase.cairo +++ b/src/operators/tensor/math/sequence_erase.cairo @@ -14,9 +14,7 @@ fn sequence_erase< ) -> Array> { let position: Tensor = match position { - Option::Some(value) => { - position.unwrap() - }, + Option::Some(p) => p, Option::None(_) => { let mut shape = ArrayTrait::::new(); let mut data = ArrayTrait::::new(); @@ -38,12 +36,13 @@ fn sequence_erase< } let mut input_sequence_copy = sequence; - let mut output_sequence = ArrayTrait::new(); + let mut output_sequence = ArrayTrait::>::new(); let mut tensor_counter: usize = 0; loop { match input_sequence_copy.pop_front() { Option::Some(input_sequence_value) => { if tensor_counter == position_value { + tensor_counter += 1; continue; } output_sequence.append(input_sequence_value); diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5270a5048..35e5e7ad5 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -719,3 +719,18 @@ mod reduce_mean_u32_1D; mod reduce_mean_u32_2D_default; mod reduce_mean_u32_2D_keepdims; mod reduce_mean_u32_2D_axis_1; +mod sequence_erase_u32_positive; +mod sequence_erase_u32_negative; +mod sequence_erase_u32_empty; +mod sequence_erase_fp16x16_positive; +mod sequence_erase_fp16x16_negative; +mod sequence_erase_fp16x16_empty; +mod sequence_erase_fp8x23_positive; +mod sequence_erase_fp8x23_negative; +mod sequence_erase_fp8x23_empty; +mod sequence_erase_i32_positive; +mod sequence_erase_i32_negative; +mod sequence_erase_i32_empty; +mod sequence_erase_i8_positive; +mod sequence_erase_i8_negative; +mod sequence_erase_i8_empty; diff --git a/tests/nodes/sequence_erase_fp16x16_empty.cairo b/tests/nodes/sequence_erase_fp16x16_empty.cairo new file mode 100644 index 000000000..2097aa2d8 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_empty.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp16x16_empty() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::None(())); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp16x16_empty/input_0.cairo b/tests/nodes/sequence_erase_fp16x16_empty/input_0.cairo new file mode 100644 index 000000000..f2f4b9dc9 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_empty/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp16x16_empty/output_0.cairo b/tests/nodes/sequence_erase_fp16x16_empty/output_0.cairo new file mode 100644 index 000000000..c5a287783 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_empty/output_0.cairo @@ -0,0 +1,78 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp16x16_negative.cairo b/tests/nodes/sequence_erase_fp16x16_negative.cairo new file mode 100644 index 000000000..65c0dd469 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp16x16_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp16x16_negative/input_0.cairo b/tests/nodes/sequence_erase_fp16x16_negative/input_0.cairo new file mode 100644 index 000000000..8a43627e8 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_negative/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp16x16_negative/input_1.cairo b/tests/nodes/sequence_erase_fp16x16_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_fp16x16_negative/output_0.cairo b/tests/nodes/sequence_erase_fp16x16_negative/output_0.cairo new file mode 100644 index 000000000..349ea4750 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_negative/output_0.cairo @@ -0,0 +1,54 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp16x16_positive.cairo b/tests/nodes/sequence_erase_fp16x16_positive.cairo new file mode 100644 index 000000000..107a12a0d --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp16x16_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp16x16_positive/input_0.cairo b/tests/nodes/sequence_erase_fp16x16_positive/input_0.cairo new file mode 100644 index 000000000..a89f27eed --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_positive/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp16x16_positive/input_1.cairo b/tests/nodes/sequence_erase_fp16x16_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_fp16x16_positive/output_0.cairo b/tests/nodes/sequence_erase_fp16x16_positive/output_0.cairo new file mode 100644 index 000000000..f0de2f6db --- /dev/null +++ b/tests/nodes/sequence_erase_fp16x16_positive/output_0.cairo @@ -0,0 +1,78 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_empty.cairo b/tests/nodes/sequence_erase_fp8x23_empty.cairo new file mode 100644 index 000000000..5c9e2703f --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_empty.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp8x23_empty() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::None(())); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp8x23_empty/input_0.cairo b/tests/nodes/sequence_erase_fp8x23_empty/input_0.cairo new file mode 100644 index 000000000..7433c08db --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_empty/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_empty/output_0.cairo b/tests/nodes/sequence_erase_fp8x23_empty/output_0.cairo new file mode 100644 index 000000000..af939bbd4 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_empty/output_0.cairo @@ -0,0 +1,78 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_negative.cairo b/tests/nodes/sequence_erase_fp8x23_negative.cairo new file mode 100644 index 000000000..d338f8939 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp8x23_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp8x23_negative/input_0.cairo b/tests/nodes/sequence_erase_fp8x23_negative/input_0.cairo new file mode 100644 index 000000000..9216c3962 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_negative/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_negative/input_1.cairo b/tests/nodes/sequence_erase_fp8x23_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_fp8x23_negative/output_0.cairo b/tests/nodes/sequence_erase_fp8x23_negative/output_0.cairo new file mode 100644 index 000000000..864ee6320 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_negative/output_0.cairo @@ -0,0 +1,78 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_positive.cairo b/tests/nodes/sequence_erase_fp8x23_positive.cairo new file mode 100644 index 000000000..d9ab5faeb --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_fp8x23_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_fp8x23_positive/input_0.cairo b/tests/nodes/sequence_erase_fp8x23_positive/input_0.cairo new file mode 100644 index 000000000..2abf6ebf2 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_positive/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_fp8x23_positive/input_1.cairo b/tests/nodes/sequence_erase_fp8x23_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_fp8x23_positive/output_0.cairo b/tests/nodes/sequence_erase_fp8x23_positive/output_0.cairo new file mode 100644 index 000000000..425c0435e --- /dev/null +++ b/tests/nodes/sequence_erase_fp8x23_positive/output_0.cairo @@ -0,0 +1,58 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_empty.cairo b/tests/nodes/sequence_erase_i32_empty.cairo new file mode 100644 index 000000000..de47e1521 --- /dev/null +++ b/tests/nodes/sequence_erase_i32_empty.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i32_empty() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::None(())); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i32_empty/input_0.cairo b/tests/nodes/sequence_erase_i32_empty/input_0.cairo new file mode 100644 index 000000000..621522696 --- /dev/null +++ b/tests/nodes/sequence_erase_i32_empty/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_empty/output_0.cairo b/tests/nodes/sequence_erase_i32_empty/output_0.cairo new file mode 100644 index 000000000..7834c10cd --- /dev/null +++ b/tests/nodes/sequence_erase_i32_empty/output_0.cairo @@ -0,0 +1,66 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_negative.cairo b/tests/nodes/sequence_erase_i32_negative.cairo new file mode 100644 index 000000000..605e4011c --- /dev/null +++ b/tests/nodes/sequence_erase_i32_negative.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i32_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i32_negative/input_0.cairo b/tests/nodes/sequence_erase_i32_negative/input_0.cairo new file mode 100644 index 000000000..44f78a59d --- /dev/null +++ b/tests/nodes/sequence_erase_i32_negative/input_0.cairo @@ -0,0 +1,55 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_negative/input_1.cairo b/tests/nodes/sequence_erase_i32_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_erase_i32_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_i32_negative/output_0.cairo b/tests/nodes/sequence_erase_i32_negative/output_0.cairo new file mode 100644 index 000000000..2c820804d --- /dev/null +++ b/tests/nodes/sequence_erase_i32_negative/output_0.cairo @@ -0,0 +1,46 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_positive.cairo b/tests/nodes/sequence_erase_i32_positive.cairo new file mode 100644 index 000000000..42c0482aa --- /dev/null +++ b/tests/nodes/sequence_erase_i32_positive.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i32_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i32_positive/input_0.cairo b/tests/nodes/sequence_erase_i32_positive/input_0.cairo new file mode 100644 index 000000000..e2780346b --- /dev/null +++ b/tests/nodes/sequence_erase_i32_positive/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i32_positive/input_1.cairo b/tests/nodes/sequence_erase_i32_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_erase_i32_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_i32_positive/output_0.cairo b/tests/nodes/sequence_erase_i32_positive/output_0.cairo new file mode 100644 index 000000000..32c38ada4 --- /dev/null +++ b/tests/nodes/sequence_erase_i32_positive/output_0.cairo @@ -0,0 +1,58 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 5, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_empty.cairo b/tests/nodes/sequence_erase_i8_empty.cairo new file mode 100644 index 000000000..d47106e61 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_empty.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i8_empty() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::None(())); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i8_empty/input_0.cairo b/tests/nodes/sequence_erase_i8_empty/input_0.cairo new file mode 100644 index 000000000..607b8988c --- /dev/null +++ b/tests/nodes/sequence_erase_i8_empty/input_0.cairo @@ -0,0 +1,60 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_empty/output_0.cairo b/tests/nodes/sequence_erase_i8_empty/output_0.cairo new file mode 100644 index 000000000..628243876 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_empty/output_0.cairo @@ -0,0 +1,50 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_negative.cairo b/tests/nodes/sequence_erase_i8_negative.cairo new file mode 100644 index 000000000..0108f1974 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i8_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i8_negative/input_0.cairo b/tests/nodes/sequence_erase_i8_negative/input_0.cairo new file mode 100644 index 000000000..871a3ebc1 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_negative/input_0.cairo @@ -0,0 +1,95 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + 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: 4, 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: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_negative/input_1.cairo b/tests/nodes/sequence_erase_i8_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_i8_negative/output_0.cairo b/tests/nodes/sequence_erase_i8_negative/output_0.cairo new file mode 100644 index 000000000..93faab4fb --- /dev/null +++ b/tests/nodes/sequence_erase_i8_negative/output_0.cairo @@ -0,0 +1,78 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + 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: 4, 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: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_positive.cairo b/tests/nodes/sequence_erase_i8_positive.cairo new file mode 100644 index 000000000..563dd88dc --- /dev/null +++ b/tests/nodes/sequence_erase_i8_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_i8_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_i8_positive/input_0.cairo b/tests/nodes/sequence_erase_i8_positive/input_0.cairo new file mode 100644 index 000000000..5b133afa4 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_positive/input_0.cairo @@ -0,0 +1,55 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_i8_positive/input_1.cairo b/tests/nodes/sequence_erase_i8_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_erase_i8_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_i8_positive/output_0.cairo b/tests/nodes/sequence_erase_i8_positive/output_0.cairo new file mode 100644 index 000000000..e7f4d51bd --- /dev/null +++ b/tests/nodes/sequence_erase_i8_positive/output_0.cairo @@ -0,0 +1,46 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_empty.cairo b/tests/nodes/sequence_erase_u32_empty.cairo new file mode 100644 index 000000000..97e6102ad --- /dev/null +++ b/tests/nodes/sequence_erase_u32_empty.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_u32_empty() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::None(())); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_u32_empty/input_0.cairo b/tests/nodes/sequence_erase_u32_empty/input_0.cairo new file mode 100644 index 000000000..46581b7cc --- /dev/null +++ b/tests/nodes/sequence_erase_u32_empty/input_0.cairo @@ -0,0 +1,69 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(2); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(0); + data.append(3); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(4); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(5); + data.append(4); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(2); + data.append(3); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_empty/output_0.cairo b/tests/nodes/sequence_erase_u32_empty/output_0.cairo new file mode 100644 index 000000000..39cd31408 --- /dev/null +++ b/tests/nodes/sequence_erase_u32_empty/output_0.cairo @@ -0,0 +1,57 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(2); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(0); + data.append(3); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(4); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(5); + data.append(4); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_negative.cairo b/tests/nodes/sequence_erase_u32_negative.cairo new file mode 100644 index 000000000..fb216846d --- /dev/null +++ b/tests/nodes/sequence_erase_u32_negative.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_u32_negative() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_u32_negative/input_0.cairo b/tests/nodes/sequence_erase_u32_negative/input_0.cairo new file mode 100644 index 000000000..ed28ebc8c --- /dev/null +++ b/tests/nodes/sequence_erase_u32_negative/input_0.cairo @@ -0,0 +1,69 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(0); + data.append(2); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(5); + data.append(1); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(3); + data.append(1); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(0); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_negative/input_1.cairo b/tests/nodes/sequence_erase_u32_negative/input_1.cairo new file mode 100644 index 000000000..a74b0bb65 --- /dev/null +++ b/tests/nodes/sequence_erase_u32_negative/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_u32_negative/output_0.cairo b/tests/nodes/sequence_erase_u32_negative/output_0.cairo new file mode 100644 index 000000000..ff88162ca --- /dev/null +++ b/tests/nodes/sequence_erase_u32_negative/output_0.cairo @@ -0,0 +1,57 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(0); + data.append(2); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(5); + data.append(1); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(5); + data.append(0); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_positive.cairo b/tests/nodes/sequence_erase_u32_positive.cairo new file mode 100644 index 000000000..dd2cf149c --- /dev/null +++ b/tests/nodes/sequence_erase_u32_positive.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_sequence_erase_u32_positive() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = TensorTrait::sequence_erase(input_0, Option::Some(input_1)); + + assert_seq_eq(y, z); +} diff --git a/tests/nodes/sequence_erase_u32_positive/input_0.cairo b/tests/nodes/sequence_erase_u32_positive/input_0.cairo new file mode 100644 index 000000000..f8ae0f8a5 --- /dev/null +++ b/tests/nodes/sequence_erase_u32_positive/input_0.cairo @@ -0,0 +1,54 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/sequence_erase_u32_positive/input_1.cairo b/tests/nodes/sequence_erase_u32_positive/input_1.cairo new file mode 100644 index 000000000..11bf62c03 --- /dev/null +++ b/tests/nodes/sequence_erase_u32_positive/input_1.cairo @@ -0,0 +1,12 @@ +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(); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/sequence_erase_u32_positive/output_0.cairo b/tests/nodes/sequence_erase_u32_positive/output_0.cairo new file mode 100644 index 000000000..477a20f89 --- /dev/null +++ b/tests/nodes/sequence_erase_u32_positive/output_0.cairo @@ -0,0 +1,45 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(2); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} From c346836dae96535f242f44527891995c77ba925b Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 17 Nov 2023 11:33:22 +0100 Subject: [PATCH 087/160] Fix nodegen script --- nodegen/node/sequence_insert.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nodegen/node/sequence_insert.py b/nodegen/node/sequence_insert.py index ac0a2c79c..9cc2ceb82 100644 --- a/nodegen/node/sequence_insert.py +++ b/nodegen/node/sequence_insert.py @@ -30,7 +30,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_u32" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,Option::Some(input_2))", name) default() @@ -56,7 +56,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_i32" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,Option::Some(input_2))", name) default() @@ -82,7 +82,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_i8" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,Option::Some(input_2))", name) default() @@ -110,7 +110,7 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_fp8x23" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,Option::Some(input_2))", name) default() @@ -138,6 +138,6 @@ def default(): expected_sequence.insert(position, tensor) name = "sequence_insert_fp16x16" - make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,@input_2)", name) + make_test([sequence, tensor, scalar(position)], expected_sequence, "input_0.sequence_insert(@input_1,Option::Some(input_2))", name) default() From d14489ce9903ffcd9b9b7465822bf6490dd9330f Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Fri, 17 Nov 2023 12:05:42 +0100 Subject: [PATCH 088/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.sequence_erase.md | 47 ++++++++++++++++++ src/operators/tensor/core.cairo | 49 +++++++++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_erase.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index c33854677..904b51f7b 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -107,6 +107,7 @@ * [tensor.shrink](framework/operators/tensor/tensor.shrink.md) * [tensor.sequence\_empty](framework/operators/tensor/tensor.sequence\_empty.md) * [tensor.reduce_mean](framework/operators/tensor/tensor.reduce\_mean.md) + * [tensor.sequence\_erase](framework/operators/tensor/tensor.sequence\_erase.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 7cd555358..c405954a4 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -87,5 +87,6 @@ You can see below the list of current supported ONNX Operators: | [Shrink](operators/tensor/tensor.shrink.md) | :white\_check\_mark: | | [SequenceEmpty](operators/tensor/tensor.sequence\_empty.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [SequenceErase](operators/tensor/tensor.sequence\_erase.md) | :white\_check\_mark: | -Current Operators support: **81/156 (52%)** +Current Operators support: **82/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index dbb70e15b..7c5f80250 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -105,6 +105,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | | [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | +| [`tensor.sequence_erase`](tensor.sequence\_erase.md) | Outputs the tensor sequence with the erased tensor at the specified position. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_erase.md b/docs/framework/operators/tensor/tensor.sequence_erase.md new file mode 100644 index 000000000..4c5f94a39 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_erase.md @@ -0,0 +1,47 @@ +## tensor.sequence_erase + +```rust + fn sequence_erase(sequence: Array>, position: Option>) -> Array>; +``` + +Outputs the tensor sequence with the erased tensor at the specified position. + +## Args + +* `tensors`(`Array>`) - The tensor sequence. +* `position`(`Option>`) - The optional position tensor (by default erases the last tensor). + +## Panics + +* Panics if position is not a scalar +* Panics if position is out of bounds [-n, n - 1] + +## Returns + +The tensor sequence `Array>` with the erased tensor at the specified position. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn sequence_erase_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + let tensor3 = TensorTrait::new(shape: array![2, 2].span(), data: array![8, 9, 10, 11].span()); + + let mut sequence = ArrayTrait::new(); + sequence.append(tensor1); + sequence.append(tensor2); + sequence.append(tensor3); + + let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + + let result = TensorTrait::sequence_erase(sequence, position); + return result; +} +>>> [[0, 1, 2, 3], [8, 9, 10, 11]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 445654ec1..d8206cfea 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -101,6 +101,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3914,6 +3915,54 @@ trait TensorTrait { keepdims: Option, noop_with_empty_axes: Option ) -> Tensor; + /// ## tensor.sequence_erase + /// + /// ```rust + /// fn sequence_erase(sequence: Array>, position: Option>) -> Array>; + /// ``` + /// + /// Outputs the tensor sequence with the erased tensor at the specified position. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The tensor sequence. + /// * `position`(`Option>`) - The optional position tensor (by default erases the last tensor). + /// + /// ## Panics + /// + /// * Panics if position is not a scalar + /// * Panics if position is out of bounds [-n, n - 1] + /// + /// ## Returns + /// + /// The tensor sequence `Array>` with the erased tensor at the specified position. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn sequence_erase_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let tensor3 = TensorTrait::new(shape: array![2, 2].span(), data: array![8, 9, 10, 11].span()); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// sequence.append(tensor3); + /// + /// let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + /// + /// let result = TensorTrait::sequence_erase(sequence, position); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [8, 9, 10, 11]] + /// ``` + /// fn sequence_erase(sequence: Array>, position: Option>) -> Array>; } From 1f3306897ab69a97d6cc958f999724345582bb3d Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 17 Nov 2023 12:26:02 +0100 Subject: [PATCH 089/160] Fix missing argument --- nodegen/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 517954c14..a5b84efb3 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -158,7 +158,7 @@ def get_all_test_refs(dtypes: list[Dtype], trait: Trait) -> list[str]: return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: if trait == Trait.NN and dtype == Dtype.BOOL: raise Exception("NN trait does not support bool dtype") From e10c4f84ddf05645ed463779daab0b461d73115c Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Sat, 18 Nov 2023 14:57:54 +0100 Subject: [PATCH 090/160] gather elements --- src/operators/tensor/core.cairo | 4 + .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 6 + .../implementations/tensor_fp16x16wide.cairo | 7 + .../implementations/tensor_fp32x32.cairo | 6 + .../implementations/tensor_fp64x64.cairo | 6 + .../implementations/tensor_fp8x23.cairo | 6 + .../implementations/tensor_fp8x23wide.cairo | 6 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 5 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + .../tensor/math/gather_elements.cairo | 605 ++++++++++++++++++ 13 files changed, 664 insertions(+) create mode 100644 src/operators/tensor/math/gather_elements.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..0dbbdfd50 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -94,6 +94,8 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3584,6 +3586,8 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..59727d476 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -312,6 +312,10 @@ impl BoolTensor of TensorTrait { fn constant_of_shape(shape: Span, value: bool) -> Tensor { constant_of_shape(shape, value) } + + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..75d17157a 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -340,6 +340,12 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..68acd1797 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -328,6 +328,13 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } + } /// 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 f764b1920..83bc29d11 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -341,6 +341,12 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// 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 6cded29b3..7521998f3 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -341,6 +341,12 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// 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 fdcdac1eb..490721d77 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -340,6 +340,12 @@ impl FP8x23Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..7c5d29d8c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -318,6 +318,12 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// 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 8017ab300..39eda4438 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -340,6 +340,10 @@ impl I32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// 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 4f2731b80..095e14ce9 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -339,6 +339,11 @@ impl I8Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } + } /// 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 2f3c3a2ef..bf6611db6 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -310,6 +310,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + math::gather_elements::gather_elements(self, indices, axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..77e48b98c 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod gather_elements; \ No newline at end of file diff --git a/src/operators/tensor/math/gather_elements.cairo b/src/operators/tensor/math/gather_elements.cairo new file mode 100644 index 000000000..56a390a2d --- /dev/null +++ b/src/operators/tensor/math/gather_elements.cairo @@ -0,0 +1,605 @@ +use alexandria_data_structures::array_ext::SpanTraitExt; +use array::ArrayTrait; +use array::SpanTrait; + +use core::traits::Into; +use debug::PrintTrait; +use core::traits::TryInto; +use core::serde::Serde; +use core::traits::Destruct; +use option::OptionTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +/// Cf: TensorTrait::gather docstring +fn gather_elements< + T, + impl TTensorTrait: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop, + // impl TAddEq: AddEq, + // impl TMulEq: MulEq, + // impl TPartialOrd: PartialOrd, + // impl TPartialEq: PartialEq, +>( + self: @Tensor, indices: Tensor, axis: Option +) -> Tensor { + let axis = match axis { + Option::Some(val) => val, + Option::None(_) => 0 + }; + assert(axis < (*self.shape).len(), 'axis out of dimensions'); + + let data_rank = (*self.shape).len(); + let indices_rank = (indices.shape).len(); + assert((data_rank == indices_rank ) & (indices_rank >= 1), 'must be same rank'); + + + let axis_shape = *(*self.shape).at(axis); + let ind_max = indices.data.max().unwrap(); + assert(ind_max < axis_shape, 'this index out of bounds'); + + + // let ind_max = indices.data.max().unwrap(); + // assert(ind_max < axis_shape, 'this index out of bounds'); + let mut indices_shape = indices.shape; + let data_shape = *self.shape; + + + if (indices_rank == 2) { + if (axis == 0) { + assert(indices_shape.at(axis+1) == data_shape.at(axis+1), 'out of index') + } + if (axis == 1) { + assert(indices_shape.at(axis-1) == data_shape.at(axis-1), 'out of index') + } + } + + // if (indices_rank == 3) { + // if (axis == 0) { + // assert((indices_shape.at(axis+1) == data_shape.at(axis+1)) & (indices_shape.at(axis+2) == data_shape.at(axis+2)), 'out of index') + // } + // if (axis == 1) { + // assert((*indices_shape.at(axis-1) < *data_shape.at(axis-1)) & (indices_shape.at(axis+1) == data_shape.at(axis+1)), 'out of index') + // } + // if (axis == 2) { + // assert((*indices_shape.at(axis-2) <= *data_shape.at(axis-2)) & (indices_shape.at(axis-1) == data_shape.at(axis-1)), 'out of index') + // } + // } + + let mut output_data = ArrayTrait::new(); + + let mut outer_loop = indices_shape.at(axis); + let mut inner_loop = 1; + let mut multiplier = 1; + let mut ind = 0; + loop { + match indices_shape.pop_front() { + Option::Some(val) => { + inner_loop *= *val; + if (ind >= axis) { + multiplier *= *val; + } + + ind += 1; + }, + Option::None(_) => { break; } + }; + }; + + let looper = multiplier / *outer_loop; + + if inner_loop != 1 { + inner_loop /= *outer_loop; + } + + + + let mut data_indices = indices.data; + let mut i: usize = 0; + loop { + match data_indices.pop_front() { + Option::Some(val) => { + if (axis == 0){ + let value = *val * inner_loop.into() + (i % inner_loop); + output_data.append(*self.data[value]); + } + if ((axis == indices_rank-1) & (axis != 0)) { + let value = *val + *outer_loop * (i / *outer_loop); + output_data.append(*self.data[value]); + + } + if ((axis != indices_rank-1) & (axis != 0)) { + let value = *val * (looper ) + (i % looper) + (multiplier * (i / multiplier)); + // 'start'.print(); + // i.print(); + // (*val).print(); + // (looper).print(); + // (i % multiplier).print(); + // (multiplier).print(); + // (i / multiplier).print(); + // value.print(); + + output_data.append(*self.data[value]); + } + i += 1; + }, + Option::None(_) => { break; } + }; + }; + + let mut output_tensor = TensorTrait::::new(indices.shape, output_data.span()); + return output_tensor; +} + + +// Tests-------------------------------------------------------------------------------------------------------------- + + +use orion::numbers::fixed_point::implementations::fp8x23::helpers::assert_precise; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::assert_eq; + + +fn indices1() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(5); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn indices() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + + TensorTrait::new(shape.span(), data.span()) +} + +fn indices2() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + + TensorTrait::new(shape.span(), data.span()) +} + +fn indices22() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + 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(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + + TensorTrait::new(shape.span(), data.span()) +} + +fn data1() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(5); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn data() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn data2() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(3); + sizes.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn data3() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(3); + sizes.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn u32_tensor_3x2x3x2_index() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(2); + sizes.append(3); + sizes.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + 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); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn u32_tensor_3x2x3x2_helper() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(2); + sizes.append(3); + sizes.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(31); + data.append(32); + data.append(33); + data.append(34); + data.append(35); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + + + +#[test] +#[available_gas(20000000000)] +fn test_gather_elements_default() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(2)); + let mut output = y.data; + + loop { + match output.pop_front() { + Option::Some(val) => { + (*val).print(); + }, + Option::None(_) => { break; } + }; + }; + +} + +#[test] +#[available_gas(20000000000)] +fn test_gather_elements_axis_1() { + let data = data2(); + let indices = indices22(); + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; + + assert(*output[0] == 0, 'not correct'); + assert(*output[1] == 3, 'not correct'); + assert(*output[2] == 2, 'not correct'); + assert(*output[3] == 3, 'not correct'); + assert(*output[4] == 2, 'not correct'); + assert(*output[5] == 1, 'not correct'); + assert(*output[6] == 8, 'not correct'); + assert(*output[7] == 9, 'not correct'); + assert(*output[8] == 8, 'not correct'); + assert(*output[9] == 7, 'not correct'); + assert(*output[10] == 8, 'not correct'); + assert(*output[11] == 9, 'not correct'); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; + + + +} + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3_lastaxis() { +// let data = data(); +// let indices = indices(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 2, 'not correct'); +// assert(*output[2] == 3, 'not correct'); +// assert(*output[3] == 5, 'not correct'); +// assert(*output[4] == 4, 'not correct'); +// assert(*output[5] == 5, 'not correct'); + +// } + +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements2_lastaxis() { +// let data = data2(); +// let indices = indices22(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); +// let mut output = y.data; + +// assert(*output[0] == 0, 'not correct'); +// assert(*output[1] == 1, 'not correct'); +// assert(*output[2] == 3, 'not correct'); +// assert(*output[3] == 3, 'not correct'); +// assert(*output[4] == 5, 'not correct'); +// assert(*output[5] == 4, 'not correct'); +// assert(*output[6] == 7, 'not correct'); +// assert(*output[7] == 7, 'not correct'); +// assert(*output[8] == 9, 'not correct'); +// assert(*output[9] == 8, 'not correct'); +// assert(*output[10] == 11, 'not correct'); +// assert(*output[11] == 11, 'not correct'); + +// } + +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements2() { +// let data = data2(); +// let indices = indices22(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 0, 'not correct'); +// assert(*output[1] == 7, 'not correct'); +// assert(*output[2] == 8, 'not correct'); +// assert(*output[3] == 9, 'not correct'); +// assert(*output[4] == 10, 'not correct'); +// assert(*output[5] == 5, 'not correct'); +// assert(*output[6] == 6, 'not correct'); +// assert(*output[7] == 7, 'not correct'); +// assert(*output[8] == 8, 'not correct'); +// assert(*output[9] == 3, 'not correct'); + +// } + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_1() { +// let data = data1(); +// let indices = indices1(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 2, 'not correct'); +// assert(*output[2] == 1, 'not correct'); +// assert(*output[3] == 3, 'not correct'); +// assert(*output[4] == 3, 'not correct'); +// } + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3() { +// let data = data(); +// let indices = indices(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 5, 'not correct'); +// assert(*output[2] == 9, 'not correct'); +// assert(*output[3] == 4, 'not correct'); +// assert(*output[4] == 2, 'not correct'); +// assert(*output[5] == 6, 'not correct'); + +// } \ No newline at end of file From d84be27636129e0962d3c0f1631fe3d40d201d77 Mon Sep 17 00:00:00 2001 From: Dincer Guner Date: Sun, 19 Nov 2023 00:27:16 +0300 Subject: [PATCH 091/160] implement pow --- docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + docs/framework/operators/tensor/tensor.pow.md | 67 +++++++++++++++++ nodegen/helpers.py | 2 +- nodegen/node/pow.py | 75 +++++++++++++++++++ src/operators/tensor/core.cairo | 70 +++++++++++++++++ .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/pow.cairo | 43 +++++++++++ tests/nodes.cairo | 4 + tests/nodes/pow_fp16x16.cairo | 22 ++++++ tests/nodes/pow_fp16x16/input_0.cairo | 15 ++++ tests/nodes/pow_fp16x16/input_1.cairo | 15 ++++ tests/nodes/pow_fp16x16/output_0.cairo | 15 ++++ tests/nodes/pow_fp16x16_broadcast.cairo | 22 ++++++ .../nodes/pow_fp16x16_broadcast/input_0.cairo | 15 ++++ .../nodes/pow_fp16x16_broadcast/input_1.cairo | 13 ++++ .../pow_fp16x16_broadcast/output_0.cairo | 15 ++++ tests/nodes/pow_fp8x23.cairo | 22 ++++++ tests/nodes/pow_fp8x23/input_0.cairo | 15 ++++ tests/nodes/pow_fp8x23/input_1.cairo | 15 ++++ tests/nodes/pow_fp8x23/output_0.cairo | 15 ++++ tests/nodes/pow_fp8x23_broadcast.cairo | 22 ++++++ .../nodes/pow_fp8x23_broadcast/input_0.cairo | 15 ++++ .../nodes/pow_fp8x23_broadcast/input_1.cairo | 13 ++++ .../nodes/pow_fp8x23_broadcast/output_0.cairo | 15 ++++ 35 files changed, 567 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.pow.md create mode 100644 nodegen/node/pow.py create mode 100644 src/operators/tensor/math/pow.cairo create mode 100644 tests/nodes/pow_fp16x16.cairo create mode 100644 tests/nodes/pow_fp16x16/input_0.cairo create mode 100644 tests/nodes/pow_fp16x16/input_1.cairo create mode 100644 tests/nodes/pow_fp16x16/output_0.cairo create mode 100644 tests/nodes/pow_fp16x16_broadcast.cairo create mode 100644 tests/nodes/pow_fp16x16_broadcast/input_0.cairo create mode 100644 tests/nodes/pow_fp16x16_broadcast/input_1.cairo create mode 100644 tests/nodes/pow_fp16x16_broadcast/output_0.cairo create mode 100644 tests/nodes/pow_fp8x23.cairo create mode 100644 tests/nodes/pow_fp8x23/input_0.cairo create mode 100644 tests/nodes/pow_fp8x23/input_1.cairo create mode 100644 tests/nodes/pow_fp8x23/output_0.cairo create mode 100644 tests/nodes/pow_fp8x23_broadcast.cairo create mode 100644 tests/nodes/pow_fp8x23_broadcast/input_0.cairo create mode 100644 tests/nodes/pow_fp8x23_broadcast/input_1.cairo create mode 100644 tests/nodes/pow_fp8x23_broadcast/output_0.cairo diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index c33854677..7ff6d9b98 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -107,6 +107,7 @@ * [tensor.shrink](framework/operators/tensor/tensor.shrink.md) * [tensor.sequence\_empty](framework/operators/tensor/tensor.sequence\_empty.md) * [tensor.reduce_mean](framework/operators/tensor/tensor.reduce\_mean.md) + * [tensor.pow](framework/operators/tensor/tensor.pow.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index dbb70e15b..2125aef4a 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -105,6 +105,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | | [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | +| [`tensor.pow`](tensor.pow.md) | Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function f(x) = x^exponent, is applied to the data tensor elementwise. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.pow.md b/docs/framework/operators/tensor/tensor.pow.md new file mode 100644 index 000000000..0a0ae4ac7 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.pow.md @@ -0,0 +1,67 @@ +#tensor.pow + +```rust + fn pow(self: @Tensor, other: @Tensor) -> Tensor; +``` + +Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function f(x) = x^exponent, is applied to the data tensor elementwise. +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, base of the exponent. +* `other`(`@Tensor`) - The second tensor, power of the exponent. + +## Panics + +* Panics if the shapes are not equal or broadcastable + +## Returns + +A new `Tensor` 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 pow_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.pow(@tensor_2); +} +>>> [0,1,4,0,4,25,0,7,64] +``` + +Case 2: Compare tensors with different shapes + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn pow_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.pow(@tensor_2); +} +>>> [0,1,4,0,4,25,0,7,64] +``` diff --git a/nodegen/helpers.py b/nodegen/helpers.py index 517954c14..a5b84efb3 100644 --- a/nodegen/helpers.py +++ b/nodegen/helpers.py @@ -158,7 +158,7 @@ def get_all_test_refs(dtypes: list[Dtype], trait: Trait) -> list[str]: return list(set(refs)) -def get_test_refs(dtype: Dtype, trait: Trait, is_sequence: bool) -> list[str]: +def get_test_refs(dtype: Dtype, trait: Trait) -> list[str]: if trait == Trait.NN and dtype == Dtype.BOOL: raise Exception("NN trait does not support bool dtype") diff --git a/nodegen/node/pow.py b/nodegen/node/pow.py new file mode 100644 index 000000000..ebc257fc0 --- /dev/null +++ b/nodegen/node/pow.py @@ -0,0 +1,75 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Pow(RunAll): + @staticmethod + def pow_fp8x23(): + def default(): + x = np.array([1, 2, 3]).astype(np.float64) + y = np.array([1, 2, 3]).astype(np.float64) + z = np.array(pow(x, y), dtype=np.float64) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "pow_fp8x23" + make_test([x, y], z, "input_0.pow(@input_1)", name) + + def broadcast(): + x = np.array([1, 2, 3]).astype(np.float64) + y = np.array([2]).astype(np.float64) + z = np.array(pow(x, y), dtype=np.float64) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + z = Tensor(Dtype.FP8x23, z.shape, to_fp( + z.flatten(), FixedImpl.FP8x23)) + + name = "pow_fp8x23_broadcast" + make_test([x, y], z, "input_0.pow(@input_1)", name) + + default() + broadcast() + + @staticmethod + def and_fp16x16(): + def default(): + x = np.array([1, 2, 3]).astype(np.float64) + y = np.array([1, 2, 3]).astype(np.float64) + z = np.array(pow(x, y), dtype=np.float64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "pow_fp16x16" + make_test([x, y], z, "input_0.pow(@input_1)", name) + + def broadcast(): + x = np.array([1, 2, 3]).astype(np.float64) + y = np.array([2]).astype(np.float64) + z = np.array(pow(x, y), dtype=np.float64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + z = Tensor(Dtype.FP16x16, z.shape, to_fp( + z.flatten(), FixedImpl.FP16x16)) + + name = "pow_fp16x16_broadcast" + make_test([x, y], z, "input_0.pow(@input_1)", name) + + default() + broadcast() diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 6e7c728e3..ac84039de 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -101,6 +101,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -3914,6 +3915,75 @@ trait TensorTrait { keepdims: Option, noop_with_empty_axes: Option ) -> Tensor; + /// #tensor.pow + /// + /// ```rust + /// fn pow(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function f(x) = x^exponent, is applied to the data tensor elementwise. + /// 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, base of the exponent. + /// * `other`(`@Tensor`) - The second tensor, power of the exponent. + /// + /// ## Panics + /// + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Returns + /// + /// A new `Tensor` 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 pow_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.pow(@tensor_2); + /// } + /// >>> [0,1,4,0,4,25,0,7,64] + /// ``` + /// + /// Case 2: Compare tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn pow_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.pow(@tensor_2); + /// } + /// >>> [0,1,4,0,4,25,0,7,64] + /// ``` + /// + fn pow(self: @Tensor, other: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d24d9a88b..b13676909 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -349,6 +349,10 @@ impl BoolTensor of TensorTrait { ) -> Tensor { panic(array!['not supported!']) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 610ffba1e..cd32921c5 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -380,6 +380,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 3a9873570..3572a8bb2 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -370,6 +370,10 @@ impl FP16x16WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(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 6b50b1074..72786f520 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -381,6 +381,10 @@ impl FP32x32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(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 9931dd661..4713a4f34 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -381,6 +381,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(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 5d5e2e06a..69134aca4 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -378,6 +378,10 @@ impl FP8x23Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(self, other) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8fd044343..555aade5a 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -359,6 +359,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + math::pow::pow(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 9c7c2dc3b..6b07ce8da 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -378,6 +378,10 @@ impl I32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 2d8b7ab4c..aa144ae9e 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -377,6 +377,10 @@ impl I8Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index d5ec1bd4b..8680c41d0 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -348,6 +348,10 @@ impl U32Tensor of TensorTrait { ) -> Tensor { math::reduce_min::reduce_min(self, axes, keepdims, noop_with_empty_axes) } + + fn pow(self: @Tensor, other: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 14625600c..16ee08a7e 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -49,3 +49,4 @@ mod sequence_construct; mod shrink; mod sequence_empty; mod reduce_mean; +mod pow; diff --git a/src/operators/tensor/math/pow.cairo b/src/operators/tensor/math/pow.cairo new file mode 100644 index 000000000..2a2ffd991 --- /dev/null +++ b/src/operators/tensor/math/pow.cairo @@ -0,0 +1,43 @@ +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 +}; + +/// Cf: TensorTrait::pow docstring +fn pow< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensorTrait: 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); + + result.append(NumberTrait::pow(*(*y.data)[indices_self], *(*z.data)[indices_other])); + + n += 1; + if n == num_elements { + break (); + }; + }; + + return TensorTrait::new(broadcasted_shape, result.span()); +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5270a5048..7f326d91a 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -719,3 +719,7 @@ mod reduce_mean_u32_1D; mod reduce_mean_u32_2D_default; mod reduce_mean_u32_2D_keepdims; mod reduce_mean_u32_2D_axis_1; +mod pow_fp16x16; +mod pow_fp16x16_broadcast; +mod pow_fp8x23; +mod pow_fp8x23_broadcast; diff --git a/tests/nodes/pow_fp16x16.cairo b/tests/nodes/pow_fp16x16.cairo new file mode 100644 index 000000000..184fd5d91 --- /dev/null +++ b/tests/nodes/pow_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_pow_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.pow(@input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/pow_fp16x16/input_0.cairo b/tests/nodes/pow_fp16x16/input_0.cairo new file mode 100644 index 000000000..5d7b7d5d7 --- /dev/null +++ b/tests/nodes/pow_fp16x16/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp16x16/input_1.cairo b/tests/nodes/pow_fp16x16/input_1.cairo new file mode 100644 index 000000000..9bd1cb813 --- /dev/null +++ b/tests/nodes/pow_fp16x16/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp16x16/output_0.cairo b/tests/nodes/pow_fp16x16/output_0.cairo new file mode 100644 index 000000000..aa13aa708 --- /dev/null +++ b/tests/nodes/pow_fp16x16/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 1769472, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp16x16_broadcast.cairo b/tests/nodes/pow_fp16x16_broadcast.cairo new file mode 100644 index 000000000..65a5e204f --- /dev/null +++ b/tests/nodes/pow_fp16x16_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_pow_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.pow(@input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/pow_fp16x16_broadcast/input_0.cairo b/tests/nodes/pow_fp16x16_broadcast/input_0.cairo new file mode 100644 index 000000000..5d7b7d5d7 --- /dev/null +++ b/tests/nodes/pow_fp16x16_broadcast/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp16x16_broadcast/input_1.cairo b/tests/nodes/pow_fp16x16_broadcast/input_1.cairo new file mode 100644 index 000000000..882d809a9 --- /dev/null +++ b/tests/nodes/pow_fp16x16_broadcast/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp16x16_broadcast/output_0.cairo b/tests/nodes/pow_fp16x16_broadcast/output_0.cairo new file mode 100644 index 000000000..88175ab45 --- /dev/null +++ b/tests/nodes/pow_fp16x16_broadcast/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23.cairo b/tests/nodes/pow_fp8x23.cairo new file mode 100644 index 000000000..232bb68ec --- /dev/null +++ b/tests/nodes/pow_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_pow_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.pow(@input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/pow_fp8x23/input_0.cairo b/tests/nodes/pow_fp8x23/input_0.cairo new file mode 100644 index 000000000..d1d57cd57 --- /dev/null +++ b/tests/nodes/pow_fp8x23/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23/input_1.cairo b/tests/nodes/pow_fp8x23/input_1.cairo new file mode 100644 index 000000000..0ae3da8ef --- /dev/null +++ b/tests/nodes/pow_fp8x23/input_1.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23/output_0.cairo b/tests/nodes/pow_fp8x23/output_0.cairo new file mode 100644 index 000000000..c63189380 --- /dev/null +++ b/tests/nodes/pow_fp8x23/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 226492416, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23_broadcast.cairo b/tests/nodes/pow_fp8x23_broadcast.cairo new file mode 100644 index 000000000..d698a0b87 --- /dev/null +++ b/tests/nodes/pow_fp8x23_broadcast.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; + +#[test] +#[available_gas(2000000000)] +fn test_pow_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.pow(@input_1); + + assert_eq(y, z); +} diff --git a/tests/nodes/pow_fp8x23_broadcast/input_0.cairo b/tests/nodes/pow_fp8x23_broadcast/input_0.cairo new file mode 100644 index 000000000..d1d57cd57 --- /dev/null +++ b/tests/nodes/pow_fp8x23_broadcast/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23_broadcast/input_1.cairo b/tests/nodes/pow_fp8x23_broadcast/input_1.cairo new file mode 100644 index 000000000..4e33d4a18 --- /dev/null +++ b/tests/nodes/pow_fp8x23_broadcast/input_1.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/pow_fp8x23_broadcast/output_0.cairo b/tests/nodes/pow_fp8x23_broadcast/output_0.cairo new file mode 100644 index 000000000..3d96d6d3e --- /dev/null +++ b/tests/nodes/pow_fp8x23_broadcast/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} From 961f1336137a2eab166c4704a871a5ed7a1fb1a8 Mon Sep 17 00:00:00 2001 From: Raphael Doukhan Date: Mon, 20 Nov 2023 08:54:19 +0000 Subject: [PATCH 092/160] GITBOOK-40: Update models and spaces --- docs/hub/algorithms.md | 4 ++-- docs/hub/spaces.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/hub/algorithms.md b/docs/hub/algorithms.md index 138e4b535..bd54d70d9 100644 --- a/docs/hub/algorithms.md +++ b/docs/hub/algorithms.md @@ -1,7 +1,7 @@ # Models -Discover amazing ML models made by the community with Orion! +Discover amazing ML models made by the community with Orion! -
Verifiable Support Vector Machine

September 26 - 0xd3bs

Verifiable-Logistic-Regression

August 20 - Bowen

Verifiable-Linear-Regression
August 15 - Bem Baraki
MNIST Classification with Feedforward Neural Network June 8, 2023 - Raphael Doukhan
+
Tic-Tac-Toe AI AgentNovember 10 - Raphael Doukhanhttps://github.com/gizatechxyz/Orion-Hub/tree/main/gaming/tic_tac_toe
Verifiable Support Vector MachineSeptember 26 - 0xd3bshttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/verifiable_support_vector_machine
Verifiable-Logistic-RegressionAugust 20 - Bowenhttps://github.com/bowenyou/cairo-logistic-regression
Verifiable-Linear-RegressionAugust 15 - Bem Barakihttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/verifiable_linear_regression_model
MNIST Classification with Feedforward Neural NetworkJune 8, 2023 - Raphael Doukhanhttps://github.com/gizatechxyz/Orion-Hub/tree/main/basic/mnist_nn
We encourage you to contribute your own implementations and help grow this collection, benefiting the community and driving innovation in verifiable ML model inference. diff --git a/docs/hub/spaces.md b/docs/hub/spaces.md index 4c5323940..a1dcd041e 100644 --- a/docs/hub/spaces.md +++ b/docs/hub/spaces.md @@ -2,6 +2,6 @@ Discover amazing ML apps and POCs made by the community with Orion! -{% hint style="info" %} -This section is currently under development. If you're looking for ideas for POCs that can be implemented using Orion, don't hesitate to contact [Raphael](https://twitter.com/raphael\_dkhn) or [Fran](https://twitter.com/franalgaba\_). We have a bunch of exciting ideas to share! -{% endhint %} + + +
Tic Tac Toe in PixeLAWWelcome to the Tic Tac Toe game integrated into the PixeLAW world, where you can challenge an ML bot to a game of Tic Tac Toe onchain!https://github.com/OwnerOfJK/TicTacToeAgent/tree/main
From 634749ce4bd5b2eb35186a7d61f08f4c2726e07e Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 20 Nov 2023 10:07:56 +0100 Subject: [PATCH 093/160] gather elements for all axis --- .../tensor/math/gather_elements.cairo | 485 ++++++++++++------ 1 file changed, 329 insertions(+), 156 deletions(-) diff --git a/src/operators/tensor/math/gather_elements.cairo b/src/operators/tensor/math/gather_elements.cairo index 56a390a2d..a86389fd3 100644 --- a/src/operators/tensor/math/gather_elements.cairo +++ b/src/operators/tensor/math/gather_elements.cairo @@ -19,10 +19,6 @@ fn gather_elements< impl TTensorTrait: TensorTrait, impl TCopy: Copy, impl TDrop: Drop, - // impl TAddEq: AddEq, - // impl TMulEq: MulEq, - // impl TPartialOrd: PartialOrd, - // impl TPartialEq: PartialEq, >( self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { @@ -36,53 +32,41 @@ fn gather_elements< let indices_rank = (indices.shape).len(); assert((data_rank == indices_rank ) & (indices_rank >= 1), 'must be same rank'); - let axis_shape = *(*self.shape).at(axis); let ind_max = indices.data.max().unwrap(); assert(ind_max < axis_shape, 'this index out of bounds'); - - // let ind_max = indices.data.max().unwrap(); - // assert(ind_max < axis_shape, 'this index out of bounds'); let mut indices_shape = indices.shape; - let data_shape = *self.shape; + let mut data_shape = *self.shape; + let mut data_shape_clone = data_shape.clone(); - if (indices_rank == 2) { - if (axis == 0) { - assert(indices_shape.at(axis+1) == data_shape.at(axis+1), 'out of index') - } - if (axis == 1) { - assert(indices_shape.at(axis-1) == data_shape.at(axis-1), 'out of index') - } - } - - // if (indices_rank == 3) { - // if (axis == 0) { - // assert((indices_shape.at(axis+1) == data_shape.at(axis+1)) & (indices_shape.at(axis+2) == data_shape.at(axis+2)), 'out of index') - // } - // if (axis == 1) { - // assert((*indices_shape.at(axis-1) < *data_shape.at(axis-1)) & (indices_shape.at(axis+1) == data_shape.at(axis+1)), 'out of index') - // } - // if (axis == 2) { - // assert((*indices_shape.at(axis-2) <= *data_shape.at(axis-2)) & (indices_shape.at(axis-1) == data_shape.at(axis-1)), 'out of index') - // } - // } + let mut ind = 0; + loop { + match data_shape.pop_front() { + Option::Some(val) => { + if (ind != axis) { + assert(*val == *indices_shape.at(ind), 'shape mismatch'); + } + ind += 1; + }, + Option::None(_) => { break; } + }; + }; let mut output_data = ArrayTrait::new(); - let mut outer_loop = indices_shape.at(axis); + let mut outer_loop = data_shape_clone.at(axis); let mut inner_loop = 1; let mut multiplier = 1; let mut ind = 0; loop { - match indices_shape.pop_front() { + match data_shape_clone.pop_front() { Option::Some(val) => { inner_loop *= *val; if (ind >= axis) { multiplier *= *val; } - ind += 1; }, Option::None(_) => { break; } @@ -95,7 +79,19 @@ fn gather_elements< inner_loop /= *outer_loop; } - + let mut multiplier_index = 1; + let mut ind = 0; + loop { + match indices_shape.pop_front() { + Option::Some(val) => { + if (ind >= axis) { + multiplier_index *= *val; + } + ind += 1; + }, + Option::None(_) => { break; } + }; + }; let mut data_indices = indices.data; let mut i: usize = 0; @@ -109,19 +105,9 @@ fn gather_elements< if ((axis == indices_rank-1) & (axis != 0)) { let value = *val + *outer_loop * (i / *outer_loop); output_data.append(*self.data[value]); - } - if ((axis != indices_rank-1) & (axis != 0)) { - let value = *val * (looper ) + (i % looper) + (multiplier * (i / multiplier)); - // 'start'.print(); - // i.print(); - // (*val).print(); - // (looper).print(); - // (i % multiplier).print(); - // (multiplier).print(); - // (i / multiplier).print(); - // value.print(); - + if ((axis != indices_rank-1) & (axis != 0)) { + let value = *val * (looper ) + (i % looper) + (multiplier * (i / multiplier_index)); output_data.append(*self.data[value]); } i += 1; @@ -448,29 +434,216 @@ fn u32_tensor_3x2x3x2_helper() -> Tensor { return tensor; } +fn u32_tensor_3x2x3x2_index0() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(2); + sizes.append(2); + sizes.append(3); + sizes.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + 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); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + + return tensor; +} + +fn u32_tensor_3x2x3x2_index2() -> Tensor { + let mut sizes = ArrayTrait::new(); + sizes.append(3); + sizes.append(2); + sizes.append(4); + sizes.append(2); + + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + + 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); + data.append(1); + + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + + + let tensor = TensorTrait::::new(sizes.span(), data.span()); + return tensor; +} #[test] #[available_gas(20000000000)] fn test_gather_elements_default() { + let data = data2(); + let indices = indices22(); + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; + + // loop { + // match output.pop_front() { + // Option::Some(val) => { + // (*val).print(); + // }, + // Option::None(_) => { break; } + // }; + // }; + +} + + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3error_work() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index0(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(0)); + let mut output = y.data; +} + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3error1() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index0(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; +} + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3error2() { let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index(); + let indices = u32_tensor_3x2x3x2_index0(); let y = data.gather_elements(indices: indices, axis:Option::Some(2)); let mut output = y.data; +} - loop { - match output.pop_front() { - Option::Some(val) => { - (*val).print(); - }, - Option::None(_) => { break; } - }; - }; +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3error3() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index0(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(3)); + let mut output = y.data; +} + + + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3errorSecond0() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index2(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(0)); + let mut output = y.data; +} + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3errorSecond1() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index2(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; } +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3errorSecondwork() { + let data = u32_tensor_3x2x3x2_helper(); + let indices = u32_tensor_3x2x3x2_index2(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(2)); + let mut output = y.data; +} + + + #[test] #[available_gas(20000000000)] fn test_gather_elements_axis_1() { @@ -501,105 +674,105 @@ fn test_gather_elements_axis_1() { } -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3_lastaxis() { -// let data = data(); -// let indices = indices(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 2, 'not correct'); -// assert(*output[2] == 3, 'not correct'); -// assert(*output[3] == 5, 'not correct'); -// assert(*output[4] == 4, 'not correct'); -// assert(*output[5] == 5, 'not correct'); - -// } - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements2_lastaxis() { -// let data = data2(); -// let indices = indices22(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); -// let mut output = y.data; - -// assert(*output[0] == 0, 'not correct'); -// assert(*output[1] == 1, 'not correct'); -// assert(*output[2] == 3, 'not correct'); -// assert(*output[3] == 3, 'not correct'); -// assert(*output[4] == 5, 'not correct'); -// assert(*output[5] == 4, 'not correct'); -// assert(*output[6] == 7, 'not correct'); -// assert(*output[7] == 7, 'not correct'); -// assert(*output[8] == 9, 'not correct'); -// assert(*output[9] == 8, 'not correct'); -// assert(*output[10] == 11, 'not correct'); -// assert(*output[11] == 11, 'not correct'); - -// } - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements2() { -// let data = data2(); -// let indices = indices22(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 0, 'not correct'); -// assert(*output[1] == 7, 'not correct'); -// assert(*output[2] == 8, 'not correct'); -// assert(*output[3] == 9, 'not correct'); -// assert(*output[4] == 10, 'not correct'); -// assert(*output[5] == 5, 'not correct'); -// assert(*output[6] == 6, 'not correct'); -// assert(*output[7] == 7, 'not correct'); -// assert(*output[8] == 8, 'not correct'); -// assert(*output[9] == 3, 'not correct'); - -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_1() { -// let data = data1(); -// let indices = indices1(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 2, 'not correct'); -// assert(*output[2] == 1, 'not correct'); -// assert(*output[3] == 3, 'not correct'); -// assert(*output[4] == 3, 'not correct'); -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3() { -// let data = data(); -// let indices = indices(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 5, 'not correct'); -// assert(*output[2] == 9, 'not correct'); -// assert(*output[3] == 4, 'not correct'); -// assert(*output[4] == 2, 'not correct'); -// assert(*output[5] == 6, 'not correct'); - -// } \ No newline at end of file +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3_lastaxis() { + let data = data(); + let indices = indices(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(1)); + let mut output = y.data; + + assert(*output[0] == 1, 'not correct'); + assert(*output[1] == 2, 'not correct'); + assert(*output[2] == 3, 'not correct'); + assert(*output[3] == 5, 'not correct'); + assert(*output[4] == 4, 'not correct'); + assert(*output[5] == 5, 'not correct'); + +} + +#[test] +#[available_gas(20000000000)] +fn test_gather_elements2_lastaxis() { + let data = data2(); + let indices = indices22(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(2)); + let mut output = y.data; + + assert(*output[0] == 0, 'not correct'); + assert(*output[1] == 1, 'not correct'); + assert(*output[2] == 3, 'not correct'); + assert(*output[3] == 3, 'not correct'); + assert(*output[4] == 5, 'not correct'); + assert(*output[5] == 4, 'not correct'); + assert(*output[6] == 7, 'not correct'); + assert(*output[7] == 7, 'not correct'); + assert(*output[8] == 9, 'not correct'); + assert(*output[9] == 8, 'not correct'); + assert(*output[10] == 11, 'not correct'); + assert(*output[11] == 11, 'not correct'); + +} + +#[test] +#[available_gas(20000000000)] +fn test_gather_elements2() { + let data = data2(); + let indices = indices22(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(0)); + let mut output = y.data; + + assert(*output[0] == 0, 'not correct'); + assert(*output[1] == 7, 'not correct'); + assert(*output[2] == 8, 'not correct'); + assert(*output[3] == 9, 'not correct'); + assert(*output[4] == 10, 'not correct'); + assert(*output[5] == 5, 'not correct'); + assert(*output[6] == 6, 'not correct'); + assert(*output[7] == 7, 'not correct'); + assert(*output[8] == 8, 'not correct'); + assert(*output[9] == 3, 'not correct'); + +} + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_1() { + let data = data1(); + let indices = indices1(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(0)); + let mut output = y.data; + + assert(*output[0] == 1, 'not correct'); + assert(*output[1] == 2, 'not correct'); + assert(*output[2] == 1, 'not correct'); + assert(*output[3] == 3, 'not correct'); + assert(*output[4] == 3, 'not correct'); +} + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_3() { + let data = data(); + let indices = indices(); + + + let y = data.gather_elements(indices: indices, axis:Option::Some(0)); + let mut output = y.data; + + assert(*output[0] == 1, 'not correct'); + assert(*output[1] == 5, 'not correct'); + assert(*output[2] == 9, 'not correct'); + assert(*output[3] == 4, 'not correct'); + assert(*output[4] == 2, 'not correct'); + assert(*output[5] == 6, 'not correct'); + +} \ No newline at end of file From ae487855b2749917e4a7ca24c82a097e7262350d Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 20 Nov 2023 11:54:21 +0100 Subject: [PATCH 094/160] gather elements and tests --- docs/CHANGELOG.md | 5 + docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.gather_elements.md | 47 +++ nodegen/node/gather_elements.py | 268 ++++++++++++ src/operators/tensor/core.cairo | 49 ++- .../tensor/math/gather_elements.cairo | 397 +++++++++--------- tests/nodes.cairo | 15 + .../gather_elements_fp16x16_3d_axis1.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../gather_elements_fp16x16_3d_axis2.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../gather_elements_fp16x16_3d_default.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../gather_elements_fp8x23_3d_axis1.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../gather_elements_fp8x23_3d_axis2.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../gather_elements_fp8x23_3d_default.cairo | 24 ++ .../input_0.cairo | 41 ++ .../input_1.cairo | 40 ++ .../output_0.cairo | 41 ++ .../nodes/gather_elements_i32_3d_axis1.cairo | 24 ++ .../input_0.cairo | 38 ++ .../input_1.cairo | 49 +++ .../output_0.cairo | 50 +++ .../nodes/gather_elements_i32_3d_axis2.cairo | 24 ++ .../input_0.cairo | 38 ++ .../input_1.cairo | 45 ++ .../output_0.cairo | 46 ++ .../gather_elements_i32_3d_default.cairo | 24 ++ .../input_0.cairo | 38 ++ .../input_1.cairo | 43 ++ .../output_0.cairo | 44 ++ tests/nodes/gather_elements_i8_3d_axis1.cairo | 24 ++ .../gather_elements_i8_3d_axis1/input_0.cairo | 22 + .../gather_elements_i8_3d_axis1/input_1.cairo | 21 + .../output_0.cairo | 22 + .../nodes/gather_elements_i8_3d_default.cairo | 24 ++ .../input_0.cairo | 22 + .../input_1.cairo | 21 + .../output_0.cairo | 22 + tests/nodes/gather_elements_u32_axis1.cairo | 22 + .../gather_elements_u32_axis1/input_0.cairo | 122 ++++++ .../gather_elements_u32_axis1/input_1.cairo | 194 +++++++++ .../gather_elements_u32_axis1/output_0.cairo | 194 +++++++++ tests/nodes/gather_elements_u32_axis2.cairo | 22 + .../gather_elements_u32_axis2/input_0.cairo | 122 ++++++ .../gather_elements_u32_axis2/input_1.cairo | 122 ++++++ .../gather_elements_u32_axis2/output_0.cairo | 122 ++++++ tests/nodes/gather_elements_u32_axis3.cairo | 22 + .../gather_elements_u32_axis3/input_0.cairo | 122 ++++++ .../gather_elements_u32_axis3/input_1.cairo | 230 ++++++++++ .../gather_elements_u32_axis3/output_0.cairo | 230 ++++++++++ tests/nodes/gather_elements_u32_default.cairo | 22 + .../gather_elements_u32_default/input_0.cairo | 122 ++++++ .../gather_elements_u32_default/input_1.cairo | 374 +++++++++++++++++ .../output_0.cairo | 374 +++++++++++++++++ 69 files changed, 4518 insertions(+), 199 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.gather_elements.md create mode 100644 nodegen/node/gather_elements.py create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis1.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis1/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis1/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis1/output_0.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis2.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis2/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis2/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_axis2/output_0.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_default.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_default/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_default/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp16x16_3d_default/output_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis1.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis1/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis1/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis1/output_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis2.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis2/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis2/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_axis2/output_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_default.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_default/input_0.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_default/input_1.cairo create mode 100644 tests/nodes/gather_elements_fp8x23_3d_default/output_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis1.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis1/input_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis1/input_1.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis1/output_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis2.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis2/input_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis2/input_1.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_axis2/output_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_default.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_default/input_0.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_default/input_1.cairo create mode 100644 tests/nodes/gather_elements_i32_3d_default/output_0.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_axis1.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_axis1/input_0.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_axis1/input_1.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_axis1/output_0.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_default.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_default/input_0.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_default/input_1.cairo create mode 100644 tests/nodes/gather_elements_i8_3d_default/output_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis1.cairo create mode 100644 tests/nodes/gather_elements_u32_axis1/input_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis1/input_1.cairo create mode 100644 tests/nodes/gather_elements_u32_axis1/output_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis2.cairo create mode 100644 tests/nodes/gather_elements_u32_axis2/input_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis2/input_1.cairo create mode 100644 tests/nodes/gather_elements_u32_axis2/output_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis3.cairo create mode 100644 tests/nodes/gather_elements_u32_axis3/input_0.cairo create mode 100644 tests/nodes/gather_elements_u32_axis3/input_1.cairo create mode 100644 tests/nodes/gather_elements_u32_axis3/output_0.cairo create mode 100644 tests/nodes/gather_elements_u32_default.cairo create mode 100644 tests/nodes/gather_elements_u32_default/input_0.cairo create mode 100644 tests/nodes/gather_elements_u32_default/input_1.cairo create mode 100644 tests/nodes/gather_elements_u32_default/output_0.cairo diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 68fede545..73b2da763 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2023-11-20 + +## Added +- Gather Elements Operator. + ## [Unreleased] - 2023-11-06 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 8db15644a..bbd9c7244 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.gather\_elements](framework/operators/tensor/tensor.gather\_elements.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 ebc50ad77..fb2ce1e18 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -81,5 +81,6 @@ You can see below the list of current supported ONNX Operators: | [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | +| [GatherElements](operators/tensor/tensor.gather/_elements.md) | :white\_check\_mark: | Current Operators support: **75/156 (48%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..169a250d7 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.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.gather_elements`](tensor.gather\_elements.md) | GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.gather_elements.md b/docs/framework/operators/tensor/tensor.gather_elements.md new file mode 100644 index 000000000..ad8b6c3bb --- /dev/null +++ b/docs/framework/operators/tensor/tensor.gather_elements.md @@ -0,0 +1,47 @@ +# tensor.gather_elements + +```rust + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; +``` + +GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `indices`(`Tensor`) - Tensor of indices. +* `axis`(`Option`) - Axis to gather_elements on. Default: axis=0. + +## Panics + +* Panics if index values are not within bounds [-s, s-1] along axis of size s. + +## Returns + +A new `Tensor` . + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn gather_elements_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![3, 3].span(), + data: array![[ 1, 2, 3],[4, 5, 6], [7, 8, 9]].span(), + ); + let indices = TensorTrait::::new( + shape: array![1, 2, 0].span(), + data: array![2, 0, 0].span(), + ); + + return tensor.gather_elements( + indices: indices, + axis: Option::None(()), + ); +} +>>> [[4. 8. 3.] + [7. 2. 3.]] +``` diff --git a/nodegen/node/gather_elements.py b/nodegen/node/gather_elements.py new file mode 100644 index 000000000..604a666c7 --- /dev/null +++ b/nodegen/node/gather_elements.py @@ -0,0 +1,268 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait + +def gather_elements(data, indices, axis=0): # type: ignore + data_swaped = np.swapaxes(data, 0, axis) + index_swaped = np.swapaxes(indices, 0, axis) + gathered = np.choose(index_swaped, data_swaped, mode="wrap") + y = np.swapaxes(gathered, 0, axis) + return y + +class Gather_elements(RunAll): + + @staticmethod + def gather_elements_fp16x16(): + def gather_elements_3D(): + def default(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=2, size=(3,3,3)).astype(np.uint32) + y = gather_elements(x1, x2, axis=0) + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "gather_elements_fp16x16_3d_default" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(0))", + name= name) + + def axis1(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=3, size=(3,3,3)).astype(np.uint32) + y = gather_elements(x1, x2, axis=1) + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "gather_elements_fp16x16_3d_axis1" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(1))", + name= name) + + def axis2(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=3, size=(3,3,3)).astype(np.uint32) + y = gather_elements(x1, x2, axis=2) + + x1 = Tensor(Dtype.FP16x16, x1.shape, to_fp(x1.flatten(), FixedImpl.FP16x16)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "gather_elements_fp16x16_3d_axis2" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(2))", + name= name) + + default() + axis1() + axis2() + gather_elements_3D() + + + @staticmethod + def gather_elements_fp8x23(): + def gather_elements_3D(): + def default(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=2, size=(3,3,3)).astype(np.int64) + y = gather_elements(x1, x2, axis=0) + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "gather_elements_fp8x23_3d_default" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(0))", + name= name) + + def axis1(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=3, size=(3,3,3)).astype(np.int64) + y = gather_elements(x1, x2, axis=1) + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "gather_elements_fp8x23_3d_axis1" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(1))", + name= name) + + def axis2(): + x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) + x2 = np.random.randint(low = 0,high=3, size=(3,3,3)).astype(np.int64) + y = gather_elements(x1, x2, axis=2) + + x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x23)) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) + + name = "gather_elements_fp8x23_3d_axis2" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(2))", + name= name) + + default() + axis1() + axis2() + gather_elements_3D() + + + @staticmethod + def gather_elements_i8(): + def gather_elements_3D(): + def default(): + x1 = np.arange(0,9).reshape(3,3).astype(np.int8) + x2 = np.random.randint(low = 0,high=2, size=(3,3)).astype(np.int8) + y = gather_elements(x1, x2, axis=0) + + x1 = Tensor(Dtype.I8, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "gather_elements_i8_3d_default" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(0))", + name= name) + + def axis1(): + x1 = np.arange(0,9).reshape(3,3).astype(np.int8) + x2 = np.random.randint(low = 0,high=2, size=(3,3)).astype(np.int8) + y = gather_elements(x1, x2, axis=1) + + x1 = Tensor(Dtype.I8, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.I8, y.shape, y.flatten()) + + name = "gather_elements_i8_3d_axis1" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(1))", + name= name) + + default() + axis1() + gather_elements_3D() + + + @staticmethod + def gather_elements_i32(): + def gather_elements_3D(): + def default(): + x1 = np.arange(0,24).reshape(4,2,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=2, size=(5,2,3)).astype(np.int32) + y = gather_elements(x1, x2, axis=0) + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "gather_elements_i32_3d_default" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(0))", + name= name) + + def axis1(): + x1 = np.arange(0,24).reshape(4,2,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=2, size=(4,3,3)).astype(np.int32) + y = gather_elements(x1, x2, axis=1) + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "gather_elements_i32_3d_axis1" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(1))", + name= name) + + def axis2(): + x1 = np.arange(0,24).reshape(4,2,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=2, size=(4,2,4)).astype(np.int32) + y = gather_elements(x1, x2, axis=2) + + x1 = Tensor(Dtype.I32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "gather_elements_i32_3d_axis2" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(2))", + name= name) + + default() + axis1() + axis2() + gather_elements_3D() + + @staticmethod + def gather_elements_u32(): + def gather_elements_3D(): + def default(): + x1 = np.arange(0,108).reshape(3,3,4,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=3, size=(10,3,4,3)).astype(np.int32) + y = gather_elements(x1, x2, axis=0) + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "gather_elements_u32_default" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(0))", + name= name) + + def axis1(): + x1 = np.arange(0,108).reshape(3,3,4,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=3, size=(3,5,4,3)).astype(np.int32) + y = gather_elements(x1, x2, axis=1) + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "gather_elements_u32_axis1" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(1))", + name= name) + + def axis2(): + x1 = np.arange(0,108).reshape(3,3,4,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=3, size=(3,3,4,3)).astype(np.int32) + y = gather_elements(x1, x2, axis=2) + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "gather_elements_u32_axis2" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(2))", + name= name) + + def axis3(): + x1 = np.arange(0,108).reshape(3,3,4,3).astype(np.int32) + x2 = np.random.randint(low = 0,high=3, size=(3,3,4,6)).astype(np.int32) + y = gather_elements(x1, x2, axis=3) + + x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) + x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "gather_elements_u32_axis3" + make_test( + inputs = [x1, x2], output = y, func_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(3))", + name= name) + + default() + axis1() + axis2() + axis3() + gather_elements_3D() \ No newline at end of file diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 0dbbdfd50..be0f85c4c 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3586,7 +3586,54 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; - + /// # tensor.gather_elements + /// + /// ```rust + /// fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; + /// ``` + /// + /// GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// * `axis`(`Option`) - Axis to gather_elements on. Default: axis=0. + /// + /// ## Panics + /// + /// * Panics if index values are not within bounds [-s, s-1] along axis of size s. + /// + /// ## Returns + /// + /// A new `Tensor` . + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn gather_elements_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![3, 3].span(), + /// data: array![[ 1, 2, 3],[4, 5, 6], [7, 8, 9]].span(), + /// ); + /// let indices = TensorTrait::::new( + /// shape: array![1, 2, 0].span(), + /// data: array![2, 0, 0].span(), + /// ); + /// + /// return tensor.gather_elements( + /// indices: indices, + /// axis: Option::None(()), + /// ); + /// } + /// >>> [[4. 8. 3.] + /// [7. 2. 3.]] + /// ``` + /// fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; } diff --git a/src/operators/tensor/math/gather_elements.cairo b/src/operators/tensor/math/gather_elements.cairo index a86389fd3..ef365e06d 100644 --- a/src/operators/tensor/math/gather_elements.cairo +++ b/src/operators/tensor/math/gather_elements.cairo @@ -80,6 +80,7 @@ fn gather_elements< } let mut multiplier_index = 1; + let mut outer_loop_index = indices_shape.at(axis); let mut ind = 0; loop { match indices_shape.pop_front() { @@ -103,7 +104,7 @@ fn gather_elements< output_data.append(*self.data[value]); } if ((axis == indices_rank-1) & (axis != 0)) { - let value = *val + *outer_loop * (i / *outer_loop); + let value = *val + *outer_loop * (i / *outer_loop_index); output_data.append(*self.data[value]); } if ((axis != indices_rank-1) & (axis != 0)) { @@ -541,238 +542,238 @@ fn u32_tensor_3x2x3x2_index2() -> Tensor { return tensor; } -#[test] -#[available_gas(20000000000)] -fn test_gather_elements_default() { - let data = data2(); - let indices = indices22(); +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements_default() { +// let data = data2(); +// let indices = indices22(); - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; - // loop { - // match output.pop_front() { - // Option::Some(val) => { - // (*val).print(); - // }, - // Option::None(_) => { break; } - // }; - // }; +// // loop { +// // match output.pop_front() { +// // Option::Some(val) => { +// // (*val).print(); +// // }, +// // Option::None(_) => { break; } +// // }; +// // }; -} +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3error_work() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index0(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3error_work() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index0(); - let y = data.gather_elements(indices: indices, axis:Option::Some(0)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3error1() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index0(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3error1() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index0(); - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3error2() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index0(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3error2() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index0(); - let y = data.gather_elements(indices: indices, axis:Option::Some(2)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3error3() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index0(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3error3() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index0(); - let y = data.gather_elements(indices: indices, axis:Option::Some(3)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(3)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3errorSecond0() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index2(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3errorSecond0() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index2(); - let y = data.gather_elements(indices: indices, axis:Option::Some(0)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3errorSecond1() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index2(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3errorSecond1() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index2(); - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; +// } -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3errorSecondwork() { - let data = u32_tensor_3x2x3x2_helper(); - let indices = u32_tensor_3x2x3x2_index2(); +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3errorSecondwork() { +// let data = u32_tensor_3x2x3x2_helper(); +// let indices = u32_tensor_3x2x3x2_index2(); - let y = data.gather_elements(indices: indices, axis:Option::Some(2)); - let mut output = y.data; -} +// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); +// let mut output = y.data; +// } -#[test] -#[available_gas(20000000000)] -fn test_gather_elements_axis_1() { - let data = data2(); - let indices = indices22(); +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements_axis_1() { +// let data = data2(); +// let indices = indices22(); - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; - assert(*output[0] == 0, 'not correct'); - assert(*output[1] == 3, 'not correct'); - assert(*output[2] == 2, 'not correct'); - assert(*output[3] == 3, 'not correct'); - assert(*output[4] == 2, 'not correct'); - assert(*output[5] == 1, 'not correct'); - assert(*output[6] == 8, 'not correct'); - assert(*output[7] == 9, 'not correct'); - assert(*output[8] == 8, 'not correct'); - assert(*output[9] == 7, 'not correct'); - assert(*output[10] == 8, 'not correct'); - assert(*output[11] == 9, 'not correct'); +// assert(*output[0] == 0, 'not correct'); +// assert(*output[1] == 3, 'not correct'); +// assert(*output[2] == 2, 'not correct'); +// assert(*output[3] == 3, 'not correct'); +// assert(*output[4] == 2, 'not correct'); +// assert(*output[5] == 1, 'not correct'); +// assert(*output[6] == 8, 'not correct'); +// assert(*output[7] == 9, 'not correct'); +// assert(*output[8] == 8, 'not correct'); +// assert(*output[9] == 7, 'not correct'); +// assert(*output[10] == 8, 'not correct'); +// assert(*output[11] == 9, 'not correct'); - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; -} - -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3_lastaxis() { - let data = data(); - let indices = indices(); - - - let y = data.gather_elements(indices: indices, axis:Option::Some(1)); - let mut output = y.data; - - assert(*output[0] == 1, 'not correct'); - assert(*output[1] == 2, 'not correct'); - assert(*output[2] == 3, 'not correct'); - assert(*output[3] == 5, 'not correct'); - assert(*output[4] == 4, 'not correct'); - assert(*output[5] == 5, 'not correct'); - -} - -#[test] -#[available_gas(20000000000)] -fn test_gather_elements2_lastaxis() { - let data = data2(); - let indices = indices22(); - - - let y = data.gather_elements(indices: indices, axis:Option::Some(2)); - let mut output = y.data; - - assert(*output[0] == 0, 'not correct'); - assert(*output[1] == 1, 'not correct'); - assert(*output[2] == 3, 'not correct'); - assert(*output[3] == 3, 'not correct'); - assert(*output[4] == 5, 'not correct'); - assert(*output[5] == 4, 'not correct'); - assert(*output[6] == 7, 'not correct'); - assert(*output[7] == 7, 'not correct'); - assert(*output[8] == 9, 'not correct'); - assert(*output[9] == 8, 'not correct'); - assert(*output[10] == 11, 'not correct'); - assert(*output[11] == 11, 'not correct'); - -} - -#[test] -#[available_gas(20000000000)] -fn test_gather_elements2() { - let data = data2(); - let indices = indices22(); - - - let y = data.gather_elements(indices: indices, axis:Option::Some(0)); - let mut output = y.data; - - assert(*output[0] == 0, 'not correct'); - assert(*output[1] == 7, 'not correct'); - assert(*output[2] == 8, 'not correct'); - assert(*output[3] == 9, 'not correct'); - assert(*output[4] == 10, 'not correct'); - assert(*output[5] == 5, 'not correct'); - assert(*output[6] == 6, 'not correct'); - assert(*output[7] == 7, 'not correct'); - assert(*output[8] == 8, 'not correct'); - assert(*output[9] == 3, 'not correct'); - -} - -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_1() { - let data = data1(); - let indices = indices1(); - - - let y = data.gather_elements(indices: indices, axis:Option::Some(0)); - let mut output = y.data; - - assert(*output[0] == 1, 'not correct'); - assert(*output[1] == 2, 'not correct'); - assert(*output[2] == 1, 'not correct'); - assert(*output[3] == 3, 'not correct'); - assert(*output[4] == 3, 'not correct'); -} - -#[test] -#[available_gas(2000000000)] -fn test_gather_elements_3() { - let data = data(); - let indices = indices(); - - - let y = data.gather_elements(indices: indices, axis:Option::Some(0)); - let mut output = y.data; - - assert(*output[0] == 1, 'not correct'); - assert(*output[1] == 5, 'not correct'); - assert(*output[2] == 9, 'not correct'); - assert(*output[3] == 4, 'not correct'); - assert(*output[4] == 2, 'not correct'); - assert(*output[5] == 6, 'not correct'); - -} \ No newline at end of file +// } + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3_lastaxis() { +// let data = data(); +// let indices = indices(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 2, 'not correct'); +// assert(*output[2] == 3, 'not correct'); +// assert(*output[3] == 5, 'not correct'); +// assert(*output[4] == 4, 'not correct'); +// assert(*output[5] == 5, 'not correct'); + +// } + +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements2_lastaxis() { +// let data = data2(); +// let indices = indices22(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); +// let mut output = y.data; + +// assert(*output[0] == 0, 'not correct'); +// assert(*output[1] == 1, 'not correct'); +// assert(*output[2] == 3, 'not correct'); +// assert(*output[3] == 3, 'not correct'); +// assert(*output[4] == 5, 'not correct'); +// assert(*output[5] == 4, 'not correct'); +// assert(*output[6] == 7, 'not correct'); +// assert(*output[7] == 7, 'not correct'); +// assert(*output[8] == 9, 'not correct'); +// assert(*output[9] == 8, 'not correct'); +// assert(*output[10] == 11, 'not correct'); +// assert(*output[11] == 11, 'not correct'); + +// } + +// #[test] +// #[available_gas(20000000000)] +// fn test_gather_elements2() { +// let data = data2(); +// let indices = indices22(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 0, 'not correct'); +// assert(*output[1] == 7, 'not correct'); +// assert(*output[2] == 8, 'not correct'); +// assert(*output[3] == 9, 'not correct'); +// assert(*output[4] == 10, 'not correct'); +// assert(*output[5] == 5, 'not correct'); +// assert(*output[6] == 6, 'not correct'); +// assert(*output[7] == 7, 'not correct'); +// assert(*output[8] == 8, 'not correct'); +// assert(*output[9] == 3, 'not correct'); + +// } + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_1() { +// let data = data1(); +// let indices = indices1(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 2, 'not correct'); +// assert(*output[2] == 1, 'not correct'); +// assert(*output[3] == 3, 'not correct'); +// assert(*output[4] == 3, 'not correct'); +// } + +// #[test] +// #[available_gas(2000000000)] +// fn test_gather_elements_3() { +// let data = data(); +// let indices = indices(); + + +// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); +// let mut output = y.data; + +// assert(*output[0] == 1, 'not correct'); +// assert(*output[1] == 5, 'not correct'); +// assert(*output[2] == 9, 'not correct'); +// assert(*output[3] == 4, 'not correct'); +// assert(*output[4] == 2, 'not correct'); +// assert(*output[5] == 6, 'not correct'); + +// } \ No newline at end of file diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..abc51a01e 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,18 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod gather_elements_fp16x16_3d_default; +mod gather_elements_fp16x16_3d_axis1; +mod gather_elements_fp16x16_3d_axis2; +mod gather_elements_fp8x23_3d_default; +mod gather_elements_fp8x23_3d_axis1; +mod gather_elements_fp8x23_3d_axis2; +mod gather_elements_i8_3d_default; +mod gather_elements_i8_3d_axis1; +mod gather_elements_i32_3d_default; +mod gather_elements_i32_3d_axis1; +mod gather_elements_i32_3d_axis2; +mod gather_elements_u32_default; +mod gather_elements_u32_axis1; +mod gather_elements_u32_axis2; +mod gather_elements_u32_axis3; diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis1.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis1.cairo new file mode 100644 index 000000000..b7fbad90b --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp16x16_3d_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis1/input_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis1/input_0.cairo new file mode 100644 index 000000000..e6f14fe6d --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis1/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 851968, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 1179648, sign: false }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1507328, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 1703936, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis1/input_1.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis1/input_1.cairo new file mode 100644 index 000000000..965fb55b7 --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis1/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis1/output_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis1/output_0.cairo new file mode 100644 index 000000000..e275ba45c --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis1/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 1507328, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1507328, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis2.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis2.cairo new file mode 100644 index 000000000..f1a37f468 --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis2.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp16x16_3d_axis2() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(2)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis2/input_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis2/input_0.cairo new file mode 100644 index 000000000..e6f14fe6d --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis2/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 851968, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 1179648, sign: false }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1507328, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 1703936, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis2/input_1.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis2/input_1.cairo new file mode 100644 index 000000000..f0b0ecc4d --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis2/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(2); + data.append(2); + 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(0); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_axis2/output_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_axis2/output_0.cairo new file mode 100644 index 000000000..d3c4bc465 --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_axis2/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 1703936, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_default.cairo b/tests/nodes/gather_elements_fp16x16_3d_default.cairo new file mode 100644 index 000000000..b622d16c4 --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp16x16_3d_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_default/input_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_default/input_0.cairo new file mode 100644 index 000000000..e6f14fe6d --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_default/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 851968, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 1048576, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 1179648, sign: false }); + data.append(FP16x16 { mag: 1245184, sign: false }); + data.append(FP16x16 { mag: 1310720, sign: false }); + data.append(FP16x16 { mag: 1376256, sign: false }); + data.append(FP16x16 { mag: 1441792, sign: false }); + data.append(FP16x16 { mag: 1507328, sign: false }); + data.append(FP16x16 { mag: 1572864, sign: false }); + data.append(FP16x16 { mag: 1638400, sign: false }); + data.append(FP16x16 { mag: 1703936, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_default/input_1.cairo b/tests/nodes/gather_elements_fp16x16_3d_default/input_1.cairo new file mode 100644 index 000000000..783d2169a --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_default/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(1); + 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(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp16x16_3d_default/output_0.cairo b/tests/nodes/gather_elements_fp16x16_3d_default/output_0.cairo new file mode 100644 index 000000000..9c94a9532 --- /dev/null +++ b/tests/nodes/gather_elements_fp16x16_3d_default/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 655360, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 851968, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + data.append(FP16x16 { mag: 589824, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 983040, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 1114112, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 720896, sign: false }); + data.append(FP16x16 { mag: 786432, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 917504, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + data.append(FP16x16 { mag: 458752, sign: false }); + data.append(FP16x16 { mag: 524288, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis1.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis1.cairo new file mode 100644 index 000000000..b705ecdcc --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp8x23_3d_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis1/input_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis1/input_0.cairo new file mode 100644 index 000000000..de5867b1f --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis1/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 167772160, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis1/input_1.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis1/input_1.cairo new file mode 100644 index 000000000..5630eb6cb --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis1/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis1/output_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis1/output_0.cairo new file mode 100644 index 000000000..5fa2a148c --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis1/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 167772160, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis2.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis2.cairo new file mode 100644 index 000000000..4296693df --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis2.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp8x23_3d_axis2() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(2)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis2/input_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis2/input_0.cairo new file mode 100644 index 000000000..de5867b1f --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis2/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 167772160, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis2/input_1.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis2/input_1.cairo new file mode 100644 index 000000000..f029f0f5e --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis2/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_axis2/output_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_axis2/output_0.cairo new file mode 100644 index 000000000..93c6c209e --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_axis2/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_default.cairo b/tests/nodes/gather_elements_fp8x23_3d_default.cairo new file mode 100644 index 000000000..564715093 --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_fp8x23_3d_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_default/input_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_default/input_0.cairo new file mode 100644 index 000000000..de5867b1f --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_default/input_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 58720256, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 92274688, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 150994944, sign: false }); + data.append(FP8x23 { mag: 159383552, sign: false }); + data.append(FP8x23 { mag: 167772160, sign: false }); + data.append(FP8x23 { mag: 176160768, sign: false }); + data.append(FP8x23 { mag: 184549376, sign: false }); + data.append(FP8x23 { mag: 192937984, sign: false }); + data.append(FP8x23 { mag: 201326592, sign: false }); + data.append(FP8x23 { mag: 209715200, sign: false }); + data.append(FP8x23 { mag: 218103808, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_default/input_1.cairo b/tests/nodes/gather_elements_fp8x23_3d_default/input_1.cairo new file mode 100644 index 000000000..fe0c62031 --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_default/input_1.cairo @@ -0,0 +1,40 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + 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(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_fp8x23_3d_default/output_0.cairo b/tests/nodes/gather_elements_fp8x23_3d_default/output_0.cairo new file mode 100644 index 000000000..2fa7ffd60 --- /dev/null +++ b/tests/nodes/gather_elements_fp8x23_3d_default/output_0.cairo @@ -0,0 +1,41 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 83886080, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 100663296, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 142606336, sign: false }); + data.append(FP8x23 { mag: 75497472, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 109051904, sign: false }); + data.append(FP8x23 { mag: 117440512, sign: false }); + data.append(FP8x23 { mag: 125829120, sign: false }); + data.append(FP8x23 { mag: 134217728, sign: false }); + data.append(FP8x23 { mag: 67108864, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis1.cairo b/tests/nodes/gather_elements_i32_3d_axis1.cairo new file mode 100644 index 000000000..1c0e01766 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_i32_3d_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_i32_3d_axis1/input_0.cairo b/tests/nodes/gather_elements_i32_3d_axis1/input_0.cairo new file mode 100644 index 000000000..e96796beb --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis1/input_0.cairo @@ -0,0 +1,38 @@ +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(4); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + 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: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis1/input_1.cairo b/tests/nodes/gather_elements_i32_3d_axis1/input_1.cairo new file mode 100644 index 000000000..4f3a314c3 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis1/input_1.cairo @@ -0,0 +1,49 @@ +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(4); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + 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(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis1/output_0.cairo b/tests/nodes/gather_elements_i32_3d_axis1/output_0.cairo new file mode 100644 index 000000000..4aa418f8f --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis1/output_0.cairo @@ -0,0 +1,50 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(4); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis2.cairo b/tests/nodes/gather_elements_i32_3d_axis2.cairo new file mode 100644 index 000000000..ff06e84b8 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis2.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_i32_3d_axis2() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(2)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_i32_3d_axis2/input_0.cairo b/tests/nodes/gather_elements_i32_3d_axis2/input_0.cairo new file mode 100644 index 000000000..e96796beb --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis2/input_0.cairo @@ -0,0 +1,38 @@ +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(4); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + 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: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis2/input_1.cairo b/tests/nodes/gather_elements_i32_3d_axis2/input_1.cairo new file mode 100644 index 000000000..ed889b349 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis2/input_1.cairo @@ -0,0 +1,45 @@ +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(4); + shape.append(2); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + 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(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_axis2/output_0.cairo b/tests/nodes/gather_elements_i32_3d_axis2/output_0.cairo new file mode 100644 index 000000000..1aac2bec6 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_axis2/output_0.cairo @@ -0,0 +1,46 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(4); + shape.append(2); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 21, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_default.cairo b/tests/nodes/gather_elements_i32_3d_default.cairo new file mode 100644 index 000000000..28180a16d --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_i32_3d_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_i32_3d_default/input_0.cairo b/tests/nodes/gather_elements_i32_3d_default/input_0.cairo new file mode 100644 index 000000000..e96796beb --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_default/input_0.cairo @@ -0,0 +1,38 @@ +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(4); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + 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: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 12, sign: false }); + data.append(i32 { mag: 13, sign: false }); + data.append(i32 { mag: 14, sign: false }); + data.append(i32 { mag: 15, sign: false }); + data.append(i32 { mag: 16, sign: false }); + data.append(i32 { mag: 17, sign: false }); + data.append(i32 { mag: 18, sign: false }); + data.append(i32 { mag: 19, sign: false }); + data.append(i32 { mag: 20, sign: false }); + data.append(i32 { mag: 21, sign: false }); + data.append(i32 { mag: 22, sign: false }); + data.append(i32 { mag: 23, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_default/input_1.cairo b/tests/nodes/gather_elements_i32_3d_default/input_1.cairo new file mode 100644 index 000000000..2567d760a --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_default/input_1.cairo @@ -0,0 +1,43 @@ +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(5); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + 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(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i32_3d_default/output_0.cairo b/tests/nodes/gather_elements_i32_3d_default/output_0.cairo new file mode 100644 index 000000000..0f8443c80 --- /dev/null +++ b/tests/nodes/gather_elements_i32_3d_default/output_0.cairo @@ -0,0 +1,44 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(5); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 4, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 6, sign: false }); + data.append(i32 { mag: 7, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 9, sign: false }); + data.append(i32 { mag: 10, sign: false }); + data.append(i32 { mag: 11, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_axis1.cairo b/tests/nodes/gather_elements_i8_3d_axis1.cairo new file mode 100644 index 000000000..41807acad --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_axis1.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_i8_3d_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_i8_3d_axis1/input_0.cairo b/tests/nodes/gather_elements_i8_3d_axis1/input_0.cairo new file mode 100644 index 000000000..500932fc7 --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_axis1/input_0.cairo @@ -0,0 +1,22 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_axis1/input_1.cairo b/tests/nodes/gather_elements_i8_3d_axis1/input_1.cairo new file mode 100644 index 000000000..a8c72abbd --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_axis1/input_1.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_axis1/output_0.cairo b/tests/nodes/gather_elements_i8_3d_axis1/output_0.cairo new file mode 100644 index 000000000..0188dc836 --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_axis1/output_0.cairo @@ -0,0 +1,22 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 7, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_default.cairo b/tests/nodes/gather_elements_i8_3d_default.cairo new file mode 100644 index 000000000..422f418bb --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_default.cairo @@ -0,0 +1,24 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8TensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_i8_3d_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_i8_3d_default/input_0.cairo b/tests/nodes/gather_elements_i8_3d_default/input_0.cairo new file mode 100644 index 000000000..500932fc7 --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_default/input_0.cairo @@ -0,0 +1,22 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 6, sign: false }); + data.append(i8 { mag: 7, sign: false }); + data.append(i8 { mag: 8, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_default/input_1.cairo b/tests/nodes/gather_elements_i8_3d_default/input_1.cairo new file mode 100644 index 000000000..f2db2fc85 --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_default/input_1.cairo @@ -0,0 +1,21 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_1() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_i8_3d_default/output_0.cairo b/tests/nodes/gather_elements_i8_3d_default/output_0.cairo new file mode 100644 index 000000000..efd3a5621 --- /dev/null +++ b/tests/nodes/gather_elements_i8_3d_default/output_0.cairo @@ -0,0 +1,22 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 5, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis1.cairo b/tests/nodes/gather_elements_u32_axis1.cairo new file mode 100644 index 000000000..4b8269991 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis1.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_u32_axis1() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_u32_axis1/input_0.cairo b/tests/nodes/gather_elements_u32_axis1/input_0.cairo new file mode 100644 index 000000000..409b07da6 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis1/input_0.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(31); + data.append(32); + data.append(33); + data.append(34); + data.append(35); + data.append(36); + data.append(37); + data.append(38); + data.append(39); + data.append(40); + data.append(41); + data.append(42); + data.append(43); + data.append(44); + data.append(45); + data.append(46); + data.append(47); + data.append(48); + data.append(49); + data.append(50); + data.append(51); + data.append(52); + data.append(53); + data.append(54); + data.append(55); + data.append(56); + data.append(57); + data.append(58); + data.append(59); + data.append(60); + data.append(61); + data.append(62); + data.append(63); + data.append(64); + data.append(65); + data.append(66); + data.append(67); + data.append(68); + data.append(69); + data.append(70); + data.append(71); + data.append(72); + data.append(73); + data.append(74); + data.append(75); + data.append(76); + data.append(77); + data.append(78); + data.append(79); + data.append(80); + data.append(81); + data.append(82); + data.append(83); + data.append(84); + data.append(85); + data.append(86); + data.append(87); + data.append(88); + data.append(89); + data.append(90); + data.append(91); + data.append(92); + data.append(93); + data.append(94); + data.append(95); + data.append(96); + data.append(97); + data.append(98); + data.append(99); + data.append(100); + data.append(101); + data.append(102); + data.append(103); + data.append(104); + data.append(105); + data.append(106); + data.append(107); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis1/input_1.cairo b/tests/nodes/gather_elements_u32_axis1/input_1.cairo new file mode 100644 index 000000000..8c4f4d59f --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis1/input_1.cairo @@ -0,0 +1,194 @@ +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(5); + shape.append(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + 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(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + 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(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis1/output_0.cairo b/tests/nodes/gather_elements_u32_axis1/output_0.cairo new file mode 100644 index 000000000..7efd8fecf --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis1/output_0.cairo @@ -0,0 +1,194 @@ +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(5); + shape.append(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(24); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(17); + data.append(6); + data.append(19); + data.append(32); + data.append(33); + data.append(34); + data.append(23); + data.append(0); + data.append(1); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(19); + data.append(20); + data.append(33); + data.append(22); + data.append(35); + data.append(12); + data.append(1); + data.append(14); + data.append(15); + data.append(4); + data.append(5); + data.append(18); + data.append(19); + data.append(32); + data.append(9); + data.append(22); + data.append(35); + data.append(12); + data.append(25); + data.append(14); + data.append(3); + data.append(16); + data.append(29); + data.append(18); + data.append(7); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(12); + data.append(13); + data.append(2); + data.append(15); + data.append(16); + data.append(29); + data.append(6); + data.append(31); + data.append(20); + data.append(33); + data.append(34); + data.append(11); + data.append(36); + data.append(61); + data.append(62); + data.append(51); + data.append(40); + data.append(41); + data.append(66); + data.append(55); + data.append(68); + data.append(45); + data.append(70); + data.append(47); + data.append(60); + data.append(37); + data.append(62); + data.append(63); + data.append(40); + data.append(53); + data.append(42); + data.append(55); + data.append(44); + data.append(45); + data.append(46); + data.append(59); + data.append(60); + data.append(49); + data.append(50); + data.append(39); + data.append(40); + data.append(65); + data.append(54); + data.append(43); + data.append(68); + data.append(57); + data.append(70); + data.append(47); + data.append(36); + data.append(61); + data.append(62); + data.append(39); + data.append(40); + data.append(53); + data.append(42); + data.append(67); + data.append(68); + data.append(45); + data.append(58); + data.append(47); + data.append(60); + data.append(37); + data.append(50); + data.append(63); + data.append(40); + data.append(65); + data.append(42); + data.append(67); + data.append(68); + data.append(69); + data.append(58); + data.append(71); + data.append(84); + data.append(73); + data.append(86); + data.append(75); + data.append(88); + data.append(101); + data.append(102); + data.append(103); + data.append(92); + data.append(81); + data.append(94); + data.append(95); + data.append(96); + data.append(97); + data.append(98); + data.append(87); + data.append(100); + data.append(101); + data.append(90); + data.append(79); + data.append(80); + data.append(105); + data.append(82); + data.append(83); + data.append(96); + data.append(73); + data.append(74); + data.append(87); + data.append(76); + data.append(89); + data.append(78); + data.append(91); + data.append(104); + data.append(105); + data.append(82); + data.append(83); + data.append(96); + data.append(85); + data.append(86); + data.append(87); + data.append(100); + data.append(77); + data.append(102); + data.append(103); + data.append(92); + data.append(105); + data.append(106); + data.append(107); + data.append(84); + data.append(97); + data.append(86); + data.append(87); + data.append(88); + data.append(77); + data.append(78); + data.append(91); + data.append(80); + data.append(93); + data.append(82); + data.append(83); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis2.cairo b/tests/nodes/gather_elements_u32_axis2.cairo new file mode 100644 index 000000000..84f3927fc --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis2.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_u32_axis2() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(2)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_u32_axis2/input_0.cairo b/tests/nodes/gather_elements_u32_axis2/input_0.cairo new file mode 100644 index 000000000..409b07da6 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis2/input_0.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(31); + data.append(32); + data.append(33); + data.append(34); + data.append(35); + data.append(36); + data.append(37); + data.append(38); + data.append(39); + data.append(40); + data.append(41); + data.append(42); + data.append(43); + data.append(44); + data.append(45); + data.append(46); + data.append(47); + data.append(48); + data.append(49); + data.append(50); + data.append(51); + data.append(52); + data.append(53); + data.append(54); + data.append(55); + data.append(56); + data.append(57); + data.append(58); + data.append(59); + data.append(60); + data.append(61); + data.append(62); + data.append(63); + data.append(64); + data.append(65); + data.append(66); + data.append(67); + data.append(68); + data.append(69); + data.append(70); + data.append(71); + data.append(72); + data.append(73); + data.append(74); + data.append(75); + data.append(76); + data.append(77); + data.append(78); + data.append(79); + data.append(80); + data.append(81); + data.append(82); + data.append(83); + data.append(84); + data.append(85); + data.append(86); + data.append(87); + data.append(88); + data.append(89); + data.append(90); + data.append(91); + data.append(92); + data.append(93); + data.append(94); + data.append(95); + data.append(96); + data.append(97); + data.append(98); + data.append(99); + data.append(100); + data.append(101); + data.append(102); + data.append(103); + data.append(104); + data.append(105); + data.append(106); + data.append(107); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis2/input_1.cairo b/tests/nodes/gather_elements_u32_axis2/input_1.cairo new file mode 100644 index 000000000..aa4e75528 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis2/input_1.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis2/output_0.cairo b/tests/nodes/gather_elements_u32_axis2/output_0.cairo new file mode 100644 index 000000000..a27abae4f --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis2/output_0.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(4); + data.append(2); + data.append(0); + data.append(1); + data.append(5); + data.append(0); + data.append(7); + data.append(5); + data.append(0); + data.append(7); + data.append(2); + data.append(15); + data.append(19); + data.append(20); + data.append(18); + data.append(16); + data.append(20); + data.append(12); + data.append(19); + data.append(17); + data.append(18); + data.append(13); + data.append(14); + data.append(30); + data.append(28); + data.append(29); + data.append(24); + data.append(28); + data.append(29); + data.append(30); + data.append(25); + data.append(26); + data.append(30); + data.append(31); + data.append(32); + data.append(36); + data.append(43); + data.append(44); + data.append(42); + data.append(40); + data.append(41); + data.append(36); + data.append(37); + data.append(44); + data.append(39); + data.append(43); + data.append(38); + data.append(51); + data.append(52); + data.append(56); + data.append(51); + data.append(55); + data.append(50); + data.append(48); + data.append(55); + data.append(50); + data.append(54); + data.append(52); + data.append(53); + data.append(63); + data.append(61); + data.append(65); + data.append(60); + data.append(61); + data.append(68); + data.append(66); + data.append(61); + data.append(62); + data.append(63); + data.append(67); + data.append(65); + data.append(72); + data.append(76); + data.append(74); + data.append(72); + data.append(79); + data.append(74); + data.append(72); + data.append(73); + data.append(74); + data.append(75); + data.append(79); + data.append(80); + data.append(84); + data.append(85); + data.append(89); + data.append(84); + data.append(88); + data.append(92); + data.append(90); + data.append(88); + data.append(86); + data.append(90); + data.append(85); + data.append(86); + data.append(102); + data.append(103); + data.append(104); + data.append(102); + data.append(100); + data.append(104); + data.append(102); + data.append(103); + data.append(98); + data.append(96); + data.append(97); + data.append(104); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis3.cairo b/tests/nodes/gather_elements_u32_axis3.cairo new file mode 100644 index 000000000..7dc511980 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis3.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_u32_axis3() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(3)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_u32_axis3/input_0.cairo b/tests/nodes/gather_elements_u32_axis3/input_0.cairo new file mode 100644 index 000000000..409b07da6 --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis3/input_0.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(31); + data.append(32); + data.append(33); + data.append(34); + data.append(35); + data.append(36); + data.append(37); + data.append(38); + data.append(39); + data.append(40); + data.append(41); + data.append(42); + data.append(43); + data.append(44); + data.append(45); + data.append(46); + data.append(47); + data.append(48); + data.append(49); + data.append(50); + data.append(51); + data.append(52); + data.append(53); + data.append(54); + data.append(55); + data.append(56); + data.append(57); + data.append(58); + data.append(59); + data.append(60); + data.append(61); + data.append(62); + data.append(63); + data.append(64); + data.append(65); + data.append(66); + data.append(67); + data.append(68); + data.append(69); + data.append(70); + data.append(71); + data.append(72); + data.append(73); + data.append(74); + data.append(75); + data.append(76); + data.append(77); + data.append(78); + data.append(79); + data.append(80); + data.append(81); + data.append(82); + data.append(83); + data.append(84); + data.append(85); + data.append(86); + data.append(87); + data.append(88); + data.append(89); + data.append(90); + data.append(91); + data.append(92); + data.append(93); + data.append(94); + data.append(95); + data.append(96); + data.append(97); + data.append(98); + data.append(99); + data.append(100); + data.append(101); + data.append(102); + data.append(103); + data.append(104); + data.append(105); + data.append(106); + data.append(107); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis3/input_1.cairo b/tests/nodes/gather_elements_u32_axis3/input_1.cairo new file mode 100644 index 000000000..76d27a0ff --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis3/input_1.cairo @@ -0,0 +1,230 @@ +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(4); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + 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(1); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + 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(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + 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(0); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_axis3/output_0.cairo b/tests/nodes/gather_elements_u32_axis3/output_0.cairo new file mode 100644 index 000000000..106c0d20f --- /dev/null +++ b/tests/nodes/gather_elements_u32_axis3/output_0.cairo @@ -0,0 +1,230 @@ +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(4); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(5); + data.append(4); + data.append(3); + data.append(3); + data.append(5); + data.append(4); + data.append(8); + data.append(8); + data.append(6); + data.append(7); + data.append(7); + data.append(8); + data.append(9); + data.append(11); + data.append(9); + data.append(11); + data.append(10); + data.append(9); + data.append(12); + data.append(14); + data.append(14); + data.append(14); + data.append(13); + data.append(13); + data.append(15); + data.append(16); + data.append(15); + data.append(16); + data.append(17); + data.append(16); + data.append(19); + data.append(20); + data.append(18); + data.append(18); + data.append(18); + data.append(19); + data.append(22); + data.append(22); + data.append(21); + data.append(22); + data.append(22); + data.append(22); + data.append(26); + data.append(24); + data.append(24); + data.append(24); + data.append(25); + data.append(24); + data.append(28); + data.append(28); + data.append(29); + data.append(27); + data.append(27); + data.append(27); + data.append(31); + data.append(30); + data.append(30); + data.append(30); + data.append(31); + data.append(30); + data.append(35); + data.append(33); + data.append(33); + data.append(34); + data.append(35); + data.append(34); + data.append(37); + data.append(38); + data.append(38); + data.append(37); + data.append(36); + data.append(38); + data.append(41); + data.append(39); + data.append(39); + data.append(40); + data.append(40); + data.append(39); + data.append(44); + data.append(43); + data.append(43); + data.append(44); + data.append(42); + data.append(42); + data.append(45); + data.append(45); + data.append(46); + data.append(45); + data.append(45); + data.append(45); + data.append(49); + data.append(49); + data.append(50); + data.append(48); + data.append(50); + data.append(48); + data.append(51); + data.append(52); + data.append(51); + data.append(51); + data.append(53); + data.append(53); + data.append(54); + data.append(55); + data.append(54); + data.append(56); + data.append(54); + data.append(56); + data.append(57); + data.append(59); + data.append(57); + data.append(58); + data.append(58); + data.append(58); + data.append(61); + data.append(60); + data.append(62); + data.append(60); + data.append(62); + data.append(62); + data.append(64); + data.append(64); + data.append(65); + data.append(64); + data.append(63); + data.append(65); + data.append(66); + data.append(67); + data.append(66); + data.append(68); + data.append(66); + data.append(68); + data.append(69); + data.append(70); + data.append(70); + data.append(69); + data.append(71); + data.append(71); + data.append(74); + data.append(74); + data.append(74); + data.append(72); + data.append(74); + data.append(74); + data.append(77); + data.append(77); + data.append(76); + data.append(75); + data.append(76); + data.append(75); + data.append(79); + data.append(78); + data.append(80); + data.append(80); + data.append(80); + data.append(78); + data.append(82); + data.append(81); + data.append(82); + data.append(82); + data.append(81); + data.append(82); + data.append(84); + data.append(84); + data.append(84); + data.append(84); + data.append(85); + data.append(84); + data.append(88); + data.append(87); + data.append(87); + data.append(89); + data.append(87); + data.append(87); + data.append(92); + data.append(91); + data.append(91); + data.append(90); + data.append(91); + data.append(91); + data.append(95); + data.append(94); + data.append(94); + data.append(94); + data.append(94); + data.append(93); + data.append(98); + data.append(98); + data.append(98); + data.append(98); + data.append(97); + data.append(98); + data.append(99); + data.append(99); + data.append(99); + data.append(99); + data.append(99); + data.append(100); + data.append(102); + data.append(104); + data.append(102); + data.append(102); + data.append(103); + data.append(103); + data.append(106); + data.append(106); + data.append(106); + data.append(106); + data.append(105); + data.append(106); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_default.cairo b/tests/nodes/gather_elements_u32_default.cairo new file mode 100644 index 000000000..f5fe7c1e9 --- /dev/null +++ b/tests/nodes/gather_elements_u32_default.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod input_1; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::U32TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_gather_elements_u32_default() { + let input_0 = input_0::input_0(); + let input_1 = input_1::input_1(); + let z = output_0::output_0(); + + let y = input_0.gather_elements(indices:input_1, axis:Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/gather_elements_u32_default/input_0.cairo b/tests/nodes/gather_elements_u32_default/input_0.cairo new file mode 100644 index 000000000..409b07da6 --- /dev/null +++ b/tests/nodes/gather_elements_u32_default/input_0.cairo @@ -0,0 +1,122 @@ +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(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + data.append(4); + data.append(5); + data.append(6); + data.append(7); + data.append(8); + data.append(9); + data.append(10); + data.append(11); + data.append(12); + data.append(13); + data.append(14); + data.append(15); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(23); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(29); + data.append(30); + data.append(31); + data.append(32); + data.append(33); + data.append(34); + data.append(35); + data.append(36); + data.append(37); + data.append(38); + data.append(39); + data.append(40); + data.append(41); + data.append(42); + data.append(43); + data.append(44); + data.append(45); + data.append(46); + data.append(47); + data.append(48); + data.append(49); + data.append(50); + data.append(51); + data.append(52); + data.append(53); + data.append(54); + data.append(55); + data.append(56); + data.append(57); + data.append(58); + data.append(59); + data.append(60); + data.append(61); + data.append(62); + data.append(63); + data.append(64); + data.append(65); + data.append(66); + data.append(67); + data.append(68); + data.append(69); + data.append(70); + data.append(71); + data.append(72); + data.append(73); + data.append(74); + data.append(75); + data.append(76); + data.append(77); + data.append(78); + data.append(79); + data.append(80); + data.append(81); + data.append(82); + data.append(83); + data.append(84); + data.append(85); + data.append(86); + data.append(87); + data.append(88); + data.append(89); + data.append(90); + data.append(91); + data.append(92); + data.append(93); + data.append(94); + data.append(95); + data.append(96); + data.append(97); + data.append(98); + data.append(99); + data.append(100); + data.append(101); + data.append(102); + data.append(103); + data.append(104); + data.append(105); + data.append(106); + data.append(107); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_default/input_1.cairo b/tests/nodes/gather_elements_u32_default/input_1.cairo new file mode 100644 index 000000000..d1d98f1da --- /dev/null +++ b/tests/nodes/gather_elements_u32_default/input_1.cairo @@ -0,0 +1,374 @@ +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(10); + shape.append(3); + shape.append(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(2); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(2); + 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(2); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(1); + data.append(1); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(1); + data.append(2); + data.append(0); + data.append(1); + data.append(1); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(1); + data.append(0); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(2); + data.append(2); + data.append(0); + data.append(0); + data.append(1); + data.append(0); + data.append(2); + data.append(1); + data.append(0); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/gather_elements_u32_default/output_0.cairo b/tests/nodes/gather_elements_u32_default/output_0.cairo new file mode 100644 index 000000000..5bd86a8bd --- /dev/null +++ b/tests/nodes/gather_elements_u32_default/output_0.cairo @@ -0,0 +1,374 @@ +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(10); + shape.append(3); + shape.append(4); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(37); + data.append(38); + data.append(39); + data.append(4); + data.append(77); + data.append(42); + data.append(79); + data.append(80); + data.append(45); + data.append(46); + data.append(83); + data.append(84); + data.append(49); + data.append(50); + data.append(15); + data.append(52); + data.append(17); + data.append(54); + data.append(91); + data.append(20); + data.append(93); + data.append(22); + data.append(59); + data.append(96); + data.append(25); + data.append(98); + data.append(99); + data.append(64); + data.append(65); + data.append(30); + data.append(31); + data.append(32); + data.append(105); + data.append(34); + data.append(35); + data.append(72); + data.append(37); + data.append(74); + data.append(39); + data.append(76); + data.append(41); + data.append(78); + data.append(79); + data.append(80); + data.append(81); + data.append(82); + data.append(11); + data.append(48); + data.append(13); + data.append(50); + data.append(15); + data.append(88); + data.append(53); + data.append(54); + data.append(19); + data.append(20); + data.append(93); + data.append(22); + data.append(23); + data.append(60); + data.append(61); + data.append(98); + data.append(99); + data.append(64); + data.append(65); + data.append(102); + data.append(31); + data.append(32); + data.append(105); + data.append(70); + data.append(107); + data.append(0); + data.append(1); + data.append(74); + data.append(39); + data.append(40); + data.append(5); + data.append(78); + data.append(79); + data.append(44); + data.append(45); + data.append(10); + data.append(11); + data.append(84); + data.append(49); + data.append(14); + data.append(51); + data.append(16); + data.append(17); + data.append(54); + data.append(55); + data.append(92); + data.append(57); + data.append(94); + data.append(95); + data.append(24); + data.append(61); + data.append(98); + data.append(99); + data.append(28); + data.append(101); + data.append(102); + data.append(103); + data.append(104); + data.append(69); + data.append(34); + data.append(35); + data.append(36); + data.append(73); + data.append(2); + data.append(75); + data.append(40); + data.append(41); + data.append(78); + data.append(79); + data.append(8); + data.append(9); + data.append(10); + data.append(83); + data.append(12); + data.append(49); + data.append(86); + data.append(51); + data.append(52); + data.append(53); + data.append(18); + data.append(55); + data.append(56); + data.append(57); + data.append(94); + data.append(59); + data.append(60); + data.append(61); + data.append(98); + data.append(99); + data.append(28); + data.append(65); + data.append(30); + data.append(67); + data.append(104); + data.append(69); + data.append(70); + data.append(35); + data.append(36); + data.append(73); + data.append(2); + data.append(75); + data.append(40); + data.append(41); + data.append(78); + data.append(43); + data.append(8); + data.append(9); + data.append(10); + data.append(47); + data.append(84); + data.append(85); + data.append(14); + data.append(87); + data.append(52); + data.append(53); + data.append(18); + data.append(55); + data.append(92); + data.append(21); + data.append(94); + data.append(95); + data.append(24); + data.append(25); + data.append(26); + data.append(27); + data.append(28); + data.append(65); + data.append(30); + data.append(103); + data.append(104); + data.append(69); + data.append(34); + data.append(107); + data.append(72); + data.append(1); + data.append(2); + data.append(75); + data.append(76); + data.append(5); + data.append(42); + data.append(7); + data.append(80); + data.append(45); + data.append(82); + data.append(11); + data.append(48); + data.append(49); + data.append(86); + data.append(87); + data.append(88); + data.append(53); + data.append(54); + data.append(91); + data.append(20); + data.append(93); + data.append(94); + data.append(23); + data.append(96); + data.append(25); + data.append(26); + data.append(27); + data.append(64); + data.append(65); + data.append(102); + data.append(31); + data.append(68); + data.append(33); + data.append(70); + data.append(71); + data.append(36); + data.append(73); + data.append(38); + data.append(3); + data.append(40); + data.append(5); + data.append(6); + data.append(79); + data.append(80); + data.append(45); + data.append(46); + data.append(11); + data.append(84); + data.append(49); + data.append(86); + data.append(51); + data.append(16); + data.append(17); + data.append(18); + data.append(19); + data.append(56); + data.append(57); + data.append(22); + data.append(59); + data.append(24); + data.append(61); + data.append(62); + data.append(99); + data.append(64); + data.append(101); + data.append(30); + data.append(103); + data.append(104); + data.append(105); + data.append(70); + data.append(35); + data.append(72); + data.append(37); + data.append(38); + data.append(75); + data.append(40); + data.append(41); + data.append(42); + data.append(43); + data.append(8); + data.append(81); + data.append(82); + data.append(83); + data.append(12); + data.append(85); + data.append(86); + data.append(15); + data.append(16); + data.append(89); + data.append(18); + data.append(19); + data.append(20); + data.append(21); + data.append(22); + data.append(95); + data.append(24); + data.append(97); + data.append(26); + data.append(27); + data.append(28); + data.append(101); + data.append(102); + data.append(67); + data.append(68); + data.append(105); + data.append(70); + data.append(107); + data.append(72); + data.append(37); + data.append(2); + data.append(3); + data.append(4); + data.append(77); + data.append(78); + data.append(7); + data.append(80); + data.append(81); + data.append(10); + data.append(11); + data.append(84); + data.append(49); + data.append(50); + data.append(15); + data.append(16); + data.append(53); + data.append(54); + data.append(55); + data.append(20); + data.append(57); + data.append(58); + data.append(95); + data.append(60); + data.append(61); + data.append(98); + data.append(63); + data.append(28); + data.append(29); + data.append(66); + data.append(67); + data.append(68); + data.append(105); + data.append(70); + data.append(71); + data.append(0); + data.append(73); + data.append(38); + data.append(3); + data.append(76); + data.append(77); + data.append(78); + data.append(7); + data.append(44); + data.append(9); + data.append(46); + data.append(47); + data.append(84); + data.append(13); + data.append(50); + data.append(51); + data.append(16); + data.append(17); + data.append(54); + data.append(19); + data.append(56); + data.append(21); + data.append(22); + data.append(95); + data.append(24); + data.append(97); + data.append(98); + data.append(99); + data.append(28); + data.append(29); + data.append(66); + data.append(31); + data.append(104); + data.append(69); + data.append(34); + data.append(35); + TensorTrait::new(shape.span(), data.span()) +} From 71919ec88e33f885acf5107bc7af8e924f479664 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 20 Nov 2023 12:24:21 +0100 Subject: [PATCH 095/160] missing closing brace --- src/operators/tensor/implementations/tensor_bool.cairo | 3 ++- src/operators/tensor/implementations/tensor_fp16x16.cairo | 1 + src/operators/tensor/implementations/tensor_fp32x32.cairo | 1 + src/operators/tensor/implementations/tensor_fp64x64.cairo | 1 + src/operators/tensor/implementations/tensor_fp8x23.cairo | 1 + src/operators/tensor/implementations/tensor_fp8x23wide.cairo | 1 + src/operators/tensor/implementations/tensor_i32.cairo | 1 + src/operators/tensor/implementations/tensor_u32.cairo | 1 + 8 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 9b71e6a65..f06f95be0 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -314,8 +314,9 @@ impl BoolTensor of TensorTrait { fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } -fn sequence_construct(tensors: Array>) -> Array> { + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 0e3563c23..f3a1ac1e8 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -353,6 +353,7 @@ impl FP16x16Tensor of TensorTrait { self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 67f799a86..2c7ed596d 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -354,6 +354,7 @@ impl FP32x32Tensor of TensorTrait { self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 995a4c21f..385635fef 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -354,6 +354,7 @@ impl FP64x64Tensor of TensorTrait { self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index e93665141..40ad7df0c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -345,6 +345,7 @@ impl FP8x23Tensor of TensorTrait { self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8576ed369..1b1193c37 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -332,6 +332,7 @@ impl FP8x23WTensor of TensorTrait { self: @Tensor, indices: Tensor, axis: Option ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 54f091b7d..7c963edbc 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -351,6 +351,7 @@ impl I32Tensor of TensorTrait { fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 0da01cf6a..fa48370e4 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -321,6 +321,7 @@ impl U32Tensor of TensorTrait { fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) + } fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) From 59ffcaba786d919939e8fb087447423e6e5079c6 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Mon, 20 Nov 2023 13:13:40 +0100 Subject: [PATCH 096/160] removed in gather_elements cairo tests --- .../tensor/math/gather_elements.cairo | 659 +----------------- 1 file changed, 1 insertion(+), 658 deletions(-) diff --git a/src/operators/tensor/math/gather_elements.cairo b/src/operators/tensor/math/gather_elements.cairo index ef365e06d..dd9b9aa83 100644 --- a/src/operators/tensor/math/gather_elements.cairo +++ b/src/operators/tensor/math/gather_elements.cairo @@ -119,661 +119,4 @@ fn gather_elements< let mut output_tensor = TensorTrait::::new(indices.shape, output_data.span()); return output_tensor; -} - - -// Tests-------------------------------------------------------------------------------------------------------------- - - -use orion::numbers::fixed_point::implementations::fp8x23::helpers::assert_precise; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::I32TensorPartialEq; -use orion::utils::assert_eq; - - -fn indices1() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(5); - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(0); - data.append(2); - data.append(2); - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn indices() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(2); - data.append(1); - data.append(0); - data.append(1); - data.append(2); - data.append(0); - data.append(1); - - TensorTrait::new(shape.span(), data.span()) -} - -fn indices2() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(1); - data.append(2); - data.append(1); - data.append(0); - data.append(1); - data.append(2); - data.append(1); - data.append(0); - data.append(2); - data.append(1); - data.append(1); - data.append(2); - data.append(1); - data.append(0); - data.append(2); - data.append(1); - - TensorTrait::new(shape.span(), data.span()) -} - -fn indices22() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - 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(1); - data.append(1); - data.append(0); - data.append(1); - data.append(1); - - TensorTrait::new(shape.span(), data.span()) -} - -fn data1() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(5); - - let mut data = ArrayTrait::new(); - data.append(1); - data.append(2); - data.append(3); - data.append(4); - data.append(5); - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn data() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(3); - - let mut data = ArrayTrait::new(); - data.append(1); - data.append(2); - data.append(3); - data.append(4); - data.append(5); - data.append(6); - data.append(7); - data.append(8); - data.append(9); - - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn data2() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(3); - sizes.append(2); - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(2); - data.append(3); - data.append(4); - data.append(5); - data.append(6); - data.append(7); - data.append(8); - data.append(9); - data.append(10); - data.append(11); - data.append(12); - data.append(13); - data.append(14); - data.append(15); - data.append(16); - data.append(17); - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn data3() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(3); - sizes.append(3); - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(2); - data.append(3); - data.append(4); - data.append(5); - data.append(6); - data.append(7); - data.append(8); - data.append(9); - data.append(10); - data.append(11); - data.append(12); - data.append(13); - data.append(14); - data.append(15); - data.append(16); - data.append(17); - data.append(18); - data.append(19); - data.append(20); - data.append(21); - data.append(22); - data.append(23); - data.append(24); - data.append(25); - data.append(26); - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn u32_tensor_3x2x3x2_index() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(2); - sizes.append(3); - sizes.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - 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); - data.append(1); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn u32_tensor_3x2x3x2_helper() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(2); - sizes.append(3); - sizes.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(2); - data.append(3); - data.append(4); - data.append(5); - data.append(6); - data.append(7); - data.append(8); - data.append(9); - data.append(10); - data.append(11); - data.append(12); - data.append(13); - data.append(14); - data.append(15); - data.append(16); - data.append(17); - data.append(18); - data.append(19); - data.append(20); - data.append(21); - data.append(22); - data.append(23); - data.append(24); - data.append(25); - data.append(26); - data.append(27); - data.append(28); - data.append(29); - data.append(30); - data.append(31); - data.append(32); - data.append(33); - data.append(34); - data.append(35); - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn u32_tensor_3x2x3x2_index0() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(2); - sizes.append(2); - sizes.append(3); - sizes.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - 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); - data.append(1); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -fn u32_tensor_3x2x3x2_index2() -> Tensor { - let mut sizes = ArrayTrait::new(); - sizes.append(3); - sizes.append(2); - sizes.append(4); - sizes.append(2); - - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - - 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); - data.append(1); - - data.append(0); - data.append(1); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - - data.append(1); - data.append(0); - data.append(1); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - data.append(0); - - - let tensor = TensorTrait::::new(sizes.span(), data.span()); - - return tensor; -} - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements_default() { -// let data = data2(); -// let indices = indices22(); - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; - -// // loop { -// // match output.pop_front() { -// // Option::Some(val) => { -// // (*val).print(); -// // }, -// // Option::None(_) => { break; } -// // }; -// // }; - -// } - - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3error_work() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index0(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3error1() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index0(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3error2() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index0(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); -// let mut output = y.data; -// } - - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3error3() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index0(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(3)); -// let mut output = y.data; -// } - - - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3errorSecond0() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index2(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3errorSecond1() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index2(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3errorSecondwork() { -// let data = u32_tensor_3x2x3x2_helper(); -// let indices = u32_tensor_3x2x3x2_index2(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); -// let mut output = y.data; -// } - - - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements_axis_1() { -// let data = data2(); -// let indices = indices22(); - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; - -// assert(*output[0] == 0, 'not correct'); -// assert(*output[1] == 3, 'not correct'); -// assert(*output[2] == 2, 'not correct'); -// assert(*output[3] == 3, 'not correct'); -// assert(*output[4] == 2, 'not correct'); -// assert(*output[5] == 1, 'not correct'); -// assert(*output[6] == 8, 'not correct'); -// assert(*output[7] == 9, 'not correct'); -// assert(*output[8] == 8, 'not correct'); -// assert(*output[9] == 7, 'not correct'); -// assert(*output[10] == 8, 'not correct'); -// assert(*output[11] == 9, 'not correct'); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; - - - -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3_lastaxis() { -// let data = data(); -// let indices = indices(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(1)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 2, 'not correct'); -// assert(*output[2] == 3, 'not correct'); -// assert(*output[3] == 5, 'not correct'); -// assert(*output[4] == 4, 'not correct'); -// assert(*output[5] == 5, 'not correct'); - -// } - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements2_lastaxis() { -// let data = data2(); -// let indices = indices22(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(2)); -// let mut output = y.data; - -// assert(*output[0] == 0, 'not correct'); -// assert(*output[1] == 1, 'not correct'); -// assert(*output[2] == 3, 'not correct'); -// assert(*output[3] == 3, 'not correct'); -// assert(*output[4] == 5, 'not correct'); -// assert(*output[5] == 4, 'not correct'); -// assert(*output[6] == 7, 'not correct'); -// assert(*output[7] == 7, 'not correct'); -// assert(*output[8] == 9, 'not correct'); -// assert(*output[9] == 8, 'not correct'); -// assert(*output[10] == 11, 'not correct'); -// assert(*output[11] == 11, 'not correct'); - -// } - -// #[test] -// #[available_gas(20000000000)] -// fn test_gather_elements2() { -// let data = data2(); -// let indices = indices22(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 0, 'not correct'); -// assert(*output[1] == 7, 'not correct'); -// assert(*output[2] == 8, 'not correct'); -// assert(*output[3] == 9, 'not correct'); -// assert(*output[4] == 10, 'not correct'); -// assert(*output[5] == 5, 'not correct'); -// assert(*output[6] == 6, 'not correct'); -// assert(*output[7] == 7, 'not correct'); -// assert(*output[8] == 8, 'not correct'); -// assert(*output[9] == 3, 'not correct'); - -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_1() { -// let data = data1(); -// let indices = indices1(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 2, 'not correct'); -// assert(*output[2] == 1, 'not correct'); -// assert(*output[3] == 3, 'not correct'); -// assert(*output[4] == 3, 'not correct'); -// } - -// #[test] -// #[available_gas(2000000000)] -// fn test_gather_elements_3() { -// let data = data(); -// let indices = indices(); - - -// let y = data.gather_elements(indices: indices, axis:Option::Some(0)); -// let mut output = y.data; - -// assert(*output[0] == 1, 'not correct'); -// assert(*output[1] == 5, 'not correct'); -// assert(*output[2] == 9, 'not correct'); -// assert(*output[3] == 4, 'not correct'); -// assert(*output[4] == 2, 'not correct'); -// assert(*output[5] == 6, 'not correct'); - -// } \ No newline at end of file +} \ No newline at end of file From 9ceb845817af86f8d1daaed924fefe33cb058938 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 21 Nov 2023 11:56:38 +0200 Subject: [PATCH 097/160] Update orion-usage.md --- orion-usage.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/orion-usage.md b/orion-usage.md index a24a8ef7f..855254937 100644 --- a/orion-usage.md +++ b/orion-usage.md @@ -48,18 +48,27 @@ Discover ML models made by the community with Orion! | Bem Baraki | [Linear Regression](https://github.com/BemTG/Verifiable-Linear-Regression-) | | Raphael Doukhan | [MNIST MLP](https://github.com/gizatechxyz/orion_tutorials/blob/main/mnist_nn/QAT_MNIST_MLP.ipynb) | +# Spaces + +Discover amazing ML apps and POCs made by the community with Orion! + +| Author | Title | +| --------------------------------- | ------------------------------------------------------------------------------------------- | +| ownerofjk, umburloko, coostendorp | [Tic Tac Toe in PixeLAW with ML Bot](https://github.com/OwnerOfJK/TicTacToeAgent/tree/main) | + ## Hackathon Projects -| Author | Event | Title | Prizes | -| --------------------- | -------------- | -------------------------------------------------------------------------------------- | ------------------ | -| manuj-mishra | Lambda ZK week | [ZK Differential Privacy](https://github.com/manuj-mishra/zkdiffpriv) | 🏅 | -| codingnirvana | Lambda ZK week | [Cairo Convolution ](https://github.com/gizatechxyz/orion/pull/160) | | -| danilo, richie, falco | ETHGlobal | [Cairo Einsum](https://x.com/danilowhk2/status/1683138159985545216?s=20) | 🥇 (Starknet track) | -| 0xbyyou | ETHToronto | [Cairo Logistic Regression](https://x.com/gizatechxyz/status/1695016787698417770?s=20) | | +| Author | Event | Title | Prizes | +| --------------------------------- | -------------- | ------------------------------------------------------------------------------------------- | ------------------ | +| manuj-mishra | Lambda ZK week | [ZK Differential Privacy](https://github.com/manuj-mishra/zkdiffpriv) | 🏅 | +| codingnirvana | Lambda ZK week | [Cairo Convolution ](https://github.com/gizatechxyz/orion/pull/160) | | +| danilo, richie, falco | ETHGlobal | [Cairo Einsum](https://x.com/danilowhk2/status/1683138159985545216?s=20) | 🥇 (Starknet track) | +| 0xbyyou | ETHToronto | [Cairo Logistic Regression](https://x.com/gizatechxyz/status/1695016787698417770?s=20) | | +| ownerofjk, umburloko, coostendorp | ETHGlobal Ist. | [Tic Tac Toe in PixeLAW with ML Bot](https://github.com/OwnerOfJK/TicTacToeAgent/tree/main) | 🥇 (Starknet track) | ## Use Cases | Author | Title | Description | | ----------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | StorSwift | Verifiable Medical Diagnosis | A verifiable medical diagnosis web3 app. The aim is to create a robust and reliable platform to empower individuals in their healthcare decision-making process | -| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model in fraud detection and analysis of bank transaction alerts. | +| dblancove & dataonchain | Fraud Detection with Verifiable ML | A verifiable anomaly detection model in fraud detection and analysis of bank transaction alerts. | From f04aff57381ac46dbd253880421e4c6f71e74e36 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 21 Nov 2023 14:36:06 +0200 Subject: [PATCH 098/160] Update tensor_bool.cairo --- .../tensor/implementations/tensor_bool.cairo | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d24d9a88b..3dae7647d 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -273,6 +273,18 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor:: { + panic(array!['not supported!']) + } fn round(self: @Tensor) -> Tensor { panic(array!['not supported!']) From c924f813662f07ec37d96b04ec5259d1b19376f9 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 21 Nov 2023 14:43:15 +0200 Subject: [PATCH 099/160] Update tensor_bool.cairo --- .../tensor/implementations/tensor_bool.cairo | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 3dae7647d..b373d03b7 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -286,6 +286,17 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn round(self: @Tensor) -> Tensor { panic(array!['not supported!']) } From 0664a274493e8878fe06beaa97833692d84efc2b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Tue, 21 Nov 2023 15:02:19 +0200 Subject: [PATCH 100/160] Update qlinear_concat_test.cairo --- tests/operators/qlinear_concat_test.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/operators/qlinear_concat_test.cairo b/tests/operators/qlinear_concat_test.cairo index c2d18ee28..ea2a982fc 100644 --- a/tests/operators/qlinear_concat_test.cairo +++ b/tests/operators/qlinear_concat_test.cairo @@ -73,7 +73,6 @@ fn qlinear_concat_test() { let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); - print_span(actual_output.data); assert((*actual_output.data[0]).into() == 3, '*result[0] == 3'); assert((*actual_output.data[1]).into() == 6, '*result[1] == 6'); assert((*actual_output.data[2]).into() == 9, '*result[2] == 9'); From b43bc3dfe5536bb6d01063dacbcf24de4745ac2f Mon Sep 17 00:00:00 2001 From: zhangzhichao Date: Wed, 22 Nov 2023 15:17:13 +0800 Subject: [PATCH 101/160] fixed: Tree x_value get from nodes_featureids in TreeEnsembleClassifier operator --- src/operators/ml/tree_ensemble/core.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operators/ml/tree_ensemble/core.cairo b/src/operators/ml/tree_ensemble/core.cairo index a54295822..08fed475d 100644 --- a/src/operators/ml/tree_ensemble/core.cairo +++ b/src/operators/ml/tree_ensemble/core.cairo @@ -59,7 +59,7 @@ impl TreeEnsembleImpl< NODE_MODES::LEAF => { break; }, }; - let x_value = *x.at(*(self.atts.nodes_missing_value_tracks_true).at(index)); + let x_value = *x.at(*(self.atts.nodes_featureids).at(index)); let r = if x_value.is_nan() { *self.atts.nodes_missing_value_tracks_true.at(index) >= 1 } else { From 3b046cf6a0da26f6ccde2e0139c8772bb1a22a3e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 07:54:42 +0000 Subject: [PATCH 102/160] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3631dc7cc..30592d048 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -99,6 +99,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Ephraim Chukwu
Ephraim Chukwu

💻 Bal7hazar
Bal7hazar

🐛 Tony Stark
Tony Stark

📖 + HappyTomatoo
HappyTomatoo

🐛 From 987acd08789c6f18be78b5894f32a17f9e202d78 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 07:54:43 +0000 Subject: [PATCH 103/160] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b282fc04..99b9c7eac 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -224,6 +224,15 @@ "contributions": [ "doc" ] + }, + { + "login": "HappyTomatoo", + "name": "HappyTomatoo", + "avatar_url": "https://avatars.githubusercontent.com/u/143050661?v=4", + "profile": "https://github.com/HappyTomatoo", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, From 6006c0da46b21bbe8b89c006b0f85dd4008ee084 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 22 Nov 2023 18:48:05 +0200 Subject: [PATCH 104/160] generate doc --- .../tensor/tensor.sequence_insert.md | 55 +++++++++++++++++++ src/operators/tensor/core.cairo | 10 ---- 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.sequence_insert.md diff --git a/docs/framework/operators/tensor/tensor.sequence_insert.md b/docs/framework/operators/tensor/tensor.sequence_insert.md new file mode 100644 index 000000000..3f5ae339e --- /dev/null +++ b/docs/framework/operators/tensor/tensor.sequence_insert.md @@ -0,0 +1,55 @@ +# tensor.sequence_insert + +```rust + fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; +``` + +Returns a tensor sequence that inserts 'tensor' into 'self' at 'position'. + +## Args + +* `self`(`Array>`) - input sequence. +* `tensor` (`@Tensor`) - the tensor to insert. +* `position` (`@Tensor`) - the index for insertion (default: -1). + +## Returns + +Tensor sequence containing 'tensor' inserted into 'self' at 'position'. + +## Examples + +Let's insert the tensor [2] into the sequence [[1], [3]] at position 1. +use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + +fn sequence_insert_example() -> Array> { + // Prepare sequence + let mut sequence = ArrayTrait::new(); + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + sequence.append(TensorTrait::new(shape.span(), data.span())); + let mut data = ArrayTrait::new(); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + // Prepare input tensor + let mut data = ArrayTrait::new(); + data.append(2); + let tensor = TensorTrait::new(shape.span(), data.span()); + + // Prepare position + let mut shape = ArrayTrait::::new(); + let mut data = ArrayTrait::::new(); + data.append(i32 { mag: 1, sign: false }); + let position = TensorTrait::::new(shape.span(), data.span()) + + let sequence = self.sequence_insert(tensor, Option::Some(position)); + + return sequence; +} + +>>> [[1], [2], [3]] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index bc10b9da8..61d0fcb22 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -77,9 +77,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde { /// # tensor.new From 345df5dfd7be2936f53279841c7c74524ff45c98 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Wed, 22 Nov 2023 19:00:53 +0200 Subject: [PATCH 105/160] fix doc --- docs/framework/operators/tensor/README.md | 16 ++++++++-------- .../operators/tensor/tensor.sequence_empty.md | 2 +- src/operators/tensor/core.cairo | 11 +++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d5f6c6d7f..a728eb223 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -81,9 +81,9 @@ use orion::operators::tensor::TensorTrait; | [`tensor.quantize_linear`](tensor.quantize\_linear.md) | Quantizes a Tensor to i8 using linear quantization. | | [`tensor.dequantize_linear`](tensor.dequantize\_linear.md) | Dequantizes an i8 Tensor using linear dequantization. | | [`tensor.qlinear_add`](tensor.qlinear\_add.md) | Performs the sum of two quantized i8 Tensors. | -| [`tensor.qlinear_mul`](tensor.qlinear\_mul.md) | Performs the element-wise multiplication of two quantized i8 Tensors. | +| [`tensor.qlinear_mul`](tensor.qlinear\_mul.md) | Performs the element-wise multiplication of quantized Tensors. | | [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. | -| [`tensor.qlinear_concat`](tensor.qlinear\_concat.md) | Performs the concatenation of a list of quantized i8 Tensors. | +| [`tensor.qlinear_concat`](tensor.qlinear\_concat.md) | Concatenate a list of tensors after dequantizing them with their respective scales and zero_points and returns the quantized result. | | [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. | | [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). | | [`tensor.squeeze`](tensor.squeeze.md) | Removes dimensions of size 1 from the shape of a tensor. | @@ -98,17 +98,17 @@ use orion::operators::tensor::TensorTrait; | [`tensor.reduce_l1`](tensor.reduce\_l1.md) | Computes the L1 norm of the input tensor's elements along the provided axes. | | [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. | | [`tensor.scatter`](tensor.scatter.md) | Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices. | -| [`tensor.array_feature_extractor`](tensor.array_feature_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | -| [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | +| [`tensor.sequence_insert`](tensor.sequence\_insert.md) | Insert a tensor into a sequence. | | [`tensor.sequence_at`](tensor.sequence\_at.md) | Outputs the tensor at the specified position in the input sequence. | -| [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | | [`tensor.sequence_construct`](tensor.sequence\_construct.md) | Constructs a tensor sequence containing the input tensors. | -| [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | -| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | +| [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor. | | [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | -| [`tensor.sequence_insert`](tensor.sequence\_insert.md) | Insert a tensor into a sequence. | +| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | +| [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | +| [`tensor.array_feature_extractor`](tensor.array\_feature\_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | +| [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.sequence_empty.md b/docs/framework/operators/tensor/tensor.sequence_empty.md index a95f952b9..a46ddba5f 100644 --- a/docs/framework/operators/tensor/tensor.sequence_empty.md +++ b/docs/framework/operators/tensor/tensor.sequence_empty.md @@ -1,6 +1,6 @@ # tensor.sequence_empty -```rust +```rust fn sequence_empty() -> Array>; ``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 61d0fcb22..25a57aa6b 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -77,7 +77,9 @@ impl TensorSerde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde { /// # tensor.new /// From f8ff198bb45990cc2c9749d2cb590693b661b553 Mon Sep 17 00:00:00 2001 From: chachaleo Date: Fri, 17 Nov 2023 21:44:30 +0700 Subject: [PATCH 106/160] feat: qlinear leaky relu --- src/operators/tensor/core.cairo | 81 +++++++++++++++++++ .../tensor/implementations/tensor_bool.cairo | 9 +++ .../implementations/tensor_fp16x16.cairo | 17 ++++ .../implementations/tensor_fp16x16wide.cairo | 10 +++ .../implementations/tensor_fp32x32.cairo | 17 ++++ .../implementations/tensor_fp64x64.cairo | 17 ++++ .../implementations/tensor_fp8x23.cairo | 18 +++++ .../implementations/tensor_fp8x23wide.cairo | 10 +++ .../tensor/implementations/tensor_i32.cairo | 16 ++++ .../tensor/implementations/tensor_i8.cairo | 19 ++++- .../tensor/implementations/tensor_u32.cairo | 10 +++ src/operators/tensor/quantization.cairo | 1 + .../quantization/qlinear_leakyrelu.cairo | 60 ++++++++++++++ tests/operators.cairo | 1 + tests/operators/qlinear_leakyrelu_test.cairo | 52 ++++++++++++ 15 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 src/operators/tensor/quantization/qlinear_leakyrelu.cairo create mode 100644 tests/operators/qlinear_leakyrelu_test.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 5a3cf5936..3da2bd76a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3011,6 +3011,87 @@ trait TensorTrait { y_zero_point: @Tensor, axis: usize ) -> Tensor::; + /// # tensor.qlinear_leakyrelu + /// + /// ```rust + /// fn qlinear_leakyrelu(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T) -> Tensor::; + /// ``` + /// + /// Apply the Leaky Relu operator to a quantized Tensor + /// + /// QLinar LeakyRelu takes as input a quantized Tensor, its scale and zero point and an scalar alpha, and produces one output data (a quantized Tensor) + /// where the function `f(x) = alpha * x for x < 0, f(x) = x for x >= 0`, is applied to the data tensor elementwise. + /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). + /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). + /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `a_scale`(`@Tensor`) - Scale for input `a`. + /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. + /// * `alpha`(`T`) - The factor multiplied to negative elements. + /// + /// ## Returns + /// + /// A new `Tensor`, containing result of the Leaky Relu. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// bool tensor, not supported. + /// + /// ## Example + /// + /// ```rust + + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// + /// fn qlinear_leakyrelu_example() -> Tensor { + /// let a = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 3].span(), + /// data: array![ + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, false), + /// IntegerTrait::::new(10_u8, false), + /// IntegerTrait::::new(10_u8, false) + /// ] + /// .span(), + /// ); + /// + /// let a_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + /// let a_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + /// + /// let alpha = FixedTrait::::new(655360, false); + /// + /// return = a + /// .qlinear_leakyrelu( + /// @a_scale, @a_zero_point, alpha + /// ); + /// } + /// + /// >>> [[-118, -118, -118], [10, 10, 10]] + /// + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: T + ) -> Tensor::; /// # tensor.slice /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 0dd00f8ea..00ea6a3ce 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -296,6 +296,15 @@ impl BoolTensor of TensorTrait { ) -> Tensor:: { panic(array!['not supported!']) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: bool, + ) -> 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 5e22d89c0..f87a8c1f6 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -303,6 +303,23 @@ impl FP16x16Tensor of TensorTrait { ) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP16x16 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1eff6975d..f47b88210 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -267,6 +267,16 @@ impl FP16x16WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP16x16W + + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index a6a5a1828..7b239a565 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -304,6 +304,23 @@ impl FP32x32Tensor of TensorTrait { ) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP32x32 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index d9aa80a58..304e0d366 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -304,6 +304,23 @@ impl FP64x64Tensor of TensorTrait { ) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP64x64 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 9f2e9d822..d9fad88fa 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -303,6 +303,24 @@ impl FP8x23Tensor of TensorTrait { ) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP8x23 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index ea75501fb..d58bd1481 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -261,6 +261,16 @@ impl FP8x23WTensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: FP8x23W + + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index facc8a59a..27b4ad99b 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -304,6 +304,22 @@ impl I32Tensor of TensorTrait { ) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: i32 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } fn slice( self: @Tensor, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 02ef9ff66..af7eec0ac 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -297,7 +297,24 @@ impl I8Tensor of TensorTrait { zero_points, y_scale, y_zero_point, - axis, + axis, + NumberTrait::new_unscaled(128, true), + NumberTrait::new_unscaled(127, false) + ) + } + + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: i8 + + ) -> Tensor:: { + quantization::qlinear_leakyrelu::qlinear_leakyrelu( + self, + a_scale, + a_zero_point, + alpha, NumberTrait::new_unscaled(128, true), NumberTrait::new_unscaled(127, false) ) diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 15575d969..184ea2896 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -255,6 +255,16 @@ impl U32Tensor of TensorTrait { panic(array!['not supported!']) } + fn qlinear_leakyrelu( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: u32 + + ) -> Tensor:: { + panic(array!['not supported!']) + } + fn slice( self: @Tensor, starts: Span, diff --git a/src/operators/tensor/quantization.cairo b/src/operators/tensor/quantization.cairo index 4e88d8df4..559dc061e 100644 --- a/src/operators/tensor/quantization.cairo +++ b/src/operators/tensor/quantization.cairo @@ -4,3 +4,4 @@ mod qlinear_matmul; mod qlinear_concat; mod qlinear_add; mod qlinear_mul; +mod qlinear_leakyrelu; diff --git a/src/operators/tensor/quantization/qlinear_leakyrelu.cairo b/src/operators/tensor/quantization/qlinear_leakyrelu.cairo new file mode 100644 index 000000000..56cb58292 --- /dev/null +++ b/src/operators/tensor/quantization/qlinear_leakyrelu.cairo @@ -0,0 +1,60 @@ +use array::ArrayTrait; +use array::SpanTrait; +use option::OptionTrait; + +use orion::numbers::{NumberTrait}; +use orion::operators::tensor::quantization::dequantize_linear::dequantize_linear; +use orion::operators::tensor::quantization::quantize_linear::quantize_linear; +use orion::operators::tensor::{TensorTrait, Tensor}; + +fn qlinear_leakyrelu< + T, + MAG, + Q, + impl TTensor: TensorTrait, + impl QTensor: TensorTrait, + impl QIntoT: Into, + impl QTensorIntoTTensor: Into, Tensor>, + impl TAdd: Add, + impl TSub: Sub, + impl TDiv: Div, + impl TMul: Mul, + impl TTensorAdd: Add>, + impl TTensorSub: Sub>, + impl TTensorMul: Mul>, + impl TTensorDiv: Div>, + impl TPartialOrd: PartialOrd, + impl TNumber: NumberTrait, + impl TTryInto: TryInto, + impl TAddEq: AddEq, + impl TCopy: Copy, + impl TDrop: Drop, + impl QCopy: Copy, + impl QDrop: Drop +>( + a: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + alpha: T, + min: T, + max: T +) -> Tensor { + let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); + + let mut result_data = ArrayTrait::::new(); + let mut i = 0; + loop { + match dequantized_a.data.pop_front() { + Option::Some(elem) => { + if *elem < NumberTrait::zero() { + result_data.append(*elem * alpha); + } else { + result_data.append(*elem); + } + }, + Option::None(_) => { break;} + }; + }; + + return quantize_linear(@TensorTrait::new(dequantized_a.shape, result_data.span()), a_scale, a_zero_point, min, max); +} diff --git a/tests/operators.cairo b/tests/operators.cairo index a47fc8248..d02bf25a4 100644 --- a/tests/operators.cairo +++ b/tests/operators.cairo @@ -3,3 +3,4 @@ mod qlinear_matmul_test; mod qlinear_concat_test; mod qlinear_add_test; mod constant_of_shape_test; +mod qlinear_leakyrelu_test; diff --git a/tests/operators/qlinear_leakyrelu_test.cairo b/tests/operators/qlinear_leakyrelu_test.cairo new file mode 100644 index 000000000..951e5ba76 --- /dev/null +++ b/tests/operators/qlinear_leakyrelu_test.cairo @@ -0,0 +1,52 @@ +use debug::PrintTrait; +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{ + TensorTrait, Tensor, I8Tensor, I32Tensor, U32Tensor, FP16x16Tensor, FP32x32Tensor +}; +use orion::numbers::{FP16x16, FP16x16Impl, FP32x32, FP32x32Impl, FixedTrait}; +use orion::numbers::{IntegerTrait}; +use orion::numbers::{i8, i32}; + + +#[test] +#[available_gas(200000000000)] +fn qlinear_leakyrelu_test() { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); + let a_zero_point = TensorTrait::< + FP16x16 + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); + + let alpha = FixedTrait::::new(655360, false); + + let actual_output = a.qlinear_leakyrelu(@a_scale, @a_zero_point, alpha); + + assert((*actual_output.data[0]).abs().into() == 118, '*result[0] == 118'); + assert((*actual_output.data[1]).abs().into() == 118, '*result[1] == 118'); + assert((*actual_output.data[2]).abs().into() == 118, '*result[2] == 118'); + assert((*actual_output.data[3]).into() == 10, '*result[3] == 10'); + assert((*actual_output.data[4]).into() == 10, '*result[4] == 10'); + assert((*actual_output.data[5]).into() == 10, '*result[5] == 10'); +} + From b1076820fd5fa949bfdcd0f39b71d4c114500b13 Mon Sep 17 00:00:00 2001 From: chachaleo Date: Thu, 23 Nov 2023 09:50:12 +0700 Subject: [PATCH 107/160] modif from review --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.qlinear_leakyrelu.md | 74 +++++++++++++++++++ src/operators/tensor/core.cairo | 8 +- .../tensor/implementations/tensor_bool.cairo | 5 +- .../implementations/tensor_fp16x16.cairo | 6 +- .../implementations/tensor_fp16x16wide.cairo | 1 - .../implementations/tensor_fp32x32.cairo | 6 +- .../implementations/tensor_fp64x64.cairo | 6 +- .../implementations/tensor_fp8x23.cairo | 6 +- .../implementations/tensor_fp8x23wide.cairo | 6 +- .../tensor/implementations/tensor_i32.cairo | 6 +- .../tensor/implementations/tensor_i8.cairo | 6 +- .../tensor/implementations/tensor_u32.cairo | 6 +- .../quantization/qlinear_leakyrelu.cairo | 19 ++--- 16 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.qlinear_leakyrelu.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 804d4dbb9..82183b55d 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -88,6 +88,7 @@ * [tensor.qlinear\_mul](framework/operators/tensor/tensor.qlinear\_mul.md) * [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md) * [tensor.qlinear\_concat](framework/operators/tensor/tensor.qlinear\_concat.md) + * [tensor.qlinear\_leakyrelu](framework/operators/tensor/tensor.qlinear\_leakyrelu.md) * [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) * [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) * [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index f82c4408a..a450fd0dc 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -60,6 +60,7 @@ You can see below the list of current supported ONNX Operators: | [QLinearConcat](operators/tensor/tensor.qlinear\_concat.md) | :white\_check\_mark: | | [QlinearAdd](operators/tensor/tensor.qlinear\_add.md) | :white\_check\_mark: | | [QlinearMul](operators/tensor/tensor.qlinear\_mul.md) | :white\_check\_mark: | +| [QLinearLeakyRelu](operators/tensor/tensor.qlinear\_leakyrelu.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: | diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 7a0133369..8521d8783 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -84,6 +84,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.qlinear_mul`](tensor.qlinear\_mul.md) | Performs the element-wise multiplication of quantized Tensors. | | [`tensor.qlinear_matmul`](tensor.qlinear\_matmul.md) | Performs the product of two quantized i8 Tensors. | | [`tensor.qlinear_concat`](tensor.qlinear\_concat.md) | Concatenate a list of tensors after dequantizing them with their respective scales and zero_points and returns the quantized result. | +| [`tensor.qlinear_leakyrelu`](tensor.qlinear\_leakyrelu.md) | Applies the Leaky Relu operator to a quantized Tensor | | [`tensor.gather`](tensor.gather.md) | Gather entries of the axis dimension of data. | | [`tensor.nonzero`](tensor.nonzero.md) | Produces indices of the elements that are non-zero (in row-major order - by dimension). | | [`tensor.squeeze`](tensor.squeeze.md) | Removes dimensions of size 1 from the shape of a tensor. | diff --git a/docs/framework/operators/tensor/tensor.qlinear_leakyrelu.md b/docs/framework/operators/tensor/tensor.qlinear_leakyrelu.md new file mode 100644 index 000000000..0dfa04498 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.qlinear_leakyrelu.md @@ -0,0 +1,74 @@ +# tensor.qlinear_leakyrelu + +```rust + fn qlinear_leakyrelu(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T) -> Tensor::; +``` + +Applies the Leaky Relu operator to a quantized Tensor + +QLinar LeakyRelu takes as input a quantized Tensor, its scale and zero point and an scalar alpha, and produces one output data (a quantized Tensor) +where the function `f(x) = alpha * x for x < 0, f(x) = x for x >= 0`, is applied to the data tensor elementwise. +The quantization formula is y = saturate((x / y_scale) + y_zero_point). +Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). +Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + +## Args + +* `self`(`@Tensor`) - The first tensor to be multiplied (a). +* `a_scale`(`@Tensor`) - Scale for input `a`. +* `a_zero_point`(`@Tensor`) - Zero point for input `a`. +* `alpha`(`T`) - The factor multiplied to negative elements. + +## Returns + +A new `Tensor`, containing result of the Leaky Relu. + +## Type Constraints + +u32 tensor, not supported. +fp8x23wide tensor, not supported. +fp16x16wide tensor, not supported. +bool tensor, not supported. + +## Example + +```rust + +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; +use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + + +fn qlinear_leakyrelu_example() -> Tensor { + let a = TensorTrait::< + i8 + >::new( + shape: array![2, 3].span(), + data: array![ + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, true), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false), + IntegerTrait::::new(10_u8, false) + ] + .span(), + ); + + let a_scale = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + let a_zero_point = TensorTrait::< + FP16x16 + >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + + let alpha = FixedTrait::::new(655360, false); + + return = a + .qlinear_leakyrelu( + @a_scale, @a_zero_point, alpha + ); +} + +>>> [[-118, -118, -118], [10, 10, 10]] diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 3da2bd76a..d6a0ad82f 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -80,6 +80,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// fn qlinear_leakyrelu(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T) -> Tensor::; /// ``` /// - /// Apply the Leaky Relu operator to a quantized Tensor + /// Applies the Leaky Relu operator to a quantized Tensor /// /// QLinar LeakyRelu takes as input a quantized Tensor, its scale and zero point and an scalar alpha, and produces one output data (a quantized Tensor) /// where the function `f(x) = alpha * x for x < 0, f(x) = x for x >= 0`, is applied to the data tensor elementwise. @@ -3087,10 +3088,7 @@ trait TensorTrait { /// >>> [[-118, -118, -118], [10, 10, 10]] /// fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: T + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T ) -> Tensor::; /// # tensor.slice /// diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 00ea6a3ce..d5de496a6 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -297,10 +297,7 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: bool, + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: bool, ) -> Tensor:: { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index f87a8c1f6..31028f340 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -304,11 +304,7 @@ impl FP16x16Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: FP16x16 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP16x16 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index f47b88210..1340bba67 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -272,7 +272,6 @@ impl FP16x16WTensor of TensorTrait { a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP16x16W - ) -> Tensor:: { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 7b239a565..b94309d28 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -305,11 +305,7 @@ impl FP32x32Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: FP32x32 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP32x32 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 304e0d366..23f81d0d6 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -305,11 +305,7 @@ impl FP64x64Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: FP64x64 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP64x64 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index d9fad88fa..43eb1a1e1 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -304,11 +304,7 @@ impl FP8x23Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: FP8x23 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP8x23 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index d58bd1481..88aa7690b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -262,11 +262,7 @@ impl FP8x23WTensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: FP8x23W - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP8x23W ) -> Tensor:: { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 27b4ad99b..c42363db6 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -305,11 +305,7 @@ impl I32Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: i32 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: i32 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index af7eec0ac..92cf45d39 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -304,11 +304,7 @@ impl I8Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: i8 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: i8 ) -> Tensor:: { quantization::qlinear_leakyrelu::qlinear_leakyrelu( self, diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 184ea2896..43cb6d1d0 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -256,11 +256,7 @@ impl U32Tensor of TensorTrait { } fn qlinear_leakyrelu( - self: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: u32 - + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: u32 ) -> Tensor:: { panic(array!['not supported!']) } diff --git a/src/operators/tensor/quantization/qlinear_leakyrelu.cairo b/src/operators/tensor/quantization/qlinear_leakyrelu.cairo index 56cb58292..964467d69 100644 --- a/src/operators/tensor/quantization/qlinear_leakyrelu.cairo +++ b/src/operators/tensor/quantization/qlinear_leakyrelu.cairo @@ -32,29 +32,26 @@ fn qlinear_leakyrelu< impl QCopy: Copy, impl QDrop: Drop >( - a: @Tensor, - a_scale: @Tensor, - a_zero_point: @Tensor, - alpha: T, - min: T, - max: T + a: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T, min: T, max: T ) -> Tensor { let mut dequantized_a = dequantize_linear(@(*a), a_scale, a_zero_point); - + let mut result_data = ArrayTrait::::new(); let mut i = 0; loop { match dequantized_a.data.pop_front() { - Option::Some(elem) => { + Option::Some(elem) => { if *elem < NumberTrait::zero() { result_data.append(*elem * alpha); } else { result_data.append(*elem); } - }, - Option::None(_) => { break;} + }, + Option::None(_) => { break; } }; }; - return quantize_linear(@TensorTrait::new(dequantized_a.shape, result_data.span()), a_scale, a_zero_point, min, max); + return quantize_linear( + @TensorTrait::new(dequantized_a.shape, result_data.span()), a_scale, a_zero_point, min, max + ); } From 41bf6849cd95c982e99dc473909a71bdd49f72d4 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 23 Nov 2023 10:48:23 +0200 Subject: [PATCH 108/160] Update nn.cairo --- src/operators/nn.cairo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/operators/nn.cairo b/src/operators/nn.cairo index 1f7a3abe5..625e63216 100644 --- a/src/operators/nn.cairo +++ b/src/operators/nn.cairo @@ -6,6 +6,8 @@ use orion::operators::nn::core::NNTrait; use orion::operators::nn::implementations::nn_fp8x23::FP8x23NN; use orion::operators::nn::implementations::nn_fp16x16::FP16x16NN; +use orion::operators::nn::implementations::nn_fp32x32::FP32x32NN; +use orion::operators::nn::implementations::nn_fp64x64::FP64x64NN; use orion::operators::nn::implementations::nn_i8::I8NN; use orion::operators::nn::implementations::nn_i32::I32NN; use orion::operators::nn::implementations::nn_u32::U32NN; From c6e61e17ff6a67c39b858063ca11935007151b24 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 24 Nov 2023 13:16:38 +0100 Subject: [PATCH 109/160] Add nodegen script --- nodegen/node/is_inf.py | 167 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 nodegen/node/is_inf.py diff --git a/nodegen/node/is_inf.py b/nodegen/node/is_inf.py new file mode 100644 index 000000000..b4054cbe1 --- /dev/null +++ b/nodegen/node/is_inf.py @@ -0,0 +1,167 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + +INF = 2**32 - 1 + +class Is_inf(RunAll): + + @staticmethod + def is_inf_u32(): + def default(): + input_0 = np.array([1, 0, INF, 8, -INF, INF], dtype=np.uint32) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.U32, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_inf_u32" + make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) + + default() + + @staticmethod + def is_inf_i32(): + def default(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int32) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.I32, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_inf_i32" + make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) + + def positive(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int32) + output = np.array([False, False, True, False, False, True], dtype=bool) + + input_0 = Tensor(Dtype.I32, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_pos_inf_i32" + make_test([input_0], output, "TensorTrait::is_pos_inf(@input_0, Option::Some(0), Option::Some(1))", name) + + def negative(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int32) + output = np.array([False, False, False, False, True, False], dtype=bool) + + input_0 = Tensor(Dtype.I32, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_neg_inf_i32" + make_test([input_0], output, "TensorTrait::is_neg_inf(@input_0, Option::Some(1), Optoin::Some(0))", name) + + default() + positive() + negative() + + @staticmethod + def is_inf_i8(): + def default(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int8) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.I8, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_inf_i8" + make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) + + def positive(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int32) + output = np.array([False, False, True, False, False, True], dtype=bool) + + input_0 = Tensor(Dtype.I8, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_pos_inf_i8" + make_test([input_0], output, "TensorTrait::is_pos_inf(@input_0, Option::Some(0), Option::Some(1))", name) + + def negative(): + input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int32) + output = np.array([False, False, False, False, True, False], dtype=bool) + + input_0 = Tensor(Dtype.I8, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_neg_inf_i8" + make_test([input_0], output, "TensorTrait::is_neg_inf(@input_0, Option::Some(1), Option::Some(0))", name) + + default() + positive() + negative() + + @staticmethod + def is_inf_fp8x23(): + def default(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.FP8x23, input_0.shape, to_fp( + input_0.flatten(), FixedImpl.FP8x23)) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_inf_fp8x23" + make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) + + def positive(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, True, False, False, True], dtype=bool) + + input_0 = Tensor(Dtype.FP8x23, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_pos_inf_fp8x23" + make_test([input_0], output, "TensorTrait::is_pos_inf(@input_0, Option::Some(0), Option::Some(1))", name) + + def negative(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, False, False, True, False], dtype=bool) + + input_0 = Tensor(Dtype.FP8x23, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_neg_inf_fp8x23" + make_test([input_0], output, "TensorTrait::is_neg_inf(@input_0, Option::Some(1), Option::Some(0))", name) + + default() + positive() + negative() + + @staticmethod + def is_inf_fp16x16(): + def default(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.FP16x16, input_0.shape, to_fp( + input_0.flatten(), FixedImpl.FP16x16)) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_inf_fp16x16" + make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) + + def positive(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, True, False, False, True], dtype=bool) + + input_0 = Tensor(Dtype.FP16x16, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_pos_inf_fp16x16" + make_test([input_0], output, "TensorTrait::is_pos_inf(@input_0, Option::Some(0), Option::Some(1))", name) + + def negative(): + input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) + output = np.array([False, False, False, False, True, False], dtype=bool) + + input_0 = Tensor(Dtype.FP16x16, input_0.shape, input_0.flatten()) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_neg_inf_fp16x16" + make_test([input_0], output, "TensorTrait::is_neg_inf(@input_0, Option::Some(1), Option::Some(0))", name) + + default() + positive() + negative() From cd0296ba8056c2e195920561b1d328885dad0718 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 24 Nov 2023 13:50:22 +0100 Subject: [PATCH 110/160] Add tests --- tests/nodes/is_inf_fp16x16.cairo | 22 +++++++++++++++++++ tests/nodes/is_inf_fp16x16/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_inf_fp16x16/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_inf_fp8x23.cairo | 22 +++++++++++++++++++ tests/nodes/is_inf_fp8x23/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_inf_fp8x23/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_inf_i32.cairo | 22 +++++++++++++++++++ tests/nodes/is_inf_i32/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_inf_i32/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_inf_i8.cairo | 22 +++++++++++++++++++ tests/nodes/is_inf_i8/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_inf_i8/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_inf_u32.cairo | 22 +++++++++++++++++++ tests/nodes/is_inf_u32/input_0.cairo | 17 ++++++++++++++ tests/nodes/is_inf_u32/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_neg_inf_fp16x16.cairo | 22 +++++++++++++++++++ tests/nodes/is_neg_inf_fp16x16/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_neg_inf_fp16x16/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_neg_inf_fp8x23.cairo | 22 +++++++++++++++++++ tests/nodes/is_neg_inf_fp8x23/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_neg_inf_fp8x23/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_neg_inf_i32.cairo | 22 +++++++++++++++++++ tests/nodes/is_neg_inf_i32/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_neg_inf_i32/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_neg_inf_i8.cairo | 22 +++++++++++++++++++ tests/nodes/is_neg_inf_i8/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_neg_inf_i8/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_pos_inf_fp16x16.cairo | 22 +++++++++++++++++++ tests/nodes/is_pos_inf_fp16x16/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_pos_inf_fp16x16/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_pos_inf_fp8x23.cairo | 22 +++++++++++++++++++ tests/nodes/is_pos_inf_fp8x23/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_pos_inf_fp8x23/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_pos_inf_i32.cairo | 22 +++++++++++++++++++ tests/nodes/is_pos_inf_i32/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_pos_inf_i32/output_0.cairo | 17 ++++++++++++++ tests/nodes/is_pos_inf_i8.cairo | 22 +++++++++++++++++++ tests/nodes/is_pos_inf_i8/input_0.cairo | 18 +++++++++++++++ tests/nodes/is_pos_inf_i8/output_0.cairo | 17 ++++++++++++++ 39 files changed, 740 insertions(+) create mode 100644 tests/nodes/is_inf_fp16x16.cairo create mode 100644 tests/nodes/is_inf_fp16x16/input_0.cairo create mode 100644 tests/nodes/is_inf_fp16x16/output_0.cairo create mode 100644 tests/nodes/is_inf_fp8x23.cairo create mode 100644 tests/nodes/is_inf_fp8x23/input_0.cairo create mode 100644 tests/nodes/is_inf_fp8x23/output_0.cairo create mode 100644 tests/nodes/is_inf_i32.cairo create mode 100644 tests/nodes/is_inf_i32/input_0.cairo create mode 100644 tests/nodes/is_inf_i32/output_0.cairo create mode 100644 tests/nodes/is_inf_i8.cairo create mode 100644 tests/nodes/is_inf_i8/input_0.cairo create mode 100644 tests/nodes/is_inf_i8/output_0.cairo create mode 100644 tests/nodes/is_inf_u32.cairo create mode 100644 tests/nodes/is_inf_u32/input_0.cairo create mode 100644 tests/nodes/is_inf_u32/output_0.cairo create mode 100644 tests/nodes/is_neg_inf_fp16x16.cairo create mode 100644 tests/nodes/is_neg_inf_fp16x16/input_0.cairo create mode 100644 tests/nodes/is_neg_inf_fp16x16/output_0.cairo create mode 100644 tests/nodes/is_neg_inf_fp8x23.cairo create mode 100644 tests/nodes/is_neg_inf_fp8x23/input_0.cairo create mode 100644 tests/nodes/is_neg_inf_fp8x23/output_0.cairo create mode 100644 tests/nodes/is_neg_inf_i32.cairo create mode 100644 tests/nodes/is_neg_inf_i32/input_0.cairo create mode 100644 tests/nodes/is_neg_inf_i32/output_0.cairo create mode 100644 tests/nodes/is_neg_inf_i8.cairo create mode 100644 tests/nodes/is_neg_inf_i8/input_0.cairo create mode 100644 tests/nodes/is_neg_inf_i8/output_0.cairo create mode 100644 tests/nodes/is_pos_inf_fp16x16.cairo create mode 100644 tests/nodes/is_pos_inf_fp16x16/input_0.cairo create mode 100644 tests/nodes/is_pos_inf_fp16x16/output_0.cairo create mode 100644 tests/nodes/is_pos_inf_fp8x23.cairo create mode 100644 tests/nodes/is_pos_inf_fp8x23/input_0.cairo create mode 100644 tests/nodes/is_pos_inf_fp8x23/output_0.cairo create mode 100644 tests/nodes/is_pos_inf_i32.cairo create mode 100644 tests/nodes/is_pos_inf_i32/input_0.cairo create mode 100644 tests/nodes/is_pos_inf_i32/output_0.cairo create mode 100644 tests/nodes/is_pos_inf_i8.cairo create mode 100644 tests/nodes/is_pos_inf_i8/input_0.cairo create mode 100644 tests/nodes/is_pos_inf_i8/output_0.cairo diff --git a/tests/nodes/is_inf_fp16x16.cairo b/tests/nodes/is_inf_fp16x16.cairo new file mode 100644 index 000000000..10c0d82a5 --- /dev/null +++ b/tests/nodes/is_inf_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_inf_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::None, Option::None); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_inf_fp16x16/input_0.cairo b/tests/nodes/is_inf_fp16x16/input_0.cairo new file mode 100644 index 000000000..51a6816fc --- /dev/null +++ b/tests/nodes/is_inf_fp16x16/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, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 78643, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FP16x16 { mag: 183500, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: true }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_fp16x16/output_0.cairo b/tests/nodes/is_inf_fp16x16/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_inf_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_fp8x23.cairo b/tests/nodes/is_inf_fp8x23.cairo new file mode 100644 index 000000000..a471a6b5c --- /dev/null +++ b/tests/nodes/is_inf_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_inf_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::None, Option::None); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_inf_fp8x23/input_0.cairo b/tests/nodes/is_inf_fp8x23/input_0.cairo new file mode 100644 index 000000000..80a8c4936 --- /dev/null +++ b/tests/nodes/is_inf_fp8x23/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, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 10066329, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FP8x23 { mag: 23488102, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: true }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_fp8x23/output_0.cairo b/tests/nodes/is_inf_fp8x23/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_inf_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_i32.cairo b/tests/nodes/is_inf_i32.cairo new file mode 100644 index 000000000..be97cb7be --- /dev/null +++ b/tests/nodes/is_inf_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_is_inf_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::None, Option::None); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_inf_i32/input_0.cairo b/tests/nodes/is_inf_i32/input_0.cairo new file mode 100644 index 000000000..9cd471efb --- /dev/null +++ b/tests/nodes/is_inf_i32/input_0.cairo @@ -0,0 +1,18 @@ +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(6); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 4294967295, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_i32/output_0.cairo b/tests/nodes/is_inf_i32/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_inf_i32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_i8.cairo b/tests/nodes/is_inf_i8.cairo new file mode 100644 index 000000000..dc606757d --- /dev/null +++ b/tests/nodes/is_inf_i8.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I8TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_inf_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::None, Option::None); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_inf_i8/input_0.cairo b/tests/nodes/is_inf_i8/input_0.cairo new file mode 100644 index 000000000..bbb1ceaf5 --- /dev/null +++ b/tests/nodes/is_inf_i8/input_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 255, sign: true }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 255, sign: false }); + data.append(i8 { mag: 255, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_i8/output_0.cairo b/tests/nodes/is_inf_i8/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_inf_i8/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_u32.cairo b/tests/nodes/is_inf_u32.cairo new file mode 100644 index 000000000..393146e9f --- /dev/null +++ b/tests/nodes/is_inf_u32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::U32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_is_inf_u32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::None, Option::None); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_inf_u32/input_0.cairo b/tests/nodes/is_inf_u32/input_0.cairo new file mode 100644 index 000000000..52d147bbc --- /dev/null +++ b/tests/nodes/is_inf_u32/input_0.cairo @@ -0,0 +1,17 @@ +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(6); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(4294967295); + data.append(8); + data.append(4294967295); + data.append(4294967295); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_inf_u32/output_0.cairo b/tests/nodes/is_inf_u32/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_inf_u32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_fp16x16.cairo b/tests/nodes/is_neg_inf_fp16x16.cairo new file mode 100644 index 000000000..85e7a0f24 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_neg_inf_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(1), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_neg_inf_fp16x16/input_0.cairo b/tests/nodes/is_neg_inf_fp16x16/input_0.cairo new file mode 100644 index 000000000..2c5fa5777 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp16x16/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, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FP16x16 { mag: 2, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: true }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_fp16x16/output_0.cairo b/tests/nodes/is_neg_inf_fp16x16/output_0.cairo new file mode 100644 index 000000000..48bea29a2 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_fp8x23.cairo b/tests/nodes/is_neg_inf_fp8x23.cairo new file mode 100644 index 000000000..eac5cb1a6 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_neg_inf_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(1), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_neg_inf_fp8x23/input_0.cairo b/tests/nodes/is_neg_inf_fp8x23/input_0.cairo new file mode 100644 index 000000000..fe0082468 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp8x23/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, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: true }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_fp8x23/output_0.cairo b/tests/nodes/is_neg_inf_fp8x23/output_0.cairo new file mode 100644 index 000000000..48bea29a2 --- /dev/null +++ b/tests/nodes/is_neg_inf_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_i32.cairo b/tests/nodes/is_neg_inf_i32.cairo new file mode 100644 index 000000000..9c01eeac2 --- /dev/null +++ b/tests/nodes/is_neg_inf_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_is_neg_inf_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(1), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_neg_inf_i32/input_0.cairo b/tests/nodes/is_neg_inf_i32/input_0.cairo new file mode 100644 index 000000000..9cd471efb --- /dev/null +++ b/tests/nodes/is_neg_inf_i32/input_0.cairo @@ -0,0 +1,18 @@ +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(6); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 4294967295, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_i32/output_0.cairo b/tests/nodes/is_neg_inf_i32/output_0.cairo new file mode 100644 index 000000000..67513d0d6 --- /dev/null +++ b/tests/nodes/is_neg_inf_i32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_i8.cairo b/tests/nodes/is_neg_inf_i8.cairo new file mode 100644 index 000000000..084b4a639 --- /dev/null +++ b/tests/nodes/is_neg_inf_i8.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I8TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_neg_inf_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(1), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_neg_inf_i8/input_0.cairo b/tests/nodes/is_neg_inf_i8/input_0.cairo new file mode 100644 index 000000000..bbb1ceaf5 --- /dev/null +++ b/tests/nodes/is_neg_inf_i8/input_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 255, sign: true }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 255, sign: false }); + data.append(i8 { mag: 255, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_neg_inf_i8/output_0.cairo b/tests/nodes/is_neg_inf_i8/output_0.cairo new file mode 100644 index 000000000..67513d0d6 --- /dev/null +++ b/tests/nodes/is_neg_inf_i8/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_fp16x16.cairo b/tests/nodes/is_pos_inf_fp16x16.cairo new file mode 100644 index 000000000..d5a9d43f0 --- /dev/null +++ b/tests/nodes/is_pos_inf_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP16x16TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_pos_inf_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(0), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_pos_inf_fp16x16/input_0.cairo b/tests/nodes/is_pos_inf_fp16x16/input_0.cairo new file mode 100644 index 000000000..2c5fa5777 --- /dev/null +++ b/tests/nodes/is_pos_inf_fp16x16/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, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 1, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FP16x16 { mag: 2, sign: false }); + data.append(FP16x16 { mag: 4294967295, sign: true }); + data.append(FP16x16 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_fp16x16/output_0.cairo b/tests/nodes/is_pos_inf_fp16x16/output_0.cairo new file mode 100644 index 000000000..67513d0d6 --- /dev/null +++ b/tests/nodes/is_pos_inf_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_fp8x23.cairo b/tests/nodes/is_pos_inf_fp8x23.cairo new file mode 100644 index 000000000..a1b6888bb --- /dev/null +++ b/tests/nodes/is_pos_inf_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::FP8x23TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_pos_inf_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(0), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_pos_inf_fp8x23/input_0.cairo b/tests/nodes/is_pos_inf_fp8x23/input_0.cairo new file mode 100644 index 000000000..fe0082468 --- /dev/null +++ b/tests/nodes/is_pos_inf_fp8x23/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, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 1, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 4294967295, sign: true }); + data.append(FP8x23 { mag: 4294967295, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_fp8x23/output_0.cairo b/tests/nodes/is_pos_inf_fp8x23/output_0.cairo new file mode 100644 index 000000000..67513d0d6 --- /dev/null +++ b/tests/nodes/is_pos_inf_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_i32.cairo b/tests/nodes/is_pos_inf_i32.cairo new file mode 100644 index 000000000..819472be1 --- /dev/null +++ b/tests/nodes/is_pos_inf_i32.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I32Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_is_pos_inf_i32() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(0), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_pos_inf_i32/input_0.cairo b/tests/nodes/is_pos_inf_i32/input_0.cairo new file mode 100644 index 000000000..9cd471efb --- /dev/null +++ b/tests/nodes/is_pos_inf_i32/input_0.cairo @@ -0,0 +1,18 @@ +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(6); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + data.append(i32 { mag: 8, sign: false }); + data.append(i32 { mag: 4294967295, sign: false }); + data.append(i32 { mag: 4294967295, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_i32/output_0.cairo b/tests/nodes/is_pos_inf_i32/output_0.cairo new file mode 100644 index 000000000..48bea29a2 --- /dev/null +++ b/tests/nodes/is_pos_inf_i32/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_i8.cairo b/tests/nodes/is_pos_inf_i8.cairo new file mode 100644 index 000000000..74612f181 --- /dev/null +++ b/tests/nodes/is_pos_inf_i8.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::BoolTensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::I8Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::I8TensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_pos_inf_i8() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_inf(@input_0, Option::Some(0), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_pos_inf_i8/input_0.cairo b/tests/nodes/is_pos_inf_i8/input_0.cairo new file mode 100644 index 000000000..bbb1ceaf5 --- /dev/null +++ b/tests/nodes/is_pos_inf_i8/input_0.cairo @@ -0,0 +1,18 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 255, sign: true }); + data.append(i8 { mag: 8, sign: false }); + data.append(i8 { mag: 255, sign: false }); + data.append(i8 { mag: 255, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_pos_inf_i8/output_0.cairo b/tests/nodes/is_pos_inf_i8/output_0.cairo new file mode 100644 index 000000000..48bea29a2 --- /dev/null +++ b/tests/nodes/is_pos_inf_i8/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + TensorTrait::new(shape.span(), data.span()) +} From b5da5326215b7c3e3382211719abe0736c35c9f2 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 24 Nov 2023 14:41:19 +0100 Subject: [PATCH 111/160] Add implementation --- src/numbers.cairo | 197 +++++++++++++++++- src/numbers/fixed_point/core.cairo | 6 + .../implementations/fp16x16/core.cairo | 24 +++ .../implementations/fp16x16wide/core.cairo | 24 +++ .../implementations/fp32x32/core.cairo | 24 +++ .../implementations/fp64x64/core.cairo | 24 +++ .../implementations/fp8x23/core.cairo | 24 +++ .../implementations/fp8x23wide/core.cairo | 24 +++ src/numbers/signed_integer/i128.cairo | 24 +++ src/numbers/signed_integer/i16.cairo | 24 +++ src/numbers/signed_integer/i32.cairo | 24 +++ src/numbers/signed_integer/i64.cairo | 24 +++ src/numbers/signed_integer/i8.cairo | 24 +++ .../signed_integer/integer_trait.cairo | 6 + src/operators/tensor/core.cairo | 4 +- .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 6 +- .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/is_inf.cairo | 102 +++++++++ tests/nodes.cairo | 13 ++ tests/nodes/is_inf_fp16x16/input_0.cairo | 6 +- tests/nodes/is_inf_fp8x23/input_0.cairo | 6 +- tests/nodes/is_inf_i32/input_0.cairo | 6 +- tests/nodes/is_inf_i8/input_0.cairo | 6 +- tests/nodes/is_inf_u32/input_0.cairo | 7 +- tests/nodes/is_neg_inf_fp16x16/input_0.cairo | 6 +- tests/nodes/is_neg_inf_fp8x23/input_0.cairo | 6 +- tests/nodes/is_neg_inf_i32/input_0.cairo | 6 +- tests/nodes/is_neg_inf_i8/input_0.cairo | 6 +- tests/nodes/is_pos_inf_fp16x16/input_0.cairo | 6 +- tests/nodes/is_pos_inf_fp8x23/input_0.cairo | 6 +- tests/nodes/is_pos_inf_i32/input_0.cairo | 6 +- tests/nodes/is_pos_inf_i8/input_0.cairo | 6 +- 41 files changed, 671 insertions(+), 43 deletions(-) create mode 100644 src/operators/tensor/math/is_inf.cairo diff --git a/src/numbers.cairo b/src/numbers.cairo index bb781afb3..ae99a4d3c 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -52,6 +52,10 @@ trait NumberTrait { fn where(self: T, x: T, y: T) -> T; fn NaN() -> T; fn is_nan(self: T) -> bool; + fn INF() -> T; + fn is_inf(self: T) -> bool; + fn is_pos_inf(self: T) -> bool; + fn is_neg_inf(self: T) -> bool; fn bitwise_and(lhs: T, rhs: T) -> T; fn add(lhs: T, rhs: T) -> T; fn sub(lhs: T, rhs: T) -> T; @@ -247,6 +251,22 @@ impl FP8x23Number of NumberTrait { FP8x23Impl::is_nan(self) } + fn INF() -> FP8x23 { + FP8x23Impl::INF() + } + + fn is_inf(self: FP8x23) -> bool { + FP8x23Impl::is_inf(self) + } + + fn is_pos_inf(self: FP8x23) -> bool { + FP8x23Impl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP8x23) -> bool { + FP8x23Impl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { comp_fp8x23::bitwise_and(lhs, rhs) } @@ -450,6 +470,22 @@ impl FP8x23WNumber of NumberTrait { FP8x23WImpl::is_nan(self) } + fn INF() -> FP8x23W { + FP8x23WImpl::INF() + } + + fn is_inf(self: FP8x23W) -> bool { + FP8x23WImpl::is_inf(self) + } + + fn is_pos_inf(self: FP8x23W) -> bool { + FP8x23WImpl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP8x23W) -> bool { + FP8x23WImpl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { comp_fp8x23wide::bitwise_and(lhs, rhs) } @@ -653,6 +689,22 @@ impl FP16x16Number of NumberTrait { FP16x16Impl::is_nan(self) } + fn INF() -> FP16x16 { + FP16x16Impl::INF() + } + + fn is_inf(self: FP16x16) -> bool { + FP16x16Impl::is_inf(self) + } + + fn is_pos_inf(self: FP16x16) -> bool { + FP16x16Impl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP16x16) -> bool { + FP16x16Impl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { comp_fp16x16::bitwise_and(lhs, rhs) } @@ -856,6 +908,22 @@ impl FP16x16WNumber of NumberTrait { FP16x16WImpl::is_nan(self) } + fn INF() -> FP16x16W { + FP16x16WImpl::INF() + } + + fn is_inf(self: FP16x16W) -> bool { + FP16x16WImpl::is_inf(self) + } + + fn is_pos_inf(self: FP16x16W) -> bool { + FP16x16WImpl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP16x16W) -> bool { + FP16x16WImpl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { comp_fp16x16wide::bitwise_and(lhs, rhs) } @@ -1060,6 +1128,22 @@ impl FP64x64Number of NumberTrait { FP64x64Impl::is_nan(self) } + fn INF() -> FP64x64 { + FP64x64Impl::INF() + } + + fn is_inf(self: FP64x64) -> bool { + FP64x64Impl::is_inf(self) + } + + fn is_pos_inf(self: FP64x64) -> bool { + FP64x64Impl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP64x64) -> bool { + FP64x64Impl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { comp_fp64x64::bitwise_and(lhs, rhs) } @@ -1264,6 +1348,22 @@ impl FP32x32Number of NumberTrait { FP32x32Impl::is_nan(self) } + fn INF() -> FP32x32 { + FP32x32Impl::INF() + } + + fn is_inf(self: FP32x32) -> bool { + FP32x32Impl::is_inf(self) + } + + fn is_pos_inf(self: FP32x32) -> bool { + FP32x32Impl::is_pos_inf(self) + } + + fn is_neg_inf(self: FP32x32) -> bool { + FP32x32Impl::is_neg_inf(self) + } + fn bitwise_and(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { comp_fp32x32::bitwise_and(lhs, rhs) } @@ -1481,6 +1581,22 @@ impl I8Number of NumberTrait { IntegerTrait::is_nan(self) } + fn INF() -> i8 { + IntegerTrait::INF() + } + + fn is_inf(self: i8) -> bool { + IntegerTrait::is_inf(self) + } + + fn is_pos_inf(self: i8) -> bool { + IntegerTrait::is_pos_inf(self) + } + + fn is_neg_inf(self: i8) -> bool { + IntegerTrait::is_neg_inf(self) + } + fn bitwise_and(lhs: i8, rhs: i8) -> i8 { i8_core::i8_bitwise_and(lhs, rhs) } @@ -1698,6 +1814,22 @@ impl i16Number of NumberTrait { IntegerTrait::is_nan(self) } + fn INF() -> i16 { + IntegerTrait::INF() + } + + fn is_inf(self: i16) -> bool { + IntegerTrait::is_inf(self) + } + + fn is_pos_inf(self: i16) -> bool { + IntegerTrait::is_pos_inf(self) + } + + fn is_neg_inf(self: i16) -> bool { + IntegerTrait::is_neg_inf(self) + } + fn bitwise_and(lhs: i16, rhs: i16) -> i16 { i16_core::i16_bitwise_and(lhs, rhs) } @@ -1915,6 +2047,22 @@ impl i32Number of NumberTrait { IntegerTrait::is_nan(self) } + fn INF() -> i32 { + IntegerTrait::INF() + } + + fn is_inf(self: i32) -> bool { + IntegerTrait::is_inf(self) + } + + fn is_pos_inf(self: i32) -> bool { + IntegerTrait::is_pos_inf(self) + } + + fn is_neg_inf(self: i32) -> bool { + IntegerTrait::is_neg_inf(self) + } + fn bitwise_and(lhs: i32, rhs: i32) -> i32 { i32_core::i32_bitwise_and(lhs, rhs) } @@ -2132,6 +2280,22 @@ impl i64Number of NumberTrait { IntegerTrait::is_nan(self) } + fn INF() -> i64 { + IntegerTrait::INF() + } + + fn is_inf(self: i64) -> bool { + IntegerTrait::is_inf(self) + } + + fn is_pos_inf(self: i64) -> bool { + IntegerTrait::is_pos_inf(self) + } + + fn is_neg_inf(self: i64) -> bool { + IntegerTrait::is_neg_inf(self) + } + fn bitwise_and(lhs: i64, rhs: i64) -> i64 { i64_core::i64_bitwise_and(lhs, rhs) } @@ -2342,7 +2506,6 @@ impl i128Number of NumberTrait { } } - fn NaN() -> i128 { IntegerTrait::NaN() } @@ -2351,6 +2514,22 @@ impl i128Number of NumberTrait { IntegerTrait::is_nan(self) } + fn INF() -> i128 { + IntegerTrait::INF() + } + + fn is_inf(self: i128) -> bool { + IntegerTrait::is_inf(self) + } + + fn is_pos_inf(self: i128) -> bool { + IntegerTrait::is_pos_inf(self) + } + + fn is_neg_inf(self: i128) -> bool { + IntegerTrait::is_neg_inf(self) + } + fn bitwise_and(lhs: i128, rhs: i128) -> i128 { i128_core::i128_bitwise_and(lhs, rhs) } @@ -2573,6 +2752,22 @@ impl u32Number of NumberTrait { self == 4242424242 } + fn INF() -> u32 { + 4294967295 + } + + fn is_inf(self: u32) -> bool { + self == 4294967295 + } + + fn is_pos_inf(self: u32) -> bool { + self == 4294967295 + } + + fn is_neg_inf(self: u32) -> bool { + panic(array!['not supported!']) + } + fn bitwise_and(lhs: u32, rhs: u32) -> u32 { lhs & rhs } diff --git a/src/numbers/fixed_point/core.cairo b/src/numbers/fixed_point/core.cairo index 1b3ceb0d4..769190f93 100644 --- a/src/numbers/fixed_point/core.cairo +++ b/src/numbers/fixed_point/core.cairo @@ -1105,4 +1105,10 @@ trait FixedTrait { fn MAX() -> T; fn NaN() -> T; fn is_nan(self: T) -> bool; + fn INF() -> T; + fn POS_INF() -> T; + fn NEG_INF() -> T; + fn is_inf(self: T) -> bool; + fn is_pos_inf(self: T) -> bool; + fn is_neg_inf(self: T) -> bool; } diff --git a/src/numbers/fixed_point/implementations/fp16x16/core.cairo b/src/numbers/fixed_point/implementations/fp16x16/core.cairo index ead8dfd9c..02a4f9db8 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/core.cairo @@ -194,6 +194,30 @@ impl FP16x16Impl of FixedTrait { fn is_nan(self: FP16x16) -> bool { self == FP16x16 { mag: 0, sign: true } } + + fn INF() -> FP16x16 { + return FP16x16 { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP16x16 { + return FP16x16 { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP16x16 { + return FP16x16 { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP16x16) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP16x16) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP16x16) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo index 0d70e5a89..7be8ab278 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/core.cairo @@ -194,6 +194,30 @@ impl FP16x16WImpl of FixedTrait { fn is_nan(self: FP16x16W) -> bool { self == FP16x16W { mag: 0, sign: true } } + + fn INF() -> FP16x16W { + return FP16x16W { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP16x16W { + return FP16x16W { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP16x16W { + return FP16x16W { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP16x16W) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP16x16W) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP16x16W) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/fixed_point/implementations/fp32x32/core.cairo b/src/numbers/fixed_point/implementations/fp32x32/core.cairo index 27ef0819a..fca39b6fb 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/core.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/core.cairo @@ -185,6 +185,30 @@ impl FP32x32Impl of FixedTrait { fn is_nan(self: FP32x32) -> bool { self == FP32x32 { mag: 0, sign: true } } + + fn INF() -> FP32x32 { + return FP32x32 { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP32x32 { + return FP32x32 { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP32x32 { + return FP32x32 { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP32x32) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP32x32) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP32x32) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/fixed_point/implementations/fp64x64/core.cairo b/src/numbers/fixed_point/implementations/fp64x64/core.cairo index 2095824e4..bb674e03c 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/core.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/core.cairo @@ -185,6 +185,30 @@ impl FP64x64Impl of FixedTrait { fn is_nan(self: FP64x64) -> bool { self == FP64x64 { mag: 0, sign: true } } + + fn INF() -> FP64x64 { + return FP64x64 { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP64x64 { + return FP64x64 { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP64x64 { + return FP64x64 { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP64x64) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP64x64) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP64x64) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23/core.cairo b/src/numbers/fixed_point/implementations/fp8x23/core.cairo index 9f6bd327a..9faffd18e 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/core.cairo @@ -194,6 +194,30 @@ impl FP8x23Impl of FixedTrait { fn is_nan(self: FP8x23) -> bool { self == FP8x23 { mag: 0, sign: true } } + + fn INF() -> FP8x23 { + return FP8x23 { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP8x23 { + return FP8x23 { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP8x23 { + return FP8x23 { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP8x23) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP8x23) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP8x23) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo index 72a3bc776..428570029 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/core.cairo @@ -194,6 +194,30 @@ impl FP8x23WImpl of FixedTrait { fn is_nan(self: FP8x23W) -> bool { self == FP8x23W { mag: 0, sign: true } } + + fn INF() -> FP8x23W { + return FP8x23W { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> FP8x23W { + return FP8x23W { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> FP8x23W { + return FP8x23W { mag: 4294967295, sign: true }; + } + + fn is_inf(self: FP8x23W) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: FP8x23W) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: FP8x23W) -> bool { + self.is_inf() && self.sign + } } diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index ae1adbb4d..0724c9a20 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -45,6 +45,30 @@ impl i128Impl of IntegerTrait { fn is_nan(self: i128) -> bool { self == i128 { mag: 0, sign: true } } + + fn INF() -> i128 { + return i128 { mag: 340282366920938463463374607431768211455, sign: false }; + } + + fn POS_INF() -> i128 { + return i128 { mag: 340282366920938463463374607431768211455, sign: false }; + } + + fn NEG_INF() -> i128 { + return i128 { mag: 340282366920938463463374607431768211455, sign: true }; + } + + fn is_inf(self: i128) -> bool { + self.mag == 340282366920938463463374607431768211455 + } + + fn is_pos_inf(self: i128) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: i128) -> bool { + self.is_inf() && self.sign + } } // Implements the Into trait for i128. diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index 3dd7e68f2..cdb4a15da 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -45,6 +45,30 @@ impl i16Impl of IntegerTrait { fn is_nan(self: i16) -> bool { self == i16 { mag: 0, sign: true } } + + fn INF() -> i16 { + return i16 { mag: 65535, sign: false }; + } + + fn POS_INF() -> i16 { + return i16 { mag: 65535, sign: false }; + } + + fn NEG_INF() -> i16 { + return i16 { mag: 65535, sign: true }; + } + + fn is_inf(self: i16) -> bool { + self.mag == 65535 + } + + fn is_pos_inf(self: i16) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: i16) -> bool { + self.is_inf() && self.sign + } } // Implements the Into trait for i16. diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index 9a9e00552..b2ebb5275 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -48,6 +48,30 @@ impl i32Impl of IntegerTrait { fn is_nan(self: i32) -> bool { self == i32 { mag: 0, sign: true } } + + fn INF() -> i32 { + return i32 { mag: 4294967295, sign: false }; + } + + fn POS_INF() -> i32 { + return i32 { mag: 4294967295, sign: false }; + } + + fn NEG_INF() -> i32 { + return i32 { mag: 4294967295, sign: true }; + } + + fn is_inf(self: i32) -> bool { + self.mag == 4294967295 + } + + fn is_pos_inf(self: i32) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: i32) -> bool { + self.is_inf() && self.sign + } } // Implements the Into trait for i32. diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index c502795b5..c2df9dee7 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -45,6 +45,30 @@ impl i64Impl of IntegerTrait { fn is_nan(self: i64) -> bool { self == i64 { mag: 0, sign: true } } + + fn INF() -> i64 { + return i64 { mag: 18446744073709551615, sign: false }; + } + + fn POS_INF() -> i64 { + return i64 { mag: 18446744073709551615, sign: false }; + } + + fn NEG_INF() -> i64 { + return i64 { mag: 18446744073709551615, sign: true }; + } + + fn is_inf(self: i64) -> bool { + self.mag == 18446744073709551615 + } + + fn is_pos_inf(self: i64) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: i64) -> bool { + self.is_inf() && self.sign + } } // Implements the Into trait for i64. diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 14bc4f441..a36e6e24e 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -51,6 +51,30 @@ impl i8Impl of IntegerTrait { fn is_nan(self: i8) -> bool { self == i8 { mag: 0, sign: true } } + + fn INF() -> i8 { + return i8 { mag: 255, sign: false }; + } + + fn POS_INF() -> i8 { + return i8 { mag: 255, sign: false }; + } + + fn NEG_INF() -> i8 { + return i8 { mag: 255, sign: true }; + } + + fn is_inf(self: i8) -> bool { + self.mag == 255 + } + + fn is_pos_inf(self: i8) -> bool { + self.is_inf() && !self.sign + } + + fn is_neg_inf(self: i8) -> bool { + self.is_inf() && self.sign + } } // Implements the Into trait for i8. diff --git a/src/numbers/signed_integer/integer_trait.cairo b/src/numbers/signed_integer/integer_trait.cairo index 23aca9f8c..ac53fe62c 100644 --- a/src/numbers/signed_integer/integer_trait.cairo +++ b/src/numbers/signed_integer/integer_trait.cairo @@ -212,5 +212,11 @@ trait IntegerTrait { fn NaN() -> T; fn is_nan(self: T) -> bool; + fn INF() -> T; + fn POS_INF() -> T; + fn NEG_INF() -> T; + fn is_inf(self: T) -> bool; + fn is_pos_inf(self: T) -> bool; + fn is_neg_inf(self: T) -> bool; } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 5a3cf5936..bce157de9 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -108,7 +108,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -4416,6 +4416,8 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; + /// TODO + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 0dd00f8ea..121b332d1 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -392,6 +392,10 @@ impl BoolTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 5e22d89c0..b756ea83b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -409,8 +409,6 @@ impl FP16x16Tensor of TensorTrait { math::sequence_construct::sequence_construct(tensors) } - - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -444,6 +442,10 @@ impl FP16x16Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1eff6975d..f0f64a6f9 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -412,6 +412,10 @@ impl FP16x16WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 a6a5a1828..27b5d14f1 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -443,6 +443,10 @@ impl FP32x32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 d9aa80a58..3342b5c7a 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -445,6 +445,10 @@ impl FP64x64Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 9f2e9d822..97c1fbff8 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -443,6 +443,10 @@ impl FP8x23Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index ea75501fb..5effcbab6 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -402,6 +402,10 @@ impl FP8x23WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 facc8a59a..3472bb01b 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -444,6 +444,10 @@ impl I32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 02ef9ff66..f2aec1331 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -443,6 +443,10 @@ impl I8Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// 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 15575d969..b25b780d6 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -394,6 +394,10 @@ impl U32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 04a7253ae..3eaded06a 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -54,3 +54,4 @@ mod reduce_mean; mod pow; mod sequence_erase; mod sequence_insert; +mod is_inf; diff --git a/src/operators/tensor/math/is_inf.cairo b/src/operators/tensor/math/is_inf.cairo new file mode 100644 index 000000000..52f4aa2e3 --- /dev/null +++ b/src/operators/tensor/math/is_inf.cairo @@ -0,0 +1,102 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::operators::tensor::implementations::tensor_bool::BoolTensor; + +/// Cf: TensorTrait::is_inf docstring +fn is_inf< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>(x: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { + let neg_opt = match detect_negative { + Option::Some(val) => { + if val == 0 { 0 } else { 1 } + }, + Option::None => 1, + }; + + let pos_opt = match detect_positive { + Option::Some(val) => { + if val == 0 { 0 } else { 1 } + }, + Option::None => 1, + }; + + if neg_opt == 0 && pos_opt == 0 { + return TensorTrait::new(*x.shape, ArrayTrait::::new().span()); + } + + if neg_opt == 0 && pos_opt == 1 { + return is_pos_inf(x); + } + + if neg_opt == 1 && pos_opt == 0 { + return is_neg_inf(x); + } + + let mut data_result = ArrayTrait::::new(); + let mut y: Span = *x.data; + loop { + match y.pop_front() { + Option::Some(item) => { + data_result.append((*item).is_inf()); + }, + Option::None(_) => { break; } + }; + }; + + return TensorTrait::new(*x.shape, data_result.span()); +} + +/// Cf: TensorTrait::is_pos_inf docstring +fn is_pos_inf< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>(x: @Tensor) -> Tensor { + let mut data_result = ArrayTrait::::new(); + let mut y: Span = *x.data; + loop { + match y.pop_front() { + Option::Some(item) => { + data_result.append((*item).is_pos_inf()); + }, + Option::None(_) => { break; } + }; + }; + + return TensorTrait::new(*x.shape, data_result.span()); +} + +/// Cf: TensorTrait::is_neg_inf docstring +fn is_neg_inf< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>(x: @Tensor) -> Tensor { + let mut data_result = ArrayTrait::::new(); + let mut y: Span = *x.data; + loop { + match y.pop_front() { + Option::Some(item) => { + data_result.append((*item).is_neg_inf()); + }, + Option::None(_) => { break; } + }; + }; + + return TensorTrait::new(*x.shape, data_result.span()); +} diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5d5fc5536..8d041b612 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -763,3 +763,16 @@ mod sequence_insert_fp8x23; mod sequence_insert_i32; mod sequence_insert_i8; mod sequence_insert_u32; +mod is_inf_fp16x16; +mod is_inf_fp8x23; +mod is_inf_i32; +mod is_inf_i8; +mod is_inf_u32; +mod is_pos_inf_fp16x16; +mod is_neg_inf_fp16x16; +mod is_pos_inf_fp8x23; +mod is_neg_inf_fp8x23; +mod is_pos_inf_i32; +mod is_neg_inf_i32; +mod is_pos_inf_i8; +mod is_neg_inf_i8; diff --git a/tests/nodes/is_inf_fp16x16/input_0.cairo b/tests/nodes/is_inf_fp16x16/input_0.cairo index 51a6816fc..1914f1d8e 100644 --- a/tests/nodes/is_inf_fp16x16/input_0.cairo +++ b/tests/nodes/is_inf_fp16x16/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 78643, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); data.append(FP16x16 { mag: 183500, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: true }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); + data.append(FixedTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_inf_fp8x23/input_0.cairo b/tests/nodes/is_inf_fp8x23/input_0.cairo index 80a8c4936..652dcf3d8 100644 --- a/tests/nodes/is_inf_fp8x23/input_0.cairo +++ b/tests/nodes/is_inf_fp8x23/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 10066329, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); data.append(FP8x23 { mag: 23488102, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: true }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); + data.append(FixedTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_inf_i32/input_0.cairo b/tests/nodes/is_inf_i32/input_0.cairo index 9cd471efb..9ae5a9580 100644 --- a/tests/nodes/is_inf_i32/input_0.cairo +++ b/tests/nodes/is_inf_i32/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i32 { mag: 8, sign: false }); - data.append(i32 { mag: 4294967295, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_inf_i8/input_0.cairo b/tests/nodes/is_inf_i8/input_0.cairo index bbb1ceaf5..c476d38de 100644 --- a/tests/nodes/is_inf_i8/input_0.cairo +++ b/tests/nodes/is_inf_i8/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i8 { mag: 8, sign: false }); - data.append(i8 { mag: 255, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_inf_u32/input_0.cairo b/tests/nodes/is_inf_u32/input_0.cairo index 52d147bbc..d948a400f 100644 --- a/tests/nodes/is_inf_u32/input_0.cairo +++ b/tests/nodes/is_inf_u32/input_0.cairo @@ -1,6 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32Tensor; +use orion::numbers::NumberTrait; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -9,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(1); data.append(0); - data.append(4294967295); + data.append(NumberTrait::INF()); data.append(8); - data.append(4294967295); - data.append(4294967295); + data.append(NumberTrait::INF()); + data.append(NumberTrait::INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_neg_inf_fp16x16/input_0.cairo b/tests/nodes/is_neg_inf_fp16x16/input_0.cairo index 2c5fa5777..e2039eee7 100644 --- a/tests/nodes/is_neg_inf_fp16x16/input_0.cairo +++ b/tests/nodes/is_neg_inf_fp16x16/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 1, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); data.append(FP16x16 { mag: 2, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: true }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); + data.append(FixedTrait::POS_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_neg_inf_fp8x23/input_0.cairo b/tests/nodes/is_neg_inf_fp8x23/input_0.cairo index fe0082468..7316601fb 100644 --- a/tests/nodes/is_neg_inf_fp8x23/input_0.cairo +++ b/tests/nodes/is_neg_inf_fp8x23/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 1, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); data.append(FP8x23 { mag: 2, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: true }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); + data.append(FixedTrait::POS_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_neg_inf_i32/input_0.cairo b/tests/nodes/is_neg_inf_i32/input_0.cairo index 9cd471efb..9ae5a9580 100644 --- a/tests/nodes/is_neg_inf_i32/input_0.cairo +++ b/tests/nodes/is_neg_inf_i32/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i32 { mag: 8, sign: false }); - data.append(i32 { mag: 4294967295, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_neg_inf_i8/input_0.cairo b/tests/nodes/is_neg_inf_i8/input_0.cairo index bbb1ceaf5..c476d38de 100644 --- a/tests/nodes/is_neg_inf_i8/input_0.cairo +++ b/tests/nodes/is_neg_inf_i8/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i8 { mag: 8, sign: false }); - data.append(i8 { mag: 255, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_pos_inf_fp16x16/input_0.cairo b/tests/nodes/is_pos_inf_fp16x16/input_0.cairo index 2c5fa5777..e2039eee7 100644 --- a/tests/nodes/is_pos_inf_fp16x16/input_0.cairo +++ b/tests/nodes/is_pos_inf_fp16x16/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP16x16 { mag: 1, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); data.append(FP16x16 { mag: 2, sign: false }); - data.append(FP16x16 { mag: 4294967295, sign: true }); - data.append(FP16x16 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); + data.append(FixedTrait::POS_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_pos_inf_fp8x23/input_0.cairo b/tests/nodes/is_pos_inf_fp8x23/input_0.cairo index fe0082468..7316601fb 100644 --- a/tests/nodes/is_pos_inf_fp8x23/input_0.cairo +++ b/tests/nodes/is_pos_inf_fp8x23/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 1, sign: true }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::POS_INF()); data.append(FP8x23 { mag: 2, sign: false }); - data.append(FP8x23 { mag: 4294967295, sign: true }); - data.append(FP8x23 { mag: 4294967295, sign: false }); + data.append(FixedTrait::NEG_INF()); + data.append(FixedTrait::POS_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_pos_inf_i32/input_0.cairo b/tests/nodes/is_pos_inf_i32/input_0.cairo index 9cd471efb..9ae5a9580 100644 --- a/tests/nodes/is_pos_inf_i32/input_0.cairo +++ b/tests/nodes/is_pos_inf_i32/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i32 { mag: 1, sign: true }); data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i32 { mag: 8, sign: false }); - data.append(i32 { mag: 4294967295, sign: false }); - data.append(i32 { mag: 4294967295, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/is_pos_inf_i8/input_0.cairo b/tests/nodes/is_pos_inf_i8/input_0.cairo index bbb1ceaf5..c476d38de 100644 --- a/tests/nodes/is_pos_inf_i8/input_0.cairo +++ b/tests/nodes/is_pos_inf_i8/input_0.cairo @@ -10,9 +10,9 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::NEG_INF()); data.append(i8 { mag: 8, sign: false }); - data.append(i8 { mag: 255, sign: false }); - data.append(i8 { mag: 255, sign: true }); + data.append(IntegerTrait::POS_INF()); + data.append(IntegerTrait::NEG_INF()); TensorTrait::new(shape.span(), data.span()) } From 38e169cf5028415f3d36fb3cf16913dde7daabdf Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Fri, 24 Nov 2023 16:01:41 +0100 Subject: [PATCH 112/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.is_inf.md | 35 +++++++++++++++++++ src/operators/tensor/core.cairo | 34 +++++++++++++++++- 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.is_inf.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 804d4dbb9..b78503737 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,6 +114,7 @@ * [tensor.pow](framework/operators/tensor/tensor.pow.md) * [tensor.sequence\_erase](framework/operators/tensor/tensor.sequence\_erase.md) * [tensor.sequence\_insert](framework/operators/tensor/tensor.sequence\_insert.md) + * [tensor.is_inf](framework/operators/tensor/tensor.is\_inf.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 f82c4408a..251cb46d4 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -93,5 +93,6 @@ You can see below the list of current supported ONNX Operators: | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | | [SequenceErase](operators/tensor/tensor.sequence\_erase.md) | :white\_check\_mark: | | [SequenceInsert](operators/tensor/tensor.sequence\_insert.md) | :white\_check\_mark: | +| [IsInf](operators/tensor/tensor.is\_inf.md) | :white\_check\_mark: | -Current Operators support: **82/156 (53%)** +Current Operators support: **88/156 (56%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 7a0133369..f19b669ad 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -114,6 +114,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | | [`tensor.array_feature_extractor`](tensor.array\_feature\_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | | [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | +| [`tensor.is_inf`](tensor.is\_inf.md) | Maps infinity to true and other values to false. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.is_inf.md b/docs/framework/operators/tensor/tensor.is_inf.md new file mode 100644 index 000000000..d787a2043 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.is_inf.md @@ -0,0 +1,35 @@ +## tensor.is_inf + +```rust + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; +``` + +Maps infinity to true and other values to false. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `detect_negative`(`Option`) - Optional Whether map negative infinity to true. Default to 1 so that negative infinity induces true. +* `detect_positive`(`Option`) - Optional Whether map positive infinity to true. Default to 1 so that positive infinity induces true. + + +## Returns + +A new `Tensor` instance with entries set to true iff the input tensors corresponding element was infinity. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, U32Tensor}; + +fn is_inf_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![6].span(), data: array![1, 0, NumberTrait::INF(), 8, NumberTrait::INF(), NumberTrait::INF()].span(), + ); + + return tensor.is_inf(detect_negative: Option::None, detect_positive: Option::None); +} +>>> [false, false, true, false, true, true] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index bce157de9..a883ae82d 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -4416,7 +4416,39 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; - /// TODO + /// ## tensor.is_inf + /// + /// ```rust + /// fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; + /// ``` + /// + /// Maps infinity to true and other values to false. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `detect_negative`(`Option`) - Optional Whether map negative infinity to true. Default to 1 so that negative infinity induces true. + /// * `detect_positive`(`Option`) - Optional Whether map positive infinity to true. Default to 1 so that positive infinity induces true. + /// + /// + /// ## Returns + /// + /// A new `Tensor` instance with entries set to true iff the input tensors corresponding element was infinity. + /// + /// ## Examples + /// + /// use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, U32Tensor}; + /// + /// fn is_inf_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![6].span(), data: array![1, 0, NumberTrait::INF(), 8, NumberTrait::INF(), NumberTrait::INF()].span(), + /// ); + /// + /// return tensor.is_inf(detect_negative: Option::None, detect_positive: Option::None); + /// } + /// >>> [false, false, true, false, true, true] + /// ``` + /// fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; } From 43b91a0f531702ae7c4f6d52b69619b4cc9f1e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Fri, 24 Nov 2023 19:54:51 +0000 Subject: [PATCH 113/160] feat: bitwise or implementation added for numbers --- src/numbers.cairo | 49 +++++++++++++++++++ .../implementations/fp16x16/math/comp.cairo | 4 ++ .../fp16x16wide/math/comp.cairo | 4 ++ .../implementations/fp32x32/comp.cairo | 4 ++ .../implementations/fp64x64/comp.cairo | 4 ++ .../implementations/fp8x23/math/comp.cairo | 4 ++ .../fp8x23wide/math/comp.cairo | 4 ++ src/numbers/signed_integer/i128.cairo | 4 ++ src/numbers/signed_integer/i16.cairo | 5 ++ src/numbers/signed_integer/i32.cairo | 4 ++ src/numbers/signed_integer/i64.cairo | 4 ++ src/numbers/signed_integer/i8.cairo | 4 ++ 12 files changed, 94 insertions(+) diff --git a/src/numbers.cairo b/src/numbers.cairo index 6c6a06c86..697b3a670 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -50,6 +50,7 @@ trait NumberTrait { fn and(lhs: T, rhs: T) -> bool; fn where(self: T, x: T, y: T) -> T; fn bitwise_and(lhs: T, rhs: T) -> T; + fn bitwise_or(lhs: T, rhs: T) -> T; } use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23}; @@ -231,6 +232,10 @@ impl FP8x23Number of NumberTrait { fn bitwise_and(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { comp_fp8x23::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + comp_fp8x23::bitwise_or(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp8x23wide::core::{FP8x23WImpl, FP8x23W}; @@ -412,6 +417,10 @@ impl FP8x23WNumber of NumberTrait { fn bitwise_and(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { comp_fp8x23wide::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + comp_fp8x23wide::bitwise_or(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16::core::{FP16x16Impl, FP16x16}; @@ -593,6 +602,10 @@ impl FP16x16Number of NumberTrait { fn bitwise_and(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { comp_fp16x16::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + comp_fp16x16::bitwise_or(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp16x16wide::core::{FP16x16WImpl, FP16x16W}; @@ -774,6 +787,10 @@ impl FP16x16WNumber of NumberTrait { fn bitwise_and(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { comp_fp16x16wide::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + comp_fp16x16wide::bitwise_or(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp64x64::core::{FP64x64Impl, FP64x64}; @@ -956,6 +973,10 @@ impl FP64x64Number of NumberTrait { fn bitwise_and(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { comp_fp64x64::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + comp_fp64x64::bitwise_or(lhs, rhs) + } } use orion::numbers::fixed_point::implementations::fp32x32::core::{FP32x32Impl, FP32x32}; @@ -1138,6 +1159,10 @@ impl FP32x32Number of NumberTrait { fn bitwise_and(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { comp_fp32x32::bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + comp_fp32x32::bitwise_or(lhs, rhs) + } } use orion::numbers::signed_integer::i8 as i8_core; @@ -1334,6 +1359,10 @@ impl I8Number of NumberTrait { fn bitwise_and(lhs: i8, rhs: i8) -> i8 { i8_core::i8_bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: i8, rhs: i8) -> i8 { + i8_core::i8_bitwise_or(lhs, rhs) + } } use orion::numbers::signed_integer::i16 as i16_core; @@ -1530,6 +1559,10 @@ impl i16Number of NumberTrait { fn bitwise_and(lhs: i16, rhs: i16) -> i16 { i16_core::i16_bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: i16, rhs: i16) -> i16 { + i16_core::i16_bitwise_or(lhs, rhs) + } } use orion::numbers::signed_integer::i32 as i32_core; @@ -1726,6 +1759,10 @@ impl i32Number of NumberTrait { fn bitwise_and(lhs: i32, rhs: i32) -> i32 { i32_core::i32_bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: i32, rhs: i32) -> i32 { + i32_core::i32_bitwise_or(lhs, rhs) + } } use orion::numbers::signed_integer::i64 as i64_core; @@ -1922,6 +1959,10 @@ impl i64Number of NumberTrait { fn bitwise_and(lhs: i64, rhs: i64) -> i64 { i64_core::i64_bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: i64, rhs: i64) -> i64 { + i64_core::i64_bitwise_or(lhs, rhs) + } } use orion::numbers::signed_integer::i128 as i128_core; @@ -2119,6 +2160,10 @@ impl i128Number of NumberTrait { fn bitwise_and(lhs: i128, rhs: i128) -> i128 { i128_core::i128_bitwise_and(lhs, rhs) } + + fn bitwise_or(lhs: i128, rhs: i128) -> i128 { + i128_core::i128_bitwise_or(lhs, rhs) + } } impl u32Number of NumberTrait { @@ -2321,4 +2366,8 @@ impl u32Number of NumberTrait { fn bitwise_and(lhs: u32, rhs: u32) -> u32 { lhs & rhs } + + fn bitwise_or(lhs: u32, rhs: u32) -> u32 { + lhs | rhs + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 12003fc75..55d1fc6c4 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP16x16, b: FP16x16) -> FP16x16 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_or(a: FP16x16, b: FP16x16) -> FP16x16 { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 012d959c1..b14a71fcd 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP16x16W, b: FP16x16W) -> FP16x16W { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_or(a: FP16x16W, b: FP16x16W) -> FP16x16W { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo index ed1fa7d92..ce32d6879 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo @@ -38,3 +38,7 @@ fn where(a: FP32x32, b: FP32x32, c: FP32x32) -> FP32x32 { fn bitwise_and(a: FP32x32, b: FP32x32) -> FP32x32 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } + +fn bitwise_or(a: FP32x32, b: FP32x32) -> FP32x32 { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} \ No newline at end of file diff --git a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo index 98528a00c..b5e249995 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo @@ -38,3 +38,7 @@ fn where(a: FP64x64, b: FP64x64, c: FP64x64) -> FP64x64 { fn bitwise_and(a: FP64x64, b: FP64x64) -> FP64x64 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } + +fn bitwise_or(a: FP64x64, b: FP64x64) -> FP64x64 { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index f329371e6..647d8b9cb 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP8x23, b: FP8x23) -> FP8x23 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_or(a: FP8x23, b: FP8x23) -> FP8x23 { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index da3739fb0..a822400ba 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP8x23W, b: FP8x23W) -> FP8x23W { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_or(a: FP8x23W, b: FP8x23W) -> FP8x23W { + return FixedTrait::new(a.mag | b.mag, a.sign | b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index 93608fe24..f8b765775 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -473,3 +473,7 @@ fn i128_sign(a: i128) -> i128 { fn i128_bitwise_and(a: i128, b: i128) -> i128 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i128_bitwise_or(a: i128, b: i128) -> i128 { + IntegerTrait::::new(a.mag | b.mag, a.sign | b.sign) +} diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index c51c803bd..aa5a35755 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -473,3 +473,8 @@ fn i16_sign(a: i16) -> i16 { fn i16_bitwise_and(a: i16, b: i16) -> i16 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i16_bitwise_or(a: i16, b: i16) -> i16 { + IntegerTrait::::new(a.mag | b.mag, a.sign | b.sign) +} + diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index ee44c73b1..d4069d6f5 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -505,3 +505,7 @@ fn i32_sign(a: i32) -> i32 { fn i32_bitwise_and(a: i32, b: i32) -> i32 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i32_bitwise_or(a: i32, b: i32) -> i32 { + IntegerTrait::::new(a.mag | b.mag, a.sign | b.sign) +} diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index 0b5db1c6b..55f6e9630 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -473,3 +473,7 @@ fn i64_sign(a: i64) -> i64 { fn i64_bitwise_and(a: i64, b: i64) -> i64 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i64_bitwise_or(a: i64, b: i64) -> i64 { + IntegerTrait::::new(a.mag | b.mag, a.sign | b.sign) +} diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 72e92e911..4a2439b36 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -550,3 +550,7 @@ fn i8_sign(a: i8) -> i8 { fn i8_bitwise_and(a: i8, b: i8) -> i8 { return IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign); } + +fn i8_bitwise_or(a: i8, b: i8) -> i8 { + return IntegerTrait::::new(a.mag | b.mag, a.sign | b.sign); +} From 9890380af5ea5377ded8315ad03f88e3255166fb Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Sat, 25 Nov 2023 22:00:22 +0300 Subject: [PATCH 114/160] feat: bitwise_or tensor operator added --- src/operators/tensor/core.cairo | 46 ++++++++++++++++++ .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/bitwise_or.cairo | 47 +++++++++++++++++++ 13 files changed, 134 insertions(+) create mode 100644 src/operators/tensor/math/bitwise_or.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..6d8f50c89 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3423,6 +3423,52 @@ trait TensorTrait { /// ``` /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; + /// #tensor.bitwise_or + /// + /// ```rust + /// fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the bitwise OR 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` with the same shape as the broadcasted inputs. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn or_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, 4, 5, 0, 6, 2].span(), + /// ); + /// + /// return tensor_1.bitwise_or(@tensor_2); + /// } + /// >>> [0,1,2,3,4,5,6,7,10] + /// ``` + /// + fn bitwise_or(self: @Tensor, other: @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 29bf1c77b..8f493171d 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -296,6 +296,10 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn bitwise_or(self: @Tensor, other: @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_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..165c9d17e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -311,6 +311,10 @@ impl FP16x16Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 68f2482e7..2c5fa0cc0 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -299,6 +299,10 @@ impl FP16x16WTensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 f764b1920..71703cc04 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -312,6 +312,10 @@ impl FP32x32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 6cded29b3..292712617 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -312,6 +312,10 @@ impl FP64x64Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 fdcdac1eb..6dde019a6 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -311,6 +311,10 @@ impl FP8x23Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 510731702..4619dc44c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -289,6 +289,10 @@ impl FP8x23WTensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 8017ab300..12976036e 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -311,6 +311,10 @@ impl I32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 4f2731b80..c56a228cd 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -310,6 +310,10 @@ impl I8Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + 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 2f3c3a2ef..b164e8f2f 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -281,6 +281,10 @@ impl U32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_or::bitwise_or(self, other) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..c4835965d 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -43,3 +43,4 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod bitwise_or; diff --git a/src/operators/tensor/math/bitwise_or.cairo b/src/operators/tensor/math/bitwise_or.cairo new file mode 100644 index 000000000..ca3fea6c9 --- /dev/null +++ b/src/operators/tensor/math/bitwise_or.cairo @@ -0,0 +1,47 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::helpers::{ + broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility +}; + +/// Cf: TensorTrait::and docstring +fn bitwise_or< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: 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); + + let lhs = *(*y.data)[indices_self]; + let rhs = *(*z.data)[indices_other]; + + result.append(NumberTrait::bitwise_or(lhs, rhs)); + + n += 1; + if n == num_elements { + break (); + }; + }; + + return TensorTrait::::new(broadcasted_shape, result.span()); +} From 81ad616cc307dc55b3920379940445c8770ae814 Mon Sep 17 00:00:00 2001 From: bilgin-kocak Date: Sat, 25 Nov 2023 22:19:01 +0300 Subject: [PATCH 115/160] test: bitwise_or unit tests added --- .../implementations/fp16x16/math/comp.cairo | 11 ++++++++++- .../implementations/fp16x16wide/math/comp.cairo | 11 ++++++++++- .../implementations/fp8x23/math/comp.cairo | 10 +++++++++- .../implementations/fp8x23wide/math/comp.cairo | 10 +++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 55d1fc6c4..223f0d313 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_or(a: FP16x16, b: FP16x16) -> FP16x16 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_or}; #[test] @@ -113,4 +113,13 @@ mod tests { assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_or() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(4160974848, true); + + assert(bitwise_or(a, b) == c, 'bitwise_or(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index b14a71fcd..fa63fca8e 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_or(a: FP16x16W, b: FP16x16W) -> FP16x16W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_or}; #[test] @@ -113,4 +113,13 @@ mod tests { assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_or() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(4160974848, true); + + assert(bitwise_or(a, b) == c, 'bitwise_or(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index 647d8b9cb..1dfc31b85 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_or(a: FP8x23, b: FP8x23) -> FP8x23 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_or}; #[test] fn test_max() { @@ -110,4 +110,12 @@ mod tests { assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_or() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + + assert(bitwise_or(a, b) == b, 'bitwise_or(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index a822400ba..a67f0bf2c 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_or(a: FP8x23W, b: FP8x23W) -> FP8x23W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_or}; #[test] @@ -112,4 +112,12 @@ mod tests { assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_or() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + + assert(bitwise_or(a, b) == b, 'bitwise_or(a,b)') + } } From 28f18ad669314e667d6842854475924bc1575eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Sat, 25 Nov 2023 19:36:56 +0000 Subject: [PATCH 116/160] docs: bitwise_or docs added --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.bitwise_or.md | 44 +++++++++++++++++++ src/operators/tensor/core.cairo | 1 + 5 files changed, 48 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.bitwise_or.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..69a69899e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -95,6 +95,7 @@ * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.md) + * [tensor.bitwise_or](framework/operators/tensor/tensor.bitwise_or.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index ebc50ad77..2cf0d9403 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -72,6 +72,7 @@ You can see below the list of current supported ONNX Operators: | [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: | | [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: | | [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: | +| [BitwiseOr](operators/tensor/tensor.bitwise_or.md) | :white\_check\_mark: | | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..adbf3b3c7 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -92,6 +92,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.bitwise_and`](tensor.bitwise\_and.md) | Computes the bitwise AND of two tensors element-wise. | +| [`tensor.bitwise_or`](tensor.bitwise\_or.md) | Computes the bitwise OR of two tensors element-wise. | | [`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. | | [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. | diff --git a/docs/framework/operators/tensor/tensor.bitwise_or.md b/docs/framework/operators/tensor/tensor.bitwise_or.md new file mode 100644 index 000000000..ac3ac4f38 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.bitwise_or.md @@ -0,0 +1,44 @@ +#tensor.bitwise_or + +```rust + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor; +``` + +Computes the bitwise OR 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` with the same shape as the broadcasted inputs. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn or_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, 4, 5, 0, 6, 2].span(), + ); + + return tensor_1.bitwise_or(@tensor_2); +} +>>> [0,1,2,3,4,5,6,7,10] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 6d8f50c89..e5830e02b 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -88,6 +88,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde Date: Sat, 25 Nov 2023 19:43:37 +0000 Subject: [PATCH 117/160] docs: operator count changed --- docs/framework/compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index 2cf0d9403..6cbcb8103 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -83,4 +83,4 @@ You can see below the list of current supported ONNX Operators: | [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | -Current Operators support: **75/156 (48%)** +Current Operators support: **76/156 (48%)** From 59ece647cb7f8e760a1a62c0ec1b83e80ffcd9b5 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Sun, 26 Nov 2023 03:38:08 -0300 Subject: [PATCH 118/160] added comp and summary --- docs/SUMMARY.md | 347 ++++++++++++------ docs/framework/compatibility.md | 222 +++++++---- docs/framework/operators/tensor/README.md | 1 + docs/framework/operators/tensor/tensor.not.md | 39 ++ src/operators/tensor/core.cairo | 27 ++ .../tensor/implementations/tensor_bool.cairo | 5 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math/not.cairo | 2 - .../tensor/math/optional_get_element.cairo | 31 ++ tests/nodes/not_bool.cairo | 2 +- 18 files changed, 509 insertions(+), 203 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.not.md create mode 100644 src/operators/tensor/math/optional_get_element.cairo diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 837752e5e..04ca10bfe 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -2,138 +2,243 @@ ## 👋 Welcome -* [Orion](README.md) -* [Why Validity ML?](welcome/why-validity-ml.md) +- [Orion](README.md) +- [Why Validity ML?](welcome/why-validity-ml.md) ## 🧱 Framework +- [Get Started](framework/get-started.md) +- [Contribute](framework/contribute.md) +- [Compatibility](framework/compatibility.md) +- [Numbers](framework/numbers/README.md) + - [Signed Integer](framework/numbers/signed-integer/README.md) + - [int.new](framework/numbers/signed-integer/int.new.md) + - [int.div_rem](framework/numbers/signed-integer/int.div_rem.md) + - [int.abs](framework/numbers/signed-integer/int.abs.md) + - [int.max](framework/numbers/signed-integer/int.max.md) + - [int.min](framework/numbers/signed-integer/int.min.md) + - [int.sign](framework/numbers/signed-integer/int.sign.md) + - [Fixed Point](framework/numbers/fixed-point/README.md) + - [fp.new](framework/numbers/fixed-point/fp.new.md) + - [fp.new_unscaled](framework/numbers/fixed-point/fp.new_unscaled.md) + - [fp.from_felt](framework/numbers/fixed-point/fp.from_felt.md) + - [fp.abs](framework/numbers/fixed-point/fp.abs.md) + - [fp.ceil](framework/numbers/fixed-point/fp.ceil.md) + - [fp.floor](framework/numbers/fixed-point/fp.floor.md) + - [fp.exp](framework/numbers/fixed-point/fp.exp.md) + - [fp.exp2](framework/numbers/fixed-point/fp.exp2.md) + - [fp.log](framework/numbers/fixed-point/fp.log.md) + - [fp.log2](framework/numbers/fixed-point/fp.log2.md) + - [fp.log10](framework/numbers/fixed-point/fp.log10.md) + - [fp.pow](framework/numbers/fixed-point/fp.pow.md) + - [fp.round](framework/numbers/fixed-point/fp.round.md) + - [fp.sqrt](framework/numbers/fixed-point/fp.sqrt.md) + - [fp.sin](framework/numbers/fixed-point/fp.sin.md) + - [fp.atan](framework/numbers/fixed-point/fp.atan.md) + - [fp.sign](framework/numbers/fixed-point/fp.sign.md) +- [Operators](framework/operators/README.md) + - [Tensor](framework/operators/tensor/README.md) + - [tensor.new](framework/operators/tensor/tensor.new.md) + - [tensor.at](framework/operators/tensor/tensor.at.md) + - [tensor.min_in_tensor](framework/operators/tensor/tensor.min_in_tensor.md) + - [tensor.min](framework/operators/tensor/tensor.min.md) + - [tensor.max_in_tensor](framework/operators/tensor/tensor.max_in_tensor.md) + - [tensor.max](framework/operators/tensor/tensor.max.md) + - [tensor.stride](framework/operators/tensor/tensor.stride.md) + - [tensor.ravel_index](framework/operators/tensor/tensor.ravel_index.md) + - [tensor.unravel_index](framework/operators/tensor/tensor.unravel_index.md) + - [tensor.reshape](framework/operators/tensor/tensor.reshape.md) + - [tensor.transpose](framework/operators/tensor/tensor.transpose.md) + - [tensor.reduce_sum](framework/operators/tensor/tensor.reduce_sum.md) + - [tensor.argmax](framework/operators/tensor/tensor.argmax.md) + - [tensor.argmin](framework/operators/tensor/tensor.argmin.md) + - [tensor.matmul](framework/operators/tensor/tensor.matmul.md) + - [tensor.exp](framework/operators/tensor/tensor.exp.md) + - [tensor.log](framework/operators/tensor/tensor.log.md) + - [tensor.equal](framework/operators/tensor/tensor.equal.md) + - [tensor.greater](framework/operators/tensor/tensor.greater.md) + - [tensor.greater_equal](framework/operators/tensor/tensor.greater_equal.md) + - [tensor.less](framework/operators/tensor/tensor.less.md) + - [tensor.less_equal](framework/operators/tensor/tensor.less_equal.md) + - [tensor.abs](framework/operators/tensor/tensor.abs.md) + - [tensor.neg](framework/operators/tensor/tensor.neg.md) + - [tensor.ceil](framework/operators/tensor/tensor.ceil.md) + - [tensor.cumsum](framework/operators/tensor/tensor.cumsum.md) + - [tensor.sin](framework/operators/tensor/tensor.sin.md) + - [tensor.cos](framework/operators/tensor/tensor.cos.md) + - [tensor.asin](framework/operators/tensor/tensor.asin.md) + - [tensor.flatten](framework/operators/tensor/tensor.flatten.md) + - [tensor.sinh](framework/operators/tensor/tensor.sinh.md) + - [tensor.asinh](framework/operators/tensor/tensor.asinh.md) + - [tensor.cosh](framework/operators/tensor/tensor.cosh.md) + - [tensor.acosh](framework/operators/tensor/tensor.acosh.md) + - [tensor.tanh](framework/operators/tensor/tensor.tanh.md) + - [tensor.atan](framework/operators/tensor/tensor.atan.md) + - [tensor.acos](framework/operators/tensor/tensor.acos.md) + - [tensor.sqrt](framework/operators/tensor/tensor.sqrt.md) + - [tensor.or](framework/operators/tensor/tensor.or.md) + - [tensor.xor](framework/operators/tensor/tensor.xor.md) + - [tensor.onehot](framework/operators/tensor/tensor.onehot.md) + - [tensor.slice](framework/operators/tensor/tensor.slice.md) + - [tensor.concat](framework/operators/tensor/tensor.concat.md) + - [tensor.gather](framework/operators/tensor/tensor.gather.md) + - [tensor.quantize_linear](framework/operators/tensor/tensor.quantize_linear.md) + - [tensor.dequantize_linear](framework/operators/tensor/tensor.dequantize_linear.md) + - [tensor.qlinear_add](framework/operators/tensor/tensor.qlinear_add.md) + - [tensor.qlinear_matmul](framework/operators/tensor/tensor.qlinear_matmul.md) + - [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) + - [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) + - [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) + - [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) + - [tensor.where](framework/operators/tensor/tensor.where.md) + - [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.md) + - [tensor.round](framework/operators/tensor/tensor.round.md) + - [tensor.scatter](framework/operators/tensor/tensor.scatter.md) + - [tensor.array_feature_extractor](framework/operators/tensor/tensor.array_feature_extractor.md) + - [tensor.binarizer](framework/operators/tensor/tensor.binarizer.md) + - [tensor.reduce_sum_square](framework/operators/tensor/tensor.reduce_sum_square.md) + - [tensor.reduce_l2](framework/operators/tensor/tensor.reduce_l2.md) + - [tensor.reduce_l1](framework/operators/tensor/tensor.reduce_l1.md) + - [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) + - [nn.sigmoid](framework/operators/neural-network/nn.sigmoid.md) + - [nn.softmax](framework/operators/neural-network/nn.softmax.md) + - [nn.logsoftmax](framework/operators/neural-network/nn.logsoftmax.md) + - [nn.softsign](framework/operators/neural-network/nn.softsign.md) + - [nn.softplus](framework/operators/neural-network/nn.softplus.md) + - [nn.linear](framework/operators/neural-network/nn.linear.md) + - [nn.hard_sigmoid](framework/operators/neural-network/nn.hard_sigmoid.md) + - [nn.thresholded_relu](framework/operators/neural-network/nn.thresholded_relu.md) + - [nn.gemm](framework/operators/neural-network/nn.gemm.md) + - [Machine Learning](framework/operators/machine-learning/README.md) + - [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) + - [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md) + - [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) + - [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) + - [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) + - [tree.predict](framework/operators/machine-learning/tree-classifier/tree.predict.md) + - [tree.predict_proba](framework/operators/machine-learning/tree-classifier/tree.predict_proba.md) + - [XGBoost Regressor](framework/operators/machine-learning/xgboost-regressor/README.md) + - [xgboost.predict](framework/operators/machine-learning/xgboost-regressor/xgboost.predict.md) + * [Get Started](framework/get-started.md) * [Contribute](framework/contribute.md) * [Compatibility](framework/compatibility.md) * [Numbers](framework/numbers/README.md) - * [Signed Integer](framework/numbers/signed-integer/README.md) - * [int.new](framework/numbers/signed-integer/int.new.md) - * [int.div\_rem](framework/numbers/signed-integer/int.div\_rem.md) - * [int.abs](framework/numbers/signed-integer/int.abs.md) - * [int.max](framework/numbers/signed-integer/int.max.md) - * [int.min](framework/numbers/signed-integer/int.min.md) - * [int.sign](framework/numbers/signed-integer/int.sign.md) - * [Fixed Point](framework/numbers/fixed-point/README.md) - * [fp.new](framework/numbers/fixed-point/fp.new.md) - * [fp.new\_unscaled](framework/numbers/fixed-point/fp.new\_unscaled.md) - * [fp.from\_felt](framework/numbers/fixed-point/fp.from\_felt.md) - * [fp.abs](framework/numbers/fixed-point/fp.abs.md) - * [fp.ceil](framework/numbers/fixed-point/fp.ceil.md) - * [fp.floor](framework/numbers/fixed-point/fp.floor.md) - * [fp.exp](framework/numbers/fixed-point/fp.exp.md) - * [fp.exp2](framework/numbers/fixed-point/fp.exp2.md) - * [fp.log](framework/numbers/fixed-point/fp.log.md) - * [fp.log2](framework/numbers/fixed-point/fp.log2.md) - * [fp.log10](framework/numbers/fixed-point/fp.log10.md) - * [fp.pow](framework/numbers/fixed-point/fp.pow.md) - * [fp.round](framework/numbers/fixed-point/fp.round.md) - * [fp.sqrt](framework/numbers/fixed-point/fp.sqrt.md) - * [fp.sin](framework/numbers/fixed-point/fp.sin.md) - * [fp.atan](framework/numbers/fixed-point/fp.atan.md) - * [fp.sign](framework/numbers/fixed-point/fp.sign.md) + - [Signed Integer](framework/numbers/signed-integer/README.md) + - [int.new](framework/numbers/signed-integer/int.new.md) + - [int.div_rem](framework/numbers/signed-integer/int.div_rem.md) + - [int.abs](framework/numbers/signed-integer/int.abs.md) + - [int.max](framework/numbers/signed-integer/int.max.md) + - [int.min](framework/numbers/signed-integer/int.min.md) + - [int.sign](framework/numbers/signed-integer/int.sign.md) + - [Fixed Point](framework/numbers/fixed-point/README.md) + - [fp.new](framework/numbers/fixed-point/fp.new.md) + - [fp.new_unscaled](framework/numbers/fixed-point/fp.new_unscaled.md) + - [fp.from_felt](framework/numbers/fixed-point/fp.from_felt.md) + - [fp.abs](framework/numbers/fixed-point/fp.abs.md) + - [fp.ceil](framework/numbers/fixed-point/fp.ceil.md) + - [fp.floor](framework/numbers/fixed-point/fp.floor.md) + - [fp.exp](framework/numbers/fixed-point/fp.exp.md) + - [fp.exp2](framework/numbers/fixed-point/fp.exp2.md) + - [fp.log](framework/numbers/fixed-point/fp.log.md) + - [fp.log2](framework/numbers/fixed-point/fp.log2.md) + - [fp.log10](framework/numbers/fixed-point/fp.log10.md) + - [fp.pow](framework/numbers/fixed-point/fp.pow.md) + - [fp.round](framework/numbers/fixed-point/fp.round.md) + - [fp.sqrt](framework/numbers/fixed-point/fp.sqrt.md) + - [fp.sin](framework/numbers/fixed-point/fp.sin.md) + - [fp.atan](framework/numbers/fixed-point/fp.atan.md) + - [fp.sign](framework/numbers/fixed-point/fp.sign.md) * [Operators](framework/operators/README.md) - * [Tensor](framework/operators/tensor/README.md) - * [tensor.new](framework/operators/tensor/tensor.new.md) - * [tensor.at](framework/operators/tensor/tensor.at.md) - * [tensor.min_in_tensor](framework/operators/tensor/tensor.min_in_tensor.md) - * [tensor.min](framework/operators/tensor/tensor.min.md) - * [tensor.max\_in\_tensor](framework/operators/tensor/tensor.max\_in\_tensor.md) - * [tensor.max](framework/operators/tensor/tensor.max.md) - * [tensor.stride](framework/operators/tensor/tensor.stride.md) - * [tensor.ravel\_index](framework/operators/tensor/tensor.ravel\_index.md) - * [tensor.unravel\_index](framework/operators/tensor/tensor.unravel\_index.md) - * [tensor.reshape](framework/operators/tensor/tensor.reshape.md) - * [tensor.transpose](framework/operators/tensor/tensor.transpose.md) - * [tensor.reduce\_sum](framework/operators/tensor/tensor.reduce\_sum.md) - * [tensor.argmax](framework/operators/tensor/tensor.argmax.md) - * [tensor.argmin](framework/operators/tensor/tensor.argmin.md) - * [tensor.matmul](framework/operators/tensor/tensor.matmul.md) - * [tensor.exp](framework/operators/tensor/tensor.exp.md) - * [tensor.log](framework/operators/tensor/tensor.log.md) - * [tensor.equal](framework/operators/tensor/tensor.equal.md) - * [tensor.greater](framework/operators/tensor/tensor.greater.md) - * [tensor.greater\_equal](framework/operators/tensor/tensor.greater\_equal.md) - * [tensor.less](framework/operators/tensor/tensor.less.md) - * [tensor.less\_equal](framework/operators/tensor/tensor.less\_equal.md) - * [tensor.abs](framework/operators/tensor/tensor.abs.md) - * [tensor.neg](framework/operators/tensor/tensor.neg.md) - * [tensor.ceil](framework/operators/tensor/tensor.ceil.md) - * [tensor.cumsum](framework/operators/tensor/tensor.cumsum.md) - * [tensor.sin](framework/operators/tensor/tensor.sin.md) - * [tensor.cos](framework/operators/tensor/tensor.cos.md) - * [tensor.asin](framework/operators/tensor/tensor.asin.md) - * [tensor.flatten](framework/operators/tensor/tensor.flatten.md) - * [tensor.sinh](framework/operators/tensor/tensor.sinh.md) - * [tensor.asinh](framework/operators/tensor/tensor.asinh.md) - * [tensor.cosh](framework/operators/tensor/tensor.cosh.md) - * [tensor.acosh](framework/operators/tensor/tensor.acosh.md) - * [tensor.tanh](framework/operators/tensor/tensor.tanh.md) - * [tensor.atan](framework/operators/tensor/tensor.atan.md) - * [tensor.acos](framework/operators/tensor/tensor.acos.md) - * [tensor.sqrt](framework/operators/tensor/tensor.sqrt.md) - * [tensor.or](framework/operators/tensor/tensor.or.md) - * [tensor.xor](framework/operators/tensor/tensor.xor.md) - * [tensor.onehot](framework/operators/tensor/tensor.onehot.md) - * [tensor.slice](framework/operators/tensor/tensor.slice.md) - * [tensor.concat](framework/operators/tensor/tensor.concat.md) - * [tensor.gather](framework/operators/tensor/tensor.gather.md) - * [tensor.quantize\_linear](framework/operators/tensor/tensor.quantize\_linear.md) - * [tensor.dequantize\_linear](framework/operators/tensor/tensor.dequantize\_linear.md) - * [tensor.qlinear\_add](framework/operators/tensor/tensor.qlinear\_add.md) - * [tensor.qlinear\_matmul](framework/operators/tensor/tensor.qlinear\_matmul.md) - * [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) - * [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) - * [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) - * [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) - * [tensor.where](framework/operators/tensor/tensor.where.md) - * [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.md) - * [tensor.round](framework/operators/tensor/tensor.round.md) - * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) - * [tensor.array_feature_extractor](framework/operators/tensor/tensor.array\_feature\_extractor.md) - * [tensor.binarizer](framework/operators/tensor/tensor.binarizer.md) - * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) - * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) - * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) - * [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) - * [nn.sigmoid](framework/operators/neural-network/nn.sigmoid.md) - * [nn.softmax](framework/operators/neural-network/nn.softmax.md) - * [nn.logsoftmax](framework/operators/neural-network/nn.logsoftmax.md) - * [nn.softsign](framework/operators/neural-network/nn.softsign.md) - * [nn.softplus](framework/operators/neural-network/nn.softplus.md) - * [nn.linear](framework/operators/neural-network/nn.linear.md) - * [nn.hard\_sigmoid](framework/operators/neural-network/nn.hard\_sigmoid.md) - * [nn.thresholded\_relu](framework/operators/neural-network/nn.thresholded_relu.md) - * [nn.gemm](framework/operators/neural-network/nn.gemm.md) - * [Machine Learning](framework/operators/machine-learning/README.md) - * [Tree Ensemble Classifier](framework/operators/machine-learning/tree-ensemble-classifier/README.md) - * [tree_ensemble_classifier.predict](framework/operators/machine-learning/tree-ensemble-classifier/tree_ensemble_classifier.predict.md) - * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) - * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) - * [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) - * [tree.predict](framework/operators/machine-learning/tree-classifier/tree.predict.md) - * [tree.predict_proba](framework/operators/machine-learning/tree-classifier/tree.predict_proba.md) - * [XGBoost Regressor](framework/operators/machine-learning/xgboost-regressor/README.md) - * [xgboost.predict](framework/operators/machine-learning/xgboost-regressor/xgboost.predict.md) + - [Tensor](framework/operators/tensor/README.md) + - [tensor.new](framework/operators/tensor/tensor.new.md) + - [tensor.at](framework/operators/tensor/tensor.at.md) + - [tensor.min](framework/operators/tensor/tensor.min.md) + - [tensor.max](framework/operators/tensor/tensor.max.md) + - [tensor.stride](framework/operators/tensor/tensor.stride.md) + - [tensor.ravel_index](framework/operators/tensor/tensor.ravel_index.md) + - [tensor.unravel_index](framework/operators/tensor/tensor.unravel_index.md) + - [tensor.reshape](framework/operators/tensor/tensor.reshape.md) + - [tensor.transpose](framework/operators/tensor/tensor.transpose.md) + - [tensor.reduce_sum](framework/operators/tensor/tensor.reduce_sum.md) + - [tensor.argmax](framework/operators/tensor/tensor.argmax.md) + - [tensor.argmin](framework/operators/tensor/tensor.argmin.md) + - [tensor.matmul](framework/operators/tensor/tensor.matmul.md) + - [tensor.exp](framework/operators/tensor/tensor.exp.md) + - [tensor.log](framework/operators/tensor/tensor.log.md) + - [tensor.equal](framework/operators/tensor/tensor.equal.md) + - [tensor.greater](framework/operators/tensor/tensor.greater.md) + - [tensor.greater_equal](framework/operators/tensor/tensor.greater_equal.md) + - [tensor.less](framework/operators/tensor/tensor.less.md) + - [tensor.less_equal](framework/operators/tensor/tensor.less_equal.md) + - [tensor.abs](framework/operators/tensor/tensor.abs.md) + - [tensor.neg](framework/operators/tensor/tensor.neg.md) + - [tensor.ceil](framework/operators/tensor/tensor.ceil.md) + - [tensor.cumsum](framework/operators/tensor/tensor.cumsum.md) + - [tensor.sin](framework/operators/tensor/tensor.sin.md) + - [tensor.cos](framework/operators/tensor/tensor.cos.md) + - [tensor.asin](framework/operators/tensor/tensor.asin.md) + - [tensor.flatten](framework/operators/tensor/tensor.flatten.md) + - [tensor.sinh](framework/operators/tensor/tensor.sinh.md) + - [tensor.asinh](framework/operators/tensor/tensor.asinh.md) + - [tensor.cosh](framework/operators/tensor/tensor.cosh.md) + - [tensor.acosh](framework/operators/tensor/tensor.acosh.md) + - [tensor.tanh](framework/operators/tensor/tensor.tanh.md) + - [tensor.atan](framework/operators/tensor/tensor.atan.md) + - [tensor.acos](framework/operators/tensor/tensor.acos.md) + - [tensor.sqrt](framework/operators/tensor/tensor.sqrt.md) + - [tensor.or](framework/operators/tensor/tensor.or.md) + - [tensor.xor](framework/operators/tensor/tensor.xor.md) + - [tensor.onehot](framework/operators/tensor/tensor.onehot.md) + - [tensor.slice](framework/operators/tensor/tensor.slice.md) + - [tensor.concat](framework/operators/tensor/tensor.concat.md) + - [tensor.gather](framework/operators/tensor/tensor.gather.md) + - [tensor.quantize_linear](framework/operators/tensor/tensor.quantize_linear.md) + - [tensor.dequantize_linear](framework/operators/tensor/tensor.dequantize_linear.md) + - [tensor.nonzero](framework/operators/tensor/tensor.nonzero.md) + - [tensor.squeeze](framework/operators/tensor/tensor.squeeze.md) + - [tensor.unsqueeze](framework/operators/tensor/tensor.unsqueeze.md) + - [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) + - [tensor.where](framework/operators/tensor/tensor.where.md) + - [tensor.not](framework/operators/tensor/tensor.not.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) + - [nn.sigmoid](framework/operators/neural-network/nn.sigmoid.md) + - [nn.softmax](framework/operators/neural-network/nn.softmax.md) + - [nn.logsoftmax](framework/operators/neural-network/nn.logsoftmax.md) + - [nn.softsign](framework/operators/neural-network/nn.softsign.md) + - [nn.softplus](framework/operators/neural-network/nn.softplus.md) + - [nn.linear](framework/operators/neural-network/nn.linear.md) + - [nn.hard_sigmoid](framework/operators/neural-network/nn.hard_sigmoid.md) + - [nn.thresholded_relu](framework/operators/neural-network/nn.thresholded_relu.md) + - [nn.gemm](framework/operators/neural-network/nn.gemm.md) + - [Machine Learning](framework/operators/machine-learning/README.md) + - [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) + - [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) + - [Tree Classifier](framework/operators/machine-learning/tree-classifier/README.md) + - [tree.predict](framework/operators/machine-learning/tree-classifier/tree.predict.md) + - [tree.predict_proba](framework/operators/machine-learning/tree-classifier/tree.predict_proba.md) + - [XGBoost Regressor](framework/operators/machine-learning/xgboost-regressor/README.md) + - [xgboost.predict](framework/operators/machine-learning/xgboost-regressor/xgboost.predict.md) ## 🏛 Hub -* [Models](hub/algorithms.md) -* [Spaces](hub/spaces.md) +- [Models](hub/algorithms.md) +- [Spaces](hub/spaces.md) ## 🧑🎓 Academy -* [Tutorials](academy/tutorials/README.md) - * [MNIST Classification with Orion](academy/tutorials/mnist-classification-with-orion.md) - * [Implement new operators in Orion](academy/tutorials/implement-new-operators-in-orion.md) - * [Verifiable Linear Regression Model](academy/tutorials/verifiable-linear-regression-model-in-orion.md) - * [Verifiable Support Vector Machine](academy/tutorials/verifiable-support-vector-machine.md) +- [Tutorials](academy/tutorials/README.md) + - [MNIST Classification with Orion](academy/tutorials/mnist-classification-with-orion.md) + - [Implement new operators in Orion](academy/tutorials/implement-new-operators-in-orion.md) + - [Verifiable Linear Regression Model](academy/tutorials/verifiable-linear-regression-model-in-orion.md) + - [Verifiable Support Vector Machine](academy/tutorials/verifiable-support-vector-machine.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index a631bd66b..dd233dcf1 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -4,84 +4,148 @@ 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: | -| [Atanh](operators/tensor/tensor.atanh.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: | -| [QlinearAdd](operators/tensor/tensor.qlinear\_add.md) | :white\_check\_mark: | -| [QLinearMatmul](operators/tensor/tensor.qlinear\_matmul.md) | :white\_check\_mark: | -| [Nonzero](operators/tensor/tensor.nonzero.md) | :white\_check\_mark: | -| [Squeeze](operators/tensor/tensor.squeeze.md) | :white\_check\_mark: | -| [Unsqueeze](operators/tensor/tensor.unsqueeze.md) | :white\_check\_mark: | -| [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: | -| [Xor](operators/tensor/tensor.xor.md) | :white\_check\_mark: | -| [Or](operators/tensor/tensor.or.md) | :white\_check\_mark: | -| [Gemm](operators/neural-network/nn.gemm.md) | :white\_check\_mark: | -| [MinInTensor](operators/tensor/tensor.min\_in\_tensor.md) | :white\_check\_mark: | -| [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: | -| [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: | -| [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: | -| [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | -| [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | -| [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | -| [ReduceSumSquare](operators/tensor/tensor.reduce\_sum\_square.md) | :white\_check\_mark: | -| [Trilu](operators/tensor/tensor.trilu.md) | :white\_check\_mark: | -| [Scatter](operators/tensor/scatter.max.md) | :white\_check\_mark: | -| [ArrayFeatureExtractor](operators/tensor/tensor.array\_feature\_extractor.md) | :white\_check\_mark: | -| [Binarizer](operators/tensor/tensor.binarizer.md) | :white\_check\_mark: | -| [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white\_check\_mark: | -| [ReduceL1](operators/tensor/tensor.reduce\_l1.md) | :white\_check\_mark: | -| [ReduceL2](operators/tensor/tensor.reduce\_l2.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: | +| [Atanh](operators/tensor/tensor.atanh.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: | +| [QlinearAdd](operators/tensor/tensor.qlinear_add.md) | :white_check_mark: | +| [QLinearMatmul](operators/tensor/tensor.qlinear_matmul.md) | :white_check_mark: | +| [Nonzero](operators/tensor/tensor.nonzero.md) | :white_check_mark: | +| [Squeeze](operators/tensor/tensor.squeeze.md) | :white_check_mark: | +| [Unsqueeze](operators/tensor/tensor.unsqueeze.md) | :white_check_mark: | +| [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: | +| [Xor](operators/tensor/tensor.xor.md) | :white_check_mark: | +| [Or](operators/tensor/tensor.or.md) | :white_check_mark: | +| [Gemm](operators/neural-network/nn.gemm.md) | :white_check_mark: | +| [MinInTensor](operators/tensor/tensor.min_in_tensor.md) | :white_check_mark: | +| [Min](operators/tensor/tensor.min.md) | :white_check_mark: | +| [Where](operators/tensor/tensor.where.md) | :white_check_mark: | +| [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white_check_mark: | +| [Round](operators/tensor/tensor.round.md) | :white_check_mark: | +| [MaxInTensor](operators/tensor/tensor.max_in_tensor.md) | :white_check_mark: | +| [Max](operators/tensor/tensor.max.md) | :white_check_mark: | +| [ReduceSumSquare](operators/tensor/tensor.reduce_sum_square.md) | :white_check_mark: | +| [Trilu](operators/tensor/tensor.trilu.md) | :white_check_mark: | +| [Scatter](operators/tensor/scatter.max.md) | :white_check_mark: | +| [ArrayFeatureExtractor](operators/tensor/tensor.array_feature_extractor.md) | :white_check_mark: | +| [Binarizer](operators/tensor/tensor.binarizer.md) | :white_check_mark: | +| [ConstantOfShape](operators/tensor/tensor.constant_of_shape.md) | :white_check_mark: | +| [ReduceL1](operators/tensor/tensor.reduce_l1.md) | :white_check_mark: | +| [ReduceL2](operators/tensor/tensor.reduce_l2.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: | +| [Atanh](operators/tensor/tensor.atanh.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: | +| [Xor](operators/tensor/tensor.xor.md) | :white_check_mark: | +| [Or](operators/tensor/tensor.or.md) | :white_check_mark: | +| [Gemm](operators/neural-network/nn.gemm.md) | :white_check_mark: | +| [Where](operators/tensor/tensor.where.md) | :white_check_mark: | +| [Not](operators/tensor/tensor.not.md) | :white_check_mark: | Current Operators support: **75/156 (48%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index fe1ccc7bc..0ae1ca383 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -64,6 +64,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.log`](tensor.log.md) | Computes the natural log of all elements of the input tensor. | | [`tensor.abs`](tensor.abs.md) | Computes the absolute value of all elements in the input tensor. | | [`tensor.neg`](tensor.neg.md) | Computes the negation of all elements in the input tensor. | +| [`tensor.not`](tensor.not.md) | Computes the logical negation of all elements in the input tensor. | | [`tensor.ceil`](tensor.ceil.md) | Rounds up the value of each element in the input tensor. | | [`tensor.sqrt`](tensor.sqrt.md) | Computes the square root of all elements of the input tensor. | | [`tensor.sin`](tensor.sin.md) | Computes the sine of all elements of the input tensor. | diff --git a/docs/framework/operators/tensor/tensor.not.md b/docs/framework/operators/tensor/tensor.not.md new file mode 100644 index 000000000..0add0277a --- /dev/null +++ b/docs/framework/operators/tensor/tensor.not.md @@ -0,0 +1,39 @@ +#tensor.not + +```rust + fn not(self: @Tensor) -> Tensor`) - The input tensor. + + +## Returns + +A new `Tensor` of the same shape as the input tensor with +the negation of all elements in the input tensor. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, BoolTensor}; +use orion::numbers::{i32, IntegerTrait}; + +fn not_example() -> Tensor { + let tensor = TensorTrait::new( + shape: array![3].span(), + data: array![ + true, true, false + ] + .span(), + ); + + return tensor.not(); +} +>>> [true, true, false] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 241003448..931ea04a0 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -60,6 +60,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ``` /// /// Computes the round value of all elements in the input tensor. + /// #tensor.not + /// + /// ```rust + /// fn not(self: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the negation of the elements in the bool type input tensor. /// /// ## Args /// @@ -3244,6 +3252,7 @@ trait TensorTrait { /// /// A new `Tensor` of the same shape as the input tensor with /// the round value of all elements in the input tensor. + /// the negation of all elements in the input tensor. /// /// ## Example /// @@ -3686,6 +3695,24 @@ trait TensorTrait { /// ``` /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// use orion::operators::tensor::{TensorTrait, Tensor, BoolTensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn not_example() -> Tensor { + /// let tensor = TensorTrait::new( + /// shape: array![3].span(), + /// data: array![ + /// true, true, false + /// ] + /// .span(), + /// ); + /// + /// return tensor.not(); + /// } + /// >>> [true, true, false] + /// ``` + /// + fn not(self: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 59263eafc..eb5354508 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -260,6 +260,10 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn not(self: @Tensor) -> Tensor { + math::not::not(*self) + } + fn qlinear_add( self: @Tensor, a_scale: @Tensor, @@ -320,6 +324,7 @@ impl BoolTensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } + } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index d430d2866..548182a2f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -348,6 +348,10 @@ impl FP16x16Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 49e708cb8..ecc04cd9e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -336,6 +336,10 @@ impl FP16x16WTensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// 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 757578bb1..738d2d4ab 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -349,6 +349,10 @@ impl FP32x32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { math::reduce_l2::reduce_l2(self, axis, keepdims) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// 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 793ad123d..2853afca3 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -349,6 +349,10 @@ impl FP64x64Tensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// 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 89cd0ff4a..bb4ef2fe9 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -348,6 +348,10 @@ impl FP8x23Tensor of TensorTrait { fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor { ml::array_feature_extractor::array_feature_extractor(*self, indices) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 76758d20a..52c3cbbbc 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -327,6 +327,10 @@ impl FP8x23WTensor of TensorTrait { ) -> Tensor { math::scatter::scatter(self, updates, indices, axis, reduction) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// 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 3fbc63c31..87ba9f62a 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -346,6 +346,10 @@ impl I32Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } + + fn not(self: @Tensor) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index a0f1bd14d..934d72908 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -346,6 +346,10 @@ impl I8Tensor of TensorTrait { } fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } + + fn not(self: @Tensor) -> Tensor { panic(array!['not supported!']) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index bdcd60858..d7bfa8478 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -318,6 +318,10 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } + + fn not(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math/not.cairo b/src/operators/tensor/math/not.cairo index f59daa20f..23b245a8b 100644 --- a/src/operators/tensor/math/not.cairo +++ b/src/operators/tensor/math/not.cairo @@ -10,9 +10,7 @@ use orion::operators::tensor::implementations::{tensor_bool::BoolTensor}; // Cf TensorTrait::not docstring fn not < T, - MAG, impl TTensor: TensorTrait, - impl TNumber: NumberTrait, impl TPartialOrd: PartialOrd, impl TCopy: Copy, impl TDrop: Drop diff --git a/src/operators/tensor/math/optional_get_element.cairo b/src/operators/tensor/math/optional_get_element.cairo new file mode 100644 index 000000000..47906db29 --- /dev/null +++ b/src/operators/tensor/math/optional_get_element.cairo @@ -0,0 +1,31 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::numbers::NumberTrait; + +/// Cf: TensorTrait::optional_get_element docstring +fn optional_get_element< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumberTrait: NumberTrait, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut z: Tensor, index: usize +) -> Tensor { + let mut data_result = ArrayTrait::::new(); + + // use of match to get element within and out the array bound + match z.data.get(index) { + Option::Some(item) => { data_result.append((*item.unbox())); }, + Option::None(_) => { + + } + }; + + + return TensorTrait::::new(z.shape, data_result.span()); +} diff --git a/tests/nodes/not_bool.cairo b/tests/nodes/not_bool.cairo index 1c5489895..eec0d20ca 100644 --- a/tests/nodes/not_bool.cairo +++ b/tests/nodes/not_bool.cairo @@ -14,7 +14,7 @@ fn test_not_bool() { let input_0 = input_0::input_0(); let z = output_0::output_0(); - let y = input_0; + let y = input_0.not(); assert_eq(y, z); } \ No newline at end of file From 81c538860df8ac208157f73880d2bfc631c94cf9 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Sun, 26 Nov 2023 16:09:25 +0430 Subject: [PATCH 119/160] implementing reduce prod operator --- src/operators/tensor/math/reduce_prod.cairo | 156 ++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/operators/tensor/math/reduce_prod.cairo diff --git a/src/operators/tensor/math/reduce_prod.cairo b/src/operators/tensor/math/reduce_prod.cairo new file mode 100644 index 000000000..5014ca38e --- /dev/null +++ b/src/operators/tensor/math/reduce_prod.cairo @@ -0,0 +1,156 @@ +use core::option::OptionTrait; +use core::traits::MulEq; +use array::ArrayTrait; +use array::SpanTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, ravel_index, unravel_index}; +use orion::operators::tensor::helpers::{reduce_output_shape, len_from_shape, combine_indices}; + +/// reduce_prod - Reduces a tensor to its products along specified axis. +fn reduce_prod< + T, + MAG, + impl TTensor: TensorTrait, + impl TNumber: NumberTrait, + impl TAddEq: AddEq, + impl TMulEq: MulEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + self: @Tensor, axis: usize, keepdims: bool +) -> Tensor { + /// Performs the reduction operation akin to ONNX's 'reduce_prod' on the given tensor for Orion Runtime. + /// + /// Given a tensor `self`, this function computes the product of elements along the specified axis. + /// If the tensor is one-dimensional, the axis must be 0. For multi-dimensional tensors, + /// the axis determines the dimension along which the reduction is performed. + /// + /// Arguments: + /// - `self`: A reference to the input tensor on which the reduction operation is applied. + /// - `axis`: The axis along which the reduction operation is performed. + /// - `keepdims`: A boolean flag indicating whether to keep the reduced dimension in the output shape. + /// + /// Returns: + /// - A new tensor resulting from the reduction operation. + /// If `keepdims` is `true`, the output tensor retains reduced dimensions; + /// otherwise, the reduced dimensions are eliminated from the output shape. + /// + /// # Panics + /// - Panics if the specified axis is out of the tensor's dimensions. + /// + /// # Examples + /// ```rust + /// // Create a tensor + /// let tensor_1 = TensorTrait::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),); + /// + /// // Reduce along axis 1 while keeping the dimension + /// let reduced = reduce_prod(@tensor_1, 1, true); + /// + /// // Verify the shape of the reduced tensor + /// assert(reduced.shape == array![2,1,2].span() , 'the tensors shapes are not equal'); + /// ``` + /// + /// # Notes + /// - This function utilizes accumulation of products along the specified axis to perform the reduction. + /// - For one-dimensional tensors, the axis must be 0 to compute the product of all elements. + /// + /// # See Also + /// - ONNX's 'reduce_prod' operation: https://github.com/onnx/onnx/blob/main/docs/Operators.md#ReduceProd + /// + /// # References + /// - Orion: https://orion.gizatech.xyz/ + /// - ONNX: Open Neural Network Exchange: https://onnx.ai/ + /// + /// ``` + let mut output_data = ArrayTrait::new(); + + if (*self.shape).len() == 1 { + assert(axis == 0, 'axis out of dimensions'); + let current_prod = accumulate_production::(*self.data, *self.shape, *self.shape, axis); + output_data.append(current_prod); + + let mut output_shape = ArrayTrait::new(); + output_shape.append(1); + + return TensorTrait::new(output_shape.span(), output_data.span()); + } else { + assert(axis <= (*self.shape).len(), 'axis out of dimensions'); + let output_shape = reduce_output_shape(*self.shape, axis, false); + let output_data_len = len_from_shape(output_shape); + let mut index: usize = 0; + loop { + let output_indices = unravel_index(index, output_shape); + let current_sum = accumulate_production::(*self.data, *self.shape, output_indices, axis); + + output_data.append(current_sum); + + index += 1; + if index == output_data_len { + break (); + }; + }; + + if keepdims { + let output_shape = reduce_output_shape(*self.shape, axis, true); + return TensorTrait::::new(output_shape, output_data.span()); + } else { + return TensorTrait::::new(output_shape, output_data.span()); + } + } +} + + +/// Helper function that accumulates the product of elements along a specific axis. +/// +/// # Arguments +/// * `input_data` - The input's data. +/// * `input_shape` - The input's shape. +/// * `output_indices` - A span of output indices. +/// * `axis` - The axis along which to accumulate the product. +/// +/// # Panics +/// * Panics if gas limit is exceeded during execution. +/// +/// # Returns +/// * An i32 value representing the accumulated product along the specified axis. +fn accumulate_production< + T, + MAG, + impl TNumber: NumberTrait, + impl TAddEq: AddEq, + impl TMulEq: MulEq, + impl TCopy: Copy, + impl TDrop: Drop +>( + mut input_data: Span, input_shape: Span, output_indices: Span, axis: usize +) -> T { + let axis_len = *(input_shape)[axis]; + let mut acc: T = NumberTrait::one(); + + let mut axis_index: usize = 0; + + if (input_shape).len() > 1 { + loop { + if axis_index == axis_len { + break (); + } + + let input_indices = combine_indices(output_indices, axis_index, axis); + let input_index = ravel_index(input_shape, input_indices); + let ele = *(input_data)[input_index]; + acc *= ele; + axis_index += 1; + }; + } else { + loop { + match input_data.pop_front() { + Option::Some(item) => { acc *= *item; }, + Option::None(_) => { break; } + }; + }; + } + + return acc; +} From bbad5bdb1ece7d4c63afaa43302acb9626c8360d Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Sun, 26 Nov 2023 14:55:46 +0100 Subject: [PATCH 120/160] Add tests --- nodegen/node/is_nan.py | 39 +++++++++++++++++++++++ tests/nodes.cairo | 2 ++ tests/nodes/is_nan_fp16x16.cairo | 22 +++++++++++++ tests/nodes/is_nan_fp16x16/input_0.cairo | 18 +++++++++++ tests/nodes/is_nan_fp16x16/output_0.cairo | 17 ++++++++++ tests/nodes/is_nan_fp8x23.cairo | 22 +++++++++++++ tests/nodes/is_nan_fp8x23/input_0.cairo | 18 +++++++++++ tests/nodes/is_nan_fp8x23/output_0.cairo | 17 ++++++++++ 8 files changed, 155 insertions(+) create mode 100644 nodegen/node/is_nan.py create mode 100644 tests/nodes/is_nan_fp16x16.cairo create mode 100644 tests/nodes/is_nan_fp16x16/input_0.cairo create mode 100644 tests/nodes/is_nan_fp16x16/output_0.cairo create mode 100644 tests/nodes/is_nan_fp8x23.cairo create mode 100644 tests/nodes/is_nan_fp8x23/input_0.cairo create mode 100644 tests/nodes/is_nan_fp8x23/output_0.cairo diff --git a/nodegen/node/is_nan.py b/nodegen/node/is_nan.py new file mode 100644 index 000000000..05f7ab5df --- /dev/null +++ b/nodegen/node/is_nan.py @@ -0,0 +1,39 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +# NaN is represented with -0 +NaN = -0 + +class Is_nan(RunAll): + + @staticmethod + def is_nan_fp8x23(): + def default(): + input_0 = np.array([-1.2, 0, NaN, 2.8, NaN, NaN], dtype=np.float64) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.FP8x23, input_0.shape, to_fp( + input_0.flatten(), FixedImpl.FP8x23)) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_nan_fp8x23" + make_test([input_0], output, "TensorTrait::is_nan(@input_0)", name) + + default() + + @staticmethod + def is_nan_fp16x16(): + def default(): + input_0 = np.array([-1.2, 0, NaN, 2.8, NaN, NaN], dtype=np.float64) + output = np.array([False, False, True, False, True, True], dtype=bool) + + input_0 = Tensor(Dtype.FP16x16, input_0.shape, to_fp( + input_0.flatten(), FixedImpl.FP16x16)) + output = Tensor(Dtype.BOOL, output.shape, output.flatten()) + + name = "is_nan_fp16x16" + make_test([input_0], output, "TensorTrait::is_nan(@input_0)", name) + + default() diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5d5fc5536..60775c397 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -763,3 +763,5 @@ mod sequence_insert_fp8x23; mod sequence_insert_i32; mod sequence_insert_i8; mod sequence_insert_u32; +mod is_nan_fp16x16; +mod is_nan_fp8x23; diff --git a/tests/nodes/is_nan_fp16x16.cairo b/tests/nodes/is_nan_fp16x16.cairo new file mode 100644 index 000000000..41d7a734e --- /dev/null +++ b/tests/nodes/is_nan_fp16x16.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::operators::tensor::BoolTensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_nan_fp16x16() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_nan(@input_0); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_nan_fp16x16/input_0.cairo b/tests/nodes/is_nan_fp16x16/input_0.cairo new file mode 100644 index 000000000..9977494b7 --- /dev/null +++ b/tests/nodes/is_nan_fp16x16/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, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 78643, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FixedTrait::NaN()); + data.append(FP16x16 { mag: 183500, sign: false }); + data.append(FixedTrait::NaN()); + data.append(FixedTrait::NaN()); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_nan_fp16x16/output_0.cairo b/tests/nodes/is_nan_fp16x16/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_nan_fp16x16/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_nan_fp8x23.cairo b/tests/nodes/is_nan_fp8x23.cairo new file mode 100644 index 000000000..4d2e27882 --- /dev/null +++ b/tests/nodes/is_nan_fp8x23.cairo @@ -0,0 +1,22 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::BoolTensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::BoolTensorPartialEq; + +#[test] +#[available_gas(2000000000)] +fn test_is_nan_fp8x23() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::is_nan(@input_0); + + assert_eq(y, z); +} diff --git a/tests/nodes/is_nan_fp8x23/input_0.cairo b/tests/nodes/is_nan_fp8x23/input_0.cairo new file mode 100644 index 000000000..5f2b3a1cc --- /dev/null +++ b/tests/nodes/is_nan_fp8x23/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, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 10066329, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FixedTrait::NaN()); + data.append(FP8x23 { mag: 23488102, sign: false }); + data.append(FixedTrait::NaN()); + data.append(FixedTrait::NaN()); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/is_nan_fp8x23/output_0.cairo b/tests/nodes/is_nan_fp8x23/output_0.cairo new file mode 100644 index 000000000..c7e7851fe --- /dev/null +++ b/tests/nodes/is_nan_fp8x23/output_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::BoolTensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(6); + + let mut data = ArrayTrait::new(); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + TensorTrait::new(shape.span(), data.span()) +} From ce9eb0af4609690d29c247f6bf1f1d9c1ab509c2 Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Sun, 26 Nov 2023 15:50:03 +0100 Subject: [PATCH 121/160] Add implementation --- src/operators/tensor/core.cairo | 40 +++++++++++++++++++ .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/is_nan.cairo | 30 ++++++++++++++ 13 files changed, 111 insertions(+) create mode 100644 src/operators/tensor/math/is_nan.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 5a3cf5936..f3d20e383 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -108,6 +108,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new @@ -4416,6 +4417,45 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; + /// ## tensor.is_nan + /// + /// ```rust + /// fn is_nan(self: @Tensor) -> Tensor; + /// ``` + /// + /// Maps NaN to true and other values to false. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// + /// ## Returns + /// + /// A new `Tensor` instance with entries set to true iff the input tensors corresponding element was NaN. + /// + /// ## Examples + /// + /// use array::{ArrayTrait, SpanTrait}; + /// use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// fn is_nan_example() -> Tensor { + /// let mut shape = ArrayTrait::::new(); + /// shape.append(4); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(FP8x23 { mag: 10066329, sign: true }); + /// data.append(FP8x23 { mag: 0, sign: false }); + /// data.append(FixedTrait::NaN()); + /// data.append(FP8x23 { mag: 23488102, sign: false }); + /// let tensor = TensorTrait::new(shape.span(), data.span()) + /// + /// return tensor.is_nan(); + /// } + /// >>> [false, false, true, false] + /// ``` + /// + fn is_nan(self: @Tensor) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 0dd00f8ea..863ea315c 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -392,6 +392,10 @@ impl BoolTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 5e22d89c0..f2ac4e431 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -444,6 +444,10 @@ impl FP16x16Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1eff6975d..980078948 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -412,6 +412,10 @@ impl FP16x16WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// 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 a6a5a1828..88271394c 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -443,6 +443,10 @@ impl FP32x32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// 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 d9aa80a58..ff6599853 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -445,6 +445,10 @@ impl FP64x64Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// 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 9f2e9d822..a5a6c093c 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -443,6 +443,10 @@ impl FP8x23Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index ea75501fb..740569404 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -402,6 +402,10 @@ impl FP8x23WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + math::is_nan::is_nan(self) + } } /// 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 facc8a59a..66047fc88 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -444,6 +444,10 @@ impl I32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 02ef9ff66..4c63c982a 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -443,6 +443,10 @@ impl I8Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 15575d969..a1c3efd99 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -394,6 +394,10 @@ impl U32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn is_nan(self: @Tensor) -> Tensor { + panic(array!['not supported!']) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 04a7253ae..0d5ee016c 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -54,3 +54,4 @@ mod reduce_mean; mod pow; mod sequence_erase; mod sequence_insert; +mod is_nan; diff --git a/src/operators/tensor/math/is_nan.cairo b/src/operators/tensor/math/is_nan.cairo new file mode 100644 index 000000000..32468e703 --- /dev/null +++ b/src/operators/tensor/math/is_nan.cairo @@ -0,0 +1,30 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait}; +use orion::operators::tensor::implementations::tensor_bool::BoolTensor; + +/// Cf: TensorTrait::is_nan docstring +fn is_nan< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: TensorTrait, + impl TCopy: Copy, + impl TDrop: Drop +>(x: @Tensor) -> Tensor { + let mut data_result = ArrayTrait::::new(); + let mut y: Span = *x.data; + loop { + match y.pop_front() { + Option::Some(item) => { + data_result.append((*item).is_nan()); + }, + Option::None(_) => { break; } + }; + }; + + return TensorTrait::new(*x.shape, data_result.span()); +} From a0f32e8456e414c370b65b9bbc273a09423cadde Mon Sep 17 00:00:00 2001 From: "Thomas S. Bauer" Date: Sun, 26 Nov 2023 16:00:00 +0100 Subject: [PATCH 122/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.is_nan.md | 37 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 docs/framework/operators/tensor/tensor.is_nan.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 804d4dbb9..87ece0565 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,6 +114,7 @@ * [tensor.pow](framework/operators/tensor/tensor.pow.md) * [tensor.sequence\_erase](framework/operators/tensor/tensor.sequence\_erase.md) * [tensor.sequence\_insert](framework/operators/tensor/tensor.sequence\_insert.md) + * [tensor.is\_nan](framework/operators/tensor/tensor.is\_nan.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 f82c4408a..2389b4ac7 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -93,5 +93,6 @@ You can see below the list of current supported ONNX Operators: | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | | [SequenceErase](operators/tensor/tensor.sequence\_erase.md) | :white\_check\_mark: | | [SequenceInsert](operators/tensor/tensor.sequence\_insert.md) | :white\_check\_mark: | +| [IsNaN](operators/tensor/tensor.is\_nan.md) | :white\_check\_mark: | -Current Operators support: **82/156 (53%)** +Current Operators support: **83/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 7a0133369..3c6f11e75 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -114,6 +114,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | | [`tensor.array_feature_extractor`](tensor.array\_feature\_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | | [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | +| [`tensor.is_nan`](tensor.is\_nan.md) | Returns which elements of the input are NaN. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.is_nan.md b/docs/framework/operators/tensor/tensor.is_nan.md new file mode 100644 index 000000000..28e5881e0 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.is_nan.md @@ -0,0 +1,37 @@ +## tensor.is_nan + +```rust + fn is_nan(self: @Tensor) -> Tensor; +``` + +Maps NaN to true and other values to false. + +## Args + +* `self`(`@Tensor`) - The input tensor. + +## Returns + +A new `Tensor` instance with entries set to true iff the input tensors corresponding element was NaN. + +## Examples + +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, FP8x23Tensor}; +use orion::numbers::{FixedTrait, FP8x23}; + +fn is_nan_example() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(4); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 10066329, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FixedTrait::NaN()); + data.append(FP8x23 { mag: 23488102, sign: false }); + let tensor = TensorTrait::new(shape.span(), data.span()) + + return tensor.is_nan(); +} +>>> [false, false, true, false] +``` From 8268a58d831cc23de7817b6a80003e4abe19e8ef Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Sun, 26 Nov 2023 23:07:30 +0430 Subject: [PATCH 123/160] adding tests for reduce_prod --- nodegen/node/reduce_prod.py | 287 ++++++++++++++++++ tests/nodes.cairo | 20 ++ tests/nodes/reduce_prod_fp16x16_1D.cairo | 20 ++ .../reduce_prod_fp16x16_1D/input_0.cairo | 15 + .../reduce_prod_fp16x16_1D/output_0.cairo | 13 + .../nodes/reduce_prod_fp16x16_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_prod_fp16x16_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_prod_fp16x16_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + tests/nodes/reduce_prod_fp8x23_1D.cairo | 20 ++ .../nodes/reduce_prod_fp8x23_1D/input_0.cairo | 15 + .../reduce_prod_fp8x23_1D/output_0.cairo | 13 + .../nodes/reduce_prod_fp8x23_2D_axis_1.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../nodes/reduce_prod_fp8x23_2D_default.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 14 + .../reduce_prod_fp8x23_2D_keepdims.cairo | 20 ++ .../input_0.cairo | 17 ++ .../output_0.cairo | 15 + tests/nodes/reduce_prod_i32_1D.cairo | 20 ++ tests/nodes/reduce_prod_i32_1D/input_0.cairo | 15 + tests/nodes/reduce_prod_i32_1D/output_0.cairo | 13 + tests/nodes/reduce_prod_i32_2D_axis_1.cairo | 20 ++ .../reduce_prod_i32_2D_axis_1/input_0.cairo | 17 ++ .../reduce_prod_i32_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_prod_i32_2D_default.cairo | 20 ++ .../reduce_prod_i32_2D_default/input_0.cairo | 17 ++ .../reduce_prod_i32_2D_default/output_0.cairo | 14 + tests/nodes/reduce_prod_i32_2D_keepdims.cairo | 20 ++ .../reduce_prod_i32_2D_keepdims/input_0.cairo | 17 ++ .../output_0.cairo | 15 + tests/nodes/reduce_prod_i8_1D.cairo | 20 ++ tests/nodes/reduce_prod_i8_1D/input_0.cairo | 15 + tests/nodes/reduce_prod_i8_1D/output_0.cairo | 13 + tests/nodes/reduce_prod_i8_2D_axis_1.cairo | 20 ++ .../reduce_prod_i8_2D_axis_1/input_0.cairo | 17 ++ .../reduce_prod_i8_2D_axis_1/output_0.cairo | 14 + tests/nodes/reduce_prod_i8_2D_default.cairo | 20 ++ .../reduce_prod_i8_2D_default/input_0.cairo | 17 ++ .../reduce_prod_i8_2D_default/output_0.cairo | 14 + tests/nodes/reduce_prod_i8_2D_keepdims.cairo | 20 ++ .../reduce_prod_i8_2D_keepdims/input_0.cairo | 17 ++ .../reduce_prod_i8_2D_keepdims/output_0.cairo | 15 + tests/nodes/reduce_prod_u32_1D.cairo | 20 ++ tests/nodes/reduce_prod_u32_1D/input_0.cairo | 14 + tests/nodes/reduce_prod_u32_1D/output_0.cairo | 12 + tests/nodes/reduce_prod_u32_2D_axis_1.cairo | 20 ++ .../reduce_prod_u32_2D_axis_1/input_0.cairo | 16 + .../reduce_prod_u32_2D_axis_1/output_0.cairo | 13 + tests/nodes/reduce_prod_u32_2D_default.cairo | 20 ++ .../reduce_prod_u32_2D_default/input_0.cairo | 16 + .../reduce_prod_u32_2D_default/output_0.cairo | 13 + tests/nodes/reduce_prod_u32_2D_keepdims.cairo | 20 ++ .../reduce_prod_u32_2D_keepdims/input_0.cairo | 16 + .../output_0.cairo | 14 + 62 files changed, 1309 insertions(+) create mode 100644 nodegen/node/reduce_prod.py create mode 100644 tests/nodes/reduce_prod_fp16x16_1D.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_1D/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_1D/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_default.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp16x16_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_1D.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_1D/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_1D/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_default.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_prod_fp8x23_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_1D.cairo create mode 100644 tests/nodes/reduce_prod_i32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_default.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i32_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_1D.cairo create mode 100644 tests/nodes/reduce_prod_i8_1D/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_1D/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_default.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_prod_i8_2D_keepdims/output_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_1D.cairo create mode 100644 tests/nodes/reduce_prod_u32_1D/input_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_1D/output_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_axis_1.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_axis_1/input_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_axis_1/output_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_default.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_default/input_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_default/output_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_keepdims.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_keepdims/input_0.cairo create mode 100644 tests/nodes/reduce_prod_u32_2D_keepdims/output_0.cairo diff --git a/nodegen/node/reduce_prod.py b/nodegen/node/reduce_prod.py new file mode 100644 index 000000000..7d145bae1 --- /dev/null +++ b/nodegen/node/reduce_prod.py @@ -0,0 +1,287 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Reduce_prod(RunAll): + @staticmethod + def reduce_prod_u32(): + def reduce_prod_1D(): + x = np.array([0, 1, 2,]).astype(np.uint32) + y = np.array([0]).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_prod_u32_1D" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def reduce_prod_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.array([0, 3]).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_prod_u32_2D_default" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.array([0, 3]).astype(np.uint32).reshape(1, 2) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_prod_u32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_prod(0, true)", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.uint32).reshape(2, 2) + y = np.array([0, 6]).astype(np.uint32) + + x = Tensor(Dtype.U32, x.shape, x.flatten()) + y = Tensor(Dtype.U32, y.shape, y.flatten()) + + name = "reduce_prod_u32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_prod(1, false)", name) + + default() + keepdims() + axis_1() + reduce_prod_1D() + reduce_prod_2D() + + @staticmethod + def reduce_prod_i32(): + def reduce_prod_1D(): + x = np.array([0, 1, 2,]).astype(np.int32) + y = np.array([0]).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_prod_i32_1D" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def reduce_prod_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.array([0, 3]).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_prod_i32_2D_default" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.array([0, 3]).astype(np.int32).reshape(1, 2) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_prod_i32_2D_keepdims" + make_test( + [x], y, "input_0.reduce_prod(0, true)", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int32).reshape(2, 2) + y = np.array([0, 6]).astype(np.int32) + + x = Tensor(Dtype.I32, x.shape, x.flatten()) + y = Tensor(Dtype.I32, y.shape, y.flatten()) + + name = "reduce_prod_i32_2D_axis_1" + make_test( + [x], y, "input_0.reduce_prod(1, false)", name) + + default() + keepdims() + axis_1() + reduce_prod_1D() + reduce_prod_2D() + + @staticmethod + def reduce_prod_i8(): + def reduce_prod_1D(): + x = np.array([0, 1, 2,]).astype(np.int8) + y = np.array([0]).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_prod_i8_1D" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def reduce_prod_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.array([0, 3]).astype(np.int8) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_prod_i8_2D_default" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.array([0, 3]).astype(np.int8).reshape(1, 2) + + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_prod_i8_2D_keepdims" + make_test( + [x], y, "input_0.reduce_prod(0, true)", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int8).reshape(2, 2) + y = np.array([0, 6]).astype(np.int8) + x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) + y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) + + name = "reduce_prod_i8_2D_axis_1" + make_test( + [x], y, "input_0.reduce_prod(1, false)", name) + + default() + keepdims() + axis_1() + reduce_prod_1D() + reduce_prod_2D() + + @staticmethod + def reduce_prod_fp8x23(): + def reduce_prod_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.array([0]).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_prod_fp8x23_1D" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def reduce_prod_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 3]).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_prod_fp8x23_2D_default" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 3]).astype(np.int64).reshape(1, 2) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_prod_fp8x23_2D_keepdims" + make_test( + [x], y, "input_0.reduce_prod(0, true)", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 6]).astype(np.int64) + + x = Tensor(Dtype.FP8x23, x.shape, to_fp( + x.flatten(), FixedImpl.FP8x23)) + y = Tensor(Dtype.FP8x23, y.shape, to_fp( + y.flatten(), FixedImpl.FP8x23)) + + name = "reduce_prod_fp8x23_2D_axis_1" + make_test( + [x], y, "input_0.reduce_prod(1, false)", name) + + default() + keepdims() + axis_1() + + reduce_prod_1D() + reduce_prod_2D() + + @staticmethod + def reduce_prod_fp16x16(): + def reduce_prod_1D(): + x = np.array([0, 1, 2,]).astype(np.int64) + y = np.array([0]).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_prod_fp16x16_1D" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def reduce_prod_2D(): + def default(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 3]).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_prod_fp16x16_2D_default" + make_test( + [x], y, "input_0.reduce_prod(0, false)", name) + + def keepdims(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 3]).astype(np.int64).reshape(1, 2) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_prod_fp16x16_2D_keepdims" + make_test( + [x], y, "input_0.reduce_prod(0, true)", name) + + def axis_1(): + x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) + y = np.array([0, 6]).astype(np.int64) + + x = Tensor(Dtype.FP16x16, x.shape, to_fp( + x.flatten(), FixedImpl.FP16x16)) + y = Tensor(Dtype.FP16x16, y.shape, to_fp( + y.flatten(), FixedImpl.FP16x16)) + + name = "reduce_prod_fp16x16_2D_axis_1" + make_test( + [x], y, "input_0.reduce_prod(1, false)", name) + + default() + keepdims() + axis_1() + + reduce_prod_1D() + reduce_prod_2D() diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 23f5c9731..8f38321d7 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -654,3 +654,23 @@ mod reduce_l1_i8_export_negative_axes_keepdims; mod reduce_l1_u32_export_do_not_keepdims; mod reduce_l1_u32_export_keepdims; mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_prod_fp16x16_1D; +mod reduce_prod_fp16x16_2D_default; +mod reduce_prod_fp16x16_2D_keepdims; +mod reduce_prod_fp16x16_2D_axis_1; +mod reduce_prod_fp8x23_1D; +mod reduce_prod_fp8x23_2D_default; +mod reduce_prod_fp8x23_2D_keepdims; +mod reduce_prod_fp8x23_2D_axis_1; +mod reduce_prod_i32_1D; +mod reduce_prod_i32_2D_default; +mod reduce_prod_i32_2D_keepdims; +mod reduce_prod_i32_2D_axis_1; +mod reduce_prod_i8_1D; +mod reduce_prod_i8_2D_default; +mod reduce_prod_i8_2D_keepdims; +mod reduce_prod_i8_2D_axis_1; +mod reduce_prod_u32_1D; +mod reduce_prod_u32_2D_default; +mod reduce_prod_u32_2D_keepdims; +mod reduce_prod_u32_2D_axis_1; diff --git a/tests/nodes/reduce_prod_fp16x16_1D.cairo b/tests/nodes/reduce_prod_fp16x16_1D.cairo new file mode 100644 index 000000000..c0198f388 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp16x16_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp16x16_1D/input_0.cairo b/tests/nodes/reduce_prod_fp16x16_1D/input_0.cairo new file mode 100644 index 000000000..4ce1ac478 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_1D/output_0.cairo b/tests/nodes/reduce_prod_fp16x16_1D/output_0.cairo new file mode 100644 index 000000000..b6702d88e --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_axis_1.cairo b/tests/nodes/reduce_prod_fp16x16_2D_axis_1.cairo new file mode 100644 index 000000000..bfa4c0a1a --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp16x16_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(1, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_axis_1/input_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_axis_1/output_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..d3534bfa1 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_default.cairo b/tests/nodes/reduce_prod_fp16x16_2D_default.cairo new file mode 100644 index 000000000..3191d9255 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp16x16_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_default/input_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_default/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_default/output_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_default/output_0.cairo new file mode 100644 index 000000000..60697a9ef --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_keepdims.cairo b/tests/nodes/reduce_prod_fp16x16_2D_keepdims.cairo new file mode 100644 index 000000000..c51be7d97 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::FP16x16Tensor; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp16x16_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_keepdims/input_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..f930430e8 --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, 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: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp16x16_2D_keepdims/output_0.cairo b/tests/nodes/reduce_prod_fp16x16_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..aee50214e --- /dev/null +++ b/tests/nodes/reduce_prod_fp16x16_2D_keepdims/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_1D.cairo b/tests/nodes/reduce_prod_fp8x23_1D.cairo new file mode 100644 index 000000000..60043339a --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp8x23_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp8x23_1D/input_0.cairo b/tests/nodes/reduce_prod_fp8x23_1D/input_0.cairo new file mode 100644 index 000000000..e0b0864ea --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_1D/output_0.cairo b/tests/nodes/reduce_prod_fp8x23_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_axis_1.cairo b/tests/nodes/reduce_prod_fp8x23_2D_axis_1.cairo new file mode 100644 index 000000000..7aeac2794 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp8x23_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(1, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_axis_1/input_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_axis_1/output_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..d83be7b63 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_default.cairo b/tests/nodes/reduce_prod_fp8x23_2D_default.cairo new file mode 100644 index 000000000..bbb9ad19f --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp8x23_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_default/input_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_default/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_default/output_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_default/output_0.cairo new file mode 100644 index 000000000..a7871ca64 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_keepdims.cairo b/tests/nodes/reduce_prod_fp8x23_2D_keepdims.cairo new file mode 100644 index 000000000..85d325fb9 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_fp8x23_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_keepdims/input_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..fe51dd535 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_fp8x23_2D_keepdims/output_0.cairo b/tests/nodes/reduce_prod_fp8x23_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..97f6b9ca0 --- /dev/null +++ b/tests/nodes/reduce_prod_fp8x23_2D_keepdims/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_1D.cairo b/tests/nodes/reduce_prod_i32_1D.cairo new file mode 100644 index 000000000..b7fc26f87 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i32_1D/input_0.cairo b/tests/nodes/reduce_prod_i32_1D/input_0.cairo new file mode 100644 index 000000000..0f01c1e62 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_1D/input_0.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_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_1D/output_0.cairo b/tests/nodes/reduce_prod_i32_1D/output_0.cairo new file mode 100644 index 000000000..cc24fe978 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_axis_1.cairo b/tests/nodes/reduce_prod_i32_2D_axis_1.cairo new file mode 100644 index 000000000..a57d4c716 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(1, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_prod_i32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_prod_i32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..c52fbd9fc --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 6, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_default.cairo b/tests/nodes/reduce_prod_i32_2D_default.cairo new file mode 100644 index 000000000..3f8df6104 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i32_2D_default/input_0.cairo b/tests/nodes/reduce_prod_i32_2D_default/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_default/output_0.cairo b/tests/nodes/reduce_prod_i32_2D_default/output_0.cairo new file mode 100644 index 000000000..556bf4911 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_keepdims.cairo b/tests/nodes/reduce_prod_i32_2D_keepdims.cairo new file mode 100644 index 000000000..a5b598f69 --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::I32TensorPartialEq; +use orion::operators::tensor::I32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_prod_i32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..1af9ec7cc --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_prod_i32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..47e03ae9d --- /dev/null +++ b/tests/nodes/reduce_prod_i32_2D_keepdims/output_0.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 output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_1D.cairo b/tests/nodes/reduce_prod_i8_1D.cairo new file mode 100644 index 000000000..b499e10c1 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i8_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i8_1D/input_0.cairo b/tests/nodes/reduce_prod_i8_1D/input_0.cairo new file mode 100644 index 000000000..1d76655fb --- /dev/null +++ b/tests/nodes/reduce_prod_i8_1D/input_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_1D/output_0.cairo b/tests/nodes/reduce_prod_i8_1D/output_0.cairo new file mode 100644 index 000000000..7efd27555 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_1D/output_0.cairo @@ -0,0 +1,13 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_axis_1.cairo b/tests/nodes/reduce_prod_i8_2D_axis_1.cairo new file mode 100644 index 000000000..7cb36553e --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i8_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(1, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i8_2D_axis_1/input_0.cairo b/tests/nodes/reduce_prod_i8_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_axis_1/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_axis_1/output_0.cairo b/tests/nodes/reduce_prod_i8_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..9c630cfed --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_axis_1/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 6, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_default.cairo b/tests/nodes/reduce_prod_i8_2D_default.cairo new file mode 100644 index 000000000..c04b59358 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i8_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i8_2D_default/input_0.cairo b/tests/nodes/reduce_prod_i8_2D_default/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_default/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_default/output_0.cairo b/tests/nodes/reduce_prod_i8_2D_default/output_0.cairo new file mode 100644 index 000000000..4a13023ba --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_default/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_keepdims.cairo b/tests/nodes/reduce_prod_i8_2D_keepdims.cairo new file mode 100644 index 000000000..d822c1ae3 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::FP8x23Tensor; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_i8_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_i8_2D_keepdims/input_0.cairo b/tests/nodes/reduce_prod_i8_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..e7a52a260 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_keepdims/input_0.cairo @@ -0,0 +1,17 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 1, sign: false }); + data.append(FP8x23 { mag: 2, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_i8_2D_keepdims/output_0.cairo b/tests/nodes/reduce_prod_i8_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..2244888e7 --- /dev/null +++ b/tests/nodes/reduce_prod_i8_2D_keepdims/output_0.cairo @@ -0,0 +1,15 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_1D.cairo b/tests/nodes/reduce_prod_u32_1D.cairo new file mode 100644 index 000000000..11e700531 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_1D.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_u32_1D() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_u32_1D/input_0.cairo b/tests/nodes/reduce_prod_u32_1D/input_0.cairo new file mode 100644 index 000000000..60317db10 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_1D/input_0.cairo @@ -0,0 +1,14 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_1D/output_0.cairo b/tests/nodes/reduce_prod_u32_1D/output_0.cairo new file mode 100644 index 000000000..2374279b0 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_1D/output_0.cairo @@ -0,0 +1,12 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_axis_1.cairo b/tests/nodes/reduce_prod_u32_2D_axis_1.cairo new file mode 100644 index 000000000..d8830335e --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_axis_1.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_u32_2D_axis_1() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(1, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_u32_2D_axis_1/input_0.cairo b/tests/nodes/reduce_prod_u32_2D_axis_1/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_axis_1/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_axis_1/output_0.cairo b/tests/nodes/reduce_prod_u32_2D_axis_1/output_0.cairo new file mode 100644 index 000000000..7aa57e848 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_axis_1/output_0.cairo @@ -0,0 +1,13 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(6); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_default.cairo b/tests/nodes/reduce_prod_u32_2D_default.cairo new file mode 100644 index 000000000..71d61e049 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_default.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_u32_2D_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, false); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_u32_2D_default/input_0.cairo b/tests/nodes/reduce_prod_u32_2D_default/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_default/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_default/output_0.cairo b/tests/nodes/reduce_prod_u32_2D_default/output_0.cairo new file mode 100644 index 000000000..ab9787693 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_default/output_0.cairo @@ -0,0 +1,13 @@ +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); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_keepdims.cairo b/tests/nodes/reduce_prod_u32_2D_keepdims.cairo new file mode 100644 index 000000000..e1875a313 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_keepdims.cairo @@ -0,0 +1,20 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::U32TensorPartialEq; +use orion::operators::tensor::{TensorTrait, Tensor}; +use array::{ArrayTrait, SpanTrait}; + +#[test] +#[available_gas(2000000000)] +fn test_reduce_prod_u32_2D_keepdims() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = input_0.reduce_prod(0, true); + + assert_eq(y, z); +} diff --git a/tests/nodes/reduce_prod_u32_2D_keepdims/input_0.cairo b/tests/nodes/reduce_prod_u32_2D_keepdims/input_0.cairo new file mode 100644 index 000000000..8e3c51970 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_keepdims/input_0.cairo @@ -0,0 +1,16 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(2); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/reduce_prod_u32_2D_keepdims/output_0.cairo b/tests/nodes/reduce_prod_u32_2D_keepdims/output_0.cairo new file mode 100644 index 000000000..44ed1a287 --- /dev/null +++ b/tests/nodes/reduce_prod_u32_2D_keepdims/output_0.cairo @@ -0,0 +1,14 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(3); + TensorTrait::new(shape.span(), data.span()) +} From bbf82c4de786e2d8afb2c996fa08919c4aaeab34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Sun, 26 Nov 2023 20:25:25 +0000 Subject: [PATCH 124/160] feat: bitwise or added for numbers --- src/numbers.cairo | 49 +++++++++++++++++++ .../implementations/fp16x16/math/comp.cairo | 4 ++ .../fp16x16wide/math/comp.cairo | 4 ++ .../implementations/fp32x32/comp.cairo | 4 ++ .../implementations/fp64x64/comp.cairo | 4 ++ .../implementations/fp8x23/math/comp.cairo | 4 ++ .../fp8x23wide/math/comp.cairo | 4 ++ src/numbers/signed_integer/i128.cairo | 4 ++ src/numbers/signed_integer/i16.cairo | 4 ++ src/numbers/signed_integer/i32.cairo | 4 ++ src/numbers/signed_integer/i64.cairo | 4 ++ src/numbers/signed_integer/i8.cairo | 5 ++ 12 files changed, 94 insertions(+) diff --git a/src/numbers.cairo b/src/numbers.cairo index bb781afb3..d0b715c04 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -53,6 +53,7 @@ trait NumberTrait { fn NaN() -> T; fn is_nan(self: T) -> bool; fn bitwise_and(lhs: T, rhs: T) -> T; + fn bitwise_xor(lhs: T, rhs: T) -> T; fn add(lhs: T, rhs: T) -> T; fn sub(lhs: T, rhs: T) -> T; } @@ -251,6 +252,10 @@ impl FP8x23Number of NumberTrait { comp_fp8x23::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { + comp_fp8x23::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP8x23, rhs: FP8x23) -> FP8x23 { FP8x23Add::add(lhs, rhs) } @@ -454,6 +459,10 @@ impl FP8x23WNumber of NumberTrait { comp_fp8x23wide::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { + comp_fp8x23wide::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP8x23W, rhs: FP8x23W) -> FP8x23W { FP8x23WAdd::add(lhs, rhs) } @@ -657,6 +666,10 @@ impl FP16x16Number of NumberTrait { comp_fp16x16::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { + comp_fp16x16::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP16x16, rhs: FP16x16) -> FP16x16 { FP16x16Add::add(lhs, rhs) } @@ -860,6 +873,10 @@ impl FP16x16WNumber of NumberTrait { comp_fp16x16wide::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { + comp_fp16x16wide::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP16x16W, rhs: FP16x16W) -> FP16x16W { FP16x16WAdd::add(lhs, rhs) } @@ -1064,6 +1081,10 @@ impl FP64x64Number of NumberTrait { comp_fp64x64::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { + comp_fp64x64::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP64x64, rhs: FP64x64) -> FP64x64 { FP64x64Add::add(lhs, rhs) } @@ -1268,6 +1289,10 @@ impl FP32x32Number of NumberTrait { comp_fp32x32::bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { + comp_fp32x32::bitwise_xor(lhs, rhs) + } + fn add(lhs: FP32x32, rhs: FP32x32) -> FP32x32 { FP32x32Add::add(lhs, rhs) } @@ -1485,6 +1510,10 @@ impl I8Number of NumberTrait { i8_core::i8_bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: i8, rhs: i8) -> i8 { + i8_core::i8_bitwise_xor(lhs, rhs) + } + fn add(lhs: i8, rhs: i8) -> i8 { i8Add::add(lhs, rhs) } @@ -1702,6 +1731,10 @@ impl i16Number of NumberTrait { i16_core::i16_bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: i16, rhs: i16) -> i16 { + i16_core::i16_bitwise_xor(lhs, rhs) + } + fn add(lhs: i16, rhs: i16) -> i16 { i16Add::add(lhs, rhs) } @@ -1919,6 +1952,10 @@ impl i32Number of NumberTrait { i32_core::i32_bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: i32, rhs: i32) -> i32 { + i32_core::i32_bitwise_xor(lhs, rhs) + } + fn add(lhs: i32, rhs: i32) -> i32 { i32Add::add(lhs, rhs) } @@ -2136,6 +2173,10 @@ impl i64Number of NumberTrait { i64_core::i64_bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: i64, rhs: i64) -> i64 { + i64_core::i64_bitwise_xor(lhs, rhs) + } + fn add(lhs: i64, rhs: i64) -> i64 { i64Add::add(lhs, rhs) } @@ -2355,6 +2396,10 @@ impl i128Number of NumberTrait { i128_core::i128_bitwise_and(lhs, rhs) } + fn bitwise_xor(lhs: i128, rhs: i128) -> i128 { + i128_core::i128_bitwise_xor(lhs, rhs) + } + fn add(lhs: i128, rhs: i128) -> i128 { i128Add::add(lhs, rhs) } @@ -2577,6 +2622,10 @@ impl u32Number of NumberTrait { lhs & rhs } + fn bitwise_xor(lhs: u32, rhs: u32) -> u32 { + lhs ^ rhs + } + fn add(lhs: u32, rhs: u32) -> u32 { lhs + rhs } diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 12003fc75..5c0755a54 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP16x16, b: FP16x16) -> FP16x16 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_xor(a: FP16x16, b: FP16x16) -> FP16x16 { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 012d959c1..3290b03dd 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP16x16W, b: FP16x16W) -> FP16x16W { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_xor(a: FP16x16W, b: FP16x16W) -> FP16x16W { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo index ed1fa7d92..0d4a0453d 100644 --- a/src/numbers/fixed_point/implementations/fp32x32/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp32x32/comp.cairo @@ -38,3 +38,7 @@ fn where(a: FP32x32, b: FP32x32, c: FP32x32) -> FP32x32 { fn bitwise_and(a: FP32x32, b: FP32x32) -> FP32x32 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } + +fn bitwise_xor(a: FP32x32, b: FP32x32) -> FP32x32 { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} diff --git a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo index 98528a00c..590266d35 100644 --- a/src/numbers/fixed_point/implementations/fp64x64/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp64x64/comp.cairo @@ -38,3 +38,7 @@ fn where(a: FP64x64, b: FP64x64, c: FP64x64) -> FP64x64 { fn bitwise_and(a: FP64x64, b: FP64x64) -> FP64x64 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } + +fn bitwise_xor(a: FP64x64, b: FP64x64) -> FP64x64 { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index f329371e6..1cad06b9b 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP8x23, b: FP8x23) -> FP8x23 { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_xor(a: FP8x23, b: FP8x23) -> FP8x23 { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index da3739fb0..92ecd9f8c 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -56,6 +56,10 @@ fn bitwise_and(a: FP8x23W, b: FP8x23W) -> FP8x23W { return FixedTrait::new(a.mag & b.mag, a.sign & b.sign); } +fn bitwise_xor(a: FP8x23W, b: FP8x23W) -> FP8x23W { + return FixedTrait::new(a.mag ^ b.mag, a.sign ^ b.sign); +} + // Tests -------------------------------------------------------------------------------------------------------------- #[cfg(test)] diff --git a/src/numbers/signed_integer/i128.cairo b/src/numbers/signed_integer/i128.cairo index ae1adbb4d..50df25b33 100644 --- a/src/numbers/signed_integer/i128.cairo +++ b/src/numbers/signed_integer/i128.cairo @@ -481,3 +481,7 @@ fn i128_sign(a: i128) -> i128 { fn i128_bitwise_and(a: i128, b: i128) -> i128 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i128_bitwise_xor(a: i128, b: i128) -> i128 { + IntegerTrait::::new(a.mag ^ b.mag, a.sign ^ b.sign) +} \ No newline at end of file diff --git a/src/numbers/signed_integer/i16.cairo b/src/numbers/signed_integer/i16.cairo index 3dd7e68f2..468b7d99d 100644 --- a/src/numbers/signed_integer/i16.cairo +++ b/src/numbers/signed_integer/i16.cairo @@ -481,3 +481,7 @@ fn i16_sign(a: i16) -> i16 { fn i16_bitwise_and(a: i16, b: i16) -> i16 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i16_bitwise_xor(a: i16, b: i16) -> i16 { + IntegerTrait::::new(a.mag ^ b.mag, a.sign ^ b.sign) +} diff --git a/src/numbers/signed_integer/i32.cairo b/src/numbers/signed_integer/i32.cairo index 9a9e00552..047ebdb51 100644 --- a/src/numbers/signed_integer/i32.cairo +++ b/src/numbers/signed_integer/i32.cairo @@ -513,3 +513,7 @@ fn i32_sign(a: i32) -> i32 { fn i32_bitwise_and(a: i32, b: i32) -> i32 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i32_bitwise_xor(a: i32, b: i32) -> i32 { + IntegerTrait::::new(a.mag ^ b.mag, a.sign ^ b.sign) +} diff --git a/src/numbers/signed_integer/i64.cairo b/src/numbers/signed_integer/i64.cairo index c502795b5..6e713325f 100644 --- a/src/numbers/signed_integer/i64.cairo +++ b/src/numbers/signed_integer/i64.cairo @@ -481,3 +481,7 @@ fn i64_sign(a: i64) -> i64 { fn i64_bitwise_and(a: i64, b: i64) -> i64 { IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign) } + +fn i64_bitwise_xor(a: i64, b: i64) -> i64 { + IntegerTrait::::new(a.mag ^ b.mag, a.sign ^ b.sign) +} diff --git a/src/numbers/signed_integer/i8.cairo b/src/numbers/signed_integer/i8.cairo index 14bc4f441..2e480d58a 100644 --- a/src/numbers/signed_integer/i8.cairo +++ b/src/numbers/signed_integer/i8.cairo @@ -558,3 +558,8 @@ fn i8_sign(a: i8) -> i8 { fn i8_bitwise_and(a: i8, b: i8) -> i8 { return IntegerTrait::::new(a.mag & b.mag, a.sign & b.sign); } + +fn i8_bitwise_xor(a: i8, b: i8) -> i8 { + return IntegerTrait::::new(a.mag ^ b.mag, a.sign ^ b.sign); +} + From 41fe76bbfa005b7bf6a9dd0bb3ae2980a752ba7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Mon, 27 Nov 2023 12:52:55 +0000 Subject: [PATCH 125/160] feat: bitwise xor operator added for tensors --- .../implementations/fp16x16/math/comp.cairo | 11 ++++- .../fp16x16wide/math/comp.cairo | 11 ++++- .../implementations/fp8x23/math/comp.cairo | 11 ++++- .../fp8x23wide/math/comp.cairo | 11 ++++- src/operators/tensor/core.cairo | 47 +++++++++++++++++++ .../tensor/implementations/tensor_bool.cairo | 4 ++ .../implementations/tensor_fp16x16.cairo | 4 ++ .../implementations/tensor_fp16x16wide.cairo | 4 ++ .../implementations/tensor_fp32x32.cairo | 4 ++ .../implementations/tensor_fp64x64.cairo | 4 ++ .../implementations/tensor_fp8x23.cairo | 4 ++ .../implementations/tensor_fp8x23wide.cairo | 4 ++ .../tensor/implementations/tensor_i32.cairo | 4 ++ .../tensor/implementations/tensor_i8.cairo | 4 ++ .../tensor/implementations/tensor_u32.cairo | 4 ++ src/operators/tensor/math.cairo | 1 + src/operators/tensor/math/bitwise_xor.cairo | 47 +++++++++++++++++++ 17 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 src/operators/tensor/math/bitwise_xor.cairo diff --git a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo index 5c0755a54..3a342a856 100644 --- a/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_xor(a: FP16x16, b: FP16x16) -> FP16x16 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_xor}; #[test] @@ -113,4 +113,13 @@ mod tests { assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_xor() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(4160880640, true); + + assert(bitwise_xor(a, b) == c, 'bitwise_xor(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo index 3290b03dd..aad89af64 100644 --- a/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp16x16wide/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_xor(a: FP16x16W, b: FP16x16W) -> FP16x16W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_xor}; #[test] @@ -113,4 +113,13 @@ mod tests { assert(bitwise_and(a, b) == c, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_xor() { + let a = FixedTrait::new(225280, false); // 3.4375 + let b = FixedTrait::new(4160843776, true); // -2046.5625 + let c = FixedTrait::new(4160880640, true); + + assert(bitwise_xor(a, b) == c, 'bitwise_xor(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo index 1cad06b9b..049b47416 100644 --- a/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_xor(a: FP8x23, b: FP8x23) -> FP8x23 { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_xor}; #[test] fn test_max() { @@ -110,4 +110,13 @@ mod tests { assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_xor() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + let c = FixedTrait::new(1610612736, true); + + assert(bitwise_xor(a, b) == c, 'bitwise_xor(a,b)') + } } diff --git a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo index 92ecd9f8c..b0fcebeab 100644 --- a/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo +++ b/src/numbers/fixed_point/implementations/fp8x23wide/math/comp.cairo @@ -64,7 +64,7 @@ fn bitwise_xor(a: FP8x23W, b: FP8x23W) -> FP8x23W { #[cfg(test)] mod tests { - use super::{FixedTrait, max, min, bitwise_and}; + use super::{FixedTrait, max, min, bitwise_and, bitwise_xor}; #[test] @@ -112,4 +112,13 @@ mod tests { assert(bitwise_and(a, b) == a, 'bitwise_and(a,b)') } + + #[test] + fn test_bitwise_xor() { + let a = FixedTrait::new(28835840, false); // 3.4375 + let b = FixedTrait::new(1639448576, true); // -60.5625 + let c = FixedTrait::new(1610612736, true); + + assert(bitwise_xor(a, b) == c, 'bitwise_xor(a,b)') + } } diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 5a3cf5936..821f7b25a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -90,6 +90,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ``` /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; + /// #tensor.bitwise_xor + /// + /// ```rust + /// fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the bitwise XOR 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` with the same shape as the broadcasted inputs. + /// + /// ## Example + /// + /// ```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, 4, 5, 0, 6, 2].span(), + /// ); + /// + /// return tensor_1.bitwise_xor(@tensor_2); + /// } + /// >>> [0,0,0,3,0,0,6,1,10] + /// ``` + /// + fn bitwise_xor(self: @Tensor, other: @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 0dd00f8ea..9326e3039 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -319,6 +319,10 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn bitwise_xor(self: @Tensor, other: @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_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 5e22d89c0..95adf450f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -355,6 +355,10 @@ impl FP16x16Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 1eff6975d..fcb7f325e 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -323,6 +323,10 @@ impl FP16x16WTensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 a6a5a1828..6d5dce313 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -356,6 +356,10 @@ impl FP32x32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 d9aa80a58..404fb0206 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -356,6 +356,10 @@ impl FP64x64Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 9f2e9d822..58ba7415d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -355,6 +355,10 @@ impl FP8x23Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 ea75501fb..f7b4fb15e 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -313,6 +313,10 @@ impl FP8x23WTensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 facc8a59a..1f6bb2c8b 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -355,6 +355,10 @@ impl I32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 02ef9ff66..c6b07779d 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -354,6 +354,10 @@ impl I8Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + 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 15575d969..272263661 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -305,6 +305,10 @@ impl U32Tensor of TensorTrait { math::bitwise_and::bitwise_and(self, other) } + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { + math::bitwise_xor::bitwise_xor(self, other) + } + fn round(self: @Tensor) -> Tensor { math::round::round(*self) } diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 04a7253ae..81bb915cf 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -44,6 +44,7 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; +mod bitwise_xor; mod sequence_length; mod sequence_at; mod reduce_min; diff --git a/src/operators/tensor/math/bitwise_xor.cairo b/src/operators/tensor/math/bitwise_xor.cairo new file mode 100644 index 000000000..d1a699f3d --- /dev/null +++ b/src/operators/tensor/math/bitwise_xor.cairo @@ -0,0 +1,47 @@ +use array::ArrayTrait; +use option::OptionTrait; +use array::SpanTrait; +use debug::PrintTrait; + +use orion::numbers::NumberTrait; +use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::helpers::{ + broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility +}; + +/// Cf: TensorTrait::and docstring +fn bitwise_xor< + T, + MAG, + impl TNumber: NumberTrait, + impl TTensor: 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); + + let lhs = *(*y.data)[indices_self]; + let rhs = *(*z.data)[indices_other]; + + result.append(NumberTrait::bitwise_xor(lhs, rhs)); + + n += 1; + if n == num_elements { + break (); + }; + }; + + return TensorTrait::::new(broadcasted_shape, result.span()); +} From 34581f952083cf78cc8f0d832e3db71608e5e8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilgin=20Ko=C3=A7ak?= Date: Mon, 27 Nov 2023 12:57:47 +0000 Subject: [PATCH 126/160] docs: bitwise_xor docs added --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 3 +- docs/framework/operators/tensor/README.md | 4 +- .../operators/tensor/tensor.bitwise_xor.md | 44 +++++++++++++++++++ src/operators/tensor/core.cairo | 2 +- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 docs/framework/operators/tensor/tensor.bitwise_xor.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 804d4dbb9..55069986e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -97,6 +97,7 @@ * [tensor.and](framework/operators/tensor/tensor.and.md) * [tensor.where](framework/operators/tensor/tensor.where.md) * [tensor.bitwise_and](framework/operators/tensor/tensor.bitwise_and.md) + * [tensor.bitwise_xor](framework/operators/tensor/tensor.bitwise_xor.md) * [tensor.round](framework/operators/tensor/tensor.round.md) * [tensor.scatter](framework/operators/tensor/tensor.scatter.md) * [tensor.array_feature_extractor](framework/operators/tensor/tensor.array\_feature\_extractor.md) diff --git a/docs/framework/compatibility.md b/docs/framework/compatibility.md index f82c4408a..2866f5280 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -74,6 +74,7 @@ You can see below the list of current supported ONNX Operators: | [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: | | [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: | | [BitwiseAnd](operators/tensor/tensor.bitwise_and.md) | :white\_check\_mark: | +| [BitwiseXor](operators/tensor/tensor.bitwise_xor.md) | :white\_check\_mark: | | [Round](operators/tensor/tensor.round.md) | :white\_check\_mark: | | [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: | | [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: | @@ -94,4 +95,4 @@ You can see below the list of current supported ONNX Operators: | [SequenceErase](operators/tensor/tensor.sequence\_erase.md) | :white\_check\_mark: | | [SequenceInsert](operators/tensor/tensor.sequence\_insert.md) | :white\_check\_mark: | -Current Operators support: **82/156 (53%)** +Current Operators support: **83/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 7a0133369..6f91f6e97 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -94,6 +94,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.identity`](tensor.identity.md) | Return a Tensor with the same shape and contents as input. | | [`tensor.where`](tensor.where.md) | Return elements chosen from x or y depending on condition. | | [`tensor.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.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. | | [`tensor.trilu`](tensor.trilu.md) | Returns the upper or lower triangular part of a tensor or a batch of 2D matrices. | @@ -101,15 +102,12 @@ use orion::operators::tensor::TensorTrait; | [`tensor.reduce_sum_square`](tensor.reduce\_sum\_square.md) | Computes the sum square of the input tensor's elements along the provided axes. | | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | | [`tensor.sequence_length`](tensor.sequence\_length.md) | Returns the length of the input sequence. | -| [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on a defined formula. | -| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.sequence_insert`](tensor.sequence\_insert.md) | Insert a tensor into a sequence. | | [`tensor.sequence_at`](tensor.sequence\_at.md) | Outputs the tensor at the specified position in the input sequence. | | [`tensor.sequence_construct`](tensor.sequence\_construct.md) | Constructs a tensor sequence containing the input tensors. | | [`tensor.shrink`](tensor.shrink.md) | Shrinks the input tensor element-wise to the output tensor. | | [`tensor.reduce_mean`](tensor.reduce\_mean.md) | Computes the mean of the input tensor's elements along the provided axes. | | [`tensor.pow`](tensor.pow.md) | Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function f(x) = x^exponent, is applied to the data tensor elementwise. | -| [`tensor.sequence_erase`](tensor.sequence\_erase.md) | Outputs the tensor sequence with the erased tensor at the specified position. | | [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | | [`tensor.array_feature_extractor`](tensor.array\_feature\_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | diff --git a/docs/framework/operators/tensor/tensor.bitwise_xor.md b/docs/framework/operators/tensor/tensor.bitwise_xor.md new file mode 100644 index 000000000..62f1dd0b1 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.bitwise_xor.md @@ -0,0 +1,44 @@ +#tensor.bitwise_xor + +```rust + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor; +``` + +Computes the bitwise XOR 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` with the same shape as the broadcasted inputs. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn xor_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, 4, 5, 0, 6, 2].span(), + ); + + return tensor_1.bitwise_xor(@tensor_2); +} +>>> [0,0,0,3,0,0,6,1,10] +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 821f7b25a..55353702a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3658,7 +3658,7 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn and_example() -> Tensor { + /// fn xor_example() -> Tensor { /// let tensor_1 = TensorTrait::::new( /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), /// ); From c64fffcffb80beebee63b75db73c7cf64ca2cd59 Mon Sep 17 00:00:00 2001 From: Ephraim-nonso Date: Mon, 27 Nov 2023 12:48:58 -0300 Subject: [PATCH 127/160] Updated all as reviewed --- src/operators/tensor/math/not.cairo | 8 +------- tests/nodes/not_bool/input_0.cairo | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/operators/tensor/math/not.cairo b/src/operators/tensor/math/not.cairo index 23b245a8b..68483ff29 100644 --- a/src/operators/tensor/math/not.cairo +++ b/src/operators/tensor/math/not.cairo @@ -8,13 +8,7 @@ use orion::operators::tensor::implementations::{tensor_bool::BoolTensor}; // Cf TensorTrait::not docstring -fn not < - T, - impl TTensor: TensorTrait, - impl TPartialOrd: PartialOrd, - impl TCopy: Copy, - impl TDrop: Drop -> (mut z: Tensor) -> Tensor { +fn not (mut z: Tensor) -> Tensor { let mut data_result = ArrayTrait::::new(); loop { diff --git a/tests/nodes/not_bool/input_0.cairo b/tests/nodes/not_bool/input_0.cairo index 2b0e42256..54ca73dbe 100644 --- a/tests/nodes/not_bool/input_0.cairo +++ b/tests/nodes/not_bool/input_0.cairo @@ -8,6 +8,6 @@ fn input_0() -> Tensor { shape.append(1); let mut data = ArrayTrait::new(); - data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } \ No newline at end of file From 3fad79945ff990088ba221af1fb5fa63bc231c62 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 20:59:18 +0430 Subject: [PATCH 128/160] adding the reduce_prod to math module --- src/operators/tensor/math.cairo | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 881642e20..9abe495db 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -3,6 +3,7 @@ mod min; mod max_in_tensor; mod max; mod reduce_sum; +mod reduce_prod; mod argmax; mod argmin; mod exp; @@ -42,4 +43,4 @@ mod scatter; mod reduce_l2; mod reduce_l1; mod reduce_sum_square; -mod bitwise_and; +mod bitwise_and; \ No newline at end of file From 0b7b1022344233e419095073c124b1bc6a3444db Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:05:08 +0430 Subject: [PATCH 129/160] adding FP8x23 reduce_prod impl --- src/operators/tensor/implementations/tensor_fp8x23.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index fdcdac1eb..47dbb1922 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -61,6 +61,10 @@ impl FP8x23Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_sum(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From d48852e39509d6a3c772344e87bb81ce8a64ce0d Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:07:46 +0430 Subject: [PATCH 130/160] adding reduce_impl for FP8x23wide --- src/operators/tensor/implementations/tensor_fp8x23wide.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 510731702..680b26a33 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -61,6 +61,10 @@ impl FP8x23WTensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From 88f20764a6bbb97198dbb187cb3134012570093f Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:09:45 +0430 Subject: [PATCH 131/160] adding reduce_impl for FP16x16 --- src/operators/tensor/implementations/tensor_fp16x16.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 8b27883fa..cbbd735a4 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -61,6 +61,10 @@ impl FP16x16Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From 4c8742e295a4826ed3ef26253e6b0b61751a785e Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:11:57 +0430 Subject: [PATCH 132/160] adding reduce_impl for FP16x16wide --- src/operators/tensor/implementations/tensor_fp16x16wide.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 68f2482e7..00dad05d0 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -61,6 +61,10 @@ impl FP16x16WTensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, From af180b28cf3563e5f00b7b22f1b09bb1b9af1003 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:13:05 +0430 Subject: [PATCH 133/160] adding reduce_impl for FP32x32 --- src/operators/tensor/implementations/tensor_fp32x32.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index f764b1920..fe5cdb506 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -62,6 +62,10 @@ impl FP32x32Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From db54e5bbc8b02e74b96dc7a5f60289cd50530731 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:14:11 +0430 Subject: [PATCH 134/160] adding reduce_impl for FP64x64 --- src/operators/tensor/implementations/tensor_fp64x64.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 6cded29b3..db0b5f4cc 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -62,6 +62,10 @@ impl FP64x64Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From d5f4f35e1c505f1789cb958b91d1b19d45a76846 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:15:13 +0430 Subject: [PATCH 135/160] adding reduce_impl for i8 --- src/operators/tensor/implementations/tensor_i8.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 4f2731b80..a3ae7a3d2 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -61,6 +61,10 @@ impl I8Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From 1e6f16a0e8e0e8a429747cb3857cd8ef533c718f Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:16:20 +0430 Subject: [PATCH 136/160] adding reduce_impl for i32 --- src/operators/tensor/implementations/tensor_i32.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 8017ab300..f79e9af51 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -62,6 +62,10 @@ impl I32Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From 3eb9ed17d7ef7e970e40b78a9918561c3048d068 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:17:43 +0430 Subject: [PATCH 137/160] adding reduce_impl for u32 --- src/operators/tensor/implementations/tensor_u32.cairo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 2f3c3a2ef..50344dbb6 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -61,6 +61,10 @@ impl U32Tensor of TensorTrait { math::reduce_sum::reduce_sum(self, axis, keepdims) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + math::reduce_prod::reduce_prod(self, axis, keepdims) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { From ea97c8d2abe751e2009a0fa3cf7d8a830de49895 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:32:09 +0430 Subject: [PATCH 138/160] adding reduce_prod to Trait --- src/operators/tensor/core.cairo | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 9ac16691e..6c9f9ff3c 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -52,6 +52,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ## tensor.reduce_prod + /// + /// ```rust + /// fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Reduces a tensor by multiplying its elements along a specified axis. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by multiplying its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_prod_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_prod` function as follows. + /// return tensor.reduce_prod(axis: 0, keepdims: false); + /// } + /// >>> [[0,5],[12,21]] + /// ``` + /// + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring From a0c21984ff6e7b6516ca3e95f061a3b90d9d87ff Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Mon, 27 Nov 2023 22:32:27 +0430 Subject: [PATCH 139/160] fixing the typos --- src/operators/tensor/implementations/tensor_bool.cairo | 4 ++++ src/operators/tensor/implementations/tensor_fp8x23.cairo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 29bf1c77b..1bc89c02b 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -57,6 +57,10 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { + panic(array!['not supported!']) + } + fn argmax( self: @Tensor, axis: usize, keepdims: Option, select_last_index: Option ) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 47dbb1922..f5ce36f28 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -62,7 +62,7 @@ impl FP8x23Tensor of TensorTrait { } fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { - math::reduce_prod::reduce_sum(self, axis, keepdims) + math::reduce_prod::reduce_prod(self, axis, keepdims) } fn argmax( From cb5b54a58338068d5c55d19f1e4e07d90b119824 Mon Sep 17 00:00:00 2001 From: Hakeem Kazeem Date: Tue, 28 Nov 2023 07:52:17 +0100 Subject: [PATCH 140/160] The name is defined multiple times resolved --- src/operators/tensor/implementations/tensor_fp32x32.cairo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index a368a65b1..ab6cba0fe 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -416,10 +416,6 @@ impl FP32x32Tensor of TensorTrait { math::sequence_at::sequence_at(sequence, position) } - fn sequence_construct(tensors: Array>) -> Array> { - math::sequence_construct::sequence_construct(tensors) - } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } From d697e3fe3c6583d727b836e8f6b12565bc622071 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Sat, 25 Nov 2023 14:50:51 +0100 Subject: [PATCH 141/160] Implement operator --- src/operators/tensor/core.cairo | 1 + .../tensor/implementations/tensor_bool.cairo | 4 + .../implementations/tensor_fp16x16.cairo | 4 + .../implementations/tensor_fp16x16wide.cairo | 4 + .../implementations/tensor_fp32x32.cairo | 4 + .../implementations/tensor_fp64x64.cairo | 4 + .../implementations/tensor_fp8x23.cairo | 4 + .../implementations/tensor_fp8x23wide.cairo | 4 + .../tensor/implementations/tensor_i32.cairo | 4 + .../tensor/implementations/tensor_i8.cairo | 4 + .../tensor/implementations/tensor_u32.cairo | 4 + src/operators/tensor/math.cairo | 1 + .../tensor/math/concat_from_sequence.cairo | 226 ++++++++++++++++++ 13 files changed, 268 insertions(+) create mode 100644 src/operators/tensor/math/concat_from_sequence.cairo diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 5a3cf5936..236736b3f 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -4416,6 +4416,7 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; } /// Cf: TensorTrait::new docstring diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index 0dd00f8ea..6d5540646 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -392,6 +392,10 @@ impl BoolTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + panic(array!['not supported!']) + } } /// Implements partial equal for two `Tensor` using the `PartialEq` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 5e22d89c0..ac968158f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -444,6 +444,10 @@ impl FP16x16Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1eff6975d..671dbe0e7 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -412,6 +412,10 @@ impl FP16x16WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 a6a5a1828..0b58988bb 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -443,6 +443,10 @@ impl FP32x32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 d9aa80a58..24ba382c3 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -445,6 +445,10 @@ impl FP64x64Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 9f2e9d822..cf635d737 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -443,6 +443,10 @@ impl FP8x23Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index ea75501fb..c5f19227b 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -402,6 +402,10 @@ impl FP8x23WTensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 facc8a59a..fc3120c80 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -444,6 +444,10 @@ impl I32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 02ef9ff66..efb7f1629 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -443,6 +443,10 @@ impl I8Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// 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 15575d969..1e61383b2 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -394,6 +394,10 @@ impl U32Tensor of TensorTrait { fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { math::sequence_insert::sequence_insert(self, tensor, position) } + + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) + } } /// Implements addition for `Tensor` using the `Add` trait. diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 04a7253ae..3f732b23d 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -54,3 +54,4 @@ mod reduce_mean; mod pow; mod sequence_erase; mod sequence_insert; +mod concat_from_sequence; diff --git a/src/operators/tensor/math/concat_from_sequence.cairo b/src/operators/tensor/math/concat_from_sequence.cairo new file mode 100644 index 000000000..e8d838515 --- /dev/null +++ b/src/operators/tensor/math/concat_from_sequence.cairo @@ -0,0 +1,226 @@ +use core::clone::Clone; +use array::{ArrayTrait, SpanTrait}; +use option::OptionTrait; +use debug::PrintTrait; +use core::traits::Into; + +use orion::operators::tensor::helpers::replace_index; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::numbers::signed_integer::i32::i32; + + +fn concat_from_sequence, impl TCopy: Copy, impl TDrop: Drop,>( + sequence: Array>, axis: i32, new_axis: Option +) -> Tensor { + + let new_axis: usize = match new_axis { + Option::Some(p) => { + assert(p == 0 || p == 1, 'new_axis must be 0 or 1'); + p + }, + Option::None(_) => 0 + }; + + let first_tensor = *sequence.at(0); + let r = first_tensor.shape.len(); + + let axis_is_negative: bool = axis.sign; + let mut axis_value: u32 = axis.mag; + + if new_axis == 0 { + /// assert in range [-r, r - 1] + assert((axis_is_negative == false && axis_value <= r - 1) || (axis_is_negative == true && axis_value <= r), 'Out of bounds for dimension'); + if axis_is_negative == true { + axis_value = r - axis_value + } + concat(sequence.span(), axis_value) + } else { + /// assert in range [-r - 1, r] + assert((axis_is_negative == false && axis_value <= r) || (axis_is_negative == true && axis_value <= r + 1), 'Out of bounds for dimension'); + if axis_is_negative == true { + if axis_value > r { + axis_value = 0 + } else { + axis_value = r - axis_value + } + } + let mut input_sequence_copy = sequence; + let mut reshaped_sequence = ArrayTrait::>::new(); + loop { + match input_sequence_copy.pop_front() { + Option::Some(input_sequence_value) => { + let mut reshaped_tensor = add_new_dimension(input_sequence_value, axis_value); + reshaped_sequence.append(reshaped_tensor); + }, + Option::None(_) => { break; } + }; + }; + concat(reshaped_sequence.span(), axis_value) + } +} + + +fn add_new_dimension, impl TCopy: Copy, impl TDrop: Drop,>( + mut tensor: Tensor, axis: usize +) -> Tensor { + let mut tensor_shape = tensor.shape; + let mut new_tensor_shape = ArrayTrait::::new(); + let mut tensor_shape_counter: usize = 0; + loop { + match tensor_shape.pop_front() { + Option::Some(tensor_shape_value) => { + if tensor_shape_counter == axis { + new_tensor_shape.append(1); + } + new_tensor_shape.append(*tensor_shape_value); + tensor_shape_counter += 1; + }, + Option::None(_) => { break; } + }; + }; + if axis >= tensor.shape.len() { + new_tensor_shape.append(1); + } + TensorTrait::::new(new_tensor_shape.span(), tensor.data) +} + + +fn concat, impl TCopy: Copy, impl TDrop: Drop,>( + mut tensors: Span>, axis: usize +) -> Tensor { + assert(tensors.len() >= 2, 'Input tensors must be > 1'); + let base_tensor = *tensors.at(0); + let base_shape = base_tensor.shape; + let dimension = base_shape.len(); + assert(dimension > axis, 'Out of bounds for dimension'); + + // Validate shapes of tensors + validate_shapes(tensors, base_shape, axis); + + // Calculate output size + let output_size = compute_output_size(base_shape, tensors, axis); + + // Concatenate tensor data + let output_data: Array = concatenate_data(tensors, axis, base_shape); + + TensorTrait::::new(output_size.span(), output_data.span()) +} + +fn validate_shapes(mut tensors: Span>, mut base_shape: Span, axis: usize) { + loop { + match tensors.pop_front() { + Option::Some(tensor) => { + assert(base_shape.len() == (*tensor.shape).len(), 'Dimension not the same'); + + let mut axis_index = 0; + let mut tensor_shape = *tensor.shape; + let mut base_shape_copy = base_shape; + loop { + match tensor_shape.pop_front() { + Option::Some(tensor_shape_i) => { + let base_shape_i = base_shape_copy.pop_front().unwrap(); + if axis_index != axis { + assert(base_shape_i == tensor_shape_i, 'Shape is not the same'); + } + axis_index += 1; + }, + Option::None(_) => { break; } + }; + }; + }, + Option::None(_) => { break; } + }; + }; +} + +fn compute_output_size( + mut base_shape: Span, mut tensors: Span>, axis: usize +) -> Array { + let mut output_size = ArrayTrait::::new(); + + let mut axis_size = 0; + loop { + match tensors.pop_front() { + Option::Some(tensor) => { axis_size += *(*tensor.shape).at(axis); }, + Option::None(_) => { break; } + }; + }; + + let mut shape_index = 0; + loop { + match base_shape.pop_front() { + Option::Some(item) => { + if shape_index == axis { + output_size.append(axis_size); + } else { + output_size.append(*item); + } + shape_index += 1; + }, + Option::None(_) => { break; } + }; + }; + + output_size +} + +fn concatenate_data, impl TDrop: Drop,>( + mut tensors: Span>, axis: usize, base_shape: Span +) -> Array { + let mut output_data = ArrayTrait::::new(); + + let total_loops = product_upto(base_shape, axis); + + let mut outer_loop_index = 0; + loop { + if outer_loop_index == total_loops { + break; + } + + let mut tensors_copy = tensors; + loop { + match tensors_copy.pop_front() { + Option::Some(tensor) => { + let slice_len = (*tensor.data).len() / total_loops; + + let mut inner_index = 0; + loop { + if inner_index == slice_len { + break; + } + + output_data + .append(*(*tensor.data).at(slice_len * outer_loop_index + inner_index)); + inner_index += 1; + }; + }, + Option::None(_) => { break; } + }; + }; + + outer_loop_index += 1; + }; + + output_data +} + +fn product_upto(mut shape: Span, upto: usize) -> usize { + let mut total = 1; + let mut index = 0; + + loop { + match shape.pop_front() { + Option::Some(val) => { + if index == upto { + break; + } + + total *= *val; + index += 1; + }, + Option::None(_) => { break; } + }; + }; + + total +} From 2010ca9a7d11b282d9063afdc9fe6ab6d7feaaa9 Mon Sep 17 00:00:00 2001 From: chachaleo Date: Wed, 29 Nov 2023 10:52:33 +0700 Subject: [PATCH 142/160] complex numbers --- docgen/src/main.rs | 8 + docs/framework/numbers/README.md | 4 +- .../numbers/complex-number/README.md | 0 .../numbers/complex-number/complex.arg.md | 32 ++ .../complex-number/complex.conjugate.md | 29 + .../numbers/complex-number/complex.exp.md | 31 ++ .../complex-number/complex.from_polar.md | 31 ++ .../numbers/complex-number/complex.img.md | 28 + .../numbers/complex-number/complex.ln.md | 31 ++ .../numbers/complex-number/complex.mag.md | 32 ++ .../numbers/complex-number/complex.new.md | 27 + .../numbers/complex-number/complex.one.md | 23 + .../numbers/complex-number/complex.pow.md | 48 ++ .../numbers/complex-number/complex.real.md | 28 + .../complex-number/complex.reciprocal.md | 35 ++ .../numbers/complex-number/complex.sqrt.md | 32 ++ .../complex-number/complex.to_polar.md | 36 ++ .../numbers/complex-number/complex.zero.md | 23 + src/numbers.cairo | 1 + src/numbers/complex_number.cairo | 2 + src/numbers/complex_number/complex64.cairo | 328 +++++++++++ .../complex_number/complex_trait.cairo | 516 ++++++++++++++++++ src/operators/tensor/core.cairo | 8 +- .../tensor/implementations/tensor_bool.cairo | 20 +- .../implementations/tensor_fp16x16.cairo | 27 +- .../implementations/tensor_fp16x16wide.cairo | 30 +- .../implementations/tensor_fp32x32.cairo | 28 +- .../implementations/tensor_fp64x64.cairo | 29 +- .../implementations/tensor_fp8x23.cairo | 24 +- .../implementations/tensor_fp8x23wide.cairo | 30 +- .../tensor/implementations/tensor_i32.cairo | 25 +- .../tensor/implementations/tensor_i8.cairo | 29 +- .../tensor/implementations/tensor_u32.cairo | 25 +- src/operators/tensor/math/pow.cairo | 4 +- src/operators/tensor/math/sequence_at.cairo | 15 +- .../tensor/math/sequence_erase.cairo | 13 +- .../tensor/math/sequence_insert.cairo | 38 +- .../tensor/math/sequence_length.cairo | 5 +- .../tensor/quantization/qlinear_concat.cairo | 125 +++-- tests/lib.cairo | 1 + tests/nodes/sequence_insert_fp16x16.cairo | 2 +- tests/nodes/sequence_insert_fp8x23.cairo | 2 +- tests/nodes/sequence_insert_i32.cairo | 2 +- tests/nodes/sequence_insert_i8.cairo | 2 +- tests/nodes/sequence_insert_u32.cairo | 2 +- tests/numbers.cairo | 1 + tests/numbers/complex_number_test.cairo | 408 ++++++++++++++ tests/operators/qlinear_concat_test.cairo | 54 +- 48 files changed, 2038 insertions(+), 236 deletions(-) create mode 100644 docs/framework/numbers/complex-number/README.md create mode 100644 docs/framework/numbers/complex-number/complex.arg.md create mode 100644 docs/framework/numbers/complex-number/complex.conjugate.md create mode 100644 docs/framework/numbers/complex-number/complex.exp.md create mode 100644 docs/framework/numbers/complex-number/complex.from_polar.md create mode 100644 docs/framework/numbers/complex-number/complex.img.md create mode 100644 docs/framework/numbers/complex-number/complex.ln.md create mode 100644 docs/framework/numbers/complex-number/complex.mag.md create mode 100644 docs/framework/numbers/complex-number/complex.new.md create mode 100644 docs/framework/numbers/complex-number/complex.one.md create mode 100644 docs/framework/numbers/complex-number/complex.pow.md create mode 100644 docs/framework/numbers/complex-number/complex.real.md create mode 100644 docs/framework/numbers/complex-number/complex.reciprocal.md create mode 100644 docs/framework/numbers/complex-number/complex.sqrt.md create mode 100644 docs/framework/numbers/complex-number/complex.to_polar.md create mode 100644 docs/framework/numbers/complex-number/complex.zero.md create mode 100644 src/numbers/complex_number.cairo create mode 100644 src/numbers/complex_number/complex64.cairo create mode 100644 src/numbers/complex_number/complex_trait.cairo create mode 100644 tests/numbers/complex_number_test.cairo diff --git a/docgen/src/main.rs b/docgen/src/main.rs index 97d11b112..7b41e3a50 100644 --- a/docgen/src/main.rs +++ b/docgen/src/main.rs @@ -35,6 +35,14 @@ fn main() { doc_trait(trait_path, doc_path, label); doc_functions(trait_path, doc_path, trait_name, label); + // COMPLEX NUMBER DOC + let trait_path = "src/numbers/complex_number/complex_trait.cairo"; + let doc_path = "docs/framework/numbers/complex-number"; + let label = "complex"; + let trait_name: &str = "ComplexTrait"; + doc_trait(trait_path, doc_path, label); + doc_functions(trait_path, doc_path, trait_name, label); + // TREE REGRESSOR DOC let trait_path = "src/operators/ml/tree_regressor/core.cairo"; let doc_path = "docs/framework/operators/machine-learning/tree-regressor"; diff --git a/docs/framework/numbers/README.md b/docs/framework/numbers/README.md index 545903c30..d28567d33 100644 --- a/docs/framework/numbers/README.md +++ b/docs/framework/numbers/README.md @@ -1,5 +1,5 @@ # Numbers -A full implementation of Signed Integer and Fixed Point in Cairo. +A full implementation of Signed Integer, Fixed Point and Complex Number in Cairo. -
Signed Integersigned-integer
Fixed Pointfixed-point
+
Signed Integersigned-integer
Fixed Pointfixed-point
Complex Numbercomplex-number
diff --git a/docs/framework/numbers/complex-number/README.md b/docs/framework/numbers/complex-number/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/framework/numbers/complex-number/complex.arg.md b/docs/framework/numbers/complex-number/complex.arg.md new file mode 100644 index 000000000..ada656032 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.arg.md @@ -0,0 +1,32 @@ +# ComplexTrait::arg + +```rust +fn arg(self: T) -> F; +``` + +Returns the argument of the complex number + +## Args + +* `self`(`T`) - The input complex number + +## Returns + +A fixed point number '', representing the argument of the complex number in radian. +'arg(z) = atan2(b, a)'. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn arg_complex64_example() -> FP64x64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.arg() +} +>>> {mag: 27224496882576083824, sign: false} // arg = 1.4758446204521403 (rad) +``` diff --git a/docs/framework/numbers/complex-number/complex.conjugate.md b/docs/framework/numbers/complex-number/complex.conjugate.md new file mode 100644 index 000000000..e81f9767f --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.conjugate.md @@ -0,0 +1,29 @@ +# ComplexTrait::conjugate + +```rust +fn conjugate(self: T) -> T; +``` + +Returns the conjugate of a complex number. The complex number is represented in Cartesian form `z = a + bi`. +The conjugate of `z = a + bi` is `z̅ = a - bi` + +## Args + +* `self`(`T`) - The complex number from which we want the conjugate. + +## Returns + +A complex number ``, representing the imaginary part of `self` . + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn conjugate_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + z.conjugate() +} +>>> {real: {mag: 184467440737095516160, sign: false}, im: {mag: 18446744073709551616, sign: true}} // 10 - i +``` diff --git a/docs/framework/numbers/complex-number/complex.exp.md b/docs/framework/numbers/complex-number/complex.exp.md new file mode 100644 index 000000000..73b55c360 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.exp.md @@ -0,0 +1,31 @@ +# ComplexTrait::exp + +```rust +fn exp(self: T) -> T; +``` + +Returns the value of e raised to the power of the complex number. + +## Args + +* `self`(`T`) - The input complex number + +## Returns + +The natural exponent of the input complex number. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn exp_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + ComplexTrait::exp(z) +} +>>> {real: {mag: 402848450095324460000, sign: true}, im: {mag: 923082101320478400000, sign: true}} // -21.838458238788455-50.04038098170736 i +``` diff --git a/docs/framework/numbers/complex-number/complex.from_polar.md b/docs/framework/numbers/complex-number/complex.from_polar.md new file mode 100644 index 000000000..1aa744c87 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.from_polar.md @@ -0,0 +1,31 @@ +# ComplexTrait::from_polar + + +```rust +fn from_polar(mag: F, arg: F) -> T; +``` + +Returns a complex number (in the Cartesian form) from the polar coordinates of the complex number. + +## Args + +* `mag`(`F`) - The input fixed point number representing the magnitude. +* `arg`(`F`) - The input fixed point number representing the argument. + +## Returns + +The complex number representing the Cartesian form calculated from the input polar coordinates. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn from_polar_complex64_example() -> complex64 { + let mag: FP64x64 = FixedTrait::new(778268985067028086784, false); // 42.190046219457976 + let arg: FP64x64 = FixedTrait::new(27224496882576083824, false); //1.4758446204521403 + ComplexTrait::from_polar(mag,arg) +} +>>> {real: {mag: 73787936714814843012, sign: false}, im: {mag: 774759489569697723777, sign: false}} // 4 + 42 i + ``` diff --git a/docs/framework/numbers/complex-number/complex.img.md b/docs/framework/numbers/complex-number/complex.img.md new file mode 100644 index 000000000..a4c82bc8c --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.img.md @@ -0,0 +1,28 @@ +# ComplexTrait::img + +```rust +fn img(self: T) -> F; +``` + +Returns the imaginary part of a complex number. The complex number is represented in Cartesian form `z = a + bi` where `b` is the imaginary part. + +## Args + +* `self`(`T`) - The complex number from which we want the imaginary part. + +## Returns + +A fixed point number ``, representing the imaginary part of `self` . + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn img_complex64_example() -> FP64x64 { + let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + z.img() +} +>>> {mag: 18446744073709551616, sign: false} // 1 +``` diff --git a/docs/framework/numbers/complex-number/complex.ln.md b/docs/framework/numbers/complex-number/complex.ln.md new file mode 100644 index 000000000..cf77a9d67 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.ln.md @@ -0,0 +1,31 @@ +# ComplexTrait::ln + +```rust +fn ln(self: T) -> T; +``` + +Returns the natural logarithm of the complex number. + +## Args + +* `self`(`T`) - The input complex number. + +## Returns + +A complex number representing the natural logarithm of the input number. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn ln_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.ln() +} +>>> {real: {mag: 69031116512113681970, sign: false}, im: {mag: 27224496882576083824, sign: false}} // 3.7421843216430655 + 1.4758446204521403 i + ``` diff --git a/docs/framework/numbers/complex-number/complex.mag.md b/docs/framework/numbers/complex-number/complex.mag.md new file mode 100644 index 000000000..a9514fead --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.mag.md @@ -0,0 +1,32 @@ +# ComplexTrait::mag + +```rust +fn mag(self: T) -> F; +``` + +Returns the magnitude of the complex number + +## Args + +* `self`(`T`) - The input complex number + +## Returns + +A fixed point number '', representing the magnitude of the complex number. +'mag(z) = sqrt(a^2 + b^2)'. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn mag_complex64_example() -> FP64x64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.mag() +} +>>> {mag: 0x2a30a6de7900000000, sign: false} // mag = 42.190046219457976 +``` diff --git a/docs/framework/numbers/complex-number/complex.new.md b/docs/framework/numbers/complex-number/complex.new.md new file mode 100644 index 000000000..6efed8bb2 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.new.md @@ -0,0 +1,27 @@ +# ComplexTrait::new + +```rust +fn new(real: F, img: F) -> T; +``` + +## Args + +* `real`(`F`) - The real part of the complex number. +* `img`(`F`) - The imaginary part of the complex number. + +## Returns + +A new complex number. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + + +fn new_complex64_example() -> complex64 { + ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)) +} +>>> {real: {mag: 184467440737095516160, sign: false}, im: {mag: 18446744073709551616, sign: false}} // 10 + i +``` diff --git a/docs/framework/numbers/complex-number/complex.one.md b/docs/framework/numbers/complex-number/complex.one.md new file mode 100644 index 000000000..99b4e8e95 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.one.md @@ -0,0 +1,23 @@ +# ComplexTrait::one + +```rust +fn one(self: T) -> T; +``` + +Returns the multiplicative identity element one + +## Returns + +A complex number ``, representing the multiplicative identity element of the complex field : `1 + 0i`. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn one_complex64_example() -> complex64 { + ComplexTrait::one() +} +>>> {real: {mag: 18446744073709551616, sign: false}, im: {mag: 0, sign: false}} // 1 + 0i +``` diff --git a/docs/framework/numbers/complex-number/complex.pow.md b/docs/framework/numbers/complex-number/complex.pow.md new file mode 100644 index 000000000..fa4e015e6 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.pow.md @@ -0,0 +1,48 @@ +# ComplexTrait::pow + +```rust +fn pow(self: T, b: T) -> T; +``` + +Returns the result of raising the complex number to the power of another complex number. + +## Args + +* `self`(`T`) - The input complex number. +* `b`(`T`) - The exponent complex number. + +## Returns + +A complex number representing the result of z^w. + +## Examples + +```rust +use orion::numbers::complex_number::complex_trait::ComplexTrait; +use orion::numbers::complex_number::complex64::{TWO, complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn pow_2_complex64_example() -> complex64 { + let two = ComplexTrait::new(FP64x64Impl::new(TWO, false),FP64x64Impl::new(0, false)); + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.pow(two) +} +>>> {real: {mag: 32244908640844296224768, sign: true}, im: {mag: 6198106008766409342976, sign: false}} // -1748 + 336 i + +fn pow_w_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + + let w: complex64 = ComplexTrait::new( + FixedTrait::new(36893488147419103232, false), + FixedTrait::new(18446744073709551616, false) + ); // 2 + i + z.pow(w) +} +>>> {real: {mag: 6881545343236111419203, sign: false}, im: {mag: 2996539405459717736042, sign: false}} // -373.0485407816205 + 162.4438823807959 i +``` diff --git a/docs/framework/numbers/complex-number/complex.real.md b/docs/framework/numbers/complex-number/complex.real.md new file mode 100644 index 000000000..8e448d1c3 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.real.md @@ -0,0 +1,28 @@ +# ComplexTrait::real + +```rust +fn real(self: T) -> F; +``` + +Returns the real part of a complex number. The complex number is represented in Cartesian form `z = a + bi` where `a` is the real part. + +## Args + +* `self`(`T`) - The complex number from which we want the real part. + +## Returns + +A fixed point number ``, representing the real part of `self` . + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn real_complex64_example() -> FP64x64 { + let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + z.real() +} +>>> {mag: 184467440737095516160, sign: false} // 10 +``` diff --git a/docs/framework/numbers/complex-number/complex.reciprocal.md b/docs/framework/numbers/complex-number/complex.reciprocal.md new file mode 100644 index 000000000..3265a7e67 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.reciprocal.md @@ -0,0 +1,35 @@ +# ComplexTrait::reciprocal + + +```rust +fn reciprocal(self: T) -> T; +``` + +Returns a the reciprocal of the complex number (i.e. 1/z). + +## Args + +* `self`(`T`) - The input complex number. + +## Returns + +The reciprocal of the complex number \(a + bi\) is given by: +\[ +\frac{1}{a + bi} = \frac{a}{a^2 + b^2} - \frac{b}{a^2 + b^2}i +\] + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn reciprocal_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.reciprocal() +} +>>> {real: {mag: 41453357469010228, sign: false}, im: {mag: 435260253424607397, sign: true}} // 0.002247191011 - 0.0235955056 i + ``` diff --git a/docs/framework/numbers/complex-number/complex.sqrt.md b/docs/framework/numbers/complex-number/complex.sqrt.md new file mode 100644 index 000000000..c8da966bc --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.sqrt.md @@ -0,0 +1,32 @@ +# ComplexTrait::sqrt + +```rust +fn arg(self: T) -> F; +``` + +Returns the value of the squre root of the complex number. + +## Args + +* `self`(`T`) - The input complex number + +## Returns + +A complex number '', representing the square root of the complex number. +'arg(z) = atan2(b, a)'. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn sqrt_complex64_example() -> complex64 { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.sqrt() +} +>>> {real: {mag: 88650037379463118848, sign: false}, im: {mag: 80608310115317055488, sign: false}} // 4.80572815603723 + 4.369785247552674 i +``` diff --git a/docs/framework/numbers/complex-number/complex.to_polar.md b/docs/framework/numbers/complex-number/complex.to_polar.md new file mode 100644 index 000000000..923387090 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.to_polar.md @@ -0,0 +1,36 @@ + +//fn log2(self: T) -> T; + +//fn log10(self: T) -> T; + +# ComplexTrait::to_polar + +```rust +fn to_polar(self: T) -> (F, F); +``` + +Returns the polar coordinates (magnitude and argument) of the complex number. + +## Args + +* `self`(`T`) - The input complex number. + +## Returns + +A tuple of two fixed point numbers representing the polar coordinates of the input number. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn to_polar_complex64_example() -> (FP64x64, FP64x64) { + let z: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), + FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + z.to_polar() +} +>>> ({mag: 778268985067028086784, sign: false}, {mag: 27224496882576083824, sign: false}) // mag : 42.190046219457976 + arg : 1.4758446204521403 + ``` diff --git a/docs/framework/numbers/complex-number/complex.zero.md b/docs/framework/numbers/complex-number/complex.zero.md new file mode 100644 index 000000000..609cfe2e7 --- /dev/null +++ b/docs/framework/numbers/complex-number/complex.zero.md @@ -0,0 +1,23 @@ +# ComplexTrait::zero + +```rust +fn zero(self: T) -> T; +``` + +Returns the additive identity element zero + +## Returns + +A complex number ``, representing the additive identity element of the complex field `0`. + +## Examples + +```rust +use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + +fn zero_complex64_example() -> complex64 { + ComplexTrait::zero() +} +>>> {real: {mag: 0, sign: false}, im: {mag: 0, sign: false}} // 0 + 0i +``` diff --git a/src/numbers.cairo b/src/numbers.cairo index bb781afb3..9d6e1e239 100644 --- a/src/numbers.cairo +++ b/src/numbers.cairo @@ -1,5 +1,6 @@ mod fixed_point; mod signed_integer; +mod complex_number; use orion::numbers::signed_integer::integer_trait::IntegerTrait; use orion::numbers::fixed_point::core::FixedTrait; diff --git a/src/numbers/complex_number.cairo b/src/numbers/complex_number.cairo new file mode 100644 index 000000000..2cf4cb2e5 --- /dev/null +++ b/src/numbers/complex_number.cairo @@ -0,0 +1,2 @@ +mod complex_trait; +mod complex64; diff --git a/src/numbers/complex_number/complex64.cairo b/src/numbers/complex_number/complex64.cairo new file mode 100644 index 000000000..026fcd58b --- /dev/null +++ b/src/numbers/complex_number/complex64.cairo @@ -0,0 +1,328 @@ +use debug::PrintTrait; + +use orion::numbers::complex_number::complex_trait::ComplexTrait; +use orion::numbers::{FP64x64, FP64x64Impl, FP32x32, FP32x32Impl, FixedTrait}; + +// ====================== Complex 64 ====================== + +// complex64 represents a complex number in the Cartesian form z = a + bi where a and b are Fixed Points FP64x64. +// The real field holds the value of the real part. +// The img field holds the value of the imaginary part. +#[derive(Serde, Copy, Drop)] +struct complex64 { + real: FP64x64, + img: FP64x64, +} + +// CONSTANTS for FP64x64 + +const PI: u128 = 57952155664616982739; +const HALF_PI: u128 = 28976077832308491370; +const TWO: u128 = 36893488147419103232; +const E: u128 = 50143449208471493718; + +impl Complex64Impl of ComplexTrait { + fn new(real: FP64x64, img: FP64x64) -> complex64 { + complex64 { real, img } + } + + fn real(self: complex64) -> FP64x64 { + self.real + } + + fn img(self: complex64) -> FP64x64 { + self.img + } + + fn conjugate(self: complex64) -> complex64 { + ComplexTrait::new(self.real, -self.img) + } + + fn zero() -> complex64 { + return complex64 { real: FixedTrait::ZERO(), img: FP64x64Impl::ZERO() }; + } + + fn one() -> complex64 { + return complex64 { real: FP64x64Impl::ONE(), img: FP64x64Impl::ZERO() }; + } + + fn mag(self: complex64) -> FP64x64 { + let two = FP64x64Impl::new(TWO, false); + (self.real.pow(two) + self.img.pow(two)).sqrt() + } + + fn arg(self: complex64) -> FP64x64 { + atan2(self.real, self.img) + } + + fn exp(self: complex64) -> complex64 { + let real = self.real.exp() * self.img.cos(); + let img = self.real.exp() * self.img.sin(); + complex64 { real, img } + } + + fn sqrt(self: complex64) -> complex64 { + let x = self.real; + let y = self.img; + let two = FP64x64Impl::new(TWO, false); + let real = (((x.pow(two) + y.pow(two)).sqrt() + x) / two).sqrt(); + let img = (((x.pow(two) + y.pow(two)).sqrt() - x) / two).sqrt(); + let img = FP64x64Impl::new(img.mag, y.sign); + complex64 { real, img } + } + + fn ln(self: complex64) -> complex64 { + let real = self.mag().ln(); + let img = self.arg(); + complex64 { real, img } + } + + fn pow(self: complex64, b: complex64) -> complex64 { + let two = FP64x64Impl::new(TWO, false); + let x = self.real; + let y = self.img; + + //z^2=(a^2-b^2)+2abi + if (b.real == two && b.img == FP64x64Impl::new(0, false)) { + let real = x.pow(two) - y.pow(two); + let img = two * x * y; + return complex64 { real, img }; + } + + //(a+bi)^n=r^n(cos(nθ)+isin(nθ)) + if (b.img == FP64x64Impl::new(0, false)) { + let mag_pow_n = self.mag().pow(b.real); + let arg_mul_n = b.real * self.arg(); + let real = mag_pow_n * arg_mul_n.cos(); + let img = mag_pow_n * arg_mul_n.sin(); + return complex64 { real, img }; + } + + //let z = (a+bi) (a+bi)^(c+di)= e^(c * ln(mag(z)) - d arg(z)) * cos (c * arg(z) + d ln(mag(r))) + i * e^(c * ln(mag(z)) - d arg(z)) * cos (c * arg(z) + d ln(mag(r))) + //let A = e^(c * ln(mag(z)) - d arg(z)) and B = c * arg(z) + d ln(mag(r)) + //(a+bi)^(c+di)= A * cos (B) + i * A * sin B + let A = FP64x64Impl::new(E, false).pow(b.real * self.mag().ln() - b.img * self.arg()); + let B = b.real * self.arg() + b.img * self.mag().ln(); + let real = A * B.cos(); + let img = A * B.sin(); + complex64 { real, img } + } + + + fn to_polar(self: complex64) -> (FP64x64, FP64x64) { + let mag = self.mag(); + let arg = self.arg(); + return (mag, arg); + } + + fn from_polar(mag: FP64x64, arg: FP64x64) -> complex64 { + let real = mag * arg.cos(); + let img = mag * arg.sin(); + complex64 { real, img } + } + + fn reciprocal(self: complex64) -> complex64 { + let two = FP64x64Impl::new(TWO, false); + let x = self.real; + let y = self.img; + + let real = x / (x.pow(two) + y.pow(two)); + let img = -y / (x.pow(two) + y.pow(two)); + complex64 { real, img } + } +} + +fn atan2(x: FP64x64, y: FP64x64) -> FP64x64 { + let two = FP64x64Impl::new(TWO, false); + if (y != FP64x64Impl::ZERO() || x > FP64x64Impl::ZERO()) { + return two * (y / (x + (x.pow(two) + y.pow(two)).sqrt())).atan(); + } else if x < FP64x64Impl::ZERO() { + return FP64x64Impl::new(PI, false); + } else { + panic(array!['undifined']) + } +} + +impl complex64Print of PrintTrait { + fn print(self: complex64) { + self.real.print(); + '+'.print(); + self.img.print(); + 'i'.print(); + } +} + +// Implements the Add trait for complex64. +impl complex64Add of Add { + fn add(lhs: complex64, rhs: complex64) -> complex64 { + complex64_add(lhs, rhs) + } +} + +// Implements the AddEq trait for complex64. +impl complex64AddEq of AddEq { + #[inline(always)] + fn add_eq(ref self: complex64, other: complex64) { + self = Add::add(self, other); + } +} + +// Implements the Sub trait for complex64. +impl complex64Sub of Sub { + fn sub(lhs: complex64, rhs: complex64) -> complex64 { + complex64_sub(lhs, rhs) + } +} + +// Implements the SubEq trait for complex64. +impl complex64SubEq of SubEq { + #[inline(always)] + fn sub_eq(ref self: complex64, other: complex64) { + self = Sub::sub(self, other); + } +} + +// Implements the Mul trait for complex64. +impl complex64Mul of Mul { + fn mul(lhs: complex64, rhs: complex64) -> complex64 { + complex64_mul(lhs, rhs) + } +} + +// Implements the MulEq trait for complex64. +impl complex64MulEq of MulEq { + #[inline(always)] + fn mul_eq(ref self: complex64, other: complex64) { + self = Mul::mul(self, other); + } +} + +// Implements the Div trait for complex64. +impl complex64Div of Div { + fn div(lhs: complex64, rhs: complex64) -> complex64 { + complex64_div(lhs, rhs) + } +} + +// Implements the DivEq trait for complex64. +impl complex64DivEq of DivEq { + #[inline(always)] + fn div_eq(ref self: complex64, other: complex64) { + self = Div::div(self, other); + } +} + + +// Implements the PartialEq trait for complex64. +impl complex64PartialEq of PartialEq { + fn eq(lhs: @complex64, rhs: @complex64) -> bool { + complex64_eq(*lhs, *rhs) + } + + fn ne(lhs: @complex64, rhs: @complex64) -> bool { + complex64_ne(*lhs, *rhs) + } +} + +// Implements the Neg trait for complex64. +impl i8Neg of Neg { + fn neg(a: complex64) -> complex64 { + complex64_neg(a) + } +} + +/// Cf: ComplexTrait::new docstring + +// Adds two complex64 complex numbers. +// +// The sum of two complex numbers (x + yi) + (u + vi) = (x + u) + (y + v)i. +// The result is a new complex number where the real part equals (x + u) and the imaginary part equals (y + v). +// # Arguments +// * `a` - The first complex64 to add. +// * `b` - The second complex64 to add. +// # Returns +// * `complex64` - The sum of `a` and `b`. +fn complex64_add(a: complex64, b: complex64) -> complex64 { + let real = a.real + b.real; + let img = a.img + b.img; + return ComplexTrait::new(real, img); +} + +// Subtracts complex64 complex numbers. +// +// The sum of two complex numbers (x + yi) - (u + vi) = (x - u) + (y - v)i. +// The result is a new complex number where the real part equals (x - u) and the imaginary part equals (y - v). +// # Arguments +// * `a` - The first complex64 to subtract. +// * `b` - The second complex64 to subtract. +// # Returns +// * `complex64` - The difference of `a` and `b`. +fn complex64_sub(a: complex64, b: complex64) -> complex64 { + let real = a.real - b.real; + let img = a.img - b.img; + return ComplexTrait::new(real, img); +} + +// Multiplies two complex64 integers. +// +// The sum of two complex numbers (x + yi) * (u + vi) = (xu - yv) + (xv - yu)i. +// The result is a new complex number where the real part equals (xu - yv) and the imaginary part equals (xv - yu). +// # Arguments +// +// * `a` - The first complex64 to multiply. +// * `b` - The second complex64 to multiply. +// +// # Returns +// +// * `complex64` - The product of `a` and `b`. +fn complex64_mul(a: complex64, b: complex64) -> complex64 { + let real = a.real * b.real - a.img * b.img; + let img = a.real * b.img + a.img * b.real; + return ComplexTrait::new(real, img); +} + +// Divides the first complex64 by the second complex64. +// # Arguments +// * `a` - The complex64 dividend. +// * `b` - The complex64 divisor. +// # Returns +// * `complex64` - The quotient of `a` and `b`. +fn complex64_div(a: complex64, b: complex64) -> complex64 { + complex64_mul(a, b.reciprocal()) +} + +// Compares two complex64 complex numbers for equality. +// # Arguments +// * `a` - The first complex64 complex number to compare. +// * `b` - The second complex64 complex number to compare. +// # Returns +// * `bool` - `true` if the two complex numbers are equal, `false` otherwise. +fn complex64_eq(a: complex64, b: complex64) -> bool { + // Check if the two complex numbers have the same real part and the same imaginary part. + if a.real == b.real && a.img == b.img { + return true; + } + + return false; +} + +// Compares two complex64 complex numbers for inequality. +// # Arguments +// * `a` - The first complex64 complex number to compare. +// * `b` - The second complex64 complex number to compare. +// # Returns +// * `bool` - `true` if the two complex numbers are not equal, `false` otherwise. +fn complex64_ne(a: complex64, b: complex64) -> bool { + // The result is the inverse of the equal function. + return !complex64_eq(a, b); +} + +// Negates the given complex64 complex number. +// # Arguments +// * `x` - The complex64 complex number to negate. +// # Returns +// * `complex64` - The negation of `x`. +fn complex64_neg(x: complex64) -> complex64 { + // The negation of an complex number is obtained by negating its real part and its imaginary part. + return ComplexTrait::new(-x.real, -x.img); +} diff --git a/src/numbers/complex_number/complex_trait.cairo b/src/numbers/complex_number/complex_trait.cairo new file mode 100644 index 000000000..37cf8396b --- /dev/null +++ b/src/numbers/complex_number/complex_trait.cairo @@ -0,0 +1,516 @@ +/// Trait +/// +/// new - Constructs a new `complex_number` +/// real - Returns the real part of the `complex_number` +/// img - Returns the imaginary part of the `complex_number` +/// conjugate - Returns the conjugate of the `complex_number` +/// zero - Returns the additive identity element zero +/// one - Returns the multiplicative identity element one +/// mag - Returns the magnitude of the `complex_number` +/// arg - Returns the argument of the `complex_number` +/// exp - Returns the value of e raised to the power of the `complex_number` +/// sqrt - Returns the value of the squre root of the `complex_number` +/// pow - Returns the result of raising the `complex_number` to the power of another `complex_number` +/// ln - Returns the natural logarithm of the `complex_number` +/// to_polar - Returns the polar coordinates of the `complex_number` +/// from_polar - Returns a `complex_number` from the polar coordinates of the `complex_number` +/// reciprocal - Returns a the reciprocal of the `complex_number` +/// +trait ComplexTrait { + /// # ComplexTrait::new + /// + /// ```rust + /// fn new(real: F, img: F) -> T; + /// ``` + /// + /// ## Args + /// + /// * `real`(`F`) - The real part of the complex number. + /// * `img`(`F`) - The imaginary part of the complex number. + /// + /// ## Returns + /// + /// A new complex number. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// + /// fn new_complex64_example() -> complex64 { + /// ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)) + /// } + /// >>> {real: {mag: 184467440737095516160, sign: false}, im: {mag: 18446744073709551616, sign: false}} // 10 + i + /// ``` + /// + fn new(real: F, img: F) -> T; + /// # ComplexTrait::real + /// + /// ```rust + /// fn real(self: T) -> F; + /// ``` + /// + /// Returns the real part of a complex number. The complex number is represented in Cartesian form `z = a + bi` where `a` is the real part. + /// + /// ## Args + /// + /// * `self`(`T`) - The complex number from which we want the real part. + /// + /// ## Returns + /// + /// A fixed point number ``, representing the real part of `self` . + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn real_complex64_example() -> FP64x64 { + /// let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + /// z.real() + /// } + /// >>> {mag: 184467440737095516160, sign: false} // 10 + /// ``` + /// + fn real(self: T) -> F; + /// # ComplexTrait::img + /// + /// ```rust + /// fn img(self: T) -> F; + /// ``` + /// + /// Returns the imaginary part of a complex number. The complex number is represented in Cartesian form `z = a + bi` where `b` is the imaginary part. + /// + /// ## Args + /// + /// * `self`(`T`) - The complex number from which we want the imaginary part. + /// + /// ## Returns + /// + /// A fixed point number ``, representing the imaginary part of `self` . + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn img_complex64_example() -> FP64x64 { + /// let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + /// z.img() + /// } + /// >>> {mag: 18446744073709551616, sign: false} // 1 + /// ``` + /// + fn img(self: T) -> F; + /// # ComplexTrait::conjugate + /// + /// ```rust + /// fn conjugate(self: T) -> T; + /// ``` + /// + /// Returns the conjugate of a complex number. The complex number is represented in Cartesian form `z = a + bi`. + /// The conjugate of `z = a + bi` is `z̅ = a - bi` + /// + /// ## Args + /// + /// * `self`(`T`) - The complex number from which we want the conjugate. + /// + /// ## Returns + /// + /// A complex number ``, representing the imaginary part of `self` . + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn conjugate_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new(FixedTrait::new(184467440737095516160, false), FixedTrait::new(18446744073709551616, false)); + /// z.conjugate() + /// } + /// >>> {real: {mag: 184467440737095516160, sign: false}, im: {mag: 18446744073709551616, sign: true}} // 10 - i + /// ``` + /// + fn conjugate(self: T) -> T; + /// # ComplexTrait::zero + /// + /// ```rust + /// fn zero(self: T) -> T; + /// ``` + /// + /// Returns the additive identity element zero + /// + /// ## Returns + /// + /// A complex number ``, representing the additive identity element of the complex field `0`. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn zero_complex64_example() -> complex64 { + /// ComplexTrait::zero() + /// } + /// >>> {real: {mag: 0, sign: false}, im: {mag: 0, sign: false}} // 0 + 0i + /// ``` + /// + fn zero() -> T; + /// # ComplexTrait::one + /// + /// ```rust + /// fn one(self: T) -> T; + /// ``` + /// + /// Returns the multiplicative identity element one + /// + /// ## Returns + /// + /// A complex number ``, representing the multiplicative identity element of the complex field : `1 + 0i`. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn one_complex64_example() -> complex64 { + /// ComplexTrait::one() + /// } + /// >>> {real: {mag: 18446744073709551616, sign: false}, im: {mag: 0, sign: false}} // 1 + 0i + /// ``` + /// + fn one() -> T; + /// # ComplexTrait::mag + /// + /// ```rust + /// fn mag(self: T) -> F; + /// ``` + /// + /// Returns the magnitude of the complex number + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number + /// + /// ## Returns + /// + /// A fixed point number '', representing the magnitude of the complex number. + /// 'mag(z) = sqrt(a^2 + b^2)'. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn mag_complex64_example() -> FP64x64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.mag() + /// } + /// >>> {mag: 0x2a30a6de7900000000, sign: false} // mag = 42.190046219457976 + /// ``` + /// + fn mag(self: T) -> F; + /// # ComplexTrait::arg + /// + /// ```rust + /// fn arg(self: T) -> F; + /// ``` + /// + /// Returns the argument of the complex number + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number + /// + /// ## Returns + /// + /// A fixed point number '', representing the argument of the complex number in radian. + /// 'arg(z) = atan2(b, a)'. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn arg_complex64_example() -> FP64x64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.arg() + /// } + /// >>> {mag: 27224496882576083824, sign: false} // arg = 1.4758446204521403 (rad) + /// ``` + /// + fn arg(self: T) -> F; + /// # ComplexTrait::exp + /// + /// ```rust + /// fn exp(self: T) -> T; + /// ``` + /// + /// Returns the value of e raised to the power of the complex number. + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number + /// + /// ## Returns + /// + /// The natural exponent of the input complex number. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn exp_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// ComplexTrait::exp(z) + /// } + /// >>> {real: {mag: 402848450095324460000, sign: true}, im: {mag: 923082101320478400000, sign: true}} // -21.838458238788455-50.04038098170736 i + /// ``` + /// + fn exp(self: T) -> T; + /// # ComplexTrait::sqrt + /// + /// ```rust + /// fn arg(self: T) -> F; + /// ``` + /// + /// Returns the value of the squre root of the complex number. + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number + /// + /// ## Returns + /// + /// A complex number '', representing the square root of the complex number. + /// 'arg(z) = atan2(b, a)'. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn sqrt_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.sqrt() + /// } + /// >>> {real: {mag: 88650037379463118848, sign: false}, im: {mag: 80608310115317055488, sign: false}} // 4.80572815603723 + 4.369785247552674 i + /// ``` + /// + fn sqrt(self: T) -> T; + /// # ComplexTrait::pow + /// + /// ```rust + /// fn pow(self: T, b: T) -> T; + /// ``` + /// + /// Returns the result of raising the complex number to the power of another complex number. + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number. + /// * `b`(`T`) - The exponent complex number. + /// + /// ## Returns + /// + /// A complex number representing the result of z^w. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::complex_trait::ComplexTrait; + /// use orion::numbers::complex_number::complex64::{TWO, complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn pow_2_complex64_example() -> complex64 { + /// let two = ComplexTrait::new(FP64x64Impl::new(TWO, false),FP64x64Impl::new(0, false)); + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.pow(two) + /// } + /// >>> {real: {mag: 32244908640844296224768, sign: true}, im: {mag: 6198106008766409342976, sign: false}} // -1748 + 336 i + /// + /// fn pow_w_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// + /// let w: complex64 = ComplexTrait::new( + /// FixedTrait::new(36893488147419103232, false), + /// FixedTrait::new(18446744073709551616, false) + /// ); // 2 + i + /// z.pow(w) + /// } + /// >>> {real: {mag: 6881545343236111419203, sign: false}, im: {mag: 2996539405459717736042, sign: false}} // -373.0485407816205 + 162.4438823807959 i + /// ``` + /// + fn pow(self: T, b: T) -> T; + /// # ComplexTrait::ln + /// + /// ```rust + /// fn ln(self: T) -> T; + /// ``` + /// + /// Returns the natural logarithm of the complex number. + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number. + /// + /// ## Returns + /// + /// A complex number representing the natural logarithm of the input number. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn ln_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.ln() + /// } + /// >>> {real: {mag: 69031116512113681970, sign: false}, im: {mag: 27224496882576083824, sign: false}} // 3.7421843216430655 + 1.4758446204521403 i + /// ``` + /// + fn ln(self: T) -> T; + /// + //fn log2(self: T) -> T; + /// + //fn log10(self: T) -> T; + /// + /// # ComplexTrait::to_polar + /// + /// ```rust + /// fn to_polar(self: T) -> (F, F); + /// ``` + /// + /// Returns the polar coordinates (magnitude and argument) of the complex number. + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number. + /// + /// ## Returns + /// + /// A tuple of two fixed point numbers representing the polar coordinates of the input number. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn to_polar_complex64_example() -> (FP64x64, FP64x64) { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.to_polar() + /// } + /// >>> ({mag: 778268985067028086784, sign: false}, {mag: 27224496882576083824, sign: false}) // mag : 42.190046219457976 + arg : 1.4758446204521403 + /// ``` + /// + fn to_polar(self: T) -> (F, F); + /// # ComplexTrait::from_polar + /// + /// + /// ```rust + /// fn from_polar(mag: F, arg: F) -> T; + /// ``` + /// + /// Returns a complex number (in the Cartesian form) from the polar coordinates of the complex number. + /// + /// ## Args + /// + /// * `mag`(`F`) - The input fixed point number representing the magnitude. + /// * `arg`(`F`) - The input fixed point number representing the argument. + /// + /// ## Returns + /// + /// The complex number representing the Cartesian form calculated from the input polar coordinates. + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn from_polar_complex64_example() -> complex64 { + /// let mag: FP64x64 = FixedTrait::new(778268985067028086784, false); // 42.190046219457976 + /// let arg: FP64x64 = FixedTrait::new(27224496882576083824, false); //1.4758446204521403 + /// ComplexTrait::from_polar(mag,arg) + /// } + /// >>> {real: {mag: 73787936714814843012, sign: false}, im: {mag: 774759489569697723777, sign: false}} // 4 + 42 i + /// ``` + /// + fn from_polar(mag: F, arg: F) -> T; + /// # ComplexTrait::reciprocal + /// + /// + /// ```rust + /// fn reciprocal(self: T) -> T; + /// ``` + /// + /// Returns a the reciprocal of the complex number (i.e. 1/z). + /// + /// ## Args + /// + /// * `self`(`T`) - The input complex number. + /// + /// ## Returns + /// + /// The reciprocal of the complex number \(a + bi\) is given by: + /// \[ + /// \frac{1}{a + bi} = \frac{a}{a^2 + b^2} - \frac{b}{a^2 + b^2}i + /// \] + /// + /// ## Examples + /// + /// ```rust + /// use orion::numbers::complex_number::{complex_trait::ComplexTrait, complex64::complex64}; + /// use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; + /// + /// fn reciprocal_complex64_example() -> complex64 { + /// let z: complex64 = ComplexTrait::new( + /// FixedTrait::new(73786976294838206464, false), + /// FixedTrait::new(774763251095801167872, false) + /// ); // 4 + 42i + /// z.reciprocal() + /// } + /// >>> {real: {mag: 41453357469010228, sign: false}, im: {mag: 435260253424607397, sign: true}} // 0.002247191011 - 0.0235955056 i + /// ``` + /// + fn reciprocal(self: T) -> T; +} diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index d6a0ad82f..bd91938e0 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -4291,7 +4291,9 @@ trait TensorTrait { /// >>> [[1], [2], [3]] /// ``` /// - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array>; /// ## tensor.sequence_at /// /// ```rust @@ -4387,7 +4389,9 @@ trait TensorTrait { /// >>> [[0, 1, 2, 3], [8, 9, 10, 11]] /// ``` /// - fn sequence_erase(sequence: Array>, position: Option>) -> Array>; + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array>; /// #tensor.pow /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d5de496a6..d76295671 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -283,7 +283,7 @@ impl BoolTensor of TensorTrait { y_scale: @Tensor, y_zero_point: @Tensor ) -> Tensor:: { - panic(array!['not supported!']) + panic(array!['not supported!']) } fn qlinear_concat( @@ -342,9 +342,9 @@ impl BoolTensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } @@ -390,13 +390,17 @@ impl BoolTensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { panic(array!['not supported!']) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 31028f340..cf8cfe78f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -407,22 +407,23 @@ impl FP16x16Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() @@ -449,13 +450,17 @@ impl FP16x16Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index 1340bba67..274db2eb4 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -265,7 +265,7 @@ impl FP16x16WTensor of TensorTrait { axis: usize ) -> Tensor:: { panic(array!['not supported!']) - } + } fn qlinear_leakyrelu( self: @Tensor, @@ -373,17 +373,19 @@ impl FP16x16WTensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } @@ -413,13 +415,17 @@ impl FP16x16WTensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index b94309d28..b8ffb7620 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -302,7 +302,7 @@ impl FP32x32Tensor of TensorTrait { NumberTrait::new_unscaled(128, true), NumberTrait::new_unscaled(127, false) ) - } + } fn qlinear_leakyrelu( self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: FP32x32 @@ -408,17 +408,19 @@ impl FP32x32Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } @@ -448,13 +450,17 @@ impl FP32x32Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 23f81d0d6..f2224ddba 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -408,23 +408,24 @@ impl FP64x64Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -450,13 +451,17 @@ impl FP64x64Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 43eb1a1e1..c5948dde9 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -400,17 +400,17 @@ impl FP8x23Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } @@ -449,13 +449,17 @@ impl FP8x23Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 88aa7690b..313d23ef2 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -359,22 +359,24 @@ impl FP8x23WTensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - - fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - math::shrink::shrink(self, bias, lambd) + + fn shrink( + self: Tensor, bias: Option, lambd: Option + ) -> Tensor { + math::shrink::shrink(self, bias, lambd) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - + fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -400,13 +402,17 @@ impl FP8x23WTensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { math::pow::pow(self, other) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index c42363db6..60446c0d3 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -406,23 +406,22 @@ impl I32Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -448,13 +447,17 @@ impl I32Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { panic(array!['not supported!']) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 92cf45d39..24d8efce5 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -297,12 +297,12 @@ impl I8Tensor of TensorTrait { zero_points, y_scale, y_zero_point, - axis, + axis, NumberTrait::new_unscaled(128, true), NumberTrait::new_unscaled(127, false) ) } - + fn qlinear_leakyrelu( self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: i8 ) -> Tensor:: { @@ -406,23 +406,22 @@ impl I8Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -448,13 +447,17 @@ impl I8Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { panic(array!['not supported!']) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 43cb6d1d0..5f8f5fe46 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -350,23 +350,22 @@ impl U32Tensor of TensorTrait { } fn sequence_length(self: Array>) -> Tensor { - math::sequence_length::sequence_length(self) + math::sequence_length::sequence_length(self) } - + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor { - panic(array!['not supported!']) + panic(array!['not supported!']) } - + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor { math::sequence_at::sequence_at(sequence, position) } - + fn sequence_construct(tensors: Array>) -> Array> { math::sequence_construct::sequence_construct(tensors) } - fn sequence_empty() -> Array> { math::sequence_empty::sequence_empty::() } @@ -392,13 +391,17 @@ impl U32Tensor of TensorTrait { fn pow(self: @Tensor, other: @Tensor) -> Tensor { panic(array!['not supported!']) } - - fn sequence_erase(sequence: Array>, position: Option>) -> Array> { + + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array> { math::sequence_erase::sequence_erase(sequence, position) } - - fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array> { - math::sequence_insert::sequence_insert(self, tensor, position) + + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array> { + math::sequence_insert::sequence_insert(self, tensor, position) } } diff --git a/src/operators/tensor/math/pow.cairo b/src/operators/tensor/math/pow.cairo index 2a2ffd991..f31fd774b 100644 --- a/src/operators/tensor/math/pow.cairo +++ b/src/operators/tensor/math/pow.cairo @@ -4,9 +4,7 @@ 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 -}; +use orion::operators::tensor::helpers::{broadcast_shape, broadcast_index_mapping, len_from_shape}; /// Cf: TensorTrait::pow docstring fn pow< diff --git a/src/operators/tensor/math/sequence_at.cairo b/src/operators/tensor/math/sequence_at.cairo index c819afdab..983aa3986 100644 --- a/src/operators/tensor/math/sequence_at.cairo +++ b/src/operators/tensor/math/sequence_at.cairo @@ -6,24 +6,25 @@ use orion::numbers::NumberTrait; use orion::numbers::signed_integer::i32::i32; /// Cf: TensorTrait::sequence_at docstring -fn sequence_at< - T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop ->( +fn sequence_at, impl TCopy: Copy, impl TDrop: Drop>( sequence: Array>, position: Tensor ) -> Tensor { - assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); let position_value_i32: i32 = *position.data.at(0); let is_negative: bool = position_value_i32.sign; let position_value: u32 = position_value_i32.mag; - assert((is_negative == false && position_value <= sequence.len() - 1) || (is_negative == true && position_value <= sequence.len()), 'Position out of bounds'); - + assert( + (is_negative == false && position_value <= sequence.len() - 1) + || (is_negative == true && position_value <= sequence.len()), + 'Position out of bounds' + ); + if is_negative == false { return *sequence.at(position_value); } else { let normalized_position_value = sequence.len() - position_value; return *sequence.at(normalized_position_value); } -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/sequence_erase.cairo b/src/operators/tensor/math/sequence_erase.cairo index 252ce777f..6d7d4b913 100644 --- a/src/operators/tensor/math/sequence_erase.cairo +++ b/src/operators/tensor/math/sequence_erase.cairo @@ -7,12 +7,9 @@ use orion::numbers::NumberTrait; use orion::numbers::signed_integer::i32::i32; /// Cf: TensorTrait::sequence_erase docstring -fn sequence_erase< - T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop ->( +fn sequence_erase, impl TCopy: Copy, impl TDrop: Drop>( sequence: Array>, position: Option> ) -> Array> { - let position: Tensor = match position { Option::Some(p) => p, Option::None(_) => { @@ -29,7 +26,11 @@ fn sequence_erase< let is_negative: bool = position_value_i32.sign; let mut position_value: u32 = position_value_i32.mag; - assert((is_negative == false && position_value <= sequence.len() - 1) || (is_negative == true && position_value <= sequence.len()), 'Position out of bounds'); + assert( + (is_negative == false && position_value <= sequence.len() - 1) + || (is_negative == true && position_value <= sequence.len()), + 'Position out of bounds' + ); if is_negative == true { position_value = sequence.len() - position_value; @@ -54,4 +55,4 @@ fn sequence_erase< }; return output_sequence; -} \ No newline at end of file +} diff --git a/src/operators/tensor/math/sequence_insert.cairo b/src/operators/tensor/math/sequence_insert.cairo index 0ece08928..85b06f64a 100644 --- a/src/operators/tensor/math/sequence_insert.cairo +++ b/src/operators/tensor/math/sequence_insert.cairo @@ -7,19 +7,17 @@ use orion::numbers::NumberTrait; use orion::numbers::signed_integer::i32::i32; /// Cf: TensorTrait::sequence_insert docstring -fn sequence_insert< - T, impl TTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop ->( +fn sequence_insert, impl TCopy: Copy, impl TDrop: Drop>( self: Array>, tensor: @Tensor, position: Option> ) -> Array> { let position: Tensor = match position { Option::Some(p) => p, - Option::None(_) => { + Option::None(_) => { let mut shape = ArrayTrait::::new(); let mut data = ArrayTrait::::new(); data.append(i32 { mag: 1, sign: true }); TensorTrait::::new(shape.span(), data.span()) - }, + }, }; assert(position.shape.len() == 0 && position.data.len() == 1, 'Position must be a scalar'); @@ -28,7 +26,11 @@ fn sequence_insert< let is_negative: bool = position_value_i32.sign; let mut position_value: u32 = position_value_i32.mag; - assert((is_negative == false && position_value <= self.len() - 1) || (is_negative == true && position_value <= self.len()), 'Position out of bounds'); + assert( + (is_negative == false && position_value <= self.len() - 1) + || (is_negative == true && position_value <= self.len()), + 'Position out of bounds' + ); if is_negative == true { position_value = self.len() - position_value; @@ -39,18 +41,18 @@ fn sequence_insert< let mut self_copy = self; loop { match self_copy.pop_front() { - Option::Some(t) => { - if position_value == 0 && inserted == false { - new_sequence.append(*tensor); - inserted = true; - } - new_sequence.append(t); - if inserted == false { - position_value -= 1; - } - }, - Option::None(_) => { break; }, - }; + Option::Some(t) => { + if position_value == 0 && inserted == false { + new_sequence.append(*tensor); + inserted = true; + } + new_sequence.append(t); + if inserted == false { + position_value -= 1; + } + }, + Option::None(_) => { break; }, + }; }; return new_sequence; diff --git a/src/operators/tensor/math/sequence_length.cairo b/src/operators/tensor/math/sequence_length.cairo index 65feeab43..c9057bc9c 100644 --- a/src/operators/tensor/math/sequence_length.cairo +++ b/src/operators/tensor/math/sequence_length.cairo @@ -9,8 +9,5 @@ fn sequence_length>(self: Array>) -> Tensor { - shape: shape.span(), - data: result.span(), - } + Tensor:: { shape: shape.span(), data: result.span(), } } diff --git a/src/operators/tensor/quantization/qlinear_concat.cairo b/src/operators/tensor/quantization/qlinear_concat.cairo index 7147dd936..7b990af2b 100644 --- a/src/operators/tensor/quantization/qlinear_concat.cairo +++ b/src/operators/tensor/quantization/qlinear_concat.cairo @@ -6,7 +6,9 @@ use orion::numbers::{NumberTrait}; use orion::operators::tensor::quantization::dequantize_linear::dequantize_linear; use orion::operators::tensor::quantization::quantize_linear::quantize_linear; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::math::concat::{validate_shapes, compute_output_size, concatenate_data}; +use orion::operators::tensor::math::concat::{ + validate_shapes, compute_output_size, concatenate_data +}; fn qlinear_concat< T, @@ -115,14 +117,21 @@ fn dequantize_tensors< impl TCopy: Copy, impl QCopy: Copy, impl QDrop: Drop - //MAybe numberTRait ->(mut tensors: Span>, scales: Span>, zero_points: Span>, min: T, max: T) -> Span> { +//MAybe numberTRait +>( + mut tensors: Span>, + scales: Span>, + zero_points: Span>, + min: T, + max: T +) -> Span> { let mut array = ArrayTrait::>::new(); let mut i = 0; loop { match tensors.pop_front() { Option::Some(tensor) => { - array.append(dequantize_linear(@(*tensor), @(*scales.at(i)), @(*zero_points.at(i)))); + array + .append(dequantize_linear(@(*tensor), @(*scales.at(i)), @(*zero_points.at(i)))); }, Option::None(_) => { break; } }; @@ -130,58 +139,58 @@ fn dequantize_tensors< }; return array.span(); } +/// # tensor.concat +/// +/// ```rust +/// fn concat(tensors: Span>, axis: usize, ) -> Tensor; +/// ``` +/// +/// Concatenate a list of tensors into a single tensor. +/// +/// ## Args +/// +/// * `tensors`(` Span>,`) - Array of the input tensors. +/// * `axis`(`usize`) - Axis to concat on. +/// +/// ## Panics +/// +/// * Panic if tensor length is not greater than 1. +/// * Panics if dimension is not greater than axis. +/// +/// ## Returns +/// +/// A new `Tensor` concatenated tensor of the input tensors. +/// +/// ## Example +/// +/// ```rust +/// use array::{ArrayTrait, SpanTrait}; +/// +/// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; +/// +/// fn concat_example() -> Tensor { +/// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); +/// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); +/// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 0); +/// return result; +/// } +/// >>> [[0. 1.] +/// [2. 3.], +/// [0. 1.] +/// [2. 3.]] +/// +/// result.shape +/// >>> (4, 2) +/// +/// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 1); +/// return result; +/// } +/// >>> [[0. 1., 0., 1.] +/// [2. 3., 2., 3.]] +/// +/// result.shape +/// >>> (2, 4 ) +/// ``` +/// +///fn concat(tensors: Span>, axis: usize,) -> Tensor; - /// # tensor.concat - /// - /// ```rust - /// fn concat(tensors: Span>, axis: usize, ) -> Tensor; - /// ``` - /// - /// Concatenate a list of tensors into a single tensor. - /// - /// ## Args - /// - /// * `tensors`(` Span>,`) - Array of the input tensors. - /// * `axis`(`usize`) - Axis to concat on. - /// - /// ## Panics - /// - /// * Panic if tensor length is not greater than 1. - /// * Panics if dimension is not greater than axis. - /// - /// ## Returns - /// - /// A new `Tensor` concatenated tensor of the input tensors. - /// - /// ## Example - /// - /// ```rust - /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; - /// - /// fn concat_example() -> Tensor { - /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); - /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); - /// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 0); - /// return result; - /// } - /// >>> [[0. 1.] - /// [2. 3.], - /// [0. 1.] - /// [2. 3.]] - /// - /// result.shape - /// >>> (4, 2) - /// - /// let result = TensorTrait::concat(tensors: array![tensor1, tensor2].span(), axis: 1); - /// return result; - /// } - /// >>> [[0. 1., 0., 1.] - /// [2. 3., 2., 3.]] - /// - /// result.shape - /// >>> (2, 4 ) - /// ``` - /// - ///fn concat(tensors: Span>, axis: usize,) -> Tensor; \ No newline at end of file diff --git a/tests/lib.cairo b/tests/lib.cairo index b8f3c9b96..f5cecb77d 100644 --- a/tests/lib.cairo +++ b/tests/lib.cairo @@ -4,3 +4,4 @@ mod tensor_core; mod nodes; mod ml; mod operators; + diff --git a/tests/nodes/sequence_insert_fp16x16.cairo b/tests/nodes/sequence_insert_fp16x16.cairo index 04a6b29cf..1fe67ce53 100644 --- a/tests/nodes/sequence_insert_fp16x16.cairo +++ b/tests/nodes/sequence_insert_fp16x16.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_fp16x16() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); + let y = input_0.sequence_insert(@input_1, Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_fp8x23.cairo b/tests/nodes/sequence_insert_fp8x23.cairo index e531a5cbb..f85b9a0f9 100644 --- a/tests/nodes/sequence_insert_fp8x23.cairo +++ b/tests/nodes/sequence_insert_fp8x23.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_fp8x23() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); + let y = input_0.sequence_insert(@input_1, Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_i32.cairo b/tests/nodes/sequence_insert_i32.cairo index 1b61242c7..fe516d5fd 100644 --- a/tests/nodes/sequence_insert_i32.cairo +++ b/tests/nodes/sequence_insert_i32.cairo @@ -18,7 +18,7 @@ fn test_sequence_insert_i32() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); + let y = input_0.sequence_insert(@input_1, Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_i8.cairo b/tests/nodes/sequence_insert_i8.cairo index 7d0b59401..112790b42 100644 --- a/tests/nodes/sequence_insert_i8.cairo +++ b/tests/nodes/sequence_insert_i8.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_i8() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); + let y = input_0.sequence_insert(@input_1, Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/nodes/sequence_insert_u32.cairo b/tests/nodes/sequence_insert_u32.cairo index 9c9a79717..7cee89af8 100644 --- a/tests/nodes/sequence_insert_u32.cairo +++ b/tests/nodes/sequence_insert_u32.cairo @@ -20,7 +20,7 @@ fn test_sequence_insert_u32() { let input_2 = input_2::input_2(); let z = output_0::output_0(); - let y = input_0.sequence_insert(@input_1,Option::Some(input_2)); + let y = input_0.sequence_insert(@input_1, Option::Some(input_2)); assert_seq_eq(y, z); } diff --git a/tests/numbers.cairo b/tests/numbers.cairo index d481977db..91ae91e96 100644 --- a/tests/numbers.cairo +++ b/tests/numbers.cairo @@ -1,3 +1,4 @@ // mod fixed_point; mod signed_integer_test; +mod complex_number_test; diff --git a/tests/numbers/complex_number_test.cairo b/tests/numbers/complex_number_test.cairo new file mode 100644 index 000000000..f644f8ed3 --- /dev/null +++ b/tests/numbers/complex_number_test.cairo @@ -0,0 +1,408 @@ +use orion::numbers::complex_number::complex_trait::ComplexTrait; +use orion::numbers::complex_number::complex64::{TWO, complex64}; +use orion::numbers::{FP64x64, FP64x64Impl, FixedTrait}; +use debug::PrintTrait; + + +#[test] +#[available_gas(2000000000)] +fn test_add() { + // Test addition of two complex numbers + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(36893488147419103232, false), + FixedTrait::::new(239807672958224171008, false) + ); + let result = a + b; + assert(result.real == FixedTrait::::new(110680464442257309696, false), '4 + 2 = 6'); + assert( + result.img == FixedTrait::::new(1014570924054025338880, false), + '42i + 13i = 55i, b = 55' + ); +} + +#[test] +#[available_gas(2000000000)] +fn test_sub() { + // Test substraction of two complex numbers + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(36893488147419103232, false), + FixedTrait::::new(239807672958224171008, false) + ); + let result = a - b; + assert(result.real == FixedTrait::::new(36893488147419103232, false), '4 - 2 = 2'); + assert( + result.img == FixedTrait::::new(534955578137576996864, false), + '42i - 13i = 29i, b = 29' + ); +} + +#[test] +#[available_gas(2000000000)] +fn test_mul() { + // Test multiplication of positive integers + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(36893488147419103232, false), + FixedTrait::::new(239807672958224171008, false) + ); + let result = a * b; + assert( + result.real == FixedTrait::::new(9924348311655738769408, true), + '4*2 - 42*13 = -538' + ); + assert( + result.img == FixedTrait::::new(2508757194024499019776, false), + '(4*13 + 2*42)i = 136i, b = 136' + ); + + // Test multiplication with a pure imaginary number + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(0, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(36893488147419103232, false), + FixedTrait::::new(239807672958224171008, false) + ); + let result = a * b; + assert( + result.real == FixedTrait::::new(10071922264245415182336, true), + '0*2 - 42*13 = 546' + ); + assert( + result.img == FixedTrait::::new(1549526502191602335744, false), + '(0*13 + 2*42)i = 84, b = 84' + ); + + // Test multiplication by zero + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new(FixedTrait::::new(0, false), FixedTrait::::new(0, false)); + let result = a * b; + assert(result.real == FixedTrait::::new(0, false), '0'); + assert(result.img == FixedTrait::::new(0, false), '0'); + + // Test i * i = -1 + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(0, false), + FixedTrait::::new(18446744073709551616, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(0, false), + FixedTrait::::new(18446744073709551616, false) + ); + let result = a * b; + assert(result.real == FixedTrait::::new(18446744073709551616, true), 'i * i = -1'); + assert(result.img == FixedTrait::::new(0, false), 'i * i = -1 + 0i'); +} + + +#[test] +#[available_gas(2000000000)] +fn test_div_no_rem() { + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(36893488147419103232, false), + FixedTrait::::new(239807672958224171008, false) + ); + let result = a / b; + assert( + result.real == FixedTrait::::new(59072232467254864688, false), + 'real = 3.2023121387283235' + ); + assert( + result.img == FixedTrait::::new(3412114510743963284, false), + 'img = 0.18497109826589594j' + ); +} + +#[test] +#[available_gas(2000000000)] +fn test_zero() { + // Test multiplication by zero + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let b = ComplexTrait::zero(); + let result = a * b; + assert(result.real == FixedTrait::::new(0, false), 'should be 0'); + assert(result.img == FixedTrait::::new(0, false), 'should be 0'); +} + + +#[test] +#[available_gas(2000000000)] +fn test_conjugate() { + // Test conjugate of a complex number + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let conjugate = a.conjugate(); + assert( + conjugate.real == FixedTrait::::new(73786976294838206464, false), + 'conjugate.real = 4' + ); + assert( + conjugate.img == FixedTrait::::new(774763251095801167872, true), + 'conjugate.img = -42' + ); +} + +#[test] +#[available_gas(2000000000)] +fn test_mag() { + // Test mag of a complex number + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); + let mag = a.mag(); + assert(mag == FixedTrait::new(0x2a30a6de7900000000, false), 'mag = 42.190046219457976'); +// should be 778268985068318500000 +// is : 778268985067028086784 + +} + +#[test] +#[available_gas(2000000000)] +fn test_arg() { + // Test arg of a complex number + let a = ComplexTrait::< + complex64 + >::new( + FixedTrait::::new(73786976294838206464, false), + FixedTrait::::new(774763251095801167872, false) + ); + let arg = a.arg(); + assert( + arg == FixedTrait::::new(27224496882576083824, false), 'arg = 1.4758446204521403' + ); +// should be 27224528006041640000 +// is : 27224496882576083824 +} + +#[test] +#[available_gas(2000000000)] +fn test_exp() { + // Test exp of a complex number + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + + let z = ComplexTrait::exp(a); + + let z_expected: complex64 = ComplexTrait::new( + FixedTrait::new(402848450095324460000, true), FixedTrait::new(923082101320478400000, true) + ); +// real part : +// should be 402848450095324460000 +// is : 402847992570293444378 + +// img part : +// should be 923082101320478400000 +// is : 923081058030224714169 + +//assert(z == z_expected, '-21.838458238788455-50.04038098170736j'); +} + + +#[test] +#[available_gas(2000000000)] +fn test_sqrt() { + // Test square root of a complex number + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); + let sqrt = a.sqrt(); + assert(sqrt.real == FixedTrait::new(88650037379463118848, false), 'real = 4.80572815603723'); + assert(sqrt.img == FixedTrait::new(80608310115317055488, false), 'img = 4.369785247552674'); +// real part : +// should be 88650037382238900000 +// is : 88650037379463118848 + +// img part : +// should be 80608310118675710000 +// is : 80608310115317055488 +} + +#[test] +#[available_gas(2000000000)] +fn test_ln() { + // Test ln of a complex number + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); + let ln = a.ln(); + assert(ln.real == FixedTrait::new(69031116512113681970, false), 'ln.real = 3.7421843216430655'); + assert(ln.img == FixedTrait::new(27224496882576083824, false), 'ln.img = 1.4758446204521403'); +// real part : +// should be 69031116457998020000 +// is : 69031116512113681970 + +// img part : +// should be 27224528006041640000 +// is : 27224496882576083824 +} + +#[test] +#[available_gas(2000000000)] +fn test_pow() { + // Test pow with exp = 2 + let two = ComplexTrait::new(FP64x64Impl::new(TWO, false), FP64x64Impl::new(0, false)); + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); + + let pow = a.pow(two); + assert(pow.real == FixedTrait::new(32244908640844296224768, true), 'pow.real = -1748'); + assert(pow.img == FixedTrait::new(6198106008766409342976, false), 'pow.img = 336'); + + // Test pow with exp = n, int + let three: complex64 = ComplexTrait::new( + FP64x64Impl::new(55340232221128654848, false), FP64x64Impl::new(0, false) + ); + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); + + let pow = a.pow(three); + assert(pow.real == FixedTrait::new(389305023520047451076807, true), 'pow.real = -21104'); + assert(pow.img == FixedTrait::new(1329485652886846033475029, true), 'pow.img = 72072'); + + // real part : + // should be 389300086931566377304064 + // is : 389305023520047451076807 + + // img part : + // should be 1329493738880394804068352 + // is : 1329485652886846033475029 + + // Test pow with exp = w, complex + let w: complex64 = ComplexTrait::new( + FixedTrait::new(36893488147419103232, false), FixedTrait::new(18446744073709551616, false) + ); // 2 + i + + let pow = a.pow(w); + assert( + pow.real == FixedTrait::new(6881545343236111419203, false), 'pow.real = 373.0485407816205' + ); + assert( + pow.img == FixedTrait::new(2996539405459717736042, false), 'pow.img = 162.4438823807959' + ); +// real part : +// should be 6881530958869354000000 +// is : 6881545343236111419203 + +// img part : +// should be 2996560724618318400000 +// is : 2996539405459717736042 +} + +#[test] +#[available_gas(2000000000)] +fn test_to_polar() { + // Test to polar coordinates of a complex number + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + let (mag, arg) = a.to_polar(); + + assert(mag == FixedTrait::new(778268985067028086784, false), 'mag = 42.190046219457976'); + assert(arg == FixedTrait::new(27224496882576083824, false), 'arg = 1.4758446204521403'); +// mag : +// should be 778268985067028086784 +// is : 778268985068318500000 + +// arg : +// should be 27224496882576083824 +// is : 27224528006041640000 +} + +#[test] +#[available_gas(2000000000)] +fn test_from_polar() { + // Test from polar coordiantes of a complex number + let mag: FP64x64 = FixedTrait::new(778268985067028086784, false); // 42.190046219457976 + let arg: FP64x64 = FixedTrait::new(27224496882576083824, false); //1.4758446204521403 + let z_actual: complex64 = ComplexTrait::from_polar(mag, arg); + + let z_expected: complex64 = ComplexTrait::new( + FixedTrait::new(73787936714814843012, false), FixedTrait::new(774759489569697723777, false) + ); + // mag : + // should be 73786976294838206464 + // is : 73787936714814843012 + + // img : + // should be 774763251095801167872 + // is : 774759489569697723777 + + assert(z_actual == z_expected, 'wrong number'); +} + +#[test] +#[available_gas(2000000000)] +fn test_reciprocal() { + // Test from polar coordiantes of a complex number + let a: complex64 = ComplexTrait::new( + FixedTrait::new(73786976294838206464, false), FixedTrait::new(774763251095801167872, false) + ); // 4 + 42i + + let z_actual = a.reciprocal(); + + let z_expected: complex64 = ComplexTrait::new( + FixedTrait::new(41453357469010228, false), FixedTrait::new(435260253424607397, true) + ); + assert(z_actual == z_expected, '0.002247191011 - 0.0235955056 i'); +} diff --git a/tests/operators/qlinear_concat_test.cairo b/tests/operators/qlinear_concat_test.cairo index ea2a982fc..585c5edc3 100644 --- a/tests/operators/qlinear_concat_test.cairo +++ b/tests/operators/qlinear_concat_test.cairo @@ -56,7 +56,7 @@ fn qlinear_concat_test() { let tensor1_zero_point = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); let tensor2_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); @@ -71,8 +71,10 @@ fn qlinear_concat_test() { FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); - let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); - + let actual_output = TensorTrait::qlinear_concat( + tensors, scales, zero_points, @y_scale, @y_zero_point, 0 + ); + assert((*actual_output.data[0]).into() == 3, '*result[0] == 3'); assert((*actual_output.data[1]).into() == 6, '*result[1] == 6'); assert((*actual_output.data[2]).into() == 9, '*result[2] == 9'); @@ -82,8 +84,7 @@ fn qlinear_concat_test() { assert((*actual_output.data[6]).into() == 22, '*result[6] == 22'); assert((*actual_output.data[7]).into() == 30, '*result[7] == 30'); } - - + #[test] #[available_gas(200000000000)] @@ -125,15 +126,18 @@ fn qlinear_concat_test_shape() { .span(), ); - let tensors = array![tensor1, tensor2, tensor3].span(); let tensor1_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); let tensor2_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(), + ); let tensor3_scale = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); @@ -142,10 +146,10 @@ fn qlinear_concat_test_shape() { let tensor1_zero_point = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); let tensor2_zero_point = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); let tensor3_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); @@ -160,13 +164,13 @@ fn qlinear_concat_test_shape() { FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); - let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + let actual_output = TensorTrait::qlinear_concat( + tensors, scales, zero_points, @y_scale, @y_zero_point, 0 + ); assert((*actual_output.shape[0]).into() == 6, '*result.shape[0] == 6'); assert((*actual_output.shape[1]).into() == 2, '*result.shape[1] == 2'); - } - #[test] @@ -201,16 +205,22 @@ fn qlinear_concat_example_doc() { let tensor1_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + ); let tensor2_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(), + ); let scales = array![tensor1_scale, tensor2_scale].span(); let tensor1_zero_point = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(), + ); let tensor2_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); @@ -219,14 +229,18 @@ fn qlinear_concat_example_doc() { let y_scale = TensorTrait::< FP16x16 - >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + >::new( + shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(), + ); let y_zero_point = TensorTrait::< FP16x16 >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); - let actual_output = TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); - + let actual_output = TensorTrait::qlinear_concat( + tensors, scales, zero_points, @y_scale, @y_zero_point, 0 + ); + assert((*actual_output.data[0]).into() == 1, '*result[0] == 1'); assert((*actual_output.data[1]).into() == 1, '*result[1] == 1'); assert((*actual_output.data[2]).into() == 1, '*result[2] == 1'); @@ -235,4 +249,4 @@ fn qlinear_concat_example_doc() { assert((*actual_output.data[5]).into() == 2, '*result[5] == 2'); assert((*actual_output.data[6]).into() == 2, '*result[4] == 2'); assert((*actual_output.data[7]).into() == 2, '*result[5] == 2'); -} \ No newline at end of file +} From 0b24badb6eeb8eea7a68a22f64509bf053c914ac Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 29 Nov 2023 10:22:36 +0100 Subject: [PATCH 143/160] Add tests --- nodegen/node/concat_from_sequence.py | 340 ++++++++++++++++++ .../tensor/math/concat_from_sequence.cairo | 6 +- tests/nodes.cairo | 15 + ...om_sequence_fp16x16_new_axis_default.cairo | 21 ++ .../input_0.cairo | 80 +++++ .../output_0.cairo | 43 +++ ...t_from_sequence_fp16x16_new_axis_one.cairo | 21 ++ .../input_0.cairo | 55 +++ .../output_0.cairo | 19 + ..._from_sequence_fp16x16_new_axis_zero.cairo | 21 ++ .../input_0.cairo | 70 ++++ .../output_0.cairo | 33 ++ ...rom_sequence_fp8x23_new_axis_default.cairo | 21 ++ .../input_0.cairo | 70 ++++ .../output_0.cairo | 33 ++ ...at_from_sequence_fp8x23_new_axis_one.cairo | 21 ++ .../input_0.cairo | 80 +++++ .../output_0.cairo | 44 +++ ...t_from_sequence_fp8x23_new_axis_zero.cairo | 21 ++ .../input_0.cairo | 80 +++++ .../output_0.cairo | 43 +++ ...t_from_sequence_i32_new_axis_default.cairo | 21 ++ .../input_0.cairo | 65 ++++ .../output_0.cairo | 28 ++ ...oncat_from_sequence_i32_new_axis_one.cairo | 21 ++ .../input_0.cairo | 65 ++++ .../output_0.cairo | 29 ++ ...ncat_from_sequence_i32_new_axis_zero.cairo | 21 ++ .../input_0.cairo | 60 ++++ .../output_0.cairo | 23 ++ ...at_from_sequence_i8_new_axis_default.cairo | 21 ++ .../input_0.cairo | 65 ++++ .../output_0.cairo | 28 ++ ...concat_from_sequence_i8_new_axis_one.cairo | 21 ++ .../input_0.cairo | 55 +++ .../output_0.cairo | 19 + ...oncat_from_sequence_i8_new_axis_zero.cairo | 21 ++ .../input_0.cairo | 80 +++++ .../output_0.cairo | 43 +++ ...t_from_sequence_u32_new_axis_default.cairo | 21 ++ .../input_0.cairo | 64 ++++ .../output_0.cairo | 27 ++ ...oncat_from_sequence_u32_new_axis_one.cairo | 21 ++ .../input_0.cairo | 64 ++++ .../output_0.cairo | 28 ++ ...ncat_from_sequence_u32_new_axis_zero.cairo | 21 ++ .../input_0.cairo | 79 ++++ .../output_0.cairo | 42 +++ 48 files changed, 2187 insertions(+), 3 deletions(-) create mode 100644 nodegen/node/concat_from_sequence.py create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_default.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_default/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_default/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_one.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_one/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_one/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_zero.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_default.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_default/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_default/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_one.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_one/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_one/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_zero.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_default.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_default/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_default/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_one.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_one/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_one/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_zero.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_zero/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i32_new_axis_zero/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_default.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_default/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_default/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_one.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_one/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_one/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_zero.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_zero/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_i8_new_axis_zero/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_default.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_default/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_default/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_one.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_one/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_one/output_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_zero.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_zero/input_0.cairo create mode 100644 tests/nodes/concat_from_sequence_u32_new_axis_zero/output_0.cairo diff --git a/nodegen/node/concat_from_sequence.py b/nodegen/node/concat_from_sequence.py new file mode 100644 index 000000000..4918785ea --- /dev/null +++ b/nodegen/node/concat_from_sequence.py @@ -0,0 +1,340 @@ +import numpy as np +from nodegen.node import RunAll +from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl + + +class Concat_from_sequence(RunAll): + + @staticmethod + def concat_from_sequence_u32(): + def new_axis_zero(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.U32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_u32_new_axis_zero" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0))", name) + + def new_axis_one(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(1) + + concatenated_tensor = np.stack(values_array, axis) + concatenated_tensor = Tensor(Dtype.U32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_u32_new_axis_one" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1))", name) + + def new_axis_default(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(0, 6, shape).astype(np.uint32) + tensor = Tensor(Dtype.U32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.U32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_u32_new_axis_default" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(()))", name) + + new_axis_zero() + new_axis_one() + new_axis_default() + + + @staticmethod + def concat_from_sequence_i32(): + def new_axis_zero(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.I32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i32_new_axis_zero" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0))", name) + + def new_axis_one(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(1) + + concatenated_tensor = np.stack(values_array, axis) + concatenated_tensor = Tensor(Dtype.I32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i32_new_axis_one" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1))", name) + + def new_axis_default(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int32) + tensor = Tensor(Dtype.I32, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.I32, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i32_new_axis_default" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(()))", name) + + new_axis_zero() + new_axis_one() + new_axis_default() + + + @staticmethod + def concat_from_sequence_i8(): + def new_axis_zero(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.I8, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i8_new_axis_zero" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0))", name) + + def new_axis_one(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(1) + + concatenated_tensor = np.stack(values_array, axis) + concatenated_tensor = Tensor(Dtype.I8, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i8_new_axis_one" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1))", name) + + def new_axis_default(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.int8) + tensor = Tensor(Dtype.I8, values.shape, values.flatten()) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.I8, concatenated_tensor.shape, concatenated_tensor.flatten()) + + name = "concat_from_sequence_i8_new_axis_default" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(()))", name) + + new_axis_zero() + new_axis_one() + new_axis_default() + + + @staticmethod + def concat_from_sequence_fp8x23(): + def new_axis_zero(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP8x23, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP8x23)) + + name = "concat_from_sequence_fp8x23_new_axis_zero" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0))", name) + + def new_axis_one(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(1) + + concatenated_tensor = np.stack(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP8x23, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP8x23)) + + name = "concat_from_sequence_fp8x23_new_axis_one" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1))", name) + + def new_axis_default(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP8x23, values.shape, to_fp(values.flatten(), FixedImpl.FP8x23)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP8x23, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP8x23)) + + name = "concat_from_sequence_fp8x23_new_axis_default" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(()))", name) + + new_axis_zero() + new_axis_one() + new_axis_default() + + + @staticmethod + def concat_from_sequence_fp16x16(): + def new_axis_zero(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP16x16, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP16x16)) + + name = "concat_from_sequence_fp16x16_new_axis_zero" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0))", name) + + def new_axis_one(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(1) + + concatenated_tensor = np.stack(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP16x16, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP16x16)) + + name = "concat_from_sequence_fp16x16_new_axis_one" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1))", name) + + def new_axis_default(): + sequence = [] + values_array = [] + shape = np.random.randint(1, 4, 2) + + for _ in range(5): + values = np.random.randint(-6, 6, shape).astype(np.float64) + tensor = Tensor(Dtype.FP16x16, values.shape, to_fp(values.flatten(), FixedImpl.FP16x16)) + sequence.append(tensor) + values_array.append(values) + + axis = np.int32(1) + new_axis = np.uint32(0) + + concatenated_tensor = np.concatenate(values_array, axis) + concatenated_tensor = Tensor(Dtype.FP16x16, concatenated_tensor.shape, to_fp(concatenated_tensor.flatten(), FixedImpl.FP16x16)) + + name = "concat_from_sequence_fp16x16_new_axis_default" + make_test([sequence], concatenated_tensor, "TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(()))", name) + + new_axis_zero() + new_axis_one() + new_axis_default() \ No newline at end of file diff --git a/src/operators/tensor/math/concat_from_sequence.cairo b/src/operators/tensor/math/concat_from_sequence.cairo index e8d838515..cad6a5c96 100644 --- a/src/operators/tensor/math/concat_from_sequence.cairo +++ b/src/operators/tensor/math/concat_from_sequence.cairo @@ -14,9 +14,9 @@ fn concat_from_sequence, impl TCopy: Copy Tensor { let new_axis: usize = match new_axis { - Option::Some(p) => { - assert(p == 0 || p == 1, 'new_axis must be 0 or 1'); - p + Option::Some(val) => { + assert(val == 0 || val == 1, 'new_axis must be 0 or 1'); + val }, Option::None(_) => 0 }; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 5d5fc5536..3fdc5f656 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -763,3 +763,18 @@ mod sequence_insert_fp8x23; mod sequence_insert_i32; mod sequence_insert_i8; mod sequence_insert_u32; +mod concat_from_sequence_fp8x23_new_axis_zero; +mod concat_from_sequence_fp8x23_new_axis_one; +mod concat_from_sequence_fp8x23_new_axis_default; +mod concat_from_sequence_fp16x16_new_axis_zero; +mod concat_from_sequence_fp16x16_new_axis_one; +mod concat_from_sequence_fp16x16_new_axis_default; +mod concat_from_sequence_i32_new_axis_zero; +mod concat_from_sequence_i32_new_axis_one; +mod concat_from_sequence_i32_new_axis_default; +mod concat_from_sequence_i8_new_axis_zero; +mod concat_from_sequence_i8_new_axis_one; +mod concat_from_sequence_i8_new_axis_default; +mod concat_from_sequence_u32_new_axis_zero; +mod concat_from_sequence_u32_new_axis_one; +mod concat_from_sequence_u32_new_axis_default; diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_default.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default.cairo new file mode 100644 index 000000000..073f4e1ad --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp16x16_new_axis_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/input_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/input_0.cairo new file mode 100644 index 000000000..b1738ccfb --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/output_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/output_0.cairo new file mode 100644 index 000000000..261590303 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_default/output_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(15); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_one.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one.cairo new file mode 100644 index 000000000..7f96b8a2b --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp16x16_new_axis_one() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/input_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/input_0.cairo new file mode 100644 index 000000000..3c307d0f5 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/input_0.cairo @@ -0,0 +1,55 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 196608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/output_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/output_0.cairo new file mode 100644 index 000000000..a750d97ad --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_one/output_0.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(5); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero.cairo new file mode 100644 index 000000000..faa5c7c32 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16TensorPartialEq; +use orion::operators::tensor::FP16x16Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp16x16_new_axis_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/input_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/input_0.cairo new file mode 100644 index 000000000..4c313e272 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/output_0.cairo b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/output_0.cairo new file mode 100644 index 000000000..c4cfbd234 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp16x16_new_axis_zero/output_0.cairo @@ -0,0 +1,33 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP16x16Tensor; +use orion::numbers::{FixedTrait, FP16x16}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(10); + + let mut data = ArrayTrait::new(); + data.append(FP16x16 { mag: 262144, sign: true }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 262144, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 393216, sign: true }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 196608, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 327680, sign: false }); + data.append(FP16x16 { mag: 327680, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_default.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default.cairo new file mode 100644 index 000000000..780bfff55 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp8x23_new_axis_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/input_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/input_0.cairo new file mode 100644 index 000000000..ffb2a84e6 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/input_0.cairo @@ -0,0 +1,70 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + 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: 33554432, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/output_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/output_0.cairo new file mode 100644 index 000000000..168cc8ac2 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_default/output_0.cairo @@ -0,0 +1,33 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(10); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_one.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one.cairo new file mode 100644 index 000000000..281abbd99 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp8x23_new_axis_one() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/input_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/input_0.cairo new file mode 100644 index 000000000..d4efa62bd --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/output_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/output_0.cairo new file mode 100644 index 000000000..fb7f7be12 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_one/output_0.cairo @@ -0,0 +1,44 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(5); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 41943040, 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: 0, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero.cairo new file mode 100644 index 000000000..bce4effd6 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; +use orion::operators::tensor::FP8x23Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_fp8x23_new_axis_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/input_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/input_0.cairo new file mode 100644 index 000000000..09afee204 --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/output_0.cairo b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/output_0.cairo new file mode 100644 index 000000000..778edfeea --- /dev/null +++ b/tests/nodes/concat_from_sequence_fp8x23_new_axis_zero/output_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23Tensor; +use orion::numbers::{FixedTrait, FP8x23}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(2); + shape.append(15); + + let mut data = ArrayTrait::new(); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 41943040, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 33554432, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 50331648, sign: true }); + data.append(FP8x23 { mag: 16777216, 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: 50331648, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_default.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_default.cairo new file mode 100644 index 000000000..aab6b6728 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_default.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i32_new_axis_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_default/input_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_default/input_0.cairo new file mode 100644 index 000000000..10f61f58b --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_default/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 5, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_default/output_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_default/output_0.cairo new file mode 100644 index 000000000..84f58e4cc --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_default/output_0.cairo @@ -0,0 +1,28 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(5); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 5, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 1, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_one.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_one.cairo new file mode 100644 index 000000000..68de76897 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_one.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i32_new_axis_one() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_one/input_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_one/input_0.cairo new file mode 100644 index 000000000..cf85bb16a --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_one/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 3, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 1, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_one/output_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_one/output_0.cairo new file mode 100644 index 000000000..9850fdd78 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_one/output_0.cairo @@ -0,0 +1,29 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(5); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 5, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_zero.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_zero.cairo new file mode 100644 index 000000000..db7eb5234 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_zero.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::operators::tensor::I32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i32_new_axis_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_zero/input_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_zero/input_0.cairo new file mode 100644 index 000000000..900e8291e --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_zero/input_0.cairo @@ -0,0 +1,60 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i32_new_axis_zero/output_0.cairo b/tests/nodes/concat_from_sequence_i32_new_axis_zero/output_0.cairo new file mode 100644 index 000000000..a2fb2f76f --- /dev/null +++ b/tests/nodes/concat_from_sequence_i32_new_axis_zero/output_0.cairo @@ -0,0 +1,23 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32Tensor; +use orion::numbers::{IntegerTrait, i32}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(10); + + let mut data = ArrayTrait::new(); + data.append(i32 { mag: 4, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 3, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 6, sign: true }); + data.append(i32 { mag: 2, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_default.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_default.cairo new file mode 100644 index 000000000..7dadc7eb0 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_default.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i8_new_axis_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_default/input_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_default/input_0.cairo new file mode 100644 index 000000000..a5b98acc0 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_default/input_0.cairo @@ -0,0 +1,65 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_default/output_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_default/output_0.cairo new file mode 100644 index 000000000..e38284c2b --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_default/output_0.cairo @@ -0,0 +1,28 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(15); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 5, sign: true }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_one.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_one.cairo new file mode 100644 index 000000000..5f9840525 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_one.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i8_new_axis_one() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_one/input_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_one/input_0.cairo new file mode 100644 index 000000000..e2efb065f --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_one/input_0.cairo @@ -0,0 +1,55 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_one/output_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_one/output_0.cairo new file mode 100644 index 000000000..ec6ba48b6 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_one/output_0.cairo @@ -0,0 +1,19 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(5); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 0, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_zero.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_zero.cairo new file mode 100644 index 000000000..8280ec8b1 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_zero.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::I8Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_i8_new_axis_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_zero/input_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_zero/input_0.cairo new file mode 100644 index 000000000..b7b745cf4 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_zero/input_0.cairo @@ -0,0 +1,80 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 4, sign: true }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 3, sign: false }); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_i8_new_axis_zero/output_0.cairo b/tests/nodes/concat_from_sequence_i8_new_axis_zero/output_0.cairo new file mode 100644 index 000000000..c0642cb46 --- /dev/null +++ b/tests/nodes/concat_from_sequence_i8_new_axis_zero/output_0.cairo @@ -0,0 +1,43 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I8Tensor; +use orion::numbers::{IntegerTrait, i8}; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(10); + + let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 5, sign: false }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: false }); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 5, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 4, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 6, sign: true }); + data.append(i8 { mag: 4, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 3, sign: false }); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_default.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_default.cairo new file mode 100644 index 000000000..c14c74210 --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_default.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_u32_new_axis_default() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::None(())); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_default/input_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_default/input_0.cairo new file mode 100644 index 000000000..44ce910ce --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_default/input_0.cairo @@ -0,0 +1,64 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(2); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(4); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(0); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(4); + data.append(2); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(1); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(1); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_default/output_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_default/output_0.cairo new file mode 100644 index 000000000..5b4cb64ab --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_default/output_0.cairo @@ -0,0 +1,27 @@ +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(5); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(0); + data.append(0); + data.append(4); + data.append(1); + data.append(2); + data.append(4); + data.append(0); + data.append(2); + data.append(1); + data.append(1); + data.append(0); + data.append(3); + data.append(3); + data.append(4); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_one.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_one.cairo new file mode 100644 index 000000000..daf7a36d4 --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_one.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_u32_new_axis_one() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(1)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_one/input_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_one/input_0.cairo new file mode 100644 index 000000000..d712408ad --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_one/input_0.cairo @@ -0,0 +1,64 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(5); + data.append(2); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(2); + data.append(3); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(1); + data.append(0); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_one/output_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_one/output_0.cairo new file mode 100644 index 000000000..56c2eec1b --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_one/output_0.cairo @@ -0,0 +1,28 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn output_0() -> Tensor { + let mut shape = ArrayTrait::::new(); + shape.append(1); + shape.append(5); + shape.append(3); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(1); + data.append(5); + data.append(5); + data.append(2); + data.append(5); + data.append(0); + data.append(1); + data.append(4); + data.append(0); + data.append(2); + data.append(3); + data.append(2); + data.append(1); + data.append(0); + TensorTrait::new(shape.span(), data.span()) +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_zero.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_zero.cairo new file mode 100644 index 000000000..a1ba9dee2 --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_zero.cairo @@ -0,0 +1,21 @@ +mod input_0; +mod output_0; + + +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::U32TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::numbers::signed_integer::{integer_trait::IntegerTrait, i32::i32}; + +#[test] +#[available_gas(2000000000)] +fn test_concat_from_sequence_u32_new_axis_zero() { + let input_0 = input_0::input_0(); + let z = output_0::output_0(); + + let y = TensorTrait::concat_from_sequence(input_0, IntegerTrait::::new(1, false), Option::Some(0)); + + assert_eq(y, z); +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_zero/input_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_zero/input_0.cairo new file mode 100644 index 000000000..ff84c60db --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_zero/input_0.cairo @@ -0,0 +1,79 @@ +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::U32Tensor; + +fn input_0() -> Array> { + let mut sequence = ArrayTrait::new(); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(2); + data.append(3); + data.append(3); + data.append(2); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(0); + data.append(2); + data.append(5); + data.append(1); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(2); + data.append(0); + data.append(3); + data.append(2); + data.append(5); + data.append(4); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(0); + data.append(5); + data.append(4); + data.append(0); + data.append(4); + data.append(5); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + let mut shape = ArrayTrait::::new(); + shape.append(3); + shape.append(2); + + let mut data = ArrayTrait::new(); + data.append(1); + data.append(3); + data.append(2); + data.append(1); + data.append(3); + data.append(1); + + sequence.append(TensorTrait::new(shape.span(), data.span())); + + sequence +} diff --git a/tests/nodes/concat_from_sequence_u32_new_axis_zero/output_0.cairo b/tests/nodes/concat_from_sequence_u32_new_axis_zero/output_0.cairo new file mode 100644 index 000000000..0d8ab7519 --- /dev/null +++ b/tests/nodes/concat_from_sequence_u32_new_axis_zero/output_0.cairo @@ -0,0 +1,42 @@ +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(10); + + let mut data = ArrayTrait::new(); + data.append(3); + data.append(2); + data.append(1); + data.append(0); + data.append(2); + data.append(0); + data.append(0); + data.append(5); + data.append(1); + data.append(3); + data.append(3); + data.append(3); + data.append(2); + data.append(5); + data.append(3); + data.append(2); + data.append(4); + data.append(0); + data.append(2); + data.append(1); + data.append(2); + data.append(5); + data.append(1); + data.append(1); + data.append(5); + data.append(4); + data.append(4); + data.append(5); + data.append(3); + data.append(1); + TensorTrait::new(shape.span(), data.span()) +} From 7922943c938e9b7638f7ac8d819de37f3badd615 Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 29 Nov 2023 11:42:11 +0100 Subject: [PATCH 144/160] Add docs --- docs/SUMMARY.md | 1 + docs/framework/compatibility.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../tensor/tensor.concat_from_sequence.md | 59 ++++++++++++++++++ src/operators/tensor/core.cairo | 61 +++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.concat_from_sequence.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 804d4dbb9..28ac6e510 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -114,6 +114,7 @@ * [tensor.pow](framework/operators/tensor/tensor.pow.md) * [tensor.sequence\_erase](framework/operators/tensor/tensor.sequence\_erase.md) * [tensor.sequence\_insert](framework/operators/tensor/tensor.sequence\_insert.md) + * [tensor.concat\_from\_sequence](framework/operators/tensor/tensor.concat\_from\_sequence.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 f82c4408a..137bc2293 100644 --- a/docs/framework/compatibility.md +++ b/docs/framework/compatibility.md @@ -93,5 +93,6 @@ You can see below the list of current supported ONNX Operators: | [ReduceL2](operators/tensor/tensor.reduce\_l2.md) | :white\_check\_mark: | | [SequenceErase](operators/tensor/tensor.sequence\_erase.md) | :white\_check\_mark: | | [SequenceInsert](operators/tensor/tensor.sequence\_insert.md) | :white\_check\_mark: | +| [ConcatFromSequence](operators/tensor/tensor.concat\_from\_sequence.md) | :white\_check\_mark: | Current Operators support: **82/156 (53%)** diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 7a0133369..500f59a91 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -114,6 +114,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.binarizer`](tensor.binarizer.md) | Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. | | [`tensor.array_feature_extractor`](tensor.array\_feature\_extractor.md) | Selects elements of the input tensor based on the indices passed applied to the last tensor axis. | | [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | +| [`tensor.concat_from_sequence`](tensor.concat\_from\_sequence.md) | Concatenate a sequence of tensors into a single tensor. | ## Arithmetic Operations diff --git a/docs/framework/operators/tensor/tensor.concat_from_sequence.md b/docs/framework/operators/tensor/tensor.concat_from_sequence.md new file mode 100644 index 000000000..846322b90 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.concat_from_sequence.md @@ -0,0 +1,59 @@ +# tensor.concat_from_sequence + +```rust + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; +``` + +Concatenate a sequence of tensors into a single tensor. + +## Args + +* `sequence`(`Array>`) - The input sequence. +* `axis`(`i32`) - Axis to concat on. +* `new_axis`(`Option`) - Optionally added new axis. + +## Panics + +* Panics if new_axis not 0 or 1 (if value provided). +* Panics if axis not in accepted ranges. +* Panics if sequence length is not greater than 1. + +## Returns + +A new `Tensor` concatenated tensor from the input tensor sequence. + +## Example + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn concat_example() -> Tensor { + let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + + let mut sequence = ArrayTrait::new(); + sequence.append(tensor1); + sequence.append(tensor2); + + let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 0, new_axis: Option::Some(0)); + return result; +} +>>> [[0. 1.] + [2. 3.], + [0. 1.] + [2. 3.]] + + result.shape +>>> (4, 2) + + let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 1, new_axis: Option::Some(0)); + return result; +} +>>> [[0. 1., 0., 1.] + [2. 3., 2., 3.]] + + result.shape +>>> (2, 4 ) +``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 236736b3f..31b2ab79b 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -108,6 +108,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde { /// # tensor.new @@ -4416,6 +4417,66 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; + /// # tensor.concat_from_sequence + /// + /// ```rust + /// fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; + /// ``` + /// + /// Concatenate a sequence of tensors into a single tensor. + /// + /// ## Args + /// + /// * `sequence`(`Array>`) - The input sequence. + /// * `axis`(`i32`) - Axis to concat on. + /// * `new_axis`(`Option`) - Optionally added new axis. + /// + /// ## Panics + /// + /// * Panics if new_axis not 0 or 1 (if value provided). + /// * Panics if axis not in accepted ranges. + /// * Panics if sequence length is not greater than 1. + /// + /// ## Returns + /// + /// A new `Tensor` concatenated tensor from the input tensor sequence. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn concat_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// + /// let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 0, new_axis: Option::Some(0)); + /// return result; + /// } + /// >>> [[0. 1.] + /// [2. 3.], + /// [0. 1.] + /// [2. 3.]] + /// + /// result.shape + /// >>> (4, 2) + /// + /// let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 1, new_axis: Option::Some(0)); + /// return result; + /// } + /// >>> [[0. 1., 0., 1.] + /// [2. 3., 2., 3.]] + /// + /// result.shape + /// >>> (2, 4 ) + /// ``` + /// fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; } From 2243fda9b04de2ff7294adcb72755e349ea78d3e Mon Sep 17 00:00:00 2001 From: Daniel Voronov Date: Wed, 29 Nov 2023 12:42:41 +0100 Subject: [PATCH 145/160] Refactor operator --- .../tensor/math/concat_from_sequence.cairo | 217 ++++-------------- 1 file changed, 48 insertions(+), 169 deletions(-) diff --git a/src/operators/tensor/math/concat_from_sequence.cairo b/src/operators/tensor/math/concat_from_sequence.cairo index cad6a5c96..598b139c3 100644 --- a/src/operators/tensor/math/concat_from_sequence.cairo +++ b/src/operators/tensor/math/concat_from_sequence.cairo @@ -7,6 +7,7 @@ use core::traits::Into; use orion::operators::tensor::helpers::replace_index; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::numbers::signed_integer::i32::i32; +use orion::operators::tensor::math::concat::concat; fn concat_from_sequence, impl TCopy: Copy, impl TDrop: Drop,>( @@ -23,40 +24,59 @@ fn concat_from_sequence, impl TCopy: Copy, impl TCopy: Copy, impl TDrop: Drop,>( + sequence: Array>, axis: i32, r: usize +) -> Tensor { let axis_is_negative: bool = axis.sign; let mut axis_value: u32 = axis.mag; - - if new_axis == 0 { - /// assert in range [-r, r - 1] - assert((axis_is_negative == false && axis_value <= r - 1) || (axis_is_negative == true && axis_value <= r), 'Out of bounds for dimension'); - if axis_is_negative == true { + + /// assert in range [-r, r - 1] + assert((axis_is_negative == false && axis_value <= r - 1) || (axis_is_negative == true && axis_value <= r), 'Out of bounds for dimension'); + + if axis_is_negative == true { + axis_value = r - axis_value + } + concat(sequence.span(), axis_value) +} + + +fn concat_with_new_axis, impl TCopy: Copy, impl TDrop: Drop,>( + sequence: Array>, axis: i32, r: usize +) -> Tensor { + let axis_is_negative: bool = axis.sign; + let mut axis_value: u32 = axis.mag; + + /// assert in range [-r - 1, r] + assert((axis_is_negative == false && axis_value <= r) || (axis_is_negative == true && axis_value <= r + 1), 'Out of bounds for dimension'); + + if axis_is_negative == true { + if axis_value > r { + axis_value = 0 + } else { axis_value = r - axis_value } - concat(sequence.span(), axis_value) - } else { - /// assert in range [-r - 1, r] - assert((axis_is_negative == false && axis_value <= r) || (axis_is_negative == true && axis_value <= r + 1), 'Out of bounds for dimension'); - if axis_is_negative == true { - if axis_value > r { - axis_value = 0 - } else { - axis_value = r - axis_value - } - } - let mut input_sequence_copy = sequence; - let mut reshaped_sequence = ArrayTrait::>::new(); - loop { - match input_sequence_copy.pop_front() { - Option::Some(input_sequence_value) => { - let mut reshaped_tensor = add_new_dimension(input_sequence_value, axis_value); - reshaped_sequence.append(reshaped_tensor); - }, - Option::None(_) => { break; } - }; - }; - concat(reshaped_sequence.span(), axis_value) } + let mut input_sequence_copy = sequence; + let mut reshaped_sequence = ArrayTrait::>::new(); + loop { + match input_sequence_copy.pop_front() { + Option::Some(input_sequence_value) => { + let mut reshaped_tensor = add_new_dimension(input_sequence_value, axis_value); + reshaped_sequence.append(reshaped_tensor); + }, + Option::None(_) => { break; } + }; + }; + concat(reshaped_sequence.span(), axis_value) } @@ -83,144 +103,3 @@ fn add_new_dimension, impl TCopy: Copy, } TensorTrait::::new(new_tensor_shape.span(), tensor.data) } - - -fn concat, impl TCopy: Copy, impl TDrop: Drop,>( - mut tensors: Span>, axis: usize -) -> Tensor { - assert(tensors.len() >= 2, 'Input tensors must be > 1'); - let base_tensor = *tensors.at(0); - let base_shape = base_tensor.shape; - let dimension = base_shape.len(); - assert(dimension > axis, 'Out of bounds for dimension'); - - // Validate shapes of tensors - validate_shapes(tensors, base_shape, axis); - - // Calculate output size - let output_size = compute_output_size(base_shape, tensors, axis); - - // Concatenate tensor data - let output_data: Array = concatenate_data(tensors, axis, base_shape); - - TensorTrait::::new(output_size.span(), output_data.span()) -} - -fn validate_shapes(mut tensors: Span>, mut base_shape: Span, axis: usize) { - loop { - match tensors.pop_front() { - Option::Some(tensor) => { - assert(base_shape.len() == (*tensor.shape).len(), 'Dimension not the same'); - - let mut axis_index = 0; - let mut tensor_shape = *tensor.shape; - let mut base_shape_copy = base_shape; - loop { - match tensor_shape.pop_front() { - Option::Some(tensor_shape_i) => { - let base_shape_i = base_shape_copy.pop_front().unwrap(); - if axis_index != axis { - assert(base_shape_i == tensor_shape_i, 'Shape is not the same'); - } - axis_index += 1; - }, - Option::None(_) => { break; } - }; - }; - }, - Option::None(_) => { break; } - }; - }; -} - -fn compute_output_size( - mut base_shape: Span, mut tensors: Span>, axis: usize -) -> Array { - let mut output_size = ArrayTrait::::new(); - - let mut axis_size = 0; - loop { - match tensors.pop_front() { - Option::Some(tensor) => { axis_size += *(*tensor.shape).at(axis); }, - Option::None(_) => { break; } - }; - }; - - let mut shape_index = 0; - loop { - match base_shape.pop_front() { - Option::Some(item) => { - if shape_index == axis { - output_size.append(axis_size); - } else { - output_size.append(*item); - } - shape_index += 1; - }, - Option::None(_) => { break; } - }; - }; - - output_size -} - -fn concatenate_data, impl TDrop: Drop,>( - mut tensors: Span>, axis: usize, base_shape: Span -) -> Array { - let mut output_data = ArrayTrait::::new(); - - let total_loops = product_upto(base_shape, axis); - - let mut outer_loop_index = 0; - loop { - if outer_loop_index == total_loops { - break; - } - - let mut tensors_copy = tensors; - loop { - match tensors_copy.pop_front() { - Option::Some(tensor) => { - let slice_len = (*tensor.data).len() / total_loops; - - let mut inner_index = 0; - loop { - if inner_index == slice_len { - break; - } - - output_data - .append(*(*tensor.data).at(slice_len * outer_loop_index + inner_index)); - inner_index += 1; - }; - }, - Option::None(_) => { break; } - }; - }; - - outer_loop_index += 1; - }; - - output_data -} - -fn product_upto(mut shape: Span, upto: usize) -> usize { - let mut total = 1; - let mut index = 0; - - loop { - match shape.pop_front() { - Option::Some(val) => { - if index == upto { - break; - } - - total *= *val; - index += 1; - }, - Option::None(_) => { break; } - }; - }; - - total -} From 741428a845748243e2227a92c43973034d20b420 Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Wed, 29 Nov 2023 22:33:12 +0430 Subject: [PATCH 146/160] adding documentation of reduce prod --- docs/CHANGELOG.md | 5 +++ docs/SUMMARY.md | 1 + docs/framework/operators/tensor/README.md | 1 + .../operators/tensor/tensor.reduce_prod.md | 39 +++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 docs/framework/operators/tensor/tensor.reduce_prod.md diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 68fede545..fc69cc3d5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2023-11-27 + +## Added +- Reduce Prod Operator + ## [Unreleased] - 2023-11-06 ## Added diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1ddffa843..0e789ef21 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -100,6 +100,7 @@ * [tensor.reduce\_sum\_square](framework/operators/tensor/tensor.reduce\_sum\_square.md) * [tensor.reduce\_l2](framework/operators/tensor/tensor.reduce\_l2.md) * [tensor.reduce\_l1](framework/operators/tensor/tensor.reduce\_l1.md) + * [tensor.greater](framework/operators/tensor/tensor.reduce_prod.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/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index d793cc692..300b3230e 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -56,6 +56,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.min`](tensor.min.md) | Returns the minimum value in the tensor. | | [`tensor.max`](tensor.max.md) | Returns the maximum value in the tensor. | | [`tensor.reduce_sum`](tensor.reduce\_sum.md) | Reduces a tensor by summing its elements along a specified axis. | +| [`tensor.reduce_prod`](tensor.reduce\_prod.md) | Reduces a tensor to its products along specified axis. | | [`tensor.argmax`](tensor.argmax.md) | Returns the index of the maximum value along the specified axis. | | [`tensor.argmin`](tensor.argmin.md) | Returns the index of the minimum value along the specified axis. | | [`tensor.cumsum`](tensor.cumsum.md) | Performs cumulative sum of the input elements along the given axis. | diff --git a/docs/framework/operators/tensor/tensor.reduce_prod.md b/docs/framework/operators/tensor/tensor.reduce_prod.md new file mode 100644 index 000000000..35117d602 --- /dev/null +++ b/docs/framework/operators/tensor/tensor.reduce_prod.md @@ -0,0 +1,39 @@ +## tensor.reduce_prod + +```rust + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; +``` + +Reduces a tensor by multiplying its elements along a specified axis. + +## Args + +* `self`(`@Tensor`) - The input tensor. +* `axis`(`usize`) - The dimension to reduce. +* `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + +## Panics + +* Panics if axis is not in the range of the input tensor's dimensions. + +## Returns + +A new `Tensor` instance with the specified axis reduced by multiplying its elements. + +## Examples + +```rust +use array::{ArrayTrait, SpanTrait}; + +use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + +fn reduce_prod_example() -> Tensor { + let tensor = TensorTrait::::new( + shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + ); + + // We can call `reduce_prod` function as follows. + return tensor.reduce_prod(axis: 0, keepdims: false); +} +>>> [[0,5],[12,21]] +``` From 014b396e47ad7026f5509701e5790af07500b43c Mon Sep 17 00:00:00 2001 From: Mahmoud Mohajer Date: Wed, 29 Nov 2023 23:19:54 +0430 Subject: [PATCH 147/160] fixed duplication of one item --- src/operators/tensor/math.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/operators/tensor/math.cairo b/src/operators/tensor/math.cairo index 091a25a18..e26a2b1c1 100644 --- a/src/operators/tensor/math.cairo +++ b/src/operators/tensor/math.cairo @@ -45,7 +45,6 @@ mod reduce_l2; mod reduce_l1; mod reduce_sum_square; mod bitwise_and; -mod bitwise_and; mod sequence_length; mod sequence_at; mod reduce_min; From 0cf12d399cf19b11b437093a1e11d66b24b0d46e Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 12:36:42 +0200 Subject: [PATCH 148/160] remove duplicated sequence_construct --- src/operators/tensor/implementations/tensor_fp32x32.cairo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index f04426593..35b842d46 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -412,10 +412,6 @@ impl FP32x32Tensor of TensorTrait { ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) } - - fn sequence_construct(tensors: Array>) -> Array> { - math::sequence_construct::sequence_construct(tensors) - } fn sequence_length(self: Array>) -> Tensor { math::sequence_length::sequence_length(self) From 93a7b5c8b1b8d7d94beb82389dbaef7293a269da Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 13:47:08 +0200 Subject: [PATCH 149/160] add reduce_prod in trait --- src/operators/tensor/core.cairo | 108 ++++++++++++-------------------- 1 file changed, 41 insertions(+), 67 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index a81acd013..250954954 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3913,13 +3913,6 @@ trait TensorTrait { /// ``` /// fn constant_of_shape(shape: Span, value: T) -> Tensor; - /// ## tensor.reduce_prod - /// - /// ```rust - /// fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; - /// ``` - /// - /// Reduces a tensor by multiplying its elements along a specified axis. /// # tensor.binarizer /// /// ```rust @@ -4020,66 +4013,6 @@ trait TensorTrait { /// ``` /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; - /// ## tensor.reduce_mean - /// - /// ```rust - /// fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; - /// ``` - /// - /// Computes the mean of the input tensor's elements along the provided axes. - /// - /// ## Args - /// - /// * `self`(`@Tensor`) - The input tensor. - /// * `axis`(`usize`) - The dimension to reduce. - /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. - /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. - /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. - /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. - /// - /// ## Panics - /// - /// * Panics if axis is not in the range of the input tensor's dimensions. - /// - /// ## Returns - /// - /// A new `Tensor` instance with the specified axis reduced by multiplying its elements. - /// A new `Tensor` instance with the specified axes reduced by meaning its elements. - /// - /// ## Examples - /// - /// ```rust - /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; - /// - /// fn reduce_prod_example() -> Tensor { - /// fn reduce_mean_example() -> Tensor { - /// let tensor = TensorTrait::::new( - /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), - /// ); - /// - /// // We can call `reduce_prod` function as follows. - /// return tensor.reduce_prod(axis: 0, keepdims: false); - /// } - /// >>> [[0,5],[12,21]] - /// ``` - /// - fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; - /// // We can call `reduce_mean` function as follows. - /// return tensor.reduce_mean(axes: array![1].span(), - /// keepdims: Option::None(()), - /// noop_with_empty_axes: Option::None(())); - /// } - /// >>> [[1,2],[5,6]] - /// ``` - /// - fn reduce_mean( - self: @Tensor, - axes: Option>, - keepdims: Option, - noop_with_empty_axes: Option - ) -> Tensor; /// # tensor.sequence_empty /// /// ```rust @@ -4514,6 +4447,47 @@ trait TensorTrait { /// ``` /// fn sequence_length(self: Array>) -> Tensor; + /// ## tensor.reduce_prod + /// + /// ```rust + /// fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Reduces a tensor by multiplying its elements along a specified axis. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by multiplying its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_prod_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_prod` function as follows. + /// return tensor.reduce_prod(axis: 0, keepdims: false); + /// } + /// >>> [[0,5],[12,21]] + /// ``` + /// + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; } /// Cf: TensorTrait::new docstring From 808bcb972ce6953c7fdae972ddc34095cae9f193 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 13:50:10 +0200 Subject: [PATCH 150/160] Update core.cairo --- src/operators/tensor/core.cairo | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 0fb3dcdc5..ae708e6f8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -4281,6 +4281,55 @@ trait TensorTrait { /// ``` /// fn sequence_construct(tensors: Array>) -> Array>; + /// ## tensor.reduce_mean + /// + /// ```rust + /// fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the mean of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by meaning its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_mean_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_mean(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[1,2],[5,6]] + /// ``` + /// + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; /// ## tensor.reduce_min /// /// ```rust @@ -4316,7 +4365,7 @@ trait TensorTrait { /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), /// ); /// - /// // We can call `reduce_mean` function as follows. + /// // We can call `reduce_min` function as follows. /// return tensor.reduce_min(axes: array![1].span(), /// keepdims: Option::None(()), /// noop_with_empty_axes: Option::None(())); @@ -4635,6 +4684,7 @@ trait TensorTrait { /// ``` /// fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ## tensor.is_inf /// /// ```rust From dfe51bac303d48c900f3dfb1b63e00ad5e64c2bd Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 13:55:14 +0200 Subject: [PATCH 151/160] fix doc --- docs/framework/operators/tensor/README.md | 2 +- .../tensor/tensor.array_feature_extractor.md | 1 - docs/framework/operators/tensor/tensor.is_inf.md | 3 +-- docs/framework/operators/tensor/tensor.reduce_min.md | 2 +- src/operators/tensor/core.cairo | 11 +++++++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 8127175e5..92a3f8acc 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -106,7 +106,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.reduce_l2`](tensor.reduce\_l2.md) | Computes the L2 norm of the input tensor's elements along the provided axes. | | [`tensor.gather_elements`](tensor.gather\_elements.md) | GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. | | [`tensor.reduce_min`](tensor.reduce\_min.md) | Computes the min of the input tensor's elements along the provided axes. | -| [`tensor.sequence_construct`](tensor.sequence\_construct.md) | Constructs a tensor sequence containing the input tensors. | +| [`tensor.sequence_empty`](tensor.sequence\_empty.md) | Returns an empty tensor sequence. | | [`tensor.sequence_length`](tensor.sequence\_length.md) | Returns the length of the input sequence. | | [`tensor.sequence_insert`](tensor.sequence\_insert.md) | Insert a tensor into a sequence. | | [`tensor.sequence_at`](tensor.sequence\_at.md) | Outputs the tensor at the specified position in the input sequence. | diff --git a/docs/framework/operators/tensor/tensor.array_feature_extractor.md b/docs/framework/operators/tensor/tensor.array_feature_extractor.md index a852239d4..f06bdaf00 100644 --- a/docs/framework/operators/tensor/tensor.array_feature_extractor.md +++ b/docs/framework/operators/tensor/tensor.array_feature_extractor.md @@ -23,7 +23,6 @@ A new `Tensor` of the same shape as the input tensor with selected elements b ```rust use array::{ArrayTrait, SpanTrait}; - use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; use orion::numbers::{i32, IntegerTrait}; diff --git a/docs/framework/operators/tensor/tensor.is_inf.md b/docs/framework/operators/tensor/tensor.is_inf.md index d787a2043..e77a5fb61 100644 --- a/docs/framework/operators/tensor/tensor.is_inf.md +++ b/docs/framework/operators/tensor/tensor.is_inf.md @@ -20,8 +20,7 @@ A new `Tensor` instance with entries set to true iff the input tensors cor ## Examples ```rust -use array::{ArrayTrait, SpanTrait}; - +use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, U32Tensor}; fn is_inf_example() -> Tensor { diff --git a/docs/framework/operators/tensor/tensor.reduce_min.md b/docs/framework/operators/tensor/tensor.reduce_min.md index 611324be3..eb416b7f7 100644 --- a/docs/framework/operators/tensor/tensor.reduce_min.md +++ b/docs/framework/operators/tensor/tensor.reduce_min.md @@ -33,7 +33,7 @@ fn reduce_min_example() -> Tensor { shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), ); - // We can call `reduce_mean` function as follows. + // We can call `reduce_min` function as follows. return tensor.reduce_min(axes: array![1].span(), keepdims: Option::None(()), noop_with_empty_axes: Option::None(())); diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index ae708e6f8..16e10c2a8 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3745,7 +3745,7 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn xor_example() -> Tensor { + /// 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(), /// ); @@ -3837,7 +3837,7 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn and_example() -> Tensor { + /// fn xor_example() -> Tensor { /// let tensor_1 = TensorTrait::::new( /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), /// ); @@ -4130,6 +4130,11 @@ trait TensorTrait { /// ## Returns /// /// A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; /// use orion::numbers::{i32, IntegerTrait}; /// @@ -4706,6 +4711,8 @@ trait TensorTrait { /// /// ## Examples /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; /// use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, U32Tensor}; /// /// fn is_inf_example() -> Tensor { From fbf0bd360995ee4e309e8ef2740bfdacd263fefe Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:58:42 +0000 Subject: [PATCH 152/160] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3631dc7cc..9323e6798 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # Orion: An Open-source Framework for Validity and ZK ML ✨ -[![All Contributors](https://img.shields.io/badge/all_contributors-22-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-) Orion is an open-source, community-driven framework dedicated to Provable Machine Learning. It provides essential components and a new ONNX runtime for building verifiable Machine Learning models using [STARKs](https://starkware.co/stark/). @@ -99,6 +99,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Ephraim Chukwu
Ephraim Chukwu

💻 Bal7hazar
Bal7hazar

🐛 Tony Stark
Tony Stark

📖 + Mahmoud Mohajer
Mahmoud Mohajer

💻 From 113117f1dd03ec788ccf55f7d7c279b413c282d5 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:58:43 +0000 Subject: [PATCH 153/160] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b282fc04..6c196ff0f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -224,6 +224,15 @@ "contributions": [ "doc" ] + }, + { + "login": "MahmoudMohajer", + "name": "Mahmoud Mohajer", + "avatar_url": "https://avatars.githubusercontent.com/u/89094323?v=4", + "profile": "https://medium.com/@mohajermahmoud3", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, From 72d31a03295dd631b95d4e22e4e96a1e414bbd1b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 14:14:56 +0200 Subject: [PATCH 154/160] Update core.cairo --- src/operators/tensor/core.cairo | 1514 +++++++++++++++++++++++++++---- 1 file changed, 1334 insertions(+), 180 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 931ea04a0..553f5e49a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -52,6 +52,7 @@ impl TensorSerde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde, impl TDrop: Drop> of Serde { /// # tensor.new /// @@ -2509,6 +2532,8 @@ trait TensorTrait { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Examples /// @@ -2559,17 +2584,17 @@ trait TensorTrait { /// /// It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). - /// It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the multiplication. + /// It perfoms the addition of the two vectors once dequantized, then return the quantization of the result of the addition. /// The broadcasting is supported /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. /// /// ## Args /// - /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `self`(`@Tensor`) - The first tensor to be additionned (a). /// * `a_scale`(`@Tensor`) - Scale for input `a`. /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. - /// * `b`(`@Tensor`) - The second tensor to be multiplied + /// * `b`(`@Tensor`) - The second tensor to be additionned /// * `b_scale`(`@Tensor`) - Scale for input `b`. /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. /// * `y_scale`(`@Tensor`) - Scale for outut. @@ -2582,6 +2607,8 @@ trait TensorTrait { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Example /// @@ -2660,6 +2687,125 @@ trait TensorTrait { y_scale: @Tensor, y_zero_point: @Tensor ) -> Tensor::; + /// # tensor.qlinear_mul + /// + /// ```rust + /// fn qlinear_mul(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, b: @Tensor, b_scale: @Tensor, b_zero_point: @Tensor, y_scale: @Tensor, y_zero_point: @Tensor) -> Tensor::; + /// ``` + /// + /// Performs the element-wise multiplication of quantized Tensors + /// + /// It consumes two quantized input tensors, their scales and zero points, scale and zero point of output, and computes the quantized output. + /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). + /// It perfoms the element-wise multiplication of the two vectors once dequantized, then return the quantization of the result of the multiplication. + /// The broadcasting is supported + /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). + /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `a_scale`(`@Tensor`) - Scale for input `a`. + /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. + /// * `b`(`@Tensor`) - The second tensor to be multiplied + /// * `b_scale`(`@Tensor`) - Scale for input `b`. + /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. + /// * `y_scale`(`@Tensor`) - Scale for outut. + /// * `y_zero_point`(`@Tensor`) - Zero point for output. + /// + /// ## Returns + /// + /// A new `Tensor`, containing the quantized result of the element-wise multiplication of the dequantized inputs. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// + /// ## Example + /// + /// + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// ```rust + /// #[test] + /// #[available_gas(200000000000)] + /// fn qlinear_mul_example() -> Tensor{ + /// let a = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 3].span(), + /// data: array![ + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(21_u8, false), + /// IntegerTrait::::new(41_u8, false), + /// IntegerTrait::::new(41_u8, false), + /// IntegerTrait::::new(41_u8, false) + /// ] + /// .span(), + /// ); + /// let b = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![1, 3].span(), + /// data: array![ + /// IntegerTrait::::new(4_u8, false), + /// IntegerTrait::::new(8_u8, false), + /// IntegerTrait::::new(12_u8, false) + /// ] + /// .span(), + /// ); + /// + /// let a_scale = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(), + /// ); + /// let a_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + /// let b_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(16384, false)].span(),); + /// let b_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + /// + /// let y_scale = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(393216, false)].span(), + /// ); + /// let y_zero_point = TensorTrait::< + /// FP16x16 + /// >::new( + /// shape: array![1].span(), data: array![FixedTrait::::new(655360, false)].span(), + /// ); + /// + /// return = a + /// .qlinear_mul( + /// @a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point + /// ); + /// + /// } + /// + /// >>> [[16, 23, 30], [23, 36, 50]] + /// ``` + fn qlinear_mul( + self: @Tensor, + a_scale: @Tensor, + a_zero_point: @Tensor, + b: @Tensor, + b_scale: @Tensor, + b_zero_point: @Tensor, + y_scale: @Tensor, + y_zero_point: @Tensor + ) -> Tensor::; /// # tensor.qlinear_matmul /// /// ```rust @@ -2683,7 +2829,7 @@ trait TensorTrait { /// * `b`(`@Tensor`) - The second tensor to be multiplied /// * `b_scale`(`@Tensor`) - Scale for input `b`. /// * `b_zero_point`(`@Tensor`) - Zero point for input `b`. - /// * `y_scale`(`@Tensor`) - Scale for outut. + /// * `y_scale`(`@Tensor`) - Scale for output. /// * `y_zero_point`(`@Tensor`) - Zero point for output. /// /// ## Returns @@ -2693,6 +2839,8 @@ trait TensorTrait { /// ## Type Constraints /// /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. /// /// ## Example /// @@ -2755,6 +2903,7 @@ trait TensorTrait { /// } /// >>> [14, 13] /// ``` + /// fn qlinear_matmul( self: @Tensor, a_scale: @Tensor, @@ -2765,6 +2914,192 @@ trait TensorTrait { y_scale: @Tensor, y_zero_point: @Tensor ) -> Tensor::; + /// # tensor.qlinear_concat + /// + /// ```rust + /// qlinear_concat(tensors: Span>, scales: Span>, zero_points: Span>, y_scale: @Tensor, y_zero_point: @Tensor, axis: usize) -> Tensor::; + /// ``` + /// + /// Concatenate a list of tensors after dequantizing them with their respective scales and zero_points and returns the quantized result. + /// + /// ## Args + /// + /// * `tensors`(` Span>,`) - Array of the quantized input tensors. + /// * `scales`(` Span>,`) - Array of the scales of the quantized input tensors. + /// * `zero_points`(` Span>,`) - Arrayof the zero_points of the quantized input tensors. + /// * `y_scale`(`@Tensor`) - Scale for output. + /// * `y_zero_point`(`@Tensor`) - Zero point for output. + /// * `axis`(`usize`) - Axis to concat on. + /// + /// ## Panics + /// + /// * Panic if tensor length is not greater than 1. + /// * Panics if dimension is not greater than axis. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// + /// ## Returns + /// + /// A new `Tensor` concatenated quantized tensor of the dequantized input tensors. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// fn qlinear_concat_example() -> Tensor { + /// let tensor1 = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// IntegerTrait::::new(5_u8, false), + /// ] + /// .span(), + /// ); + /// let tensor2 = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// IntegerTrait::::new(1_u8, false), + /// ] + /// .span(), + /// ); + /// + /// let tensors = array![tensor1, tensor2].span(); + /// + /// let tensor1_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + /// let tensor2_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + /// + /// let scales = array![tensor1_scale, tensor2_scale].span(); + /// + /// let tensor1_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + /// let tensor2_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(0, false)].span(),); + /// + /// let zero_points = array![tensor1_zero_point, tensor2_zero_point].span(); + /// + /// let y_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(262144, false)].span(),); + /// + /// let y_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(65536, false)].span(),); + /// + /// return TensorTrait::qlinear_concat(tensors, scales, zero_points, @y_scale, @y_zero_point, 0); + /// } + /// + /// >>> [[1, 1, 1, 1], [2, 2, 2, 2]] + /// ``` + /// + fn qlinear_concat( + tensors: Span>, + scales: Span>, + zero_points: Span>, + y_scale: @Tensor, + y_zero_point: @Tensor, + axis: usize + ) -> Tensor::; + /// # tensor.qlinear_leakyrelu + /// + /// ```rust + /// fn qlinear_leakyrelu(self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T) -> Tensor::; + /// ``` + /// + /// Applies the Leaky Relu operator to a quantized Tensor + /// + /// QLinar LeakyRelu takes as input a quantized Tensor, its scale and zero point and an scalar alpha, and produces one output data (a quantized Tensor) + /// where the function `f(x) = alpha * x for x < 0, f(x) = x for x >= 0`, is applied to the data tensor elementwise. + /// The quantization formula is y = saturate((x / y_scale) + y_zero_point). + /// Scale and zero point must have same shape and the same type. They must be either scalar (per tensor) or N-D tensor (per row for 'a' and per column for 'b'). + /// Scalar refers to per tensor quantization whereas N-D refers to per row or per column quantization. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The first tensor to be multiplied (a). + /// * `a_scale`(`@Tensor`) - Scale for input `a`. + /// * `a_zero_point`(`@Tensor`) - Zero point for input `a`. + /// * `alpha`(`T`) - The factor multiplied to negative elements. + /// + /// ## Returns + /// + /// A new `Tensor`, containing result of the Leaky Relu. + /// + /// ## Type Constraints + /// + /// u32 tensor, not supported. + /// fp8x23wide tensor, not supported. + /// fp16x16wide tensor, not supported. + /// bool tensor, not supported. + /// + /// ## Example + /// + /// ```rust + + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, I8Tensor, FP16x16Tensor}; + /// use orion::numbers::{i8, FP16x16, FP16x16Impl, IntegerTrait, FixedTrait}; + /// + /// + /// fn qlinear_leakyrelu_example() -> Tensor { + /// let a = TensorTrait::< + /// i8 + /// >::new( + /// shape: array![2, 3].span(), + /// data: array![ + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, true), + /// IntegerTrait::::new(10_u8, false), + /// IntegerTrait::::new(10_u8, false), + /// IntegerTrait::::new(10_u8, false) + /// ] + /// .span(), + /// ); + /// + /// let a_scale = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(327680, false)].span(),); + /// let a_zero_point = TensorTrait::< + /// FP16x16 + /// >::new(shape: array![1].span(), data: array![FixedTrait::::new(131072, false)].span(),); + /// + /// let alpha = FixedTrait::::new(655360, false); + /// + /// return = a + /// .qlinear_leakyrelu( + /// @a_scale, @a_zero_point, alpha + /// ); + /// } + /// + /// >>> [[-118, -118, -118], [10, 10, 10]] + /// + fn qlinear_leakyrelu( + self: @Tensor, a_scale: @Tensor, a_zero_point: @Tensor, alpha: T + ) -> Tensor::; /// # tensor.slice /// /// ```rust @@ -3235,13 +3570,6 @@ trait TensorTrait { /// ``` /// /// Computes the round value of all elements in the input tensor. - /// #tensor.not - /// - /// ```rust - /// fn not(self: @Tensor) -> Tensor; - /// ``` - /// - /// Computes the negation of the elements in the bool type input tensor. /// /// ## Args /// @@ -3252,7 +3580,6 @@ trait TensorTrait { /// /// A new `Tensor` of the same shape as the input tensor with /// the round value of all elements in the input tensor. - /// the negation of all elements in the input tensor. /// /// ## Example /// @@ -3434,272 +3761,1099 @@ trait TensorTrait { /// ``` /// fn bitwise_and(self: @Tensor, other: @Tensor) -> Tensor; - /// ## tensor.reduce_l1 + /// #tensor.bitwise_or /// - /// ```rust - /// fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ```rust + /// fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor; /// ``` /// - /// Computes the L1 norm of the input tensor's elements along the provided axes. + /// Computes the bitwise OR 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 input tensor. - /// * `axis`(`usize`) - The dimension to reduce. - /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// * `self`(`@Tensor`) - The first tensor to be compared + /// * `other`(`@Tensor`) - The second tensor to be compared /// - /// ## Panics - /// - /// * Panics if axis is not in the range of the input tensor's dimensions. + /// ## Panics + /// + /// * Panics if the shapes are not equal or broadcastable /// /// ## Returns /// - /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// A new `Tensor` with the same shape as the broadcasted inputs. /// - /// ## Examples + /// ## Example /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; - /// - /// fn reduce_l1_example() -> Tensor { + /// + /// fn or_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, 4, 5, 0, 6, 2].span(), + /// ); + /// + /// return tensor_1.bitwise_or(@tensor_2); + /// } + /// >>> [0,1,2,3,4,5,6,7,10] + /// ``` + /// + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor; + /// #tensor.bitwise_xor + /// + /// ```rust + /// fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Computes the bitwise XOR 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` with the same shape as the broadcasted inputs. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn xor_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, 4, 5, 0, 6, 2].span(), + /// ); + /// + /// return tensor_1.bitwise_xor(@tensor_2); + /// } + /// >>> [0,0,0,3,0,0,6,1,10] + /// ``` + /// + fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor; + /// ## tensor.reduce_l1 + /// + /// ```rust + /// fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the L1 norm of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_l1_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_l1` function as follows. + /// return tensor.reduce_l1(axis: 1, keepdims: false); + /// } + /// >>> [[2,4],[10,12]] + /// ``` + /// + fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ## tensor.reduce_l2 + /// + /// ```rust + /// fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the L2 norm of the input tensor's elements along the provided axes. + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// fn reduce_l2_example() -> Tensor { + /// + /// let mut shape = ArrayTrait::::new(); + /// shape.append(2); + /// shape.append(2); + /// let mut data = ArrayTrait::new(); + /// data.append(FixedTrait::new_unscaled(1, false)); + /// data.append(FixedTrait::new_unscaled(2, false)); + /// data.append(FixedTrait::new_unscaled(3, false)); + /// data.append(FixedTrait::new_unscaled(5, false)); + /// let tensor = TensorTrait::::new(shape.span(), data.span()); + /// + /// We can call `reduce_l2` function as follows. + /// return tensor.reduce_l2(axis: 1, keepdims: true); + /// } + /// >>> [[0x11e3779, 0x2ea5ca1]] + /// ``` + /// + fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ## tensor.reduce_sum_square + /// + /// ```rust + /// fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Computes the sum square of the input tensor's elements along the provided axes. + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axis`(`usize`) - The dimension to reduce. + /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// + /// fn reduce_sum_square_example() -> Tensor { + /// + /// let mut shape = ArrayTrait::::new(); + /// shape.append(2); + /// shape.append(2); + /// let mut data = ArrayTrait::new(); + /// data.append(1); + /// data.append(2); + /// data.append(3); + /// data.append(4); + /// let tensor = TensorTrait::::new(shape.span(), data.span()); + /// + /// We can call `reduce_sum_square` function as follows. + /// return tensor.reduce_sum_square(axis: 1, keepdims: true); + /// } + /// >>> [[5, 25]] + /// ``` + /// + fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// # tensor.constant_of_shape + /// + /// ```rust + /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ``` + /// + /// Returns a new tensor with the given shape and constant value. + /// + /// ## Args + /// + /// * `shape`(`Span`) - A span representing the shape of the tensor. + /// * `value` (`T`) - the constant value. + /// + /// ## Returns + /// + /// A new `Tensor` instance. + /// + /// ## Examples + /// + /// Let's create new u32 Tensor with constant 42. + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{ + /// TensorTrait, // we import the trait + /// Tensor, // we import the type + /// U32Tensor // we import the implementation. + /// }; + /// + /// fn constant_of_shape_example() -> Tensor { + /// let tensor = TensorTrait::constant_of_shape(shape: array![3].span(), value: 42); + /// + /// return tensor; + /// } + /// + /// >>> [42, 42, 42] + /// ``` + /// + fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// # tensor.gather_elements + /// + /// ```rust + /// fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; + /// ``` + /// + /// GatherElements is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// * `axis`(`Option`) - Axis to gather_elements on. Default: axis=0. + /// + /// ## Panics + /// + /// * Panics if index values are not within bounds [-s, s-1] along axis of size s. + /// + /// ## Returns + /// + /// A new `Tensor` . + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn gather_elements_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![3, 3].span(), + /// data: array![[ 1, 2, 3],[4, 5, 6], [7, 8, 9]].span(), + /// ); + /// let indices = TensorTrait::::new( + /// shape: array![1, 2, 0].span(), + /// data: array![2, 0, 0].span(), + /// ); + /// + /// return tensor.gather_elements( + /// indices: indices, + /// axis: Option::None(()), + /// ); + /// } + /// >>> [[4. 8. 3.] + /// [7. 2. 3.]] + /// ``` + /// + fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor; + /// # tensor.binarizer + /// + /// ```rust + /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor + /// ``` + /// + /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be binarized. + /// * `threshold`(`Option`) - The threshold for the binarization operation. + /// + /// ## Returns + /// A new `Tensor` of the same shape as the input tensor with binarized values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point numbers. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// fn binarizer_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// FixedTrait::new(0, false), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false), + /// FixedTrait::new(3, false) + /// ] + /// .span(), + /// ); + /// let threshold = Option::Some(FixedTrait::new(1, false)) + /// + /// return tensor.binarizer(@tensor, threshold); + /// } + /// >>> [0, 0, 8388608, 8388608] + /// // The fixed point representation of + /// [0, 0, 1, 1] + /// ``` + /// + fn binarizer(self: @Tensor, threshold: Option) -> Tensor; + /// # tensor.array_feature_extractor + /// + /// ```rust + /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// ``` + /// + /// Selects elements of the input tensor based on the indices passed applied to the last tensor axis. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `indices`(`Tensor`) - Tensor of indices. + /// + /// ## Panics + /// + /// * Panics if indices tensor is not 1-dimensional. + /// + /// ## Returns + /// + /// A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn array_feature_extractor_example() -> Tensor { + /// let input_tensor = TensorTrait::new( + /// shape: array![3, 4].span(), + /// data: array![ + /// IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), + /// IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), + /// IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) + /// ] + /// .span(), + /// ); + /// + /// let indices = TensorTrait::::new( + /// shape: array![2].span(), data: array![1, 3].span(), + /// ); + /// + /// return tensor.array_feature_extractor(@input_tensor, @indices); + /// } + /// >>> [[1, 3] + /// [5, 7] + /// [9, 11]] + /// ``` + /// + fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// # tensor.sequence_empty + /// + /// ```rust + /// fn sequence_empty() -> Array>; + /// ``` + /// + /// Returns an empty tensor sequence. + /// + /// ## Args + /// + /// ## Returns + /// + /// An empty `Array>` instance. + /// + /// ## Examples + /// + /// Let's create a new empty sequence. + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{ + /// TensorTrait, // we import the trait + /// Tensor, // we import the type + /// U32Tensor // we import the implementation. + /// }; + /// + /// fn sequence_empty_example() -> Array> { + /// let sequence = TensorTrait::sequence_empty(); + /// + /// return sequence; + /// } + /// + /// >>> [] + /// ``` + /// + fn sequence_empty() -> Array>; + /// # tensor.shrink + /// + /// ```rust + /// fn shrink(self: @Tensor, bias: Option, lambd: Option) -> Tensor + /// ``` + /// + /// Shrinks the input tensor element-wise to the output tensor with the same datatype and shape based on the following formula: + /// If x < -lambd: y = x + bias; If x > lambd: y = x - bias; Otherwise: y = 0. + /// + /// ## Args + /// * `self`(`@Tensor`) - The input tensor to be shrinked. + /// * `bias`(`Option`) - The bias value added to or subtracted from input tensor values. + /// * `lambd`(`Option`) - The lambd value defining the shrink condition. + /// + /// ## Returns + /// A new `Tensor` of the same datatype and shape as the input tensor with shrinked values. + /// + /// ## Type Constraints + /// + /// Constrain input and output types to fixed point numbers. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::numbers::{FixedTrait, FP8x23}; + /// + /// fn shrink_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2].span(), + /// data: array![ + /// FixedTrait::new(2, true), + /// FixedTrait::new(1, true), + /// FixedTrait::new(1, false), + /// FixedTrait::new(2, false) + /// ] + /// .span(), + /// ); + /// let bias = Option::Some(FixedTrait::new(1, false)) + /// let lambd = Option::Some(FixedTrait::new(1, false)) + /// + /// return tensor.shrink(tensor, bias, lambd); + /// } + /// >>> [-8388608, 0, 0, 8388608] + /// // The fixed point representation of + /// [-1, 0, 0, 1] + /// ``` + /// + fn shrink(self: Tensor, bias: Option, lambd: Option) -> Tensor; + /// ## tensor.sequence_construct + /// + /// ```rust + /// fn sequence_construct(tensors: Array>) -> Array>; + /// ``` + /// + /// Constructs a tensor sequence containing the input tensors. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The array of input tensors. + /// + /// ## Panics + /// + /// * Panics if input tensor array is empty. + /// + /// ## Returns + /// + /// A tensor sequence `Array>` containing the input tensors. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn sequence_construct_example() -> Array> { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let result = TensorTrait::sequence_construct(tensors: array![tensor1, tensor2]); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [4, 5, 6, 7]] + /// ``` + /// + fn sequence_construct(tensors: Array>) -> Array>; + /// ## tensor.reduce_mean + /// + /// ```rust + /// fn reduce_mean(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the mean of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by meaning its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_mean_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_mean` function as follows. + /// return tensor.reduce_mean(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[1,2],[5,6]] + /// ``` + /// + fn reduce_mean( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; + /// ## tensor.reduce_min + /// + /// ```rust + /// fn reduce_min(self: @Tensor, axes: Option>, keepdims: Option, noop_with_empty_axes: Option) -> Tensor; + /// ``` + /// + /// Computes the min of the input tensor's elements along the provided axes. + /// + /// ## Args + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `axes`(`Option>`) - Optional input list of integers, along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop_with_empty_axes' is false, else act as an Identity op when 'noop_with_empty_axes' is true. + /// * `keepdims`(`Option`) - Keep the reduced dimension or not, default true means keep reduced dimension. + /// * `noop_with_empty_axes`(`Option`) - Defines behavior if 'axes' is empty. Default behavior with 'false' is to reduce all axes. When axes is empty and this attribute is set to true, input tensor will not be reduced,and the output tensor would be equivalent to input tensor. + /// + /// ## Panics + /// + /// * Panics if axis is not in the range of the input tensor's dimensions. + /// + /// ## Returns + /// + /// A new `Tensor` instance with the specified axes reduced by minimum of its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_min_example() -> Tensor { /// let tensor = TensorTrait::::new( /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), /// ); /// - /// // We can call `reduce_l1` function as follows. - /// return tensor.reduce_l1(axis: 1, keepdims: false); + /// // We can call `reduce_min` function as follows. + /// return tensor.reduce_min(axes: array![1].span(), + /// keepdims: Option::None(()), + /// noop_with_empty_axes: Option::None(())); + /// } + /// >>> [[0,1],[4,5]] + /// ``` + /// + fn reduce_min( + self: @Tensor, + axes: Option>, + keepdims: Option, + noop_with_empty_axes: Option + ) -> Tensor; + /// # tensor.sequence_insert + /// + /// ```rust + /// fn sequence_insert(self: Array>, tensor: @Tensor, position: Option>) -> Array>; + /// ``` + /// + /// Returns a tensor sequence that inserts 'tensor' into 'self' at 'position'. + /// + /// ## Args + /// + /// * `self`(`Array>`) - input sequence. + /// * `tensor` (`@Tensor`) - the tensor to insert. + /// * `position` (`@Tensor`) - the index for insertion (default: -1). + /// + /// ## Returns + /// + /// Tensor sequence containing 'tensor' inserted into 'self' at 'position'. + /// + /// ## Examples + /// + /// Let's insert the tensor [2] into the sequence [[1], [3]] at position 1. + /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; + /// + /// fn sequence_insert_example() -> Array> { + /// // Prepare sequence + /// let mut sequence = ArrayTrait::new(); + /// let mut shape = ArrayTrait::::new(); + /// shape.append(1); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(1); + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// let mut data = ArrayTrait::new(); + /// data.append(3); + /// + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// + /// // Prepare input tensor + /// let mut data = ArrayTrait::new(); + /// data.append(2); + /// let tensor = TensorTrait::new(shape.span(), data.span()); + /// + /// // Prepare position + /// let mut shape = ArrayTrait::::new(); + /// let mut data = ArrayTrait::::new(); + /// data.append(i32 { mag: 1, sign: false }); + /// let position = TensorTrait::::new(shape.span(), data.span()) + /// + /// let sequence = self.sequence_insert(tensor, Option::Some(position)); + /// + /// return sequence; + /// } + /// + /// >>> [[1], [2], [3]] + /// ``` + /// + fn sequence_insert( + self: Array>, tensor: @Tensor, position: Option> + ) -> Array>; + /// ## tensor.sequence_at + /// + /// ```rust + /// fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; + /// ``` + /// + /// Outputs the tensor at the specified position in the input sequence. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The tensor sequence. + /// * `position`(`Tensor`) - The position tensor. + /// + /// ## Panics + /// + /// * Panics if position is not a scalar + /// * Panics if position is out of bounds [-n, n - 1] + /// + /// ## Returns + /// + /// The tensor `Tensor` from the sequence at the specified position. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn sequence_at_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// + /// let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + /// + /// let result = TensorTrait::sequence_at(sequence, position); + /// return result; + /// } + /// >>> [4, 5, 6, 7] + /// ``` + /// + fn sequence_at(sequence: Array>, position: Tensor) -> Tensor; + /// ## tensor.sequence_erase + /// + /// ```rust + /// fn sequence_erase(sequence: Array>, position: Option>) -> Array>; + /// ``` + /// + /// Outputs the tensor sequence with the erased tensor at the specified position. + /// + /// ## Args + /// + /// * `tensors`(`Array>`) - The tensor sequence. + /// * `position`(`Option>`) - The optional position tensor (by default erases the last tensor). + /// + /// ## Panics + /// + /// * Panics if position is not a scalar + /// * Panics if position is out of bounds [-n, n - 1] + /// + /// ## Returns + /// + /// The tensor sequence `Array>` with the erased tensor at the specified position. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor, I32Tensor}; + /// use orion::numbers::{i32, IntegerTrait}; + /// + /// fn sequence_erase_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span()); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![4, 5, 6, 7].span()); + /// let tensor3 = TensorTrait::new(shape: array![2, 2].span(), data: array![8, 9, 10, 11].span()); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// sequence.append(tensor3); + /// + /// let position = TensorTrait::new(shape: array![].span(), data: array![IntegerTrait::new(1, false)].span()); + /// + /// let result = TensorTrait::sequence_erase(sequence, position); + /// return result; + /// } + /// >>> [[0, 1, 2, 3], [8, 9, 10, 11]] + /// ``` + /// + fn sequence_erase( + sequence: Array>, position: Option> + ) -> Array>; + /// #tensor.pow + /// + /// ```rust + /// fn pow(self: @Tensor, other: @Tensor) -> Tensor; + /// ``` + /// + /// Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function f(x) = x^exponent, is applied to the data tensor elementwise. + /// 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, base of the exponent. + /// * `other`(`@Tensor`) - The second tensor, power of the exponent. + /// + /// ## Panics + /// + /// * Panics if the shapes are not equal or broadcastable + /// + /// ## Returns + /// + /// A new `Tensor` 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 pow_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.pow(@tensor_2); + /// } + /// >>> [0,1,4,0,4,25,0,7,64] + /// ``` + /// + /// Case 2: Compare tensors with different shapes + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn pow_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.pow(@tensor_2); /// } - /// >>> [[2,4],[10,12]] + /// >>> [0,1,4,0,4,25,0,7,64] /// ``` /// - fn reduce_l1(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; - /// ## tensor.reduce_l2 + fn pow(self: @Tensor, other: @Tensor) -> Tensor; + /// # tensor.sequence_length /// - /// ```rust - /// fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ```rust + /// fn sequence_length(self: Array>) -> Tensor; /// ``` /// - /// Computes the L2 norm of the input tensor's elements along the provided axes. - /// ## Args + /// Returns the length of the input sequence. /// - /// * `self`(`@Tensor`) - The input tensor. - /// * `axis`(`usize`) - The dimension to reduce. - /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. + /// ## Args /// - /// ## Panics - /// - /// * Panics if axis is not in the range of the input tensor's dimensions. + /// * `self`(`Array>`) - The input sequence. /// /// ## Returns /// - /// A new `Tensor` instance with the specified axis reduced by summing its elements. + /// The length of the sequence as scalar, i.e. a tensor of shape []. /// - /// fn reduce_l2_example() -> Tensor { + /// ## Examples /// - /// let mut shape = ArrayTrait::::new(); - /// shape.append(2); - /// shape.append(2); - /// let mut data = ArrayTrait::new(); - /// data.append(FixedTrait::new_unscaled(1, false)); - /// data.append(FixedTrait::new_unscaled(2, false)); - /// data.append(FixedTrait::new_unscaled(3, false)); - /// data.append(FixedTrait::new_unscaled(5, false)); - /// let tensor = TensorTrait::::new(shape.span(), data.span()); - /// - /// We can call `reduce_l2` function as follows. - /// return tensor.reduce_l2(axis: 1, keepdims: true); - /// } - /// >>> [[0x11e3779, 0x2ea5ca1]] - /// ``` + /// Let's create new u32 Tensor with constant 42. /// - fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; - /// ## tensor.reduce_sum_square + /// ```rust + /// let mut sequence = ArrayTrait::new(); /// - /// ```rust - /// fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// let mut shape = ArrayTrait::::new(); + /// shape.append(1); + /// shape.append(2); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(3); + /// data.append(1); + /// + /// sequence.append(TensorTrait::new(shape.span(), data.span())); + /// + /// sequence.sequence_length() + /// >>> [1] /// ``` /// - /// Computes the sum square of the input tensor's elements along the provided axes. + fn sequence_length(self: Array>) -> Tensor; + /// ## tensor.reduce_prod + /// + /// ```rust + /// fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ``` + /// + /// Reduces a tensor by multiplying its elements along a specified axis. + /// /// ## Args - /// + /// /// * `self`(`@Tensor`) - The input tensor. /// * `axis`(`usize`) - The dimension to reduce. /// * `keepdims`(`bool`) - If true, retains reduced dimensions with length 1. - /// + /// /// ## Panics /// /// * Panics if axis is not in the range of the input tensor's dimensions. - /// + /// /// ## Returns - /// - /// A new `Tensor` instance with the specified axis reduced by summing its elements. - /// - /// fn reduce_sum_square_example() -> Tensor { - /// - /// let mut shape = ArrayTrait::::new(); - /// shape.append(2); - /// shape.append(2); - /// let mut data = ArrayTrait::new(); - /// data.append(1); - /// data.append(2); - /// data.append(3); - /// data.append(4); - /// let tensor = TensorTrait::::new(shape.span(), data.span()); /// - /// We can call `reduce_sum_square` function as follows. - /// return tensor.reduce_sum_square(axis: 1, keepdims: true); + /// A new `Tensor` instance with the specified axis reduced by multiplying its elements. + /// + /// ## Examples + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; + /// + /// fn reduce_prod_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(), + /// ); + /// + /// // We can call `reduce_prod` function as follows. + /// return tensor.reduce_prod(axis: 0, keepdims: false); /// } - /// >>> [[5, 25]] + /// >>> [[0,5],[12,21]] /// ``` /// - fn reduce_sum_square(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; - /// # tensor.constant_of_shape + fn reduce_prod(self: @Tensor, axis: usize, keepdims: bool) -> Tensor; + /// ## tensor.is_inf /// - /// ```rust - /// fn constant_of_shape(shape: Span, value: T) -> Tensor; + /// ```rust + /// fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; /// ``` /// - /// Returns a new tensor with the given shape and constant value. - /// + /// Maps infinity to true and other values to false. + /// /// ## Args - /// - /// * `shape`(`Span`) - A span representing the shape of the tensor. - /// * `value` (`T`) - the constant value. + /// + /// * `self`(`@Tensor`) - The input tensor. + /// * `detect_negative`(`Option`) - Optional Whether map negative infinity to true. Default to 1 so that negative infinity induces true. + /// * `detect_positive`(`Option`) - Optional Whether map positive infinity to true. Default to 1 so that positive infinity induces true. + /// /// /// ## Returns /// - /// A new `Tensor` instance. + /// A new `Tensor` instance with entries set to true iff the input tensors corresponding element was infinity. /// /// ## Examples - /// - /// Let's create new u32 Tensor with constant 42. - /// + /// /// ```rust - /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{ - /// TensorTrait, // we import the trait - /// Tensor, // we import the type - /// U32Tensor // we import the implementation. - /// }; - /// - /// fn constant_of_shape_example() -> Tensor { - /// let tensor = TensorTrait::constant_of_shape(shape: array![3].span(), value: 42); - /// - /// return tensor; + /// use array::{ArrayTrait, SpanTrait}; + /// use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, U32Tensor}; + /// + /// fn is_inf_example() -> Tensor { + /// let tensor = TensorTrait::::new( + /// shape: array![6].span(), data: array![1, 0, NumberTrait::INF(), 8, NumberTrait::INF(), NumberTrait::INF()].span(), + /// ); + /// + /// return tensor.is_inf(detect_negative: Option::None, detect_positive: Option::None); /// } - /// - /// >>> [42, 42, 42] + /// >>> [false, false, true, false, true, true] /// ``` /// - fn constant_of_shape(shape: Span, value: T) -> Tensor; - /// # tensor.binarizer - /// + fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; + /// ## tensor.is_nan + /// /// ```rust - /// fn binarizer(self: @Tensor, threshold: Option) -> Tensor + /// fn is_nan(self: @Tensor) -> Tensor; /// ``` /// - /// Maps the values of a tensor element-wise to 0 or 1 based on the comparison against a threshold value. + /// Maps NaN to true and other values to false. /// /// ## Args - /// * `self`(`@Tensor`) - The input tensor to be binarized. - /// * `threshold`(`Option`) - The threshold for the binarization operation. /// - /// ## Returns - /// A new `Tensor` of the same shape as the input tensor with binarized values. + /// * `self`(`@Tensor`) - The input tensor. /// - /// ## Type Constraints + /// ## Returns /// - /// Constrain input and output types to fixed point numbers. + /// A new `Tensor` instance with entries set to true iff the input tensors corresponding element was NaN. /// /// ## Examples /// - /// ```rust /// use array::{ArrayTrait, SpanTrait}; - /// - /// use orion::operators::tensor::{TensorTrait, Tensor, FP8x23Tensor}; + /// use orion::operators::tensor::{BoolTensor, TensorTrait, Tensor, FP8x23Tensor}; /// use orion::numbers::{FixedTrait, FP8x23}; - /// - /// fn binarizer_example() -> Tensor { - /// let tensor = TensorTrait::::new( - /// shape: array![2, 2].span(), - /// data: array![ - /// FixedTrait::new(0, false), - /// FixedTrait::new(1, false), - /// FixedTrait::new(2, false), - /// FixedTrait::new(3, false) - /// ] - /// .span(), - /// ); - /// let threshold = Option::Some(FixedTrait::new(1, false)) - /// - /// return tensor.binarizer(@tensor, threshold); + /// + /// fn is_nan_example() -> Tensor { + /// let mut shape = ArrayTrait::::new(); + /// shape.append(4); + /// + /// let mut data = ArrayTrait::new(); + /// data.append(FP8x23 { mag: 10066329, sign: true }); + /// data.append(FP8x23 { mag: 0, sign: false }); + /// data.append(FixedTrait::NaN()); + /// data.append(FP8x23 { mag: 23488102, sign: false }); + /// let tensor = TensorTrait::new(shape.span(), data.span()) + /// + /// return tensor.is_nan(); /// } - /// >>> [0, 0, 8388608, 8388608] - /// // The fixed point representation of - /// [0, 0, 1, 1] + /// >>> [false, false, true, false] /// ``` /// - fn binarizer(self: @Tensor, threshold: Option) -> Tensor; - /// # tensor.array_feature_extractor + fn is_nan(self: @Tensor) -> Tensor; + /// # tensor.concat_from_sequence /// - /// ```rust - /// fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + /// ```rust + /// fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; /// ``` /// - /// Selects elements of the input tensor based on the indices passed applied to the last tensor axis. - /// + /// Concatenate a sequence of tensors into a single tensor. + /// /// ## Args /// - /// * `self`(`@Tensor`) - The input tensor. - /// * `indices`(`Tensor`) - Tensor of indices. + /// * `sequence`(`Array>`) - The input sequence. + /// * `axis`(`i32`) - Axis to concat on. + /// * `new_axis`(`Option`) - Optionally added new axis. /// /// ## Panics /// - /// * Panics if indices tensor is not 1-dimensional. + /// * Panics if new_axis not 0 or 1 (if value provided). + /// * Panics if axis not in accepted ranges. + /// * Panics if sequence length is not greater than 1. /// - /// ## Returns + /// ## Returns /// - /// A new `Tensor` of the same shape as the input tensor with selected elements based on provided indices. + /// A new `Tensor` concatenated tensor from the input tensor sequence. /// /// ## Example /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// - /// use orion::operators::tensor::{TensorTrait, Tensor, I32Tensor, U32Tensor}; - /// use orion::numbers::{i32, IntegerTrait}; - /// - /// fn array_feature_extractor_example() -> Tensor { - /// let input_tensor = TensorTrait::new( - /// shape: array![3, 4].span(), - /// data: array![ - /// IntegerTrait::new(0, false), IntegerTrait::new(1, false), IntegerTrait::new(2, false), IntegerTrait::new(3, false), - /// IntegerTrait::new(4, false), IntegerTrait::new(5, false), IntegerTrait::new(6, false), IntegerTrait::new(7, false), - /// IntegerTrait::new(8, false), IntegerTrait::new(9, false), IntegerTrait::new(10, false), IntegerTrait::new(11, false) - /// ] - /// .span(), - /// ); - /// - /// let indices = TensorTrait::::new( - /// shape: array![2].span(), data: array![1, 3].span(), - /// ); + /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// return tensor.array_feature_extractor(@input_tensor, @indices); + /// fn concat_example() -> Tensor { + /// let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),); + /// + /// let mut sequence = ArrayTrait::new(); + /// sequence.append(tensor1); + /// sequence.append(tensor2); + /// + /// let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 0, new_axis: Option::Some(0)); + /// return result; /// } - /// >>> [[1, 3] - /// [5, 7] - /// [9, 11]] + /// >>> [[0. 1.] + /// [2. 3.], + /// [0. 1.] + /// [2. 3.]] + /// + /// result.shape + /// >>> (4, 2) + /// + /// let result = TensorTrait::concat_from_sequence(sequence: sequence, axis: 1, new_axis: Option::Some(0)); + /// return result; + /// } + /// >>> [[0. 1., 0., 1.] + /// [2. 3., 2., 3.]] + /// + /// result.shape + /// >>> (2, 4 ) /// ``` /// - fn array_feature_extractor(self: @Tensor, indices: Tensor) -> Tensor; + fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; + /// #tensor.not + /// + /// ```rust + /// fn not(self: @Tensor) -> Tensor`) - The input tensor. + /// + /// + /// ## Returns + /// + /// A new `Tensor` of the same shape as the input tensor with + /// the negation of all elements in the input tensor. + /// + /// ## Example + /// + /// ```rust + /// use array::{ArrayTrait, SpanTrait}; + /// /// use orion::operators::tensor::{TensorTrait, Tensor, BoolTensor}; /// use orion::numbers::{i32, IntegerTrait}; /// /// fn not_example() -> Tensor { - /// let tensor = TensorTrait::new( + /// let tensor = TensorTrait::new( /// shape: array![3].span(), /// data: array![ /// true, true, false @@ -4274,4 +5428,4 @@ fn clip< /// Cf: TensorTrait::identity docstring fn identity(self: @Tensor) -> Tensor { Tensor:: { shape: *self.shape, data: *self.data } -} +} \ No newline at end of file From 75cf8e9fd7c3087929b3dd8cd22725322808a32b Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 30 Nov 2023 20:23:16 +0200 Subject: [PATCH 155/160] move tensor arithmetic to trait --- src/operators/tensor/core.cairo | 4 ++++ .../tensor/implementations/tensor_bool.cairo | 17 +++++++++++++++++ .../tensor/implementations/tensor_fp16x16.cairo | 16 ++++++++++++++++ .../implementations/tensor_fp16x16wide.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_fp32x32.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_fp64x64.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_fp8x23.cairo | 16 ++++++++++++++++ .../implementations/tensor_fp8x23wide.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_i32.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_i8.cairo | 16 ++++++++++++++++ .../tensor/implementations/tensor_u32.cairo | 16 ++++++++++++++++ 11 files changed, 165 insertions(+) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 7a58734a3..72d13f627 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -258,6 +258,10 @@ trait TensorTrait { /// ``` /// fn min_in_tensor(self: @Tensor) -> T; + fn add(lhs: Tensor, rhs: Tensor) -> Tensor; + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor; + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor; + fn div(lhs: Tensor, rhs: Tensor) -> Tensor; /// # tensor.min /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index ceda6c74e..d9e7a8357 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -21,6 +21,23 @@ impl BoolTensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + panic(array!['not supported!']) + } + + fn min_in_tensor(self: @Tensor) -> bool { panic(array!['not supported!']) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index a5a9a05ac..c3e0986cc 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -21,6 +21,22 @@ impl FP16x16Tensor of TensorTrait { constant_of_shape(shape, value) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn at(self: @Tensor, indices: Span) -> FP16x16 { *at_tensor(self, indices) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index d2cba0787..c993f960f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -25,6 +25,22 @@ impl FP16x16WTensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> FP16x16W { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index fc078a9ec..a267451f0 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -22,6 +22,22 @@ impl FP32x32Tensor of TensorTrait { constant_of_shape(shape, value) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn at(self: @Tensor, indices: Span) -> FP32x32 { *at_tensor(self, indices) } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 1814ac552..fea845ce4 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -26,6 +26,22 @@ impl FP64x64Tensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> FP64x64 { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 8daf2fafc..2d00eded0 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -25,6 +25,22 @@ impl FP8x23Tensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> FP8x23 { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8c3afd0ec..8f153c592 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -25,6 +25,22 @@ impl FP8x23WTensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> FP8x23W { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index d07098f9e..6a41b927e 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -26,6 +26,22 @@ impl I32Tensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> i32 { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 407ffc13d..9862907fd 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -25,6 +25,22 @@ impl I8Tensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> i8 { math::min_in_tensor::min_in_tensor::(*self.data) } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 6c474554b..05084e743 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -25,6 +25,22 @@ impl U32Tensor of TensorTrait { *at_tensor(self, indices) } + fn add(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::add(@lhs, @rhs) + } + + fn sub(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::sub(@lhs, @rhs) + } + + fn mul(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::mul(@lhs, @rhs) + } + + fn div(lhs: Tensor, rhs: Tensor) -> Tensor { + math::arithmetic::div(@lhs, @rhs) + } + fn min_in_tensor(self: @Tensor) -> u32 { math::min_in_tensor::min_in_tensor::(*self.data) } From cf485f2dc3c0db1dc66841ce4685a04d597fa5b2 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 1 Dec 2023 10:06:14 +0200 Subject: [PATCH 156/160] replace usize with bool --- docs/framework/operators/tensor/README.md | 2 +- nodegen/node/and.py | 20 +- src/operators/tensor/core.cairo | 24 +- .../tensor/implementations/tensor_bool.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 4 +- .../implementations/tensor_fp16x16wide.cairo | 4 +- .../implementations/tensor_fp32x32.cairo | 4 +- .../implementations/tensor_fp64x64.cairo | 4 +- .../implementations/tensor_fp8x23.cairo | 4 +- .../implementations/tensor_fp8x23wide.cairo | 4 +- .../tensor/implementations/tensor_i32.cairo | 4 +- .../tensor/implementations/tensor_i8.cairo | 4 +- .../tensor/implementations/tensor_u32.cairo | 4 +- src/operators/tensor/math/and.cairo | 10 +- tests/nodes.cairo | 1662 ++++++++--------- 15 files changed, 880 insertions(+), 876 deletions(-) diff --git a/docs/framework/operators/tensor/README.md b/docs/framework/operators/tensor/README.md index 574779ffe..0f0ed5513 100644 --- a/docs/framework/operators/tensor/README.md +++ b/docs/framework/operators/tensor/README.md @@ -65,7 +65,6 @@ use orion::operators::tensor::TensorTrait; | [`tensor.log`](tensor.log.md) | Computes the natural log of all elements of the input tensor. | | [`tensor.abs`](tensor.abs.md) | Computes the absolute value of all elements in the input tensor. | | [`tensor.neg`](tensor.neg.md) | Computes the negation of all elements in the input tensor. | -| [`tensor.not`](tensor.not.md) | Computes the logical negation of all elements in the input tensor. | | [`tensor.ceil`](tensor.ceil.md) | Rounds up the value of each element in the input tensor. | | [`tensor.sqrt`](tensor.sqrt.md) | Computes the square root of all elements of the input tensor. | | [`tensor.sin`](tensor.sin.md) | Computes the sine of all elements of the input tensor. | @@ -122,6 +121,7 @@ use orion::operators::tensor::TensorTrait; | [`tensor.concat_from_sequence`](tensor.concat\_from\_sequence.md) | Concatenate a sequence of tensors into a single tensor. | | [`tensor.is_nan`](tensor.is\_nan.md) | Returns which elements of the input are NaN. | | [`tensor.is_inf`](tensor.is\_inf.md) | Maps infinity to true and other values to false. | +| [`tensor.not`](tensor.not.md) | Computes the logical negation of all elements in the input tensor. | ## Arithmetic Operations diff --git a/nodegen/node/and.py b/nodegen/node/and.py index b446354d5..6ef5ea17f 100644 --- a/nodegen/node/and.py +++ b/nodegen/node/and.py @@ -13,7 +13,7 @@ def default(): x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_u32" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -25,7 +25,7 @@ def broadcast(): x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype.U32, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_u32_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -42,7 +42,7 @@ def default(): x = Tensor(Dtype.I32, x.shape, x.flatten()) y = Tensor(Dtype.I32, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_i32" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -54,7 +54,7 @@ def broadcast(): x = Tensor(Dtype.I32, x.shape, x.flatten()) y = Tensor(Dtype.I32, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_i32_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -71,7 +71,7 @@ def default(): x = Tensor(Dtype.I8, x.shape, x.flatten()) y = Tensor(Dtype.I8, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_i8" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -83,7 +83,7 @@ def broadcast(): x = Tensor(Dtype.I8, x.shape, x.flatten()) y = Tensor(Dtype.I8, y.shape, y.flatten()) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_i8_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -102,7 +102,7 @@ def default(): x.flatten(), FixedImpl.FP8x23)) y = Tensor(Dtype.FP8x23, y.shape, to_fp( y.flatten(), FixedImpl.FP8x23)) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_fp8x23" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -116,7 +116,7 @@ def broadcast(): x.flatten(), FixedImpl.FP8x23)) y = Tensor(Dtype.FP8x23, y.shape, to_fp( y.flatten(), FixedImpl.FP8x23)) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_fp8x23_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -135,7 +135,7 @@ def default(): x.flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_fp16x16" make_test([x, y], z, "input_0.and(@input_1)", name) @@ -149,7 +149,7 @@ def broadcast(): x.flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) - z = Tensor(Dtype.U32, z.shape, z.flatten()) + z = Tensor(Dtype.BOOL, z.shape, z.flatten()) name = "and_fp16x16_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 72d13f627..d2ffdb12a 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3452,7 +3452,7 @@ trait TensorTrait { /// #tensor.and /// /// ```rust - /// fn and(self: @Tensor, other: @Tensor) -> Tensor; + /// fn and(self: @Tensor, other: @Tensor) -> Tensor; /// ``` /// /// Computes the logical AND of two tensors element-wise. @@ -3471,7 +3471,7 @@ trait TensorTrait { /// /// ## Returns /// - /// A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. + /// A new `Tensor` with the same shape as the broadcasted inputs. /// /// ## Examples /// @@ -3482,7 +3482,7 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn and_example() -> Tensor { + /// 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(), /// ); @@ -3493,7 +3493,7 @@ trait TensorTrait { /// /// return tensor_1.and(@tensor_2); /// } - /// >>> [0,1,1,0,1,1,0,1,1] + /// >>> [false, true, true, false, true, true, false, true, true] /// ``` /// /// Case 2: Compare tensors with different shapes @@ -3503,7 +3503,7 @@ trait TensorTrait { /// /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// - /// fn and_example() -> Tensor { + /// 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(), /// ); @@ -3514,10 +3514,10 @@ trait TensorTrait { /// /// return tensor_1.and(@tensor_2); /// } - /// >>> [0,1,1,0,1,1,0,1,1] + /// >>> [false, true, true, false, true, true, false, true, true] /// ``` /// - fn and(self: @Tensor, other: @Tensor) -> Tensor; + fn and(self: @Tensor, other: @Tensor) -> Tensor; /// #tensor.where /// /// ```rust @@ -4730,7 +4730,9 @@ trait TensorTrait { /// >>> [false, false, true, false, true, true] /// ``` /// - fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor; + fn is_inf( + self: @Tensor, detect_negative: Option, detect_positive: Option + ) -> Tensor; /// ## tensor.is_nan /// /// ```rust @@ -4830,7 +4832,9 @@ trait TensorTrait { /// >>> (2, 4 ) /// ``` /// - fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor; + fn concat_from_sequence( + sequence: Array>, axis: i32, new_axis: Option + ) -> Tensor; /// #tensor.not /// /// ```rust @@ -5433,4 +5437,4 @@ fn clip< /// Cf: TensorTrait::identity docstring fn identity(self: @Tensor) -> Tensor { Tensor:: { shape: *self.shape, data: *self.data } -} \ No newline at end of file +} diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index d9e7a8357..cfd6639db 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -256,7 +256,7 @@ impl BoolTensor of TensorTrait { panic(array!['not supported!']) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @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 c3e0986cc..33829c816 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16}; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP16x16Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -372,7 +372,7 @@ impl FP16x16Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c993f960f..c892b9c0f 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP16x16W}; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP16x16WTensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -334,7 +334,7 @@ impl FP16x16WTensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index a267451f0..2f804c750 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -11,7 +11,7 @@ use orion::operators::tensor::core::{ use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP32x32, FP32x32Impl}; use orion::numbers::fixed_point::implementations::fp32x32::core::ONE; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP32x32Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -373,7 +373,7 @@ impl FP32x32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index fea845ce4..6e8ec0dc0 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -11,7 +11,7 @@ use orion::operators::tensor::core::{ use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP64x64, FP64x64Impl}; use orion::numbers::fixed_point::implementations::fp64x64::core::ONE; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP64x64Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -373,7 +373,7 @@ impl FP64x64Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 2d00eded0..7ef733cfc 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23}; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP8x23Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -373,7 +373,7 @@ impl FP8x23Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index 8f153c592..a81f87d20 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait, FP8x23W}; -use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor}; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl FP8x23WTensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -323,7 +323,7 @@ impl FP8x23WTensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index 6a41b927e..e54dc6a35 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i32, i8, NumberTrait}; -use orion::operators::tensor::implementations::{tensor_u32::U32Tensor, tensor_i8::I8Tensor}; +use orion::operators::tensor::implementations::{tensor_u32::U32Tensor, tensor_i8::I8Tensor, tensor_bool::BoolTensor}; impl I32Tensor of TensorTrait { @@ -371,7 +371,7 @@ impl I32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 9862907fd..56386bdd1 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; -use orion::operators::tensor::implementations::tensor_u32::U32Tensor; +use orion::operators::tensor::implementations::{tensor_u32::U32Tensor, tensor_bool::BoolTensor}; impl I8Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -371,7 +371,7 @@ impl I8Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 05084e743..003ed3380 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -10,7 +10,7 @@ use orion::operators::tensor::core::{ }; use orion::operators::tensor::{math, linalg, quantization, core, ml}; use orion::numbers::{i8, i32, NumberTrait}; -use orion::operators::tensor::implementations::tensor_i8::I8Tensor; +use orion::operators::tensor::implementations::{tensor_i8::I8Tensor, tensor_bool::BoolTensor}; impl U32Tensor of TensorTrait { fn new(shape: Span, data: Span) -> Tensor { @@ -315,7 +315,7 @@ impl U32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/math/and.cairo b/src/operators/tensor/math/and.cairo index 80872185e..1f31dc8de 100644 --- a/src/operators/tensor/math/and.cairo +++ b/src/operators/tensor/math/and.cairo @@ -13,14 +13,14 @@ fn and< T, MAG, impl TNumber: NumberTrait, - impl UsizeFTensor: TensorTrait, + impl UsizeFTensor: TensorTrait, impl TCopy: Copy, impl TDrop: Drop >( y: @Tensor, z: @Tensor -) -> Tensor { +) -> Tensor { let broadcasted_shape = broadcast_shape(*y.shape, *z.shape); - let mut result: Array = ArrayTrait::new(); + let mut result: Array = ArrayTrait::new(); let num_elements = len_from_shape(broadcasted_shape); @@ -32,9 +32,9 @@ fn and< let indices_other = broadcast_index_mapping(*z.shape, indices_broadcasted); if NumberTrait::and(*(*y.data)[indices_self], *(*z.data)[indices_other]) { - result.append(1); + result.append(true); } else { - result.append(0); + result.append(false); } n += 1; diff --git a/tests/nodes.cairo b/tests/nodes.cairo index f7986bb13..7caafcc03 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,831 +1,831 @@ -mod abs_fp16x16; -mod abs_fp8x23; -mod abs_i32; -mod abs_i8; -mod acos_fp16x16; -mod acos_fp8x23; -mod acosh_fp16x16; -mod acosh_fp8x23; -mod add_fp16x16; -mod add_fp16x16_broadcast; -mod add_fp8x23; -mod add_fp8x23_broadcast; -mod add_i32; -mod add_i32_broadcast; -mod add_i8; -mod add_i8_broadcast; -mod add_u32; -mod add_u32_broadcast; -mod argmax_fp16x16_1D_default; -mod argmax_fp16x16_1D_keepdims_false; -mod argmax_fp16x16_1D_last_index; -mod argmax_fp16x16_2D_default; -mod argmax_fp16x16_2D_keepdims_false; -mod argmax_fp16x16_2D_last_index; -mod argmax_fp16x16_3D_default; -mod argmax_fp16x16_3D_keepdims_false; -mod argmax_fp16x16_3D_last_index; -mod argmax_fp8x23_1D_default; -mod argmax_fp8x23_1D_keepdims_false; -mod argmax_fp8x23_1D_last_index; -mod argmax_fp8x23_2D_default; -mod argmax_fp8x23_2D_keepdims_false; -mod argmax_fp8x23_2D_last_index; -mod argmax_fp8x23_3D_default; -mod argmax_fp8x23_3D_keepdims_false; -mod argmax_fp8x23_3D_last_index; -mod argmax_i32_1D_default; -mod argmax_i32_1D_keepdims_false; -mod argmax_i32_1D_last_index; -mod argmax_i32_2D_default; -mod argmax_i32_2D_keepdims_false; -mod argmax_i32_2D_last_index; -mod argmax_i32_3D_default; -mod argmax_i32_3D_keepdims_false; -mod argmax_i32_3D_last_index; -mod argmax_i8_1D_default; -mod argmax_i8_1D_keepdims_false; -mod argmax_i8_1D_last_index; -mod argmax_i8_2D_default; -mod argmax_i8_2D_keepdims_false; -mod argmax_i8_2D_last_index; -mod argmax_i8_3D_default; -mod argmax_i8_3D_keepdims_false; -mod argmax_i8_3D_last_index; -mod argmax_u32_1D_default; -mod argmax_u32_1D_keepdims_false; -mod argmax_u32_1D_last_index; -mod argmax_u32_2D_default; -mod argmax_u32_2D_keepdims_false; -mod argmax_u32_2D_last_index; -mod argmax_u32_3D_default; -mod argmax_u32_3D_keepdims_false; -mod argmax_u32_3D_last_index; -mod argmin_fp16x16_1D_default; -mod argmin_fp16x16_1D_keepdims_false; -mod argmin_fp16x16_1D_last_index; -mod argmin_fp16x16_2D_default; -mod argmin_fp16x16_2D_keepdims_false; -mod argmin_fp16x16_2D_last_index; -mod argmin_fp16x16_3D_default; -mod argmin_fp16x16_3D_keepdims_false; -mod argmin_fp16x16_3D_last_index; -mod argmin_fp8x23_1D_default; -mod argmin_fp8x23_1D_keepdims_false; -mod argmin_fp8x23_1D_last_index; -mod argmin_fp8x23_2D_default; -mod argmin_fp8x23_2D_keepdims_false; -mod argmin_fp8x23_2D_last_index; -mod argmin_fp8x23_3D_default; -mod argmin_fp8x23_3D_keepdims_false; -mod argmin_fp8x23_3D_last_index; -mod argmin_i32_1D_default; -mod argmin_i32_1D_keepdims_false; -mod argmin_i32_1D_last_index; -mod argmin_i32_2D_default; -mod argmin_i32_2D_keepdims_false; -mod argmin_i32_2D_last_index; -mod argmin_i32_3D_default; -mod argmin_i32_3D_keepdims_false; -mod argmin_i32_3D_last_index; -mod argmin_i8_1D_default; -mod argmin_i8_1D_keepdims_false; -mod argmin_i8_1D_last_index; -mod argmin_i8_2D_default; -mod argmin_i8_2D_keepdims_false; -mod argmin_i8_2D_last_index; -mod argmin_i8_3D_default; -mod argmin_i8_3D_keepdims_false; -mod argmin_i8_3D_last_index; -mod argmin_u32_1D_default; -mod argmin_u32_1D_keepdims_false; -mod argmin_u32_1D_last_index; -mod argmin_u32_2D_default; -mod argmin_u32_2D_keepdims_false; -mod argmin_u32_2D_last_index; -mod argmin_u32_3D_default; -mod argmin_u32_3D_keepdims_false; -mod argmin_u32_3D_last_index; -mod asin_fp16x16; -mod asin_fp8x23; -mod asinh_fp16x16; -mod asinh_fp8x23; -mod atan_fp16x16; -mod atan_fp8x23; -mod ceil_fp16x16; -mod ceil_fp8x23; -mod concat_fp16x16_1d; -mod concat_fp16x16_2d; -mod concat_fp16x16_3d_default; -mod concat_fp16x16_3d_axis_1; -mod concat_fp16x16_3d_axis_2; -mod concat_fp16x16_3d_three_tensors_axis_1; -mod concat_fp16x16_3d_three_tensors_axis_2; -mod concat_fp8x23_1d; -mod concat_fp8x23_2d; -mod concat_fp8x23_3d_default; -mod concat_fp8x23_3d_axis_1; -mod concat_fp8x23_3d_axis_2; -mod concat_fp8x23_3d_three_tensors_axis_1; -mod concat_fp8x23_3d_three_tensors_axis_2; -mod concat_i32_1d; -mod concat_i32_2d; -mod concat_i32_3d_default; -mod concat_i32_3d_axis_1; -mod concat_i32_3d_axis_2; -mod concat_i32_3d_three_tensors_axis_1; -mod concat_i32_3d_three_tensors_axis_2; -mod concat_i8_1d; -mod concat_i8_2d; -mod concat_i8_3d_default; -mod concat_i8_3d_axis_1; -mod concat_i8_3d_axis_2; -mod concat_i8_3d_three_tensors_axis_1; -mod concat_i8_3d_three_tensors_axis_2; -mod concat_u32_1d; -mod concat_u32_2d; -mod concat_u32_3d_default; -mod concat_u32_3d_axis_1; -mod concat_u32_3d_axis_2; -mod concat_u32_3d_three_tensors_axis_1; -mod concat_u32_3d_three_tensors_axis_2; -mod cos_fp16x16; -mod cos_fp8x23; -mod cosh_fp16x16; -mod cosh_fp8x23; -mod cumsum_fp16x16_1d_default; -mod cumsum_fp16x16_1d_exclusive; -mod cumsum_fp16x16_1d_reverse; -mod cumsum_fp16x16_1d_reverse_exclusive; -mod cumsum_fp16x16_2d_axis_0; -mod cumsum_fp16x16_2d_axis_1; -mod cumsum_fp8x23_1d_default; -mod cumsum_fp8x23_1d_exclusive; -mod cumsum_fp8x23_1d_reverse; -mod cumsum_fp8x23_1d_reverse_exclusive; -mod cumsum_fp8x23_2d_axis_0; -mod cumsum_fp8x23_2d_axis_1; -mod cumsum_i32_1d_default; -mod cumsum_i32_1d_exclusive; -mod cumsum_i32_1d_reverse; -mod cumsum_i32_1d_reverse_exclusive; -mod cumsum_i32_2d_axis_0; -mod cumsum_i32_2d_axis_1; -mod cumsum_i8_1d_default; -mod cumsum_i8_1d_exclusive; -mod cumsum_i8_1d_reverse; -mod cumsum_i8_1d_reverse_exclusive; -mod cumsum_i8_2d_axis_0; -mod cumsum_i8_2d_axis_1; -mod cumsum_u32_1d_default; -mod cumsum_u32_1d_exclusive; -mod cumsum_u32_1d_reverse; -mod cumsum_u32_1d_reverse_exclusive; -mod cumsum_u32_2d_axis_0; -mod cumsum_u32_2d_axis_1; -mod div_fp16x16; -mod div_fp16x16_broadcast; -mod div_fp8x23; -mod div_fp8x23_broadcast; -mod div_i32; -mod div_i32_broadcast; -mod div_i8; -mod div_i8_broadcast; -mod div_u32; -mod div_u32_broadcast; -mod equal_fp16x16; -mod equal_fp16x16_broadcast; -mod equal_fp8x23; -mod equal_fp8x23_broadcast; -mod equal_i32; -mod equal_i32_broadcast; -mod equal_i8; -mod equal_i8_broadcast; -mod equal_u32; -mod equal_u32_broadcast; -mod exp_fp16x16; -mod exp_fp8x23; -mod less_equal_fp16x16; -mod less_equal_fp16x16_broadcast; -mod less_equal_fp8x23; -mod less_equal_fp8x23_broadcast; -mod less_equal_i32; -mod less_equal_i32_broadcast; -mod less_equal_i8; -mod less_equal_i8_broadcast; -mod less_equal_u32; -mod less_equal_u32_broadcast; -mod greater_fp16x16; -mod greater_fp16x16_broadcast; -mod greater_fp8x23; -mod greater_fp8x23_broadcast; -mod greater_i32; -mod greater_i32_broadcast; -mod greater_i8; -mod greater_i8_broadcast; -mod greater_u32; -mod greater_u32_broadcast; -mod leaky_relu_fp16x16; -mod leaky_relu_fp8x23; -mod linear_fp16x16; -mod linear_fp8x23; -mod linear_i32; -mod linear_i8; -mod linear_u32; -mod log_fp16x16; -mod log_fp8x23; -mod logsoftmax_fp16x16_axis_0; -mod logsoftmax_fp16x16_axis_1; -mod logsoftmax_fp8x23_axis_0; -mod logsoftmax_fp8x23_axis_1; -mod matmul_fp16x16_1d; -mod matmul_fp16x16_2x2; -mod matmul_fp16x16_2x1; -mod matmul_fp16x16_1x2; -mod matmul_fp8x23_1d; -mod matmul_fp8x23_2x2; -mod matmul_fp8x23_2x1; -mod matmul_fp8x23_1x2; -mod matmul_i32_1d; -mod matmul_i32_2x2; -mod matmul_i32_2x1; -mod matmul_i32_1x2; -mod matmul_i8_1d; -mod matmul_i8_2x2; -mod matmul_i8_2x1; -mod matmul_i8_1x2; -mod matmul_u32_1d; -mod matmul_u32_2x2; -mod matmul_u32_2x1; -mod matmul_u32_1x2; -mod mul_fp16x16; -mod mul_fp16x16_broadcast; -mod mul_fp8x23; -mod mul_fp8x23_broadcast; -mod mul_i32; -mod mul_i32_broadcast; -mod mul_i8; -mod mul_i8_broadcast; -mod mul_u32; -mod mul_u32_broadcast; -mod or_fp16x16; -mod or_fp16x16_broadcast; -mod or_fp8x23; -mod or_fp8x23_broadcast; -mod or_i32; -mod or_i32_broadcast; -mod or_i8; -mod or_i8_broadcast; -mod or_u32; -mod or_u32_broadcast; -mod reduce_sum_fp16x16_1D; -mod reduce_sum_fp16x16_2D_default; -mod reduce_sum_fp16x16_2D_keepdims; -mod reduce_sum_fp16x16_2D_axis_1; -mod reduce_sum_fp8x23_1D; -mod reduce_sum_fp8x23_2D_default; -mod reduce_sum_fp8x23_2D_keepdims; -mod reduce_sum_fp8x23_2D_axis_1; -mod reduce_sum_i32_1D; -mod reduce_sum_i32_2D_default; -mod reduce_sum_i32_2D_keepdims; -mod reduce_sum_i32_2D_axis_1; -mod reduce_sum_i8_1D; -mod reduce_sum_i8_2D_default; -mod reduce_sum_i8_2D_keepdims; -mod reduce_sum_i8_2D_axis_1; -mod reduce_sum_u32_1D; -mod reduce_sum_u32_2D_default; -mod reduce_sum_u32_2D_keepdims; -mod reduce_sum_u32_2D_axis_1; -mod relu_fp16x16; -mod relu_fp8x23; -mod relu_i32; -mod relu_i8; -mod sigmoid_fp16x16; -mod sigmoid_fp8x23; -mod sin_fp16x16; -mod sin_fp8x23; -mod sinh_fp16x16; -mod sinh_fp8x23; -mod softmax_fp16x16; -mod softmax_fp8x23; -mod softplus_fp8x23; -mod softplus_fp16x16; -mod softsign_fp8x23; -mod softsign_fp16x16; -mod sqrt_fp16x16; -mod sqrt_fp8x23; -mod sub_fp16x16; -mod sub_fp16x16_broadcast; -mod sub_fp8x23; -mod sub_fp8x23_broadcast; -mod sub_i32; -mod sub_i32_broadcast; -mod sub_i8; -mod sub_i8_broadcast; -mod sub_u32; -mod sub_u32_broadcast; -mod tanh_fp16x16; -mod tanh_fp8x23; -mod transpose_fp16x16_2d; -mod transpose_fp16x16_3d; -mod transpose_fp8x23_2d; -mod transpose_fp8x23_3d; -mod transpose_i32_2d; -mod transpose_i32_3d; -mod transpose_i8_2d; -mod transpose_i8_3d; -mod transpose_u32_2d; -mod transpose_u32_3d; -mod xor_fp16x16; -mod xor_fp16x16_broadcast; -mod xor_fp8x23; -mod xor_fp8x23_broadcast; -mod xor_i32; -mod xor_i32_broadcast; -mod xor_i8; -mod xor_i8_broadcast; -mod xor_u32; -mod xor_u32_broadcast; -mod less_fp16x16; -mod less_fp16x16_broadcast; -mod less_fp8x23; -mod less_fp8x23_broadcast; -mod less_i32; -mod less_i32_broadcast; -mod less_i8; -mod less_i8_broadcast; -mod less_u32; -mod less_u32_broadcast; -mod greater_equal_fp16x16; -mod greater_equal_fp16x16_broadcast; -mod greater_equal_fp8x23; -mod greater_equal_fp8x23_broadcast; -mod greater_equal_i32; -mod greater_equal_i32_broadcast; -mod greater_equal_i8; -mod greater_equal_i8_broadcast; -mod greater_equal_u32; -mod greater_equal_u32_broadcast; -mod slice_fp16x16_2d; -mod slice_fp16x16_3d; -mod slice_fp8x23_2d; -mod slice_fp8x23_3d; -mod slice_i32_2d; -mod slice_i32_3d; -mod slice_i8_2d; -mod slice_i8_3d; -mod slice_u32_2d; -mod slice_u32_3d; -mod gather_fp8x23_3d_default; -mod gather_fp8x23_3d_axis1; -mod gather_fp8x23_3d_axis2; -mod gather_fp16x16_3d_default; -mod gather_fp16x16_3d_axis1; -mod gather_fp16x16_3d_axis2; -mod gather_i8_3d_default; -mod gather_i8_3d_axis1; -mod gather_i8_3d_axis2; -mod gather_i32_3d_default; -mod gather_i32_3d_axis1; -mod gather_i32_3d_axis2; -mod gather_u32_3d_default; -mod gather_u32_3d_axis1; -mod gather_u32_3d_axis2; -mod nonzero_fp16x16_2d; -mod nonzero_fp16x16_3d; -mod nonzero_fp8x23_2d; -mod nonzero_fp8x23_3d; -mod nonzero_i32_2d; -mod nonzero_i32_3d; -mod nonzero_i8_2d; -mod nonzero_i8_3d; -mod nonzero_u32_2d; -mod nonzero_u32_3d; -mod squeeze_fP16x16; -mod squeeze_fP8x23; -mod squeeze_i32; -mod squeeze_i8; -mod squeeze_u32; -mod unsqueeze_fp16x16_2d; -mod unsqueeze_fp16x16_3d; -mod unsqueeze_fp8x23_2d; -mod unsqueeze_fp8x23_3d; -mod unsqueeze_i32_2d; -mod unsqueeze_i32_3d; -mod unsqueeze_i8_2d; -mod unsqueeze_i8_3d; -mod unsqueeze_u32_2d; -mod unsqueeze_u32_3d; -mod sign_fP16x16; -mod sign_fP8x23; -mod sign_fail; -mod sign_i32; -mod sign_i8; -mod clip_fp16x16_2d; -mod clip_fp16x16_3d; -mod clip_fp8x23_2d; -mod clip_fp8x23_3d; -mod clip_i32_2d; -mod clip_i32_3d; -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; -mod identity_fP16x16; -mod identity_fP8x23; -mod identity_i32; -mod identity_i8; -mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; -mod where_fp16x16; -mod where_fp16x16_broadcast; -mod where_fp8x23; -mod where_fp8x23_broadcast; -mod where_i32; -mod where_i32_broadcast; -mod where_i8; -mod where_i8_broadcast; -mod where_u32; -mod where_u32_broadcast; -mod not_bool; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_1D_i32; -mod array_feature_extractor_1D_fp8x23; -mod array_feature_extractor_1D_fp16x16; -mod array_feature_extractor_2D_i32; -mod array_feature_extractor_2D_fp8x23; -mod array_feature_extractor_2D_fp16x16; -mod array_feature_extractor_3D_i32; -mod array_feature_extractor_3D_fp8x23; -mod array_feature_extractor_3D_fp16x16; -mod binarizer_fp16x16; -mod binarizer_fp8x23; -mod tril_fp16x16; -mod tril_fp16x16_neg; -mod tril_fp16x16_one_row; -mod tril_fp16x16_out_neg; -mod tril_fp16x16_out_pos; -mod tril_fp16x16_pos; -mod tril_fp16x16_square; -mod tril_fp16x16_square_neg; -mod tril_fp16x16_zero; -mod triu_fp16x16; -mod triu_fp16x16_neg; -mod triu_fp16x16_one_row; -mod triu_fp16x16_out_neg; -mod triu_fp16x16_out_pos; -mod triu_fp16x16_pos; -mod triu_fp16x16_square; -mod triu_fp16x16_square_neg; -mod triu_fp16x16_zero; -mod tril_fp8x23; -mod tril_fp8x23_neg; -mod tril_fp8x23_one_row; -mod tril_fp8x23_out_neg; -mod tril_fp8x23_out_pos; -mod tril_fp8x23_pos; -mod tril_fp8x23_square; -mod tril_fp8x23_square_neg; -mod tril_fp8x23_zero; -mod triu_fp8x23; -mod triu_fp8x23_neg; -mod triu_fp8x23_one_row; -mod triu_fp8x23_out_neg; -mod triu_fp8x23_out_pos; -mod triu_fp8x23_pos; -mod triu_fp8x23_square; -mod triu_fp8x23_square_neg; -mod triu_fp8x23_zero; -mod tril_i32; -mod tril_neg_i32; -mod tril_i32_one_row; -mod tril_i32_out_neg; -mod tril_i32_out_pos; -mod tril_i32_pos; -mod tril_i32_square; -mod tril_i32_square_neg; -mod tril_i32_zero; -mod triu_i32; -mod triu_i32_neg; -mod triu_i32_one_row; -mod triu_i32_out_neg; -mod triu_i32_out_pos; -mod triu_i32_pos; -mod triu_i32_square; -mod triu_i32_square_neg; -mod triu_i32_zero; -mod tril_i8; -mod tril_i8_neg; -mod tril_i8_one_row; -mod tril_i8_out_neg; -mod tril_i8_out_pos; -mod tril_i8_pos; -mod tril_i8_square; -mod tril_i8_square_neg; -mod tril_i8_zero; -mod triu_i8; -mod triu_i8_neg; -mod triu_i8_one_row; -mod triu_i8_out_neg; -mod triu_i8_out_pos; -mod triu_i8_pos; -mod triu_i8_square; -mod triu_i8_square_neg; -mod triu_i8_zero; -mod tril_u32; -mod tril_u32_neg; -mod tril_u32_one_row; -mod tril_u32_out_neg; -mod tril_u32_out_pos; -mod tril_u32_pos; -mod tril_u32_square; -mod tril_u32_square_neg; -mod tril_u32_zero; -mod triu_u32; -mod triu_u32_neg; -mod triu_u32_one_row; -mod triu_u32_out_neg; -mod triu_u32_out_pos; -mod triu_u32_pos; -mod triu_u32_square; -mod triu_u32_square_neg; -mod triu_u32_zero; -mod reduce_sum_square_fp16x16_export_do_not_keepdims; -mod reduce_sum_square_fp16x16_export_keepdims; -mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; -mod reduce_sum_square_fp8x23_export_do_not_keepdims; -mod reduce_sum_square_fp8x23_export_keepdims; -mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; -mod reduce_sum_square_i32_export_do_not_keepdims; -mod reduce_sum_square_i32_export_keepdims; -mod reduce_sum_square_i32_export_negative_axes_keepdims; -mod reduce_sum_square_i8_export_do_not_keepdims; -mod reduce_sum_square_i8_export_keepdims; -mod reduce_sum_square_i8_export_negative_axes_keepdims; -mod reduce_sum_square_u32_export_do_not_keepdims; -mod reduce_sum_square_u32_export_keepdims; -mod reduce_sum_square_u32_export_negative_axes_keepdims; -mod reduce_l2_fp16x16_export_do_not_keepdims; -mod reduce_l2_fp16x16_export_keepdims; -mod reduce_l2_fp16x16_export_negative_axes_keepdims; -mod reduce_l2_fp8x23_export_do_not_keepdims; -mod reduce_l2_fp8x23_export_keepdims; -mod reduce_l2_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_fp16x16_export_do_not_keepdims; -mod reduce_l1_fp16x16_export_keepdims; -mod reduce_l1_fp16x16_export_negative_axes_keepdims; -mod reduce_l1_fp8x23_export_do_not_keepdims; -mod reduce_l1_fp8x23_export_keepdims; -mod reduce_l1_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_i32_export_do_not_keepdims; -mod reduce_l1_i32_export_keepdims; -mod reduce_l1_i32_export_negative_axes_keepdims; -mod reduce_l1_i8_export_do_not_keepdims; -mod reduce_l1_i8_export_keepdims; -mod reduce_l1_i8_export_negative_axes_keepdims; -mod reduce_l1_u32_export_do_not_keepdims; -mod reduce_l1_u32_export_keepdims; -mod reduce_l1_u32_export_negative_axes_keepdims; -mod reduce_prod_fp16x16_1D; -mod reduce_prod_fp16x16_2D_default; -mod reduce_prod_fp16x16_2D_keepdims; -mod reduce_prod_fp16x16_2D_axis_1; -mod reduce_prod_fp8x23_1D; -mod reduce_prod_fp8x23_2D_default; -mod reduce_prod_fp8x23_2D_keepdims; -mod reduce_prod_fp8x23_2D_axis_1; -mod reduce_prod_i32_1D; -mod reduce_prod_i32_2D_default; -mod reduce_prod_i32_2D_keepdims; -mod reduce_prod_i32_2D_axis_1; -mod reduce_prod_i8_1D; -mod reduce_prod_i8_2D_default; -mod reduce_prod_i8_2D_keepdims; -mod reduce_prod_i8_2D_axis_1; -mod reduce_prod_u32_1D; -mod reduce_prod_u32_2D_default; -mod reduce_prod_u32_2D_keepdims; -mod reduce_prod_u32_2D_axis_1; -mod gather_elements_fp16x16_3d_default; -mod gather_elements_fp16x16_3d_axis1; -mod gather_elements_fp16x16_3d_axis2; -mod gather_elements_fp8x23_3d_default; -mod gather_elements_fp8x23_3d_axis1; -mod gather_elements_fp8x23_3d_axis2; -mod gather_elements_i8_3d_default; -mod gather_elements_i8_3d_axis1; -mod gather_elements_i32_3d_default; -mod gather_elements_i32_3d_axis1; -mod gather_elements_i32_3d_axis2; -mod gather_elements_u32_default; -mod gather_elements_u32_axis1; -mod gather_elements_u32_axis2; -mod gather_elements_u32_axis3; -mod sequence_length_fp16x16; -mod sequence_length_fp16x16_broadcast; -mod sequence_length_fp8x23; -mod sequence_length_fp8x23_broadcast; -mod sequence_length_i32; -mod sequence_length_i32_broadcast; -mod sequence_length_i8; -mod sequence_length_i8_broadcast; -mod sequence_length_u32; -mod sequence_length_u32_broadcast; -mod sequence_at_u32_positive; -mod sequence_at_u32_negative; -mod sequence_at_fp16x16_positive; -mod sequence_at_fp16x16_negative; -mod sequence_at_fp8x23_positive; -mod sequence_at_fp8x23_negative; -mod sequence_at_i32_positive; -mod sequence_at_i32_negative; -mod sequence_at_i8_positive; -mod sequence_at_i8_negative; -mod reduce_min_fp16x16_1D; -mod reduce_min_fp16x16_2D_default; -mod reduce_min_fp16x16_2D_keepdims; -mod reduce_min_fp16x16_2D_axis_1; -mod reduce_min_fp8x23_1D; -mod reduce_min_fp8x23_2D_default; -mod reduce_min_fp8x23_2D_keepdims; -mod reduce_min_fp8x23_2D_axis_1; -mod reduce_min_i32_1D; -mod reduce_min_i32_2D_default; -mod reduce_min_i32_2D_keepdims; -mod reduce_min_i32_2D_axis_1; -mod reduce_min_i8_1D; -mod reduce_min_i8_2D_default; -mod reduce_min_i8_2D_keepdims; -mod reduce_min_i8_2D_axis_1; -mod reduce_min_u32_1D; -mod reduce_min_u32_2D_default; -mod reduce_min_u32_2D_keepdims; -mod reduce_min_u32_2D_axis_1; -mod sequence_construct_fp16x16; -mod sequence_construct_fp8x23; -mod sequence_construct_i32; -mod sequence_construct_i8; -mod sequence_construct_u32; -mod shrink_hard_fp16x16; -mod shrink_soft_fp16x16; -mod shrink_hard_fp8x23; -mod shrink_soft_fp8x23; -mod sequence_empty_fp16x16; -mod sequence_empty_fp8x23; -mod sequence_empty_i32; -mod sequence_empty_i8; -mod sequence_empty_u32; -mod reduce_mean_fp16x16_1D; -mod reduce_mean_fp16x16_2D_default; -mod reduce_mean_fp16x16_2D_keepdims; -mod reduce_mean_fp16x16_2D_axis_1; -mod reduce_mean_fp8x23_1D; -mod reduce_mean_fp8x23_2D_default; -mod reduce_mean_fp8x23_2D_keepdims; -mod reduce_mean_fp8x23_2D_axis_1; -mod reduce_mean_i32_1D; -mod reduce_mean_i32_2D_default; -mod reduce_mean_i32_2D_keepdims; -mod reduce_mean_i32_2D_axis_1; -mod reduce_mean_i8_1D; -mod reduce_mean_i8_2D_default; -mod reduce_mean_i8_2D_keepdims; -mod reduce_mean_i8_2D_axis_1; -mod reduce_mean_u32_1D; -mod reduce_mean_u32_2D_default; -mod reduce_mean_u32_2D_keepdims; -mod reduce_mean_u32_2D_axis_1; -mod pow_fp16x16; -mod pow_fp16x16_broadcast; -mod pow_fp8x23; -mod pow_fp8x23_broadcast; -mod sequence_erase_u32_positive; -mod sequence_erase_u32_negative; -mod sequence_erase_u32_empty; -mod sequence_erase_fp16x16_positive; -mod sequence_erase_fp16x16_negative; -mod sequence_erase_fp16x16_empty; -mod sequence_erase_fp8x23_positive; -mod sequence_erase_fp8x23_negative; -mod sequence_erase_fp8x23_empty; -mod sequence_erase_i32_positive; -mod sequence_erase_i32_negative; -mod sequence_erase_i32_empty; -mod sequence_erase_i8_positive; -mod sequence_erase_i8_negative; -mod sequence_erase_i8_empty; -mod sequence_insert_fp16x16; -mod sequence_insert_fp8x23; -mod sequence_insert_i32; -mod sequence_insert_i8; -mod sequence_insert_u32; -mod concat_from_sequence_fp8x23_new_axis_zero; -mod concat_from_sequence_fp8x23_new_axis_one; -mod concat_from_sequence_fp8x23_new_axis_default; -mod concat_from_sequence_fp16x16_new_axis_zero; -mod concat_from_sequence_fp16x16_new_axis_one; -mod concat_from_sequence_fp16x16_new_axis_default; -mod concat_from_sequence_i32_new_axis_zero; -mod concat_from_sequence_i32_new_axis_one; -mod concat_from_sequence_i32_new_axis_default; -mod concat_from_sequence_i8_new_axis_zero; -mod concat_from_sequence_i8_new_axis_one; -mod concat_from_sequence_i8_new_axis_default; -mod concat_from_sequence_u32_new_axis_zero; -mod concat_from_sequence_u32_new_axis_one; -mod concat_from_sequence_u32_new_axis_default; -mod is_nan_fp16x16; -mod is_nan_fp8x23; -mod is_inf_fp16x16; -mod is_inf_fp8x23; -mod is_inf_i32; -mod is_inf_i8; -mod is_inf_u32; -mod is_pos_inf_fp16x16; -mod is_neg_inf_fp16x16; -mod is_pos_inf_fp8x23; -mod is_neg_inf_fp8x23; -mod is_pos_inf_i32; -mod is_neg_inf_i32; -mod is_pos_inf_i8; -mod is_neg_inf_i8; +// mod abs_fp16x16; +// mod abs_fp8x23; +// mod abs_i32; +// mod abs_i8; +// mod acos_fp16x16; +// mod acos_fp8x23; +// mod acosh_fp16x16; +// mod acosh_fp8x23; +// mod add_fp16x16; +// mod add_fp16x16_broadcast; +// mod add_fp8x23; +// mod add_fp8x23_broadcast; +// mod add_i32; +// mod add_i32_broadcast; +// mod add_i8; +// mod add_i8_broadcast; +// mod add_u32; +// mod add_u32_broadcast; +// mod argmax_fp16x16_1D_default; +// mod argmax_fp16x16_1D_keepdims_false; +// mod argmax_fp16x16_1D_last_index; +// mod argmax_fp16x16_2D_default; +// mod argmax_fp16x16_2D_keepdims_false; +// mod argmax_fp16x16_2D_last_index; +// mod argmax_fp16x16_3D_default; +// mod argmax_fp16x16_3D_keepdims_false; +// mod argmax_fp16x16_3D_last_index; +// mod argmax_fp8x23_1D_default; +// mod argmax_fp8x23_1D_keepdims_false; +// mod argmax_fp8x23_1D_last_index; +// mod argmax_fp8x23_2D_default; +// mod argmax_fp8x23_2D_keepdims_false; +// mod argmax_fp8x23_2D_last_index; +// mod argmax_fp8x23_3D_default; +// mod argmax_fp8x23_3D_keepdims_false; +// mod argmax_fp8x23_3D_last_index; +// mod argmax_i32_1D_default; +// mod argmax_i32_1D_keepdims_false; +// mod argmax_i32_1D_last_index; +// mod argmax_i32_2D_default; +// mod argmax_i32_2D_keepdims_false; +// mod argmax_i32_2D_last_index; +// mod argmax_i32_3D_default; +// mod argmax_i32_3D_keepdims_false; +// mod argmax_i32_3D_last_index; +// mod argmax_i8_1D_default; +// mod argmax_i8_1D_keepdims_false; +// mod argmax_i8_1D_last_index; +// mod argmax_i8_2D_default; +// mod argmax_i8_2D_keepdims_false; +// mod argmax_i8_2D_last_index; +// mod argmax_i8_3D_default; +// mod argmax_i8_3D_keepdims_false; +// mod argmax_i8_3D_last_index; +// mod argmax_u32_1D_default; +// mod argmax_u32_1D_keepdims_false; +// mod argmax_u32_1D_last_index; +// mod argmax_u32_2D_default; +// mod argmax_u32_2D_keepdims_false; +// mod argmax_u32_2D_last_index; +// mod argmax_u32_3D_default; +// mod argmax_u32_3D_keepdims_false; +// mod argmax_u32_3D_last_index; +// mod argmin_fp16x16_1D_default; +// mod argmin_fp16x16_1D_keepdims_false; +// mod argmin_fp16x16_1D_last_index; +// mod argmin_fp16x16_2D_default; +// mod argmin_fp16x16_2D_keepdims_false; +// mod argmin_fp16x16_2D_last_index; +// mod argmin_fp16x16_3D_default; +// mod argmin_fp16x16_3D_keepdims_false; +// mod argmin_fp16x16_3D_last_index; +// mod argmin_fp8x23_1D_default; +// mod argmin_fp8x23_1D_keepdims_false; +// mod argmin_fp8x23_1D_last_index; +// mod argmin_fp8x23_2D_default; +// mod argmin_fp8x23_2D_keepdims_false; +// mod argmin_fp8x23_2D_last_index; +// mod argmin_fp8x23_3D_default; +// mod argmin_fp8x23_3D_keepdims_false; +// mod argmin_fp8x23_3D_last_index; +// mod argmin_i32_1D_default; +// mod argmin_i32_1D_keepdims_false; +// mod argmin_i32_1D_last_index; +// mod argmin_i32_2D_default; +// mod argmin_i32_2D_keepdims_false; +// mod argmin_i32_2D_last_index; +// mod argmin_i32_3D_default; +// mod argmin_i32_3D_keepdims_false; +// mod argmin_i32_3D_last_index; +// mod argmin_i8_1D_default; +// mod argmin_i8_1D_keepdims_false; +// mod argmin_i8_1D_last_index; +// mod argmin_i8_2D_default; +// mod argmin_i8_2D_keepdims_false; +// mod argmin_i8_2D_last_index; +// mod argmin_i8_3D_default; +// mod argmin_i8_3D_keepdims_false; +// mod argmin_i8_3D_last_index; +// mod argmin_u32_1D_default; +// mod argmin_u32_1D_keepdims_false; +// mod argmin_u32_1D_last_index; +// mod argmin_u32_2D_default; +// mod argmin_u32_2D_keepdims_false; +// mod argmin_u32_2D_last_index; +// mod argmin_u32_3D_default; +// mod argmin_u32_3D_keepdims_false; +// mod argmin_u32_3D_last_index; +// mod asin_fp16x16; +// mod asin_fp8x23; +// mod asinh_fp16x16; +// mod asinh_fp8x23; +// mod atan_fp16x16; +// mod atan_fp8x23; +// mod ceil_fp16x16; +// mod ceil_fp8x23; +// mod concat_fp16x16_1d; +// mod concat_fp16x16_2d; +// mod concat_fp16x16_3d_default; +// mod concat_fp16x16_3d_axis_1; +// mod concat_fp16x16_3d_axis_2; +// mod concat_fp16x16_3d_three_tensors_axis_1; +// mod concat_fp16x16_3d_three_tensors_axis_2; +// mod concat_fp8x23_1d; +// mod concat_fp8x23_2d; +// mod concat_fp8x23_3d_default; +// mod concat_fp8x23_3d_axis_1; +// mod concat_fp8x23_3d_axis_2; +// mod concat_fp8x23_3d_three_tensors_axis_1; +// mod concat_fp8x23_3d_three_tensors_axis_2; +// mod concat_i32_1d; +// mod concat_i32_2d; +// mod concat_i32_3d_default; +// mod concat_i32_3d_axis_1; +// mod concat_i32_3d_axis_2; +// mod concat_i32_3d_three_tensors_axis_1; +// mod concat_i32_3d_three_tensors_axis_2; +// mod concat_i8_1d; +// mod concat_i8_2d; +// mod concat_i8_3d_default; +// mod concat_i8_3d_axis_1; +// mod concat_i8_3d_axis_2; +// mod concat_i8_3d_three_tensors_axis_1; +// mod concat_i8_3d_three_tensors_axis_2; +// mod concat_u32_1d; +// mod concat_u32_2d; +// mod concat_u32_3d_default; +// mod concat_u32_3d_axis_1; +// mod concat_u32_3d_axis_2; +// mod concat_u32_3d_three_tensors_axis_1; +// mod concat_u32_3d_three_tensors_axis_2; +// mod cos_fp16x16; +// mod cos_fp8x23; +// mod cosh_fp16x16; +// mod cosh_fp8x23; +// mod cumsum_fp16x16_1d_default; +// mod cumsum_fp16x16_1d_exclusive; +// mod cumsum_fp16x16_1d_reverse; +// mod cumsum_fp16x16_1d_reverse_exclusive; +// mod cumsum_fp16x16_2d_axis_0; +// mod cumsum_fp16x16_2d_axis_1; +// mod cumsum_fp8x23_1d_default; +// mod cumsum_fp8x23_1d_exclusive; +// mod cumsum_fp8x23_1d_reverse; +// mod cumsum_fp8x23_1d_reverse_exclusive; +// mod cumsum_fp8x23_2d_axis_0; +// mod cumsum_fp8x23_2d_axis_1; +// mod cumsum_i32_1d_default; +// mod cumsum_i32_1d_exclusive; +// mod cumsum_i32_1d_reverse; +// mod cumsum_i32_1d_reverse_exclusive; +// mod cumsum_i32_2d_axis_0; +// mod cumsum_i32_2d_axis_1; +// mod cumsum_i8_1d_default; +// mod cumsum_i8_1d_exclusive; +// mod cumsum_i8_1d_reverse; +// mod cumsum_i8_1d_reverse_exclusive; +// mod cumsum_i8_2d_axis_0; +// mod cumsum_i8_2d_axis_1; +// mod cumsum_u32_1d_default; +// mod cumsum_u32_1d_exclusive; +// mod cumsum_u32_1d_reverse; +// mod cumsum_u32_1d_reverse_exclusive; +// mod cumsum_u32_2d_axis_0; +// mod cumsum_u32_2d_axis_1; +// mod div_fp16x16; +// mod div_fp16x16_broadcast; +// mod div_fp8x23; +// mod div_fp8x23_broadcast; +// mod div_i32; +// mod div_i32_broadcast; +// mod div_i8; +// mod div_i8_broadcast; +// mod div_u32; +// mod div_u32_broadcast; +// mod equal_fp16x16; +// mod equal_fp16x16_broadcast; +// mod equal_fp8x23; +// mod equal_fp8x23_broadcast; +// mod equal_i32; +// mod equal_i32_broadcast; +// mod equal_i8; +// mod equal_i8_broadcast; +// mod equal_u32; +// mod equal_u32_broadcast; +// mod exp_fp16x16; +// mod exp_fp8x23; +// mod less_equal_fp16x16; +// mod less_equal_fp16x16_broadcast; +// mod less_equal_fp8x23; +// mod less_equal_fp8x23_broadcast; +// mod less_equal_i32; +// mod less_equal_i32_broadcast; +// mod less_equal_i8; +// mod less_equal_i8_broadcast; +// mod less_equal_u32; +// mod less_equal_u32_broadcast; +// mod greater_fp16x16; +// mod greater_fp16x16_broadcast; +// mod greater_fp8x23; +// mod greater_fp8x23_broadcast; +// mod greater_i32; +// mod greater_i32_broadcast; +// mod greater_i8; +// mod greater_i8_broadcast; +// mod greater_u32; +// mod greater_u32_broadcast; +// mod leaky_relu_fp16x16; +// mod leaky_relu_fp8x23; +// mod linear_fp16x16; +// mod linear_fp8x23; +// mod linear_i32; +// mod linear_i8; +// mod linear_u32; +// mod log_fp16x16; +// mod log_fp8x23; +// mod logsoftmax_fp16x16_axis_0; +// mod logsoftmax_fp16x16_axis_1; +// mod logsoftmax_fp8x23_axis_0; +// mod logsoftmax_fp8x23_axis_1; +// mod matmul_fp16x16_1d; +// mod matmul_fp16x16_2x2; +// mod matmul_fp16x16_2x1; +// mod matmul_fp16x16_1x2; +// mod matmul_fp8x23_1d; +// mod matmul_fp8x23_2x2; +// mod matmul_fp8x23_2x1; +// mod matmul_fp8x23_1x2; +// mod matmul_i32_1d; +// mod matmul_i32_2x2; +// mod matmul_i32_2x1; +// mod matmul_i32_1x2; +// mod matmul_i8_1d; +// mod matmul_i8_2x2; +// mod matmul_i8_2x1; +// mod matmul_i8_1x2; +// mod matmul_u32_1d; +// mod matmul_u32_2x2; +// mod matmul_u32_2x1; +// mod matmul_u32_1x2; +// mod mul_fp16x16; +// mod mul_fp16x16_broadcast; +// mod mul_fp8x23; +// mod mul_fp8x23_broadcast; +// mod mul_i32; +// mod mul_i32_broadcast; +// mod mul_i8; +// mod mul_i8_broadcast; +// mod mul_u32; +// mod mul_u32_broadcast; +// mod or_fp16x16; +// mod or_fp16x16_broadcast; +// mod or_fp8x23; +// mod or_fp8x23_broadcast; +// mod or_i32; +// mod or_i32_broadcast; +// mod or_i8; +// mod or_i8_broadcast; +// mod or_u32; +// mod or_u32_broadcast; +// mod reduce_sum_fp16x16_1D; +// mod reduce_sum_fp16x16_2D_default; +// mod reduce_sum_fp16x16_2D_keepdims; +// mod reduce_sum_fp16x16_2D_axis_1; +// mod reduce_sum_fp8x23_1D; +// mod reduce_sum_fp8x23_2D_default; +// mod reduce_sum_fp8x23_2D_keepdims; +// mod reduce_sum_fp8x23_2D_axis_1; +// mod reduce_sum_i32_1D; +// mod reduce_sum_i32_2D_default; +// mod reduce_sum_i32_2D_keepdims; +// mod reduce_sum_i32_2D_axis_1; +// mod reduce_sum_i8_1D; +// mod reduce_sum_i8_2D_default; +// mod reduce_sum_i8_2D_keepdims; +// mod reduce_sum_i8_2D_axis_1; +// mod reduce_sum_u32_1D; +// mod reduce_sum_u32_2D_default; +// mod reduce_sum_u32_2D_keepdims; +// mod reduce_sum_u32_2D_axis_1; +// mod relu_fp16x16; +// mod relu_fp8x23; +// mod relu_i32; +// mod relu_i8; +// mod sigmoid_fp16x16; +// mod sigmoid_fp8x23; +// mod sin_fp16x16; +// mod sin_fp8x23; +// mod sinh_fp16x16; +// mod sinh_fp8x23; +// mod softmax_fp16x16; +// mod softmax_fp8x23; +// mod softplus_fp8x23; +// mod softplus_fp16x16; +// mod softsign_fp8x23; +// mod softsign_fp16x16; +// mod sqrt_fp16x16; +// mod sqrt_fp8x23; +// mod sub_fp16x16; +// mod sub_fp16x16_broadcast; +// mod sub_fp8x23; +// mod sub_fp8x23_broadcast; +// mod sub_i32; +// mod sub_i32_broadcast; +// mod sub_i8; +// mod sub_i8_broadcast; +// mod sub_u32; +// mod sub_u32_broadcast; +// mod tanh_fp16x16; +// mod tanh_fp8x23; +// mod transpose_fp16x16_2d; +// mod transpose_fp16x16_3d; +// mod transpose_fp8x23_2d; +// mod transpose_fp8x23_3d; +// mod transpose_i32_2d; +// mod transpose_i32_3d; +// mod transpose_i8_2d; +// mod transpose_i8_3d; +// mod transpose_u32_2d; +// mod transpose_u32_3d; +// mod xor_fp16x16; +// mod xor_fp16x16_broadcast; +// mod xor_fp8x23; +// mod xor_fp8x23_broadcast; +// mod xor_i32; +// mod xor_i32_broadcast; +// mod xor_i8; +// mod xor_i8_broadcast; +// mod xor_u32; +// mod xor_u32_broadcast; +// mod less_fp16x16; +// mod less_fp16x16_broadcast; +// mod less_fp8x23; +// mod less_fp8x23_broadcast; +// mod less_i32; +// mod less_i32_broadcast; +// mod less_i8; +// mod less_i8_broadcast; +// mod less_u32; +// mod less_u32_broadcast; +// mod greater_equal_fp16x16; +// mod greater_equal_fp16x16_broadcast; +// mod greater_equal_fp8x23; +// mod greater_equal_fp8x23_broadcast; +// mod greater_equal_i32; +// mod greater_equal_i32_broadcast; +// mod greater_equal_i8; +// mod greater_equal_i8_broadcast; +// mod greater_equal_u32; +// mod greater_equal_u32_broadcast; +// mod slice_fp16x16_2d; +// mod slice_fp16x16_3d; +// mod slice_fp8x23_2d; +// mod slice_fp8x23_3d; +// mod slice_i32_2d; +// mod slice_i32_3d; +// mod slice_i8_2d; +// mod slice_i8_3d; +// mod slice_u32_2d; +// mod slice_u32_3d; +// mod gather_fp8x23_3d_default; +// mod gather_fp8x23_3d_axis1; +// mod gather_fp8x23_3d_axis2; +// mod gather_fp16x16_3d_default; +// mod gather_fp16x16_3d_axis1; +// mod gather_fp16x16_3d_axis2; +// mod gather_i8_3d_default; +// mod gather_i8_3d_axis1; +// mod gather_i8_3d_axis2; +// mod gather_i32_3d_default; +// mod gather_i32_3d_axis1; +// mod gather_i32_3d_axis2; +// mod gather_u32_3d_default; +// mod gather_u32_3d_axis1; +// mod gather_u32_3d_axis2; +// mod nonzero_fp16x16_2d; +// mod nonzero_fp16x16_3d; +// mod nonzero_fp8x23_2d; +// mod nonzero_fp8x23_3d; +// mod nonzero_i32_2d; +// mod nonzero_i32_3d; +// mod nonzero_i8_2d; +// mod nonzero_i8_3d; +// mod nonzero_u32_2d; +// mod nonzero_u32_3d; +// mod squeeze_fP16x16; +// mod squeeze_fP8x23; +// mod squeeze_i32; +// mod squeeze_i8; +// mod squeeze_u32; +// mod unsqueeze_fp16x16_2d; +// mod unsqueeze_fp16x16_3d; +// mod unsqueeze_fp8x23_2d; +// mod unsqueeze_fp8x23_3d; +// mod unsqueeze_i32_2d; +// mod unsqueeze_i32_3d; +// mod unsqueeze_i8_2d; +// mod unsqueeze_i8_3d; +// mod unsqueeze_u32_2d; +// mod unsqueeze_u32_3d; +// mod sign_fP16x16; +// mod sign_fP8x23; +// mod sign_fail; +// mod sign_i32; +// mod sign_i8; +// mod clip_fp16x16_2d; +// mod clip_fp16x16_3d; +// mod clip_fp8x23_2d; +// mod clip_fp8x23_3d; +// mod clip_i32_2d; +// mod clip_i32_3d; +// 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; +// mod identity_fP16x16; +// mod identity_fP8x23; +// mod identity_i32; +// mod identity_i8; +// mod identity_u32; +// mod thresholded_relu_fp16x16; +// mod thresholded_relu_fp8x23; +// mod hard_sigmoid_fp8x23; +// mod hard_sigmoid_fp16x16; +// mod neg_fp16x16; +// mod neg_fp8x23; +// mod neg_i32; +// mod neg_i8; +// mod gemm_all_attributes; +// mod gemm_alpha; +// mod gemm_beta; +// mod gemm_default_matrix_bias; +// mod gemm_default_vector_bias; +// mod gemm_default_no_bias; +// mod gemm_transposeA; +// mod gemm_transposeB; +// mod min_fp16x16_three_tensors; +// mod min_fp16x16_broadcast_three_tensors; +// mod min_fp16x16_two_tensors; +// mod min_fp16x16_broadcast_two_tensors; +// mod min_fp8x23_three_tensors; +// mod min_fp8x23_broadcast_three_tensors; +// mod min_fp8x23_two_tensors; +// mod min_fp8x23_broadcast_two_tensors; +// mod min_i32_three_tensors; +// mod min_i32_broadcast_three_tensors; +// mod min_i32_two_tensors; +// mod min_i32_broadcast_two_tensors; +// mod min_i8_three_tensors; +// mod min_i8_broadcast_three_tensors; +// mod min_i8_two_tensors; +// mod min_i8_broadcast_two_tensors; +// mod min_u32_three_tensors; +// mod min_u32_broadcast_three_tensors; +// mod min_u32_two_tensors; +// mod min_u32_broadcast_two_tensors; +// mod where_fp16x16; +// mod where_fp16x16_broadcast; +// mod where_fp8x23; +// mod where_fp8x23_broadcast; +// mod where_i32; +// mod where_i32_broadcast; +// mod where_i8; +// mod where_i8_broadcast; +// mod where_u32; +// mod where_u32_broadcast; +// mod not_bool; +// mod round_fp16x16; +// mod round_fp8x23; +// mod max_fp16x16_three_tensors; +// mod max_fp16x16_broadcast_three_tensors; +// mod max_fp16x16_two_tensors; +// mod max_fp16x16_broadcast_two_tensors; +// mod max_fp8x23_three_tensors; +// mod max_fp8x23_broadcast_three_tensors; +// mod max_fp8x23_two_tensors; +// mod max_fp8x23_broadcast_two_tensors; +// mod max_i32_three_tensors; +// mod max_i32_broadcast_three_tensors; +// mod max_i32_two_tensors; +// mod max_i32_broadcast_two_tensors; +// mod max_i8_three_tensors; +// mod max_i8_broadcast_three_tensors; +// mod max_i8_two_tensors; +// mod max_i8_broadcast_two_tensors; +// mod max_u32_three_tensors; +// mod max_u32_broadcast_three_tensors; +// mod max_u32_two_tensors; +// mod max_u32_broadcast_two_tensors; +// mod scatter_fp16x16_3d_default; +// mod scatter_fp16x16_3d_axis1; +// mod scatter_fp16x16_3d_axis1_add; +// mod scatter_fp8x23_default; +// mod scatter_fp8x23_axis1; +// mod scatter_fp8x23_mul; +// mod scatter_i8_default; +// mod scatter_i8_axis1; +// mod scatter_i8_axis1_max; +// mod scatter_u32_default; +// mod scatter_u32_axis1; +// mod scatter_u32_add; +// mod array_feature_extractor_1D_i32; +// mod array_feature_extractor_1D_fp8x23; +// mod array_feature_extractor_1D_fp16x16; +// mod array_feature_extractor_2D_i32; +// mod array_feature_extractor_2D_fp8x23; +// mod array_feature_extractor_2D_fp16x16; +// mod array_feature_extractor_3D_i32; +// mod array_feature_extractor_3D_fp8x23; +// mod array_feature_extractor_3D_fp16x16; +// mod binarizer_fp16x16; +// mod binarizer_fp8x23; +// mod tril_fp16x16; +// mod tril_fp16x16_neg; +// mod tril_fp16x16_one_row; +// mod tril_fp16x16_out_neg; +// mod tril_fp16x16_out_pos; +// mod tril_fp16x16_pos; +// mod tril_fp16x16_square; +// mod tril_fp16x16_square_neg; +// mod tril_fp16x16_zero; +// mod triu_fp16x16; +// mod triu_fp16x16_neg; +// mod triu_fp16x16_one_row; +// mod triu_fp16x16_out_neg; +// mod triu_fp16x16_out_pos; +// mod triu_fp16x16_pos; +// mod triu_fp16x16_square; +// mod triu_fp16x16_square_neg; +// mod triu_fp16x16_zero; +// mod tril_fp8x23; +// mod tril_fp8x23_neg; +// mod tril_fp8x23_one_row; +// mod tril_fp8x23_out_neg; +// mod tril_fp8x23_out_pos; +// mod tril_fp8x23_pos; +// mod tril_fp8x23_square; +// mod tril_fp8x23_square_neg; +// mod tril_fp8x23_zero; +// mod triu_fp8x23; +// mod triu_fp8x23_neg; +// mod triu_fp8x23_one_row; +// mod triu_fp8x23_out_neg; +// mod triu_fp8x23_out_pos; +// mod triu_fp8x23_pos; +// mod triu_fp8x23_square; +// mod triu_fp8x23_square_neg; +// mod triu_fp8x23_zero; +// mod tril_i32; +// mod tril_neg_i32; +// mod tril_i32_one_row; +// mod tril_i32_out_neg; +// mod tril_i32_out_pos; +// mod tril_i32_pos; +// mod tril_i32_square; +// mod tril_i32_square_neg; +// mod tril_i32_zero; +// mod triu_i32; +// mod triu_i32_neg; +// mod triu_i32_one_row; +// mod triu_i32_out_neg; +// mod triu_i32_out_pos; +// mod triu_i32_pos; +// mod triu_i32_square; +// mod triu_i32_square_neg; +// mod triu_i32_zero; +// mod tril_i8; +// mod tril_i8_neg; +// mod tril_i8_one_row; +// mod tril_i8_out_neg; +// mod tril_i8_out_pos; +// mod tril_i8_pos; +// mod tril_i8_square; +// mod tril_i8_square_neg; +// mod tril_i8_zero; +// mod triu_i8; +// mod triu_i8_neg; +// mod triu_i8_one_row; +// mod triu_i8_out_neg; +// mod triu_i8_out_pos; +// mod triu_i8_pos; +// mod triu_i8_square; +// mod triu_i8_square_neg; +// mod triu_i8_zero; +// mod tril_u32; +// mod tril_u32_neg; +// mod tril_u32_one_row; +// mod tril_u32_out_neg; +// mod tril_u32_out_pos; +// mod tril_u32_pos; +// mod tril_u32_square; +// mod tril_u32_square_neg; +// mod tril_u32_zero; +// mod triu_u32; +// mod triu_u32_neg; +// mod triu_u32_one_row; +// mod triu_u32_out_neg; +// mod triu_u32_out_pos; +// mod triu_u32_pos; +// mod triu_u32_square; +// mod triu_u32_square_neg; +// mod triu_u32_zero; +// mod reduce_sum_square_fp16x16_export_do_not_keepdims; +// mod reduce_sum_square_fp16x16_export_keepdims; +// mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +// mod reduce_sum_square_fp8x23_export_do_not_keepdims; +// mod reduce_sum_square_fp8x23_export_keepdims; +// mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +// mod reduce_sum_square_i32_export_do_not_keepdims; +// mod reduce_sum_square_i32_export_keepdims; +// mod reduce_sum_square_i32_export_negative_axes_keepdims; +// mod reduce_sum_square_i8_export_do_not_keepdims; +// mod reduce_sum_square_i8_export_keepdims; +// mod reduce_sum_square_i8_export_negative_axes_keepdims; +// mod reduce_sum_square_u32_export_do_not_keepdims; +// mod reduce_sum_square_u32_export_keepdims; +// mod reduce_sum_square_u32_export_negative_axes_keepdims; +// mod reduce_l2_fp16x16_export_do_not_keepdims; +// mod reduce_l2_fp16x16_export_keepdims; +// mod reduce_l2_fp16x16_export_negative_axes_keepdims; +// mod reduce_l2_fp8x23_export_do_not_keepdims; +// mod reduce_l2_fp8x23_export_keepdims; +// mod reduce_l2_fp8x23_export_negative_axes_keepdims; +// mod reduce_l1_fp16x16_export_do_not_keepdims; +// mod reduce_l1_fp16x16_export_keepdims; +// mod reduce_l1_fp16x16_export_negative_axes_keepdims; +// mod reduce_l1_fp8x23_export_do_not_keepdims; +// mod reduce_l1_fp8x23_export_keepdims; +// mod reduce_l1_fp8x23_export_negative_axes_keepdims; +// mod reduce_l1_i32_export_do_not_keepdims; +// mod reduce_l1_i32_export_keepdims; +// mod reduce_l1_i32_export_negative_axes_keepdims; +// mod reduce_l1_i8_export_do_not_keepdims; +// mod reduce_l1_i8_export_keepdims; +// mod reduce_l1_i8_export_negative_axes_keepdims; +// mod reduce_l1_u32_export_do_not_keepdims; +// mod reduce_l1_u32_export_keepdims; +// mod reduce_l1_u32_export_negative_axes_keepdims; +// mod reduce_prod_fp16x16_1D; +// mod reduce_prod_fp16x16_2D_default; +// mod reduce_prod_fp16x16_2D_keepdims; +// mod reduce_prod_fp16x16_2D_axis_1; +// mod reduce_prod_fp8x23_1D; +// mod reduce_prod_fp8x23_2D_default; +// mod reduce_prod_fp8x23_2D_keepdims; +// mod reduce_prod_fp8x23_2D_axis_1; +// mod reduce_prod_i32_1D; +// mod reduce_prod_i32_2D_default; +// mod reduce_prod_i32_2D_keepdims; +// mod reduce_prod_i32_2D_axis_1; +// mod reduce_prod_i8_1D; +// mod reduce_prod_i8_2D_default; +// mod reduce_prod_i8_2D_keepdims; +// mod reduce_prod_i8_2D_axis_1; +// mod reduce_prod_u32_1D; +// mod reduce_prod_u32_2D_default; +// mod reduce_prod_u32_2D_keepdims; +// mod reduce_prod_u32_2D_axis_1; +// mod gather_elements_fp16x16_3d_default; +// mod gather_elements_fp16x16_3d_axis1; +// mod gather_elements_fp16x16_3d_axis2; +// mod gather_elements_fp8x23_3d_default; +// mod gather_elements_fp8x23_3d_axis1; +// mod gather_elements_fp8x23_3d_axis2; +// mod gather_elements_i8_3d_default; +// mod gather_elements_i8_3d_axis1; +// mod gather_elements_i32_3d_default; +// mod gather_elements_i32_3d_axis1; +// mod gather_elements_i32_3d_axis2; +// mod gather_elements_u32_default; +// mod gather_elements_u32_axis1; +// mod gather_elements_u32_axis2; +// mod gather_elements_u32_axis3; +// mod sequence_length_fp16x16; +// mod sequence_length_fp16x16_broadcast; +// mod sequence_length_fp8x23; +// mod sequence_length_fp8x23_broadcast; +// mod sequence_length_i32; +// mod sequence_length_i32_broadcast; +// mod sequence_length_i8; +// mod sequence_length_i8_broadcast; +// mod sequence_length_u32; +// mod sequence_length_u32_broadcast; +// mod sequence_at_u32_positive; +// mod sequence_at_u32_negative; +// mod sequence_at_fp16x16_positive; +// mod sequence_at_fp16x16_negative; +// mod sequence_at_fp8x23_positive; +// mod sequence_at_fp8x23_negative; +// mod sequence_at_i32_positive; +// mod sequence_at_i32_negative; +// mod sequence_at_i8_positive; +// mod sequence_at_i8_negative; +// mod reduce_min_fp16x16_1D; +// mod reduce_min_fp16x16_2D_default; +// mod reduce_min_fp16x16_2D_keepdims; +// mod reduce_min_fp16x16_2D_axis_1; +// mod reduce_min_fp8x23_1D; +// mod reduce_min_fp8x23_2D_default; +// mod reduce_min_fp8x23_2D_keepdims; +// mod reduce_min_fp8x23_2D_axis_1; +// mod reduce_min_i32_1D; +// mod reduce_min_i32_2D_default; +// mod reduce_min_i32_2D_keepdims; +// mod reduce_min_i32_2D_axis_1; +// mod reduce_min_i8_1D; +// mod reduce_min_i8_2D_default; +// mod reduce_min_i8_2D_keepdims; +// mod reduce_min_i8_2D_axis_1; +// mod reduce_min_u32_1D; +// mod reduce_min_u32_2D_default; +// mod reduce_min_u32_2D_keepdims; +// mod reduce_min_u32_2D_axis_1; +// mod sequence_construct_fp16x16; +// mod sequence_construct_fp8x23; +// mod sequence_construct_i32; +// mod sequence_construct_i8; +// mod sequence_construct_u32; +// mod shrink_hard_fp16x16; +// mod shrink_soft_fp16x16; +// mod shrink_hard_fp8x23; +// mod shrink_soft_fp8x23; +// mod sequence_empty_fp16x16; +// mod sequence_empty_fp8x23; +// mod sequence_empty_i32; +// mod sequence_empty_i8; +// mod sequence_empty_u32; +// mod reduce_mean_fp16x16_1D; +// mod reduce_mean_fp16x16_2D_default; +// mod reduce_mean_fp16x16_2D_keepdims; +// mod reduce_mean_fp16x16_2D_axis_1; +// mod reduce_mean_fp8x23_1D; +// mod reduce_mean_fp8x23_2D_default; +// mod reduce_mean_fp8x23_2D_keepdims; +// mod reduce_mean_fp8x23_2D_axis_1; +// mod reduce_mean_i32_1D; +// mod reduce_mean_i32_2D_default; +// mod reduce_mean_i32_2D_keepdims; +// mod reduce_mean_i32_2D_axis_1; +// mod reduce_mean_i8_1D; +// mod reduce_mean_i8_2D_default; +// mod reduce_mean_i8_2D_keepdims; +// mod reduce_mean_i8_2D_axis_1; +// mod reduce_mean_u32_1D; +// mod reduce_mean_u32_2D_default; +// mod reduce_mean_u32_2D_keepdims; +// mod reduce_mean_u32_2D_axis_1; +// mod pow_fp16x16; +// mod pow_fp16x16_broadcast; +// mod pow_fp8x23; +// mod pow_fp8x23_broadcast; +// mod sequence_erase_u32_positive; +// mod sequence_erase_u32_negative; +// mod sequence_erase_u32_empty; +// mod sequence_erase_fp16x16_positive; +// mod sequence_erase_fp16x16_negative; +// mod sequence_erase_fp16x16_empty; +// mod sequence_erase_fp8x23_positive; +// mod sequence_erase_fp8x23_negative; +// mod sequence_erase_fp8x23_empty; +// mod sequence_erase_i32_positive; +// mod sequence_erase_i32_negative; +// mod sequence_erase_i32_empty; +// mod sequence_erase_i8_positive; +// mod sequence_erase_i8_negative; +// mod sequence_erase_i8_empty; +// mod sequence_insert_fp16x16; +// mod sequence_insert_fp8x23; +// mod sequence_insert_i32; +// mod sequence_insert_i8; +// mod sequence_insert_u32; +// mod concat_from_sequence_fp8x23_new_axis_zero; +// mod concat_from_sequence_fp8x23_new_axis_one; +// mod concat_from_sequence_fp8x23_new_axis_default; +// mod concat_from_sequence_fp16x16_new_axis_zero; +// mod concat_from_sequence_fp16x16_new_axis_one; +// mod concat_from_sequence_fp16x16_new_axis_default; +// mod concat_from_sequence_i32_new_axis_zero; +// mod concat_from_sequence_i32_new_axis_one; +// mod concat_from_sequence_i32_new_axis_default; +// mod concat_from_sequence_i8_new_axis_zero; +// mod concat_from_sequence_i8_new_axis_one; +// mod concat_from_sequence_i8_new_axis_default; +// mod concat_from_sequence_u32_new_axis_zero; +// mod concat_from_sequence_u32_new_axis_one; +// mod concat_from_sequence_u32_new_axis_default; +// mod is_nan_fp16x16; +// mod is_nan_fp8x23; +// mod is_inf_fp16x16; +// mod is_inf_fp8x23; +// mod is_inf_i32; +// mod is_inf_i8; +// mod is_inf_u32; +// mod is_pos_inf_fp16x16; +// mod is_neg_inf_fp16x16; +// mod is_pos_inf_fp8x23; +// mod is_neg_inf_fp8x23; +// mod is_pos_inf_i32; +// mod is_neg_inf_i32; +// mod is_pos_inf_i8; +// mod is_neg_inf_i8; From cda2263dcb6dae0c5151f3e526315199e34bf312 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 1 Dec 2023 10:10:47 +0200 Subject: [PATCH 157/160] test and op --- tests/nodes.cairo | 1662 ++++++++--------- tests/nodes/and_fp16x16.cairo | 8 +- tests/nodes/and_fp16x16/input_0.cairo | 31 +- tests/nodes/and_fp16x16/input_1.cairo | 27 +- tests/nodes/and_fp16x16/output_0.cairo | 58 +- tests/nodes/and_fp16x16_broadcast.cairo | 8 +- .../nodes/and_fp16x16_broadcast/input_0.cairo | 9 +- .../nodes/and_fp16x16_broadcast/input_1.cairo | 7 +- .../and_fp16x16_broadcast/output_0.cairo | 12 +- tests/nodes/and_fp8x23.cairo | 10 +- tests/nodes/and_fp8x23/input_0.cairo | 31 +- tests/nodes/and_fp8x23/input_1.cairo | 33 +- tests/nodes/and_fp8x23/output_0.cairo | 58 +- tests/nodes/and_fp8x23_broadcast.cairo | 10 +- .../nodes/and_fp8x23_broadcast/input_0.cairo | 9 +- .../nodes/and_fp8x23_broadcast/input_1.cairo | 3 +- .../nodes/and_fp8x23_broadcast/output_0.cairo | 12 +- tests/nodes/and_i32.cairo | 8 +- tests/nodes/and_i32/input_0.cairo | 26 +- tests/nodes/and_i32/input_1.cairo | 28 +- tests/nodes/and_i32/output_0.cairo | 58 +- tests/nodes/and_i32_broadcast.cairo | 8 +- tests/nodes/and_i32_broadcast/input_0.cairo | 4 +- tests/nodes/and_i32_broadcast/input_1.cairo | 4 +- tests/nodes/and_i32_broadcast/output_0.cairo | 12 +- tests/nodes/and_i8.cairo | 10 +- tests/nodes/and_i8/input_0.cairo | 30 +- tests/nodes/and_i8/input_1.cairo | 26 +- tests/nodes/and_i8/output_0.cairo | 58 +- tests/nodes/and_i8_broadcast.cairo | 10 +- tests/nodes/and_i8_broadcast/input_0.cairo | 4 +- tests/nodes/and_i8_broadcast/input_1.cairo | 2 +- tests/nodes/and_i8_broadcast/output_0.cairo | 12 +- tests/nodes/and_u32.cairo | 10 +- tests/nodes/and_u32/input_0.cairo | 28 +- tests/nodes/and_u32/input_1.cairo | 26 +- tests/nodes/and_u32/output_0.cairo | 58 +- tests/nodes/and_u32_broadcast.cairo | 10 +- tests/nodes/and_u32_broadcast/input_0.cairo | 4 +- tests/nodes/and_u32_broadcast/input_1.cairo | 4 +- tests/nodes/and_u32_broadcast/output_0.cairo | 12 +- 41 files changed, 1226 insertions(+), 1214 deletions(-) diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 7caafcc03..f7986bb13 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,831 +1,831 @@ -// mod abs_fp16x16; -// mod abs_fp8x23; -// mod abs_i32; -// mod abs_i8; -// mod acos_fp16x16; -// mod acos_fp8x23; -// mod acosh_fp16x16; -// mod acosh_fp8x23; -// mod add_fp16x16; -// mod add_fp16x16_broadcast; -// mod add_fp8x23; -// mod add_fp8x23_broadcast; -// mod add_i32; -// mod add_i32_broadcast; -// mod add_i8; -// mod add_i8_broadcast; -// mod add_u32; -// mod add_u32_broadcast; -// mod argmax_fp16x16_1D_default; -// mod argmax_fp16x16_1D_keepdims_false; -// mod argmax_fp16x16_1D_last_index; -// mod argmax_fp16x16_2D_default; -// mod argmax_fp16x16_2D_keepdims_false; -// mod argmax_fp16x16_2D_last_index; -// mod argmax_fp16x16_3D_default; -// mod argmax_fp16x16_3D_keepdims_false; -// mod argmax_fp16x16_3D_last_index; -// mod argmax_fp8x23_1D_default; -// mod argmax_fp8x23_1D_keepdims_false; -// mod argmax_fp8x23_1D_last_index; -// mod argmax_fp8x23_2D_default; -// mod argmax_fp8x23_2D_keepdims_false; -// mod argmax_fp8x23_2D_last_index; -// mod argmax_fp8x23_3D_default; -// mod argmax_fp8x23_3D_keepdims_false; -// mod argmax_fp8x23_3D_last_index; -// mod argmax_i32_1D_default; -// mod argmax_i32_1D_keepdims_false; -// mod argmax_i32_1D_last_index; -// mod argmax_i32_2D_default; -// mod argmax_i32_2D_keepdims_false; -// mod argmax_i32_2D_last_index; -// mod argmax_i32_3D_default; -// mod argmax_i32_3D_keepdims_false; -// mod argmax_i32_3D_last_index; -// mod argmax_i8_1D_default; -// mod argmax_i8_1D_keepdims_false; -// mod argmax_i8_1D_last_index; -// mod argmax_i8_2D_default; -// mod argmax_i8_2D_keepdims_false; -// mod argmax_i8_2D_last_index; -// mod argmax_i8_3D_default; -// mod argmax_i8_3D_keepdims_false; -// mod argmax_i8_3D_last_index; -// mod argmax_u32_1D_default; -// mod argmax_u32_1D_keepdims_false; -// mod argmax_u32_1D_last_index; -// mod argmax_u32_2D_default; -// mod argmax_u32_2D_keepdims_false; -// mod argmax_u32_2D_last_index; -// mod argmax_u32_3D_default; -// mod argmax_u32_3D_keepdims_false; -// mod argmax_u32_3D_last_index; -// mod argmin_fp16x16_1D_default; -// mod argmin_fp16x16_1D_keepdims_false; -// mod argmin_fp16x16_1D_last_index; -// mod argmin_fp16x16_2D_default; -// mod argmin_fp16x16_2D_keepdims_false; -// mod argmin_fp16x16_2D_last_index; -// mod argmin_fp16x16_3D_default; -// mod argmin_fp16x16_3D_keepdims_false; -// mod argmin_fp16x16_3D_last_index; -// mod argmin_fp8x23_1D_default; -// mod argmin_fp8x23_1D_keepdims_false; -// mod argmin_fp8x23_1D_last_index; -// mod argmin_fp8x23_2D_default; -// mod argmin_fp8x23_2D_keepdims_false; -// mod argmin_fp8x23_2D_last_index; -// mod argmin_fp8x23_3D_default; -// mod argmin_fp8x23_3D_keepdims_false; -// mod argmin_fp8x23_3D_last_index; -// mod argmin_i32_1D_default; -// mod argmin_i32_1D_keepdims_false; -// mod argmin_i32_1D_last_index; -// mod argmin_i32_2D_default; -// mod argmin_i32_2D_keepdims_false; -// mod argmin_i32_2D_last_index; -// mod argmin_i32_3D_default; -// mod argmin_i32_3D_keepdims_false; -// mod argmin_i32_3D_last_index; -// mod argmin_i8_1D_default; -// mod argmin_i8_1D_keepdims_false; -// mod argmin_i8_1D_last_index; -// mod argmin_i8_2D_default; -// mod argmin_i8_2D_keepdims_false; -// mod argmin_i8_2D_last_index; -// mod argmin_i8_3D_default; -// mod argmin_i8_3D_keepdims_false; -// mod argmin_i8_3D_last_index; -// mod argmin_u32_1D_default; -// mod argmin_u32_1D_keepdims_false; -// mod argmin_u32_1D_last_index; -// mod argmin_u32_2D_default; -// mod argmin_u32_2D_keepdims_false; -// mod argmin_u32_2D_last_index; -// mod argmin_u32_3D_default; -// mod argmin_u32_3D_keepdims_false; -// mod argmin_u32_3D_last_index; -// mod asin_fp16x16; -// mod asin_fp8x23; -// mod asinh_fp16x16; -// mod asinh_fp8x23; -// mod atan_fp16x16; -// mod atan_fp8x23; -// mod ceil_fp16x16; -// mod ceil_fp8x23; -// mod concat_fp16x16_1d; -// mod concat_fp16x16_2d; -// mod concat_fp16x16_3d_default; -// mod concat_fp16x16_3d_axis_1; -// mod concat_fp16x16_3d_axis_2; -// mod concat_fp16x16_3d_three_tensors_axis_1; -// mod concat_fp16x16_3d_three_tensors_axis_2; -// mod concat_fp8x23_1d; -// mod concat_fp8x23_2d; -// mod concat_fp8x23_3d_default; -// mod concat_fp8x23_3d_axis_1; -// mod concat_fp8x23_3d_axis_2; -// mod concat_fp8x23_3d_three_tensors_axis_1; -// mod concat_fp8x23_3d_three_tensors_axis_2; -// mod concat_i32_1d; -// mod concat_i32_2d; -// mod concat_i32_3d_default; -// mod concat_i32_3d_axis_1; -// mod concat_i32_3d_axis_2; -// mod concat_i32_3d_three_tensors_axis_1; -// mod concat_i32_3d_three_tensors_axis_2; -// mod concat_i8_1d; -// mod concat_i8_2d; -// mod concat_i8_3d_default; -// mod concat_i8_3d_axis_1; -// mod concat_i8_3d_axis_2; -// mod concat_i8_3d_three_tensors_axis_1; -// mod concat_i8_3d_three_tensors_axis_2; -// mod concat_u32_1d; -// mod concat_u32_2d; -// mod concat_u32_3d_default; -// mod concat_u32_3d_axis_1; -// mod concat_u32_3d_axis_2; -// mod concat_u32_3d_three_tensors_axis_1; -// mod concat_u32_3d_three_tensors_axis_2; -// mod cos_fp16x16; -// mod cos_fp8x23; -// mod cosh_fp16x16; -// mod cosh_fp8x23; -// mod cumsum_fp16x16_1d_default; -// mod cumsum_fp16x16_1d_exclusive; -// mod cumsum_fp16x16_1d_reverse; -// mod cumsum_fp16x16_1d_reverse_exclusive; -// mod cumsum_fp16x16_2d_axis_0; -// mod cumsum_fp16x16_2d_axis_1; -// mod cumsum_fp8x23_1d_default; -// mod cumsum_fp8x23_1d_exclusive; -// mod cumsum_fp8x23_1d_reverse; -// mod cumsum_fp8x23_1d_reverse_exclusive; -// mod cumsum_fp8x23_2d_axis_0; -// mod cumsum_fp8x23_2d_axis_1; -// mod cumsum_i32_1d_default; -// mod cumsum_i32_1d_exclusive; -// mod cumsum_i32_1d_reverse; -// mod cumsum_i32_1d_reverse_exclusive; -// mod cumsum_i32_2d_axis_0; -// mod cumsum_i32_2d_axis_1; -// mod cumsum_i8_1d_default; -// mod cumsum_i8_1d_exclusive; -// mod cumsum_i8_1d_reverse; -// mod cumsum_i8_1d_reverse_exclusive; -// mod cumsum_i8_2d_axis_0; -// mod cumsum_i8_2d_axis_1; -// mod cumsum_u32_1d_default; -// mod cumsum_u32_1d_exclusive; -// mod cumsum_u32_1d_reverse; -// mod cumsum_u32_1d_reverse_exclusive; -// mod cumsum_u32_2d_axis_0; -// mod cumsum_u32_2d_axis_1; -// mod div_fp16x16; -// mod div_fp16x16_broadcast; -// mod div_fp8x23; -// mod div_fp8x23_broadcast; -// mod div_i32; -// mod div_i32_broadcast; -// mod div_i8; -// mod div_i8_broadcast; -// mod div_u32; -// mod div_u32_broadcast; -// mod equal_fp16x16; -// mod equal_fp16x16_broadcast; -// mod equal_fp8x23; -// mod equal_fp8x23_broadcast; -// mod equal_i32; -// mod equal_i32_broadcast; -// mod equal_i8; -// mod equal_i8_broadcast; -// mod equal_u32; -// mod equal_u32_broadcast; -// mod exp_fp16x16; -// mod exp_fp8x23; -// mod less_equal_fp16x16; -// mod less_equal_fp16x16_broadcast; -// mod less_equal_fp8x23; -// mod less_equal_fp8x23_broadcast; -// mod less_equal_i32; -// mod less_equal_i32_broadcast; -// mod less_equal_i8; -// mod less_equal_i8_broadcast; -// mod less_equal_u32; -// mod less_equal_u32_broadcast; -// mod greater_fp16x16; -// mod greater_fp16x16_broadcast; -// mod greater_fp8x23; -// mod greater_fp8x23_broadcast; -// mod greater_i32; -// mod greater_i32_broadcast; -// mod greater_i8; -// mod greater_i8_broadcast; -// mod greater_u32; -// mod greater_u32_broadcast; -// mod leaky_relu_fp16x16; -// mod leaky_relu_fp8x23; -// mod linear_fp16x16; -// mod linear_fp8x23; -// mod linear_i32; -// mod linear_i8; -// mod linear_u32; -// mod log_fp16x16; -// mod log_fp8x23; -// mod logsoftmax_fp16x16_axis_0; -// mod logsoftmax_fp16x16_axis_1; -// mod logsoftmax_fp8x23_axis_0; -// mod logsoftmax_fp8x23_axis_1; -// mod matmul_fp16x16_1d; -// mod matmul_fp16x16_2x2; -// mod matmul_fp16x16_2x1; -// mod matmul_fp16x16_1x2; -// mod matmul_fp8x23_1d; -// mod matmul_fp8x23_2x2; -// mod matmul_fp8x23_2x1; -// mod matmul_fp8x23_1x2; -// mod matmul_i32_1d; -// mod matmul_i32_2x2; -// mod matmul_i32_2x1; -// mod matmul_i32_1x2; -// mod matmul_i8_1d; -// mod matmul_i8_2x2; -// mod matmul_i8_2x1; -// mod matmul_i8_1x2; -// mod matmul_u32_1d; -// mod matmul_u32_2x2; -// mod matmul_u32_2x1; -// mod matmul_u32_1x2; -// mod mul_fp16x16; -// mod mul_fp16x16_broadcast; -// mod mul_fp8x23; -// mod mul_fp8x23_broadcast; -// mod mul_i32; -// mod mul_i32_broadcast; -// mod mul_i8; -// mod mul_i8_broadcast; -// mod mul_u32; -// mod mul_u32_broadcast; -// mod or_fp16x16; -// mod or_fp16x16_broadcast; -// mod or_fp8x23; -// mod or_fp8x23_broadcast; -// mod or_i32; -// mod or_i32_broadcast; -// mod or_i8; -// mod or_i8_broadcast; -// mod or_u32; -// mod or_u32_broadcast; -// mod reduce_sum_fp16x16_1D; -// mod reduce_sum_fp16x16_2D_default; -// mod reduce_sum_fp16x16_2D_keepdims; -// mod reduce_sum_fp16x16_2D_axis_1; -// mod reduce_sum_fp8x23_1D; -// mod reduce_sum_fp8x23_2D_default; -// mod reduce_sum_fp8x23_2D_keepdims; -// mod reduce_sum_fp8x23_2D_axis_1; -// mod reduce_sum_i32_1D; -// mod reduce_sum_i32_2D_default; -// mod reduce_sum_i32_2D_keepdims; -// mod reduce_sum_i32_2D_axis_1; -// mod reduce_sum_i8_1D; -// mod reduce_sum_i8_2D_default; -// mod reduce_sum_i8_2D_keepdims; -// mod reduce_sum_i8_2D_axis_1; -// mod reduce_sum_u32_1D; -// mod reduce_sum_u32_2D_default; -// mod reduce_sum_u32_2D_keepdims; -// mod reduce_sum_u32_2D_axis_1; -// mod relu_fp16x16; -// mod relu_fp8x23; -// mod relu_i32; -// mod relu_i8; -// mod sigmoid_fp16x16; -// mod sigmoid_fp8x23; -// mod sin_fp16x16; -// mod sin_fp8x23; -// mod sinh_fp16x16; -// mod sinh_fp8x23; -// mod softmax_fp16x16; -// mod softmax_fp8x23; -// mod softplus_fp8x23; -// mod softplus_fp16x16; -// mod softsign_fp8x23; -// mod softsign_fp16x16; -// mod sqrt_fp16x16; -// mod sqrt_fp8x23; -// mod sub_fp16x16; -// mod sub_fp16x16_broadcast; -// mod sub_fp8x23; -// mod sub_fp8x23_broadcast; -// mod sub_i32; -// mod sub_i32_broadcast; -// mod sub_i8; -// mod sub_i8_broadcast; -// mod sub_u32; -// mod sub_u32_broadcast; -// mod tanh_fp16x16; -// mod tanh_fp8x23; -// mod transpose_fp16x16_2d; -// mod transpose_fp16x16_3d; -// mod transpose_fp8x23_2d; -// mod transpose_fp8x23_3d; -// mod transpose_i32_2d; -// mod transpose_i32_3d; -// mod transpose_i8_2d; -// mod transpose_i8_3d; -// mod transpose_u32_2d; -// mod transpose_u32_3d; -// mod xor_fp16x16; -// mod xor_fp16x16_broadcast; -// mod xor_fp8x23; -// mod xor_fp8x23_broadcast; -// mod xor_i32; -// mod xor_i32_broadcast; -// mod xor_i8; -// mod xor_i8_broadcast; -// mod xor_u32; -// mod xor_u32_broadcast; -// mod less_fp16x16; -// mod less_fp16x16_broadcast; -// mod less_fp8x23; -// mod less_fp8x23_broadcast; -// mod less_i32; -// mod less_i32_broadcast; -// mod less_i8; -// mod less_i8_broadcast; -// mod less_u32; -// mod less_u32_broadcast; -// mod greater_equal_fp16x16; -// mod greater_equal_fp16x16_broadcast; -// mod greater_equal_fp8x23; -// mod greater_equal_fp8x23_broadcast; -// mod greater_equal_i32; -// mod greater_equal_i32_broadcast; -// mod greater_equal_i8; -// mod greater_equal_i8_broadcast; -// mod greater_equal_u32; -// mod greater_equal_u32_broadcast; -// mod slice_fp16x16_2d; -// mod slice_fp16x16_3d; -// mod slice_fp8x23_2d; -// mod slice_fp8x23_3d; -// mod slice_i32_2d; -// mod slice_i32_3d; -// mod slice_i8_2d; -// mod slice_i8_3d; -// mod slice_u32_2d; -// mod slice_u32_3d; -// mod gather_fp8x23_3d_default; -// mod gather_fp8x23_3d_axis1; -// mod gather_fp8x23_3d_axis2; -// mod gather_fp16x16_3d_default; -// mod gather_fp16x16_3d_axis1; -// mod gather_fp16x16_3d_axis2; -// mod gather_i8_3d_default; -// mod gather_i8_3d_axis1; -// mod gather_i8_3d_axis2; -// mod gather_i32_3d_default; -// mod gather_i32_3d_axis1; -// mod gather_i32_3d_axis2; -// mod gather_u32_3d_default; -// mod gather_u32_3d_axis1; -// mod gather_u32_3d_axis2; -// mod nonzero_fp16x16_2d; -// mod nonzero_fp16x16_3d; -// mod nonzero_fp8x23_2d; -// mod nonzero_fp8x23_3d; -// mod nonzero_i32_2d; -// mod nonzero_i32_3d; -// mod nonzero_i8_2d; -// mod nonzero_i8_3d; -// mod nonzero_u32_2d; -// mod nonzero_u32_3d; -// mod squeeze_fP16x16; -// mod squeeze_fP8x23; -// mod squeeze_i32; -// mod squeeze_i8; -// mod squeeze_u32; -// mod unsqueeze_fp16x16_2d; -// mod unsqueeze_fp16x16_3d; -// mod unsqueeze_fp8x23_2d; -// mod unsqueeze_fp8x23_3d; -// mod unsqueeze_i32_2d; -// mod unsqueeze_i32_3d; -// mod unsqueeze_i8_2d; -// mod unsqueeze_i8_3d; -// mod unsqueeze_u32_2d; -// mod unsqueeze_u32_3d; -// mod sign_fP16x16; -// mod sign_fP8x23; -// mod sign_fail; -// mod sign_i32; -// mod sign_i8; -// mod clip_fp16x16_2d; -// mod clip_fp16x16_3d; -// mod clip_fp8x23_2d; -// mod clip_fp8x23_3d; -// mod clip_i32_2d; -// mod clip_i32_3d; -// 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; -// mod identity_fP16x16; -// mod identity_fP8x23; -// mod identity_i32; -// mod identity_i8; -// mod identity_u32; -// mod thresholded_relu_fp16x16; -// mod thresholded_relu_fp8x23; -// mod hard_sigmoid_fp8x23; -// mod hard_sigmoid_fp16x16; -// mod neg_fp16x16; -// mod neg_fp8x23; -// mod neg_i32; -// mod neg_i8; -// mod gemm_all_attributes; -// mod gemm_alpha; -// mod gemm_beta; -// mod gemm_default_matrix_bias; -// mod gemm_default_vector_bias; -// mod gemm_default_no_bias; -// mod gemm_transposeA; -// mod gemm_transposeB; -// mod min_fp16x16_three_tensors; -// mod min_fp16x16_broadcast_three_tensors; -// mod min_fp16x16_two_tensors; -// mod min_fp16x16_broadcast_two_tensors; -// mod min_fp8x23_three_tensors; -// mod min_fp8x23_broadcast_three_tensors; -// mod min_fp8x23_two_tensors; -// mod min_fp8x23_broadcast_two_tensors; -// mod min_i32_three_tensors; -// mod min_i32_broadcast_three_tensors; -// mod min_i32_two_tensors; -// mod min_i32_broadcast_two_tensors; -// mod min_i8_three_tensors; -// mod min_i8_broadcast_three_tensors; -// mod min_i8_two_tensors; -// mod min_i8_broadcast_two_tensors; -// mod min_u32_three_tensors; -// mod min_u32_broadcast_three_tensors; -// mod min_u32_two_tensors; -// mod min_u32_broadcast_two_tensors; -// mod where_fp16x16; -// mod where_fp16x16_broadcast; -// mod where_fp8x23; -// mod where_fp8x23_broadcast; -// mod where_i32; -// mod where_i32_broadcast; -// mod where_i8; -// mod where_i8_broadcast; -// mod where_u32; -// mod where_u32_broadcast; -// mod not_bool; -// mod round_fp16x16; -// mod round_fp8x23; -// mod max_fp16x16_three_tensors; -// mod max_fp16x16_broadcast_three_tensors; -// mod max_fp16x16_two_tensors; -// mod max_fp16x16_broadcast_two_tensors; -// mod max_fp8x23_three_tensors; -// mod max_fp8x23_broadcast_three_tensors; -// mod max_fp8x23_two_tensors; -// mod max_fp8x23_broadcast_two_tensors; -// mod max_i32_three_tensors; -// mod max_i32_broadcast_three_tensors; -// mod max_i32_two_tensors; -// mod max_i32_broadcast_two_tensors; -// mod max_i8_three_tensors; -// mod max_i8_broadcast_three_tensors; -// mod max_i8_two_tensors; -// mod max_i8_broadcast_two_tensors; -// mod max_u32_three_tensors; -// mod max_u32_broadcast_three_tensors; -// mod max_u32_two_tensors; -// mod max_u32_broadcast_two_tensors; -// mod scatter_fp16x16_3d_default; -// mod scatter_fp16x16_3d_axis1; -// mod scatter_fp16x16_3d_axis1_add; -// mod scatter_fp8x23_default; -// mod scatter_fp8x23_axis1; -// mod scatter_fp8x23_mul; -// mod scatter_i8_default; -// mod scatter_i8_axis1; -// mod scatter_i8_axis1_max; -// mod scatter_u32_default; -// mod scatter_u32_axis1; -// mod scatter_u32_add; -// mod array_feature_extractor_1D_i32; -// mod array_feature_extractor_1D_fp8x23; -// mod array_feature_extractor_1D_fp16x16; -// mod array_feature_extractor_2D_i32; -// mod array_feature_extractor_2D_fp8x23; -// mod array_feature_extractor_2D_fp16x16; -// mod array_feature_extractor_3D_i32; -// mod array_feature_extractor_3D_fp8x23; -// mod array_feature_extractor_3D_fp16x16; -// mod binarizer_fp16x16; -// mod binarizer_fp8x23; -// mod tril_fp16x16; -// mod tril_fp16x16_neg; -// mod tril_fp16x16_one_row; -// mod tril_fp16x16_out_neg; -// mod tril_fp16x16_out_pos; -// mod tril_fp16x16_pos; -// mod tril_fp16x16_square; -// mod tril_fp16x16_square_neg; -// mod tril_fp16x16_zero; -// mod triu_fp16x16; -// mod triu_fp16x16_neg; -// mod triu_fp16x16_one_row; -// mod triu_fp16x16_out_neg; -// mod triu_fp16x16_out_pos; -// mod triu_fp16x16_pos; -// mod triu_fp16x16_square; -// mod triu_fp16x16_square_neg; -// mod triu_fp16x16_zero; -// mod tril_fp8x23; -// mod tril_fp8x23_neg; -// mod tril_fp8x23_one_row; -// mod tril_fp8x23_out_neg; -// mod tril_fp8x23_out_pos; -// mod tril_fp8x23_pos; -// mod tril_fp8x23_square; -// mod tril_fp8x23_square_neg; -// mod tril_fp8x23_zero; -// mod triu_fp8x23; -// mod triu_fp8x23_neg; -// mod triu_fp8x23_one_row; -// mod triu_fp8x23_out_neg; -// mod triu_fp8x23_out_pos; -// mod triu_fp8x23_pos; -// mod triu_fp8x23_square; -// mod triu_fp8x23_square_neg; -// mod triu_fp8x23_zero; -// mod tril_i32; -// mod tril_neg_i32; -// mod tril_i32_one_row; -// mod tril_i32_out_neg; -// mod tril_i32_out_pos; -// mod tril_i32_pos; -// mod tril_i32_square; -// mod tril_i32_square_neg; -// mod tril_i32_zero; -// mod triu_i32; -// mod triu_i32_neg; -// mod triu_i32_one_row; -// mod triu_i32_out_neg; -// mod triu_i32_out_pos; -// mod triu_i32_pos; -// mod triu_i32_square; -// mod triu_i32_square_neg; -// mod triu_i32_zero; -// mod tril_i8; -// mod tril_i8_neg; -// mod tril_i8_one_row; -// mod tril_i8_out_neg; -// mod tril_i8_out_pos; -// mod tril_i8_pos; -// mod tril_i8_square; -// mod tril_i8_square_neg; -// mod tril_i8_zero; -// mod triu_i8; -// mod triu_i8_neg; -// mod triu_i8_one_row; -// mod triu_i8_out_neg; -// mod triu_i8_out_pos; -// mod triu_i8_pos; -// mod triu_i8_square; -// mod triu_i8_square_neg; -// mod triu_i8_zero; -// mod tril_u32; -// mod tril_u32_neg; -// mod tril_u32_one_row; -// mod tril_u32_out_neg; -// mod tril_u32_out_pos; -// mod tril_u32_pos; -// mod tril_u32_square; -// mod tril_u32_square_neg; -// mod tril_u32_zero; -// mod triu_u32; -// mod triu_u32_neg; -// mod triu_u32_one_row; -// mod triu_u32_out_neg; -// mod triu_u32_out_pos; -// mod triu_u32_pos; -// mod triu_u32_square; -// mod triu_u32_square_neg; -// mod triu_u32_zero; -// mod reduce_sum_square_fp16x16_export_do_not_keepdims; -// mod reduce_sum_square_fp16x16_export_keepdims; -// mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; -// mod reduce_sum_square_fp8x23_export_do_not_keepdims; -// mod reduce_sum_square_fp8x23_export_keepdims; -// mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; -// mod reduce_sum_square_i32_export_do_not_keepdims; -// mod reduce_sum_square_i32_export_keepdims; -// mod reduce_sum_square_i32_export_negative_axes_keepdims; -// mod reduce_sum_square_i8_export_do_not_keepdims; -// mod reduce_sum_square_i8_export_keepdims; -// mod reduce_sum_square_i8_export_negative_axes_keepdims; -// mod reduce_sum_square_u32_export_do_not_keepdims; -// mod reduce_sum_square_u32_export_keepdims; -// mod reduce_sum_square_u32_export_negative_axes_keepdims; -// mod reduce_l2_fp16x16_export_do_not_keepdims; -// mod reduce_l2_fp16x16_export_keepdims; -// mod reduce_l2_fp16x16_export_negative_axes_keepdims; -// mod reduce_l2_fp8x23_export_do_not_keepdims; -// mod reduce_l2_fp8x23_export_keepdims; -// mod reduce_l2_fp8x23_export_negative_axes_keepdims; -// mod reduce_l1_fp16x16_export_do_not_keepdims; -// mod reduce_l1_fp16x16_export_keepdims; -// mod reduce_l1_fp16x16_export_negative_axes_keepdims; -// mod reduce_l1_fp8x23_export_do_not_keepdims; -// mod reduce_l1_fp8x23_export_keepdims; -// mod reduce_l1_fp8x23_export_negative_axes_keepdims; -// mod reduce_l1_i32_export_do_not_keepdims; -// mod reduce_l1_i32_export_keepdims; -// mod reduce_l1_i32_export_negative_axes_keepdims; -// mod reduce_l1_i8_export_do_not_keepdims; -// mod reduce_l1_i8_export_keepdims; -// mod reduce_l1_i8_export_negative_axes_keepdims; -// mod reduce_l1_u32_export_do_not_keepdims; -// mod reduce_l1_u32_export_keepdims; -// mod reduce_l1_u32_export_negative_axes_keepdims; -// mod reduce_prod_fp16x16_1D; -// mod reduce_prod_fp16x16_2D_default; -// mod reduce_prod_fp16x16_2D_keepdims; -// mod reduce_prod_fp16x16_2D_axis_1; -// mod reduce_prod_fp8x23_1D; -// mod reduce_prod_fp8x23_2D_default; -// mod reduce_prod_fp8x23_2D_keepdims; -// mod reduce_prod_fp8x23_2D_axis_1; -// mod reduce_prod_i32_1D; -// mod reduce_prod_i32_2D_default; -// mod reduce_prod_i32_2D_keepdims; -// mod reduce_prod_i32_2D_axis_1; -// mod reduce_prod_i8_1D; -// mod reduce_prod_i8_2D_default; -// mod reduce_prod_i8_2D_keepdims; -// mod reduce_prod_i8_2D_axis_1; -// mod reduce_prod_u32_1D; -// mod reduce_prod_u32_2D_default; -// mod reduce_prod_u32_2D_keepdims; -// mod reduce_prod_u32_2D_axis_1; -// mod gather_elements_fp16x16_3d_default; -// mod gather_elements_fp16x16_3d_axis1; -// mod gather_elements_fp16x16_3d_axis2; -// mod gather_elements_fp8x23_3d_default; -// mod gather_elements_fp8x23_3d_axis1; -// mod gather_elements_fp8x23_3d_axis2; -// mod gather_elements_i8_3d_default; -// mod gather_elements_i8_3d_axis1; -// mod gather_elements_i32_3d_default; -// mod gather_elements_i32_3d_axis1; -// mod gather_elements_i32_3d_axis2; -// mod gather_elements_u32_default; -// mod gather_elements_u32_axis1; -// mod gather_elements_u32_axis2; -// mod gather_elements_u32_axis3; -// mod sequence_length_fp16x16; -// mod sequence_length_fp16x16_broadcast; -// mod sequence_length_fp8x23; -// mod sequence_length_fp8x23_broadcast; -// mod sequence_length_i32; -// mod sequence_length_i32_broadcast; -// mod sequence_length_i8; -// mod sequence_length_i8_broadcast; -// mod sequence_length_u32; -// mod sequence_length_u32_broadcast; -// mod sequence_at_u32_positive; -// mod sequence_at_u32_negative; -// mod sequence_at_fp16x16_positive; -// mod sequence_at_fp16x16_negative; -// mod sequence_at_fp8x23_positive; -// mod sequence_at_fp8x23_negative; -// mod sequence_at_i32_positive; -// mod sequence_at_i32_negative; -// mod sequence_at_i8_positive; -// mod sequence_at_i8_negative; -// mod reduce_min_fp16x16_1D; -// mod reduce_min_fp16x16_2D_default; -// mod reduce_min_fp16x16_2D_keepdims; -// mod reduce_min_fp16x16_2D_axis_1; -// mod reduce_min_fp8x23_1D; -// mod reduce_min_fp8x23_2D_default; -// mod reduce_min_fp8x23_2D_keepdims; -// mod reduce_min_fp8x23_2D_axis_1; -// mod reduce_min_i32_1D; -// mod reduce_min_i32_2D_default; -// mod reduce_min_i32_2D_keepdims; -// mod reduce_min_i32_2D_axis_1; -// mod reduce_min_i8_1D; -// mod reduce_min_i8_2D_default; -// mod reduce_min_i8_2D_keepdims; -// mod reduce_min_i8_2D_axis_1; -// mod reduce_min_u32_1D; -// mod reduce_min_u32_2D_default; -// mod reduce_min_u32_2D_keepdims; -// mod reduce_min_u32_2D_axis_1; -// mod sequence_construct_fp16x16; -// mod sequence_construct_fp8x23; -// mod sequence_construct_i32; -// mod sequence_construct_i8; -// mod sequence_construct_u32; -// mod shrink_hard_fp16x16; -// mod shrink_soft_fp16x16; -// mod shrink_hard_fp8x23; -// mod shrink_soft_fp8x23; -// mod sequence_empty_fp16x16; -// mod sequence_empty_fp8x23; -// mod sequence_empty_i32; -// mod sequence_empty_i8; -// mod sequence_empty_u32; -// mod reduce_mean_fp16x16_1D; -// mod reduce_mean_fp16x16_2D_default; -// mod reduce_mean_fp16x16_2D_keepdims; -// mod reduce_mean_fp16x16_2D_axis_1; -// mod reduce_mean_fp8x23_1D; -// mod reduce_mean_fp8x23_2D_default; -// mod reduce_mean_fp8x23_2D_keepdims; -// mod reduce_mean_fp8x23_2D_axis_1; -// mod reduce_mean_i32_1D; -// mod reduce_mean_i32_2D_default; -// mod reduce_mean_i32_2D_keepdims; -// mod reduce_mean_i32_2D_axis_1; -// mod reduce_mean_i8_1D; -// mod reduce_mean_i8_2D_default; -// mod reduce_mean_i8_2D_keepdims; -// mod reduce_mean_i8_2D_axis_1; -// mod reduce_mean_u32_1D; -// mod reduce_mean_u32_2D_default; -// mod reduce_mean_u32_2D_keepdims; -// mod reduce_mean_u32_2D_axis_1; -// mod pow_fp16x16; -// mod pow_fp16x16_broadcast; -// mod pow_fp8x23; -// mod pow_fp8x23_broadcast; -// mod sequence_erase_u32_positive; -// mod sequence_erase_u32_negative; -// mod sequence_erase_u32_empty; -// mod sequence_erase_fp16x16_positive; -// mod sequence_erase_fp16x16_negative; -// mod sequence_erase_fp16x16_empty; -// mod sequence_erase_fp8x23_positive; -// mod sequence_erase_fp8x23_negative; -// mod sequence_erase_fp8x23_empty; -// mod sequence_erase_i32_positive; -// mod sequence_erase_i32_negative; -// mod sequence_erase_i32_empty; -// mod sequence_erase_i8_positive; -// mod sequence_erase_i8_negative; -// mod sequence_erase_i8_empty; -// mod sequence_insert_fp16x16; -// mod sequence_insert_fp8x23; -// mod sequence_insert_i32; -// mod sequence_insert_i8; -// mod sequence_insert_u32; -// mod concat_from_sequence_fp8x23_new_axis_zero; -// mod concat_from_sequence_fp8x23_new_axis_one; -// mod concat_from_sequence_fp8x23_new_axis_default; -// mod concat_from_sequence_fp16x16_new_axis_zero; -// mod concat_from_sequence_fp16x16_new_axis_one; -// mod concat_from_sequence_fp16x16_new_axis_default; -// mod concat_from_sequence_i32_new_axis_zero; -// mod concat_from_sequence_i32_new_axis_one; -// mod concat_from_sequence_i32_new_axis_default; -// mod concat_from_sequence_i8_new_axis_zero; -// mod concat_from_sequence_i8_new_axis_one; -// mod concat_from_sequence_i8_new_axis_default; -// mod concat_from_sequence_u32_new_axis_zero; -// mod concat_from_sequence_u32_new_axis_one; -// mod concat_from_sequence_u32_new_axis_default; -// mod is_nan_fp16x16; -// mod is_nan_fp8x23; -// mod is_inf_fp16x16; -// mod is_inf_fp8x23; -// mod is_inf_i32; -// mod is_inf_i8; -// mod is_inf_u32; -// mod is_pos_inf_fp16x16; -// mod is_neg_inf_fp16x16; -// mod is_pos_inf_fp8x23; -// mod is_neg_inf_fp8x23; -// mod is_pos_inf_i32; -// mod is_neg_inf_i32; -// mod is_pos_inf_i8; -// mod is_neg_inf_i8; +mod abs_fp16x16; +mod abs_fp8x23; +mod abs_i32; +mod abs_i8; +mod acos_fp16x16; +mod acos_fp8x23; +mod acosh_fp16x16; +mod acosh_fp8x23; +mod add_fp16x16; +mod add_fp16x16_broadcast; +mod add_fp8x23; +mod add_fp8x23_broadcast; +mod add_i32; +mod add_i32_broadcast; +mod add_i8; +mod add_i8_broadcast; +mod add_u32; +mod add_u32_broadcast; +mod argmax_fp16x16_1D_default; +mod argmax_fp16x16_1D_keepdims_false; +mod argmax_fp16x16_1D_last_index; +mod argmax_fp16x16_2D_default; +mod argmax_fp16x16_2D_keepdims_false; +mod argmax_fp16x16_2D_last_index; +mod argmax_fp16x16_3D_default; +mod argmax_fp16x16_3D_keepdims_false; +mod argmax_fp16x16_3D_last_index; +mod argmax_fp8x23_1D_default; +mod argmax_fp8x23_1D_keepdims_false; +mod argmax_fp8x23_1D_last_index; +mod argmax_fp8x23_2D_default; +mod argmax_fp8x23_2D_keepdims_false; +mod argmax_fp8x23_2D_last_index; +mod argmax_fp8x23_3D_default; +mod argmax_fp8x23_3D_keepdims_false; +mod argmax_fp8x23_3D_last_index; +mod argmax_i32_1D_default; +mod argmax_i32_1D_keepdims_false; +mod argmax_i32_1D_last_index; +mod argmax_i32_2D_default; +mod argmax_i32_2D_keepdims_false; +mod argmax_i32_2D_last_index; +mod argmax_i32_3D_default; +mod argmax_i32_3D_keepdims_false; +mod argmax_i32_3D_last_index; +mod argmax_i8_1D_default; +mod argmax_i8_1D_keepdims_false; +mod argmax_i8_1D_last_index; +mod argmax_i8_2D_default; +mod argmax_i8_2D_keepdims_false; +mod argmax_i8_2D_last_index; +mod argmax_i8_3D_default; +mod argmax_i8_3D_keepdims_false; +mod argmax_i8_3D_last_index; +mod argmax_u32_1D_default; +mod argmax_u32_1D_keepdims_false; +mod argmax_u32_1D_last_index; +mod argmax_u32_2D_default; +mod argmax_u32_2D_keepdims_false; +mod argmax_u32_2D_last_index; +mod argmax_u32_3D_default; +mod argmax_u32_3D_keepdims_false; +mod argmax_u32_3D_last_index; +mod argmin_fp16x16_1D_default; +mod argmin_fp16x16_1D_keepdims_false; +mod argmin_fp16x16_1D_last_index; +mod argmin_fp16x16_2D_default; +mod argmin_fp16x16_2D_keepdims_false; +mod argmin_fp16x16_2D_last_index; +mod argmin_fp16x16_3D_default; +mod argmin_fp16x16_3D_keepdims_false; +mod argmin_fp16x16_3D_last_index; +mod argmin_fp8x23_1D_default; +mod argmin_fp8x23_1D_keepdims_false; +mod argmin_fp8x23_1D_last_index; +mod argmin_fp8x23_2D_default; +mod argmin_fp8x23_2D_keepdims_false; +mod argmin_fp8x23_2D_last_index; +mod argmin_fp8x23_3D_default; +mod argmin_fp8x23_3D_keepdims_false; +mod argmin_fp8x23_3D_last_index; +mod argmin_i32_1D_default; +mod argmin_i32_1D_keepdims_false; +mod argmin_i32_1D_last_index; +mod argmin_i32_2D_default; +mod argmin_i32_2D_keepdims_false; +mod argmin_i32_2D_last_index; +mod argmin_i32_3D_default; +mod argmin_i32_3D_keepdims_false; +mod argmin_i32_3D_last_index; +mod argmin_i8_1D_default; +mod argmin_i8_1D_keepdims_false; +mod argmin_i8_1D_last_index; +mod argmin_i8_2D_default; +mod argmin_i8_2D_keepdims_false; +mod argmin_i8_2D_last_index; +mod argmin_i8_3D_default; +mod argmin_i8_3D_keepdims_false; +mod argmin_i8_3D_last_index; +mod argmin_u32_1D_default; +mod argmin_u32_1D_keepdims_false; +mod argmin_u32_1D_last_index; +mod argmin_u32_2D_default; +mod argmin_u32_2D_keepdims_false; +mod argmin_u32_2D_last_index; +mod argmin_u32_3D_default; +mod argmin_u32_3D_keepdims_false; +mod argmin_u32_3D_last_index; +mod asin_fp16x16; +mod asin_fp8x23; +mod asinh_fp16x16; +mod asinh_fp8x23; +mod atan_fp16x16; +mod atan_fp8x23; +mod ceil_fp16x16; +mod ceil_fp8x23; +mod concat_fp16x16_1d; +mod concat_fp16x16_2d; +mod concat_fp16x16_3d_default; +mod concat_fp16x16_3d_axis_1; +mod concat_fp16x16_3d_axis_2; +mod concat_fp16x16_3d_three_tensors_axis_1; +mod concat_fp16x16_3d_three_tensors_axis_2; +mod concat_fp8x23_1d; +mod concat_fp8x23_2d; +mod concat_fp8x23_3d_default; +mod concat_fp8x23_3d_axis_1; +mod concat_fp8x23_3d_axis_2; +mod concat_fp8x23_3d_three_tensors_axis_1; +mod concat_fp8x23_3d_three_tensors_axis_2; +mod concat_i32_1d; +mod concat_i32_2d; +mod concat_i32_3d_default; +mod concat_i32_3d_axis_1; +mod concat_i32_3d_axis_2; +mod concat_i32_3d_three_tensors_axis_1; +mod concat_i32_3d_three_tensors_axis_2; +mod concat_i8_1d; +mod concat_i8_2d; +mod concat_i8_3d_default; +mod concat_i8_3d_axis_1; +mod concat_i8_3d_axis_2; +mod concat_i8_3d_three_tensors_axis_1; +mod concat_i8_3d_three_tensors_axis_2; +mod concat_u32_1d; +mod concat_u32_2d; +mod concat_u32_3d_default; +mod concat_u32_3d_axis_1; +mod concat_u32_3d_axis_2; +mod concat_u32_3d_three_tensors_axis_1; +mod concat_u32_3d_three_tensors_axis_2; +mod cos_fp16x16; +mod cos_fp8x23; +mod cosh_fp16x16; +mod cosh_fp8x23; +mod cumsum_fp16x16_1d_default; +mod cumsum_fp16x16_1d_exclusive; +mod cumsum_fp16x16_1d_reverse; +mod cumsum_fp16x16_1d_reverse_exclusive; +mod cumsum_fp16x16_2d_axis_0; +mod cumsum_fp16x16_2d_axis_1; +mod cumsum_fp8x23_1d_default; +mod cumsum_fp8x23_1d_exclusive; +mod cumsum_fp8x23_1d_reverse; +mod cumsum_fp8x23_1d_reverse_exclusive; +mod cumsum_fp8x23_2d_axis_0; +mod cumsum_fp8x23_2d_axis_1; +mod cumsum_i32_1d_default; +mod cumsum_i32_1d_exclusive; +mod cumsum_i32_1d_reverse; +mod cumsum_i32_1d_reverse_exclusive; +mod cumsum_i32_2d_axis_0; +mod cumsum_i32_2d_axis_1; +mod cumsum_i8_1d_default; +mod cumsum_i8_1d_exclusive; +mod cumsum_i8_1d_reverse; +mod cumsum_i8_1d_reverse_exclusive; +mod cumsum_i8_2d_axis_0; +mod cumsum_i8_2d_axis_1; +mod cumsum_u32_1d_default; +mod cumsum_u32_1d_exclusive; +mod cumsum_u32_1d_reverse; +mod cumsum_u32_1d_reverse_exclusive; +mod cumsum_u32_2d_axis_0; +mod cumsum_u32_2d_axis_1; +mod div_fp16x16; +mod div_fp16x16_broadcast; +mod div_fp8x23; +mod div_fp8x23_broadcast; +mod div_i32; +mod div_i32_broadcast; +mod div_i8; +mod div_i8_broadcast; +mod div_u32; +mod div_u32_broadcast; +mod equal_fp16x16; +mod equal_fp16x16_broadcast; +mod equal_fp8x23; +mod equal_fp8x23_broadcast; +mod equal_i32; +mod equal_i32_broadcast; +mod equal_i8; +mod equal_i8_broadcast; +mod equal_u32; +mod equal_u32_broadcast; +mod exp_fp16x16; +mod exp_fp8x23; +mod less_equal_fp16x16; +mod less_equal_fp16x16_broadcast; +mod less_equal_fp8x23; +mod less_equal_fp8x23_broadcast; +mod less_equal_i32; +mod less_equal_i32_broadcast; +mod less_equal_i8; +mod less_equal_i8_broadcast; +mod less_equal_u32; +mod less_equal_u32_broadcast; +mod greater_fp16x16; +mod greater_fp16x16_broadcast; +mod greater_fp8x23; +mod greater_fp8x23_broadcast; +mod greater_i32; +mod greater_i32_broadcast; +mod greater_i8; +mod greater_i8_broadcast; +mod greater_u32; +mod greater_u32_broadcast; +mod leaky_relu_fp16x16; +mod leaky_relu_fp8x23; +mod linear_fp16x16; +mod linear_fp8x23; +mod linear_i32; +mod linear_i8; +mod linear_u32; +mod log_fp16x16; +mod log_fp8x23; +mod logsoftmax_fp16x16_axis_0; +mod logsoftmax_fp16x16_axis_1; +mod logsoftmax_fp8x23_axis_0; +mod logsoftmax_fp8x23_axis_1; +mod matmul_fp16x16_1d; +mod matmul_fp16x16_2x2; +mod matmul_fp16x16_2x1; +mod matmul_fp16x16_1x2; +mod matmul_fp8x23_1d; +mod matmul_fp8x23_2x2; +mod matmul_fp8x23_2x1; +mod matmul_fp8x23_1x2; +mod matmul_i32_1d; +mod matmul_i32_2x2; +mod matmul_i32_2x1; +mod matmul_i32_1x2; +mod matmul_i8_1d; +mod matmul_i8_2x2; +mod matmul_i8_2x1; +mod matmul_i8_1x2; +mod matmul_u32_1d; +mod matmul_u32_2x2; +mod matmul_u32_2x1; +mod matmul_u32_1x2; +mod mul_fp16x16; +mod mul_fp16x16_broadcast; +mod mul_fp8x23; +mod mul_fp8x23_broadcast; +mod mul_i32; +mod mul_i32_broadcast; +mod mul_i8; +mod mul_i8_broadcast; +mod mul_u32; +mod mul_u32_broadcast; +mod or_fp16x16; +mod or_fp16x16_broadcast; +mod or_fp8x23; +mod or_fp8x23_broadcast; +mod or_i32; +mod or_i32_broadcast; +mod or_i8; +mod or_i8_broadcast; +mod or_u32; +mod or_u32_broadcast; +mod reduce_sum_fp16x16_1D; +mod reduce_sum_fp16x16_2D_default; +mod reduce_sum_fp16x16_2D_keepdims; +mod reduce_sum_fp16x16_2D_axis_1; +mod reduce_sum_fp8x23_1D; +mod reduce_sum_fp8x23_2D_default; +mod reduce_sum_fp8x23_2D_keepdims; +mod reduce_sum_fp8x23_2D_axis_1; +mod reduce_sum_i32_1D; +mod reduce_sum_i32_2D_default; +mod reduce_sum_i32_2D_keepdims; +mod reduce_sum_i32_2D_axis_1; +mod reduce_sum_i8_1D; +mod reduce_sum_i8_2D_default; +mod reduce_sum_i8_2D_keepdims; +mod reduce_sum_i8_2D_axis_1; +mod reduce_sum_u32_1D; +mod reduce_sum_u32_2D_default; +mod reduce_sum_u32_2D_keepdims; +mod reduce_sum_u32_2D_axis_1; +mod relu_fp16x16; +mod relu_fp8x23; +mod relu_i32; +mod relu_i8; +mod sigmoid_fp16x16; +mod sigmoid_fp8x23; +mod sin_fp16x16; +mod sin_fp8x23; +mod sinh_fp16x16; +mod sinh_fp8x23; +mod softmax_fp16x16; +mod softmax_fp8x23; +mod softplus_fp8x23; +mod softplus_fp16x16; +mod softsign_fp8x23; +mod softsign_fp16x16; +mod sqrt_fp16x16; +mod sqrt_fp8x23; +mod sub_fp16x16; +mod sub_fp16x16_broadcast; +mod sub_fp8x23; +mod sub_fp8x23_broadcast; +mod sub_i32; +mod sub_i32_broadcast; +mod sub_i8; +mod sub_i8_broadcast; +mod sub_u32; +mod sub_u32_broadcast; +mod tanh_fp16x16; +mod tanh_fp8x23; +mod transpose_fp16x16_2d; +mod transpose_fp16x16_3d; +mod transpose_fp8x23_2d; +mod transpose_fp8x23_3d; +mod transpose_i32_2d; +mod transpose_i32_3d; +mod transpose_i8_2d; +mod transpose_i8_3d; +mod transpose_u32_2d; +mod transpose_u32_3d; +mod xor_fp16x16; +mod xor_fp16x16_broadcast; +mod xor_fp8x23; +mod xor_fp8x23_broadcast; +mod xor_i32; +mod xor_i32_broadcast; +mod xor_i8; +mod xor_i8_broadcast; +mod xor_u32; +mod xor_u32_broadcast; +mod less_fp16x16; +mod less_fp16x16_broadcast; +mod less_fp8x23; +mod less_fp8x23_broadcast; +mod less_i32; +mod less_i32_broadcast; +mod less_i8; +mod less_i8_broadcast; +mod less_u32; +mod less_u32_broadcast; +mod greater_equal_fp16x16; +mod greater_equal_fp16x16_broadcast; +mod greater_equal_fp8x23; +mod greater_equal_fp8x23_broadcast; +mod greater_equal_i32; +mod greater_equal_i32_broadcast; +mod greater_equal_i8; +mod greater_equal_i8_broadcast; +mod greater_equal_u32; +mod greater_equal_u32_broadcast; +mod slice_fp16x16_2d; +mod slice_fp16x16_3d; +mod slice_fp8x23_2d; +mod slice_fp8x23_3d; +mod slice_i32_2d; +mod slice_i32_3d; +mod slice_i8_2d; +mod slice_i8_3d; +mod slice_u32_2d; +mod slice_u32_3d; +mod gather_fp8x23_3d_default; +mod gather_fp8x23_3d_axis1; +mod gather_fp8x23_3d_axis2; +mod gather_fp16x16_3d_default; +mod gather_fp16x16_3d_axis1; +mod gather_fp16x16_3d_axis2; +mod gather_i8_3d_default; +mod gather_i8_3d_axis1; +mod gather_i8_3d_axis2; +mod gather_i32_3d_default; +mod gather_i32_3d_axis1; +mod gather_i32_3d_axis2; +mod gather_u32_3d_default; +mod gather_u32_3d_axis1; +mod gather_u32_3d_axis2; +mod nonzero_fp16x16_2d; +mod nonzero_fp16x16_3d; +mod nonzero_fp8x23_2d; +mod nonzero_fp8x23_3d; +mod nonzero_i32_2d; +mod nonzero_i32_3d; +mod nonzero_i8_2d; +mod nonzero_i8_3d; +mod nonzero_u32_2d; +mod nonzero_u32_3d; +mod squeeze_fP16x16; +mod squeeze_fP8x23; +mod squeeze_i32; +mod squeeze_i8; +mod squeeze_u32; +mod unsqueeze_fp16x16_2d; +mod unsqueeze_fp16x16_3d; +mod unsqueeze_fp8x23_2d; +mod unsqueeze_fp8x23_3d; +mod unsqueeze_i32_2d; +mod unsqueeze_i32_3d; +mod unsqueeze_i8_2d; +mod unsqueeze_i8_3d; +mod unsqueeze_u32_2d; +mod unsqueeze_u32_3d; +mod sign_fP16x16; +mod sign_fP8x23; +mod sign_fail; +mod sign_i32; +mod sign_i8; +mod clip_fp16x16_2d; +mod clip_fp16x16_3d; +mod clip_fp8x23_2d; +mod clip_fp8x23_3d; +mod clip_i32_2d; +mod clip_i32_3d; +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; +mod identity_fP16x16; +mod identity_fP8x23; +mod identity_i32; +mod identity_i8; +mod identity_u32; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; +mod where_fp16x16; +mod where_fp16x16_broadcast; +mod where_fp8x23; +mod where_fp8x23_broadcast; +mod where_i32; +mod where_i32_broadcast; +mod where_i8; +mod where_i8_broadcast; +mod where_u32; +mod where_u32_broadcast; +mod not_bool; +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; +mod binarizer_fp16x16; +mod binarizer_fp8x23; +mod tril_fp16x16; +mod tril_fp16x16_neg; +mod tril_fp16x16_one_row; +mod tril_fp16x16_out_neg; +mod tril_fp16x16_out_pos; +mod tril_fp16x16_pos; +mod tril_fp16x16_square; +mod tril_fp16x16_square_neg; +mod tril_fp16x16_zero; +mod triu_fp16x16; +mod triu_fp16x16_neg; +mod triu_fp16x16_one_row; +mod triu_fp16x16_out_neg; +mod triu_fp16x16_out_pos; +mod triu_fp16x16_pos; +mod triu_fp16x16_square; +mod triu_fp16x16_square_neg; +mod triu_fp16x16_zero; +mod tril_fp8x23; +mod tril_fp8x23_neg; +mod tril_fp8x23_one_row; +mod tril_fp8x23_out_neg; +mod tril_fp8x23_out_pos; +mod tril_fp8x23_pos; +mod tril_fp8x23_square; +mod tril_fp8x23_square_neg; +mod tril_fp8x23_zero; +mod triu_fp8x23; +mod triu_fp8x23_neg; +mod triu_fp8x23_one_row; +mod triu_fp8x23_out_neg; +mod triu_fp8x23_out_pos; +mod triu_fp8x23_pos; +mod triu_fp8x23_square; +mod triu_fp8x23_square_neg; +mod triu_fp8x23_zero; +mod tril_i32; +mod tril_neg_i32; +mod tril_i32_one_row; +mod tril_i32_out_neg; +mod tril_i32_out_pos; +mod tril_i32_pos; +mod tril_i32_square; +mod tril_i32_square_neg; +mod tril_i32_zero; +mod triu_i32; +mod triu_i32_neg; +mod triu_i32_one_row; +mod triu_i32_out_neg; +mod triu_i32_out_pos; +mod triu_i32_pos; +mod triu_i32_square; +mod triu_i32_square_neg; +mod triu_i32_zero; +mod tril_i8; +mod tril_i8_neg; +mod tril_i8_one_row; +mod tril_i8_out_neg; +mod tril_i8_out_pos; +mod tril_i8_pos; +mod tril_i8_square; +mod tril_i8_square_neg; +mod tril_i8_zero; +mod triu_i8; +mod triu_i8_neg; +mod triu_i8_one_row; +mod triu_i8_out_neg; +mod triu_i8_out_pos; +mod triu_i8_pos; +mod triu_i8_square; +mod triu_i8_square_neg; +mod triu_i8_zero; +mod tril_u32; +mod tril_u32_neg; +mod tril_u32_one_row; +mod tril_u32_out_neg; +mod tril_u32_out_pos; +mod tril_u32_pos; +mod tril_u32_square; +mod tril_u32_square_neg; +mod tril_u32_zero; +mod triu_u32; +mod triu_u32_neg; +mod triu_u32_one_row; +mod triu_u32_out_neg; +mod triu_u32_out_pos; +mod triu_u32_pos; +mod triu_u32_square; +mod triu_u32_square_neg; +mod triu_u32_zero; +mod reduce_sum_square_fp16x16_export_do_not_keepdims; +mod reduce_sum_square_fp16x16_export_keepdims; +mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +mod reduce_sum_square_fp8x23_export_do_not_keepdims; +mod reduce_sum_square_fp8x23_export_keepdims; +mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +mod reduce_sum_square_i32_export_do_not_keepdims; +mod reduce_sum_square_i32_export_keepdims; +mod reduce_sum_square_i32_export_negative_axes_keepdims; +mod reduce_sum_square_i8_export_do_not_keepdims; +mod reduce_sum_square_i8_export_keepdims; +mod reduce_sum_square_i8_export_negative_axes_keepdims; +mod reduce_sum_square_u32_export_do_not_keepdims; +mod reduce_sum_square_u32_export_keepdims; +mod reduce_sum_square_u32_export_negative_axes_keepdims; +mod reduce_l2_fp16x16_export_do_not_keepdims; +mod reduce_l2_fp16x16_export_keepdims; +mod reduce_l2_fp16x16_export_negative_axes_keepdims; +mod reduce_l2_fp8x23_export_do_not_keepdims; +mod reduce_l2_fp8x23_export_keepdims; +mod reduce_l2_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_fp16x16_export_do_not_keepdims; +mod reduce_l1_fp16x16_export_keepdims; +mod reduce_l1_fp16x16_export_negative_axes_keepdims; +mod reduce_l1_fp8x23_export_do_not_keepdims; +mod reduce_l1_fp8x23_export_keepdims; +mod reduce_l1_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_i32_export_do_not_keepdims; +mod reduce_l1_i32_export_keepdims; +mod reduce_l1_i32_export_negative_axes_keepdims; +mod reduce_l1_i8_export_do_not_keepdims; +mod reduce_l1_i8_export_keepdims; +mod reduce_l1_i8_export_negative_axes_keepdims; +mod reduce_l1_u32_export_do_not_keepdims; +mod reduce_l1_u32_export_keepdims; +mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_prod_fp16x16_1D; +mod reduce_prod_fp16x16_2D_default; +mod reduce_prod_fp16x16_2D_keepdims; +mod reduce_prod_fp16x16_2D_axis_1; +mod reduce_prod_fp8x23_1D; +mod reduce_prod_fp8x23_2D_default; +mod reduce_prod_fp8x23_2D_keepdims; +mod reduce_prod_fp8x23_2D_axis_1; +mod reduce_prod_i32_1D; +mod reduce_prod_i32_2D_default; +mod reduce_prod_i32_2D_keepdims; +mod reduce_prod_i32_2D_axis_1; +mod reduce_prod_i8_1D; +mod reduce_prod_i8_2D_default; +mod reduce_prod_i8_2D_keepdims; +mod reduce_prod_i8_2D_axis_1; +mod reduce_prod_u32_1D; +mod reduce_prod_u32_2D_default; +mod reduce_prod_u32_2D_keepdims; +mod reduce_prod_u32_2D_axis_1; +mod gather_elements_fp16x16_3d_default; +mod gather_elements_fp16x16_3d_axis1; +mod gather_elements_fp16x16_3d_axis2; +mod gather_elements_fp8x23_3d_default; +mod gather_elements_fp8x23_3d_axis1; +mod gather_elements_fp8x23_3d_axis2; +mod gather_elements_i8_3d_default; +mod gather_elements_i8_3d_axis1; +mod gather_elements_i32_3d_default; +mod gather_elements_i32_3d_axis1; +mod gather_elements_i32_3d_axis2; +mod gather_elements_u32_default; +mod gather_elements_u32_axis1; +mod gather_elements_u32_axis2; +mod gather_elements_u32_axis3; +mod sequence_length_fp16x16; +mod sequence_length_fp16x16_broadcast; +mod sequence_length_fp8x23; +mod sequence_length_fp8x23_broadcast; +mod sequence_length_i32; +mod sequence_length_i32_broadcast; +mod sequence_length_i8; +mod sequence_length_i8_broadcast; +mod sequence_length_u32; +mod sequence_length_u32_broadcast; +mod sequence_at_u32_positive; +mod sequence_at_u32_negative; +mod sequence_at_fp16x16_positive; +mod sequence_at_fp16x16_negative; +mod sequence_at_fp8x23_positive; +mod sequence_at_fp8x23_negative; +mod sequence_at_i32_positive; +mod sequence_at_i32_negative; +mod sequence_at_i8_positive; +mod sequence_at_i8_negative; +mod reduce_min_fp16x16_1D; +mod reduce_min_fp16x16_2D_default; +mod reduce_min_fp16x16_2D_keepdims; +mod reduce_min_fp16x16_2D_axis_1; +mod reduce_min_fp8x23_1D; +mod reduce_min_fp8x23_2D_default; +mod reduce_min_fp8x23_2D_keepdims; +mod reduce_min_fp8x23_2D_axis_1; +mod reduce_min_i32_1D; +mod reduce_min_i32_2D_default; +mod reduce_min_i32_2D_keepdims; +mod reduce_min_i32_2D_axis_1; +mod reduce_min_i8_1D; +mod reduce_min_i8_2D_default; +mod reduce_min_i8_2D_keepdims; +mod reduce_min_i8_2D_axis_1; +mod reduce_min_u32_1D; +mod reduce_min_u32_2D_default; +mod reduce_min_u32_2D_keepdims; +mod reduce_min_u32_2D_axis_1; +mod sequence_construct_fp16x16; +mod sequence_construct_fp8x23; +mod sequence_construct_i32; +mod sequence_construct_i8; +mod sequence_construct_u32; +mod shrink_hard_fp16x16; +mod shrink_soft_fp16x16; +mod shrink_hard_fp8x23; +mod shrink_soft_fp8x23; +mod sequence_empty_fp16x16; +mod sequence_empty_fp8x23; +mod sequence_empty_i32; +mod sequence_empty_i8; +mod sequence_empty_u32; +mod reduce_mean_fp16x16_1D; +mod reduce_mean_fp16x16_2D_default; +mod reduce_mean_fp16x16_2D_keepdims; +mod reduce_mean_fp16x16_2D_axis_1; +mod reduce_mean_fp8x23_1D; +mod reduce_mean_fp8x23_2D_default; +mod reduce_mean_fp8x23_2D_keepdims; +mod reduce_mean_fp8x23_2D_axis_1; +mod reduce_mean_i32_1D; +mod reduce_mean_i32_2D_default; +mod reduce_mean_i32_2D_keepdims; +mod reduce_mean_i32_2D_axis_1; +mod reduce_mean_i8_1D; +mod reduce_mean_i8_2D_default; +mod reduce_mean_i8_2D_keepdims; +mod reduce_mean_i8_2D_axis_1; +mod reduce_mean_u32_1D; +mod reduce_mean_u32_2D_default; +mod reduce_mean_u32_2D_keepdims; +mod reduce_mean_u32_2D_axis_1; +mod pow_fp16x16; +mod pow_fp16x16_broadcast; +mod pow_fp8x23; +mod pow_fp8x23_broadcast; +mod sequence_erase_u32_positive; +mod sequence_erase_u32_negative; +mod sequence_erase_u32_empty; +mod sequence_erase_fp16x16_positive; +mod sequence_erase_fp16x16_negative; +mod sequence_erase_fp16x16_empty; +mod sequence_erase_fp8x23_positive; +mod sequence_erase_fp8x23_negative; +mod sequence_erase_fp8x23_empty; +mod sequence_erase_i32_positive; +mod sequence_erase_i32_negative; +mod sequence_erase_i32_empty; +mod sequence_erase_i8_positive; +mod sequence_erase_i8_negative; +mod sequence_erase_i8_empty; +mod sequence_insert_fp16x16; +mod sequence_insert_fp8x23; +mod sequence_insert_i32; +mod sequence_insert_i8; +mod sequence_insert_u32; +mod concat_from_sequence_fp8x23_new_axis_zero; +mod concat_from_sequence_fp8x23_new_axis_one; +mod concat_from_sequence_fp8x23_new_axis_default; +mod concat_from_sequence_fp16x16_new_axis_zero; +mod concat_from_sequence_fp16x16_new_axis_one; +mod concat_from_sequence_fp16x16_new_axis_default; +mod concat_from_sequence_i32_new_axis_zero; +mod concat_from_sequence_i32_new_axis_one; +mod concat_from_sequence_i32_new_axis_default; +mod concat_from_sequence_i8_new_axis_zero; +mod concat_from_sequence_i8_new_axis_one; +mod concat_from_sequence_i8_new_axis_default; +mod concat_from_sequence_u32_new_axis_zero; +mod concat_from_sequence_u32_new_axis_one; +mod concat_from_sequence_u32_new_axis_default; +mod is_nan_fp16x16; +mod is_nan_fp8x23; +mod is_inf_fp16x16; +mod is_inf_fp8x23; +mod is_inf_i32; +mod is_inf_i8; +mod is_inf_u32; +mod is_pos_inf_fp16x16; +mod is_neg_inf_fp16x16; +mod is_pos_inf_fp8x23; +mod is_neg_inf_fp8x23; +mod is_pos_inf_i32; +mod is_neg_inf_i32; +mod is_pos_inf_i8; +mod is_neg_inf_i8; diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo index dcd53ea37..9eeff2023 100644 --- a/tests/nodes/and_fp16x16.cairo +++ b/tests/nodes/and_fp16x16.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; +use orion::operators::tensor::FP16x16TensorPartialEq; use orion::operators::tensor::FP16x16Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo index b32a5f0b6..7c02fb8d9 100644 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ b/tests/nodes/and_fp16x16/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_0() -> Tensor { 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: 131072, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 65536, sign: false }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 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: 131072, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 131072, sign: false }); data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 0, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo index 2b2036fce..d072cc603 100644 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ b/tests/nodes/and_fp16x16/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -11,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, 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: 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: 65536, sign: false }); + data.append(FP16x16 { mag: 65536, sign: true }); + 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: true }); - data.append(FP16x16 { mag: 196608, sign: true }); + data.append(FP16x16 { mag: 65536, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: 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: 0, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 65536, sign: false }); + data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo index 8a754463f..0417518fa 100644 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ b/tests/nodes/and_fp16x16/output_0.cairo @@ -1,40 +1,40 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(false); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo index 0f0a979da..735da46d7 100644 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ b/tests/nodes/and_fp16x16_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; +use orion::operators::tensor::FP16x16TensorPartialEq; use orion::operators::tensor::FP16x16Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo index 2554de21d..e88a21894 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,9 +9,9 @@ fn input_0() -> Tensor { 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 }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 131072, sign: true }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo index 019f2f532..a92003169 100644 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ b/tests/nodes/and_fp16x16_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP16x16; +use orion::numbers::{FixedTrait, FP16x16}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); + data.append(FP16x16 { mag: 0, sign: false }); + data.append(FP16x16 { mag: 196608, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_fp16x16_broadcast/output_0.cairo index 12e081541..9123acad8 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_fp16x16_broadcast/output_0.cairo @@ -1,16 +1,16 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(false); + data.append(false); + data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo index 373cfadaf..4ed68acc3 100644 --- a/tests/nodes/and_fp8x23.cairo +++ b/tests/nodes/and_fp8x23.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo index b093e4c53..09c47c6ad 100644 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ b/tests/nodes/and_fp8x23/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_0() -> Tensor { 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: true }); + data.append(FP8x23 { mag: 16777216, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo index 0553e0019..5286e4abe 100644 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ b/tests/nodes/and_fp8x23/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -12,31 +11,31 @@ fn input_1() -> Tensor { let mut data = ArrayTrait::new(); data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 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: 0, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: false }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 25165824, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: true }); data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); + data.append(FP8x23 { mag: 16777216, sign: true }); + data.append(FP8x23 { mag: 8388608, sign: false }); data.append(FP8x23 { mag: 8388608, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo index fa2a76b74..30a68fb27 100644 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ b/tests/nodes/and_fp8x23/output_0.cairo @@ -1,40 +1,40 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo index ad50264f8..c5e5aecc2 100644 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ b/tests/nodes/and_fp8x23_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::FP8x23TensorPartialEq; use orion::operators::tensor::FP8x23Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo index f7cb3a134..4d4602452 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_0.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); @@ -10,9 +9,9 @@ fn input_0() -> Tensor { 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: 8388608, sign: false }); + data.append(FP8x23 { mag: 8388608, sign: true }); + data.append(FP8x23 { mag: 0, sign: false }); data.append(FP8x23 { mag: 16777216, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo index 35cf05e4e..f357c23e3 100644 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ b/tests/nodes/and_fp8x23_broadcast/input_1.cairo @@ -1,8 +1,7 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::FixedTrait; -use orion::numbers::FP8x23; +use orion::numbers::{FixedTrait, FP8x23}; fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_fp8x23_broadcast/output_0.cairo index 3883dcaf3..c58f10275 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_fp8x23_broadcast/output_0.cairo @@ -1,16 +1,16 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(true); + data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_i32.cairo index fd56fd1bb..cce348f4f 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_i32.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo index bb190dea5..e7c8cedff 100644 --- a/tests/nodes/and_i32/input_0.cairo +++ b/tests/nodes/and_i32/input_0.cairo @@ -10,32 +10,32 @@ fn input_0() -> Tensor { 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: 1, sign: false }); + data.append(i32 { mag: 2, 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: 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: 2, sign: false }); data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: false }); 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: 3, sign: true }); 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: 2, sign: false }); + data.append(i32 { mag: 2, sign: false }); data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 2, sign: true }); + data.append(i32 { mag: 2, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo index 45d38f5a8..f1bb1ecdd 100644 --- a/tests/nodes/and_i32/input_1.cairo +++ b/tests/nodes/and_i32/input_1.cairo @@ -11,31 +11,31 @@ fn input_1() -> Tensor { 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: 0, 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: 0, sign: false }); data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 0, sign: false }); data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 2, sign: true }); 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: 3, sign: true }); + data.append(i32 { mag: 1, sign: true }); + data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 1, 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: 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 }); + data.append(i32 { mag: 1, sign: false }); + data.append(i32 { mag: 3, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo index bb81daa72..279220947 100644 --- a/tests/nodes/and_i32/output_0.cairo +++ b/tests/nodes/and_i32/output_0.cairo @@ -1,40 +1,40 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo index 761e4e147..0a2c327ae 100644 --- a/tests/nodes/and_i32_broadcast.cairo +++ b/tests/nodes/and_i32_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; +use orion::operators::tensor::I32TensorPartialEq; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo index 2d6775e4b..8bf3fb2fc 100644 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ b/tests/nodes/and_i32_broadcast/input_0.cairo @@ -11,7 +11,7 @@ fn input_0() -> Tensor { 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 }); + data.append(i32 { mag: 2, sign: false }); + data.append(i32 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo index 07dcdc4f2..e0e0ce800 100644 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ b/tests/nodes/and_i32_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: true }); + data.append(i32 { mag: 0, sign: false }); + data.append(i32 { mag: 1, sign: true }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_i32_broadcast/output_0.cairo index f7205c752..b77d9ccb8 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_i32_broadcast/output_0.cairo @@ -1,16 +1,16 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(false); + data.append(true); + data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_i8.cairo index 5f03b69eb..e662e0869 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_i8.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo index 0c3934de7..831184af2 100644 --- a/tests/nodes/and_i8/input_0.cairo +++ b/tests/nodes/and_i8/input_0.cairo @@ -12,30 +12,30 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(i8 { mag: 0, sign: false }); data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 1, sign: false }); 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: 3, sign: true }); 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: 3, sign: true }); + data.append(i8 { mag: 3, sign: true }); + data.append(i8 { mag: 2, 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: 2, sign: false }); + data.append(i8 { mag: 2, sign: true }); 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: 3, sign: true }); + data.append(i8 { mag: 1, sign: false }); + data.append(i8 { mag: 2, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo index 43c7fdb27..441a56a0c 100644 --- a/tests/nodes/and_i8/input_1.cairo +++ b/tests/nodes/and_i8/input_1.cairo @@ -10,32 +10,32 @@ fn input_1() -> Tensor { shape.append(3); let mut data = ArrayTrait::new(); + data.append(i8 { mag: 1, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 1, sign: true }); data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: true }); data.append(i8 { mag: 2, sign: true }); data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 2, sign: true }); + data.append(i8 { mag: 3, sign: true }); data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 3, 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: 3, sign: true }); 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: 3, sign: true }); 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()) } diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo index f3a1ad29a..cb879d158 100644 --- a/tests/nodes/and_i8/output_0.cairo +++ b/tests/nodes/and_i8/output_0.cairo @@ -1,40 +1,40 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo index d2da45ca6..fb730f5c8 100644 --- a/tests/nodes/and_i8_broadcast.cairo +++ b/tests/nodes/and_i8_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::I8TensorPartialEq; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo index 542c0c702..9b56de844 100644 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ b/tests/nodes/and_i8_broadcast/input_0.cairo @@ -9,9 +9,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(i8 { mag: 2, sign: false }); + data.append(i8 { mag: 2, sign: false }); 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()) } diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo index e9b39b561..9a3d0511b 100644 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ b/tests/nodes/and_i8_broadcast/input_1.cairo @@ -9,7 +9,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(i8 { mag: 0, sign: false }); + data.append(i8 { mag: 2, sign: false }); data.append(i8 { mag: 1, sign: false }); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i8_broadcast/output_0.cairo b/tests/nodes/and_i8_broadcast/output_0.cairo index f90728ddd..cfa512f61 100644 --- a/tests/nodes/and_i8_broadcast/output_0.cairo +++ b/tests/nodes/and_i8_broadcast/output_0.cairo @@ -1,16 +1,16 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(true); + data.append(true); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo index f5c996719..cd0223fe3 100644 --- a/tests/nodes/and_u32.cairo +++ b/tests/nodes/and_u32.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; -use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::U32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo index f04e9df2f..223353b25 100644 --- a/tests/nodes/and_u32/input_0.cairo +++ b/tests/nodes/and_u32/input_0.cairo @@ -10,31 +10,31 @@ fn input_0() -> Tensor { let mut data = ArrayTrait::new(); data.append(5); - data.append(2); - data.append(5); - data.append(2); + data.append(1); data.append(4); - data.append(3); data.append(1); - data.append(0); + data.append(1); data.append(2); + data.append(1); + data.append(2); + data.append(5); + data.append(4); + data.append(4); 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(4); data.append(0); data.append(0); + data.append(5); + data.append(2); data.append(1); + data.append(3); + data.append(3); + data.append(0); + data.append(3); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo index 3b2fcb9c1..0f7af1f59 100644 --- a/tests/nodes/and_u32/input_1.cairo +++ b/tests/nodes/and_u32/input_1.cairo @@ -10,31 +10,31 @@ fn input_1() -> Tensor { 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(1); + data.append(2); 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(0); data.append(1); + data.append(2); + data.append(5); + data.append(0); + data.append(2); + data.append(0); + data.append(2); + data.append(1); + data.append(5); + data.append(5); data.append(1); data.append(3); - data.append(4); + data.append(3); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo index 576401ac8..86e333ba7 100644 --- a/tests/nodes/and_u32/output_0.cairo +++ b/tests/nodes/and_u32/output_0.cairo @@ -1,40 +1,40 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(true); + data.append(false); + data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo index cf022d7e5..242b3af94 100644 --- a/tests/nodes/and_u32_broadcast.cairo +++ b/tests/nodes/and_u32_broadcast.cairo @@ -3,11 +3,13 @@ mod input_1; mod output_0; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::TensorTrait; -use orion::operators::tensor::U32Tensor; +use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::U32TensorPartialEq; -use orion::utils::assert_eq; +use orion::operators::tensor::U32Tensor; +use array::{ArrayTrait, SpanTrait}; +use orion::operators::tensor::BoolTensorPartialEq; +use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo index 17f01780b..ecd2ce1a3 100644 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ b/tests/nodes/and_u32_broadcast/input_0.cairo @@ -8,9 +8,9 @@ fn input_0() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); + data.append(0); data.append(2); + data.append(1); data.append(2); - data.append(5); - data.append(4); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo index a11f0a16e..01550d690 100644 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ b/tests/nodes/and_u32_broadcast/input_1.cairo @@ -8,7 +8,7 @@ fn input_1() -> Tensor { shape.append(2); let mut data = ArrayTrait::new(); - data.append(5); - data.append(5); + data.append(2); + data.append(1); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo index 3883dcaf3..83cb01c24 100644 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ b/tests/nodes/and_u32_broadcast/output_0.cairo @@ -1,16 +1,16 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; +use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +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); + data.append(false); + data.append(true); + data.append(true); + data.append(true); TensorTrait::new(shape.span(), data.span()) } From 657106ec6aaa4e5c86d88e5aa92444f51efcbcf8 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 1 Dec 2023 10:47:10 +0200 Subject: [PATCH 158/160] replace input types --- src/operators/tensor/core.cairo | 14 +- .../tensor/implementations/tensor_bool.cairo | 2 +- .../implementations/tensor_fp16x16.cairo | 2 +- .../implementations/tensor_fp16x16wide.cairo | 2 +- .../implementations/tensor_fp32x32.cairo | 2 +- .../implementations/tensor_fp64x64.cairo | 2 +- .../implementations/tensor_fp8x23.cairo | 2 +- .../implementations/tensor_fp8x23wide.cairo | 2 +- .../tensor/implementations/tensor_i32.cairo | 2 +- .../tensor/implementations/tensor_i8.cairo | 2 +- .../tensor/implementations/tensor_u32.cairo | 20 +- src/operators/tensor/math/and.cairo | 19 +- tests/nodes.cairo | 1662 ++++++++--------- 13 files changed, 863 insertions(+), 870 deletions(-) diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index d2ffdb12a..321d1327c 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3452,7 +3452,7 @@ trait TensorTrait { /// #tensor.and /// /// ```rust - /// fn and(self: @Tensor, other: @Tensor) -> Tensor; + /// fn and(self: @Tensor, other: @Tensor) -> Tensor; /// ``` /// /// Computes the logical AND of two tensors element-wise. @@ -3462,8 +3462,8 @@ trait TensorTrait { /// /// ## Args /// - /// * `self`(`@Tensor`) - The first tensor to be compared - /// * `other`(`@Tensor`) - The second tensor to be compared + /// * `self`(`@Tensor`) - The first tensor to be compared + /// * `other`(`@Tensor`) - The second tensor to be compared /// /// ## Panics /// @@ -3483,11 +3483,11 @@ trait TensorTrait { /// use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; /// /// fn and_example() -> Tensor { - /// let tensor_1 = TensorTrait::::new( + /// 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( + /// let tensor_2 = TensorTrait::::new( /// shape: array![3, 3].span(), data: array![0, 1, 2, 0, 1, 2, 0, 1, 2].span(), /// ); /// @@ -3508,7 +3508,7 @@ trait TensorTrait { /// shape: array![3, 3].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7, 8].span(), /// ); /// - /// let tensor_2 = TensorTrait::::new( + /// let tensor_2 = TensorTrait::::new( /// shape: array![1, 3].span(), data: array![0, 1, 2].span(), /// ); /// @@ -3517,7 +3517,7 @@ trait TensorTrait { /// >>> [false, true, true, false, true, true, false, true, true] /// ``` /// - fn and(self: @Tensor, other: @Tensor) -> Tensor; + fn and(self: @Tensor, other: @Tensor) -> Tensor; /// #tensor.where /// /// ```rust diff --git a/src/operators/tensor/implementations/tensor_bool.cairo b/src/operators/tensor/implementations/tensor_bool.cairo index cfd6639db..c0a8d1ceb 100644 --- a/src/operators/tensor/implementations/tensor_bool.cairo +++ b/src/operators/tensor/implementations/tensor_bool.cairo @@ -257,7 +257,7 @@ impl BoolTensor of TensorTrait { } fn and(self: @Tensor, other: @Tensor) -> Tensor { - panic(array!['not supported!']) + math::and::and(self, other) } fn identity(self: @Tensor) -> Tensor { diff --git a/src/operators/tensor/implementations/tensor_fp16x16.cairo b/src/operators/tensor/implementations/tensor_fp16x16.cairo index 33829c816..dee654729 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16.cairo @@ -372,7 +372,7 @@ impl FP16x16Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo index c892b9c0f..2f89df88b 100644 --- a/src/operators/tensor/implementations/tensor_fp16x16wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp16x16wide.cairo @@ -334,7 +334,7 @@ impl FP16x16WTensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp32x32.cairo b/src/operators/tensor/implementations/tensor_fp32x32.cairo index 2f804c750..7517ef7cd 100644 --- a/src/operators/tensor/implementations/tensor_fp32x32.cairo +++ b/src/operators/tensor/implementations/tensor_fp32x32.cairo @@ -373,7 +373,7 @@ impl FP32x32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp64x64.cairo b/src/operators/tensor/implementations/tensor_fp64x64.cairo index 6e8ec0dc0..d4c7e0a2b 100644 --- a/src/operators/tensor/implementations/tensor_fp64x64.cairo +++ b/src/operators/tensor/implementations/tensor_fp64x64.cairo @@ -373,7 +373,7 @@ impl FP64x64Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23.cairo b/src/operators/tensor/implementations/tensor_fp8x23.cairo index 7ef733cfc..1f10a73a5 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23.cairo @@ -373,7 +373,7 @@ impl FP8x23Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo index a81f87d20..fc820222d 100644 --- a/src/operators/tensor/implementations/tensor_fp8x23wide.cairo +++ b/src/operators/tensor/implementations/tensor_fp8x23wide.cairo @@ -323,7 +323,7 @@ impl FP8x23WTensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_i32.cairo b/src/operators/tensor/implementations/tensor_i32.cairo index e54dc6a35..106daa208 100644 --- a/src/operators/tensor/implementations/tensor_i32.cairo +++ b/src/operators/tensor/implementations/tensor_i32.cairo @@ -371,7 +371,7 @@ impl I32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_i8.cairo b/src/operators/tensor/implementations/tensor_i8.cairo index 56386bdd1..d9bb40cb1 100644 --- a/src/operators/tensor/implementations/tensor_i8.cairo +++ b/src/operators/tensor/implementations/tensor_i8.cairo @@ -371,7 +371,7 @@ impl I8Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } diff --git a/src/operators/tensor/implementations/tensor_u32.cairo b/src/operators/tensor/implementations/tensor_u32.cairo index 003ed3380..288c834e9 100644 --- a/src/operators/tensor/implementations/tensor_u32.cairo +++ b/src/operators/tensor/implementations/tensor_u32.cairo @@ -315,7 +315,7 @@ impl U32Tensor of TensorTrait { core::clip(self, min, max) } - fn and(self: @Tensor, other: @Tensor) -> Tensor { + fn and(self: @Tensor, other: @Tensor) -> Tensor { math::and::and(self, other) } @@ -334,7 +334,7 @@ impl U32Tensor of TensorTrait { fn bitwise_xor(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_xor::bitwise_xor(self, other) } - + fn bitwise_or(self: @Tensor, other: @Tensor) -> Tensor { math::bitwise_or::bitwise_or(self, other) } @@ -376,12 +376,14 @@ impl U32Tensor of TensorTrait { fn reduce_l2(self: @Tensor, axis: usize, keepdims: bool) -> Tensor { panic(array!['not supported!']) } - + fn not(self: @Tensor) -> Tensor { panic(array!['not supported!']) } - fn gather_elements(self: @Tensor, indices: Tensor, axis: Option) -> Tensor { + fn gather_elements( + self: @Tensor, indices: Tensor, axis: Option + ) -> Tensor { math::gather_elements::gather_elements(self, indices, axis) } @@ -439,15 +441,19 @@ impl U32Tensor of TensorTrait { math::sequence_insert::sequence_insert(self, tensor, position) } - fn is_inf(self: @Tensor, detect_negative: Option, detect_positive: Option) -> Tensor { - math::is_inf::is_inf(self, detect_negative, detect_positive) + fn is_inf( + self: @Tensor, detect_negative: Option, detect_positive: Option + ) -> Tensor { + math::is_inf::is_inf(self, detect_negative, detect_positive) } fn is_nan(self: @Tensor) -> Tensor { panic(array!['not supported!']) } - fn concat_from_sequence(sequence: Array>, axis: i32, new_axis: Option) -> Tensor { + fn concat_from_sequence( + sequence: Array>, axis: i32, new_axis: Option + ) -> Tensor { math::concat_from_sequence::concat_from_sequence(sequence, axis, new_axis) } } diff --git a/src/operators/tensor/math/and.cairo b/src/operators/tensor/math/and.cairo index 1f31dc8de..123ae335a 100644 --- a/src/operators/tensor/math/and.cairo +++ b/src/operators/tensor/math/and.cairo @@ -3,22 +3,13 @@ use option::OptionTrait; use array::SpanTrait; use orion::numbers::NumberTrait; -use orion::operators::tensor::core::{Tensor, TensorTrait, unravel_index}; +use orion::operators::tensor::{core::{Tensor, TensorTrait, unravel_index}, BoolTensor}; use orion::operators::tensor::helpers::{ broadcast_shape, broadcast_index_mapping, len_from_shape, check_compatibility }; /// Cf: TensorTrait::and docstring -fn and< - T, - MAG, - impl TNumber: NumberTrait, - impl UsizeFTensor: TensorTrait, - impl TCopy: Copy, - impl TDrop: Drop ->( - y: @Tensor, z: @Tensor -) -> Tensor { +fn and(y: @Tensor, z: @Tensor) -> Tensor { let broadcasted_shape = broadcast_shape(*y.shape, *z.shape); let mut result: Array = ArrayTrait::new(); @@ -31,11 +22,7 @@ fn and< 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(true); - } else { - result.append(false); - } + result.append(*(*y.data)[indices_self] && *(*z.data)[indices_other]); n += 1; if n == num_elements { diff --git a/tests/nodes.cairo b/tests/nodes.cairo index f7986bb13..7caafcc03 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,831 +1,831 @@ -mod abs_fp16x16; -mod abs_fp8x23; -mod abs_i32; -mod abs_i8; -mod acos_fp16x16; -mod acos_fp8x23; -mod acosh_fp16x16; -mod acosh_fp8x23; -mod add_fp16x16; -mod add_fp16x16_broadcast; -mod add_fp8x23; -mod add_fp8x23_broadcast; -mod add_i32; -mod add_i32_broadcast; -mod add_i8; -mod add_i8_broadcast; -mod add_u32; -mod add_u32_broadcast; -mod argmax_fp16x16_1D_default; -mod argmax_fp16x16_1D_keepdims_false; -mod argmax_fp16x16_1D_last_index; -mod argmax_fp16x16_2D_default; -mod argmax_fp16x16_2D_keepdims_false; -mod argmax_fp16x16_2D_last_index; -mod argmax_fp16x16_3D_default; -mod argmax_fp16x16_3D_keepdims_false; -mod argmax_fp16x16_3D_last_index; -mod argmax_fp8x23_1D_default; -mod argmax_fp8x23_1D_keepdims_false; -mod argmax_fp8x23_1D_last_index; -mod argmax_fp8x23_2D_default; -mod argmax_fp8x23_2D_keepdims_false; -mod argmax_fp8x23_2D_last_index; -mod argmax_fp8x23_3D_default; -mod argmax_fp8x23_3D_keepdims_false; -mod argmax_fp8x23_3D_last_index; -mod argmax_i32_1D_default; -mod argmax_i32_1D_keepdims_false; -mod argmax_i32_1D_last_index; -mod argmax_i32_2D_default; -mod argmax_i32_2D_keepdims_false; -mod argmax_i32_2D_last_index; -mod argmax_i32_3D_default; -mod argmax_i32_3D_keepdims_false; -mod argmax_i32_3D_last_index; -mod argmax_i8_1D_default; -mod argmax_i8_1D_keepdims_false; -mod argmax_i8_1D_last_index; -mod argmax_i8_2D_default; -mod argmax_i8_2D_keepdims_false; -mod argmax_i8_2D_last_index; -mod argmax_i8_3D_default; -mod argmax_i8_3D_keepdims_false; -mod argmax_i8_3D_last_index; -mod argmax_u32_1D_default; -mod argmax_u32_1D_keepdims_false; -mod argmax_u32_1D_last_index; -mod argmax_u32_2D_default; -mod argmax_u32_2D_keepdims_false; -mod argmax_u32_2D_last_index; -mod argmax_u32_3D_default; -mod argmax_u32_3D_keepdims_false; -mod argmax_u32_3D_last_index; -mod argmin_fp16x16_1D_default; -mod argmin_fp16x16_1D_keepdims_false; -mod argmin_fp16x16_1D_last_index; -mod argmin_fp16x16_2D_default; -mod argmin_fp16x16_2D_keepdims_false; -mod argmin_fp16x16_2D_last_index; -mod argmin_fp16x16_3D_default; -mod argmin_fp16x16_3D_keepdims_false; -mod argmin_fp16x16_3D_last_index; -mod argmin_fp8x23_1D_default; -mod argmin_fp8x23_1D_keepdims_false; -mod argmin_fp8x23_1D_last_index; -mod argmin_fp8x23_2D_default; -mod argmin_fp8x23_2D_keepdims_false; -mod argmin_fp8x23_2D_last_index; -mod argmin_fp8x23_3D_default; -mod argmin_fp8x23_3D_keepdims_false; -mod argmin_fp8x23_3D_last_index; -mod argmin_i32_1D_default; -mod argmin_i32_1D_keepdims_false; -mod argmin_i32_1D_last_index; -mod argmin_i32_2D_default; -mod argmin_i32_2D_keepdims_false; -mod argmin_i32_2D_last_index; -mod argmin_i32_3D_default; -mod argmin_i32_3D_keepdims_false; -mod argmin_i32_3D_last_index; -mod argmin_i8_1D_default; -mod argmin_i8_1D_keepdims_false; -mod argmin_i8_1D_last_index; -mod argmin_i8_2D_default; -mod argmin_i8_2D_keepdims_false; -mod argmin_i8_2D_last_index; -mod argmin_i8_3D_default; -mod argmin_i8_3D_keepdims_false; -mod argmin_i8_3D_last_index; -mod argmin_u32_1D_default; -mod argmin_u32_1D_keepdims_false; -mod argmin_u32_1D_last_index; -mod argmin_u32_2D_default; -mod argmin_u32_2D_keepdims_false; -mod argmin_u32_2D_last_index; -mod argmin_u32_3D_default; -mod argmin_u32_3D_keepdims_false; -mod argmin_u32_3D_last_index; -mod asin_fp16x16; -mod asin_fp8x23; -mod asinh_fp16x16; -mod asinh_fp8x23; -mod atan_fp16x16; -mod atan_fp8x23; -mod ceil_fp16x16; -mod ceil_fp8x23; -mod concat_fp16x16_1d; -mod concat_fp16x16_2d; -mod concat_fp16x16_3d_default; -mod concat_fp16x16_3d_axis_1; -mod concat_fp16x16_3d_axis_2; -mod concat_fp16x16_3d_three_tensors_axis_1; -mod concat_fp16x16_3d_three_tensors_axis_2; -mod concat_fp8x23_1d; -mod concat_fp8x23_2d; -mod concat_fp8x23_3d_default; -mod concat_fp8x23_3d_axis_1; -mod concat_fp8x23_3d_axis_2; -mod concat_fp8x23_3d_three_tensors_axis_1; -mod concat_fp8x23_3d_three_tensors_axis_2; -mod concat_i32_1d; -mod concat_i32_2d; -mod concat_i32_3d_default; -mod concat_i32_3d_axis_1; -mod concat_i32_3d_axis_2; -mod concat_i32_3d_three_tensors_axis_1; -mod concat_i32_3d_three_tensors_axis_2; -mod concat_i8_1d; -mod concat_i8_2d; -mod concat_i8_3d_default; -mod concat_i8_3d_axis_1; -mod concat_i8_3d_axis_2; -mod concat_i8_3d_three_tensors_axis_1; -mod concat_i8_3d_three_tensors_axis_2; -mod concat_u32_1d; -mod concat_u32_2d; -mod concat_u32_3d_default; -mod concat_u32_3d_axis_1; -mod concat_u32_3d_axis_2; -mod concat_u32_3d_three_tensors_axis_1; -mod concat_u32_3d_three_tensors_axis_2; -mod cos_fp16x16; -mod cos_fp8x23; -mod cosh_fp16x16; -mod cosh_fp8x23; -mod cumsum_fp16x16_1d_default; -mod cumsum_fp16x16_1d_exclusive; -mod cumsum_fp16x16_1d_reverse; -mod cumsum_fp16x16_1d_reverse_exclusive; -mod cumsum_fp16x16_2d_axis_0; -mod cumsum_fp16x16_2d_axis_1; -mod cumsum_fp8x23_1d_default; -mod cumsum_fp8x23_1d_exclusive; -mod cumsum_fp8x23_1d_reverse; -mod cumsum_fp8x23_1d_reverse_exclusive; -mod cumsum_fp8x23_2d_axis_0; -mod cumsum_fp8x23_2d_axis_1; -mod cumsum_i32_1d_default; -mod cumsum_i32_1d_exclusive; -mod cumsum_i32_1d_reverse; -mod cumsum_i32_1d_reverse_exclusive; -mod cumsum_i32_2d_axis_0; -mod cumsum_i32_2d_axis_1; -mod cumsum_i8_1d_default; -mod cumsum_i8_1d_exclusive; -mod cumsum_i8_1d_reverse; -mod cumsum_i8_1d_reverse_exclusive; -mod cumsum_i8_2d_axis_0; -mod cumsum_i8_2d_axis_1; -mod cumsum_u32_1d_default; -mod cumsum_u32_1d_exclusive; -mod cumsum_u32_1d_reverse; -mod cumsum_u32_1d_reverse_exclusive; -mod cumsum_u32_2d_axis_0; -mod cumsum_u32_2d_axis_1; -mod div_fp16x16; -mod div_fp16x16_broadcast; -mod div_fp8x23; -mod div_fp8x23_broadcast; -mod div_i32; -mod div_i32_broadcast; -mod div_i8; -mod div_i8_broadcast; -mod div_u32; -mod div_u32_broadcast; -mod equal_fp16x16; -mod equal_fp16x16_broadcast; -mod equal_fp8x23; -mod equal_fp8x23_broadcast; -mod equal_i32; -mod equal_i32_broadcast; -mod equal_i8; -mod equal_i8_broadcast; -mod equal_u32; -mod equal_u32_broadcast; -mod exp_fp16x16; -mod exp_fp8x23; -mod less_equal_fp16x16; -mod less_equal_fp16x16_broadcast; -mod less_equal_fp8x23; -mod less_equal_fp8x23_broadcast; -mod less_equal_i32; -mod less_equal_i32_broadcast; -mod less_equal_i8; -mod less_equal_i8_broadcast; -mod less_equal_u32; -mod less_equal_u32_broadcast; -mod greater_fp16x16; -mod greater_fp16x16_broadcast; -mod greater_fp8x23; -mod greater_fp8x23_broadcast; -mod greater_i32; -mod greater_i32_broadcast; -mod greater_i8; -mod greater_i8_broadcast; -mod greater_u32; -mod greater_u32_broadcast; -mod leaky_relu_fp16x16; -mod leaky_relu_fp8x23; -mod linear_fp16x16; -mod linear_fp8x23; -mod linear_i32; -mod linear_i8; -mod linear_u32; -mod log_fp16x16; -mod log_fp8x23; -mod logsoftmax_fp16x16_axis_0; -mod logsoftmax_fp16x16_axis_1; -mod logsoftmax_fp8x23_axis_0; -mod logsoftmax_fp8x23_axis_1; -mod matmul_fp16x16_1d; -mod matmul_fp16x16_2x2; -mod matmul_fp16x16_2x1; -mod matmul_fp16x16_1x2; -mod matmul_fp8x23_1d; -mod matmul_fp8x23_2x2; -mod matmul_fp8x23_2x1; -mod matmul_fp8x23_1x2; -mod matmul_i32_1d; -mod matmul_i32_2x2; -mod matmul_i32_2x1; -mod matmul_i32_1x2; -mod matmul_i8_1d; -mod matmul_i8_2x2; -mod matmul_i8_2x1; -mod matmul_i8_1x2; -mod matmul_u32_1d; -mod matmul_u32_2x2; -mod matmul_u32_2x1; -mod matmul_u32_1x2; -mod mul_fp16x16; -mod mul_fp16x16_broadcast; -mod mul_fp8x23; -mod mul_fp8x23_broadcast; -mod mul_i32; -mod mul_i32_broadcast; -mod mul_i8; -mod mul_i8_broadcast; -mod mul_u32; -mod mul_u32_broadcast; -mod or_fp16x16; -mod or_fp16x16_broadcast; -mod or_fp8x23; -mod or_fp8x23_broadcast; -mod or_i32; -mod or_i32_broadcast; -mod or_i8; -mod or_i8_broadcast; -mod or_u32; -mod or_u32_broadcast; -mod reduce_sum_fp16x16_1D; -mod reduce_sum_fp16x16_2D_default; -mod reduce_sum_fp16x16_2D_keepdims; -mod reduce_sum_fp16x16_2D_axis_1; -mod reduce_sum_fp8x23_1D; -mod reduce_sum_fp8x23_2D_default; -mod reduce_sum_fp8x23_2D_keepdims; -mod reduce_sum_fp8x23_2D_axis_1; -mod reduce_sum_i32_1D; -mod reduce_sum_i32_2D_default; -mod reduce_sum_i32_2D_keepdims; -mod reduce_sum_i32_2D_axis_1; -mod reduce_sum_i8_1D; -mod reduce_sum_i8_2D_default; -mod reduce_sum_i8_2D_keepdims; -mod reduce_sum_i8_2D_axis_1; -mod reduce_sum_u32_1D; -mod reduce_sum_u32_2D_default; -mod reduce_sum_u32_2D_keepdims; -mod reduce_sum_u32_2D_axis_1; -mod relu_fp16x16; -mod relu_fp8x23; -mod relu_i32; -mod relu_i8; -mod sigmoid_fp16x16; -mod sigmoid_fp8x23; -mod sin_fp16x16; -mod sin_fp8x23; -mod sinh_fp16x16; -mod sinh_fp8x23; -mod softmax_fp16x16; -mod softmax_fp8x23; -mod softplus_fp8x23; -mod softplus_fp16x16; -mod softsign_fp8x23; -mod softsign_fp16x16; -mod sqrt_fp16x16; -mod sqrt_fp8x23; -mod sub_fp16x16; -mod sub_fp16x16_broadcast; -mod sub_fp8x23; -mod sub_fp8x23_broadcast; -mod sub_i32; -mod sub_i32_broadcast; -mod sub_i8; -mod sub_i8_broadcast; -mod sub_u32; -mod sub_u32_broadcast; -mod tanh_fp16x16; -mod tanh_fp8x23; -mod transpose_fp16x16_2d; -mod transpose_fp16x16_3d; -mod transpose_fp8x23_2d; -mod transpose_fp8x23_3d; -mod transpose_i32_2d; -mod transpose_i32_3d; -mod transpose_i8_2d; -mod transpose_i8_3d; -mod transpose_u32_2d; -mod transpose_u32_3d; -mod xor_fp16x16; -mod xor_fp16x16_broadcast; -mod xor_fp8x23; -mod xor_fp8x23_broadcast; -mod xor_i32; -mod xor_i32_broadcast; -mod xor_i8; -mod xor_i8_broadcast; -mod xor_u32; -mod xor_u32_broadcast; -mod less_fp16x16; -mod less_fp16x16_broadcast; -mod less_fp8x23; -mod less_fp8x23_broadcast; -mod less_i32; -mod less_i32_broadcast; -mod less_i8; -mod less_i8_broadcast; -mod less_u32; -mod less_u32_broadcast; -mod greater_equal_fp16x16; -mod greater_equal_fp16x16_broadcast; -mod greater_equal_fp8x23; -mod greater_equal_fp8x23_broadcast; -mod greater_equal_i32; -mod greater_equal_i32_broadcast; -mod greater_equal_i8; -mod greater_equal_i8_broadcast; -mod greater_equal_u32; -mod greater_equal_u32_broadcast; -mod slice_fp16x16_2d; -mod slice_fp16x16_3d; -mod slice_fp8x23_2d; -mod slice_fp8x23_3d; -mod slice_i32_2d; -mod slice_i32_3d; -mod slice_i8_2d; -mod slice_i8_3d; -mod slice_u32_2d; -mod slice_u32_3d; -mod gather_fp8x23_3d_default; -mod gather_fp8x23_3d_axis1; -mod gather_fp8x23_3d_axis2; -mod gather_fp16x16_3d_default; -mod gather_fp16x16_3d_axis1; -mod gather_fp16x16_3d_axis2; -mod gather_i8_3d_default; -mod gather_i8_3d_axis1; -mod gather_i8_3d_axis2; -mod gather_i32_3d_default; -mod gather_i32_3d_axis1; -mod gather_i32_3d_axis2; -mod gather_u32_3d_default; -mod gather_u32_3d_axis1; -mod gather_u32_3d_axis2; -mod nonzero_fp16x16_2d; -mod nonzero_fp16x16_3d; -mod nonzero_fp8x23_2d; -mod nonzero_fp8x23_3d; -mod nonzero_i32_2d; -mod nonzero_i32_3d; -mod nonzero_i8_2d; -mod nonzero_i8_3d; -mod nonzero_u32_2d; -mod nonzero_u32_3d; -mod squeeze_fP16x16; -mod squeeze_fP8x23; -mod squeeze_i32; -mod squeeze_i8; -mod squeeze_u32; -mod unsqueeze_fp16x16_2d; -mod unsqueeze_fp16x16_3d; -mod unsqueeze_fp8x23_2d; -mod unsqueeze_fp8x23_3d; -mod unsqueeze_i32_2d; -mod unsqueeze_i32_3d; -mod unsqueeze_i8_2d; -mod unsqueeze_i8_3d; -mod unsqueeze_u32_2d; -mod unsqueeze_u32_3d; -mod sign_fP16x16; -mod sign_fP8x23; -mod sign_fail; -mod sign_i32; -mod sign_i8; -mod clip_fp16x16_2d; -mod clip_fp16x16_3d; -mod clip_fp8x23_2d; -mod clip_fp8x23_3d; -mod clip_i32_2d; -mod clip_i32_3d; -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; -mod identity_fP16x16; -mod identity_fP8x23; -mod identity_i32; -mod identity_i8; -mod identity_u32; -mod thresholded_relu_fp16x16; -mod thresholded_relu_fp8x23; -mod hard_sigmoid_fp8x23; -mod hard_sigmoid_fp16x16; -mod neg_fp16x16; -mod neg_fp8x23; -mod neg_i32; -mod neg_i8; -mod gemm_all_attributes; -mod gemm_alpha; -mod gemm_beta; -mod gemm_default_matrix_bias; -mod gemm_default_vector_bias; -mod gemm_default_no_bias; -mod gemm_transposeA; -mod gemm_transposeB; -mod min_fp16x16_three_tensors; -mod min_fp16x16_broadcast_three_tensors; -mod min_fp16x16_two_tensors; -mod min_fp16x16_broadcast_two_tensors; -mod min_fp8x23_three_tensors; -mod min_fp8x23_broadcast_three_tensors; -mod min_fp8x23_two_tensors; -mod min_fp8x23_broadcast_two_tensors; -mod min_i32_three_tensors; -mod min_i32_broadcast_three_tensors; -mod min_i32_two_tensors; -mod min_i32_broadcast_two_tensors; -mod min_i8_three_tensors; -mod min_i8_broadcast_three_tensors; -mod min_i8_two_tensors; -mod min_i8_broadcast_two_tensors; -mod min_u32_three_tensors; -mod min_u32_broadcast_three_tensors; -mod min_u32_two_tensors; -mod min_u32_broadcast_two_tensors; -mod where_fp16x16; -mod where_fp16x16_broadcast; -mod where_fp8x23; -mod where_fp8x23_broadcast; -mod where_i32; -mod where_i32_broadcast; -mod where_i8; -mod where_i8_broadcast; -mod where_u32; -mod where_u32_broadcast; -mod not_bool; -mod round_fp16x16; -mod round_fp8x23; -mod max_fp16x16_three_tensors; -mod max_fp16x16_broadcast_three_tensors; -mod max_fp16x16_two_tensors; -mod max_fp16x16_broadcast_two_tensors; -mod max_fp8x23_three_tensors; -mod max_fp8x23_broadcast_three_tensors; -mod max_fp8x23_two_tensors; -mod max_fp8x23_broadcast_two_tensors; -mod max_i32_three_tensors; -mod max_i32_broadcast_three_tensors; -mod max_i32_two_tensors; -mod max_i32_broadcast_two_tensors; -mod max_i8_three_tensors; -mod max_i8_broadcast_three_tensors; -mod max_i8_two_tensors; -mod max_i8_broadcast_two_tensors; -mod max_u32_three_tensors; -mod max_u32_broadcast_three_tensors; -mod max_u32_two_tensors; -mod max_u32_broadcast_two_tensors; -mod scatter_fp16x16_3d_default; -mod scatter_fp16x16_3d_axis1; -mod scatter_fp16x16_3d_axis1_add; -mod scatter_fp8x23_default; -mod scatter_fp8x23_axis1; -mod scatter_fp8x23_mul; -mod scatter_i8_default; -mod scatter_i8_axis1; -mod scatter_i8_axis1_max; -mod scatter_u32_default; -mod scatter_u32_axis1; -mod scatter_u32_add; -mod array_feature_extractor_1D_i32; -mod array_feature_extractor_1D_fp8x23; -mod array_feature_extractor_1D_fp16x16; -mod array_feature_extractor_2D_i32; -mod array_feature_extractor_2D_fp8x23; -mod array_feature_extractor_2D_fp16x16; -mod array_feature_extractor_3D_i32; -mod array_feature_extractor_3D_fp8x23; -mod array_feature_extractor_3D_fp16x16; -mod binarizer_fp16x16; -mod binarizer_fp8x23; -mod tril_fp16x16; -mod tril_fp16x16_neg; -mod tril_fp16x16_one_row; -mod tril_fp16x16_out_neg; -mod tril_fp16x16_out_pos; -mod tril_fp16x16_pos; -mod tril_fp16x16_square; -mod tril_fp16x16_square_neg; -mod tril_fp16x16_zero; -mod triu_fp16x16; -mod triu_fp16x16_neg; -mod triu_fp16x16_one_row; -mod triu_fp16x16_out_neg; -mod triu_fp16x16_out_pos; -mod triu_fp16x16_pos; -mod triu_fp16x16_square; -mod triu_fp16x16_square_neg; -mod triu_fp16x16_zero; -mod tril_fp8x23; -mod tril_fp8x23_neg; -mod tril_fp8x23_one_row; -mod tril_fp8x23_out_neg; -mod tril_fp8x23_out_pos; -mod tril_fp8x23_pos; -mod tril_fp8x23_square; -mod tril_fp8x23_square_neg; -mod tril_fp8x23_zero; -mod triu_fp8x23; -mod triu_fp8x23_neg; -mod triu_fp8x23_one_row; -mod triu_fp8x23_out_neg; -mod triu_fp8x23_out_pos; -mod triu_fp8x23_pos; -mod triu_fp8x23_square; -mod triu_fp8x23_square_neg; -mod triu_fp8x23_zero; -mod tril_i32; -mod tril_neg_i32; -mod tril_i32_one_row; -mod tril_i32_out_neg; -mod tril_i32_out_pos; -mod tril_i32_pos; -mod tril_i32_square; -mod tril_i32_square_neg; -mod tril_i32_zero; -mod triu_i32; -mod triu_i32_neg; -mod triu_i32_one_row; -mod triu_i32_out_neg; -mod triu_i32_out_pos; -mod triu_i32_pos; -mod triu_i32_square; -mod triu_i32_square_neg; -mod triu_i32_zero; -mod tril_i8; -mod tril_i8_neg; -mod tril_i8_one_row; -mod tril_i8_out_neg; -mod tril_i8_out_pos; -mod tril_i8_pos; -mod tril_i8_square; -mod tril_i8_square_neg; -mod tril_i8_zero; -mod triu_i8; -mod triu_i8_neg; -mod triu_i8_one_row; -mod triu_i8_out_neg; -mod triu_i8_out_pos; -mod triu_i8_pos; -mod triu_i8_square; -mod triu_i8_square_neg; -mod triu_i8_zero; -mod tril_u32; -mod tril_u32_neg; -mod tril_u32_one_row; -mod tril_u32_out_neg; -mod tril_u32_out_pos; -mod tril_u32_pos; -mod tril_u32_square; -mod tril_u32_square_neg; -mod tril_u32_zero; -mod triu_u32; -mod triu_u32_neg; -mod triu_u32_one_row; -mod triu_u32_out_neg; -mod triu_u32_out_pos; -mod triu_u32_pos; -mod triu_u32_square; -mod triu_u32_square_neg; -mod triu_u32_zero; -mod reduce_sum_square_fp16x16_export_do_not_keepdims; -mod reduce_sum_square_fp16x16_export_keepdims; -mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; -mod reduce_sum_square_fp8x23_export_do_not_keepdims; -mod reduce_sum_square_fp8x23_export_keepdims; -mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; -mod reduce_sum_square_i32_export_do_not_keepdims; -mod reduce_sum_square_i32_export_keepdims; -mod reduce_sum_square_i32_export_negative_axes_keepdims; -mod reduce_sum_square_i8_export_do_not_keepdims; -mod reduce_sum_square_i8_export_keepdims; -mod reduce_sum_square_i8_export_negative_axes_keepdims; -mod reduce_sum_square_u32_export_do_not_keepdims; -mod reduce_sum_square_u32_export_keepdims; -mod reduce_sum_square_u32_export_negative_axes_keepdims; -mod reduce_l2_fp16x16_export_do_not_keepdims; -mod reduce_l2_fp16x16_export_keepdims; -mod reduce_l2_fp16x16_export_negative_axes_keepdims; -mod reduce_l2_fp8x23_export_do_not_keepdims; -mod reduce_l2_fp8x23_export_keepdims; -mod reduce_l2_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_fp16x16_export_do_not_keepdims; -mod reduce_l1_fp16x16_export_keepdims; -mod reduce_l1_fp16x16_export_negative_axes_keepdims; -mod reduce_l1_fp8x23_export_do_not_keepdims; -mod reduce_l1_fp8x23_export_keepdims; -mod reduce_l1_fp8x23_export_negative_axes_keepdims; -mod reduce_l1_i32_export_do_not_keepdims; -mod reduce_l1_i32_export_keepdims; -mod reduce_l1_i32_export_negative_axes_keepdims; -mod reduce_l1_i8_export_do_not_keepdims; -mod reduce_l1_i8_export_keepdims; -mod reduce_l1_i8_export_negative_axes_keepdims; -mod reduce_l1_u32_export_do_not_keepdims; -mod reduce_l1_u32_export_keepdims; -mod reduce_l1_u32_export_negative_axes_keepdims; -mod reduce_prod_fp16x16_1D; -mod reduce_prod_fp16x16_2D_default; -mod reduce_prod_fp16x16_2D_keepdims; -mod reduce_prod_fp16x16_2D_axis_1; -mod reduce_prod_fp8x23_1D; -mod reduce_prod_fp8x23_2D_default; -mod reduce_prod_fp8x23_2D_keepdims; -mod reduce_prod_fp8x23_2D_axis_1; -mod reduce_prod_i32_1D; -mod reduce_prod_i32_2D_default; -mod reduce_prod_i32_2D_keepdims; -mod reduce_prod_i32_2D_axis_1; -mod reduce_prod_i8_1D; -mod reduce_prod_i8_2D_default; -mod reduce_prod_i8_2D_keepdims; -mod reduce_prod_i8_2D_axis_1; -mod reduce_prod_u32_1D; -mod reduce_prod_u32_2D_default; -mod reduce_prod_u32_2D_keepdims; -mod reduce_prod_u32_2D_axis_1; -mod gather_elements_fp16x16_3d_default; -mod gather_elements_fp16x16_3d_axis1; -mod gather_elements_fp16x16_3d_axis2; -mod gather_elements_fp8x23_3d_default; -mod gather_elements_fp8x23_3d_axis1; -mod gather_elements_fp8x23_3d_axis2; -mod gather_elements_i8_3d_default; -mod gather_elements_i8_3d_axis1; -mod gather_elements_i32_3d_default; -mod gather_elements_i32_3d_axis1; -mod gather_elements_i32_3d_axis2; -mod gather_elements_u32_default; -mod gather_elements_u32_axis1; -mod gather_elements_u32_axis2; -mod gather_elements_u32_axis3; -mod sequence_length_fp16x16; -mod sequence_length_fp16x16_broadcast; -mod sequence_length_fp8x23; -mod sequence_length_fp8x23_broadcast; -mod sequence_length_i32; -mod sequence_length_i32_broadcast; -mod sequence_length_i8; -mod sequence_length_i8_broadcast; -mod sequence_length_u32; -mod sequence_length_u32_broadcast; -mod sequence_at_u32_positive; -mod sequence_at_u32_negative; -mod sequence_at_fp16x16_positive; -mod sequence_at_fp16x16_negative; -mod sequence_at_fp8x23_positive; -mod sequence_at_fp8x23_negative; -mod sequence_at_i32_positive; -mod sequence_at_i32_negative; -mod sequence_at_i8_positive; -mod sequence_at_i8_negative; -mod reduce_min_fp16x16_1D; -mod reduce_min_fp16x16_2D_default; -mod reduce_min_fp16x16_2D_keepdims; -mod reduce_min_fp16x16_2D_axis_1; -mod reduce_min_fp8x23_1D; -mod reduce_min_fp8x23_2D_default; -mod reduce_min_fp8x23_2D_keepdims; -mod reduce_min_fp8x23_2D_axis_1; -mod reduce_min_i32_1D; -mod reduce_min_i32_2D_default; -mod reduce_min_i32_2D_keepdims; -mod reduce_min_i32_2D_axis_1; -mod reduce_min_i8_1D; -mod reduce_min_i8_2D_default; -mod reduce_min_i8_2D_keepdims; -mod reduce_min_i8_2D_axis_1; -mod reduce_min_u32_1D; -mod reduce_min_u32_2D_default; -mod reduce_min_u32_2D_keepdims; -mod reduce_min_u32_2D_axis_1; -mod sequence_construct_fp16x16; -mod sequence_construct_fp8x23; -mod sequence_construct_i32; -mod sequence_construct_i8; -mod sequence_construct_u32; -mod shrink_hard_fp16x16; -mod shrink_soft_fp16x16; -mod shrink_hard_fp8x23; -mod shrink_soft_fp8x23; -mod sequence_empty_fp16x16; -mod sequence_empty_fp8x23; -mod sequence_empty_i32; -mod sequence_empty_i8; -mod sequence_empty_u32; -mod reduce_mean_fp16x16_1D; -mod reduce_mean_fp16x16_2D_default; -mod reduce_mean_fp16x16_2D_keepdims; -mod reduce_mean_fp16x16_2D_axis_1; -mod reduce_mean_fp8x23_1D; -mod reduce_mean_fp8x23_2D_default; -mod reduce_mean_fp8x23_2D_keepdims; -mod reduce_mean_fp8x23_2D_axis_1; -mod reduce_mean_i32_1D; -mod reduce_mean_i32_2D_default; -mod reduce_mean_i32_2D_keepdims; -mod reduce_mean_i32_2D_axis_1; -mod reduce_mean_i8_1D; -mod reduce_mean_i8_2D_default; -mod reduce_mean_i8_2D_keepdims; -mod reduce_mean_i8_2D_axis_1; -mod reduce_mean_u32_1D; -mod reduce_mean_u32_2D_default; -mod reduce_mean_u32_2D_keepdims; -mod reduce_mean_u32_2D_axis_1; -mod pow_fp16x16; -mod pow_fp16x16_broadcast; -mod pow_fp8x23; -mod pow_fp8x23_broadcast; -mod sequence_erase_u32_positive; -mod sequence_erase_u32_negative; -mod sequence_erase_u32_empty; -mod sequence_erase_fp16x16_positive; -mod sequence_erase_fp16x16_negative; -mod sequence_erase_fp16x16_empty; -mod sequence_erase_fp8x23_positive; -mod sequence_erase_fp8x23_negative; -mod sequence_erase_fp8x23_empty; -mod sequence_erase_i32_positive; -mod sequence_erase_i32_negative; -mod sequence_erase_i32_empty; -mod sequence_erase_i8_positive; -mod sequence_erase_i8_negative; -mod sequence_erase_i8_empty; -mod sequence_insert_fp16x16; -mod sequence_insert_fp8x23; -mod sequence_insert_i32; -mod sequence_insert_i8; -mod sequence_insert_u32; -mod concat_from_sequence_fp8x23_new_axis_zero; -mod concat_from_sequence_fp8x23_new_axis_one; -mod concat_from_sequence_fp8x23_new_axis_default; -mod concat_from_sequence_fp16x16_new_axis_zero; -mod concat_from_sequence_fp16x16_new_axis_one; -mod concat_from_sequence_fp16x16_new_axis_default; -mod concat_from_sequence_i32_new_axis_zero; -mod concat_from_sequence_i32_new_axis_one; -mod concat_from_sequence_i32_new_axis_default; -mod concat_from_sequence_i8_new_axis_zero; -mod concat_from_sequence_i8_new_axis_one; -mod concat_from_sequence_i8_new_axis_default; -mod concat_from_sequence_u32_new_axis_zero; -mod concat_from_sequence_u32_new_axis_one; -mod concat_from_sequence_u32_new_axis_default; -mod is_nan_fp16x16; -mod is_nan_fp8x23; -mod is_inf_fp16x16; -mod is_inf_fp8x23; -mod is_inf_i32; -mod is_inf_i8; -mod is_inf_u32; -mod is_pos_inf_fp16x16; -mod is_neg_inf_fp16x16; -mod is_pos_inf_fp8x23; -mod is_neg_inf_fp8x23; -mod is_pos_inf_i32; -mod is_neg_inf_i32; -mod is_pos_inf_i8; -mod is_neg_inf_i8; +// mod abs_fp16x16; +// mod abs_fp8x23; +// mod abs_i32; +// mod abs_i8; +// mod acos_fp16x16; +// mod acos_fp8x23; +// mod acosh_fp16x16; +// mod acosh_fp8x23; +// mod add_fp16x16; +// mod add_fp16x16_broadcast; +// mod add_fp8x23; +// mod add_fp8x23_broadcast; +// mod add_i32; +// mod add_i32_broadcast; +// mod add_i8; +// mod add_i8_broadcast; +// mod add_u32; +// mod add_u32_broadcast; +// mod argmax_fp16x16_1D_default; +// mod argmax_fp16x16_1D_keepdims_false; +// mod argmax_fp16x16_1D_last_index; +// mod argmax_fp16x16_2D_default; +// mod argmax_fp16x16_2D_keepdims_false; +// mod argmax_fp16x16_2D_last_index; +// mod argmax_fp16x16_3D_default; +// mod argmax_fp16x16_3D_keepdims_false; +// mod argmax_fp16x16_3D_last_index; +// mod argmax_fp8x23_1D_default; +// mod argmax_fp8x23_1D_keepdims_false; +// mod argmax_fp8x23_1D_last_index; +// mod argmax_fp8x23_2D_default; +// mod argmax_fp8x23_2D_keepdims_false; +// mod argmax_fp8x23_2D_last_index; +// mod argmax_fp8x23_3D_default; +// mod argmax_fp8x23_3D_keepdims_false; +// mod argmax_fp8x23_3D_last_index; +// mod argmax_i32_1D_default; +// mod argmax_i32_1D_keepdims_false; +// mod argmax_i32_1D_last_index; +// mod argmax_i32_2D_default; +// mod argmax_i32_2D_keepdims_false; +// mod argmax_i32_2D_last_index; +// mod argmax_i32_3D_default; +// mod argmax_i32_3D_keepdims_false; +// mod argmax_i32_3D_last_index; +// mod argmax_i8_1D_default; +// mod argmax_i8_1D_keepdims_false; +// mod argmax_i8_1D_last_index; +// mod argmax_i8_2D_default; +// mod argmax_i8_2D_keepdims_false; +// mod argmax_i8_2D_last_index; +// mod argmax_i8_3D_default; +// mod argmax_i8_3D_keepdims_false; +// mod argmax_i8_3D_last_index; +// mod argmax_u32_1D_default; +// mod argmax_u32_1D_keepdims_false; +// mod argmax_u32_1D_last_index; +// mod argmax_u32_2D_default; +// mod argmax_u32_2D_keepdims_false; +// mod argmax_u32_2D_last_index; +// mod argmax_u32_3D_default; +// mod argmax_u32_3D_keepdims_false; +// mod argmax_u32_3D_last_index; +// mod argmin_fp16x16_1D_default; +// mod argmin_fp16x16_1D_keepdims_false; +// mod argmin_fp16x16_1D_last_index; +// mod argmin_fp16x16_2D_default; +// mod argmin_fp16x16_2D_keepdims_false; +// mod argmin_fp16x16_2D_last_index; +// mod argmin_fp16x16_3D_default; +// mod argmin_fp16x16_3D_keepdims_false; +// mod argmin_fp16x16_3D_last_index; +// mod argmin_fp8x23_1D_default; +// mod argmin_fp8x23_1D_keepdims_false; +// mod argmin_fp8x23_1D_last_index; +// mod argmin_fp8x23_2D_default; +// mod argmin_fp8x23_2D_keepdims_false; +// mod argmin_fp8x23_2D_last_index; +// mod argmin_fp8x23_3D_default; +// mod argmin_fp8x23_3D_keepdims_false; +// mod argmin_fp8x23_3D_last_index; +// mod argmin_i32_1D_default; +// mod argmin_i32_1D_keepdims_false; +// mod argmin_i32_1D_last_index; +// mod argmin_i32_2D_default; +// mod argmin_i32_2D_keepdims_false; +// mod argmin_i32_2D_last_index; +// mod argmin_i32_3D_default; +// mod argmin_i32_3D_keepdims_false; +// mod argmin_i32_3D_last_index; +// mod argmin_i8_1D_default; +// mod argmin_i8_1D_keepdims_false; +// mod argmin_i8_1D_last_index; +// mod argmin_i8_2D_default; +// mod argmin_i8_2D_keepdims_false; +// mod argmin_i8_2D_last_index; +// mod argmin_i8_3D_default; +// mod argmin_i8_3D_keepdims_false; +// mod argmin_i8_3D_last_index; +// mod argmin_u32_1D_default; +// mod argmin_u32_1D_keepdims_false; +// mod argmin_u32_1D_last_index; +// mod argmin_u32_2D_default; +// mod argmin_u32_2D_keepdims_false; +// mod argmin_u32_2D_last_index; +// mod argmin_u32_3D_default; +// mod argmin_u32_3D_keepdims_false; +// mod argmin_u32_3D_last_index; +// mod asin_fp16x16; +// mod asin_fp8x23; +// mod asinh_fp16x16; +// mod asinh_fp8x23; +// mod atan_fp16x16; +// mod atan_fp8x23; +// mod ceil_fp16x16; +// mod ceil_fp8x23; +// mod concat_fp16x16_1d; +// mod concat_fp16x16_2d; +// mod concat_fp16x16_3d_default; +// mod concat_fp16x16_3d_axis_1; +// mod concat_fp16x16_3d_axis_2; +// mod concat_fp16x16_3d_three_tensors_axis_1; +// mod concat_fp16x16_3d_three_tensors_axis_2; +// mod concat_fp8x23_1d; +// mod concat_fp8x23_2d; +// mod concat_fp8x23_3d_default; +// mod concat_fp8x23_3d_axis_1; +// mod concat_fp8x23_3d_axis_2; +// mod concat_fp8x23_3d_three_tensors_axis_1; +// mod concat_fp8x23_3d_three_tensors_axis_2; +// mod concat_i32_1d; +// mod concat_i32_2d; +// mod concat_i32_3d_default; +// mod concat_i32_3d_axis_1; +// mod concat_i32_3d_axis_2; +// mod concat_i32_3d_three_tensors_axis_1; +// mod concat_i32_3d_three_tensors_axis_2; +// mod concat_i8_1d; +// mod concat_i8_2d; +// mod concat_i8_3d_default; +// mod concat_i8_3d_axis_1; +// mod concat_i8_3d_axis_2; +// mod concat_i8_3d_three_tensors_axis_1; +// mod concat_i8_3d_three_tensors_axis_2; +// mod concat_u32_1d; +// mod concat_u32_2d; +// mod concat_u32_3d_default; +// mod concat_u32_3d_axis_1; +// mod concat_u32_3d_axis_2; +// mod concat_u32_3d_three_tensors_axis_1; +// mod concat_u32_3d_three_tensors_axis_2; +// mod cos_fp16x16; +// mod cos_fp8x23; +// mod cosh_fp16x16; +// mod cosh_fp8x23; +// mod cumsum_fp16x16_1d_default; +// mod cumsum_fp16x16_1d_exclusive; +// mod cumsum_fp16x16_1d_reverse; +// mod cumsum_fp16x16_1d_reverse_exclusive; +// mod cumsum_fp16x16_2d_axis_0; +// mod cumsum_fp16x16_2d_axis_1; +// mod cumsum_fp8x23_1d_default; +// mod cumsum_fp8x23_1d_exclusive; +// mod cumsum_fp8x23_1d_reverse; +// mod cumsum_fp8x23_1d_reverse_exclusive; +// mod cumsum_fp8x23_2d_axis_0; +// mod cumsum_fp8x23_2d_axis_1; +// mod cumsum_i32_1d_default; +// mod cumsum_i32_1d_exclusive; +// mod cumsum_i32_1d_reverse; +// mod cumsum_i32_1d_reverse_exclusive; +// mod cumsum_i32_2d_axis_0; +// mod cumsum_i32_2d_axis_1; +// mod cumsum_i8_1d_default; +// mod cumsum_i8_1d_exclusive; +// mod cumsum_i8_1d_reverse; +// mod cumsum_i8_1d_reverse_exclusive; +// mod cumsum_i8_2d_axis_0; +// mod cumsum_i8_2d_axis_1; +// mod cumsum_u32_1d_default; +// mod cumsum_u32_1d_exclusive; +// mod cumsum_u32_1d_reverse; +// mod cumsum_u32_1d_reverse_exclusive; +// mod cumsum_u32_2d_axis_0; +// mod cumsum_u32_2d_axis_1; +// mod div_fp16x16; +// mod div_fp16x16_broadcast; +// mod div_fp8x23; +// mod div_fp8x23_broadcast; +// mod div_i32; +// mod div_i32_broadcast; +// mod div_i8; +// mod div_i8_broadcast; +// mod div_u32; +// mod div_u32_broadcast; +// mod equal_fp16x16; +// mod equal_fp16x16_broadcast; +// mod equal_fp8x23; +// mod equal_fp8x23_broadcast; +// mod equal_i32; +// mod equal_i32_broadcast; +// mod equal_i8; +// mod equal_i8_broadcast; +// mod equal_u32; +// mod equal_u32_broadcast; +// mod exp_fp16x16; +// mod exp_fp8x23; +// mod less_equal_fp16x16; +// mod less_equal_fp16x16_broadcast; +// mod less_equal_fp8x23; +// mod less_equal_fp8x23_broadcast; +// mod less_equal_i32; +// mod less_equal_i32_broadcast; +// mod less_equal_i8; +// mod less_equal_i8_broadcast; +// mod less_equal_u32; +// mod less_equal_u32_broadcast; +// mod greater_fp16x16; +// mod greater_fp16x16_broadcast; +// mod greater_fp8x23; +// mod greater_fp8x23_broadcast; +// mod greater_i32; +// mod greater_i32_broadcast; +// mod greater_i8; +// mod greater_i8_broadcast; +// mod greater_u32; +// mod greater_u32_broadcast; +// mod leaky_relu_fp16x16; +// mod leaky_relu_fp8x23; +// mod linear_fp16x16; +// mod linear_fp8x23; +// mod linear_i32; +// mod linear_i8; +// mod linear_u32; +// mod log_fp16x16; +// mod log_fp8x23; +// mod logsoftmax_fp16x16_axis_0; +// mod logsoftmax_fp16x16_axis_1; +// mod logsoftmax_fp8x23_axis_0; +// mod logsoftmax_fp8x23_axis_1; +// mod matmul_fp16x16_1d; +// mod matmul_fp16x16_2x2; +// mod matmul_fp16x16_2x1; +// mod matmul_fp16x16_1x2; +// mod matmul_fp8x23_1d; +// mod matmul_fp8x23_2x2; +// mod matmul_fp8x23_2x1; +// mod matmul_fp8x23_1x2; +// mod matmul_i32_1d; +// mod matmul_i32_2x2; +// mod matmul_i32_2x1; +// mod matmul_i32_1x2; +// mod matmul_i8_1d; +// mod matmul_i8_2x2; +// mod matmul_i8_2x1; +// mod matmul_i8_1x2; +// mod matmul_u32_1d; +// mod matmul_u32_2x2; +// mod matmul_u32_2x1; +// mod matmul_u32_1x2; +// mod mul_fp16x16; +// mod mul_fp16x16_broadcast; +// mod mul_fp8x23; +// mod mul_fp8x23_broadcast; +// mod mul_i32; +// mod mul_i32_broadcast; +// mod mul_i8; +// mod mul_i8_broadcast; +// mod mul_u32; +// mod mul_u32_broadcast; +// mod or_fp16x16; +// mod or_fp16x16_broadcast; +// mod or_fp8x23; +// mod or_fp8x23_broadcast; +// mod or_i32; +// mod or_i32_broadcast; +// mod or_i8; +// mod or_i8_broadcast; +// mod or_u32; +// mod or_u32_broadcast; +// mod reduce_sum_fp16x16_1D; +// mod reduce_sum_fp16x16_2D_default; +// mod reduce_sum_fp16x16_2D_keepdims; +// mod reduce_sum_fp16x16_2D_axis_1; +// mod reduce_sum_fp8x23_1D; +// mod reduce_sum_fp8x23_2D_default; +// mod reduce_sum_fp8x23_2D_keepdims; +// mod reduce_sum_fp8x23_2D_axis_1; +// mod reduce_sum_i32_1D; +// mod reduce_sum_i32_2D_default; +// mod reduce_sum_i32_2D_keepdims; +// mod reduce_sum_i32_2D_axis_1; +// mod reduce_sum_i8_1D; +// mod reduce_sum_i8_2D_default; +// mod reduce_sum_i8_2D_keepdims; +// mod reduce_sum_i8_2D_axis_1; +// mod reduce_sum_u32_1D; +// mod reduce_sum_u32_2D_default; +// mod reduce_sum_u32_2D_keepdims; +// mod reduce_sum_u32_2D_axis_1; +// mod relu_fp16x16; +// mod relu_fp8x23; +// mod relu_i32; +// mod relu_i8; +// mod sigmoid_fp16x16; +// mod sigmoid_fp8x23; +// mod sin_fp16x16; +// mod sin_fp8x23; +// mod sinh_fp16x16; +// mod sinh_fp8x23; +// mod softmax_fp16x16; +// mod softmax_fp8x23; +// mod softplus_fp8x23; +// mod softplus_fp16x16; +// mod softsign_fp8x23; +// mod softsign_fp16x16; +// mod sqrt_fp16x16; +// mod sqrt_fp8x23; +// mod sub_fp16x16; +// mod sub_fp16x16_broadcast; +// mod sub_fp8x23; +// mod sub_fp8x23_broadcast; +// mod sub_i32; +// mod sub_i32_broadcast; +// mod sub_i8; +// mod sub_i8_broadcast; +// mod sub_u32; +// mod sub_u32_broadcast; +// mod tanh_fp16x16; +// mod tanh_fp8x23; +// mod transpose_fp16x16_2d; +// mod transpose_fp16x16_3d; +// mod transpose_fp8x23_2d; +// mod transpose_fp8x23_3d; +// mod transpose_i32_2d; +// mod transpose_i32_3d; +// mod transpose_i8_2d; +// mod transpose_i8_3d; +// mod transpose_u32_2d; +// mod transpose_u32_3d; +// mod xor_fp16x16; +// mod xor_fp16x16_broadcast; +// mod xor_fp8x23; +// mod xor_fp8x23_broadcast; +// mod xor_i32; +// mod xor_i32_broadcast; +// mod xor_i8; +// mod xor_i8_broadcast; +// mod xor_u32; +// mod xor_u32_broadcast; +// mod less_fp16x16; +// mod less_fp16x16_broadcast; +// mod less_fp8x23; +// mod less_fp8x23_broadcast; +// mod less_i32; +// mod less_i32_broadcast; +// mod less_i8; +// mod less_i8_broadcast; +// mod less_u32; +// mod less_u32_broadcast; +// mod greater_equal_fp16x16; +// mod greater_equal_fp16x16_broadcast; +// mod greater_equal_fp8x23; +// mod greater_equal_fp8x23_broadcast; +// mod greater_equal_i32; +// mod greater_equal_i32_broadcast; +// mod greater_equal_i8; +// mod greater_equal_i8_broadcast; +// mod greater_equal_u32; +// mod greater_equal_u32_broadcast; +// mod slice_fp16x16_2d; +// mod slice_fp16x16_3d; +// mod slice_fp8x23_2d; +// mod slice_fp8x23_3d; +// mod slice_i32_2d; +// mod slice_i32_3d; +// mod slice_i8_2d; +// mod slice_i8_3d; +// mod slice_u32_2d; +// mod slice_u32_3d; +// mod gather_fp8x23_3d_default; +// mod gather_fp8x23_3d_axis1; +// mod gather_fp8x23_3d_axis2; +// mod gather_fp16x16_3d_default; +// mod gather_fp16x16_3d_axis1; +// mod gather_fp16x16_3d_axis2; +// mod gather_i8_3d_default; +// mod gather_i8_3d_axis1; +// mod gather_i8_3d_axis2; +// mod gather_i32_3d_default; +// mod gather_i32_3d_axis1; +// mod gather_i32_3d_axis2; +// mod gather_u32_3d_default; +// mod gather_u32_3d_axis1; +// mod gather_u32_3d_axis2; +// mod nonzero_fp16x16_2d; +// mod nonzero_fp16x16_3d; +// mod nonzero_fp8x23_2d; +// mod nonzero_fp8x23_3d; +// mod nonzero_i32_2d; +// mod nonzero_i32_3d; +// mod nonzero_i8_2d; +// mod nonzero_i8_3d; +// mod nonzero_u32_2d; +// mod nonzero_u32_3d; +// mod squeeze_fP16x16; +// mod squeeze_fP8x23; +// mod squeeze_i32; +// mod squeeze_i8; +// mod squeeze_u32; +// mod unsqueeze_fp16x16_2d; +// mod unsqueeze_fp16x16_3d; +// mod unsqueeze_fp8x23_2d; +// mod unsqueeze_fp8x23_3d; +// mod unsqueeze_i32_2d; +// mod unsqueeze_i32_3d; +// mod unsqueeze_i8_2d; +// mod unsqueeze_i8_3d; +// mod unsqueeze_u32_2d; +// mod unsqueeze_u32_3d; +// mod sign_fP16x16; +// mod sign_fP8x23; +// mod sign_fail; +// mod sign_i32; +// mod sign_i8; +// mod clip_fp16x16_2d; +// mod clip_fp16x16_3d; +// mod clip_fp8x23_2d; +// mod clip_fp8x23_3d; +// mod clip_i32_2d; +// mod clip_i32_3d; +// 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; +// mod identity_fP16x16; +// mod identity_fP8x23; +// mod identity_i32; +// mod identity_i8; +// mod identity_u32; +// mod thresholded_relu_fp16x16; +// mod thresholded_relu_fp8x23; +// mod hard_sigmoid_fp8x23; +// mod hard_sigmoid_fp16x16; +// mod neg_fp16x16; +// mod neg_fp8x23; +// mod neg_i32; +// mod neg_i8; +// mod gemm_all_attributes; +// mod gemm_alpha; +// mod gemm_beta; +// mod gemm_default_matrix_bias; +// mod gemm_default_vector_bias; +// mod gemm_default_no_bias; +// mod gemm_transposeA; +// mod gemm_transposeB; +// mod min_fp16x16_three_tensors; +// mod min_fp16x16_broadcast_three_tensors; +// mod min_fp16x16_two_tensors; +// mod min_fp16x16_broadcast_two_tensors; +// mod min_fp8x23_three_tensors; +// mod min_fp8x23_broadcast_three_tensors; +// mod min_fp8x23_two_tensors; +// mod min_fp8x23_broadcast_two_tensors; +// mod min_i32_three_tensors; +// mod min_i32_broadcast_three_tensors; +// mod min_i32_two_tensors; +// mod min_i32_broadcast_two_tensors; +// mod min_i8_three_tensors; +// mod min_i8_broadcast_three_tensors; +// mod min_i8_two_tensors; +// mod min_i8_broadcast_two_tensors; +// mod min_u32_three_tensors; +// mod min_u32_broadcast_three_tensors; +// mod min_u32_two_tensors; +// mod min_u32_broadcast_two_tensors; +// mod where_fp16x16; +// mod where_fp16x16_broadcast; +// mod where_fp8x23; +// mod where_fp8x23_broadcast; +// mod where_i32; +// mod where_i32_broadcast; +// mod where_i8; +// mod where_i8_broadcast; +// mod where_u32; +// mod where_u32_broadcast; +// mod not_bool; +// mod round_fp16x16; +// mod round_fp8x23; +// mod max_fp16x16_three_tensors; +// mod max_fp16x16_broadcast_three_tensors; +// mod max_fp16x16_two_tensors; +// mod max_fp16x16_broadcast_two_tensors; +// mod max_fp8x23_three_tensors; +// mod max_fp8x23_broadcast_three_tensors; +// mod max_fp8x23_two_tensors; +// mod max_fp8x23_broadcast_two_tensors; +// mod max_i32_three_tensors; +// mod max_i32_broadcast_three_tensors; +// mod max_i32_two_tensors; +// mod max_i32_broadcast_two_tensors; +// mod max_i8_three_tensors; +// mod max_i8_broadcast_three_tensors; +// mod max_i8_two_tensors; +// mod max_i8_broadcast_two_tensors; +// mod max_u32_three_tensors; +// mod max_u32_broadcast_three_tensors; +// mod max_u32_two_tensors; +// mod max_u32_broadcast_two_tensors; +// mod scatter_fp16x16_3d_default; +// mod scatter_fp16x16_3d_axis1; +// mod scatter_fp16x16_3d_axis1_add; +// mod scatter_fp8x23_default; +// mod scatter_fp8x23_axis1; +// mod scatter_fp8x23_mul; +// mod scatter_i8_default; +// mod scatter_i8_axis1; +// mod scatter_i8_axis1_max; +// mod scatter_u32_default; +// mod scatter_u32_axis1; +// mod scatter_u32_add; +// mod array_feature_extractor_1D_i32; +// mod array_feature_extractor_1D_fp8x23; +// mod array_feature_extractor_1D_fp16x16; +// mod array_feature_extractor_2D_i32; +// mod array_feature_extractor_2D_fp8x23; +// mod array_feature_extractor_2D_fp16x16; +// mod array_feature_extractor_3D_i32; +// mod array_feature_extractor_3D_fp8x23; +// mod array_feature_extractor_3D_fp16x16; +// mod binarizer_fp16x16; +// mod binarizer_fp8x23; +// mod tril_fp16x16; +// mod tril_fp16x16_neg; +// mod tril_fp16x16_one_row; +// mod tril_fp16x16_out_neg; +// mod tril_fp16x16_out_pos; +// mod tril_fp16x16_pos; +// mod tril_fp16x16_square; +// mod tril_fp16x16_square_neg; +// mod tril_fp16x16_zero; +// mod triu_fp16x16; +// mod triu_fp16x16_neg; +// mod triu_fp16x16_one_row; +// mod triu_fp16x16_out_neg; +// mod triu_fp16x16_out_pos; +// mod triu_fp16x16_pos; +// mod triu_fp16x16_square; +// mod triu_fp16x16_square_neg; +// mod triu_fp16x16_zero; +// mod tril_fp8x23; +// mod tril_fp8x23_neg; +// mod tril_fp8x23_one_row; +// mod tril_fp8x23_out_neg; +// mod tril_fp8x23_out_pos; +// mod tril_fp8x23_pos; +// mod tril_fp8x23_square; +// mod tril_fp8x23_square_neg; +// mod tril_fp8x23_zero; +// mod triu_fp8x23; +// mod triu_fp8x23_neg; +// mod triu_fp8x23_one_row; +// mod triu_fp8x23_out_neg; +// mod triu_fp8x23_out_pos; +// mod triu_fp8x23_pos; +// mod triu_fp8x23_square; +// mod triu_fp8x23_square_neg; +// mod triu_fp8x23_zero; +// mod tril_i32; +// mod tril_neg_i32; +// mod tril_i32_one_row; +// mod tril_i32_out_neg; +// mod tril_i32_out_pos; +// mod tril_i32_pos; +// mod tril_i32_square; +// mod tril_i32_square_neg; +// mod tril_i32_zero; +// mod triu_i32; +// mod triu_i32_neg; +// mod triu_i32_one_row; +// mod triu_i32_out_neg; +// mod triu_i32_out_pos; +// mod triu_i32_pos; +// mod triu_i32_square; +// mod triu_i32_square_neg; +// mod triu_i32_zero; +// mod tril_i8; +// mod tril_i8_neg; +// mod tril_i8_one_row; +// mod tril_i8_out_neg; +// mod tril_i8_out_pos; +// mod tril_i8_pos; +// mod tril_i8_square; +// mod tril_i8_square_neg; +// mod tril_i8_zero; +// mod triu_i8; +// mod triu_i8_neg; +// mod triu_i8_one_row; +// mod triu_i8_out_neg; +// mod triu_i8_out_pos; +// mod triu_i8_pos; +// mod triu_i8_square; +// mod triu_i8_square_neg; +// mod triu_i8_zero; +// mod tril_u32; +// mod tril_u32_neg; +// mod tril_u32_one_row; +// mod tril_u32_out_neg; +// mod tril_u32_out_pos; +// mod tril_u32_pos; +// mod tril_u32_square; +// mod tril_u32_square_neg; +// mod tril_u32_zero; +// mod triu_u32; +// mod triu_u32_neg; +// mod triu_u32_one_row; +// mod triu_u32_out_neg; +// mod triu_u32_out_pos; +// mod triu_u32_pos; +// mod triu_u32_square; +// mod triu_u32_square_neg; +// mod triu_u32_zero; +// mod reduce_sum_square_fp16x16_export_do_not_keepdims; +// mod reduce_sum_square_fp16x16_export_keepdims; +// mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +// mod reduce_sum_square_fp8x23_export_do_not_keepdims; +// mod reduce_sum_square_fp8x23_export_keepdims; +// mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +// mod reduce_sum_square_i32_export_do_not_keepdims; +// mod reduce_sum_square_i32_export_keepdims; +// mod reduce_sum_square_i32_export_negative_axes_keepdims; +// mod reduce_sum_square_i8_export_do_not_keepdims; +// mod reduce_sum_square_i8_export_keepdims; +// mod reduce_sum_square_i8_export_negative_axes_keepdims; +// mod reduce_sum_square_u32_export_do_not_keepdims; +// mod reduce_sum_square_u32_export_keepdims; +// mod reduce_sum_square_u32_export_negative_axes_keepdims; +// mod reduce_l2_fp16x16_export_do_not_keepdims; +// mod reduce_l2_fp16x16_export_keepdims; +// mod reduce_l2_fp16x16_export_negative_axes_keepdims; +// mod reduce_l2_fp8x23_export_do_not_keepdims; +// mod reduce_l2_fp8x23_export_keepdims; +// mod reduce_l2_fp8x23_export_negative_axes_keepdims; +// mod reduce_l1_fp16x16_export_do_not_keepdims; +// mod reduce_l1_fp16x16_export_keepdims; +// mod reduce_l1_fp16x16_export_negative_axes_keepdims; +// mod reduce_l1_fp8x23_export_do_not_keepdims; +// mod reduce_l1_fp8x23_export_keepdims; +// mod reduce_l1_fp8x23_export_negative_axes_keepdims; +// mod reduce_l1_i32_export_do_not_keepdims; +// mod reduce_l1_i32_export_keepdims; +// mod reduce_l1_i32_export_negative_axes_keepdims; +// mod reduce_l1_i8_export_do_not_keepdims; +// mod reduce_l1_i8_export_keepdims; +// mod reduce_l1_i8_export_negative_axes_keepdims; +// mod reduce_l1_u32_export_do_not_keepdims; +// mod reduce_l1_u32_export_keepdims; +// mod reduce_l1_u32_export_negative_axes_keepdims; +// mod reduce_prod_fp16x16_1D; +// mod reduce_prod_fp16x16_2D_default; +// mod reduce_prod_fp16x16_2D_keepdims; +// mod reduce_prod_fp16x16_2D_axis_1; +// mod reduce_prod_fp8x23_1D; +// mod reduce_prod_fp8x23_2D_default; +// mod reduce_prod_fp8x23_2D_keepdims; +// mod reduce_prod_fp8x23_2D_axis_1; +// mod reduce_prod_i32_1D; +// mod reduce_prod_i32_2D_default; +// mod reduce_prod_i32_2D_keepdims; +// mod reduce_prod_i32_2D_axis_1; +// mod reduce_prod_i8_1D; +// mod reduce_prod_i8_2D_default; +// mod reduce_prod_i8_2D_keepdims; +// mod reduce_prod_i8_2D_axis_1; +// mod reduce_prod_u32_1D; +// mod reduce_prod_u32_2D_default; +// mod reduce_prod_u32_2D_keepdims; +// mod reduce_prod_u32_2D_axis_1; +// mod gather_elements_fp16x16_3d_default; +// mod gather_elements_fp16x16_3d_axis1; +// mod gather_elements_fp16x16_3d_axis2; +// mod gather_elements_fp8x23_3d_default; +// mod gather_elements_fp8x23_3d_axis1; +// mod gather_elements_fp8x23_3d_axis2; +// mod gather_elements_i8_3d_default; +// mod gather_elements_i8_3d_axis1; +// mod gather_elements_i32_3d_default; +// mod gather_elements_i32_3d_axis1; +// mod gather_elements_i32_3d_axis2; +// mod gather_elements_u32_default; +// mod gather_elements_u32_axis1; +// mod gather_elements_u32_axis2; +// mod gather_elements_u32_axis3; +// mod sequence_length_fp16x16; +// mod sequence_length_fp16x16_broadcast; +// mod sequence_length_fp8x23; +// mod sequence_length_fp8x23_broadcast; +// mod sequence_length_i32; +// mod sequence_length_i32_broadcast; +// mod sequence_length_i8; +// mod sequence_length_i8_broadcast; +// mod sequence_length_u32; +// mod sequence_length_u32_broadcast; +// mod sequence_at_u32_positive; +// mod sequence_at_u32_negative; +// mod sequence_at_fp16x16_positive; +// mod sequence_at_fp16x16_negative; +// mod sequence_at_fp8x23_positive; +// mod sequence_at_fp8x23_negative; +// mod sequence_at_i32_positive; +// mod sequence_at_i32_negative; +// mod sequence_at_i8_positive; +// mod sequence_at_i8_negative; +// mod reduce_min_fp16x16_1D; +// mod reduce_min_fp16x16_2D_default; +// mod reduce_min_fp16x16_2D_keepdims; +// mod reduce_min_fp16x16_2D_axis_1; +// mod reduce_min_fp8x23_1D; +// mod reduce_min_fp8x23_2D_default; +// mod reduce_min_fp8x23_2D_keepdims; +// mod reduce_min_fp8x23_2D_axis_1; +// mod reduce_min_i32_1D; +// mod reduce_min_i32_2D_default; +// mod reduce_min_i32_2D_keepdims; +// mod reduce_min_i32_2D_axis_1; +// mod reduce_min_i8_1D; +// mod reduce_min_i8_2D_default; +// mod reduce_min_i8_2D_keepdims; +// mod reduce_min_i8_2D_axis_1; +// mod reduce_min_u32_1D; +// mod reduce_min_u32_2D_default; +// mod reduce_min_u32_2D_keepdims; +// mod reduce_min_u32_2D_axis_1; +// mod sequence_construct_fp16x16; +// mod sequence_construct_fp8x23; +// mod sequence_construct_i32; +// mod sequence_construct_i8; +// mod sequence_construct_u32; +// mod shrink_hard_fp16x16; +// mod shrink_soft_fp16x16; +// mod shrink_hard_fp8x23; +// mod shrink_soft_fp8x23; +// mod sequence_empty_fp16x16; +// mod sequence_empty_fp8x23; +// mod sequence_empty_i32; +// mod sequence_empty_i8; +// mod sequence_empty_u32; +// mod reduce_mean_fp16x16_1D; +// mod reduce_mean_fp16x16_2D_default; +// mod reduce_mean_fp16x16_2D_keepdims; +// mod reduce_mean_fp16x16_2D_axis_1; +// mod reduce_mean_fp8x23_1D; +// mod reduce_mean_fp8x23_2D_default; +// mod reduce_mean_fp8x23_2D_keepdims; +// mod reduce_mean_fp8x23_2D_axis_1; +// mod reduce_mean_i32_1D; +// mod reduce_mean_i32_2D_default; +// mod reduce_mean_i32_2D_keepdims; +// mod reduce_mean_i32_2D_axis_1; +// mod reduce_mean_i8_1D; +// mod reduce_mean_i8_2D_default; +// mod reduce_mean_i8_2D_keepdims; +// mod reduce_mean_i8_2D_axis_1; +// mod reduce_mean_u32_1D; +// mod reduce_mean_u32_2D_default; +// mod reduce_mean_u32_2D_keepdims; +// mod reduce_mean_u32_2D_axis_1; +// mod pow_fp16x16; +// mod pow_fp16x16_broadcast; +// mod pow_fp8x23; +// mod pow_fp8x23_broadcast; +// mod sequence_erase_u32_positive; +// mod sequence_erase_u32_negative; +// mod sequence_erase_u32_empty; +// mod sequence_erase_fp16x16_positive; +// mod sequence_erase_fp16x16_negative; +// mod sequence_erase_fp16x16_empty; +// mod sequence_erase_fp8x23_positive; +// mod sequence_erase_fp8x23_negative; +// mod sequence_erase_fp8x23_empty; +// mod sequence_erase_i32_positive; +// mod sequence_erase_i32_negative; +// mod sequence_erase_i32_empty; +// mod sequence_erase_i8_positive; +// mod sequence_erase_i8_negative; +// mod sequence_erase_i8_empty; +// mod sequence_insert_fp16x16; +// mod sequence_insert_fp8x23; +// mod sequence_insert_i32; +// mod sequence_insert_i8; +// mod sequence_insert_u32; +// mod concat_from_sequence_fp8x23_new_axis_zero; +// mod concat_from_sequence_fp8x23_new_axis_one; +// mod concat_from_sequence_fp8x23_new_axis_default; +// mod concat_from_sequence_fp16x16_new_axis_zero; +// mod concat_from_sequence_fp16x16_new_axis_one; +// mod concat_from_sequence_fp16x16_new_axis_default; +// mod concat_from_sequence_i32_new_axis_zero; +// mod concat_from_sequence_i32_new_axis_one; +// mod concat_from_sequence_i32_new_axis_default; +// mod concat_from_sequence_i8_new_axis_zero; +// mod concat_from_sequence_i8_new_axis_one; +// mod concat_from_sequence_i8_new_axis_default; +// mod concat_from_sequence_u32_new_axis_zero; +// mod concat_from_sequence_u32_new_axis_one; +// mod concat_from_sequence_u32_new_axis_default; +// mod is_nan_fp16x16; +// mod is_nan_fp8x23; +// mod is_inf_fp16x16; +// mod is_inf_fp8x23; +// mod is_inf_i32; +// mod is_inf_i8; +// mod is_inf_u32; +// mod is_pos_inf_fp16x16; +// mod is_neg_inf_fp16x16; +// mod is_pos_inf_fp8x23; +// mod is_neg_inf_fp8x23; +// mod is_pos_inf_i32; +// mod is_neg_inf_i32; +// mod is_pos_inf_i8; +// mod is_neg_inf_i8; From 0504484a484935cc900c63909c7d9511acbadf64 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 1 Dec 2023 11:30:12 +0200 Subject: [PATCH 159/160] replace tests --- nodegen/node/and.py | 146 +- tests/nodes.cairo | 1653 ++++++++--------- tests/nodes/{and_i8.cairo => and_bool.cairo} | 12 +- .../output_0.cairo => and_bool/input_0.cairo} | 14 +- .../output_0.cairo => and_bool/input_1.cairo} | 14 +- .../output_0.cairo | 12 +- ...and_i32.cairo => and_bool_broadcast.cairo} | 12 +- tests/nodes/and_fp16x16.cairo | 24 - tests/nodes/and_fp16x16/input_0.cairo | 41 - tests/nodes/and_fp16x16/input_1.cairo | 41 - tests/nodes/and_fp16x16/output_0.cairo | 40 - tests/nodes/and_fp16x16_broadcast.cairo | 24 - .../nodes/and_fp16x16_broadcast/input_0.cairo | 17 - .../nodes/and_fp16x16_broadcast/input_1.cairo | 15 - tests/nodes/and_fp8x23.cairo | 24 - tests/nodes/and_fp8x23/input_0.cairo | 41 - tests/nodes/and_fp8x23/input_1.cairo | 41 - tests/nodes/and_fp8x23/output_0.cairo | 40 - tests/nodes/and_fp8x23_broadcast.cairo | 24 - .../nodes/and_fp8x23_broadcast/input_0.cairo | 17 - .../nodes/and_fp8x23_broadcast/input_1.cairo | 15 - tests/nodes/and_i32/input_0.cairo | 41 - tests/nodes/and_i32/input_1.cairo | 41 - tests/nodes/and_i32/output_0.cairo | 40 - tests/nodes/and_i32_broadcast.cairo | 24 - tests/nodes/and_i32_broadcast/input_0.cairo | 17 - tests/nodes/and_i32_broadcast/input_1.cairo | 15 - tests/nodes/and_i8/input_0.cairo | 41 - tests/nodes/and_i8/input_1.cairo | 41 - tests/nodes/and_i8/output_0.cairo | 40 - tests/nodes/and_i8_broadcast.cairo | 24 - tests/nodes/and_i8_broadcast/input_0.cairo | 17 - tests/nodes/and_i8_broadcast/input_1.cairo | 15 - tests/nodes/and_i8_broadcast/output_0.cairo | 16 - tests/nodes/and_u32.cairo | 24 - tests/nodes/and_u32/input_0.cairo | 40 - tests/nodes/and_u32/input_1.cairo | 40 - tests/nodes/and_u32/output_0.cairo | 40 - tests/nodes/and_u32_broadcast.cairo | 24 - tests/nodes/and_u32_broadcast/input_0.cairo | 16 - tests/nodes/and_u32_broadcast/input_1.cairo | 14 - tests/nodes/and_u32_broadcast/output_0.cairo | 16 - 42 files changed, 875 insertions(+), 1978 deletions(-) rename tests/nodes/{and_i8.cairo => and_bool.cairo} (75%) rename tests/nodes/{and_fp8x23_broadcast/output_0.cairo => and_bool/input_0.cairo} (57%) rename tests/nodes/{and_i32_broadcast/output_0.cairo => and_bool/input_1.cairo} (58%) rename tests/nodes/{and_fp16x16_broadcast => and_bool}/output_0.cairo (62%) rename tests/nodes/{and_i32.cairo => and_bool_broadcast.cairo} (75%) delete mode 100644 tests/nodes/and_fp16x16.cairo delete mode 100644 tests/nodes/and_fp16x16/input_0.cairo delete mode 100644 tests/nodes/and_fp16x16/input_1.cairo delete mode 100644 tests/nodes/and_fp16x16/output_0.cairo delete mode 100644 tests/nodes/and_fp16x16_broadcast.cairo delete mode 100644 tests/nodes/and_fp16x16_broadcast/input_0.cairo delete mode 100644 tests/nodes/and_fp16x16_broadcast/input_1.cairo delete mode 100644 tests/nodes/and_fp8x23.cairo delete mode 100644 tests/nodes/and_fp8x23/input_0.cairo delete mode 100644 tests/nodes/and_fp8x23/input_1.cairo delete mode 100644 tests/nodes/and_fp8x23/output_0.cairo delete mode 100644 tests/nodes/and_fp8x23_broadcast.cairo delete mode 100644 tests/nodes/and_fp8x23_broadcast/input_0.cairo delete mode 100644 tests/nodes/and_fp8x23_broadcast/input_1.cairo delete mode 100644 tests/nodes/and_i32/input_0.cairo delete mode 100644 tests/nodes/and_i32/input_1.cairo delete mode 100644 tests/nodes/and_i32/output_0.cairo delete mode 100644 tests/nodes/and_i32_broadcast.cairo delete mode 100644 tests/nodes/and_i32_broadcast/input_0.cairo delete mode 100644 tests/nodes/and_i32_broadcast/input_1.cairo delete mode 100644 tests/nodes/and_i8/input_0.cairo delete mode 100644 tests/nodes/and_i8/input_1.cairo delete mode 100644 tests/nodes/and_i8/output_0.cairo delete mode 100644 tests/nodes/and_i8_broadcast.cairo delete mode 100644 tests/nodes/and_i8_broadcast/input_0.cairo delete mode 100644 tests/nodes/and_i8_broadcast/input_1.cairo delete mode 100644 tests/nodes/and_i8_broadcast/output_0.cairo delete mode 100644 tests/nodes/and_u32.cairo delete mode 100644 tests/nodes/and_u32/input_0.cairo delete mode 100644 tests/nodes/and_u32/input_1.cairo delete mode 100644 tests/nodes/and_u32/output_0.cairo delete mode 100644 tests/nodes/and_u32_broadcast.cairo delete mode 100644 tests/nodes/and_u32_broadcast/input_0.cairo delete mode 100644 tests/nodes/and_u32_broadcast/input_1.cairo delete mode 100644 tests/nodes/and_u32_broadcast/output_0.cairo diff --git a/nodegen/node/and.py b/nodegen/node/and.py index 6ef5ea17f..dfd28caf0 100644 --- a/nodegen/node/and.py +++ b/nodegen/node/and.py @@ -5,153 +5,29 @@ class And(RunAll): @staticmethod - def and_u32(): + def and_bool(): 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) + x = (np.random.randn(3, 4) > 0).astype(bool) + y = (np.random.randn(3, 4) > 0).astype(bool) z = np.logical_and(x, y) - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + x = Tensor(Dtype.BOOL, x.shape, x.flatten()) + y = Tensor(Dtype.BOOL, y.shape, y.flatten()) z = Tensor(Dtype.BOOL, z.shape, z.flatten()) - name = "and_u32" + name = "and_bool" 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) + x = (np.random.randn(3, 4, 5) > 0).astype(bool) + y = (np.random.randn(4, 5) > 0).astype(bool) z = np.logical_and(x, y) - x = Tensor(Dtype.U32, x.shape, x.flatten()) - y = Tensor(Dtype.U32, y.shape, y.flatten()) + x = Tensor(Dtype.BOOL, x.shape, x.flatten()) + y = Tensor(Dtype.BOOL, y.shape, y.flatten()) z = Tensor(Dtype.BOOL, z.shape, z.flatten()) - name = "and_u32_broadcast" - 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.BOOL, z.shape, z.flatten()) - - name = "and_i32" - 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.BOOL, z.shape, z.flatten()) - - name = "and_i32_broadcast" - 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.BOOL, z.shape, z.flatten()) - - name = "and_i8" - 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.BOOL, z.shape, z.flatten()) - - name = "and_i8_broadcast" - 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.BOOL, z.shape, z.flatten()) - - name = "and_fp8x23" - 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.BOOL, z.shape, z.flatten()) - - name = "and_fp8x23_broadcast" - 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.BOOL, z.shape, z.flatten()) - - name = "and_fp16x16" - 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.BOOL, z.shape, z.flatten()) - - name = "and_fp16x16_broadcast" + name = "and_bool_broadcast" make_test([x, y], z, "input_0.and(@input_1)", name) default() diff --git a/tests/nodes.cairo b/tests/nodes.cairo index 7caafcc03..12bc31c9b 100644 --- a/tests/nodes.cairo +++ b/tests/nodes.cairo @@ -1,831 +1,822 @@ -// mod abs_fp16x16; -// mod abs_fp8x23; -// mod abs_i32; -// mod abs_i8; -// mod acos_fp16x16; -// mod acos_fp8x23; -// mod acosh_fp16x16; -// mod acosh_fp8x23; -// mod add_fp16x16; -// mod add_fp16x16_broadcast; -// mod add_fp8x23; -// mod add_fp8x23_broadcast; -// mod add_i32; -// mod add_i32_broadcast; -// mod add_i8; -// mod add_i8_broadcast; -// mod add_u32; -// mod add_u32_broadcast; -// mod argmax_fp16x16_1D_default; -// mod argmax_fp16x16_1D_keepdims_false; -// mod argmax_fp16x16_1D_last_index; -// mod argmax_fp16x16_2D_default; -// mod argmax_fp16x16_2D_keepdims_false; -// mod argmax_fp16x16_2D_last_index; -// mod argmax_fp16x16_3D_default; -// mod argmax_fp16x16_3D_keepdims_false; -// mod argmax_fp16x16_3D_last_index; -// mod argmax_fp8x23_1D_default; -// mod argmax_fp8x23_1D_keepdims_false; -// mod argmax_fp8x23_1D_last_index; -// mod argmax_fp8x23_2D_default; -// mod argmax_fp8x23_2D_keepdims_false; -// mod argmax_fp8x23_2D_last_index; -// mod argmax_fp8x23_3D_default; -// mod argmax_fp8x23_3D_keepdims_false; -// mod argmax_fp8x23_3D_last_index; -// mod argmax_i32_1D_default; -// mod argmax_i32_1D_keepdims_false; -// mod argmax_i32_1D_last_index; -// mod argmax_i32_2D_default; -// mod argmax_i32_2D_keepdims_false; -// mod argmax_i32_2D_last_index; -// mod argmax_i32_3D_default; -// mod argmax_i32_3D_keepdims_false; -// mod argmax_i32_3D_last_index; -// mod argmax_i8_1D_default; -// mod argmax_i8_1D_keepdims_false; -// mod argmax_i8_1D_last_index; -// mod argmax_i8_2D_default; -// mod argmax_i8_2D_keepdims_false; -// mod argmax_i8_2D_last_index; -// mod argmax_i8_3D_default; -// mod argmax_i8_3D_keepdims_false; -// mod argmax_i8_3D_last_index; -// mod argmax_u32_1D_default; -// mod argmax_u32_1D_keepdims_false; -// mod argmax_u32_1D_last_index; -// mod argmax_u32_2D_default; -// mod argmax_u32_2D_keepdims_false; -// mod argmax_u32_2D_last_index; -// mod argmax_u32_3D_default; -// mod argmax_u32_3D_keepdims_false; -// mod argmax_u32_3D_last_index; -// mod argmin_fp16x16_1D_default; -// mod argmin_fp16x16_1D_keepdims_false; -// mod argmin_fp16x16_1D_last_index; -// mod argmin_fp16x16_2D_default; -// mod argmin_fp16x16_2D_keepdims_false; -// mod argmin_fp16x16_2D_last_index; -// mod argmin_fp16x16_3D_default; -// mod argmin_fp16x16_3D_keepdims_false; -// mod argmin_fp16x16_3D_last_index; -// mod argmin_fp8x23_1D_default; -// mod argmin_fp8x23_1D_keepdims_false; -// mod argmin_fp8x23_1D_last_index; -// mod argmin_fp8x23_2D_default; -// mod argmin_fp8x23_2D_keepdims_false; -// mod argmin_fp8x23_2D_last_index; -// mod argmin_fp8x23_3D_default; -// mod argmin_fp8x23_3D_keepdims_false; -// mod argmin_fp8x23_3D_last_index; -// mod argmin_i32_1D_default; -// mod argmin_i32_1D_keepdims_false; -// mod argmin_i32_1D_last_index; -// mod argmin_i32_2D_default; -// mod argmin_i32_2D_keepdims_false; -// mod argmin_i32_2D_last_index; -// mod argmin_i32_3D_default; -// mod argmin_i32_3D_keepdims_false; -// mod argmin_i32_3D_last_index; -// mod argmin_i8_1D_default; -// mod argmin_i8_1D_keepdims_false; -// mod argmin_i8_1D_last_index; -// mod argmin_i8_2D_default; -// mod argmin_i8_2D_keepdims_false; -// mod argmin_i8_2D_last_index; -// mod argmin_i8_3D_default; -// mod argmin_i8_3D_keepdims_false; -// mod argmin_i8_3D_last_index; -// mod argmin_u32_1D_default; -// mod argmin_u32_1D_keepdims_false; -// mod argmin_u32_1D_last_index; -// mod argmin_u32_2D_default; -// mod argmin_u32_2D_keepdims_false; -// mod argmin_u32_2D_last_index; -// mod argmin_u32_3D_default; -// mod argmin_u32_3D_keepdims_false; -// mod argmin_u32_3D_last_index; -// mod asin_fp16x16; -// mod asin_fp8x23; -// mod asinh_fp16x16; -// mod asinh_fp8x23; -// mod atan_fp16x16; -// mod atan_fp8x23; -// mod ceil_fp16x16; -// mod ceil_fp8x23; -// mod concat_fp16x16_1d; -// mod concat_fp16x16_2d; -// mod concat_fp16x16_3d_default; -// mod concat_fp16x16_3d_axis_1; -// mod concat_fp16x16_3d_axis_2; -// mod concat_fp16x16_3d_three_tensors_axis_1; -// mod concat_fp16x16_3d_three_tensors_axis_2; -// mod concat_fp8x23_1d; -// mod concat_fp8x23_2d; -// mod concat_fp8x23_3d_default; -// mod concat_fp8x23_3d_axis_1; -// mod concat_fp8x23_3d_axis_2; -// mod concat_fp8x23_3d_three_tensors_axis_1; -// mod concat_fp8x23_3d_three_tensors_axis_2; -// mod concat_i32_1d; -// mod concat_i32_2d; -// mod concat_i32_3d_default; -// mod concat_i32_3d_axis_1; -// mod concat_i32_3d_axis_2; -// mod concat_i32_3d_three_tensors_axis_1; -// mod concat_i32_3d_three_tensors_axis_2; -// mod concat_i8_1d; -// mod concat_i8_2d; -// mod concat_i8_3d_default; -// mod concat_i8_3d_axis_1; -// mod concat_i8_3d_axis_2; -// mod concat_i8_3d_three_tensors_axis_1; -// mod concat_i8_3d_three_tensors_axis_2; -// mod concat_u32_1d; -// mod concat_u32_2d; -// mod concat_u32_3d_default; -// mod concat_u32_3d_axis_1; -// mod concat_u32_3d_axis_2; -// mod concat_u32_3d_three_tensors_axis_1; -// mod concat_u32_3d_three_tensors_axis_2; -// mod cos_fp16x16; -// mod cos_fp8x23; -// mod cosh_fp16x16; -// mod cosh_fp8x23; -// mod cumsum_fp16x16_1d_default; -// mod cumsum_fp16x16_1d_exclusive; -// mod cumsum_fp16x16_1d_reverse; -// mod cumsum_fp16x16_1d_reverse_exclusive; -// mod cumsum_fp16x16_2d_axis_0; -// mod cumsum_fp16x16_2d_axis_1; -// mod cumsum_fp8x23_1d_default; -// mod cumsum_fp8x23_1d_exclusive; -// mod cumsum_fp8x23_1d_reverse; -// mod cumsum_fp8x23_1d_reverse_exclusive; -// mod cumsum_fp8x23_2d_axis_0; -// mod cumsum_fp8x23_2d_axis_1; -// mod cumsum_i32_1d_default; -// mod cumsum_i32_1d_exclusive; -// mod cumsum_i32_1d_reverse; -// mod cumsum_i32_1d_reverse_exclusive; -// mod cumsum_i32_2d_axis_0; -// mod cumsum_i32_2d_axis_1; -// mod cumsum_i8_1d_default; -// mod cumsum_i8_1d_exclusive; -// mod cumsum_i8_1d_reverse; -// mod cumsum_i8_1d_reverse_exclusive; -// mod cumsum_i8_2d_axis_0; -// mod cumsum_i8_2d_axis_1; -// mod cumsum_u32_1d_default; -// mod cumsum_u32_1d_exclusive; -// mod cumsum_u32_1d_reverse; -// mod cumsum_u32_1d_reverse_exclusive; -// mod cumsum_u32_2d_axis_0; -// mod cumsum_u32_2d_axis_1; -// mod div_fp16x16; -// mod div_fp16x16_broadcast; -// mod div_fp8x23; -// mod div_fp8x23_broadcast; -// mod div_i32; -// mod div_i32_broadcast; -// mod div_i8; -// mod div_i8_broadcast; -// mod div_u32; -// mod div_u32_broadcast; -// mod equal_fp16x16; -// mod equal_fp16x16_broadcast; -// mod equal_fp8x23; -// mod equal_fp8x23_broadcast; -// mod equal_i32; -// mod equal_i32_broadcast; -// mod equal_i8; -// mod equal_i8_broadcast; -// mod equal_u32; -// mod equal_u32_broadcast; -// mod exp_fp16x16; -// mod exp_fp8x23; -// mod less_equal_fp16x16; -// mod less_equal_fp16x16_broadcast; -// mod less_equal_fp8x23; -// mod less_equal_fp8x23_broadcast; -// mod less_equal_i32; -// mod less_equal_i32_broadcast; -// mod less_equal_i8; -// mod less_equal_i8_broadcast; -// mod less_equal_u32; -// mod less_equal_u32_broadcast; -// mod greater_fp16x16; -// mod greater_fp16x16_broadcast; -// mod greater_fp8x23; -// mod greater_fp8x23_broadcast; -// mod greater_i32; -// mod greater_i32_broadcast; -// mod greater_i8; -// mod greater_i8_broadcast; -// mod greater_u32; -// mod greater_u32_broadcast; -// mod leaky_relu_fp16x16; -// mod leaky_relu_fp8x23; -// mod linear_fp16x16; -// mod linear_fp8x23; -// mod linear_i32; -// mod linear_i8; -// mod linear_u32; -// mod log_fp16x16; -// mod log_fp8x23; -// mod logsoftmax_fp16x16_axis_0; -// mod logsoftmax_fp16x16_axis_1; -// mod logsoftmax_fp8x23_axis_0; -// mod logsoftmax_fp8x23_axis_1; -// mod matmul_fp16x16_1d; -// mod matmul_fp16x16_2x2; -// mod matmul_fp16x16_2x1; -// mod matmul_fp16x16_1x2; -// mod matmul_fp8x23_1d; -// mod matmul_fp8x23_2x2; -// mod matmul_fp8x23_2x1; -// mod matmul_fp8x23_1x2; -// mod matmul_i32_1d; -// mod matmul_i32_2x2; -// mod matmul_i32_2x1; -// mod matmul_i32_1x2; -// mod matmul_i8_1d; -// mod matmul_i8_2x2; -// mod matmul_i8_2x1; -// mod matmul_i8_1x2; -// mod matmul_u32_1d; -// mod matmul_u32_2x2; -// mod matmul_u32_2x1; -// mod matmul_u32_1x2; -// mod mul_fp16x16; -// mod mul_fp16x16_broadcast; -// mod mul_fp8x23; -// mod mul_fp8x23_broadcast; -// mod mul_i32; -// mod mul_i32_broadcast; -// mod mul_i8; -// mod mul_i8_broadcast; -// mod mul_u32; -// mod mul_u32_broadcast; -// mod or_fp16x16; -// mod or_fp16x16_broadcast; -// mod or_fp8x23; -// mod or_fp8x23_broadcast; -// mod or_i32; -// mod or_i32_broadcast; -// mod or_i8; -// mod or_i8_broadcast; -// mod or_u32; -// mod or_u32_broadcast; -// mod reduce_sum_fp16x16_1D; -// mod reduce_sum_fp16x16_2D_default; -// mod reduce_sum_fp16x16_2D_keepdims; -// mod reduce_sum_fp16x16_2D_axis_1; -// mod reduce_sum_fp8x23_1D; -// mod reduce_sum_fp8x23_2D_default; -// mod reduce_sum_fp8x23_2D_keepdims; -// mod reduce_sum_fp8x23_2D_axis_1; -// mod reduce_sum_i32_1D; -// mod reduce_sum_i32_2D_default; -// mod reduce_sum_i32_2D_keepdims; -// mod reduce_sum_i32_2D_axis_1; -// mod reduce_sum_i8_1D; -// mod reduce_sum_i8_2D_default; -// mod reduce_sum_i8_2D_keepdims; -// mod reduce_sum_i8_2D_axis_1; -// mod reduce_sum_u32_1D; -// mod reduce_sum_u32_2D_default; -// mod reduce_sum_u32_2D_keepdims; -// mod reduce_sum_u32_2D_axis_1; -// mod relu_fp16x16; -// mod relu_fp8x23; -// mod relu_i32; -// mod relu_i8; -// mod sigmoid_fp16x16; -// mod sigmoid_fp8x23; -// mod sin_fp16x16; -// mod sin_fp8x23; -// mod sinh_fp16x16; -// mod sinh_fp8x23; -// mod softmax_fp16x16; -// mod softmax_fp8x23; -// mod softplus_fp8x23; -// mod softplus_fp16x16; -// mod softsign_fp8x23; -// mod softsign_fp16x16; -// mod sqrt_fp16x16; -// mod sqrt_fp8x23; -// mod sub_fp16x16; -// mod sub_fp16x16_broadcast; -// mod sub_fp8x23; -// mod sub_fp8x23_broadcast; -// mod sub_i32; -// mod sub_i32_broadcast; -// mod sub_i8; -// mod sub_i8_broadcast; -// mod sub_u32; -// mod sub_u32_broadcast; -// mod tanh_fp16x16; -// mod tanh_fp8x23; -// mod transpose_fp16x16_2d; -// mod transpose_fp16x16_3d; -// mod transpose_fp8x23_2d; -// mod transpose_fp8x23_3d; -// mod transpose_i32_2d; -// mod transpose_i32_3d; -// mod transpose_i8_2d; -// mod transpose_i8_3d; -// mod transpose_u32_2d; -// mod transpose_u32_3d; -// mod xor_fp16x16; -// mod xor_fp16x16_broadcast; -// mod xor_fp8x23; -// mod xor_fp8x23_broadcast; -// mod xor_i32; -// mod xor_i32_broadcast; -// mod xor_i8; -// mod xor_i8_broadcast; -// mod xor_u32; -// mod xor_u32_broadcast; -// mod less_fp16x16; -// mod less_fp16x16_broadcast; -// mod less_fp8x23; -// mod less_fp8x23_broadcast; -// mod less_i32; -// mod less_i32_broadcast; -// mod less_i8; -// mod less_i8_broadcast; -// mod less_u32; -// mod less_u32_broadcast; -// mod greater_equal_fp16x16; -// mod greater_equal_fp16x16_broadcast; -// mod greater_equal_fp8x23; -// mod greater_equal_fp8x23_broadcast; -// mod greater_equal_i32; -// mod greater_equal_i32_broadcast; -// mod greater_equal_i8; -// mod greater_equal_i8_broadcast; -// mod greater_equal_u32; -// mod greater_equal_u32_broadcast; -// mod slice_fp16x16_2d; -// mod slice_fp16x16_3d; -// mod slice_fp8x23_2d; -// mod slice_fp8x23_3d; -// mod slice_i32_2d; -// mod slice_i32_3d; -// mod slice_i8_2d; -// mod slice_i8_3d; -// mod slice_u32_2d; -// mod slice_u32_3d; -// mod gather_fp8x23_3d_default; -// mod gather_fp8x23_3d_axis1; -// mod gather_fp8x23_3d_axis2; -// mod gather_fp16x16_3d_default; -// mod gather_fp16x16_3d_axis1; -// mod gather_fp16x16_3d_axis2; -// mod gather_i8_3d_default; -// mod gather_i8_3d_axis1; -// mod gather_i8_3d_axis2; -// mod gather_i32_3d_default; -// mod gather_i32_3d_axis1; -// mod gather_i32_3d_axis2; -// mod gather_u32_3d_default; -// mod gather_u32_3d_axis1; -// mod gather_u32_3d_axis2; -// mod nonzero_fp16x16_2d; -// mod nonzero_fp16x16_3d; -// mod nonzero_fp8x23_2d; -// mod nonzero_fp8x23_3d; -// mod nonzero_i32_2d; -// mod nonzero_i32_3d; -// mod nonzero_i8_2d; -// mod nonzero_i8_3d; -// mod nonzero_u32_2d; -// mod nonzero_u32_3d; -// mod squeeze_fP16x16; -// mod squeeze_fP8x23; -// mod squeeze_i32; -// mod squeeze_i8; -// mod squeeze_u32; -// mod unsqueeze_fp16x16_2d; -// mod unsqueeze_fp16x16_3d; -// mod unsqueeze_fp8x23_2d; -// mod unsqueeze_fp8x23_3d; -// mod unsqueeze_i32_2d; -// mod unsqueeze_i32_3d; -// mod unsqueeze_i8_2d; -// mod unsqueeze_i8_3d; -// mod unsqueeze_u32_2d; -// mod unsqueeze_u32_3d; -// mod sign_fP16x16; -// mod sign_fP8x23; -// mod sign_fail; -// mod sign_i32; -// mod sign_i8; -// mod clip_fp16x16_2d; -// mod clip_fp16x16_3d; -// mod clip_fp8x23_2d; -// mod clip_fp8x23_3d; -// mod clip_i32_2d; -// mod clip_i32_3d; -// 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; -// mod identity_fP16x16; -// mod identity_fP8x23; -// mod identity_i32; -// mod identity_i8; -// mod identity_u32; -// mod thresholded_relu_fp16x16; -// mod thresholded_relu_fp8x23; -// mod hard_sigmoid_fp8x23; -// mod hard_sigmoid_fp16x16; -// mod neg_fp16x16; -// mod neg_fp8x23; -// mod neg_i32; -// mod neg_i8; -// mod gemm_all_attributes; -// mod gemm_alpha; -// mod gemm_beta; -// mod gemm_default_matrix_bias; -// mod gemm_default_vector_bias; -// mod gemm_default_no_bias; -// mod gemm_transposeA; -// mod gemm_transposeB; -// mod min_fp16x16_three_tensors; -// mod min_fp16x16_broadcast_three_tensors; -// mod min_fp16x16_two_tensors; -// mod min_fp16x16_broadcast_two_tensors; -// mod min_fp8x23_three_tensors; -// mod min_fp8x23_broadcast_three_tensors; -// mod min_fp8x23_two_tensors; -// mod min_fp8x23_broadcast_two_tensors; -// mod min_i32_three_tensors; -// mod min_i32_broadcast_three_tensors; -// mod min_i32_two_tensors; -// mod min_i32_broadcast_two_tensors; -// mod min_i8_three_tensors; -// mod min_i8_broadcast_three_tensors; -// mod min_i8_two_tensors; -// mod min_i8_broadcast_two_tensors; -// mod min_u32_three_tensors; -// mod min_u32_broadcast_three_tensors; -// mod min_u32_two_tensors; -// mod min_u32_broadcast_two_tensors; -// mod where_fp16x16; -// mod where_fp16x16_broadcast; -// mod where_fp8x23; -// mod where_fp8x23_broadcast; -// mod where_i32; -// mod where_i32_broadcast; -// mod where_i8; -// mod where_i8_broadcast; -// mod where_u32; -// mod where_u32_broadcast; -// mod not_bool; -// mod round_fp16x16; -// mod round_fp8x23; -// mod max_fp16x16_three_tensors; -// mod max_fp16x16_broadcast_three_tensors; -// mod max_fp16x16_two_tensors; -// mod max_fp16x16_broadcast_two_tensors; -// mod max_fp8x23_three_tensors; -// mod max_fp8x23_broadcast_three_tensors; -// mod max_fp8x23_two_tensors; -// mod max_fp8x23_broadcast_two_tensors; -// mod max_i32_three_tensors; -// mod max_i32_broadcast_three_tensors; -// mod max_i32_two_tensors; -// mod max_i32_broadcast_two_tensors; -// mod max_i8_three_tensors; -// mod max_i8_broadcast_three_tensors; -// mod max_i8_two_tensors; -// mod max_i8_broadcast_two_tensors; -// mod max_u32_three_tensors; -// mod max_u32_broadcast_three_tensors; -// mod max_u32_two_tensors; -// mod max_u32_broadcast_two_tensors; -// mod scatter_fp16x16_3d_default; -// mod scatter_fp16x16_3d_axis1; -// mod scatter_fp16x16_3d_axis1_add; -// mod scatter_fp8x23_default; -// mod scatter_fp8x23_axis1; -// mod scatter_fp8x23_mul; -// mod scatter_i8_default; -// mod scatter_i8_axis1; -// mod scatter_i8_axis1_max; -// mod scatter_u32_default; -// mod scatter_u32_axis1; -// mod scatter_u32_add; -// mod array_feature_extractor_1D_i32; -// mod array_feature_extractor_1D_fp8x23; -// mod array_feature_extractor_1D_fp16x16; -// mod array_feature_extractor_2D_i32; -// mod array_feature_extractor_2D_fp8x23; -// mod array_feature_extractor_2D_fp16x16; -// mod array_feature_extractor_3D_i32; -// mod array_feature_extractor_3D_fp8x23; -// mod array_feature_extractor_3D_fp16x16; -// mod binarizer_fp16x16; -// mod binarizer_fp8x23; -// mod tril_fp16x16; -// mod tril_fp16x16_neg; -// mod tril_fp16x16_one_row; -// mod tril_fp16x16_out_neg; -// mod tril_fp16x16_out_pos; -// mod tril_fp16x16_pos; -// mod tril_fp16x16_square; -// mod tril_fp16x16_square_neg; -// mod tril_fp16x16_zero; -// mod triu_fp16x16; -// mod triu_fp16x16_neg; -// mod triu_fp16x16_one_row; -// mod triu_fp16x16_out_neg; -// mod triu_fp16x16_out_pos; -// mod triu_fp16x16_pos; -// mod triu_fp16x16_square; -// mod triu_fp16x16_square_neg; -// mod triu_fp16x16_zero; -// mod tril_fp8x23; -// mod tril_fp8x23_neg; -// mod tril_fp8x23_one_row; -// mod tril_fp8x23_out_neg; -// mod tril_fp8x23_out_pos; -// mod tril_fp8x23_pos; -// mod tril_fp8x23_square; -// mod tril_fp8x23_square_neg; -// mod tril_fp8x23_zero; -// mod triu_fp8x23; -// mod triu_fp8x23_neg; -// mod triu_fp8x23_one_row; -// mod triu_fp8x23_out_neg; -// mod triu_fp8x23_out_pos; -// mod triu_fp8x23_pos; -// mod triu_fp8x23_square; -// mod triu_fp8x23_square_neg; -// mod triu_fp8x23_zero; -// mod tril_i32; -// mod tril_neg_i32; -// mod tril_i32_one_row; -// mod tril_i32_out_neg; -// mod tril_i32_out_pos; -// mod tril_i32_pos; -// mod tril_i32_square; -// mod tril_i32_square_neg; -// mod tril_i32_zero; -// mod triu_i32; -// mod triu_i32_neg; -// mod triu_i32_one_row; -// mod triu_i32_out_neg; -// mod triu_i32_out_pos; -// mod triu_i32_pos; -// mod triu_i32_square; -// mod triu_i32_square_neg; -// mod triu_i32_zero; -// mod tril_i8; -// mod tril_i8_neg; -// mod tril_i8_one_row; -// mod tril_i8_out_neg; -// mod tril_i8_out_pos; -// mod tril_i8_pos; -// mod tril_i8_square; -// mod tril_i8_square_neg; -// mod tril_i8_zero; -// mod triu_i8; -// mod triu_i8_neg; -// mod triu_i8_one_row; -// mod triu_i8_out_neg; -// mod triu_i8_out_pos; -// mod triu_i8_pos; -// mod triu_i8_square; -// mod triu_i8_square_neg; -// mod triu_i8_zero; -// mod tril_u32; -// mod tril_u32_neg; -// mod tril_u32_one_row; -// mod tril_u32_out_neg; -// mod tril_u32_out_pos; -// mod tril_u32_pos; -// mod tril_u32_square; -// mod tril_u32_square_neg; -// mod tril_u32_zero; -// mod triu_u32; -// mod triu_u32_neg; -// mod triu_u32_one_row; -// mod triu_u32_out_neg; -// mod triu_u32_out_pos; -// mod triu_u32_pos; -// mod triu_u32_square; -// mod triu_u32_square_neg; -// mod triu_u32_zero; -// mod reduce_sum_square_fp16x16_export_do_not_keepdims; -// mod reduce_sum_square_fp16x16_export_keepdims; -// mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; -// mod reduce_sum_square_fp8x23_export_do_not_keepdims; -// mod reduce_sum_square_fp8x23_export_keepdims; -// mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; -// mod reduce_sum_square_i32_export_do_not_keepdims; -// mod reduce_sum_square_i32_export_keepdims; -// mod reduce_sum_square_i32_export_negative_axes_keepdims; -// mod reduce_sum_square_i8_export_do_not_keepdims; -// mod reduce_sum_square_i8_export_keepdims; -// mod reduce_sum_square_i8_export_negative_axes_keepdims; -// mod reduce_sum_square_u32_export_do_not_keepdims; -// mod reduce_sum_square_u32_export_keepdims; -// mod reduce_sum_square_u32_export_negative_axes_keepdims; -// mod reduce_l2_fp16x16_export_do_not_keepdims; -// mod reduce_l2_fp16x16_export_keepdims; -// mod reduce_l2_fp16x16_export_negative_axes_keepdims; -// mod reduce_l2_fp8x23_export_do_not_keepdims; -// mod reduce_l2_fp8x23_export_keepdims; -// mod reduce_l2_fp8x23_export_negative_axes_keepdims; -// mod reduce_l1_fp16x16_export_do_not_keepdims; -// mod reduce_l1_fp16x16_export_keepdims; -// mod reduce_l1_fp16x16_export_negative_axes_keepdims; -// mod reduce_l1_fp8x23_export_do_not_keepdims; -// mod reduce_l1_fp8x23_export_keepdims; -// mod reduce_l1_fp8x23_export_negative_axes_keepdims; -// mod reduce_l1_i32_export_do_not_keepdims; -// mod reduce_l1_i32_export_keepdims; -// mod reduce_l1_i32_export_negative_axes_keepdims; -// mod reduce_l1_i8_export_do_not_keepdims; -// mod reduce_l1_i8_export_keepdims; -// mod reduce_l1_i8_export_negative_axes_keepdims; -// mod reduce_l1_u32_export_do_not_keepdims; -// mod reduce_l1_u32_export_keepdims; -// mod reduce_l1_u32_export_negative_axes_keepdims; -// mod reduce_prod_fp16x16_1D; -// mod reduce_prod_fp16x16_2D_default; -// mod reduce_prod_fp16x16_2D_keepdims; -// mod reduce_prod_fp16x16_2D_axis_1; -// mod reduce_prod_fp8x23_1D; -// mod reduce_prod_fp8x23_2D_default; -// mod reduce_prod_fp8x23_2D_keepdims; -// mod reduce_prod_fp8x23_2D_axis_1; -// mod reduce_prod_i32_1D; -// mod reduce_prod_i32_2D_default; -// mod reduce_prod_i32_2D_keepdims; -// mod reduce_prod_i32_2D_axis_1; -// mod reduce_prod_i8_1D; -// mod reduce_prod_i8_2D_default; -// mod reduce_prod_i8_2D_keepdims; -// mod reduce_prod_i8_2D_axis_1; -// mod reduce_prod_u32_1D; -// mod reduce_prod_u32_2D_default; -// mod reduce_prod_u32_2D_keepdims; -// mod reduce_prod_u32_2D_axis_1; -// mod gather_elements_fp16x16_3d_default; -// mod gather_elements_fp16x16_3d_axis1; -// mod gather_elements_fp16x16_3d_axis2; -// mod gather_elements_fp8x23_3d_default; -// mod gather_elements_fp8x23_3d_axis1; -// mod gather_elements_fp8x23_3d_axis2; -// mod gather_elements_i8_3d_default; -// mod gather_elements_i8_3d_axis1; -// mod gather_elements_i32_3d_default; -// mod gather_elements_i32_3d_axis1; -// mod gather_elements_i32_3d_axis2; -// mod gather_elements_u32_default; -// mod gather_elements_u32_axis1; -// mod gather_elements_u32_axis2; -// mod gather_elements_u32_axis3; -// mod sequence_length_fp16x16; -// mod sequence_length_fp16x16_broadcast; -// mod sequence_length_fp8x23; -// mod sequence_length_fp8x23_broadcast; -// mod sequence_length_i32; -// mod sequence_length_i32_broadcast; -// mod sequence_length_i8; -// mod sequence_length_i8_broadcast; -// mod sequence_length_u32; -// mod sequence_length_u32_broadcast; -// mod sequence_at_u32_positive; -// mod sequence_at_u32_negative; -// mod sequence_at_fp16x16_positive; -// mod sequence_at_fp16x16_negative; -// mod sequence_at_fp8x23_positive; -// mod sequence_at_fp8x23_negative; -// mod sequence_at_i32_positive; -// mod sequence_at_i32_negative; -// mod sequence_at_i8_positive; -// mod sequence_at_i8_negative; -// mod reduce_min_fp16x16_1D; -// mod reduce_min_fp16x16_2D_default; -// mod reduce_min_fp16x16_2D_keepdims; -// mod reduce_min_fp16x16_2D_axis_1; -// mod reduce_min_fp8x23_1D; -// mod reduce_min_fp8x23_2D_default; -// mod reduce_min_fp8x23_2D_keepdims; -// mod reduce_min_fp8x23_2D_axis_1; -// mod reduce_min_i32_1D; -// mod reduce_min_i32_2D_default; -// mod reduce_min_i32_2D_keepdims; -// mod reduce_min_i32_2D_axis_1; -// mod reduce_min_i8_1D; -// mod reduce_min_i8_2D_default; -// mod reduce_min_i8_2D_keepdims; -// mod reduce_min_i8_2D_axis_1; -// mod reduce_min_u32_1D; -// mod reduce_min_u32_2D_default; -// mod reduce_min_u32_2D_keepdims; -// mod reduce_min_u32_2D_axis_1; -// mod sequence_construct_fp16x16; -// mod sequence_construct_fp8x23; -// mod sequence_construct_i32; -// mod sequence_construct_i8; -// mod sequence_construct_u32; -// mod shrink_hard_fp16x16; -// mod shrink_soft_fp16x16; -// mod shrink_hard_fp8x23; -// mod shrink_soft_fp8x23; -// mod sequence_empty_fp16x16; -// mod sequence_empty_fp8x23; -// mod sequence_empty_i32; -// mod sequence_empty_i8; -// mod sequence_empty_u32; -// mod reduce_mean_fp16x16_1D; -// mod reduce_mean_fp16x16_2D_default; -// mod reduce_mean_fp16x16_2D_keepdims; -// mod reduce_mean_fp16x16_2D_axis_1; -// mod reduce_mean_fp8x23_1D; -// mod reduce_mean_fp8x23_2D_default; -// mod reduce_mean_fp8x23_2D_keepdims; -// mod reduce_mean_fp8x23_2D_axis_1; -// mod reduce_mean_i32_1D; -// mod reduce_mean_i32_2D_default; -// mod reduce_mean_i32_2D_keepdims; -// mod reduce_mean_i32_2D_axis_1; -// mod reduce_mean_i8_1D; -// mod reduce_mean_i8_2D_default; -// mod reduce_mean_i8_2D_keepdims; -// mod reduce_mean_i8_2D_axis_1; -// mod reduce_mean_u32_1D; -// mod reduce_mean_u32_2D_default; -// mod reduce_mean_u32_2D_keepdims; -// mod reduce_mean_u32_2D_axis_1; -// mod pow_fp16x16; -// mod pow_fp16x16_broadcast; -// mod pow_fp8x23; -// mod pow_fp8x23_broadcast; -// mod sequence_erase_u32_positive; -// mod sequence_erase_u32_negative; -// mod sequence_erase_u32_empty; -// mod sequence_erase_fp16x16_positive; -// mod sequence_erase_fp16x16_negative; -// mod sequence_erase_fp16x16_empty; -// mod sequence_erase_fp8x23_positive; -// mod sequence_erase_fp8x23_negative; -// mod sequence_erase_fp8x23_empty; -// mod sequence_erase_i32_positive; -// mod sequence_erase_i32_negative; -// mod sequence_erase_i32_empty; -// mod sequence_erase_i8_positive; -// mod sequence_erase_i8_negative; -// mod sequence_erase_i8_empty; -// mod sequence_insert_fp16x16; -// mod sequence_insert_fp8x23; -// mod sequence_insert_i32; -// mod sequence_insert_i8; -// mod sequence_insert_u32; -// mod concat_from_sequence_fp8x23_new_axis_zero; -// mod concat_from_sequence_fp8x23_new_axis_one; -// mod concat_from_sequence_fp8x23_new_axis_default; -// mod concat_from_sequence_fp16x16_new_axis_zero; -// mod concat_from_sequence_fp16x16_new_axis_one; -// mod concat_from_sequence_fp16x16_new_axis_default; -// mod concat_from_sequence_i32_new_axis_zero; -// mod concat_from_sequence_i32_new_axis_one; -// mod concat_from_sequence_i32_new_axis_default; -// mod concat_from_sequence_i8_new_axis_zero; -// mod concat_from_sequence_i8_new_axis_one; -// mod concat_from_sequence_i8_new_axis_default; -// mod concat_from_sequence_u32_new_axis_zero; -// mod concat_from_sequence_u32_new_axis_one; -// mod concat_from_sequence_u32_new_axis_default; -// mod is_nan_fp16x16; -// mod is_nan_fp8x23; -// mod is_inf_fp16x16; -// mod is_inf_fp8x23; -// mod is_inf_i32; -// mod is_inf_i8; -// mod is_inf_u32; -// mod is_pos_inf_fp16x16; -// mod is_neg_inf_fp16x16; -// mod is_pos_inf_fp8x23; -// mod is_neg_inf_fp8x23; -// mod is_pos_inf_i32; -// mod is_neg_inf_i32; -// mod is_pos_inf_i8; -// mod is_neg_inf_i8; +mod abs_fp16x16; +mod abs_fp8x23; +mod abs_i32; +mod abs_i8; +mod acos_fp16x16; +mod acos_fp8x23; +mod acosh_fp16x16; +mod acosh_fp8x23; +mod add_fp16x16; +mod add_fp16x16_broadcast; +mod add_fp8x23; +mod add_fp8x23_broadcast; +mod add_i32; +mod add_i32_broadcast; +mod add_i8; +mod add_i8_broadcast; +mod add_u32; +mod add_u32_broadcast; +mod argmax_fp16x16_1D_default; +mod argmax_fp16x16_1D_keepdims_false; +mod argmax_fp16x16_1D_last_index; +mod argmax_fp16x16_2D_default; +mod argmax_fp16x16_2D_keepdims_false; +mod argmax_fp16x16_2D_last_index; +mod argmax_fp16x16_3D_default; +mod argmax_fp16x16_3D_keepdims_false; +mod argmax_fp16x16_3D_last_index; +mod argmax_fp8x23_1D_default; +mod argmax_fp8x23_1D_keepdims_false; +mod argmax_fp8x23_1D_last_index; +mod argmax_fp8x23_2D_default; +mod argmax_fp8x23_2D_keepdims_false; +mod argmax_fp8x23_2D_last_index; +mod argmax_fp8x23_3D_default; +mod argmax_fp8x23_3D_keepdims_false; +mod argmax_fp8x23_3D_last_index; +mod argmax_i32_1D_default; +mod argmax_i32_1D_keepdims_false; +mod argmax_i32_1D_last_index; +mod argmax_i32_2D_default; +mod argmax_i32_2D_keepdims_false; +mod argmax_i32_2D_last_index; +mod argmax_i32_3D_default; +mod argmax_i32_3D_keepdims_false; +mod argmax_i32_3D_last_index; +mod argmax_i8_1D_default; +mod argmax_i8_1D_keepdims_false; +mod argmax_i8_1D_last_index; +mod argmax_i8_2D_default; +mod argmax_i8_2D_keepdims_false; +mod argmax_i8_2D_last_index; +mod argmax_i8_3D_default; +mod argmax_i8_3D_keepdims_false; +mod argmax_i8_3D_last_index; +mod argmax_u32_1D_default; +mod argmax_u32_1D_keepdims_false; +mod argmax_u32_1D_last_index; +mod argmax_u32_2D_default; +mod argmax_u32_2D_keepdims_false; +mod argmax_u32_2D_last_index; +mod argmax_u32_3D_default; +mod argmax_u32_3D_keepdims_false; +mod argmax_u32_3D_last_index; +mod argmin_fp16x16_1D_default; +mod argmin_fp16x16_1D_keepdims_false; +mod argmin_fp16x16_1D_last_index; +mod argmin_fp16x16_2D_default; +mod argmin_fp16x16_2D_keepdims_false; +mod argmin_fp16x16_2D_last_index; +mod argmin_fp16x16_3D_default; +mod argmin_fp16x16_3D_keepdims_false; +mod argmin_fp16x16_3D_last_index; +mod argmin_fp8x23_1D_default; +mod argmin_fp8x23_1D_keepdims_false; +mod argmin_fp8x23_1D_last_index; +mod argmin_fp8x23_2D_default; +mod argmin_fp8x23_2D_keepdims_false; +mod argmin_fp8x23_2D_last_index; +mod argmin_fp8x23_3D_default; +mod argmin_fp8x23_3D_keepdims_false; +mod argmin_fp8x23_3D_last_index; +mod argmin_i32_1D_default; +mod argmin_i32_1D_keepdims_false; +mod argmin_i32_1D_last_index; +mod argmin_i32_2D_default; +mod argmin_i32_2D_keepdims_false; +mod argmin_i32_2D_last_index; +mod argmin_i32_3D_default; +mod argmin_i32_3D_keepdims_false; +mod argmin_i32_3D_last_index; +mod argmin_i8_1D_default; +mod argmin_i8_1D_keepdims_false; +mod argmin_i8_1D_last_index; +mod argmin_i8_2D_default; +mod argmin_i8_2D_keepdims_false; +mod argmin_i8_2D_last_index; +mod argmin_i8_3D_default; +mod argmin_i8_3D_keepdims_false; +mod argmin_i8_3D_last_index; +mod argmin_u32_1D_default; +mod argmin_u32_1D_keepdims_false; +mod argmin_u32_1D_last_index; +mod argmin_u32_2D_default; +mod argmin_u32_2D_keepdims_false; +mod argmin_u32_2D_last_index; +mod argmin_u32_3D_default; +mod argmin_u32_3D_keepdims_false; +mod argmin_u32_3D_last_index; +mod asin_fp16x16; +mod asin_fp8x23; +mod asinh_fp16x16; +mod asinh_fp8x23; +mod atan_fp16x16; +mod atan_fp8x23; +mod ceil_fp16x16; +mod ceil_fp8x23; +mod concat_fp16x16_1d; +mod concat_fp16x16_2d; +mod concat_fp16x16_3d_default; +mod concat_fp16x16_3d_axis_1; +mod concat_fp16x16_3d_axis_2; +mod concat_fp16x16_3d_three_tensors_axis_1; +mod concat_fp16x16_3d_three_tensors_axis_2; +mod concat_fp8x23_1d; +mod concat_fp8x23_2d; +mod concat_fp8x23_3d_default; +mod concat_fp8x23_3d_axis_1; +mod concat_fp8x23_3d_axis_2; +mod concat_fp8x23_3d_three_tensors_axis_1; +mod concat_fp8x23_3d_three_tensors_axis_2; +mod concat_i32_1d; +mod concat_i32_2d; +mod concat_i32_3d_default; +mod concat_i32_3d_axis_1; +mod concat_i32_3d_axis_2; +mod concat_i32_3d_three_tensors_axis_1; +mod concat_i32_3d_three_tensors_axis_2; +mod concat_i8_1d; +mod concat_i8_2d; +mod concat_i8_3d_default; +mod concat_i8_3d_axis_1; +mod concat_i8_3d_axis_2; +mod concat_i8_3d_three_tensors_axis_1; +mod concat_i8_3d_three_tensors_axis_2; +mod concat_u32_1d; +mod concat_u32_2d; +mod concat_u32_3d_default; +mod concat_u32_3d_axis_1; +mod concat_u32_3d_axis_2; +mod concat_u32_3d_three_tensors_axis_1; +mod concat_u32_3d_three_tensors_axis_2; +mod cos_fp16x16; +mod cos_fp8x23; +mod cosh_fp16x16; +mod cosh_fp8x23; +mod cumsum_fp16x16_1d_default; +mod cumsum_fp16x16_1d_exclusive; +mod cumsum_fp16x16_1d_reverse; +mod cumsum_fp16x16_1d_reverse_exclusive; +mod cumsum_fp16x16_2d_axis_0; +mod cumsum_fp16x16_2d_axis_1; +mod cumsum_fp8x23_1d_default; +mod cumsum_fp8x23_1d_exclusive; +mod cumsum_fp8x23_1d_reverse; +mod cumsum_fp8x23_1d_reverse_exclusive; +mod cumsum_fp8x23_2d_axis_0; +mod cumsum_fp8x23_2d_axis_1; +mod cumsum_i32_1d_default; +mod cumsum_i32_1d_exclusive; +mod cumsum_i32_1d_reverse; +mod cumsum_i32_1d_reverse_exclusive; +mod cumsum_i32_2d_axis_0; +mod cumsum_i32_2d_axis_1; +mod cumsum_i8_1d_default; +mod cumsum_i8_1d_exclusive; +mod cumsum_i8_1d_reverse; +mod cumsum_i8_1d_reverse_exclusive; +mod cumsum_i8_2d_axis_0; +mod cumsum_i8_2d_axis_1; +mod cumsum_u32_1d_default; +mod cumsum_u32_1d_exclusive; +mod cumsum_u32_1d_reverse; +mod cumsum_u32_1d_reverse_exclusive; +mod cumsum_u32_2d_axis_0; +mod cumsum_u32_2d_axis_1; +mod div_fp16x16; +mod div_fp16x16_broadcast; +mod div_fp8x23; +mod div_fp8x23_broadcast; +mod div_i32; +mod div_i32_broadcast; +mod div_i8; +mod div_i8_broadcast; +mod div_u32; +mod div_u32_broadcast; +mod equal_fp16x16; +mod equal_fp16x16_broadcast; +mod equal_fp8x23; +mod equal_fp8x23_broadcast; +mod equal_i32; +mod equal_i32_broadcast; +mod equal_i8; +mod equal_i8_broadcast; +mod equal_u32; +mod equal_u32_broadcast; +mod exp_fp16x16; +mod exp_fp8x23; +mod less_equal_fp16x16; +mod less_equal_fp16x16_broadcast; +mod less_equal_fp8x23; +mod less_equal_fp8x23_broadcast; +mod less_equal_i32; +mod less_equal_i32_broadcast; +mod less_equal_i8; +mod less_equal_i8_broadcast; +mod less_equal_u32; +mod less_equal_u32_broadcast; +mod greater_fp16x16; +mod greater_fp16x16_broadcast; +mod greater_fp8x23; +mod greater_fp8x23_broadcast; +mod greater_i32; +mod greater_i32_broadcast; +mod greater_i8; +mod greater_i8_broadcast; +mod greater_u32; +mod greater_u32_broadcast; +mod leaky_relu_fp16x16; +mod leaky_relu_fp8x23; +mod linear_fp16x16; +mod linear_fp8x23; +mod linear_i32; +mod linear_i8; +mod linear_u32; +mod log_fp16x16; +mod log_fp8x23; +mod logsoftmax_fp16x16_axis_0; +mod logsoftmax_fp16x16_axis_1; +mod logsoftmax_fp8x23_axis_0; +mod logsoftmax_fp8x23_axis_1; +mod matmul_fp16x16_1d; +mod matmul_fp16x16_2x2; +mod matmul_fp16x16_2x1; +mod matmul_fp16x16_1x2; +mod matmul_fp8x23_1d; +mod matmul_fp8x23_2x2; +mod matmul_fp8x23_2x1; +mod matmul_fp8x23_1x2; +mod matmul_i32_1d; +mod matmul_i32_2x2; +mod matmul_i32_2x1; +mod matmul_i32_1x2; +mod matmul_i8_1d; +mod matmul_i8_2x2; +mod matmul_i8_2x1; +mod matmul_i8_1x2; +mod matmul_u32_1d; +mod matmul_u32_2x2; +mod matmul_u32_2x1; +mod matmul_u32_1x2; +mod mul_fp16x16; +mod mul_fp16x16_broadcast; +mod mul_fp8x23; +mod mul_fp8x23_broadcast; +mod mul_i32; +mod mul_i32_broadcast; +mod mul_i8; +mod mul_i8_broadcast; +mod mul_u32; +mod mul_u32_broadcast; +mod or_fp16x16; +mod or_fp16x16_broadcast; +mod or_fp8x23; +mod or_fp8x23_broadcast; +mod or_i32; +mod or_i32_broadcast; +mod or_i8; +mod or_i8_broadcast; +mod or_u32; +mod or_u32_broadcast; +mod reduce_sum_fp16x16_1D; +mod reduce_sum_fp16x16_2D_default; +mod reduce_sum_fp16x16_2D_keepdims; +mod reduce_sum_fp16x16_2D_axis_1; +mod reduce_sum_fp8x23_1D; +mod reduce_sum_fp8x23_2D_default; +mod reduce_sum_fp8x23_2D_keepdims; +mod reduce_sum_fp8x23_2D_axis_1; +mod reduce_sum_i32_1D; +mod reduce_sum_i32_2D_default; +mod reduce_sum_i32_2D_keepdims; +mod reduce_sum_i32_2D_axis_1; +mod reduce_sum_i8_1D; +mod reduce_sum_i8_2D_default; +mod reduce_sum_i8_2D_keepdims; +mod reduce_sum_i8_2D_axis_1; +mod reduce_sum_u32_1D; +mod reduce_sum_u32_2D_default; +mod reduce_sum_u32_2D_keepdims; +mod reduce_sum_u32_2D_axis_1; +mod relu_fp16x16; +mod relu_fp8x23; +mod relu_i32; +mod relu_i8; +mod sigmoid_fp16x16; +mod sigmoid_fp8x23; +mod sin_fp16x16; +mod sin_fp8x23; +mod sinh_fp16x16; +mod sinh_fp8x23; +mod softmax_fp16x16; +mod softmax_fp8x23; +mod softplus_fp8x23; +mod softplus_fp16x16; +mod softsign_fp8x23; +mod softsign_fp16x16; +mod sqrt_fp16x16; +mod sqrt_fp8x23; +mod sub_fp16x16; +mod sub_fp16x16_broadcast; +mod sub_fp8x23; +mod sub_fp8x23_broadcast; +mod sub_i32; +mod sub_i32_broadcast; +mod sub_i8; +mod sub_i8_broadcast; +mod sub_u32; +mod sub_u32_broadcast; +mod tanh_fp16x16; +mod tanh_fp8x23; +mod transpose_fp16x16_2d; +mod transpose_fp16x16_3d; +mod transpose_fp8x23_2d; +mod transpose_fp8x23_3d; +mod transpose_i32_2d; +mod transpose_i32_3d; +mod transpose_i8_2d; +mod transpose_i8_3d; +mod transpose_u32_2d; +mod transpose_u32_3d; +mod xor_fp16x16; +mod xor_fp16x16_broadcast; +mod xor_fp8x23; +mod xor_fp8x23_broadcast; +mod xor_i32; +mod xor_i32_broadcast; +mod xor_i8; +mod xor_i8_broadcast; +mod xor_u32; +mod xor_u32_broadcast; +mod less_fp16x16; +mod less_fp16x16_broadcast; +mod less_fp8x23; +mod less_fp8x23_broadcast; +mod less_i32; +mod less_i32_broadcast; +mod less_i8; +mod less_i8_broadcast; +mod less_u32; +mod less_u32_broadcast; +mod greater_equal_fp16x16; +mod greater_equal_fp16x16_broadcast; +mod greater_equal_fp8x23; +mod greater_equal_fp8x23_broadcast; +mod greater_equal_i32; +mod greater_equal_i32_broadcast; +mod greater_equal_i8; +mod greater_equal_i8_broadcast; +mod greater_equal_u32; +mod greater_equal_u32_broadcast; +mod slice_fp16x16_2d; +mod slice_fp16x16_3d; +mod slice_fp8x23_2d; +mod slice_fp8x23_3d; +mod slice_i32_2d; +mod slice_i32_3d; +mod slice_i8_2d; +mod slice_i8_3d; +mod slice_u32_2d; +mod slice_u32_3d; +mod gather_fp8x23_3d_default; +mod gather_fp8x23_3d_axis1; +mod gather_fp8x23_3d_axis2; +mod gather_fp16x16_3d_default; +mod gather_fp16x16_3d_axis1; +mod gather_fp16x16_3d_axis2; +mod gather_i8_3d_default; +mod gather_i8_3d_axis1; +mod gather_i8_3d_axis2; +mod gather_i32_3d_default; +mod gather_i32_3d_axis1; +mod gather_i32_3d_axis2; +mod gather_u32_3d_default; +mod gather_u32_3d_axis1; +mod gather_u32_3d_axis2; +mod nonzero_fp16x16_2d; +mod nonzero_fp16x16_3d; +mod nonzero_fp8x23_2d; +mod nonzero_fp8x23_3d; +mod nonzero_i32_2d; +mod nonzero_i32_3d; +mod nonzero_i8_2d; +mod nonzero_i8_3d; +mod nonzero_u32_2d; +mod nonzero_u32_3d; +mod squeeze_fP16x16; +mod squeeze_fP8x23; +mod squeeze_i32; +mod squeeze_i8; +mod squeeze_u32; +mod unsqueeze_fp16x16_2d; +mod unsqueeze_fp16x16_3d; +mod unsqueeze_fp8x23_2d; +mod unsqueeze_fp8x23_3d; +mod unsqueeze_i32_2d; +mod unsqueeze_i32_3d; +mod unsqueeze_i8_2d; +mod unsqueeze_i8_3d; +mod unsqueeze_u32_2d; +mod unsqueeze_u32_3d; +mod sign_fP16x16; +mod sign_fP8x23; +mod sign_fail; +mod sign_i32; +mod sign_i8; +mod clip_fp16x16_2d; +mod clip_fp16x16_3d; +mod clip_fp8x23_2d; +mod clip_fp8x23_3d; +mod clip_i32_2d; +mod clip_i32_3d; +mod clip_i8_2d; +mod clip_i8_3d; +mod clip_u32_2d; +mod clip_u32_3d; +mod identity_fP16x16; +mod identity_fP8x23; +mod identity_i32; +mod identity_i8; +mod identity_u32; +mod thresholded_relu_fp16x16; +mod thresholded_relu_fp8x23; +mod hard_sigmoid_fp8x23; +mod hard_sigmoid_fp16x16; +mod neg_fp16x16; +mod neg_fp8x23; +mod neg_i32; +mod neg_i8; +mod gemm_all_attributes; +mod gemm_alpha; +mod gemm_beta; +mod gemm_default_matrix_bias; +mod gemm_default_vector_bias; +mod gemm_default_no_bias; +mod gemm_transposeA; +mod gemm_transposeB; +mod min_fp16x16_three_tensors; +mod min_fp16x16_broadcast_three_tensors; +mod min_fp16x16_two_tensors; +mod min_fp16x16_broadcast_two_tensors; +mod min_fp8x23_three_tensors; +mod min_fp8x23_broadcast_three_tensors; +mod min_fp8x23_two_tensors; +mod min_fp8x23_broadcast_two_tensors; +mod min_i32_three_tensors; +mod min_i32_broadcast_three_tensors; +mod min_i32_two_tensors; +mod min_i32_broadcast_two_tensors; +mod min_i8_three_tensors; +mod min_i8_broadcast_three_tensors; +mod min_i8_two_tensors; +mod min_i8_broadcast_two_tensors; +mod min_u32_three_tensors; +mod min_u32_broadcast_three_tensors; +mod min_u32_two_tensors; +mod min_u32_broadcast_two_tensors; +mod where_fp16x16; +mod where_fp16x16_broadcast; +mod where_fp8x23; +mod where_fp8x23_broadcast; +mod where_i32; +mod where_i32_broadcast; +mod where_i8; +mod where_i8_broadcast; +mod where_u32; +mod where_u32_broadcast; +mod not_bool; +mod round_fp16x16; +mod round_fp8x23; +mod max_fp16x16_three_tensors; +mod max_fp16x16_broadcast_three_tensors; +mod max_fp16x16_two_tensors; +mod max_fp16x16_broadcast_two_tensors; +mod max_fp8x23_three_tensors; +mod max_fp8x23_broadcast_three_tensors; +mod max_fp8x23_two_tensors; +mod max_fp8x23_broadcast_two_tensors; +mod max_i32_three_tensors; +mod max_i32_broadcast_three_tensors; +mod max_i32_two_tensors; +mod max_i32_broadcast_two_tensors; +mod max_i8_three_tensors; +mod max_i8_broadcast_three_tensors; +mod max_i8_two_tensors; +mod max_i8_broadcast_two_tensors; +mod max_u32_three_tensors; +mod max_u32_broadcast_three_tensors; +mod max_u32_two_tensors; +mod max_u32_broadcast_two_tensors; +mod scatter_fp16x16_3d_default; +mod scatter_fp16x16_3d_axis1; +mod scatter_fp16x16_3d_axis1_add; +mod scatter_fp8x23_default; +mod scatter_fp8x23_axis1; +mod scatter_fp8x23_mul; +mod scatter_i8_default; +mod scatter_i8_axis1; +mod scatter_i8_axis1_max; +mod scatter_u32_default; +mod scatter_u32_axis1; +mod scatter_u32_add; +mod array_feature_extractor_1D_i32; +mod array_feature_extractor_1D_fp8x23; +mod array_feature_extractor_1D_fp16x16; +mod array_feature_extractor_2D_i32; +mod array_feature_extractor_2D_fp8x23; +mod array_feature_extractor_2D_fp16x16; +mod array_feature_extractor_3D_i32; +mod array_feature_extractor_3D_fp8x23; +mod array_feature_extractor_3D_fp16x16; +mod binarizer_fp16x16; +mod binarizer_fp8x23; +mod tril_fp16x16; +mod tril_fp16x16_neg; +mod tril_fp16x16_one_row; +mod tril_fp16x16_out_neg; +mod tril_fp16x16_out_pos; +mod tril_fp16x16_pos; +mod tril_fp16x16_square; +mod tril_fp16x16_square_neg; +mod tril_fp16x16_zero; +mod triu_fp16x16; +mod triu_fp16x16_neg; +mod triu_fp16x16_one_row; +mod triu_fp16x16_out_neg; +mod triu_fp16x16_out_pos; +mod triu_fp16x16_pos; +mod triu_fp16x16_square; +mod triu_fp16x16_square_neg; +mod triu_fp16x16_zero; +mod tril_fp8x23; +mod tril_fp8x23_neg; +mod tril_fp8x23_one_row; +mod tril_fp8x23_out_neg; +mod tril_fp8x23_out_pos; +mod tril_fp8x23_pos; +mod tril_fp8x23_square; +mod tril_fp8x23_square_neg; +mod tril_fp8x23_zero; +mod triu_fp8x23; +mod triu_fp8x23_neg; +mod triu_fp8x23_one_row; +mod triu_fp8x23_out_neg; +mod triu_fp8x23_out_pos; +mod triu_fp8x23_pos; +mod triu_fp8x23_square; +mod triu_fp8x23_square_neg; +mod triu_fp8x23_zero; +mod tril_i32; +mod tril_neg_i32; +mod tril_i32_one_row; +mod tril_i32_out_neg; +mod tril_i32_out_pos; +mod tril_i32_pos; +mod tril_i32_square; +mod tril_i32_square_neg; +mod tril_i32_zero; +mod triu_i32; +mod triu_i32_neg; +mod triu_i32_one_row; +mod triu_i32_out_neg; +mod triu_i32_out_pos; +mod triu_i32_pos; +mod triu_i32_square; +mod triu_i32_square_neg; +mod triu_i32_zero; +mod tril_i8; +mod tril_i8_neg; +mod tril_i8_one_row; +mod tril_i8_out_neg; +mod tril_i8_out_pos; +mod tril_i8_pos; +mod tril_i8_square; +mod tril_i8_square_neg; +mod tril_i8_zero; +mod triu_i8; +mod triu_i8_neg; +mod triu_i8_one_row; +mod triu_i8_out_neg; +mod triu_i8_out_pos; +mod triu_i8_pos; +mod triu_i8_square; +mod triu_i8_square_neg; +mod triu_i8_zero; +mod tril_u32; +mod tril_u32_neg; +mod tril_u32_one_row; +mod tril_u32_out_neg; +mod tril_u32_out_pos; +mod tril_u32_pos; +mod tril_u32_square; +mod tril_u32_square_neg; +mod tril_u32_zero; +mod triu_u32; +mod triu_u32_neg; +mod triu_u32_one_row; +mod triu_u32_out_neg; +mod triu_u32_out_pos; +mod triu_u32_pos; +mod triu_u32_square; +mod triu_u32_square_neg; +mod triu_u32_zero; +mod reduce_sum_square_fp16x16_export_do_not_keepdims; +mod reduce_sum_square_fp16x16_export_keepdims; +mod reduce_sum_square_fp16x16_export_negative_axes_keepdims; +mod reduce_sum_square_fp8x23_export_do_not_keepdims; +mod reduce_sum_square_fp8x23_export_keepdims; +mod reduce_sum_square_fp8x23_export_negative_axes_keepdims; +mod reduce_sum_square_i32_export_do_not_keepdims; +mod reduce_sum_square_i32_export_keepdims; +mod reduce_sum_square_i32_export_negative_axes_keepdims; +mod reduce_sum_square_i8_export_do_not_keepdims; +mod reduce_sum_square_i8_export_keepdims; +mod reduce_sum_square_i8_export_negative_axes_keepdims; +mod reduce_sum_square_u32_export_do_not_keepdims; +mod reduce_sum_square_u32_export_keepdims; +mod reduce_sum_square_u32_export_negative_axes_keepdims; +mod reduce_l2_fp16x16_export_do_not_keepdims; +mod reduce_l2_fp16x16_export_keepdims; +mod reduce_l2_fp16x16_export_negative_axes_keepdims; +mod reduce_l2_fp8x23_export_do_not_keepdims; +mod reduce_l2_fp8x23_export_keepdims; +mod reduce_l2_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_fp16x16_export_do_not_keepdims; +mod reduce_l1_fp16x16_export_keepdims; +mod reduce_l1_fp16x16_export_negative_axes_keepdims; +mod reduce_l1_fp8x23_export_do_not_keepdims; +mod reduce_l1_fp8x23_export_keepdims; +mod reduce_l1_fp8x23_export_negative_axes_keepdims; +mod reduce_l1_i32_export_do_not_keepdims; +mod reduce_l1_i32_export_keepdims; +mod reduce_l1_i32_export_negative_axes_keepdims; +mod reduce_l1_i8_export_do_not_keepdims; +mod reduce_l1_i8_export_keepdims; +mod reduce_l1_i8_export_negative_axes_keepdims; +mod reduce_l1_u32_export_do_not_keepdims; +mod reduce_l1_u32_export_keepdims; +mod reduce_l1_u32_export_negative_axes_keepdims; +mod reduce_prod_fp16x16_1D; +mod reduce_prod_fp16x16_2D_default; +mod reduce_prod_fp16x16_2D_keepdims; +mod reduce_prod_fp16x16_2D_axis_1; +mod reduce_prod_fp8x23_1D; +mod reduce_prod_fp8x23_2D_default; +mod reduce_prod_fp8x23_2D_keepdims; +mod reduce_prod_fp8x23_2D_axis_1; +mod reduce_prod_i32_1D; +mod reduce_prod_i32_2D_default; +mod reduce_prod_i32_2D_keepdims; +mod reduce_prod_i32_2D_axis_1; +mod reduce_prod_i8_1D; +mod reduce_prod_i8_2D_default; +mod reduce_prod_i8_2D_keepdims; +mod reduce_prod_i8_2D_axis_1; +mod reduce_prod_u32_1D; +mod reduce_prod_u32_2D_default; +mod reduce_prod_u32_2D_keepdims; +mod reduce_prod_u32_2D_axis_1; +mod gather_elements_fp16x16_3d_default; +mod gather_elements_fp16x16_3d_axis1; +mod gather_elements_fp16x16_3d_axis2; +mod gather_elements_fp8x23_3d_default; +mod gather_elements_fp8x23_3d_axis1; +mod gather_elements_fp8x23_3d_axis2; +mod gather_elements_i8_3d_default; +mod gather_elements_i8_3d_axis1; +mod gather_elements_i32_3d_default; +mod gather_elements_i32_3d_axis1; +mod gather_elements_i32_3d_axis2; +mod gather_elements_u32_default; +mod gather_elements_u32_axis1; +mod gather_elements_u32_axis2; +mod gather_elements_u32_axis3; +mod sequence_length_fp16x16; +mod sequence_length_fp16x16_broadcast; +mod sequence_length_fp8x23; +mod sequence_length_fp8x23_broadcast; +mod sequence_length_i32; +mod sequence_length_i32_broadcast; +mod sequence_length_i8; +mod sequence_length_i8_broadcast; +mod sequence_length_u32; +mod sequence_length_u32_broadcast; +mod sequence_at_u32_positive; +mod sequence_at_u32_negative; +mod sequence_at_fp16x16_positive; +mod sequence_at_fp16x16_negative; +mod sequence_at_fp8x23_positive; +mod sequence_at_fp8x23_negative; +mod sequence_at_i32_positive; +mod sequence_at_i32_negative; +mod sequence_at_i8_positive; +mod sequence_at_i8_negative; +mod reduce_min_fp16x16_1D; +mod reduce_min_fp16x16_2D_default; +mod reduce_min_fp16x16_2D_keepdims; +mod reduce_min_fp16x16_2D_axis_1; +mod reduce_min_fp8x23_1D; +mod reduce_min_fp8x23_2D_default; +mod reduce_min_fp8x23_2D_keepdims; +mod reduce_min_fp8x23_2D_axis_1; +mod reduce_min_i32_1D; +mod reduce_min_i32_2D_default; +mod reduce_min_i32_2D_keepdims; +mod reduce_min_i32_2D_axis_1; +mod reduce_min_i8_1D; +mod reduce_min_i8_2D_default; +mod reduce_min_i8_2D_keepdims; +mod reduce_min_i8_2D_axis_1; +mod reduce_min_u32_1D; +mod reduce_min_u32_2D_default; +mod reduce_min_u32_2D_keepdims; +mod reduce_min_u32_2D_axis_1; +mod sequence_construct_fp16x16; +mod sequence_construct_fp8x23; +mod sequence_construct_i32; +mod sequence_construct_i8; +mod sequence_construct_u32; +mod shrink_hard_fp16x16; +mod shrink_soft_fp16x16; +mod shrink_hard_fp8x23; +mod shrink_soft_fp8x23; +mod sequence_empty_fp16x16; +mod sequence_empty_fp8x23; +mod sequence_empty_i32; +mod sequence_empty_i8; +mod sequence_empty_u32; +mod reduce_mean_fp16x16_1D; +mod reduce_mean_fp16x16_2D_default; +mod reduce_mean_fp16x16_2D_keepdims; +mod reduce_mean_fp16x16_2D_axis_1; +mod reduce_mean_fp8x23_1D; +mod reduce_mean_fp8x23_2D_default; +mod reduce_mean_fp8x23_2D_keepdims; +mod reduce_mean_fp8x23_2D_axis_1; +mod reduce_mean_i32_1D; +mod reduce_mean_i32_2D_default; +mod reduce_mean_i32_2D_keepdims; +mod reduce_mean_i32_2D_axis_1; +mod reduce_mean_i8_1D; +mod reduce_mean_i8_2D_default; +mod reduce_mean_i8_2D_keepdims; +mod reduce_mean_i8_2D_axis_1; +mod reduce_mean_u32_1D; +mod reduce_mean_u32_2D_default; +mod reduce_mean_u32_2D_keepdims; +mod reduce_mean_u32_2D_axis_1; +mod pow_fp16x16; +mod pow_fp16x16_broadcast; +mod pow_fp8x23; +mod pow_fp8x23_broadcast; +mod sequence_erase_u32_positive; +mod sequence_erase_u32_negative; +mod sequence_erase_u32_empty; +mod sequence_erase_fp16x16_positive; +mod sequence_erase_fp16x16_negative; +mod sequence_erase_fp16x16_empty; +mod sequence_erase_fp8x23_positive; +mod sequence_erase_fp8x23_negative; +mod sequence_erase_fp8x23_empty; +mod sequence_erase_i32_positive; +mod sequence_erase_i32_negative; +mod sequence_erase_i32_empty; +mod sequence_erase_i8_positive; +mod sequence_erase_i8_negative; +mod sequence_erase_i8_empty; +mod sequence_insert_fp16x16; +mod sequence_insert_fp8x23; +mod sequence_insert_i32; +mod sequence_insert_i8; +mod sequence_insert_u32; +mod concat_from_sequence_fp8x23_new_axis_zero; +mod concat_from_sequence_fp8x23_new_axis_one; +mod concat_from_sequence_fp8x23_new_axis_default; +mod concat_from_sequence_fp16x16_new_axis_zero; +mod concat_from_sequence_fp16x16_new_axis_one; +mod concat_from_sequence_fp16x16_new_axis_default; +mod concat_from_sequence_i32_new_axis_zero; +mod concat_from_sequence_i32_new_axis_one; +mod concat_from_sequence_i32_new_axis_default; +mod concat_from_sequence_i8_new_axis_zero; +mod concat_from_sequence_i8_new_axis_one; +mod concat_from_sequence_i8_new_axis_default; +mod concat_from_sequence_u32_new_axis_zero; +mod concat_from_sequence_u32_new_axis_one; +mod concat_from_sequence_u32_new_axis_default; +mod is_nan_fp16x16; +mod is_nan_fp8x23; +mod is_inf_fp16x16; +mod is_inf_fp8x23; +mod is_inf_i32; +mod is_inf_i8; +mod is_inf_u32; +mod is_pos_inf_fp16x16; +mod is_neg_inf_fp16x16; +mod is_pos_inf_fp8x23; +mod is_neg_inf_fp8x23; +mod is_pos_inf_i32; +mod is_neg_inf_i32; +mod is_pos_inf_i8; +mod is_neg_inf_i8; +mod and_bool; diff --git a/tests/nodes/and_i8.cairo b/tests/nodes/and_bool.cairo similarity index 75% rename from tests/nodes/and_i8.cairo rename to tests/nodes/and_bool.cairo index e662e0869..d858d66bc 100644 --- a/tests/nodes/and_i8.cairo +++ b/tests/nodes/and_bool.cairo @@ -3,22 +3,20 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::BoolTensor; +use orion::operators::tensor::BoolTensorPartialEq; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] -fn test_and_i8() { +fn test_and_bool() { 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); + let y = BoolTensor::and(@input_0, @input_1); assert_eq(y, z); } diff --git a/tests/nodes/and_fp8x23_broadcast/output_0.cairo b/tests/nodes/and_bool/input_0.cairo similarity index 57% rename from tests/nodes/and_fp8x23_broadcast/output_0.cairo rename to tests/nodes/and_bool/input_0.cairo index c58f10275..4c8339cbc 100644 --- a/tests/nodes/and_fp8x23_broadcast/output_0.cairo +++ b/tests/nodes/and_bool/input_0.cairo @@ -2,15 +2,23 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +fn input_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); + shape.append(3); + shape.append(4); let mut data = ArrayTrait::new(); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(true); data.append(true); + data.append(false); data.append(true); data.append(false); + data.append(false); data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32_broadcast/output_0.cairo b/tests/nodes/and_bool/input_1.cairo similarity index 58% rename from tests/nodes/and_i32_broadcast/output_0.cairo rename to tests/nodes/and_bool/input_1.cairo index b77d9ccb8..1a0058463 100644 --- a/tests/nodes/and_i32_broadcast/output_0.cairo +++ b/tests/nodes/and_bool/input_1.cairo @@ -2,13 +2,21 @@ use array::{ArrayTrait, SpanTrait}; use orion::operators::tensor::{TensorTrait, Tensor}; use orion::operators::tensor::BoolTensor; -fn output_0() -> Tensor { +fn input_1() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); + shape.append(3); + shape.append(4); let mut data = ArrayTrait::new(); data.append(false); + data.append(false); + data.append(true); + data.append(true); + data.append(false); + data.append(true); + data.append(false); + data.append(true); + data.append(false); data.append(true); data.append(false); data.append(true); diff --git a/tests/nodes/and_fp16x16_broadcast/output_0.cairo b/tests/nodes/and_bool/output_0.cairo similarity index 62% rename from tests/nodes/and_fp16x16_broadcast/output_0.cairo rename to tests/nodes/and_bool/output_0.cairo index 9123acad8..b094436db 100644 --- a/tests/nodes/and_fp16x16_broadcast/output_0.cairo +++ b/tests/nodes/and_bool/output_0.cairo @@ -4,13 +4,21 @@ use orion::operators::tensor::BoolTensor; fn output_0() -> Tensor { let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); + shape.append(3); + shape.append(4); let mut data = ArrayTrait::new(); data.append(false); data.append(false); data.append(false); + data.append(false); + data.append(false); + data.append(true); + data.append(false); + data.append(false); + data.append(false); + data.append(false); + data.append(false); data.append(true); TensorTrait::new(shape.span(), data.span()) } diff --git a/tests/nodes/and_i32.cairo b/tests/nodes/and_bool_broadcast.cairo similarity index 75% rename from tests/nodes/and_i32.cairo rename to tests/nodes/and_bool_broadcast.cairo index cce348f4f..fba23fd79 100644 --- a/tests/nodes/and_i32.cairo +++ b/tests/nodes/and_bool_broadcast.cairo @@ -3,22 +3,20 @@ mod input_1; mod output_0; -use orion::utils::{assert_eq, assert_seq_eq}; +use orion::operators::tensor::BoolTensor; +use orion::operators::tensor::BoolTensorPartialEq; use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I32TensorPartialEq; +use orion::utils::{assert_eq, assert_seq_eq}; use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; #[test] #[available_gas(2000000000)] -fn test_and_i32() { +fn test_and_bool_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); + let y = BoolTensor::and(@input_0, @input_1); assert_eq(y, z); } diff --git a/tests/nodes/and_fp16x16.cairo b/tests/nodes/and_fp16x16.cairo deleted file mode 100644 index 9eeff2023..000000000 --- a/tests/nodes/and_fp16x16.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::operators::tensor::FP16x16Tensor; - -#[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); -} diff --git a/tests/nodes/and_fp16x16/input_0.cairo b/tests/nodes/and_fp16x16/input_0.cairo deleted file mode 100644 index 7c02fb8d9..000000000 --- a/tests/nodes/and_fp16x16/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, FP16x16}; - -fn input_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp16x16/input_1.cairo b/tests/nodes/and_fp16x16/input_1.cairo deleted file mode 100644 index d072cc603..000000000 --- a/tests/nodes/and_fp16x16/input_1.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, 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: 196608, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - data.append(FP16x16 { mag: 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: 65536, sign: true }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 65536, sign: false }); - data.append(FP16x16 { mag: 131072, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp16x16/output_0.cairo b/tests/nodes/and_fp16x16/output_0.cairo deleted file mode 100644 index 0417518fa..000000000 --- a/tests/nodes/and_fp16x16/output_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -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(true); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp16x16_broadcast.cairo b/tests/nodes/and_fp16x16_broadcast.cairo deleted file mode 100644 index 735da46d7..000000000 --- a/tests/nodes/and_fp16x16_broadcast.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; -use orion::operators::tensor::FP16x16TensorPartialEq; -use orion::operators::tensor::FP16x16Tensor; - -#[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); -} diff --git a/tests/nodes/and_fp16x16_broadcast/input_0.cairo b/tests/nodes/and_fp16x16_broadcast/input_0.cairo deleted file mode 100644 index e88a21894..000000000 --- a/tests/nodes/and_fp16x16_broadcast/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, 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: false }); - data.append(FP16x16 { mag: 0, sign: false }); - data.append(FP16x16 { mag: 131072, sign: true }); - data.append(FP16x16 { mag: 196608, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp16x16_broadcast/input_1.cairo b/tests/nodes/and_fp16x16_broadcast/input_1.cairo deleted file mode 100644 index a92003169..000000000 --- a/tests/nodes/and_fp16x16_broadcast/input_1.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP16x16Tensor; -use orion::numbers::{FixedTrait, 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: 0, sign: false }); - data.append(FP16x16 { mag: 196608, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp8x23.cairo b/tests/nodes/and_fp8x23.cairo deleted file mode 100644 index 4ed68acc3..000000000 --- a/tests/nodes/and_fp8x23.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use orion::operators::tensor::FP8x23Tensor; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_fp8x23/input_0.cairo b/tests/nodes/and_fp8x23/input_0.cairo deleted file mode 100644 index 09c47c6ad..000000000 --- a/tests/nodes/and_fp8x23/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; - -fn input_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 16777216, 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: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp8x23/input_1.cairo b/tests/nodes/and_fp8x23/input_1.cairo deleted file mode 100644 index 5286e4abe..000000000 --- a/tests/nodes/and_fp8x23/input_1.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, 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: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 25165824, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: false }); - data.append(FP8x23 { mag: 0, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 16777216, sign: true }); - data.append(FP8x23 { mag: 8388608, sign: false }); - data.append(FP8x23 { mag: 8388608, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp8x23/output_0.cairo b/tests/nodes/and_fp8x23/output_0.cairo deleted file mode 100644 index 30a68fb27..000000000 --- a/tests/nodes/and_fp8x23/output_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -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(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp8x23_broadcast.cairo b/tests/nodes/and_fp8x23_broadcast.cairo deleted file mode 100644 index c5e5aecc2..000000000 --- a/tests/nodes/and_fp8x23_broadcast.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23TensorPartialEq; -use orion::operators::tensor::FP8x23Tensor; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_fp8x23_broadcast/input_0.cairo b/tests/nodes/and_fp8x23_broadcast/input_0.cairo deleted file mode 100644 index 4d4602452..000000000 --- a/tests/nodes/and_fp8x23_broadcast/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, FP8x23}; - -fn input_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); - - let mut data = ArrayTrait::new(); - 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: 16777216, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_fp8x23_broadcast/input_1.cairo b/tests/nodes/and_fp8x23_broadcast/input_1.cairo deleted file mode 100644 index f357c23e3..000000000 --- a/tests/nodes/and_fp8x23_broadcast/input_1.cairo +++ /dev/null @@ -1,15 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::FP8x23Tensor; -use orion::numbers::{FixedTrait, 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()) -} diff --git a/tests/nodes/and_i32/input_0.cairo b/tests/nodes/and_i32/input_0.cairo deleted file mode 100644 index e7c8cedff..000000000 --- a/tests/nodes/and_i32/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I32Tensor; -use orion::numbers::{IntegerTrait, i32}; - -fn input_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 3, sign: 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: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: true }); - 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: 1, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 2, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i32/input_1.cairo b/tests/nodes/and_i32/input_1.cairo deleted file mode 100644 index f1bb1ecdd..000000000 --- a/tests/nodes/and_i32/input_1.cairo +++ /dev/null @@ -1,41 +0,0 @@ -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: 1, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 2, sign: true }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 2, sign: false }); - data.append(i32 { mag: 0, sign: false }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 2, sign: true }); - 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: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, 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: false }); - data.append(i32 { mag: 3, sign: true }); - data.append(i32 { mag: 1, sign: true }); - data.append(i32 { mag: 1, sign: false }); - data.append(i32 { mag: 3, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i32/output_0.cairo b/tests/nodes/and_i32/output_0.cairo deleted file mode 100644 index 279220947..000000000 --- a/tests/nodes/and_i32/output_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -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(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(false); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i32_broadcast.cairo b/tests/nodes/and_i32_broadcast.cairo deleted file mode 100644 index 0a2c327ae..000000000 --- a/tests/nodes/and_i32_broadcast.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I32TensorPartialEq; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::I32Tensor; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_i32_broadcast/input_0.cairo b/tests/nodes/and_i32_broadcast/input_0.cairo deleted file mode 100644 index 8bf3fb2fc..000000000 --- a/tests/nodes/and_i32_broadcast/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -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: 2, sign: false }); - data.append(i32 { mag: 1, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i32_broadcast/input_1.cairo b/tests/nodes/and_i32_broadcast/input_1.cairo deleted file mode 100644 index e0e0ce800..000000000 --- a/tests/nodes/and_i32_broadcast/input_1.cairo +++ /dev/null @@ -1,15 +0,0 @@ -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: 0, sign: false }); - data.append(i32 { mag: 1, sign: true }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8/input_0.cairo b/tests/nodes/and_i8/input_0.cairo deleted file mode 100644 index 831184af2..000000000 --- a/tests/nodes/and_i8/input_0.cairo +++ /dev/null @@ -1,41 +0,0 @@ -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: 0, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 2, sign: false }); - 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: false }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 3, sign: true }); - 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: 1, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: false }); - data.append(i8 { mag: 2, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8/input_1.cairo b/tests/nodes/and_i8/input_1.cairo deleted file mode 100644 index 441a56a0c..000000000 --- a/tests/nodes/and_i8/input_1.cairo +++ /dev/null @@ -1,41 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I8Tensor; -use orion::numbers::{IntegerTrait, i8}; - -fn input_1() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(3); - shape.append(3); - shape.append(3); - - let mut data = ArrayTrait::new(); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 2, sign: true }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 3, 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: 3, sign: true }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 3, sign: true }); - data.append(i8 { mag: 1, sign: false }); - 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: 3, sign: true }); - data.append(i8 { mag: 0, sign: false }); - data.append(i8 { mag: 1, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8/output_0.cairo b/tests/nodes/and_i8/output_0.cairo deleted file mode 100644 index cb879d158..000000000 --- a/tests/nodes/and_i8/output_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -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(false); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8_broadcast.cairo b/tests/nodes/and_i8_broadcast.cairo deleted file mode 100644 index fb730f5c8..000000000 --- a/tests/nodes/and_i8_broadcast.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::I8Tensor; -use orion::operators::tensor::I8TensorPartialEq; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_i8_broadcast/input_0.cairo b/tests/nodes/and_i8_broadcast/input_0.cairo deleted file mode 100644 index 9b56de844..000000000 --- a/tests/nodes/and_i8_broadcast/input_0.cairo +++ /dev/null @@ -1,17 +0,0 @@ -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: 2, sign: false }); - data.append(i8 { mag: 2, sign: false }); - data.append(i8 { mag: 1, sign: true }); - data.append(i8 { mag: 2, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8_broadcast/input_1.cairo b/tests/nodes/and_i8_broadcast/input_1.cairo deleted file mode 100644 index 9a3d0511b..000000000 --- a/tests/nodes/and_i8_broadcast/input_1.cairo +++ /dev/null @@ -1,15 +0,0 @@ -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: 2, sign: false }); - data.append(i8 { mag: 1, sign: false }); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_i8_broadcast/output_0.cairo b/tests/nodes/and_i8_broadcast/output_0.cairo deleted file mode 100644 index cfa512f61..000000000 --- a/tests/nodes/and_i8_broadcast/output_0.cairo +++ /dev/null @@ -1,16 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32.cairo b/tests/nodes/and_u32.cairo deleted file mode 100644 index cd0223fe3..000000000 --- a/tests/nodes/and_u32.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::U32Tensor; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_u32/input_0.cairo b/tests/nodes/and_u32/input_0.cairo deleted file mode 100644 index 223353b25..000000000 --- a/tests/nodes/and_u32/input_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -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(1); - data.append(4); - data.append(1); - data.append(1); - data.append(2); - data.append(1); - data.append(2); - data.append(5); - data.append(4); - data.append(4); - data.append(0); - data.append(4); - data.append(0); - data.append(3); - data.append(0); - data.append(1); - data.append(4); - data.append(0); - data.append(0); - data.append(5); - data.append(2); - data.append(1); - data.append(3); - data.append(3); - data.append(0); - data.append(3); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32/input_1.cairo b/tests/nodes/and_u32/input_1.cairo deleted file mode 100644 index 0f7af1f59..000000000 --- a/tests/nodes/and_u32/input_1.cairo +++ /dev/null @@ -1,40 +0,0 @@ -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(3); - data.append(1); - data.append(3); - data.append(1); - data.append(2); - data.append(0); - data.append(0); - data.append(5); - data.append(1); - data.append(5); - data.append(4); - data.append(4); - data.append(0); - data.append(1); - data.append(2); - data.append(5); - data.append(0); - data.append(2); - data.append(0); - data.append(2); - data.append(1); - data.append(5); - data.append(5); - data.append(1); - data.append(3); - data.append(3); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32/output_0.cairo b/tests/nodes/and_u32/output_0.cairo deleted file mode 100644 index 86e333ba7..000000000 --- a/tests/nodes/and_u32/output_0.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -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(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(true); - data.append(false); - data.append(false); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(true); - data.append(false); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32_broadcast.cairo b/tests/nodes/and_u32_broadcast.cairo deleted file mode 100644 index 242b3af94..000000000 --- a/tests/nodes/and_u32_broadcast.cairo +++ /dev/null @@ -1,24 +0,0 @@ -mod input_0; -mod input_1; -mod output_0; - - -use orion::utils::{assert_eq, assert_seq_eq}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32TensorPartialEq; -use orion::operators::tensor::U32Tensor; -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::BoolTensorPartialEq; -use orion::operators::tensor::BoolTensor; - -#[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); -} diff --git a/tests/nodes/and_u32_broadcast/input_0.cairo b/tests/nodes/and_u32_broadcast/input_0.cairo deleted file mode 100644 index ecd2ce1a3..000000000 --- a/tests/nodes/and_u32_broadcast/input_0.cairo +++ /dev/null @@ -1,16 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::U32Tensor; - -fn input_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(0); - data.append(2); - data.append(1); - data.append(2); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32_broadcast/input_1.cairo b/tests/nodes/and_u32_broadcast/input_1.cairo deleted file mode 100644 index 01550d690..000000000 --- a/tests/nodes/and_u32_broadcast/input_1.cairo +++ /dev/null @@ -1,14 +0,0 @@ -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(2); - data.append(1); - TensorTrait::new(shape.span(), data.span()) -} diff --git a/tests/nodes/and_u32_broadcast/output_0.cairo b/tests/nodes/and_u32_broadcast/output_0.cairo deleted file mode 100644 index 83cb01c24..000000000 --- a/tests/nodes/and_u32_broadcast/output_0.cairo +++ /dev/null @@ -1,16 +0,0 @@ -use array::{ArrayTrait, SpanTrait}; -use orion::operators::tensor::{TensorTrait, Tensor}; -use orion::operators::tensor::BoolTensor; - -fn output_0() -> Tensor { - let mut shape = ArrayTrait::::new(); - shape.append(2); - shape.append(2); - - let mut data = ArrayTrait::new(); - data.append(false); - data.append(true); - data.append(true); - data.append(true); - TensorTrait::new(shape.span(), data.span()) -} From 26eb00e2be9edd8b677ee82a0a97751f5f1e990d Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 1 Dec 2023 11:55:28 +0200 Subject: [PATCH 160/160] update doc --- docs/framework/operators/tensor/tensor.and.md | 43 +++++-------------- src/operators/tensor/core.cairo | 29 ++----------- 2 files changed, 13 insertions(+), 59 deletions(-) diff --git a/docs/framework/operators/tensor/tensor.and.md b/docs/framework/operators/tensor/tensor.and.md index 94556ce0f..2c2b74f16 100644 --- a/docs/framework/operators/tensor/tensor.and.md +++ b/docs/framework/operators/tensor/tensor.and.md @@ -1,7 +1,7 @@ #tensor.and ```rust - fn and(self: @Tensor, other: @Tensor) -> Tensor; + fn and(self: @Tensor, other: @Tensor) -> Tensor; ``` Computes the logical AND of two tensors element-wise. @@ -11,8 +11,8 @@ The input tensors must have either: ## Args -* `self`(`@Tensor`) - The first tensor to be compared -* `other`(`@Tensor`) - The second tensor to be compared +* `self`(`@Tensor`) - The first tensor to be compared +* `other`(`@Tensor`) - The second tensor to be compared ## Panics @@ -20,48 +20,25 @@ The input tensors must have either: ## Returns -A new `Tensor` of booleans (0 or 1) with the same shape as the broadcasted inputs. +A new `Tensor` 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(), +fn and_example() -> Tensor { + let tensor_1 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![false, true, false, false, false, true, true, false, true, false, false, true].span(), ); - let tensor_2 = TensorTrait::::new( - shape: array![1, 3].span(), data: array![0, 1, 2].span(), + let tensor_2 = TensorTrait::::new( + shape: array![3, 3].span(), data: array![false, false, true, true, false, true, false, true, false, true, false, true].span(), ); return tensor_1.and(@tensor_2); } ->>> [0,1,1,0,1,1,0,1,1] +>>> [false, false, false, false, false, true, false, false, false, false, false, true] ``` diff --git a/src/operators/tensor/core.cairo b/src/operators/tensor/core.cairo index 321d1327c..75f90224f 100644 --- a/src/operators/tensor/core.cairo +++ b/src/operators/tensor/core.cairo @@ -3475,8 +3475,6 @@ trait TensorTrait { /// /// ## Examples /// - /// Case 1: Compare tensors with same shape - /// /// ```rust /// use array::{ArrayTrait, SpanTrait}; /// @@ -3484,37 +3482,16 @@ trait TensorTrait { /// /// 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); - /// } - /// >>> [false, true, true, false, true, true, false, true, true] - /// ``` - /// - /// 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(), + /// shape: array![3, 3].span(), data: array![false, true, false, false, false, true, true, false, true, false, false, true].span(), /// ); /// /// let tensor_2 = TensorTrait::::new( - /// shape: array![1, 3].span(), data: array![0, 1, 2].span(), + /// shape: array![3, 3].span(), data: array![false, false, true, true, false, true, false, true, false, true, false, true].span(), /// ); /// /// return tensor_1.and(@tensor_2); /// } - /// >>> [false, true, true, false, true, true, false, true, true] + /// >>> [false, false, false, false, false, true, false, false, false, false, false, true] /// ``` /// fn and(self: @Tensor, other: @Tensor) -> Tensor;