pub struct DynTensor<B: Backend> { /* private fields */ }Expand description
A dynamic Tensor wrapper that can be sliced.
Implementations§
Source§impl<B: Backend> DynTensor<B>
impl<B: Backend> DynTensor<B>
Sourcepub fn new<const R: usize, K>(tensor: Tensor<B, R, K>) -> Selfwhere
K: BasicOps<B> + 'static,
pub fn new<const R: usize, K>(tensor: Tensor<B, R, K>) -> Selfwhere
K: BasicOps<B> + 'static,
Create a new TensorStub from a tensor.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Get the number of elements in the tensor.
Sourcepub fn size_estimate(&self) -> usize
pub fn size_estimate(&self) -> usize
Returns the size estimate of the tensor in bytes.
This is self.dtype().size() * self.num_elements().
Sourcepub fn downcast_clone<const R: usize, K>(&self) -> Option<Tensor<B, R, K>>where
K: 'static + BasicOps<B>,
pub fn downcast_clone<const R: usize, K>(&self) -> Option<Tensor<B, R, K>>where
K: 'static + BasicOps<B>,
Downcasts the tensor to a specific rank and kind.
§Result
Some(Tensor<B, R, K>): if the params are correct,None: otherwise.
Sourcepub fn unwrap_clone<const R: usize, K>(&self) -> Tensor<B, R, K>where
K: 'static + BasicOps<B>,
pub fn unwrap_clone<const R: usize, K>(&self) -> Tensor<B, R, K>where
K: 'static + BasicOps<B>,
Sourcepub fn slice<const R: usize, S>(self, slices: S) -> Result<Self, DynTensorError>where
S: SliceArg<R>,
pub fn slice<const R: usize, S>(self, slices: S) -> Result<Self, DynTensorError>where
S: SliceArg<R>,
Slice the stub tensor.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
slices: aSliceArg<R>.
§Result
Ok(DynTensor): the sliced tensor.Err(DynTensorError): an error.
Sourcepub fn slice_dyn(self, slices: &[Slice]) -> Result<Self, DynTensorError>
pub fn slice_dyn(self, slices: &[Slice]) -> Result<Self, DynTensorError>
A dynamic version of DynTensor::slice.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
slices: a dynamic slice ofSlice.
§Result
Ok(DynTensor): the sliced tensor.Err(DynTensorError): an error.
Sourcepub fn slice_assign<const R2: usize, S, V>(
self,
slices: S,
values: V,
) -> Result<Self, DynTensorError>
pub fn slice_assign<const R2: usize, S, V>( self, slices: S, values: V, ) -> Result<Self, DynTensorError>
Assign values to a slice.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
slices: aSlicesArg<R2>.values: a coercible value; seeValuesArg.
§Result
Ok(DynTensor): a converted tensor.Err(DynTensorError): an error.
Sourcepub fn slice_assign_dyn<V>(
self,
slices: &[Slice],
values: V,
) -> Result<Self, DynTensorError>where
V: ValuesArg<B>,
pub fn slice_assign_dyn<V>(
self,
slices: &[Slice],
values: V,
) -> Result<Self, DynTensorError>where
V: ValuesArg<B>,
Dynamic slice rank version of DynTensor::slice_assign.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
slices: a dynamic slice ofSlice.values: a coercible value; seeValuesArg.
§Result
Ok(DynTensor): a converted tensor.Err(DynTensorError): an error.
Sourcepub fn flatten(self) -> Result<Self, DynTensorError>
pub fn flatten(self) -> Result<Self, DynTensorError>
Flatten the tensor.
Dispatches via rank_dispatch::dispatch_rank.
§Result
Ok(DynTensor): a flattened (rank=1) tensor.Err(DynTensorError): an error.
Sourcepub fn cast(self, dtype: DType) -> Result<Self, DynTensorError>
pub fn cast(self, dtype: DType) -> Result<Self, DynTensorError>
Cast the tensor.
Auto-converts kind if necessary.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
dtype: the target data type.
§Result
Ok(DynTensor): a converted tensor.Err(DynTensorError): an error.
Sourcepub fn to_device(self, device: &B::Device) -> Result<Self, DynTensorError>
pub fn to_device(self, device: &B::Device) -> Result<Self, DynTensorError>
Move the tensor to the given device.
Moving to the same device is an inexpensive no-op.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
device: the target device.
§Result
Ok(DynTensor<B>): the moved tensor.Err(DynTensorError): an error.
Sourcepub fn from_data(
data: TensorData,
device: &B::Device,
) -> Result<Self, DynTensorError>
pub fn from_data( data: TensorData, device: &B::Device, ) -> Result<Self, DynTensorError>
Convert a TensorData to a DynTensor.
Dispatches via rank_dispatch::dispatch_rank.
§Arguments
data: sourceTensorData.device: the target device.
§Result
Ok(DynTensor<B>): the converted tensor.Err(DynTensorError): an error.
Sourcepub fn into_data(self) -> Result<TensorData, DynTensorError>
pub fn into_data(self) -> Result<TensorData, DynTensorError>
Convert the tensor to a TensorData.
Dispatches via rank_dispatch::dispatch_rank.
§Result
Ok(TensorData): the converted data.Err(DynTensorError): an error.
Sourcepub fn to_data(self) -> Result<TensorData, DynTensorError>
pub fn to_data(self) -> Result<TensorData, DynTensorError>
Convert the tensor to a TensorData.
Dispatches via rank_dispatch::dispatch_rank.
§Result
Ok(TensorData): the converted data.Err(DynTensorError): an error.