Trait burn::tensor::BasicOps

source ·
pub trait BasicOps<B>: TensorKind<B>
where B: Backend,
{ type Elem: 'static + Copy;
Show 23 methods // Required methods fn empty<const D: usize>( shape: Shape<D>, device: &<B as Backend>::Device ) -> Self::Primitive<D>; fn shape<const D: usize>(tensor: &Self::Primitive<D>) -> Shape<D>; fn reshape<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, shape: Shape<D2> ) -> Self::Primitive<D2>; fn transpose<const D: usize>( tensor: Self::Primitive<D> ) -> Self::Primitive<D>; fn swap_dims<const D: usize>( tensor: Self::Primitive<D>, dim1: usize, dim2: usize ) -> Self::Primitive<D>; fn permute<const D: usize>( tensor: Self::Primitive<D>, axes: [usize; D] ) -> Self::Primitive<D>; fn flip<const D: usize>( tensor: Self::Primitive<D>, axes: &[usize] ) -> Self::Primitive<D>; fn slice<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, range: [Range<usize>; D2] ) -> Self::Primitive<D1>; fn slice_assign<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, ranges: [Range<usize>; D2], value: Self::Primitive<D1> ) -> Self::Primitive<D1>; fn device<const D: usize>( tensor: &Self::Primitive<D> ) -> <B as Backend>::Device; fn to_device<const D: usize>( tensor: Self::Primitive<D>, device: &<B as Backend>::Device ) -> Self::Primitive<D>; fn into_data<const D: usize>( tensor: Self::Primitive<D> ) -> Reader<Data<Self::Elem, D>>; fn from_data<const D: usize>( data: Data<Self::Elem, D>, device: &<B as Backend>::Device ) -> Self::Primitive<D>; fn repeat<const D: usize>( tensor: Self::Primitive<D>, dim: usize, times: usize ) -> Self::Primitive<D>; fn cat<const D: usize>( vectors: Vec<Self::Primitive<D>>, dim: usize ) -> Self::Primitive<D>; fn equal<const D: usize>( lhs: Self::Primitive<D>, rhs: Self::Primitive<D> ) -> Tensor<B, D, Bool>; fn not_equal<const D: usize>( lhs: Self::Primitive<D>, rhs: Self::Primitive<D> ) -> Tensor<B, D, Bool>; fn any<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>; fn any_dim<const D: usize>( tensor: Self::Primitive<D>, dim: usize ) -> Tensor<B, D, Bool>; fn all<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>; fn all_dim<const D: usize>( tensor: Self::Primitive<D>, dim: usize ) -> Tensor<B, D, Bool>; fn expand<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, shape: Shape<D2> ) -> Self::Primitive<D2>; // 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§

source

type Elem: 'static + Copy

The type of the tensor elements.

Required Methods§

source

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

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.

source

fn shape<const D: usize>(tensor: &Self::Primitive<D>) -> Shape<D>

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.

source

fn reshape<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, shape: Shape<D2> ) -> Self::Primitive<D2>

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.

source

fn transpose<const D: usize>(tensor: Self::Primitive<D>) -> Self::Primitive<D>

Transposes a tensor.

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

The transposed tensor.

source

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

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.

source

fn permute<const D: usize>( tensor: Self::Primitive<D>, axes: [usize; D] ) -> Self::Primitive<D>

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.

source

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

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.

source

fn slice<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, range: [Range<usize>; D2] ) -> Self::Primitive<D1>

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.

source

fn slice_assign<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, ranges: [Range<usize>; D2], value: Self::Primitive<D1> ) -> Self::Primitive<D1>

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.

source

fn device<const D: usize>(tensor: &Self::Primitive<D>) -> <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.

source

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

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.

source

fn into_data<const D: usize>( tensor: Self::Primitive<D> ) -> Reader<Data<Self::Elem, D>>

Extracts the data from the tensor.

§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.

source

fn from_data<const D: usize>( data: Data<Self::Elem, D>, device: &<B as Backend>::Device ) -> Self::Primitive<D>

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.

source

fn repeat<const D: usize>( tensor: Self::Primitive<D>, dim: usize, times: usize ) -> Self::Primitive<D>

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 function, which is more high-level and designed for public use.

source

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

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.

source

fn equal<const D: usize>( lhs: Self::Primitive<D>, rhs: Self::Primitive<D> ) -> Tensor<B, D, Bool>

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.

source

fn not_equal<const D: usize>( lhs: Self::Primitive<D>, rhs: Self::Primitive<D> ) -> Tensor<B, D, Bool>

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.

source

fn any<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>

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.

source

fn any_dim<const D: usize>( tensor: Self::Primitive<D>, dim: usize ) -> Tensor<B, D, Bool>

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.

source

fn all<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>

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.

source

fn all_dim<const D: usize>( tensor: Self::Primitive<D>, dim: usize ) -> Tensor<B, D, Bool>

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.

source

fn expand<const D1: usize, const D2: usize>( tensor: Self::Primitive<D1>, shape: Shape<D2> ) -> Self::Primitive<D2>

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§

source

fn elem_type_name() -> &'static str

Returns the name of the element type.

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

type Elem = bool

source§

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

§

type Elem = <B as Backend>::FloatElem

source§

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

§

type Elem = <B as Backend>::IntElem