text
stringlengths 1
2.05k
|
---|
fn qlinearadd_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![4, 2].span(),
data: array![1_i8, 2_i8, 3_i8, 4_i8, 5_i8, 6_i8, 7_i8, 8_i8].span(),
);
let b = TensorTrait::<
i8
>::new(
shape: array![4, 2].span(),
data: array![2_i8, 4_i8, 6_i8, 8_i8, 10_i8, 12_i8, 14_i8, 16_i8].span(),
);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(20000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(25000, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(30000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let actual_output = a
.qlinear_add(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point);
assert((*actual_output.data[0]).into() == 2, '*result[0] == 2');
assert((*actual_output.data[1]).into() == 4, '*result[1] == 4');
assert((*actual_output.data[2]).into() == 7, '*result[2] == 7');
assert((*actual_output.data[3]).into() == 9, '*result[3] == 9');
assert((*actual_output.data[4]).into() == 11, '*result[4] == 11');
assert((*actual_output.data[5]).into() == 14, '*result[5] == 14');
assert((*actual_output.data[6]).into() == 16, '*result[6] == 16');
assert((*actual_output.data[7]).into() == 18, '*result[7] == 18');
} |
fn qlinearadd_broadcast_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 4].span(),
data: array![1_i8, 2_i8, 3_i8, 4_i8, 5_i8, 6_i8, 7_i8, 8_i8].span(),
);
let b = TensorTrait::<
i8
>::new(shape: array![1, 4].span(), data: array![2_i8, 4_i8, 6_i8, 8_i8,].span(),);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(20000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(25000, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(30000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let actual_output = a
.qlinear_add(@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point);
assert((*actual_output.data[0]).into() == 2, '*result[0] == 2');
assert((*actual_output.data[1]).into() == 4, '*result[1] == 4');
assert((*actual_output.data[2]).into() == 7, '*result[2] == 7');
assert((*actual_output.data[3]).into() == 9, '*result[3] == 9');
assert((*actual_output.data[4]).into() == 5, '*result[4] == 5');
assert((*actual_output.data[5]).into() == 7, '*result[5] == 7');
assert((*actual_output.data[6]).into() == 9, '*result[6] == 9');
assert((*actual_output.data[7]).into() == 12, '*result[7] == 12');
} |
fn test_example_doc() {
let a = TensorTrait::<
i8
>::new(shape: array![2, 3].span(), data: array![6_i8, 6_i8, 6_i8, 11_i8, 11_i8, 11_i8].span(),);
let b = TensorTrait::<
i8
>::new(shape: array![1, 3].span(), data: array![40_i8, 40_i8, 40_i8].span(),);
let a_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(65536, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(16384, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(655360, false)].span(),
);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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);
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');
} |
use core::debug::PrintTrait;
use core::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}; |
fn print_span(mut span: Span<i8>) {
loop {
match span.pop_front() {
Option::Some(i) => { (*i).print(); },
Option::None => { break; }
};
};
} |
fn qlinear_concat_test() {
let tensor1 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![10_i8, 20_i8, 30_i8, 40_i8,].span(),);
let tensor2 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![20_i8, 40_i8, 60_i8, 80_i8,].span(),);
let tensors = array![tensor1, tensor2].span();
let tensor1_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(20000, false)].span(),);
let tensor2_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(0, false)].span(),);
let tensor2_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(65536, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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() == 22, '*result[6] == 22');
assert( |
(*actual_output.data[7]).into() == 30, '*result[7] == 30');
} |
fn qlinear_concat_test_shape() {
let tensor1 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![2_i8, 2_i8, 2_i8, 2_i8,].span(),);
let tensor2 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![8_i8, 8_i8, 8_i8, 8_i8,].span(),);
let tensor3 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![10_i8, 10_i8, 10_i8, 10_i8,].span(),);
let tensors = array![tensor1, tensor2, tensor3].span();
let tensor1_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let tensor2_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(262144, false)].span(),
);
let tensor3_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(65536, false)].span(),);
let tensor2_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(65536, false)].span(),);
let tensor3_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(30000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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');
} |
fn qlinear_concat_example_doc() {
let tensor1 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![5_i8, 5_i8, 5_i8, 5_i8,].span(),);
let tensor2 = TensorTrait::<
i8
>::new(shape: array![2, 2].span(), data: array![1_i8, 1_i8, 1_i8, 1_i8,].span(),);
let tensors = array![tensor1, tensor2].span();
let tensor1_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let tensor2_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(327680, false)].span(),
);
let tensor2_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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::<FP16x16>::new(262144, false)].span(),
);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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');
} |
use core::debug::PrintTrait;
use core::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};
#[test]
#[available_gas(200000000000)]
fn qlinear_leakyrelu_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 3].span(),
data: array![-10_i8, -10_i8, -10_i8, 10_i8, 10_i8, 10_i8].span(),
);
let a_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let a_zero_point = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let alpha = FixedTrait::<FP16x16>::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');
}
|
use core::debug::PrintTrait;
use core::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}; |
fn qlinearmatmul_2D_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 4].span(),
data: array![1_i8, 2_i8, 3_i8, 4_i8, 5_i8, 6_i8, 7_i8, 8_i8].span(),
);
let b = TensorTrait::<
i8
>::new(
shape: array![4, 3].span(),
data: array![2_i8, 4_i8, 6_i8, 8_i8, 10_i8, 12_i8, 14_i8, 16_i8, 18_i8, 20_i8, 22_i8, 24_i8]
.span(),
);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(2000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(2500, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(3000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let actual_output = a
.qlinear_matmul(
@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point
);
assert((*actual_output.data[0]).into() == 3, '*result[0] == 3');
assert((*actual_output.data[1]).into() == 4, '*result[1] == 4');
assert((*actual_output.data[2]).into() == 4, '*result[2] == 4');
assert((*actual_output.data[3]).into() == 8, '*result[3] == 8');
assert((*actual_output.data[4]).into() == 9, '*result[4] == 9');
assert((*actual_output.data[5]).into() == 10, '*result[5] == 10');
} |
fn qlinearmatmul_3D_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 2, 3].span(),
data: array![
-1_i8, -2_i8, -2_i8, -3_i8, -4_i8, -4_i8, -5_i8, -6_i8, -6_i8, -7_i8, -8_i8, -8_i8
]
.span(),
);
let b = TensorTrait::<
i8
>::new(
shape: array![2, 3, 2].span(),
data: array![
-2_i8, -4_i8, -6_i8, -8_i8, -10_i8, -12_i8, -2_i8, -4_i8, -6_i8, -8_i8, -10_i8, -12_i8
]
.span(),
);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(20000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(25000, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(30000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let actual_output = a
.qlinear_matmul(
@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point
);
assert((*actual_output.data[0]).into() == 8, '*result[0] == 8');
assert((*actual_output.data[1]).into() == 11, '*result[1] == 11');
assert((*actual_output.data[2]).into() == 17, '*result[2] == 17');
assert((*actual_output.data[3]).into() == 23, '*result[3] == 23');
assert((*actual_output.data[4]).into() == 26, '*result[4] == 26');
assert((*actual_output.data[5]).into() == 35, '*result[5] == 35');
assert((*actual_output.data[6]).into() = |
= 36, '*result[6] == 36');
assert((*actual_output.data[7]).into() == 47, '*result[7] == 47');
} |
fn test_example_doc() {
let a = TensorTrait::<
i8
>::new(shape: array![2, 3].span(), data: array![3_i8, 4_i8, 5_i8, 2_i8, 4_i8, 3_i8].span(),);
let b = TensorTrait::<
i8
>::new(shape: array![3, 1].span(), data: array![4_i8, 8_i8, 4_i8].span(),);
let a_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(65536, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(16384, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(393216, false)].span(),
);
let y_zero_point = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(655360, false)].span(),
);
let actual_output = a
.qlinear_matmul(
@a_scale, @a_zero_point, @b, @b_scale, @b_zero_point, @y_scale, @y_zero_point
);
assert((*actual_output.data[0]).into() == 14, '*result[0] == 14');
assert((*actual_output.data[1]).into() == 13, '*result[1] == 13');
} |
fn print_span(mut span: Span<i8>) {
loop {
match span.pop_front() {
Option::Some(i) => { (*i).print(); },
Option::None => { break; }
};
};
} |
use core::debug::PrintTrait;
use core::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}; |
fn qlinearmul_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![4, 3].span(),
data: array![1_i8, 2_i8, 3_i8, 4_i8, 5_i8, 6_i8, 7_i8, 8_i8, 9_i8, 10_i8, 11_i8, 12_i8]
.span(),
);
let b = TensorTrait::<
i8
>::new(
shape: array![4, 3].span(),
data: array![2_i8, 4_i8, 6_i8, 8_i8, 10_i8, 12_i8, 14_i8, 16_i8, 18_i8, 20_i8, 22_i8, 24_i8]
.span(),
);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(2000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(2500, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(3000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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((*actu |
al_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');
} |
fn qlinear_mul_broadcast_test() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 4].span(),
data: array![1_i8, 2_i8, 3_i8, 4_i8, 5_i8, 6_i8, 7_i8, 8_i8].span(),
);
let b = TensorTrait::<
i8
>::new(shape: array![1, 4].span(), data: array![2_i8, 4_i8, 6_i8, 8_i8,].span(),);
let a_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(20000, false)].span(),);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(25000, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(30000, false)].span(),);
let y_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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');
} |
fn test_example_doc() {
let a = TensorTrait::<
i8
>::new(
shape: array![2, 3].span(), data: array![21_i8, 21_i8, 21_i8, 41_i8, 41_i8, 41_i8].span(),
);
let b = TensorTrait::<
i8
>::new(shape: array![1, 3].span(), data: array![4_i8, 8_i8, 12_i8].span(),);
let a_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(131072, false)].span(),
);
let a_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(65536, false)].span(),);
let b_scale = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(16384, false)].span(),);
let b_zero_point = TensorTrait::<
FP16x16
>::new(shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(0, false)].span(),);
let y_scale = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::new(393216, false)].span(),
);
let y_zero_point = TensorTrait::<
FP16x16
>::new(
shape: array![1].span(), data: array![FixedTrait::<FP16x16>::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');
} |
mod argmax;
mod argmin;
mod max;
mod min;
mod reduce_sum;
mod exp;
mod equal;
mod greater;
mod greater_equal;
mod less;
mod less_equal;
mod abs;
mod ceil;
mod ln;
mod arithmetic;
mod sin;
mod cos;
mod asin;
mod cumsum;
mod flatten;
mod sinh;
mod tanh;
mod cosh;
mod acosh;
mod asinh;
mod atan;
mod xor;
mod or;
mod acos;
mod onehot;
mod sqrt;
mod concat;
mod gather;
mod where;
|
use core::array::{ArrayTrait, SpanTrait};
use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
use core::debug::PrintTrait;
#[test]
#[available_gas(200000000000)]
fn transpose_test_shape() {
let tensor = TensorTrait::<
u32
>::new(shape: array![4, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),);
let result = tensor.transpose(axes: array![1, 0].span());
assert(result.shape == array![2, 4].span(), 'wrong dim');
}
#[test]
#[available_gas(200000000000)]
fn transpose_test_values() {
let tensor = TensorTrait::<
u32
>::new(shape: array![4, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),);
let result = tensor.transpose(axes: array![1, 0].span());
assert(result.data == array![0, 2, 4, 6, 1, 3, 5, 7].span(), 'wrong data');
}
#[test]
#[available_gas(200000000000)]
fn transpose_test_1D() {
let tensor = TensorTrait::<u32>::new(shape: array![4].span(), data: array![0, 1, 2, 3].span(),);
let result = tensor.transpose(axes: array![0].span());
assert(result.shape == array![4].span(), 'wrong shape');
assert(result.data == array![0, 1, 2, 3].span(), 'wrong data');
}
#[test]
#[available_gas(200000000000)]
fn transpose_test_3D() {
let tensor = TensorTrait::<
u32
>::new(shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),);
let result = tensor.transpose(axes: array![1, 2, 0].span());
assert(result.shape == array![2, 2, 2].span(), 'wrong shape');
assert(result.data == array![0, 4, 1, 5, 2, 6, 3, 7].span(), 'wrong data');
}
|
mod quantize_linear_test;
mod dequantize_linear_test;
mod dynamic_quantize_linear_test;
|
mod dequantize_linear_i32_test;
mod dequantize_linear_fp_test;
|
mod fp_i8_test;
|
mod fp8x23 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23PartialEq};
use orion::operators::tensor::I8Tensor;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP8x23; |
fn dequantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(4);
let mut data = ArrayTrait::<i8>::new();
data.append(0);
data.append(3);
data.append(125);
data.append(127);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(2, false));
let x_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(0, false));
let x_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<FP8x23> = x.dequantize_linear(@x_scale, @x_zero_point);
assert(
(*y.data[0]).into() == FixedTrait::<FP8x23, u32>::new_unscaled(0, false),
'*result[0] == 0'
);
assert(
(*y.data[1]).into() == FixedTrait::<FP8x23, u32>::new_unscaled(6, false),
'*result[1] == 6'
);
assert(
(*y.data[2]).into() == FixedTrait::<FP8x23, u32>::new_unscaled(250, false),
'*result[2] == 250'
);
assert(
(*y.data[3]).into() == FixedTrait::<FP8x23, u32>::new_unscaled(254, false),
'*result[3] == 254'
);
}
}
mod fp16x16 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp16x16::core::{
FP16x16Impl, FP16x16PartialEq
};
use orion::operators::tensor::I8Tensor;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor; |
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP16x16; |
fn dequantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(4);
let mut data = ArrayTrait::<i8>::new();
data.append(0);
data.append(3);
data.append(125);
data.append(127);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(2, false));
let x_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(0, false));
let x_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<FP16x16> = x.dequantize_linear(@x_scale, @x_zero_point);
assert(
(*y.data[0]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(0, false),
'*result[0] == 0'
);
assert(
(*y.data[1]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(6, false),
'*result[1] == 6'
);
assert(
(*y.data[2]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(250, false),
'*result[2] == 250'
);
assert(
(*y.data[3]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(254, false),
'*result[3] == 254'
);
} |
fn per_axis() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(3);
shape.append(2);
let mut data = ArrayTrait::<i8>::new();
data.append(3);
data.append(89);
data.append(34);
data.append(127);
data.append(74);
data.append(59);
data.append(5);
data.append(24);
data.append(24);
data.append(87);
data.append(32);
data.append(13);
data.append(127);
data.append(99);
data.append(4);
data.append(127);
data.append(121);
data.append(102);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(4, false));
data.append(FixedTrait::new_unscaled(5, false));
let x_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(1, false));
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(3, false));
let x_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<FP16x16> = x.dequantize_linear(@x_scale, @x_zero_point);
assert(
(*y.data[0]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(4, false),
'*result[0] == 162'
);
assert(
(*y.data[1]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(176, false),
'*result[1] == 10'
);
assert( |
(*y.data[2]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(66, false),
'*result[2] == 100'
);
assert(
(*y.data[3]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(252, false),
'*result[3] == 232'
);
assert(
(*y.data[4]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(146, false),
'*result[4] == 20'
);
assert(
(*y.data[5]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(116, false),
'*result[5] == 50'
);
assert(
(*y.data[6]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(12, false),
'*result[6] == 76'
);
assert(
(*y.data[7]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(88, false),
'*result[7] == 0'
);
assert(
(*y.data[8]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(88, false),
'*result[8] == 0'
);
assert(
(*y.data[9]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(340, false),
'*result[9] == 252'
);
assert(
(*y.data[10]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(120, false),
'*result[10] == 32'
);
assert(
(*y.data[11]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(44, false),
'*result[11] == 44'
);
assert(
(*y.data[12]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(620, false),
'*result[12] == 245'
);
assert(
(*y.data[13]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(480, false),
'*result[13] == 485'
);
assert(
(*y.data[14]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(5, false),
'*result[14] == 960'
);
assert(
(*y.data[15]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(620, false),
'*result[15] == 270'
); |
assert(
(*y.data[16]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(590, false),
'*result[16] == 375'
);
assert(
(*y.data[17]).into() == FixedTrait::<FP16x16, u32>::new_unscaled(495, false),
'*result[17] == 470'
);
}
} |
use core::debug::{PrintTrait};
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::operators::tensor::I8Tensor;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::{TensorTrait, Tensor}; |
fn dequantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(4);
let mut data = ArrayTrait::<i8>::new();
data.append(0);
data.append(3);
data.append(125);
data.append(127);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(2);
let x_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(0);
let x_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i32> = x.dequantize_linear(@x_scale, @x_zero_point);
assert((*y.data[0]).into() == 0, '*result[0] == 0');
assert((*y.data[1]).into() == 6, '*result[1] == 6');
assert((*y.data[2]).into() == 250, '*result[2] == 250');
assert((*y.data[3]).into() == 254, '*result[3] == 254');
} |
fn per_axis() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(3);
shape.append(2);
let mut data = ArrayTrait::<i8>::new();
data.append(3);
data.append(89);
data.append(34);
data.append(127);
data.append(74);
data.append(59);
data.append(5);
data.append(24);
data.append(24);
data.append(87);
data.append(32);
data.append(13);
data.append(127);
data.append(99);
data.append(4);
data.append(127);
data.append(121);
data.append(102);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(2);
data.append(4);
data.append(5);
let x_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(1);
data.append(2);
data.append(3);
let x_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i32> = x.dequantize_linear(@x_scale, @x_zero_point);
assert((*y.data[0]).into() == 4, '*result[0] == 162');
assert((*y.data[1]).into() == 176, '*result[1] == 10');
assert((*y.data[2]).into() == 66, '*result[2] == 100');
assert((*y.data[3]).into() == 252, '*result[3] == 232');
assert((*y.data[4]).into() == 146, '*result[4] == 20');
assert((*y.data[5]).into() == 116, '*result[5] == 50');
assert((*y.data[6]).into() == 12, '*result[6] == 76');
assert((*y.data[7]).into() == 88, '*result[7] == 0');
assert((*y.data[8]).into() == 88, '*result[8] == 0');
assert((*y.data[9]).into() == 340, '*result[9] == 252');
assert((*y.data[10]).into() == 120, '*result[10] == 32');
assert((*y.data[11]).into() == 44, '*result[11] == 44'); |
assert((*y.data[12]).into() == 620, '*result[12] == 245');
assert((*y.data[13]).into() == 480, '*result[13] == 485');
assert((*y.data[14]).into() == 5, '*result[14] == 960');
assert((*y.data[15]).into() == 620, '*result[15] == 270');
assert((*y.data[16]).into() == 590, '*result[16] == 375');
assert((*y.data[17]).into() == 495, '*result[17] == 470');
} |
mod dynamic_quantize_linear_fp_test;
|
mod fp8x23 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp8x23::core::FP8x23Impl;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP8x23; |
fn dynamic_quantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(6);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new(0, false));
data.append(FixedTrait::new(587203, false));
data.append(FixedTrait::new(838861, false));
data.append(FixedTrait::new(1677722, false));
data.append(FixedTrait::new(4194304, false));
data.append(FixedTrait::new(7549747, false));
let x = TensorTrait::new(shape.span(), data.span());
let (y, y_scale, y_zero_point) = x.dynamic_quantize_linear();
assert((*(y_scale.data).at(0)).into() == 29606, '*y_scale[0].mag == 0.00353');
assert((*(y_zero_point.data).at(0)).into() == 0, '*y_zero_point[0].mag == 0');
assert((*(y.data).at(0)).into() == 0, '*result[0] == 0');
assert((*(y.data).at(1)).into() == 19, '*result[1] == 19');
assert((*(y.data).at(2)).into() == 28, '*result[2] == 28');
assert((*(y.data).at(3)).into() == 56, '*result[3] == 56');
assert((*(y.data).at(4)).into() == 141, '*result[4] == 141');
assert((*(y.data).at(5)).into() == 255, '*result[5] == 255');
}
}
mod fp16x16 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp16x16::core::FP16x16Impl;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP16x16; |
fn dynamic_quantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(6);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new(10945, false));
data.append(FixedTrait::new(190054, false));
data.append(FixedTrait::new_unscaled(3, false));
data.append(FixedTrait::new(229376, false));
data.append(FixedTrait::new_unscaled(3, true));
data.append(FixedTrait::new(229376, true));
let x = TensorTrait::new(shape.span(), data.span());
let (y, y_scale, y_zero_point) = x.dynamic_quantize_linear();
assert((*(y_scale.data).at(0)).into() == 1799, '*y_scale[0].mag == 0.02745');
assert((*(y_zero_point.data).at(0)).into() == 8355967, '*y_zero_point[0].mag == 128');
assert((*(y.data).at(0)).into() == 133, '*result[0] == 134');
assert((*(y.data).at(1)).into() == 233, '*result[1] == 233');
assert((*(y.data).at(2)).into() == 236, '*result[2] == 237');
assert((*(y.data).at(3)).into() == 255, '*result[3] == 255');
assert((*(y.data).at(4)).into() == 18, '*result[4] == -18');
assert((*(y.data).at(5)).into() == 0, '*result[5] == -0');
}
} |
mod quantize_linear_i32_test;
mod quantize_linear_fp_test;
|
mod fp_i8_test;
|
mod fp8x23 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp8x23::core::FP8x23Impl;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP8x23; |
fn quantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(6);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(3, false));
data.append(FixedTrait::new_unscaled(200, false));
data.append(FixedTrait::new_unscaled(250, true));
data.append(FixedTrait::new_unscaled(100, true));
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(2, false));
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(1, false));
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 1, '*result[0] == 1');
assert((*y.data[1]).into() == 2, '*result[1] == 2');
assert((*y.data[2]).into() == 2, '*result[2] == 2');
assert((*y.data[3]).into() == 101, '*result[3] == 101');
assert((*y.data[4]).into() == -124, '*result[4] == -124');
assert((*y.data[5]).into() == -49, '*result[5] == -49');
} |
fn per_axis() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(3);
shape.append(2);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(162, true));
data.append(FixedTrait::new_unscaled(10, false));
data.append(FixedTrait::new_unscaled(100, true));
data.append(FixedTrait::new_unscaled(232, false));
data.append(FixedTrait::new_unscaled(20, true));
data.append(FixedTrait::new_unscaled(50, true));
data.append(FixedTrait::new_unscaled(76, true));
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(252, false));
data.append(FixedTrait::new_unscaled(32, false));
data.append(FixedTrait::new_unscaled(44, true));
data.append(FixedTrait::new_unscaled(245, false));
data.append(FixedTrait::new_unscaled(220, true));
data.append(FixedTrait::new_unscaled(210, true));
data.append(FixedTrait::new_unscaled(210, true));
data.append(FixedTrait::new_unscaled(200, true));
data.append(FixedTrait::new_unscaled(120, true));
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(4, false));
data.append(FixedTrait::new_unscaled(5, false));
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP8x23>::new();
data.append(FixedTrait::new_unscaled(84, |
false));
data.append(FixedTrait::new_unscaled(24, false));
data.append(FixedTrait::new_unscaled(196, false));
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 3, '*result[0] == 3');
assert((*y.data[1]).into() == 89, '*result[1] == 89');
assert((*y.data[2]).into() == 34, '*result[2] == 34');
assert((*y.data[3]).into() == 127, '*result[3] == 127');
assert((*y.data[4]).into() == 74, '*result[4] == 74');
assert((*y.data[5]).into() == 59, '*result[5] == 59');
assert((*y.data[6]).into() == 5, '*result[6] == 5');
assert((*y.data[7]).into() == 24, '*result[7] == 24');
assert((*y.data[8]).into() == 24, '*result[8] == 24');
assert((*y.data[9]).into() == 87, '*result[9] == 87');
assert((*y.data[10]).into() == 32, '*result[10] == 32');
assert((*y.data[11]).into() == 13, '*result[11] == 13');
assert((*y.data[12]).into() == 127, '*result[12] == 127');
assert((*y.data[13]).into() == 127, '*result[13] == 127');
assert((*y.data[14]).into() == 127, '*result[14] == 127');
assert((*y.data[15]).into() == 127, '*result[15] == 127');
assert((*y.data[16]).into() == 127, '*result[16] == 127');
assert((*y.data[17]).into() == 127, '*result[17] == 127');
}
}
mod fp16x16 {
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use core::debug::PrintTrait;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::numbers::fixed_point::implementations::fp16x16::core::FP16x16Impl;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::operators::tensor::{TensorTrait, Tensor};
use orion::numbers::FP16x16; |
fn quantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(6);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(3, false));
data.append(FixedTrait::new_unscaled(1000, false));
data.append(FixedTrait::new_unscaled(254, true));
data.append(FixedTrait::new_unscaled(1000, true));
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(2, false));
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(1, false));
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 1, '*result[0] == 1');
assert((*y.data[1]).into() == 2, '*result[1] == 2');
assert((*y.data[2]).into() == 2, '*result[2] == 2');
assert((*y.data[3]).into() == 127, '*result[3] == 127');
assert((*y.data[4]).into() == -126, '*result[4] == -126');
assert((*y.data[5]).into() == -127, '*result[5] == -127');
} |
fn per_axis() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(3);
shape.append(2);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(162, true));
data.append(FixedTrait::new_unscaled(10, false));
data.append(FixedTrait::new_unscaled(100, true));
data.append(FixedTrait::new_unscaled(232, false));
data.append(FixedTrait::new_unscaled(20, true));
data.append(FixedTrait::new_unscaled(50, true));
data.append(FixedTrait::new_unscaled(76, true));
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(0, false));
data.append(FixedTrait::new_unscaled(252, false));
data.append(FixedTrait::new_unscaled(32, false));
data.append(FixedTrait::new_unscaled(44, true));
data.append(FixedTrait::new_unscaled(245, false));
data.append(FixedTrait::new_unscaled(485, true));
data.append(FixedTrait::new_unscaled(960, true));
data.append(FixedTrait::new_unscaled(270, true));
data.append(FixedTrait::new_unscaled(375, true));
data.append(FixedTrait::new_unscaled(470, true));
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(2, false));
data.append(FixedTrait::new_unscaled(4, false));
data.append(FixedTrait::new_unscaled(5, false));
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<FP16x16>::new();
data.append(FixedTrait::new_unscaled(8 |
4, false));
data.append(FixedTrait::new_unscaled(24, false));
data.append(FixedTrait::new_unscaled(196, false));
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 3, '*result[0] == 3');
assert((*y.data[1]).into() == 89, '*result[1] == 89');
assert((*y.data[2]).into() == 34, '*result[2] == 34');
assert((*y.data[3]).into() == 127, '*result[3] == 127');
assert((*y.data[4]).into() == 74, '*result[4] == 74');
assert((*y.data[5]).into() == 59, '*result[5] == 59');
assert((*y.data[6]).into() == 5, '*result[6] == 5');
assert((*y.data[7]).into() == 24, '*result[7] == 24');
assert((*y.data[8]).into() == 24, '*result[8] == 24');
assert((*y.data[9]).into() == 87, '*result[9] == 87');
assert((*y.data[10]).into() == 32, '*result[10] == 32');
assert((*y.data[11]).into() == 13, '*result[11] == 13');
assert((*y.data[12]).into() == 127, '*result[12] == 127');
assert((*y.data[13]).into() == 99, '*result[13] == 99');
assert((*y.data[14]).into() == 4, '*result[14] == 4');
assert((*y.data[15]).into() == 127, '*result[15] == 127');
assert((*y.data[16]).into() == 121, '*result[16] == 121');
assert((*y.data[17]).into() == 102, '*result[17] == 102');
}
} |
use core::debug::{PrintTrait};
use core::array::ArrayTrait;
use core::array::SpanTrait;
use core::traits::Into;
use orion::numbers::fixed_point::core::{FixedTrait};
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::{TensorTrait, Tensor}; |
fn quantize_linear() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(6);
let mut data = ArrayTrait::<i32>::new();
data.append(0);
data.append(2);
data.append(3);
data.append(1000);
data.append(-254);
data.append(-1000);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(2);
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(1);
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 1, '*result[0] == 1');
assert((*y.data[1]).into() == 2, '*result[1] == 2');
assert((*y.data[2]).into() == 2, '*result[2] == 2');
assert((*y.data[3]).into() == 127, '*result[3] == 127');
assert((*y.data[4]).into() == -126, '*result[4] == -126');
assert((*y.data[5]).into() == -127, '*result[5] == -127');
} |
fn per_axis() {
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(3);
shape.append(2);
let mut data = ArrayTrait::<i32>::new();
data.append(-162);
data.append(10);
data.append(-100);
data.append(232);
data.append(-20);
data.append(-50);
data.append(-76);
data.append(0);
data.append(0);
data.append(252);
data.append(32);
data.append(-44);
data.append(245);
data.append(-485);
data.append(-960);
data.append(-270);
data.append(-375);
data.append(-470);
let x = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(2);
data.append(4);
data.append(5);
let y_scale = TensorTrait::new(shape.span(), data.span());
let mut shape = ArrayTrait::<usize>::new();
shape.append(1);
shape.append(3);
shape.append(1);
shape.append(1);
let mut data = ArrayTrait::<i32>::new();
data.append(84);
data.append(24);
data.append(196);
let y_zero_point = TensorTrait::new(shape.span(), data.span());
let y: Tensor<i8> = x.quantize_linear(@y_scale, @y_zero_point);
assert((*y.data[0]).into() == 3, '*result[0] == 3');
assert((*y.data[1]).into() == 89, '*result[1] == 89');
assert((*y.data[2]).into() == 34, '*result[2] == 34');
assert((*y.data[3]).into() == 127, '*result[3] == 127');
assert((*y.data[4]).into() == 74, '*result[4] == 74');
assert((*y.data[5]).into() == 59, '*result[5] == 59');
assert((*y.data[6]).into() == 5, '*result[6] == 5');
assert((*y.data[7]).into() == 24, '*result[7] == 24');
assert((*y.data[8]).into() == 24, '*result[8] == 24');
assert((*y.data[9]).into() == 87, '*result[9] == 87');
assert((*y.data[10]).into() == 32, '*result[10] == 32');
assert((*y.data[11]).into() == 13, '*result[11] = |
= 13');
assert((*y.data[12]).into() == 127, '*result[12] == 127');
assert((*y.data[13]).into() == 99, '*result[13] == 99');
assert((*y.data[14]).into() == 4, '*result[14] == 4');
assert((*y.data[15]).into() == 127, '*result[15] == 127');
assert((*y.data[16]).into() == 121, '*result[16] == 121');
assert((*y.data[17]).into() == 102, '*result[17] == 102');
} |
mod at;
mod flatten;
mod max;
mod min;
mod stride;
mod onehot;
|
mod at_u32_test;
mod at_i32_test;
mod at_fp_test;
mod at_bool_test;
|
mod tensor_1D {
use core::array::ArrayTrait;
use orion::operators::tensor::BoolTensor;
use orion::operators::tensor::core::{TensorTrait}; |
fn tensor_at() {
let mut sizes = ArrayTrait::new();
sizes.append(3);
let mut data = ArrayTrait::new();
data.append(false);
data.append(true);
data.append(false);
let tensor = TensorTrait::<bool>::new(sizes.span(), data.span());
let mut indices = ArrayTrait::new();
indices.append(1);
let result = tensor.at(indices.span());
assert(result == true, 'result[2] = true');
}
}
mod tensor_2D {
use core::array::ArrayTrait;
use orion::operators::tensor::{BoolTensor};
use orion::operators::tensor::core::{TensorTrait}; |
fn tensor_at() {
let mut sizes = ArrayTrait::new();
sizes.append(2);
sizes.append(2);
let mut data = ArrayTrait::new();
data.append(false);
data.append(false);
data.append(false);
data.append(true);
let tensor = TensorTrait::<bool>::new(sizes.span(), data.span());
let mut indices = ArrayTrait::new();
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == true, 'result[4] = true');
}
}
mod tensor_3D {
use core::array::ArrayTrait;
use orion::operators::tensor::{BoolTensor};
use orion::operators::tensor::core::{TensorTrait}; |
fn tensor_at() {
let mut sizes = ArrayTrait::new();
sizes.append(2);
sizes.append(2);
sizes.append(2);
let mut data = ArrayTrait::new();
data.append(false);
data.append(false);
data.append(false);
data.append(true);
data.append(false);
data.append(false);
data.append(false);
data.append(false);
let tensor = TensorTrait::<bool>::new(sizes.span(), data.span());
let mut indices = ArrayTrait::new();
indices.append(0);
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == true, 'result[3] = true');
}
} |
mod at_fp8x23_test;
mod at_fp16x16_test;
|
mod tensor_1D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_1x3_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp16x16::core::{
FP16x16Impl, FP16x16PartialEq
}; |
fn tensor_at() {
let tensor = fp_tensor_1x3_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(1, false), 'result[2] = 1');
}
}
mod tensor_2D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_2x2_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp16x16::core::{
FP16x16Impl, FP16x16PartialEq
}; |
fn tensor_at() {
let tensor = fp_tensor_2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(3, false), 'result[4] = 3');
}
}
mod tensor_3D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_2x2x2_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp16x16::core::{
FP16x16Impl, FP16x16PartialEq
}; |
fn tensor_at() {
let tensor = fp_tensor_2x2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(0);
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(3, false), 'result[3] = 3');
}
} |
mod tensor_1D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_1x3_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23PartialEq}; |
fn tensor_at() {
let tensor = fp_tensor_1x3_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(1, false), 'result[2] = 1');
}
}
mod tensor_2D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_2x2_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23PartialEq}; |
fn tensor_at() {
let tensor = fp_tensor_2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(3, false), 'result[4] = 3');
}
}
mod tensor_3D {
use core::array::ArrayTrait;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_2x2x2_helper;
use orion::numbers::fixed_point::core::FixedTrait;
use orion::numbers::fixed_point::implementations::fp8x23::core::{FP8x23Impl, FP8x23PartialEq}; |
fn tensor_at() {
let tensor = fp_tensor_2x2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(0);
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == FixedTrait::new_unscaled(3, false), 'result[3] = 3');
}
} |
// ===== 1D ===== //
#[cfg(test)]
mod tensor_1D {
use core::array::ArrayTrait;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_1x3_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = i32_tensor_1x3_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 1, 'result[2] = 1');
}
}
// ===== 2D ===== //
#[cfg(test)]
mod tensor_2D {
use core::array::ArrayTrait;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_2x2_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = i32_tensor_2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 3, 'result[4] = 3');
}
}
// ===== 3D ===== //
#[cfg(test)]
mod tensor_3D {
use core::array::ArrayTrait;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_2x2x2_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = i32_tensor_2x2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(0);
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 3, 'result[3] = 3');
}
}
|
// ===== 1D ===== //
#[cfg(test)]
mod tensor_1D {
use core::array::ArrayTrait;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_1x3_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = u32_tensor_1x3_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 1, 'result[2] = 1');
}
}
// ===== 2D ===== //
#[cfg(test)]
mod tensor_2D {
use core::array::ArrayTrait;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_2x2_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = u32_tensor_2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 3, 'result[4] = 3');
}
}
// ===== 3D ===== //
#[cfg(test)]
mod tensor_3D {
use core::array::ArrayTrait;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_2x2x2_helper;
#[test]
#[available_gas(2000000)]
fn tensor_at() {
let tensor = u32_tensor_2x2x2_helper();
let mut indices = ArrayTrait::new();
indices.append(0);
indices.append(1);
indices.append(1);
let result = tensor.at(indices.span());
assert(result == 3, 'result[3] = 3');
}
}
|
mod flatten_i32_test;
mod flatten_u32_test;
mod flatten_fp_test;
|
mod flatten_fp8x23_test;
mod flatten_fp16x16_test;
|
mod tensor_1D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_1x3_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_1x3_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 3, 'result[1] = 3');
}
}
mod tensor_2D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_2x2_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_1() {
let tensor = fp_tensor_2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
}
mod tensor_3D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp16x16::FP16x16Tensor;
use orion::test_helper::tensor::fixed_point::fp16x16::fp_tensor_2x2x2_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 8, 'result[1] = 8');
} |
fn axis_1() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_2() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(2);
assert((*result.shape[0]).into() == 4, 'result[0] = 4');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
} |
mod tensor_1D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_1x3_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_1x3_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 3, 'result[1] = 3');
}
}
mod tensor_2D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_2x2_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_1() {
let tensor = fp_tensor_2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
}
mod tensor_3D {
use core::traits::Into;
use orion::operators::tensor::implementations::tensor_fp8x23::FP8x23Tensor;
use orion::test_helper::tensor::fixed_point::fp8x23::fp_tensor_2x2x2_helper;
use orion::operators::tensor::core::TensorTrait; |
fn axis_0() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 8, 'result[1] = 8');
} |
fn axis_1() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_2() {
let tensor = fp_tensor_2x2x2_helper();
let result = tensor.flatten(2);
assert((*result.shape[0]).into() == 4, 'result[0] = 4');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
} |
mod tensor_1D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_1x3_helper; |
fn axis_0() {
let tensor = i32_tensor_1x3_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 3, 'result[1] = 3');
}
}
mod tensor_2D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_2x2_helper; |
fn axis_0() {
let tensor = i32_tensor_2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_1() {
let tensor = i32_tensor_2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
}
mod tensor_3D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::I32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::i32::i32_tensor_2x2x2_helper; |
fn axis_0() {
let tensor = i32_tensor_2x2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 8, 'result[1] = 8');
} |
fn axis_1() {
let tensor = i32_tensor_2x2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_2() {
let tensor = i32_tensor_2x2x2_helper();
let result = tensor.flatten(2);
assert((*result.shape[0]).into() == 4, 'result[0] = 4');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
} |
mod tensor_1D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_1x3_helper; |
fn axis_0() {
let tensor = u32_tensor_1x3_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 3, 'result[1] = 3');
}
}
mod tensor_2D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_2x2_helper; |
fn axis_0() {
let tensor = u32_tensor_2x2_helper();
let result = tensor.flatten(0);
assert((*result.shape[0]).into() == 1, 'result[0] = 1');
assert((*result.shape[1]).into() == 4, 'result[1] = 4');
} |
fn axis_1() {
let tensor = u32_tensor_2x2_helper();
let result = tensor.flatten(1);
assert((*result.shape[0]).into() == 2, 'result[0] = 2');
assert((*result.shape[1]).into() == 2, 'result[1] = 2');
}
}
mod tensor_3D {
use core::array::{ArrayTrait, SpanTrait};
use core::traits::Into;
use orion::operators::tensor::U32Tensor;
use orion::operators::tensor::core::{TensorTrait};
use orion::test_helper::tensor::u32::u32_tensor_2x2x2_helper; |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.