-
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 #223 from 0xd3bs/feat/add-squeeze
feat: add squeeze
- Loading branch information
Showing
31 changed files
with
631 additions
and
40 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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# tensor.squeeze | ||
|
||
```rust | ||
fn squeeze(self: @Tensor<T>, axes: Option<Span<i32>>) -> Tensor<T>; | ||
``` | ||
|
||
Removes dimensions of size 1 from the shape of a tensor. | ||
|
||
## Args | ||
|
||
* `self`(`@Tensor<T>`) - Tensor of data to calculate non-zero indices. | ||
* `axes`(`Option<Span<i32>>`) - List of integers indicating the dimensions to squeeze. | ||
|
||
## Returns | ||
|
||
A new `Tensor<T>` Reshaped tensor with same data as input. | ||
|
||
## Example | ||
|
||
```rust | ||
use array::{ArrayTrait, SpanTrait}; | ||
|
||
use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; | ||
|
||
fn squeeze_example() -> Tensor<u32> { | ||
let tensor = TensorTrait::<u32>::new( | ||
shape: array![1, 2, 1, 2, 1].span(), | ||
data: array![1, 1, 1, 1].span(), | ||
); | ||
|
||
return tensor.squeeze(axes: Option::None(()); | ||
} | ||
>>> [[1 1] | ||
[1 1]] | ||
``` |
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,84 @@ | ||
import numpy as np | ||
from nodegen.node import RunAll | ||
from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl | ||
|
||
|
||
class Squeeze(RunAll): | ||
@staticmethod | ||
def squeeze_i8(): | ||
def squeeze(): | ||
x = np.ones((1, 2, 1, 2, 1), dtype=np.int8) | ||
y = np.ones((2, 2, 1), dtype=np.int8) | ||
|
||
x = Tensor(Dtype.I8, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I8, y.shape, y.flatten()) | ||
|
||
name = "squeeze_i8" | ||
make_node([x], [y], name) | ||
make_test( | ||
[x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) | ||
squeeze() | ||
|
||
@staticmethod | ||
def squeeze_i32(): | ||
def squeeze(): | ||
x = np.ones((1, 2, 1, 2, 1), dtype=np.int32) | ||
y = np.ones((2, 2, 1), dtype=np.int32) | ||
|
||
x = Tensor(Dtype.I32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I32, y.shape, y.flatten()) | ||
|
||
name = "squeeze_i32" | ||
make_node([x], [y], name) | ||
make_test( | ||
[x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) | ||
squeeze() | ||
|
||
@staticmethod | ||
def squeeze_u32(): | ||
def squeeze(): | ||
x = np.ones((1, 2, 1, 2, 1), dtype=np.uint32) | ||
y = np.ones((2, 2, 1), dtype=np.uint32) | ||
|
||
x = Tensor(Dtype.U32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.U32, y.shape, y.flatten()) | ||
|
||
name = "squeeze_u32" | ||
make_node([x], [y], name) | ||
make_test( | ||
[x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) | ||
squeeze() | ||
|
||
@staticmethod | ||
def squeeze_fP16x16(): | ||
def squeeze(): | ||
x = to_fp(np.random.randint(0, 255, (1, 2, 1, 2, 1) | ||
).astype(np.int64), FixedImpl.FP16x16) | ||
y = to_fp(np.random.randint(0, 255, (2, 2, 1) | ||
).astype(np.int64), FixedImpl.FP16x16) | ||
|
||
x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) | ||
y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) | ||
|
||
name = "squeeze_fP16x16" | ||
make_node([x], [y], name) | ||
make_test( | ||
[x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) | ||
squeeze() | ||
|
||
@staticmethod | ||
def squeeze_fP8x23(): | ||
def squeeze(): | ||
x = to_fp(np.random.randint(0, 255, (1, 2, 1, 2, 1) | ||
).astype(np.int64), FixedImpl.FP8x23) | ||
y = to_fp(np.random.randint(0, 255, (2, 2, 1) | ||
).astype(np.int64), FixedImpl.FP8x23) | ||
|
||
x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) | ||
y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) | ||
|
||
name = "squeeze_fP8x23" | ||
make_node([x], [y], name) | ||
make_test( | ||
[x], y, "input_0.squeeze(Option::Some(array![i32 { mag: 0, sign: false }, i32 { mag: 2, sign: false }].span()))", name) | ||
squeeze() |
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
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
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
Oops, something went wrong.