-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from chachaleo/transpose2D
addition transpose 2D
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ mod tensor_core; | |
mod nodes; | ||
mod helpers; | ||
mod ml; | ||
mod operators; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod transpose_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use array::{ArrayTrait, SpanTrait}; | ||
use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; | ||
use 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_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'); | ||
} | ||
|