-
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 #410 from gizatechxyz/develop
Merge Develop into Main
- Loading branch information
Showing
1,841 changed files
with
5,063 additions
and
3,208 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,20 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "alexandria_data_structures" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=f37d73d#f37d73d8a8248e4d8dc65de3949333e30bda022f" | ||
|
||
[[package]] | ||
name = "cubit" | ||
version = "1.2.0" | ||
source = "git+https://github.com/raphaelDkhn/cubit.git#e6331ebf98c5d5f442a0e5edefe0b367c8e270d9" | ||
|
||
[[package]] | ||
name = "orion" | ||
version = "0.1.2" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
"cubit", | ||
] |
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 |
---|---|---|
@@ -1,17 +1,14 @@ | ||
[package] | ||
name = "orion" | ||
version = "0.1.2" | ||
version = "0.1.5" | ||
description = "ONNX Runtime in Cairo for verifiable ML inference using STARK" | ||
homepage = "https://github.com/gizatechxyz/orion" | ||
|
||
[dependencies] | ||
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "f37d73d" } | ||
cubit = { git = "https://github.com/influenceth/cubit.git" } | ||
cubit = { git = "https://github.com/raphaelDkhn/cubit.git" } | ||
|
||
[scripts] | ||
sierra = "cairo-compile . -r" | ||
docgen = "cd docgen && cargo run" | ||
nodegen = "python3 nodegen/node/__init__.py" | ||
|
||
[workspace] | ||
members = ["tests/"] | ||
nodegen = "python3 nodegen/node/__init__.py" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#tensor.where | ||
|
||
```rust | ||
fn where(self: @Tensor<T>, x: @Tensor<T>, y: @Tensor<T>) -> Tensor<T>; | ||
``` | ||
|
||
Computes a new tensor by selecting values from tensor x (resp. y) at | ||
indices where the condition is 1 (resp. 0). | ||
|
||
## Args | ||
|
||
* `self`(`@Tensor<T>`) - The condition tensor | ||
* `x`(`@Tensor<T>`) - The first input tensor | ||
* `y`(`@Tensor<T>`) - The second input tensor | ||
|
||
## Panics | ||
|
||
* Panics if the shapes are not equal or broadcastable | ||
|
||
## Returns | ||
|
||
Return a new `Tensor<T>` of the same shape as the input with elements | ||
chosen from x or y depending on the condition. | ||
|
||
## Example | ||
|
||
```rust | ||
use array::{ArrayTrait, SpanTrait}; | ||
|
||
use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor}; | ||
|
||
fn where_example() -> Tensor<u32> { | ||
let tensor_cond = TensorTrait::<u32>::new( | ||
shape: array![2, 2].span(), data: array![0, 1, 0, 1].span(), | ||
); | ||
|
||
let tensor_x = TensorTrait::<u32>::new( | ||
shape: array![2, 2].span(), data: array![2, 4, 6, 8].span(), | ||
); | ||
|
||
let tensor_y = TensorTrait::<u32>::new( | ||
shape: array![2, 2].span(), data: array![1, 3, 5, 9].span(), | ||
); | ||
|
||
return tensor_cond.where(@tensor_1, @tensor_2); | ||
} | ||
>>> [1,4,5,8] | ||
``` |
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,207 @@ | ||
import numpy as np | ||
from nodegen.node import RunAll | ||
from ..helpers import make_node, make_test, to_fp, Tensor, Dtype, FixedImpl | ||
|
||
|
||
class Where(RunAll): | ||
|
||
@staticmethod | ||
def where_u32(): | ||
def default(): | ||
cond = np.random.choice([1, 0], (3, 3, 3)).astype(np.uint32) | ||
x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) | ||
y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.U32, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.U32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.U32, y.shape, y.flatten()) | ||
z = Tensor(Dtype.U32, z.shape, z.flatten()) | ||
|
||
name = "where_u32" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
def broadcast(): | ||
cond = np.random.choice([1, 0], (1, 1)).astype(np.uint32) | ||
x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) | ||
y = np.random.randint(0, 6, (1, 2)).astype(np.uint32) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.U32, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.U32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.U32, y.shape, y.flatten()) | ||
z = Tensor(Dtype.U32, z.shape, z.flatten()) | ||
|
||
name = "where_u32_broadcast" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
default() | ||
broadcast() | ||
|
||
@staticmethod | ||
def where_i32(): | ||
def default(): | ||
cond = np.random.choice([1, 0], (3, 3, 3)).astype(np.int32) | ||
x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) | ||
y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int32) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.I32, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.I32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I32, y.shape, y.flatten()) | ||
z = Tensor(Dtype.I32, z.shape, z.flatten()) | ||
|
||
name = "where_i32" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
def broadcast(): | ||
cond = np.random.choice([1, 0], (1, 1)).astype(np.int32) | ||
x = np.random.randint(0, 6, (2, 2)).astype(np.int32) | ||
y = np.random.randint(0, 6, (1, 2)).astype(np.int32) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.I32, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.I32, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I32, y.shape, y.flatten()) | ||
z = Tensor(Dtype.I32, z.shape, z.flatten()) | ||
|
||
name = "where_i32_broadcast" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
default() | ||
broadcast() | ||
|
||
@staticmethod | ||
def where_i8(): | ||
def default(): | ||
cond = np.random.choice([1, 0], (3, 3, 3)).astype(np.int8) | ||
x = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) | ||
y = np.random.randint(0, 6, (3, 3, 3)).astype(np.int8) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.I8, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.I8, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I8, y.shape, y.flatten()) | ||
z = Tensor(Dtype.I8, z.shape, z.flatten()) | ||
|
||
name = "where_i8" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
def broadcast(): | ||
cond = np.random.choice([1, 0], (1, 1)).astype(np.int8) | ||
x = np.random.randint(0, 6, (2, 2)).astype(np.int8) | ||
y = np.random.randint(0, 6, (1, 2)).astype(np.int8) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.I8, cond.shape, cond.flatten()) | ||
x = Tensor(Dtype.I8, x.shape, x.flatten()) | ||
y = Tensor(Dtype.I8, y.shape, y.flatten()) | ||
z = Tensor(Dtype.I8, z.shape, z.flatten()) | ||
|
||
name = "where_i8_broadcast" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
default() | ||
broadcast() | ||
|
||
@staticmethod | ||
def where_fp8x23(): | ||
def default(): | ||
cond = np.random.choice([1, 0], (3, 3, 3)).astype(np.float64) | ||
x = np.random.randint(0, 6, (3, 3, 3)).astype(np.float64) | ||
y = np.random.randint(0, 6, (3, 3, 3)).astype(np.float64) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.FP8x23, cond.shape, to_fp( | ||
cond.flatten(), FixedImpl.FP8x23)) | ||
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 = "where_fp8x23" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
def broadcast(): | ||
cond = np.random.choice([1, 0], (1, 1)).astype(np.float64) | ||
x = np.random.randint(0, 6, (2, 2)).astype(np.float64) | ||
y = np.random.randint(0, 6, (1, 2)).astype(np.float64) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.FP8x23, cond.shape, to_fp( | ||
cond.flatten(), FixedImpl.FP8x23)) | ||
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 = "where_fp8x23_broadcast" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
default() | ||
broadcast() | ||
|
||
@staticmethod | ||
def where_fp16x16(): | ||
def default(): | ||
cond = np.random.choice([1, 0], (3, 3, 3)).astype(np.float64) | ||
x = np.random.randint(0, 6, (3, 3, 3)).astype(np.float64) | ||
y = np.random.randint(0, 6, (3, 3, 3)).astype(np.float64) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.FP16x16, cond.shape, to_fp( | ||
cond.flatten(), FixedImpl.FP16x16)) | ||
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 = "where_fp16x16" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
def broadcast(): | ||
cond = np.random.choice([1, 0], (1, 1)).astype(np.float64) | ||
x = np.random.randint(0, 6, (2, 2)).astype(np.float64) | ||
y = np.random.randint(0, 6, (1, 2)).astype(np.float64) | ||
|
||
z = np.where(cond, x, y).astype(x.dtype) | ||
|
||
cond = Tensor(Dtype.FP16x16, cond.shape, to_fp( | ||
cond.flatten(), FixedImpl.FP16x16)) | ||
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 = "where_fp16x16_broadcast" | ||
make_node([cond, x, y], [z], name) | ||
make_test([cond, x, y], z, "input_0.where(@input_1,@input_2)", name) | ||
|
||
default() | ||
broadcast() |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod operators; | ||
mod numbers; | ||
mod utils; | ||
|
||
mod test_helper; |
Oops, something went wrong.