Struct TypedTensor
pub struct TypedTensor<T, R = DynRank>where
R: TensorRank,{ /* private fields */ }Expand description
Runtime typed tensor storage with compile-time scalar type and rank metadata.
Owned tensors are compact column-major. Arbitrary strides and metadata-only
layout changes are represented by TypedTensorView and
[TypedTensorViewMut]. The buffer may be host-backed or backend-backed;
host-inspection methods do not download backend buffers implicitly.
§Examples
use tenferro_tensor::{Rank, Tensor, TypedTensor};
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 2], vec![1.0, 2.0, 3.0, 4.0]).unwrap();
assert_eq!(t.shape(), &[2, 2]);
let static_rank = TypedTensor::<f64, Rank<2>>::from_vec_col_major([2, 2], vec![1.0; 4]).unwrap();
assert_eq!(static_rank.rank(), 2);
let dynamic = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64; 4]).unwrap();
assert_eq!(dynamic.shape(), &[2, 2]);The R parameter stores rank metadata. It defaults to dynamic rank
(DynRank); use Rank<N> for compile-time rank validation.
The dtype-erased Tensor enum remains dynamic-rank.
Implementations§
§impl<T, R> TypedTensor<T, R>where
T: TensorScalar,
R: TensorRank,
impl<T, R> TypedTensor<T, R>where
T: TensorScalar,
R: TensorRank,
pub fn iter(&self) -> Result<Iter<'_, T>, Error>
pub fn iter(&self) -> Result<Iter<'_, T>, Error>
Iterate over the contiguous column-major host buffer.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
let sum: f64 = t.iter()?.copied().sum();
assert_eq!(sum, 3.0);§Errors
Returns [crate::Error::RuntimeState] when the tensor is backed by a
device buffer and has not been downloaded to host memory.
pub fn iter_mut(&mut self) -> Result<IterMut<'_, T>, Error>
pub fn iter_mut(&mut self) -> Result<IterMut<'_, T>, Error>
Mutably iterate over the contiguous column-major host buffer.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
for value in t.iter_mut()? {
*value *= 2.0;
}
assert_eq!(t.as_slice()?, &[2.0, 4.0]);§Errors
Returns [crate::Error::RuntimeState] when the tensor is backed by a
device buffer and has not been downloaded to host memory.
pub fn linear_offset2(&self, i: usize, j: usize) -> Result<usize, Error>
pub fn linear_offset2(&self, i: usize, j: usize) -> Result<usize, Error>
Compute the linear physical-buffer offset for a rank-2 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![0.0; 6]).unwrap();
assert_eq!(t.linear_offset2(1, 2)?, 5);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not two, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i or j is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows.
pub fn linear_offset3(
&self,
i: usize,
j: usize,
k: usize,
) -> Result<usize, Error>
pub fn linear_offset3( &self, i: usize, j: usize, k: usize, ) -> Result<usize, Error>
Compute the linear physical-buffer offset for a rank-3 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 3, 2], vec![0.0; 12]).unwrap();
assert_eq!(t.linear_offset3(1, 2, 1)?, 11);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not three, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i, j, or k is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows.
pub fn get2(&self, i: usize, j: usize) -> Result<&T, Error>
pub fn get2(&self, i: usize, j: usize) -> Result<&T, Error>
Borrow a single element by rank-2 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 2], vec![1.0, 2.0, 3.0, 4.0]).unwrap();
assert_eq!(t.get2(1, 0)?, &2.0);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not two, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i or j is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows. It returns [crate::Error::RuntimeState]
when the tensor is backed by a device buffer, or
[tenferro_tensor_core::ValidationError::InvalidArgument] if the
computed offset is outside the host buffer.
pub fn get3(&self, i: usize, j: usize, k: usize) -> Result<&T, Error>
pub fn get3(&self, i: usize, j: usize, k: usize) -> Result<&T, Error>
Borrow a single element by rank-3 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![1, 1, 2], vec![3.0, 4.0]).unwrap();
assert_eq!(t.get3(0, 0, 1)?, &4.0);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not three, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i, j, or k is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows. It returns [crate::Error::RuntimeState]
when the tensor is backed by a device buffer, or
[tenferro_tensor_core::ValidationError::InvalidArgument] if the
computed offset is outside the host buffer.
pub unsafe fn get_unchecked(&self, indices: &[usize]) -> Result<&T, Error>
pub unsafe fn get_unchecked(&self, indices: &[usize]) -> Result<&T, Error>
Borrow a single element by multi-index without release-mode bounds checks.
Debug builds still validate the rank and bounds.
§Safety
indices must have the same rank as this tensor and every index must
be in bounds.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert_eq!(unsafe { *t.get_unchecked(&[1])? }, 2.0);§Errors
Returns [crate::Error::RuntimeState] when the tensor is backed by a
device buffer and has not been downloaded to host memory.
§Panics
May panic if the unsafe rank/bounds precondition is violated and the checked linear-offset calculation overflows.
pub fn get_mut2(&mut self, i: usize, j: usize) -> Result<&mut T, Error>
pub fn get_mut2(&mut self, i: usize, j: usize) -> Result<&mut T, Error>
Mutably borrow a single element by rank-2 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::from_vec_col_major(vec![2, 2], vec![1.0, 2.0, 3.0, 4.0]).unwrap();
*t.get_mut2(1, 0)? = 5.0;
assert_eq!(t.as_slice()?, &[1.0, 5.0, 3.0, 4.0]);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not two, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i or j is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows. It returns [crate::Error::RuntimeState]
when the tensor is backed by a device buffer, or
[tenferro_tensor_core::ValidationError::InvalidArgument] if the
computed offset is outside the host buffer.
pub fn get_mut3(
&mut self,
i: usize,
j: usize,
k: usize,
) -> Result<&mut T, Error>
pub fn get_mut3( &mut self, i: usize, j: usize, k: usize, ) -> Result<&mut T, Error>
Mutably borrow a single element by rank-3 logical index.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::from_vec_col_major(vec![1, 1, 2], vec![3.0, 4.0]).unwrap();
*t.get_mut3(0, 0, 1)? = 5.0;
assert_eq!(t.as_slice()?, &[3.0, 5.0]);§Errors
Returns [crate::Error::Validation] containing
[tenferro_tensor_core::ValidationError::RankMismatch] when the tensor
rank is not three, [tenferro_tensor_core::ValidationError::InvalidArgument]
when i, j, or k is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when checked
offset arithmetic overflows. It returns [crate::Error::RuntimeState]
when the tensor is backed by a device buffer, or
[tenferro_tensor_core::ValidationError::InvalidArgument] if the
computed offset is outside the host buffer.
pub unsafe fn get_unchecked_mut(
&mut self,
indices: &[usize],
) -> Result<&mut T, Error>
pub unsafe fn get_unchecked_mut( &mut self, indices: &[usize], ) -> Result<&mut T, Error>
Mutably borrow a single element by multi-index without release-mode bounds checks.
Debug builds still validate the rank and bounds.
§Safety
indices must have the same rank as this tensor and every index must
be in bounds.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![1.0]).unwrap();
unsafe {
*t.get_unchecked_mut(&[0])? = 2.0;
}
assert_eq!(t.as_slice()?, &[2.0]);§Errors
Returns [crate::Error::RuntimeState] when the tensor is backed by a
device buffer and has not been downloaded to host memory.
§Panics
May panic if the unsafe rank/bounds precondition is violated and the checked linear-offset calculation overflows.
§impl<T, R> TypedTensor<T, R>where
T: TensorScalar + Zero,
R: TensorRank,
impl<T, R> TypedTensor<T, R>where
T: TensorScalar + Zero,
R: TensorRank,
pub fn zeros(
shape: impl Into<<R as TensorRank>::Shape>,
) -> Result<TypedTensor<T, R>, Error>
pub fn zeros( shape: impl Into<<R as TensorRank>::Shape>, ) -> Result<TypedTensor<T, R>, Error>
Allocate a zero-filled tensor.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2, 3]).unwrap();
assert_eq!(t.n_elements(), 6);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::IntegerOverflow] when shape
product or compact-stride arithmetic overflows.
§impl<T, R> TypedTensor<T, R>
impl<T, R> TypedTensor<T, R>
pub fn ones(
shape: impl Into<<R as TensorRank>::Shape>,
) -> Result<TypedTensor<T, R>, Error>
pub fn ones( shape: impl Into<<R as TensorRank>::Shape>, ) -> Result<TypedTensor<T, R>, Error>
Allocate a one-filled tensor.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::ones(vec![2]).unwrap();
assert_eq!(t.host_data().unwrap(), &[1.0, 1.0]);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::IntegerOverflow] when shape
product or compact-stride arithmetic overflows.
§impl<T, R> TypedTensor<T, R>where
R: TensorRank,
impl<T, R> TypedTensor<T, R>where
R: TensorRank,
pub fn from_buffer_col_major(
shape: impl Into<<R as TensorRank>::Shape>,
buffer: StorageBuffer<T>,
placement: Placement,
) -> Result<TypedTensor<T, R>, Error>
pub fn from_buffer_col_major( shape: impl Into<<R as TensorRank>::Shape>, buffer: StorageBuffer<T>, placement: Placement, ) -> Result<TypedTensor<T, R>, Error>
Create a tensor from an existing buffer and compact column-major layout.
This preserves the owned tensor invariant that layout metadata is compact column-major, including for backend-owned buffers.
§Examples
use tenferro_tensor::{StorageBuffer, Placement, TypedTensor};
let tensor = TypedTensor::<f64>::from_buffer_col_major(
vec![2],
StorageBuffer::Host(vec![1.0, 2.0]),
Placement {
memory_kind: tenferro_tensor::MemoryKind::UnpinnedHost,
device: None,
cpu_affinity: None,
},
)
.unwrap();
assert_eq!(tensor.shape(), &[2]);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::ShapeDataLengthMismatch] when
the shape product differs from the buffer length,
[tenferro_tensor_core::ValidationError::IntegerOverflow] when shape or
stride arithmetic overflows, or
[tenferro_tensor_core::ValidationError::RankMismatch] when a supplied
rank-specific shape cannot be represented.
pub fn try_into_rank<const N: usize>(
self,
) -> Result<TypedTensor<T, Rank<N>>, Error>
pub fn try_into_rank<const N: usize>( self, ) -> Result<TypedTensor<T, Rank<N>>, Error>
Convert this tensor into static rank metadata after validating its rank.
The buffer and placement are preserved. This method changes only the compile-time rank marker on the owned compact column-major tensor.
§Examples
use tenferro_tensor::{Rank, TypedTensor};
let tensor = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![1.0; 6]).unwrap();
let ranked: TypedTensor<f64, Rank<2>> = tensor.try_into_rank::<2>()?;
assert_eq!(ranked.shape(), &[2, 3]);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] when the typed
rank does not match the existing shape,
[tenferro_tensor_core::ValidationError::IntegerOverflow] when compact
strides cannot be computed, or
[tenferro_tensor_core::ValidationError::ViewOutOfBounds] when the
preserved buffer cannot hold the rank-converted layout.
pub fn n_elements(&self) -> usize
pub fn n_elements(&self) -> usize
Number of elements in the tensor.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![0.0; 6]).unwrap();
assert_eq!(t.n_elements(), 6);pub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
Tensor shape.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert_eq!(t.shape(), &[2]);pub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Tensor rank.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![0.0; 6]).unwrap();
assert_eq!(t.rank(), 2);pub fn layout(&self) -> &TensorLayout<R>
pub fn layout(&self) -> &TensorLayout<R>
Tensor layout metadata.
Owned typed tensors are always compact column-major layouts.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 3], vec![0.0; 6]).unwrap();
assert_eq!(t.layout().strides(), &[1, 2]);pub fn buffer(&self) -> &StorageBuffer<T>where
T: 'static,
pub fn buffer(&self) -> &StorageBuffer<T>where
T: 'static,
Return the storage backing this tensor.
This is an explicit storage-inspection API for backend glue and tests.
Host value inspection should prefer TypedTensor::host_data when the
caller requires host storage.
§Panics
Panics only if the typed descriptor and its single group owner are internally inconsistent.
§Examples
use tenferro_tensor::{StorageBuffer, TypedTensor};
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert!(matches!(t.buffer(), StorageBuffer::Host(_)));pub fn allocation_domain(&self) -> Option<AllocationDomainId>where
T: 'static,
pub fn allocation_domain(&self) -> Option<AllocationDomainId>where
T: 'static,
Return the shared-allocation domain carried by the backend buffer.
§Examples
use tenferro_tensor::TypedTensor;
let tensor = TypedTensor::<f32>::from_vec_col_major(vec![1], vec![1.0])?;
assert_eq!(tensor.allocation_domain(), None);pub fn allocation_id(&self) -> Option<AllocationId>where
T: 'static,
pub fn allocation_id(&self) -> Option<AllocationId>where
T: 'static,
Return the stable physical backend allocation identity.
§Examples
use tenferro_tensor::TypedTensor;
let tensor = TypedTensor::<f32>::from_vec_col_major(vec![1], vec![1.0])?;
assert_eq!(tensor.allocation_id(), None);pub fn placement(&self) -> &Placement
pub fn placement(&self) -> &Placement
Return placement metadata for this tensor.
§Examples
use tenferro_tensor::{MemoryKind, TypedTensor};
let t = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![1.0]).unwrap();
assert_eq!(t.placement().memory_kind, MemoryKind::UnpinnedHost);pub fn set_placement(&mut self, placement: Placement)
pub fn set_placement(&mut self, placement: Placement)
Replace placement metadata without changing the storage buffer.
§Examples
use tenferro_tensor::{MemoryKind, Placement, TypedTensor};
let mut t = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![1.0]).unwrap();
t.set_placement(Placement {
memory_kind: MemoryKind::PinnedHost,
device: None,
cpu_affinity: None,
});
assert_eq!(t.placement().memory_kind, MemoryKind::PinnedHost);pub fn set_cpu_affinity(&mut self, cpu_affinity: Option<CpuDomainId>)
pub fn set_cpu_affinity(&mut self, cpu_affinity: Option<CpuDomainId>)
Replace only CPU routing/locality metadata without changing storage.
Device, memory kind, backend allocation domain, and allocation identity remain unchanged.
§Examples
use tenferro_tensor::{CpuDomainId, TypedTensor};
let mut tensor = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![1.0])?;
tensor.set_cpu_affinity(Some(CpuDomainId::new(4)));
assert_eq!(tensor.placement().cpu_affinity, Some(CpuDomainId::new(4)));pub fn as_view(&self) -> TypedTensorView<'_, T, R>where
T: TensorScalar + 'static,
pub fn as_view(&self) -> TypedTensorView<'_, T, R>where
T: TensorScalar + 'static,
Borrow this tensor as a typed view preserving rank and layout metadata.
§Panics
Panics only if the typed descriptor and its single group owner are internally inconsistent.
§Examples
use tenferro_tensor::{Rank, TypedTensor};
let tensor = TypedTensor::<f64, Rank<2>>::from_vec_col_major([2, 2], vec![1.0; 4]).unwrap();
let view = tensor.as_view();
assert_eq!(view.strides(), &[1, 2]);pub fn as_view_mut(&mut self) -> TypedTensorViewMut<'_, T, R>where
T: TensorScalar + 'static,
pub fn as_view_mut(&mut self) -> TypedTensorViewMut<'_, T, R>where
T: TensorScalar + 'static,
Mutably borrow this tensor as a typed view preserving rank and layout metadata.
§Panics
Panics only if the typed descriptor and its single group owner are internally inconsistent.
§Examples
use tenferro_tensor::TypedTensor;
let mut tensor = TypedTensor::<i32>::from_vec_col_major(vec![1], vec![1]).unwrap();
*tensor.as_view_mut().get_mut(&[0]).unwrap() = 2;
assert_eq!(tensor.as_slice().unwrap(), &[2]);pub fn backend_region_view(
&self,
shape: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Result<TypedTensorView<'_, T>, Error>where
T: TensorScalar + 'static,
pub fn backend_region_view(
&self,
shape: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Result<TypedTensorView<'_, T>, Error>where
T: TensorScalar + 'static,
Borrow a read-only strided region view over this tensor’s backend (device) buffer from explicit layout metadata.
This is a metadata-only view: no data is copied or transferred. The
layout’s reachable element span is validated against the backend
buffer’s physical length. Host-backed tensors are rejected with an
explicit backend error; host regions are expressed with
TypedTensorView::from_slice over host storage instead.
§Examples
use tenferro_tensor::TypedTensor;
// Host tensors are rejected: this constructor is for backend buffers.
let host = TypedTensor::<f64>::from_vec_col_major(vec![4], vec![0.0; 4]).unwrap();
let err = host.backend_region_view(vec![2, 2], vec![1, 2], 0).unwrap_err();
assert!(err.to_string().contains("backend"));§Errors
Returns [crate::Error::RuntimeState] when this tensor is host-backed;
backend region views require a backend buffer. It returns
[crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] for incompatible
shape/stride ranks, [tenferro_tensor_core::ValidationError::ViewOutOfBounds]
when the region exceeds the backend buffer, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] for layout
arithmetic overflow.
pub fn backend_region_view_mut(
&mut self,
shape: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Result<TypedTensorViewMut<'_, T>, Error>where
T: TensorScalar + 'static,
pub fn backend_region_view_mut(
&mut self,
shape: Vec<usize>,
strides: Vec<isize>,
offset: isize,
) -> Result<TypedTensorViewMut<'_, T>, Error>where
T: TensorScalar + 'static,
Borrow a mutable strided region view over this tensor’s backend (device) buffer from explicit layout metadata.
This is the mutable counterpart of
TypedTensor::backend_region_view. The layout’s reachable element
span is validated against the backend buffer’s physical length, and
layouts whose logical elements alias the same physical element are
rejected. Host-backed tensors are rejected with an explicit backend
error; mutable host regions must go through
[TypedTensorViewMut::try_multi_slice_mut] or host constructors.
The returned view borrows the tensor’s backend owner exclusively for its lifetime. This keeps write authority tied to the owner; a second mutable region view must be created only after the first borrow ends.
§Examples
use tenferro_tensor::TypedTensor;
// Host tensors are rejected: this constructor is for backend buffers.
let mut host = TypedTensor::<f64>::from_vec_col_major(vec![4], vec![0.0; 4]).unwrap();
let err = host.backend_region_view_mut(vec![2, 2], vec![1, 2], 0).unwrap_err();
assert!(err.to_string().contains("backend"));§Errors
Returns [crate::Error::RuntimeState] when this tensor is host-backed;
mutable backend region views require a backend buffer. It returns
[crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] for incompatible
shape/stride ranks, [tenferro_tensor_core::ValidationError::ViewOutOfBounds]
when the region exceeds the backend buffer,
[tenferro_tensor_core::ValidationError::OverlappingMutableLayout] when
logical elements alias, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] for layout
arithmetic overflow.
pub fn into_layout(self) -> TensorLayout<R>
pub fn into_layout(self) -> TensorLayout<R>
Consume this tensor and return its layout metadata.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert!(t.into_layout().is_compact_col_major().unwrap());pub fn into_parts(self) -> (StorageBuffer<T>, TensorLayout<R>, Placement)where
T: TensorScalar,
pub fn into_parts(self) -> (StorageBuffer<T>, TensorLayout<R>, Placement)where
T: TensorScalar,
Consume this tensor and return its storage, layout, and placement.
§Examples
use tenferro_tensor::{StorageBuffer, TypedTensor};
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
let (buffer, layout, placement) = t.into_parts();
assert!(matches!(buffer, StorageBuffer::Host(_)));
assert_eq!(layout.shape(), &[2]);
assert!(placement.device.is_none());§impl<T, R> TypedTensor<T, R>where
T: TensorScalar,
R: TensorRank,
impl<T, R> TypedTensor<T, R>where
T: TensorScalar,
R: TensorRank,
pub fn from_vec_col_major(
shape: impl Into<<R as TensorRank>::Shape>,
data: Vec<T>,
) -> Result<TypedTensor<T, R>, Error>
pub fn from_vec_col_major( shape: impl Into<<R as TensorRank>::Shape>, data: Vec<T>, ) -> Result<TypedTensor<T, R>, Error>
Create a tensor from a column-major buffer.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2, 2], vec![1.0, 2.0, 3.0, 4.0]).unwrap();
assert_eq!(t.get(&[1, 0])?, &2.0);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::ShapeDataLengthMismatch] when
the shape product differs from data.len(), or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when shape
arithmetic overflows.
pub fn duplicate(&self) -> Result<TypedTensor<T, R>, Error>
pub fn duplicate(&self) -> Result<TypedTensor<T, R>, Error>
Make an explicit owning copy of this tensor.
Host storage is copied into a fresh allocation. Backend-owned storage must be duplicated by the active backend, so this generic tensor layer reports that operation as unsupported.
§Errors
Returns [crate::Error::RuntimeState] when host data cannot be
borrowed, or [ValidationError::InvalidArgument] when the new group
cannot be constructed.
pub fn into_vec_col_major(self) -> Result<(Vec<usize>, Vec<T>), Error>
pub fn into_vec_col_major(self) -> Result<(Vec<usize>, Vec<T>), Error>
Consume this tensor and return its owned column-major host buffer.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
let (shape, data) = t.into_vec_col_major().unwrap();
assert_eq!(shape, vec![2]);
assert_eq!(data, vec![1.0, 2.0]);§Errors
Returns [crate::Error::RuntimeState] when this tensor uses backend
storage; download it before exporting a host Vec.
pub fn into_host_vec(self) -> Result<Vec<T>, Error>
pub fn into_host_vec(self) -> Result<Vec<T>, Error>
Consume this tensor and return its owned host data without rebuilding
shape metadata. This is intended for ownership-preserving buffer-pool
handoff; callers that need the shape should use Self::into_vec_col_major.
§Errors
Returns [crate::Error::RuntimeState] when this tensor uses backend
storage.
pub fn host_data(&self) -> Result<&[T], Error>
pub fn host_data(&self) -> Result<&[T], Error>
Borrow the host buffer.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert_eq!(t.host_data()?, &[1.0, 2.0]);§Errors
Returns [crate::Error::RuntimeState] when this tensor uses backend
storage; download it before borrowing host data.
pub fn as_slice(&self) -> Result<&[T], Error>
pub fn as_slice(&self) -> Result<&[T], Error>
View the tensor data as a flat slice.
This is an alias for host_data() for API consistency with
Tensor::as_slice.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert_eq!(t.as_slice()?, &[1.0, 2.0]);§Errors
Returns [crate::Error::RuntimeState] when this tensor uses backend
storage; download it before borrowing it as a host slice.
pub fn host_data_mut(&mut self) -> Result<&mut [T], Error>
pub fn host_data_mut(&mut self) -> Result<&mut [T], Error>
Mutably borrow the host buffer.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::zeros(vec![2]).unwrap();
t.host_data_mut()?[0] = 3.0;
assert_eq!(t.host_data()?, &[3.0, 0.0]);§Errors
Returns [crate::Error::RuntimeState] when this tensor uses backend
storage; download it before mutably borrowing host data.
pub fn linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
pub fn linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
Compute the linear physical-buffer offset for a logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2, 3]).unwrap();
assert_eq!(t.linear_offset(&[1, 2])?, 5);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] when indices
has the wrong rank, [tenferro_tensor_core::ValidationError::InvalidArgument]
when an index is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when offset
arithmetic overflows.
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
Compute the physical element offset for a logical index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2, 3]).unwrap();
assert_eq!(t.layout_linear_offset(&[1, 2])?, 5);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] when indices
has the wrong rank, [tenferro_tensor_core::ValidationError::InvalidArgument]
when an index is outside its axis extent, or
[tenferro_tensor_core::ValidationError::IntegerOverflow] when offset
arithmetic overflows.
pub fn is_col_major_contiguous(&self) -> Result<bool, Error>
pub fn is_col_major_contiguous(&self) -> Result<bool, Error>
Return whether this owned tensor is compact column-major.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2]).unwrap();
assert!(t.is_col_major_contiguous()?);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::IntegerOverflow] when
compactness arithmetic overflows.
pub fn layout_summary(&self) -> String
pub fn layout_summary(&self) -> String
Return a compact string summary of this tensor’s layout metadata.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2]).unwrap();
assert!(t.layout_summary().contains("shape=[2]"));pub fn assert_col_major_contiguous(&self) -> Result<(), Error>
pub fn assert_col_major_contiguous(&self) -> Result<(), Error>
Assert this tensor is compact column-major.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::zeros(vec![2]).unwrap();
t.assert_col_major_contiguous()?;§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::IntegerOverflow] when
compactness arithmetic overflows, or
[tenferro_tensor_core::ValidationError::InvalidArgument] when the
tensor is not compact column-major.
pub fn get(&self, indices: &[usize]) -> Result<&T, Error>
pub fn get(&self, indices: &[usize]) -> Result<&T, Error>
Borrow a single element by multi-index.
§Examples
use tenferro_tensor::TypedTensor;
let t = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0]).unwrap();
assert_eq!(t.get(&[1])?, &2.0);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] when indices
has the wrong rank, [tenferro_tensor_core::ValidationError::InvalidArgument]
when an index is outside its axis extent, or
[tenferro_tensor_core::ValidationError::ViewOutOfBounds] when the
computed offset is outside the host buffer. It returns
[crate::Error::RuntimeState] when the tensor uses backend storage.
pub fn get_mut(&mut self, indices: &[usize]) -> Result<&mut T, Error>
pub fn get_mut(&mut self, indices: &[usize]) -> Result<&mut T, Error>
Mutably borrow a single element by multi-index.
§Examples
use tenferro_tensor::TypedTensor;
let mut t = TypedTensor::<f64>::zeros(vec![1]).unwrap();
*t.get_mut(&[0])? = 7.0;
assert_eq!(t.host_data()?, &[7.0]);§Errors
Returns [crate::Error::Validation] with
[tenferro_tensor_core::ValidationError::RankMismatch] when indices
has the wrong rank, [tenferro_tensor_core::ValidationError::InvalidArgument]
when an index is outside its axis extent, or
[tenferro_tensor_core::ValidationError::ViewOutOfBounds] when the
computed offset is outside the host buffer. It returns
[crate::Error::RuntimeState] when the tensor uses backend storage.
§impl<R> TypedTensor<Complex<f32>, R>where
R: TensorRank,
impl<R> TypedTensor<Complex<f32>, R>where
R: TensorRank,
pub fn as_real_view(&self) -> Result<TypedTensorView<'_, f32>, Error>
pub fn as_real_view(&self) -> Result<TypedTensorView<'_, f32>, Error>
Borrow this tensor as an interleaved f32 view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, or [ValidationError::ViewOutOfBounds] for an
invalid tensor layout.
pub fn as_real_view_mut(&mut self) -> Result<TypedTensorViewMut<'_, f32>, Error>
pub fn as_real_view_mut(&mut self) -> Result<TypedTensorViewMut<'_, f32>, Error>
Borrow this tensor mutably as an interleaved f32 view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, [ValidationError::OverlappingMutableLayout]
for a non-injective layout, or [ValidationError::ViewOutOfBounds] for
invalid representation metadata.
pub fn into_real(
self,
) -> Result<TypedTensor<f32>, ReinterpretError<TypedTensor<Complex<f32>, R>>>
pub fn into_real( self, ) -> Result<TypedTensor<f32>, ReinterpretError<TypedTensor<Complex<f32>, R>>>
Consume this tensor and reinterpret its owner as f32 without copying.
A failed operation returns the unchanged owner through
[ReinterpretError::into_owner].
§Errors
Returns [ReinterpretError::error] containing
[ValidationError::InvalidArgument] or
[ValidationError::ViewOutOfBounds] while retaining the unchanged
owner.
§impl<R> TypedTensor<Complex<f64>, R>where
R: TensorRank,
impl<R> TypedTensor<Complex<f64>, R>where
R: TensorRank,
pub fn as_real_view(&self) -> Result<TypedTensorView<'_, f64>, Error>
pub fn as_real_view(&self) -> Result<TypedTensorView<'_, f64>, Error>
Borrow this tensor as an interleaved f64 view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, or [ValidationError::ViewOutOfBounds] for an
invalid tensor layout.
pub fn as_real_view_mut(&mut self) -> Result<TypedTensorViewMut<'_, f64>, Error>
pub fn as_real_view_mut(&mut self) -> Result<TypedTensorViewMut<'_, f64>, Error>
Borrow this tensor mutably as an interleaved f64 view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, [ValidationError::OverlappingMutableLayout]
for a non-injective layout, or [ValidationError::ViewOutOfBounds] for
invalid representation metadata.
pub fn into_real(
self,
) -> Result<TypedTensor<f64>, ReinterpretError<TypedTensor<Complex<f64>, R>>>
pub fn into_real( self, ) -> Result<TypedTensor<f64>, ReinterpretError<TypedTensor<Complex<f64>, R>>>
Consume this tensor and reinterpret its owner as f64 without copying.
A failed operation returns the unchanged owner through
[ReinterpretError::into_owner].
§Errors
Returns [ReinterpretError::error] containing
[ValidationError::InvalidArgument] or
[ValidationError::ViewOutOfBounds] while retaining the unchanged
owner.
§impl<R> TypedTensor<f32, R>where
R: TensorRank,
impl<R> TypedTensor<f32, R>where
R: TensorRank,
pub fn as_complex_view(
&self,
) -> Result<TypedTensorView<'_, Complex<f32>>, Error>
pub fn as_complex_view( &self, ) -> Result<TypedTensorView<'_, Complex<f32>>, Error>
Borrow this tensor as a complex view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, or [ValidationError::ViewOutOfBounds] for an
invalid tensor layout.
pub fn as_complex_view_mut(
&mut self,
) -> Result<TypedTensorViewMut<'_, Complex<f32>>, Error>
pub fn as_complex_view_mut( &mut self, ) -> Result<TypedTensorViewMut<'_, Complex<f32>>, Error>
Borrow this tensor mutably as a complex view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, [ValidationError::OverlappingMutableLayout]
for a non-injective layout, or [ValidationError::ViewOutOfBounds] for
invalid representation metadata.
pub fn into_complex(
self,
) -> Result<TypedTensor<Complex<f32>>, ReinterpretError<TypedTensor<f32, R>>>
pub fn into_complex( self, ) -> Result<TypedTensor<Complex<f32>>, ReinterpretError<TypedTensor<f32, R>>>
Consume this tensor and reinterpret its owner as Complex32 without copying.
The compact source must have an even physical element count. A failed
operation returns the unchanged owner through
[ReinterpretError::into_owner].
§Errors
Returns [ReinterpretError::error] containing
[ValidationError::InvalidArgument] or
[ValidationError::ViewOutOfBounds] while retaining the unchanged
owner.
§impl<R> TypedTensor<f64, R>where
R: TensorRank,
impl<R> TypedTensor<f64, R>where
R: TensorRank,
pub fn as_complex_view(
&self,
) -> Result<TypedTensorView<'_, Complex<f64>>, Error>
pub fn as_complex_view( &self, ) -> Result<TypedTensorView<'_, Complex<f64>>, Error>
Borrow this tensor as a complex view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, or [ValidationError::ViewOutOfBounds] for an
invalid tensor layout.
pub fn as_complex_view_mut(
&mut self,
) -> Result<TypedTensorViewMut<'_, Complex<f64>>, Error>
pub fn as_complex_view_mut( &mut self, ) -> Result<TypedTensorViewMut<'_, Complex<f64>>, Error>
Borrow this tensor mutably as a complex view without copying.
§Errors
Returns [crate::Error::Unsupported] for backend reinterpretation
that is not supported, [ValidationError::OverlappingMutableLayout]
for a non-injective layout, or [ValidationError::ViewOutOfBounds] for
invalid representation metadata.
pub fn into_complex(
self,
) -> Result<TypedTensor<Complex<f64>>, ReinterpretError<TypedTensor<f64, R>>>
pub fn into_complex( self, ) -> Result<TypedTensor<Complex<f64>>, ReinterpretError<TypedTensor<f64, R>>>
Consume this tensor and reinterpret its owner as Complex64 without copying.
The compact source must have an even physical element count. A failed
operation returns the unchanged owner through
[ReinterpretError::into_owner].
§Errors
Returns [ReinterpretError::error] containing
[ValidationError::InvalidArgument] or
[ValidationError::ViewOutOfBounds] while retaining the unchanged
owner.
Trait Implementations§
§impl<T, R> Debug for TypedTensor<T, R>
impl<T, R> Debug for TypedTensor<T, R>
§impl From<TypedTensor<Complex<f32>>> for Tensor
Wrap a Complex32 TypedTensor into the corresponding Tensor
variant.
impl From<TypedTensor<Complex<f32>>> for Tensor
Wrap a Complex32 TypedTensor into the corresponding Tensor
variant.
§Examples
use num_complex::Complex32;
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(
vec![1],
vec![Complex32::new(1.0, 2.0)],
).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);§impl From<TypedTensor<Complex<f64>>> for Tensor
Wrap a Complex64 TypedTensor into the corresponding Tensor
variant.
impl From<TypedTensor<Complex<f64>>> for Tensor
Wrap a Complex64 TypedTensor into the corresponding Tensor
variant.
§Examples
use num_complex::Complex64;
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(
vec![1],
vec![Complex64::new(1.0, 2.0)],
).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[1]);§impl From<TypedTensor<bool>> for Tensor
Wrap a bool TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<bool>> for Tensor
Wrap a bool TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{DType, Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(vec![2], vec![true, false]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::Bool);
assert_eq!(tensor.shape(), &[2]);§fn from(t: TypedTensor<bool>) -> Tensor
fn from(t: TypedTensor<bool>) -> Tensor
§impl From<TypedTensor<f32>> for Tensor
Wrap an f32 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<f32>> for Tensor
Wrap an f32 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(vec![2], vec![1.0_f32, 2.0]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);§fn from(t: TypedTensor<f32>) -> Tensor
fn from(t: TypedTensor<f32>) -> Tensor
§impl From<TypedTensor<f64>> for Tensor
Wrap an f64 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<f64>> for Tensor
Wrap an f64 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.shape(), &[2]);§fn from(t: TypedTensor<f64>) -> Tensor
fn from(t: TypedTensor<f64>) -> Tensor
§impl From<TypedTensor<i32>> for Tensor
Wrap an i32 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<i32>> for Tensor
Wrap an i32 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{DType, Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(vec![2], vec![1_i32, 2]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::I32);
assert_eq!(tensor.shape(), &[2]);§fn from(t: TypedTensor<i32>) -> Tensor
fn from(t: TypedTensor<i32>) -> Tensor
§impl From<TypedTensor<i64>> for Tensor
Wrap an i64 TypedTensor into the corresponding Tensor variant.
impl From<TypedTensor<i64>> for Tensor
Wrap an i64 TypedTensor into the corresponding Tensor variant.
§Examples
use tenferro_tensor::{DType, Tensor, TypedTensor};
let typed = TypedTensor::from_vec_col_major(vec![2], vec![1_i64, 2]).unwrap();
let tensor: Tensor = typed.into();
assert_eq!(tensor.dtype(), DType::I64);
assert_eq!(tensor.shape(), &[2]);§fn from(t: TypedTensor<i64>) -> Tensor
fn from(t: TypedTensor<i64>) -> Tensor
Source§impl TypedTensorMaskSessionOpsExt for TypedTensor<bool>
impl TypedTensorMaskSessionOpsExt for TypedTensor<bool>
Source§fn where_select<U: TensorScalar>(
&self,
on_true: &TypedTensor<U>,
on_false: &TypedTensor<U>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<U>>
fn where_select<U: TensorScalar>( &self, on_true: &TypedTensor<U>, on_false: &TypedTensor<U>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<U>>
Source§impl<T: TensorScalar> TypedTensorSessionOpsExt<T> for TypedTensor<T>
impl<T: TensorScalar> TypedTensorSessionOpsExt<T> for TypedTensor<T>
Source§fn add(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn add( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn mul(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn mul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn exp(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn exp(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn reduce_sum(
&self,
axes: &[usize],
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn reduce_sum( &self, axes: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn sub(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn sub( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn div(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn div( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn rem(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn rem( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn pow(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn pow( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn maximum(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn maximum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn minimum(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn minimum( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn neg(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn neg(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn abs(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn abs(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn sign(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn sign(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn conj(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn conj(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn log(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn log(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn expm1(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn expm1(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
exp(x) - 1 inside a session. Read moreSource§fn log1p(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn log1p(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
log(1 + x) inside a session. Read moreSource§fn sin(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn sin(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn cos(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn cos(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn tanh(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn tanh(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn sqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn sqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn rsqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
fn rsqrt(&self, session: &mut dyn BackendSession) -> Result<TypedTensor<T>>
Source§fn compare(
&self,
rhs: &TypedTensor<T>,
dir: CompareDir,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<bool>>
fn compare( &self, rhs: &TypedTensor<T>, dir: CompareDir, session: &mut dyn BackendSession, ) -> Result<TypedTensor<bool>>
Source§fn clamp(
&self,
lower: &TypedTensor<T>,
upper: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn clamp( &self, lower: &TypedTensor<T>, upper: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn matmul(
&self,
rhs: &TypedTensor<T>,
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn matmul( &self, rhs: &TypedTensor<T>, session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn reshape(
&self,
shape: &[usize],
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn reshape( &self, shape: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn transpose(
&self,
perm: &[usize],
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn transpose( &self, perm: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Source§fn broadcast_in_dim(
&self,
shape: &[usize],
dims: &[usize],
session: &mut dyn BackendSession,
) -> Result<TypedTensor<T>>
fn broadcast_in_dim( &self, shape: &[usize], dims: &[usize], session: &mut dyn BackendSession, ) -> Result<TypedTensor<T>>
Auto Trait Implementations§
impl<T, R = DynRank> !Freeze for TypedTensor<T, R>
impl<T, R = DynRank> !RefUnwindSafe for TypedTensor<T, R>
impl<T, R = DynRank> !UnwindSafe for TypedTensor<T, R>
impl<T, R> Send for TypedTensor<T, R>
impl<T, R> Sync for TypedTensor<T, R>
impl<T, R> Unpin for TypedTensor<T, R>
impl<T, R> UnsafeUnpin for TypedTensor<T, R>where
<R as TensorRank>::Shape: UnsafeUnpin,
<R as TensorRank>::Strides: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more