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§
Required Methods§
sourcefn empty<const D: usize>(
shape: Shape<D>,
device: &<B as Backend>::Device
) -> Self::Primitive<D>
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.
sourcefn shape<const D: usize>(tensor: &Self::Primitive<D>) -> Shape<D>
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.
sourcefn reshape<const D1: usize, const D2: usize>(
tensor: Self::Primitive<D1>,
shape: Shape<D2>
) -> Self::Primitive<D2>
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.
sourcefn swap_dims<const D: usize>(
tensor: Self::Primitive<D>,
dim1: usize,
dim2: usize
) -> Self::Primitive<D>
fn swap_dims<const D: usize>( tensor: Self::Primitive<D>, dim1: usize, dim2: usize ) -> Self::Primitive<D>
sourcefn permute<const D: usize>(
tensor: Self::Primitive<D>,
axes: [usize; D]
) -> Self::Primitive<D>
fn permute<const D: usize>( tensor: Self::Primitive<D>, axes: [usize; D] ) -> Self::Primitive<D>
sourcefn slice<const D1: usize, const D2: usize>(
tensor: Self::Primitive<D1>,
range: [Range<usize>; D2]
) -> Self::Primitive<D1>
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.
sourcefn slice_assign<const D1: usize, const D2: usize>(
tensor: Self::Primitive<D1>,
ranges: [Range<usize>; D2],
value: Self::Primitive<D1>
) -> 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>
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.
sourcefn device<const D: usize>(tensor: &Self::Primitive<D>) -> <B as Backend>::Device
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.
sourcefn to_device<const D: usize>(
tensor: Self::Primitive<D>,
device: &<B as Backend>::Device
) -> Self::Primitive<D>
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.
sourcefn into_data<const D: usize>(
tensor: Self::Primitive<D>
) -> Reader<Data<Self::Elem, D>>
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.
sourcefn from_data<const D: usize>(
data: Data<Self::Elem, D>,
device: &<B as Backend>::Device
) -> Self::Primitive<D>
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.
sourcefn repeat<const D: usize>(
tensor: Self::Primitive<D>,
dim: usize,
times: usize
) -> Self::Primitive<D>
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.
sourcefn cat<const D: usize>(
vectors: Vec<Self::Primitive<D>>,
dim: usize
) -> Self::Primitive<D>
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.
sourcefn equal<const D: usize>(
lhs: Self::Primitive<D>,
rhs: Self::Primitive<D>
) -> Tensor<B, D, Bool>
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.
sourcefn not_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>
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.
sourcefn any<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>
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.
sourcefn any_dim<const D: usize>(
tensor: Self::Primitive<D>,
dim: usize
) -> Tensor<B, D, Bool>
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.
sourcefn all<const D: usize>(tensor: Self::Primitive<D>) -> Tensor<B, 1, Bool>
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.
sourcefn all_dim<const D: usize>(
tensor: Self::Primitive<D>,
dim: usize
) -> Tensor<B, D, Bool>
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.
Provided Methods§
sourcefn elem_type_name() -> &'static str
fn elem_type_name() -> &'static str
Returns the name of the element type.