Struct tract_data::prelude::Tensor
source · pub struct Tensor { /* private fields */ }Expand description
Tensor is a concrete tensor in tract.
Implementations§
source§impl Tensor
impl Tensor
sourcepub unsafe fn uninitialized<T: Datum>(shape: &[usize]) -> Result<Tensor>
pub unsafe fn uninitialized<T: Datum>(shape: &[usize]) -> Result<Tensor>
Create an uninitialized tensor (dt as type paramater).
sourcepub unsafe fn uninitialized_dt(dt: DatumType, shape: &[usize]) -> Result<Tensor>
pub unsafe fn uninitialized_dt(dt: DatumType, shape: &[usize]) -> Result<Tensor>
Create an uninitialized tensor (dt as regular parameter).
sourcepub unsafe fn uninitialized_aligned<T: Datum>(
shape: &[usize],
alignment: usize
) -> Result<Tensor>
pub unsafe fn uninitialized_aligned<T: Datum>( shape: &[usize], alignment: usize ) -> Result<Tensor>
Create an uninitialized tensor with a given alignment (in bytes).
sourcepub unsafe fn uninitialized_aligned_dt(
dt: DatumType,
shape: &[usize],
alignment: usize
) -> Result<Tensor>
pub unsafe fn uninitialized_aligned_dt( dt: DatumType, shape: &[usize], alignment: usize ) -> Result<Tensor>
Create an uninitialized tensor with a given alignment (in bytes).
pub fn stack_tensors( axis: usize, tensors: &[impl Borrow<Tensor>] ) -> Result<Tensor>
pub fn clear<T: Datum + Zero + Clone>(&mut self) -> Result<()>
pub fn zero<T: Datum + Zero>(shape: &[usize]) -> Result<Tensor>
pub fn zero_scalar<T: Datum + Zero>() -> Result<Tensor>
pub fn zero_scalar_dt(dt: DatumType) -> Result<Tensor>
pub fn zero_dt(dt: DatumType, shape: &[usize]) -> Result<Tensor>
pub fn fill_t<T: Datum + Clone>(&mut self, value: T) -> Result<()>
pub fn zero_aligned_dt( dt: DatumType, shape: &[usize], alignment: usize ) -> Result<Tensor>
pub fn zero_aligned<T: Datum + Zero>( shape: &[usize], alignment: usize ) -> Result<Tensor>
sourcepub fn from_shape<T: Datum + Copy>(
shape: &[usize],
data: &[T]
) -> Result<Tensor>
pub fn from_shape<T: Datum + Copy>( shape: &[usize], data: &[T] ) -> Result<Tensor>
Create a tensor with a given shape and a slice of elements. The data is copied and aligned to size of T.
sourcepub fn from_shape_align<T: Datum + Copy>(
shape: &[usize],
data: &[T],
align: usize
) -> Result<Tensor>
pub fn from_shape_align<T: Datum + Copy>( shape: &[usize], data: &[T], align: usize ) -> Result<Tensor>
Create a tensor with a given shape and a slice of elements. The data is copied and aligned to given alignment.
sourcepub unsafe fn from_raw<T: Datum>(
shape: &[usize],
content: &[u8]
) -> Result<Tensor>
pub unsafe fn from_raw<T: Datum>( shape: &[usize], content: &[u8] ) -> Result<Tensor>
Create a tensor from raw data.
It copies the data, aligning it to the size of T.
pub unsafe fn from_raw_aligned<T: Datum>( shape: &[usize], content: &[u8], align: usize ) -> Result<Tensor>
pub unsafe fn from_raw_dt( dt: DatumType, shape: &[usize], content: &[u8] ) -> Result<Tensor>
pub unsafe fn from_raw_dt_align( dt: DatumType, shape: &[usize], content: &[u8], align: usize ) -> Result<Tensor>
pub unsafe fn from_slice_align<T: Datum>( content: &[T], align: usize ) -> Result<Tensor>
sourcepub unsafe fn set_shape_unchecked(&mut self, shape: &[usize])
pub unsafe fn set_shape_unchecked(&mut self, shape: &[usize])
Force the tensor shape, no consistency check.
pub fn permute_axes(self, axes: &[usize]) -> Result<Tensor>
pub fn move_axis(self, from: usize, to: usize) -> Result<Tensor>
pub fn collapse_axis_with_next(self, axis: usize) -> Tensor
pub fn split_axis(self, axis: usize, outer_dim: usize) -> Result<Tensor>
sourcepub fn into_shape(self, shape: &[usize]) -> Result<Tensor>
pub fn into_shape(self, shape: &[usize]) -> Result<Tensor>
Reshape the tensor to shape.
pub fn insert_axis(&mut self, axis: usize) -> Result<()>
pub fn remove_axis(&mut self, axis: usize) -> Result<()>
pub fn broadcast_into_rank(self, rank: usize) -> Result<Tensor>
pub fn broadcast_to_rank(&mut self, rank: usize) -> Result<()>
pub fn broadcast_scalar_to_shape(&self, shape: &[usize]) -> Result<Tensor>
pub fn assign_slice( &mut self, range: impl RangeBounds<usize>, src: &Tensor, src_range: impl RangeBounds<usize>, axis: usize ) -> Result<()>
pub unsafe fn assign_slice_unchecked( &mut self, range: impl RangeBounds<usize>, src: &Tensor, src_range: impl RangeBounds<usize>, axis: usize )
sourcepub fn datum_type(&self) -> DatumType
pub fn datum_type(&self) -> DatumType
Get the datum type of the tensor.
sourcepub unsafe fn set_datum_type(&mut self, dt: DatumType)
pub unsafe fn set_datum_type(&mut self, dt: DatumType)
Set the datum type of the tensor.
sourcepub fn dump(&self, force_full: bool) -> Result<String>
pub fn dump(&self, force_full: bool) -> Result<String>
Dump the tensor in a human readable form.
force_full will force the tensor to be dump in full even if it is big.
sourcepub fn close_enough(
&self,
other: &Self,
approx: impl Into<Approximation> + Debug
) -> Result<()>
pub fn close_enough( &self, other: &Self, approx: impl Into<Approximation> + Debug ) -> Result<()>
Compare two tensors, allowing for rounding errors.
sourcepub fn into_array<D: Datum>(self) -> Result<ArrayD<D>>
pub fn into_array<D: Datum>(self) -> Result<ArrayD<D>>
Transform the tensor into a ndarray::Array.
sourcepub unsafe fn into_array_unchecked<D: Datum>(self) -> ArrayD<D>
pub unsafe fn into_array_unchecked<D: Datum>(self) -> ArrayD<D>
Transform the tensor into a ndarray::Array.
sourcepub fn to_array_view<D: Datum>(&self) -> Result<ArrayViewD<'_, D>>
pub fn to_array_view<D: Datum>(&self) -> Result<ArrayViewD<'_, D>>
Transform the data as a ndarray::Array.
sourcepub fn to_array_view_mut<D: Datum>(&mut self) -> Result<ArrayViewMutD<'_, D>>
pub fn to_array_view_mut<D: Datum>(&mut self) -> Result<ArrayViewMutD<'_, D>>
Transform the data as a mutable ndarray::Array.
sourcepub unsafe fn to_array_view_unchecked<D: Datum>(&self) -> ArrayViewD<'_, D>
pub unsafe fn to_array_view_unchecked<D: Datum>(&self) -> ArrayViewD<'_, D>
Transform the data as a ndarray::Array.
sourcepub unsafe fn to_array_view_mut_unchecked<D: Datum>(
&mut self
) -> ArrayViewMutD<'_, D>
pub unsafe fn to_array_view_mut_unchecked<D: Datum>( &mut self ) -> ArrayViewMutD<'_, D>
Transform the data as a mutable ndarray::Array.
sourcepub unsafe fn as_ptr_unchecked<D: Datum>(&self) -> *const D
pub unsafe fn as_ptr_unchecked<D: Datum>(&self) -> *const D
Access the data as a pointer.
sourcepub unsafe fn as_ptr_mut_unchecked<D: Datum>(&mut self) -> *mut D
pub unsafe fn as_ptr_mut_unchecked<D: Datum>(&mut self) -> *mut D
Access the data as a pointer.
sourcepub fn as_ptr_mut<D: Datum>(&mut self) -> Result<*mut D>
pub fn as_ptr_mut<D: Datum>(&mut self) -> Result<*mut D>
Access the data as a mutable pointer.
sourcepub fn as_slice_mut<D: Datum>(&mut self) -> Result<&mut [D]>
pub fn as_slice_mut<D: Datum>(&mut self) -> Result<&mut [D]>
Access the data as a mutable slice.
sourcepub unsafe fn as_slice_unchecked<D: Datum>(&self) -> &[D]
pub unsafe fn as_slice_unchecked<D: Datum>(&self) -> &[D]
Access the data as a slice.
sourcepub unsafe fn as_slice_mut_unchecked<D: Datum>(&mut self) -> &mut [D]
pub unsafe fn as_slice_mut_unchecked<D: Datum>(&mut self) -> &mut [D]
Access the data as a mutable slice.
sourcepub fn to_scalar_tensor(&self) -> Result<Tensor>
pub fn to_scalar_tensor(&self) -> Result<Tensor>
Make the tensor a scalar tensor (assumes it contains a single value).
sourcepub unsafe fn to_scalar_unchecked<D: Datum>(&self) -> &D
pub unsafe fn to_scalar_unchecked<D: Datum>(&self) -> &D
Access the data as a scalar.
sourcepub fn to_scalar_mut<D: Datum>(&mut self) -> Result<&mut D>
pub fn to_scalar_mut<D: Datum>(&mut self) -> Result<&mut D>
Mutable access the data as a scalar.
sourcepub unsafe fn to_scalar_mut_unchecked<D: Datum>(&mut self) -> &mut D
pub unsafe fn to_scalar_mut_unchecked<D: Datum>(&mut self) -> &mut D
Mutable access the data as a scalar.
pub unsafe fn as_bytes(&self) -> &[u8] ⓘ
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn is_uniform(&self) -> bool
pub fn as_uniform(&self) -> Option<Tensor>
pub fn is_zero(&self) -> Result<bool>
sourcepub fn cast_to<D: Datum>(&self) -> Result<Cow<'_, Tensor>>
pub fn cast_to<D: Datum>(&self) -> Result<Cow<'_, Tensor>>
Optionnaly convert data to a tensor for a new DatumType.
sourcepub fn cast_to_dt(&self, dst_dt: DatumType) -> Result<Cow<'_, Tensor>>
pub fn cast_to_dt(&self, dst_dt: DatumType) -> Result<Cow<'_, Tensor>>
Optionnaly convert data to a tensor for a new DatumType.
sourcepub fn cast_to_scalar<D: Datum + Copy>(&self) -> Result<D>
pub fn cast_to_scalar<D: Datum + Copy>(&self) -> Result<D>
Access the data as a scalar, after a cast.
sourcepub fn nth(&self, nth: usize) -> Result<Tensor>
pub fn nth(&self, nth: usize) -> Result<Tensor>
Access the nth element of the tensor, returned as a 0-rank Tensor
pub fn deep_clone(&self) -> Tensor
pub fn slice(&self, axis: usize, start: usize, end: usize) -> Result<Tensor>
pub fn view(&self) -> TensorView<'_>
pub fn view_at_prefix(&self, prefix: &[usize]) -> Result<TensorView<'_>>
pub fn view_offsetting(&self, coords: &[usize]) -> Result<TensorView<'_>>
pub unsafe fn view_offsetting_unchecked( &self, coords: &[usize] ) -> TensorView<'_>
pub fn view_mut(&mut self) -> TensorView<'_>
pub fn view_at_prefix_mut(&mut self, prefix: &[usize]) -> Result<TensorView<'_>>
pub fn view_offsetting_mut( &mut self, coords: &[usize] ) -> Result<TensorView<'_>>
sourcepub fn offset_u8_as_i8(self: &Arc<Self>) -> Arc<Self>
pub fn offset_u8_as_i8(self: &Arc<Self>) -> Arc<Self>
Offsets the tensor as an i8 type if it’s an u8 type, otherwise passes it unchanged.