Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress #524

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2023-12-25

## Added
- Compress Operator.

## [Unreleased] - 2023-12-14

## Added
Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
* [tensor.erf](framework/operators/tensor/tensor.erf.md)
* [tensor.reduce\_log\_sum](framework/operators/tensor/tensor.reduce\_log\_sum.md)
* [tensor.unique](framework/operators/tensor/tensor.unique.md)
* [tensor.compress](framework/operators/tensor/tensor.compress.md)
* [Neural Network](framework/operators/neural-network/README.md)
* [nn.relu](framework/operators/neural-network/nn.relu.md)
* [nn.leaky\_relu](framework/operators/neural-network/nn.leaky\_relu.md)
Expand Down
9 changes: 5 additions & 4 deletions docs/framework/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ You can see below the list of current supported ONNX Operators:
| [IsNaN](operators/tensor/tensor.is\_nan.md) | :white\_check\_mark: |
| [IsInf](operators/tensor/tensor.is\_inf.md) | :white\_check\_mark: |
| [Not](operators/tensor/tensor.not.md) | :white\_check\_mark: |
| [GatherND](operators/tensor/tensor.gather/_nd.md) | :white\_check\_mark: |
| [ReduceLogSum](operators/tensor/tensor.reduce\_log\_sum.md) | :white\_check\_mark: |
| [Erf](operators/tensor/tensor.erf.md) | :white\_check\_mark: |
| [GatherND](operators/tensor/tensor.gather/_nd.md) | :white\_check\_mark: |
| [ReduceLogSum](operators/tensor/tensor.reduce\_log\_sum.md) | :white\_check\_mark: |
| [Erf](operators/tensor/tensor.erf.md) | :white\_check\_mark: |
| [Compress](operators/tensor/tensor.compress.md) | :white\_check\_mark: |

Current Operators support: **96/156 (62%)**
Current Operators support: **97/156 (62%)**
39 changes: 39 additions & 0 deletions docs/framework/operators/tensor/tensor.compress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# tensor.compress

```rust
fn compress(self: @Tensor<T>, condition: Tensor<T>, axis: Option<usize>) -> Tensor<T>;
```

Selects slices from an input tensor along a given axis where condition evaluates to True for each axis index. In case axis is not provided, input is flattened before elements are selected.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `condition`(`Tensor<T>`) - Rank 1 tensor of booleans to indicate which slices or data elements to be selected. Its length can be less than the input length along the axis or the flattened input size if axis is not specified. In such cases data slices or elements exceeding the condition length are discarded.
* `axis`(`Option<usize>`) - (Optional) Axis along which to take slices. If not specified, input is flattened before elements being selected. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input).

## Panics

* Panics if condition rank is not equal to 1.

## Returns

A new `Tensor<T>` .
fn compress_example() -> Tensor<u32> {
let tensor = TensorTrait::<u32>::new(
shape: array![3, 2].span(),
data: array![[1, 2], [3, 4], [5, 6]].span(),
);
let condition = TensorTrait::<u32>::new(
shape: array![3].span(),
data: array![0, 1, 1].span(),
);

return tensor.compress(
condition: condition,
axis: Option::Some((0)),
);
}
>>> [[3, 4],
[5, 6]]
```
2 changes: 1 addition & 1 deletion docs/framework/operators/tensor/tensor.gather_nd.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn gather_nd_example() -> Tensor<u32> {

return tensor.gather_nd(
indices: indices,
axis: Option::None((0)),
axis: Option::Some((0)),
);
}
>>> [[0, 1],
Expand Down
Loading