Trait burn::tensor::BasicOps

pub trait BasicOps<B>: TensorKind<B>
where B: Backend,
{ type Elem: Element;
Show 24 methods // Required methods fn empty(shape: Shape, device: &<B as Backend>::Device) -> Self::Primitive; fn shape(tensor: &Self::Primitive) -> Shape; fn reshape(tensor: Self::Primitive, shape: Shape) -> Self::Primitive; fn transpose(tensor: Self::Primitive) -> Self::Primitive; fn swap_dims( tensor: Self::Primitive, dim1: usize, dim2: usize, ) -> Self::Primitive; fn permute(tensor: Self::Primitive, axes: &[usize]) -> Self::Primitive; fn flip(tensor: Self::Primitive, axes: &[usize]) -> Self::Primitive; fn slice(tensor: Self::Primitive, range: &[Range<usize>]) -> Self::Primitive; fn slice_assign( tensor: Self::Primitive, ranges: &[Range<usize>], value: Self::Primitive, ) -> Self::Primitive; fn device(tensor: &Self::Primitive) -> <B as Backend>::Device; fn to_device( tensor: Self::Primitive, device: &<B as Backend>::Device, ) -> Self::Primitive; fn into_data_async( tensor: Self::Primitive, ) -> impl Future<Output = TensorData> + Send; fn from_data( data: TensorData, device: &<B as Backend>::Device, ) -> Self::Primitive; fn repeat_dim( tensor: Self::Primitive, dim: usize, times: usize, ) -> Self::Primitive; fn cat(vectors: Vec<Self::Primitive>, dim: usize) -> Self::Primitive; fn chunk( tensor: Self::Primitive, chunks: usize, dim: usize, ) -> Vec<Self::Primitive>; fn equal( lhs: Self::Primitive, rhs: Self::Primitive, ) -> <B as Backend>::BoolTensorPrimitive; fn not_equal( lhs: Self::Primitive, rhs: Self::Primitive, ) -> <B as Backend>::BoolTensorPrimitive; fn any(tensor: Self::Primitive) -> <B as Backend>::BoolTensorPrimitive; fn any_dim( tensor: Self::Primitive, dim: usize, ) -> <B as Backend>::BoolTensorPrimitive; fn all(tensor: Self::Primitive) -> <B as Backend>::BoolTensorPrimitive; fn all_dim( tensor: Self::Primitive, dim: usize, ) -> <B as Backend>::BoolTensorPrimitive; fn expand(tensor: Self::Primitive, shape: Shape) -> Self::Primitive; // Provided method fn elem_type_name() -> &'static str { ... }
}
Expand description

Trait that list all operations that can be applied on all tensors.

§Warnings

This is an internal trait, use the public API provided by tensor struct.

Required Associated Types§

type Elem: Element

The type of the tensor elements.

Required Methods§

fn empty(shape: Shape, device: &<B as Backend>::Device) -> Self::Primitive

Creates an empty tensor with the given shape.

§Arguments
  • shape - The shape of the tensor.
  • device - The device on which the tensor will be allocated.
§Returns

The empty tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For creating empty tensors, users should prefer the Tensor::empty function, which is more high-level and designed for public use.

fn shape(tensor: &Self::Primitive) -> Shape

Returns the shape of the tensor.

§Arguments
  • tensor - The tensor.
§Returns

The shape of the tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For getting the shape of a tensor, users should prefer the Tensor::shape function, which is more high-level and designed for public use.

fn reshape(tensor: Self::Primitive, shape: Shape) -> Self::Primitive

Reshapes the tensor.

§Arguments
  • tensor - The tensor.
  • shape - The new shape of the tensor.
§Returns

The reshaped tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For reshaping a tensor, users should prefer the Tensor::reshape function, which is more high-level and designed for public use.

fn transpose(tensor: Self::Primitive) -> Self::Primitive

Transposes a tensor.

§Arguments
  • tensor - The tensor to transpose.
§Returns

The transposed tensor.

fn swap_dims( tensor: Self::Primitive, dim1: usize, dim2: usize, ) -> Self::Primitive

Swaps two dimensions of a tensor.

§Arguments
  • tensor - The tensor to swap the dimensions of.
  • dim1 - The first dimension to swap.
  • dim2 - The second dimension to swap.
§Returns

The tensor with the dimensions swapped.

fn permute(tensor: Self::Primitive, axes: &[usize]) -> Self::Primitive

Permutes the dimensions of a tensor.

§Arguments
  • tensor - The tensor to permute the dimensions of.
  • axes - The new order of the dimensions.
§Returns

The tensor with the dimensions permuted.

fn flip(tensor: Self::Primitive, axes: &[usize]) -> Self::Primitive

Flips the tensor along the given axes.

§Arguments
  • tensor - The tensor to flip.
  • axes - The axes to flip the tensor along.
§Returns

The tensor with the axes flipped.

fn slice(tensor: Self::Primitive, range: &[Range<usize>]) -> Self::Primitive

Select tensor elements corresponding for the given ranges.

§Arguments
  • tensor - The tensor.
  • ranges - The ranges of the elements to select.
§Returns

The selected elements.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For selecting elements of a tensor, users should prefer the Tensor::slice function, which is more high-level and designed for public use.

fn slice_assign( tensor: Self::Primitive, ranges: &[Range<usize>], value: Self::Primitive, ) -> Self::Primitive

Assigns the given value to the tensor elements corresponding for the given ranges.

§Arguments
  • tensor - The tensor.
  • ranges - The ranges of the elements to select.
  • value - The value to assign.
§Returns

The tensor with the assigned values.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For assigning values to elements of a tensor, users should prefer the Tensor::slice_assign function, which is more high-level and designed for public use.

fn device(tensor: &Self::Primitive) -> <B as Backend>::Device

Returns the device on which the tensor is allocated.

§Arguments
  • tensor - The tensor.
§Returns

The device on which the tensor is allocated.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For getting the device of a tensor, users should prefer the Tensor::device function, which is more high-level and designed for public use.

fn to_device( tensor: Self::Primitive, device: &<B as Backend>::Device, ) -> Self::Primitive

Moves the tensor to the given device.

§Arguments
  • tensor - The tensor.
  • device - The device on which the tensor will be moved.
§Returns

The tensor on the given device.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For moving a tensor to a device, users should prefer the Tensor::to_device function, which is more high-level and designed for public use.

fn into_data_async( tensor: Self::Primitive, ) -> impl Future<Output = TensorData> + Send

Extracts the data from the tensor asynchronously.

§Arguments
  • tensor - The tensor.
§Returns

The data of the tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For extracting the data of a tensor, users should prefer the Tensor::into_data function, which is more high-level and designed for public use.

fn from_data( data: TensorData, device: &<B as Backend>::Device, ) -> Self::Primitive

Creates a tensor from the given data.

§Arguments
  • data - The data of the tensor.
  • device - The device on which the tensor will be allocated.
§Returns

The tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For creating a tensor from data, users should prefer the Tensor::from_data function, which is more high-level and designed for public use.

fn repeat_dim( tensor: Self::Primitive, dim: usize, times: usize, ) -> Self::Primitive

Repeat the tensor along the given dimension.

§Arguments
  • tensor - The tensor.
  • dim - The dimension along which the tensor will be repeated.
  • times - The number of times the tensor will be repeated.
§Returns

The repeated tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For repeating a tensor, users should prefer the Tensor::repeat_dim function, which is more high-level and designed for public use.

fn cat(vectors: Vec<Self::Primitive>, dim: usize) -> Self::Primitive

Concatenates the given tensors along the given dimension.

§Arguments
  • vectors - The tensors to concatenate.
  • dim - The dimension along which the tensors will be concatenated.
§Returns

The concatenated tensor.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For concatenating tensors, users should prefer the Tensor::cat function, which is more high-level and designed for public use.

fn chunk( tensor: Self::Primitive, chunks: usize, dim: usize, ) -> Vec<Self::Primitive>

Attempts to split the tensor along the given dimension into chunks. May return less chunks than requested if the tensor size is not divisible by the number of chunks.

When the given dimension is evenly divisible by the number of chunks, the chunks will be of equal size. Otherwise all chunks will be of equal size except for the last one.

§Panics

If the dimension is greater than the number of dimensions of the tensor.

§Returns

A vector of tensors.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

To split a tensor, users should prefer the Tensor::chunk function, which is more high-level and designed for public use.

fn equal( lhs: Self::Primitive, rhs: Self::Primitive, ) -> <B as Backend>::BoolTensorPrimitive

Equates the given tensors.

§Arguments
  • lhs - The left hand side tensor.
  • rhs - The right hand side tensor.
§Returns

The tensor of booleans indicating whether the corresponding elements are equal.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For equating tensors, users should prefer the Tensor::equal function, which is more high-level and designed for public use.

fn not_equal( lhs: Self::Primitive, rhs: Self::Primitive, ) -> <B as Backend>::BoolTensorPrimitive

Applies element-wise non-equality comparison between the given tensors.

§Arguments
  • lhs - The left hand side tensor.
  • rhs - The right hand side tensor.
§Returns

The tensor of booleans indicating whether the corresponding elements are equal.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly.

For non-equality comparison of tensors, users should prefer the Tensor::not_equal function, which is more high-level and designed for public use.

fn any(tensor: Self::Primitive) -> <B as Backend>::BoolTensorPrimitive

Tests if any element in the tensor evaluates to True.

§Arguments
  • tensor - The tensor to test.
§Returns

A boolean tensor with a single element, True if any element in the input tensor evaluates to True, False otherwise.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly. Users should prefer the Tensor::any function which is more high-level and designed for public use.

fn any_dim( tensor: Self::Primitive, dim: usize, ) -> <B as Backend>::BoolTensorPrimitive

Tests if any element in the tensor evaluates to True along a given dimension dim.

§Arguments
  • tensor - The tensor to test.
  • dim - The axis along which to test.
§Returns

A boolean tensor with the same size as input tensor, except in the dim axis where the size is 1. Returns True if any element in the input tensor along the given dimension evaluates to True, False otherwise.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly. Users should prefer the Tensor::any_dim function, which is more high-level and designed for public use.

fn all(tensor: Self::Primitive) -> <B as Backend>::BoolTensorPrimitive

Tests if all elements in the tensor evaluate to True.

§Arguments
  • tensor - The tensor to test.
§Returns

A boolean tensor with a single element, True if all elements in the input tensor evaluates to True, False otherwise.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly. Users should prefer the Tensor::all function, which is more high-level and designed for public use.

fn all_dim( tensor: Self::Primitive, dim: usize, ) -> <B as Backend>::BoolTensorPrimitive

Tests if all elements in the tensor evaluate to True along a given dimension dim.

§Arguments
  • tensor - The tensor to test.
§Returns

A boolean tensor with the same size as input tensor, except in the dim axis where the size is 1. Returns True if all elements in the input tensor along the given dimension evaluate to True, False otherwise.

§Remarks

This is a low-level function used internally by the library to call different backend functions with static dispatch. It is not designed for direct usage by users, and not recommended to import or use this function directly. Users should prefer the Tensor::all_dim function, which is more high-level and designed for public use.

fn expand(tensor: Self::Primitive, shape: Shape) -> Self::Primitive

Broadcasts the given tensor to the specified shape.

§Arguments
  • tensor - The tensor to broadcast.
  • shape - The shape to broadcast to.
§Returns

The broadcasted tensor.

Provided Methods§

fn elem_type_name() -> &'static str

Returns the name of the element type.

Object Safety§

This trait is not object safe.

Implementors§

§

impl<B> BasicOps<B> for Bool
where B: Backend,

§

type Elem = bool

§

impl<B> BasicOps<B> for Float
where B: Backend,

§

type Elem = <B as Backend>::FloatElem

§

impl<B> BasicOps<B> for Int
where B: Backend,

§

type Elem = <B as Backend>::IntElem