Skip to content

Commit

Permalink
Merge pull request #413 from Dl-Vv/feat-max
Browse files Browse the repository at this point in the history
Feat: Max
  • Loading branch information
raphaelDkhn authored Oct 31, 2023
2 parents 55a544c + ccf499e commit 9122dfd
Show file tree
Hide file tree
Showing 114 changed files with 3,159 additions and 67 deletions.
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [tensor.at](framework/operators/tensor/tensor.at.md)
* [tensor.min_in_tensor](framework/operators/tensor/tensor.min_in_tensor.md)
* [tensor.min](framework/operators/tensor/tensor.min.md)
* [tensor.max\_in\_tensor](framework/operators/tensor/tensor.max\_in\_tensor.md)
* [tensor.max](framework/operators/tensor/tensor.max.md)
* [tensor.stride](framework/operators/tensor/tensor.stride.md)
* [tensor.ravel\_index](framework/operators/tensor/tensor.ravel\_index.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/framework/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,7 @@ You can see below the list of current supported ONNX Operators:
| [MinInTensor](operators/tensor/tensor.min\_in\_tensor.md) | :white\_check\_mark: |
| [Min](operators/tensor/tensor.min.md) | :white\_check\_mark: |
| [Where](operators/tensor/tensor.where.md) | :white\_check\_mark: |
| [MaxInTensor](operators/tensor/tensor.max\_in\_tensor.md) | :white\_check\_mark: |
| [Max](operators/tensor/tensor.max.md) | :white\_check\_mark: |

Current Operators support: **61/156 (39%)**
2 changes: 2 additions & 0 deletions docs/framework/operators/tensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ use orion::operators::tensor::TensorTrait;
| [`tensor.xor`](tensor.xor.md) | Computes the logical XOR of two tensors element-wise. |
| [`tensor.stride`](tensor.stride.md) | Computes the stride of each dimension in the tensor. |
| [`tensor.onehot`](tensor.onehot.md) | Produces one-hot tensor based on input. |
| [`tensor.max_in_tensor`](tensor.max\_in\_tensor.md) | Returns the maximum value in the tensor. |
| [`tensor.min_in_tensor`](tensor.min\_in\_tensor.md) | Returns the minimum value in the tensor. |
| [`tensor.min`](tensor.min.md) | Returns the minimum value in the tensor. |
| [`tensor.max`](tensor.max.md) | Returns the maximum value in the tensor. |
| [`tensor.reduce_sum`](tensor.reduce\_sum.md) | Reduces a tensor by summing its elements along a specified axis. |
| [`tensor.argmax`](tensor.argmax.md) | Returns the index of the maximum value along the specified axis. |
Expand Down
56 changes: 43 additions & 13 deletions docs/framework/operators/tensor/tensor.max.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,63 @@
# tensor.max

```rust
fn max(self: @Tensor<T>) -> T;
fn max(tensors: Span<Tensor<T>>) -> Tensor<T>;
```

Returns the maximum value in the tensor.
Returns the element-wise maximum values from a list of input tensors
The input tensors must have either:
* Exactly the same shape
* The same number of dimensions and the length of each dimension is either a common length or 1.

## Args

* `self`(`@Tensor<T>`) - The input tensor.
* `tensors`(` Span<Tensor<T>>,`) - Array of the input tensors

## Returns
## Returns

The maximum `T` value in the tensor.
A new `Tensor<T>` containing the element-wise maximum values

Examples
## Panics

* Panics if tensor array is empty
* Panics if the shapes are not equal or broadcastable

## Examples

Case 1: Process tensors with same shape

```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};

fn max_example() -> u32 {
let tensor = TensorTrait::new(
shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);
fn max_example() -> Tensor<u32> {
let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),);
let tensor2 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 3, 1, 2].span(),);
let result = TensorTrait::max(tensors: array![tensor1, tensor2].span());
return result;
}
>>> [0, 3, 2, 3]

result.shape
>>> (2, 2)
```

Case 2: Process tensors with different shapes

// We can call `max` function as follows.
return tensor.max();
```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};

fn max_example() -> Tensor<u32> {
let tensor1 = TensorTrait::new(shape: array![2, 2].span(), data: array![0, 1, 2, 3].span(),);
let tensor2 = TensorTrait::new(shape: array![1, 2].span(), data: array![1, 4].span(),);
let result = TensorTrait::max(tensors: array![tensor1, tensor2].span());
return result;
}
>>> 7
>>> [1, 4, 2, 4]

result.shape
>>> (2, 2)
```
33 changes: 33 additions & 0 deletions docs/framework/operators/tensor/tensor.max_in_tensor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# tensor.max_in_tensor

```rust
fn max_in_tensor(self: @Tensor<T>) -> T;
```

Returns the maximum value in the tensor.

## Args

* `self`(`@Tensor<T>`) - The input tensor.

## Returns

The maximum `T` value in the tensor.

Examples

```rust
use array::{ArrayTrait, SpanTrait};

use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};

fn max_in_tensor_example() -> u32 {
let tensor = TensorTrait::new(
shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);

// We can call `max_in_tensor` function as follows.
return tensor.max_in_tensor();
}
>>> 7
```
Loading

0 comments on commit 9122dfd

Please sign in to comment.