Skip to content

Commit

Permalink
Merge pull request #524 from hakymulla/compress
Browse files Browse the repository at this point in the history
Compress
  • Loading branch information
raphaelDkhn authored Jan 8, 2024
2 parents ea853a9 + f504b86 commit 6fb2d91
Show file tree
Hide file tree
Showing 97 changed files with 3,654 additions and 9 deletions.
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

0 comments on commit 6fb2d91

Please sign in to comment.