-
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 #388 from 0x73e/feat/neg
feat: neg operator
- Loading branch information
Showing
31 changed files
with
481 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
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,39 @@ | ||
#tensor.neg | ||
|
||
```rust | ||
fn neg(self: @Tensor<T>) -> Tensor<T>; | ||
``` | ||
|
||
Computes the negation of all elements in the input tensor. | ||
|
||
## Args | ||
|
||
* `self`(`@Tensor<T>`) - The input tensor. | ||
|
||
|
||
## Returns | ||
|
||
A new `Tensor<T>` 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, I32Tensor}; | ||
use orion::numbers::{i32, IntegerTrait}; | ||
|
||
fn neg_example() -> Tensor<i32> { | ||
let tensor = TensorTrait::new( | ||
shape: array![3].span(), | ||
data: array![ | ||
IntegerTrait::new(1, true), IntegerTrait::new(2, true), IntegerTrait::new(3, false) | ||
] | ||
.span(), | ||
); | ||
|
||
return tensor.neg(); | ||
} | ||
>>> [1, 2, -3] | ||
``` |
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,55 @@ | ||
import numpy as np | ||
from nodegen.node import RunAll | ||
from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl | ||
|
||
|
||
class Neg(RunAll): | ||
@staticmethod | ||
def neg_i32(): | ||
x = np.random.randint(-127, 127, (2, 2)).astype(np.int32) | ||
y = np.negative(x) | ||
|
||
x = Tensor(Dtype.I32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I32, y.shape, y.flatten()) | ||
|
||
name = "neg_i32" | ||
make_node([x], [y], name) | ||
make_test([x], y, "input_0.neg()", name) | ||
|
||
@staticmethod | ||
def neg_i8(): | ||
x = np.random.randint(-127, 127, (2, 2)).astype(np.int8) | ||
y = np.negative(x) | ||
|
||
x = Tensor(Dtype.I8, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I8, y.shape, y.flatten()) | ||
|
||
name = "neg_i8" | ||
make_node([x], [y], name) | ||
make_test([x], y, "input_0.neg()", name) | ||
|
||
@staticmethod | ||
def neg_fp8x23(): | ||
x = to_fp(np.random.randint(-127, 127, (2, 2) | ||
).astype(np.int64), FixedImpl.FP8x23) | ||
y = np.negative(x) | ||
|
||
x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) | ||
y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) | ||
|
||
name = "neg_fp8x23" | ||
make_node([x], [y], name) | ||
make_test([x], y, "input_0.neg()", name) | ||
|
||
@staticmethod | ||
def neg_fp16x16(): | ||
x = to_fp(np.random.randint(-127, 127, (2, 2) | ||
).astype(np.int64), FixedImpl.FP16x16) | ||
y = np.negative(x) | ||
|
||
x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) | ||
y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) | ||
|
||
name = "neg_fp16x16" | ||
make_node([x], [y], name) | ||
make_test([x], y, "input_0.neg()", name) |
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
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.