Comment on page

# Tensor

A Tensor represents a multi-dimensional array of elements.
A `Tensor` represents a multi-dimensional array of elements and is depicted as a struct containing both the tensor's shape and a flattened array of its data. The generic Tensor is defined as follows:
struct Tensor<T> {
shape: Span<usize>,
data: Span<T>
}

### Data types

Orion supports currently these tensor types.
Data type
dtype
32-bit integer (signed)
`Tensor<i32>`
8-bit integer (signed)
`Tensor<i8>`
32-bit integer (unsigned)
`Tensor<u32>`
Fixed point (signed)
`Tensor<FP8x23 | FP16x16 | FP64x64 | FP32x32>`

### TensorTrait

use orion::operators::tensor::TensorTrait;
`TensorTrait` defines the operations that can be performed on a Tensor.
function
description
Returns a new tensor with the given shape and data.
Returns a new tensor with the specified target shape and the same data as the input tensor.
Flattens the input tensor into a 2D tensor.
Generate a tensor with given value and shape.
Returns a new tensor with the axes rearranged according to the given permutation.
Retrieves the value at the specified indices of a Tensor.
Converts a multi-dimensional index to a one-dimensional index.
Converts a one-dimensional index to a multi-dimensional index.
Check if two tensors are equal element-wise.
Check if each element of the first tensor is greater than the corresponding element of the second tensor.
Check if each element of the first tensor is greater than or equal to the corresponding element of the second tensor.
Check if each element of the first tensor is less than the corresponding element of the second tensor.
Check if each element of the first tensor is less than or equal to the corresponding element of the second tensor.
Computes the logical OR of two tensors element-wise.
Computes the logical XOR of two tensors element-wise.
Computes the stride of each dimension in the tensor.
Produces one-hot tensor based on input.
Returns the maximum value in the tensor.
Returns the minimum value in the tensor.
Returns the minimum value in the tensor.
Returns the maximum value in the tensor.
Reduces a tensor by summing its elements along a specified axis.
Returns the index of the maximum value along the specified axis.
Returns the index of the minimum value along the specified axis.
Performs cumulative sum of the input elements along the given axis.
Performs matrix product of two tensors.
Computes the exponential of all elements of the input tensor.
Computes the natural log of all elements of the input tensor.
Computes the absolute value of all elements in the input tensor.
Computes the negation of all elements in the input tensor.
Rounds up the value of each element in the input tensor.
Computes the square root of all elements of the input tensor.
Computes the sine of all elements of the input tensor.
Computes the cosine of all elements of the input tensor.
Computes the arctangent (inverse of tangent) of all elements of the input tensor.
Computes the arcsine (inverse of sine) of all elements of the input tensor.
Computes the arccosine (inverse of cosine) of all elements of the input tensor.
Computes the hyperbolic sine of all elements of the input tensor.
Computes the hyperbolic tangent of all elements of the input tensor.
Computes the hyperbolic cosine of all elements of the input tensor.
Computes the inverse hyperbolic sine of all elements of the input tensor.
Computes the inverse hyperbolic cosine of all elements of the input tensor.
Produces a slice of the input tensor along multiple axes.
Concatenate a list of tensors into a single tensor.
Quantizes a Tensor to i8 using linear quantization.
Dequantizes an i8 Tensor using linear dequantization.
Performs the sum of two quantized i8 Tensors.
Performs the product of two quantized i8 Tensors.
Gather entries of the axis dimension of data.
Produces indices of the elements that are non-zero (in row-major order - by dimension).
Removes dimensions of size 1 from the shape of a tensor.
Inserts single-dimensional entries to the shape of an input tensor.
Calculates the sign of the given input tensor element-wise.
Clip operator limits the given input within an interval.
Computes the logical AND of two tensors element-wise.
Return a Tensor with the same shape and contents as input.
Return elements chosen from x or y depending on condition.
Computes the bitwise AND of two tensors element-wise.
Computes the round value of all elements in the input tensor.
Computes the L1 norm of the input tensor's elements along the provided axes.
Returns the upper or lower triangular part of a tensor or a batch of 2D matrices.
Produces a copy of input data, and updates value to values specified by updates at specific index positions specified by indices.
Computes the sum square of the input tensor's elements along the provided axes.
Computes the L2 norm of the input tensor's elements along the provided axes.

## Arithmetic Operations

`Tensor` implements arithmetic traits. This allows you to perform basic arithmetic operations using the associated operators. (`+`, `-`, `*`, `/` ). Tensors arithmetic operations supports broadcasting.
Two tensors are “broadcastable” if the following rules hold:
• Each tensor has at least one dimension.
• When iterating over the dimension sizes, starting at the trailing dimension, the dimension sizes must either be equal, one of them is 1, or one of them does not exist.

#### Examples

use array::{ArrayTrait, SpanTrait};
// We instantiate two 3D Tensors here.
let tensor_1 = TensorTrait::new(
shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);
let tensor_2 = TensorTrait::new(
shape: array![2, 2, 2].span(), data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);
// We can add two tensors as follows.
return tensor_1 + tensor_2;
}
>>> [[[0,2],[4,6]],[[8,10],[12,14]]]
use array::{ArrayTrait, SpanTrait};
// We instantiate two 3D Tensors here.
let tensor_1 = TensorTrait::new(
shape: array![2, 2, 2].span(),
data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);
let tensor_2 = TensorTrait::new(
shape: array![1, 2, 1].span(),
data: array![10, 100].span(),
);
// We can add two tensors as follows.
return tensor_1 + tensor_2;
}
>>> [[[10,11],[102,103]],[[14,15],[106,107]]]