-
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 #560 from HappyTomatoo/feat/Window
feat: Implement Window correlation operators:
- Loading branch information
Showing
52 changed files
with
1,693 additions
and
5 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,32 @@ | ||
# tensor.blackman_window | ||
|
||
```rust | ||
fn blackman_window(size: T, periodic: Option<usize>) -> Tensor<T>; | ||
``` | ||
|
||
Generates a Blackman window as described in the paper https://ieeexplore.ieee.org/document/1455106. | ||
|
||
|
||
* `size`(`T`) - A scalar value indicating the length of the window. | ||
* `periodic`(Option<usize>) - If 1, returns a window to be used as periodic function. If 0, return a symmetric window. When 'periodic' is specified, hann computes a window of length size + 1 and returns the first size points. The default value is 1. | ||
|
||
## Returns | ||
|
||
A Blackman window with length: size. The output has the shape: [size]. | ||
|
||
## Examples | ||
|
||
```rust | ||
use core::array::{ArrayTrait, SpanTrait}; | ||
use orion::operators::tensor::FP8x23TensorPartialEq; | ||
use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; | ||
use orion::operators::tensor::{TensorTrait, Tensor}; | ||
use orion::utils::{assert_eq, assert_seq_eq}; | ||
use orion::numbers::{FixedTrait, FP8x23}; | ||
|
||
|
||
fn blackman_window_example() -> Tensor<FP8x23> { | ||
return TensorTrait::blackman_window(FP8x23 { mag: 33554432, sign: false }, Option::Some(0)); // size: 4 | ||
} | ||
>>> [0 0.36 0.36 0] | ||
``` |
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,32 @@ | ||
# tensor.hamming_window | ||
|
||
```rust | ||
fn hamming_window(size: T, periodic: Option<usize>) -> Tensor<T>; | ||
``` | ||
|
||
Generates a Hamming window as described in the paper https://ieeexplore.ieee.org/document/1455106. | ||
|
||
|
||
* `size`(`T`) - A scalar value indicating the length of the window. | ||
* `periodic`(Option<usize>) - If 1, returns a window to be used as periodic function. If 0, return a symmetric window. When 'periodic' is specified, hann computes a window of length size + 1 and returns the first size points. The default value is 1. | ||
|
||
## Returns | ||
|
||
A Hamming window with length: size. The output has the shape: [size]. | ||
|
||
## Examples | ||
|
||
```rust | ||
use core::array::{ArrayTrait, SpanTrait}; | ||
use orion::operators::tensor::FP8x23TensorPartialEq; | ||
use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; | ||
use orion::operators::tensor::{TensorTrait, Tensor}; | ||
use orion::utils::{assert_eq, assert_seq_eq}; | ||
use orion::numbers::{FixedTrait, FP8x23}; | ||
|
||
|
||
fn hamming_window_example() -> Tensor<FP8x23> { | ||
return TensorTrait::hamming_window(FP8x23 { mag: 33554432, sign: false }, Option::Some(0)); // size: 4 | ||
} | ||
>>> [729444 6473817 6473817 729444] | ||
``` |
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,32 @@ | ||
# tensor.hann_window | ||
|
||
```rust | ||
fn hann_window(size: T, periodic: Option<usize>) -> Tensor<T>; | ||
``` | ||
|
||
Generates a Hann window as described in the paper https://ieeexplore.ieee.org/document/1455106. | ||
|
||
|
||
* `size`(`T`) - A scalar value indicating the length of the window. | ||
* `periodic`(Option<usize>) - If 1, returns a window to be used as periodic function. If 0, return a symmetric window. When 'periodic' is specified, hann computes a window of length size + 1 and returns the first size points. The default value is 1. | ||
|
||
## Returns | ||
|
||
A Hann window with length: size. The output has the shape: [size]. | ||
|
||
## Examples | ||
|
||
```rust | ||
use core::array::{ArrayTrait, SpanTrait}; | ||
use orion::operators::tensor::FP8x23TensorPartialEq; | ||
use orion::operators::tensor::{FP8x23Tensor, FP8x23TensorAdd}; | ||
use orion::operators::tensor::{TensorTrait, Tensor}; | ||
use orion::utils::{assert_eq, assert_seq_eq}; | ||
use orion::numbers::{FixedTrait, FP8x23}; | ||
|
||
|
||
fn hann_window_example() -> Tensor<FP8x23> { | ||
return TensorTrait::hann_window(FP8x23 { mag: 33554432, sign: false }, Option::Some(0)); // size: 4 | ||
} | ||
>>> [0 6291455 6291456 0] | ||
``` |
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,33 @@ | ||
# tensor.range | ||
|
||
```rust | ||
fn range(start: T, end: T, step: T) -> Tensor<T>; | ||
``` | ||
|
||
Generate a tensor containing a sequence of numbers that begin at start and extends by increments of delta up to limit (exclusive). | ||
|
||
|
||
* `start`(`T`) - First entry for the range of output values. | ||
* `end`(`T`) - Exclusive upper limit for the range of output values. | ||
* `step `(`T`) - Value to step by. | ||
|
||
## Returns | ||
|
||
A 1-D tensor with same type as the inputs containing generated range of values. | ||
|
||
## Examples | ||
|
||
```rust | ||
use core::array::{ArrayTrait, SpanTrait}; | ||
use orion::operators::tensor::I32TensorPartialEq; | ||
use orion::operators::tensor::{TensorTrait, Tensor}; | ||
use orion::operators::tensor::{I32Tensor, I32TensorAdd}; | ||
use orion::utils::{assert_eq, assert_seq_eq}; | ||
use orion::numbers::NumberTrait; | ||
|
||
|
||
fn range_example() -> Tensor<i32> { | ||
return TensorTrait::range(21,2,-3); | ||
} | ||
>>> [21 18 15 12 9 6 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
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,130 @@ | ||
import numpy as np | ||
from nodegen.node import RunAll | ||
from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait, get_data_statement | ||
|
||
def blackman_window(size, output_datatype=None, periodic=None) -> np.ndarray: # type: ignore | ||
if periodic == 1: | ||
N_1 = size | ||
else: | ||
N_1 = size - 1 | ||
ni = np.arange(size, dtype=output_datatype) | ||
alpha = 0.42 | ||
beta = 0.08 | ||
y = np.cos((ni * (np.float64(np.pi).astype(output_datatype) * 2)) / N_1).astype(output_datatype) * (-0.5) | ||
y += np.cos((ni * (np.float64(np.pi).astype(output_datatype) * 4)) / N_1) * beta | ||
y += alpha | ||
return y.astype(output_datatype) | ||
|
||
class Blackman_window(RunAll): | ||
|
||
@staticmethod | ||
# We test here with fp8x23 implementation. | ||
def fp8x23(): | ||
args = [3] | ||
# x = np.float64(4) | ||
args_str = get_data_statement(to_fp(np.array(args).flatten(), FixedImpl.FP8x23), Dtype.FP8x23) | ||
y = blackman_window(*args, np.float64) | ||
|
||
# Convert the floats values in `y` to fixed points with `to_fp` method: | ||
y = Tensor(Dtype.FP8x23, y.shape, to_fp(y.flatten(), FixedImpl.FP8x23)) | ||
|
||
# Define the name of the generated folder. | ||
name = "blackman_window_fp8x23" | ||
# Invoke `make_test` method to generate corresponding Cairo tests: | ||
make_test( | ||
[], # List of input tensors. | ||
y, # The expected output result. | ||
f"TensorTrait::blackman_window({','.join(args_str)}, Option::Some(0))", # The code signature. | ||
name # The name of the generated folder. | ||
) | ||
|
||
@staticmethod | ||
# We test here with fp16x16 implementation. | ||
def fp16x16(): | ||
print(get_data_statement(to_fp(np.array([np.pi]).flatten(), FixedImpl.FP16x16), Dtype.FP16x16)) | ||
args = [3] | ||
# x = np.float64(4) | ||
args_str = get_data_statement(to_fp(np.array(args).flatten(), FixedImpl.FP16x16), Dtype.FP16x16) | ||
y = blackman_window(*args, np.float16, 1) | ||
# Convert the floats values in `y` to fixed points with `to_fp` method: | ||
y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) | ||
|
||
# Define the name of the generated folder. | ||
name = "blackman_window_fp16x16" | ||
# Invoke `make_test` method to generate corresponding Cairo tests: | ||
make_test( | ||
[], # List of input tensors. | ||
y, # The expected output result. | ||
f"TensorTrait::blackman_window({','.join(args_str)}, Option::Some(1))", # The code signature. | ||
name # The name of the generated folder. | ||
) | ||
|
||
# @staticmethod | ||
# # We test here with i8 implementation. | ||
# def i8(): | ||
# print(get_data_statement(np.array([np.pi]).flatten(), Dtype.I8)) | ||
# args = [5] | ||
# # x = np.float64(4) | ||
# args_str = get_data_statement(np.array(args).flatten(), Dtype.I8) | ||
# y = blackman_window(*args, np.int8) | ||
# print(y) | ||
|
||
# # Convert the floats values in `y` to fixed points with `to_fp` method: | ||
# y = Tensor(Dtype.I8, y.shape, y.flatten()) | ||
|
||
# # Define the name of the generated folder. | ||
# name = "blackman_window_i8" | ||
# # Invoke `make_test` method to generate corresponding Cairo tests: | ||
# make_test( | ||
# [], # List of input tensors. | ||
# y, # The expected output result. | ||
# f"TensorTrait::blackman_window({','.join(args_str)}, Option::Some(1))", # The code signature. | ||
# name # The name of the generated folder. | ||
# ) | ||
|
||
# @staticmethod | ||
# # We test here with i32 implementation. | ||
# def i32(): | ||
# print(get_data_statement(np.array([np.pi]).flatten(), Dtype.I32)) | ||
# args = [4] | ||
# # x = np.float64(4) | ||
# args_str = get_data_statement(np.array(args).flatten(), Dtype.I32) | ||
# y = blackman_window(*args, np.int32) | ||
# print(y) | ||
|
||
# # Convert the floats values in `y` to fixed points with `to_fp` method: | ||
# y = Tensor(Dtype.I32, y.shape, y.flatten()) | ||
|
||
# # Define the name of the generated folder. | ||
# name = "blackman_window_i32" | ||
# # Invoke `make_test` method to generate corresponding Cairo tests: | ||
# make_test( | ||
# [], # List of input tensors. | ||
# y, # The expected output result. | ||
# f"TensorTrait::blackman_window({','.join(args_str)}, Option::Some(0))", # The code signature. | ||
# name # The name of the generated folder. | ||
# ) | ||
|
||
# @staticmethod | ||
# # We test here with u32 implementation. | ||
# def u32(): | ||
# print(get_data_statement(np.array([np.pi]).flatten(), Dtype.U32)) | ||
# args = [4] | ||
# # x = np.float64(4) | ||
# args_str = get_data_statement(np.array(args).flatten(), Dtype.U32) | ||
# y = blackman_window(*args, np.uint32) | ||
# print(y) | ||
|
||
# # Convert the floats values in `y` to fixed points with `to_fp` method: | ||
# y = Tensor(Dtype.U32, y.shape, y.flatten()) | ||
|
||
# # Define the name of the generated folder. | ||
# name = "blackman_window_u32" | ||
# # Invoke `make_test` method to generate corresponding Cairo tests: | ||
# make_test( | ||
# [], # List of input tensors. | ||
# y, # The expected output result. | ||
# f"TensorTrait::blackman_window({','.join(args_str)}, Option::Some(0))", # The code signature. | ||
# name # The name of the generated folder. | ||
# ) | ||
|
Oops, something went wrong.