pub struct TypedTensorView<'a, T, R: TensorRank = DynRank, D: Representation = Dynamic> { /* private fields */ }Expand description
Read-only borrowed view of typed tensor storage with arbitrary strides.
TypedTensorView is the typed representation for layout-only tensor
transformations. It borrows an existing host or backend allocation and
carries a logical shape, strides, and an offset. Slicing, reshaping when
stride-compatible, and transpose_view
update only metadata and do not copy storage.
Materialize through TensorStructural::to_contiguous_read
on the active backend session when a compact owned TypedTensor is
required. Use TypedTensorView::as_slice only when the current view is
contiguous in the requested layout.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 0, &data)?;
assert_eq!(view.get(&[1, 1]), Some(&4));Borrowed typed view of one tensor representation.
The buffer stays concrete on purpose: a generic-associated buffer would make
the projection invariant in 'a, and the borrowed-read surface relies on
TensorRead<'long> shortening to TensorRead<'short>. D therefore marks
which representation produced the view - Host is only ever built from host
slices, with no retained region.
Implementations§
Source§impl<'a, T: 'static, const N: usize, D: Representation> TypedTensorView<'a, T, Rank<N>, D>
impl<'a, T: 'static, const N: usize, D: Representation> TypedTensorView<'a, T, Rank<N>, D>
Sourcepub fn host_col_major_view(&self) -> Result<ColMajorView<'a, T, N>>
pub fn host_col_major_view(&self) -> Result<ColMajorView<'a, T, N>>
Validate and borrow this tensor view as a compact column-major host view.
Nonzero compact offsets are represented by the returned logical slice without copying.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [0_i32, 1, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 1, &data)?;
assert_eq!(view.host_col_major_view()?.as_slice(), &[1, 2, 3, 4]);§Errors
Returns crate::Error::RuntimeState when storage is backend-owned,
or crate::Error::Validation when compact layout, shape arithmetic,
or the logical host range is invalid.
Source§impl<'a, T: 'static> TypedTensorView<'a, T, DynRank>
impl<'a, T: 'static> TypedTensorView<'a, T, DynRank>
Sourcepub fn from_col_major(shape: &[usize], data: &'a [T]) -> Result<Self>
pub fn from_col_major(shape: &[usize], data: &'a [T]) -> Result<Self>
Create a borrowed dynamic-rank view over compact column-major host data.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_col_major(&[2, 2], &data)?;
assert_eq!(view.strides(), &[1, 2]);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when compact
strides or reachable bounds overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
requested shape reaches beyond data.
Sourcepub fn from_slice(
shape: impl AsRef<[usize]>,
strides: impl AsRef<[isize]>,
offset: isize,
data: &'a [T],
) -> Result<Self>
pub fn from_slice( shape: impl AsRef<[usize]>, strides: impl AsRef<[isize]>, offset: isize, data: &'a [T], ) -> Result<Self>
Create a borrowed host view from explicit layout metadata.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![-1], 2, &data)?;
assert_eq!(view.get(&[2]), Some(&1));§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when shape and
strides have different ranks,
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
reachable layout exceeds data, or
tenferro_tensor_core::ValidationError::IntegerOverflow when layout
arithmetic overflows.
Source§impl<'a, T: 'static, R: TensorRank, D: Representation> TypedTensorView<'a, T, R, D>
impl<'a, T: 'static, R: TensorRank, D: Representation> TypedTensorView<'a, T, R, D>
Sourcepub fn from_slice_ranked(
shape: impl Into<R::Shape>,
strides: impl Into<R::Strides>,
offset: isize,
data: &'a [T],
) -> Result<Self>
pub fn from_slice_ranked( shape: impl Into<R::Shape>, strides: impl Into<R::Strides>, offset: isize, data: &'a [T], ) -> Result<Self>
Create a rank-generic borrowed host view from explicit layout metadata.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 0, &data)?;
assert_eq!(view.get(&[1, 1]), Some(&4));§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when the typed
rank does not match shape or strides,
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
reachable layout exceeds data, or
tenferro_tensor_core::ValidationError::IntegerOverflow when layout
arithmetic overflows.
Source§impl<'a, T: 'static, R: TensorRank> TypedTensorView<'a, T, R, Host>
impl<'a, T: 'static, R: TensorRank> TypedTensorView<'a, T, R, Host>
Sourcepub fn from_host_slice(
shape: impl Into<R::Shape>,
strides: impl Into<R::Strides>,
offset: isize,
data: &'a [T],
) -> Result<Self>
pub fn from_host_slice( shape: impl Into<R::Shape>, strides: impl Into<R::Strides>, offset: isize, data: &'a [T], ) -> Result<Self>
Create a representation-marked view over an explicit host layout.
A Host-marked view is only ever built from a host slice, so it carries
no retained region and its host slice needs no runtime check.
§Examples
use tenferro_tensor::{DynRank, Host, TypedTensorView};
let data = [1_i32, 2, 3, 4];
let view: TypedTensorView<'_, i32, DynRank, Host> =
TypedTensorView::from_host_slice(vec![2, 2], vec![1, 2], 0, &data)?;
assert_eq!(view.as_host_slice(), &[1, 2, 3, 4]);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when strides
has a different rank, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds /
tenferro_tensor_core::ValidationError::IntegerOverflow when the
reachable layout leaves data or overflows.
Sourcepub fn as_host_slice(&self) -> &'a [T]
pub fn as_host_slice(&self) -> &'a [T]
Borrow the host elements without a runtime representation check.
§Examples
use tenferro_tensor::{DynRank, Host, TypedTensorView};
let data = [1_i32, 2];
let view: TypedTensorView<'_, i32, DynRank, Host> =
TypedTensorView::from_host_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.as_host_slice(), &[1, 2]);§Panics
Panics only if a Host-marked view was built from non-host storage,
which no constructor in this crate does.
Source§impl<'a, T: 'static, R: TensorRank, D: Representation> TypedTensorView<'a, T, R, D>
impl<'a, T: 'static, R: TensorRank, D: Representation> TypedTensorView<'a, T, R, D>
Sourcepub fn into_tensor_read(self) -> Result<TensorRead<'a>>where
T: TensorScalar,
pub fn into_tensor_read(self) -> Result<TensorRead<'a>>where
T: TensorScalar,
Erase a borrowed view’s rank and dtype for session dispatch without allocating tensor storage or promoting it into an allocation group. Common ranks use the existing inline shape and stride metadata.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [1.0_f64, 2.0];
let view = TypedTensorView::<_, Rank<1>>::from_slice_ranked([2], [1], 0, &data)?;
let read = view.into_tensor_read()?;
assert_eq!(read.as_slice::<f64>()?, &[1.0, 2.0]);§Errors
Returns crate::Error::Validation with
ValidationError::IntegerOverflow for unrepresentable metadata or
ValidationError::ViewOutOfBounds if the layout leaves its allocation.
Sourcepub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
Return the logical shape.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [0_i32; 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.shape(), &[2]);Sourcepub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Return the logical rank carried by this view.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [0_i32; 6];
let view = TypedTensorView::from_slice(vec![2, 3], vec![1, 2], 0, &data)?;
assert_eq!(view.rank(), 2);Sourcepub fn strides(&self) -> &[isize]
pub fn strides(&self) -> &[isize]
Return strides in element units.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [0_i32; 2];
let view = TypedTensorView::from_slice(vec![2], vec![-1], 1, &data)?;
assert_eq!(view.strides(), &[-1]);Sourcepub fn offset(&self) -> isize
pub fn offset(&self) -> isize
Return the physical element offset.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![1], vec![1], 1, &data)?;
assert_eq!(view.offset(), 1);Sourcepub fn host_storage(&self) -> Result<&'a [T]>
pub fn host_storage(&self) -> Result<&'a [T]>
Return the borrowed host storage backing this view.
This exposes the entire backing host allocation, not just the logical
slice covered by this view. Use TypedTensorView::as_slice when the
caller needs the contiguous logical region instead.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.host_storage()?, &[1, 2]);§Errors
Returns crate::Error::RuntimeState when this view wraps a backend
buffer; backend storage must be downloaded before host inspection.
Sourcepub fn n_elements(&self) -> usize
pub fn n_elements(&self) -> usize
Return the number of logical elements in this view.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [0_i32; 6];
let view = TypedTensorView::from_slice(vec![2, 3], vec![1, 2], 0, &data)?;
assert_eq!(view.n_elements(), 6);Sourcepub fn layout(&self) -> &TensorLayout<R>
pub fn layout(&self) -> &TensorLayout<R>
Return layout metadata for this view.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert!(view.layout().is_compact_col_major().unwrap());Sourcepub fn placement(&self) -> &Placement
pub fn placement(&self) -> &Placement
Return placement metadata for this view.
§Examples
use tenferro_tensor::{MemoryKind, TypedTensorView};
let data = [1_i32];
let view = TypedTensorView::from_slice(vec![1], vec![1], 0, &data)?;
assert_eq!(view.placement().memory_kind, MemoryKind::UnpinnedHost);Sourcepub fn linear_offset(&self, indices: &[usize]) -> Option<usize>
pub fn linear_offset(&self, indices: &[usize]) -> Option<usize>
Compute the physical element offset for a logical index.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![-1], 2, &data)?;
assert_eq!(view.linear_offset(&[2]), Some(0));Sourcepub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
Compute the physical element offset for a logical index, returning a typed error.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice([3], [-1], 2, &data)?;
assert_eq!(view.layout_linear_offset(&[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::IntegerOverflow when offset
arithmetic overflows.
Sourcepub fn is_col_major_contiguous(&self) -> Result<bool>
pub fn is_col_major_contiguous(&self) -> Result<bool>
Return whether this view is compact column-major.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
assert!(view.is_col_major_contiguous()?);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow if compactness
arithmetic overflows.
Sourcepub fn layout_summary(&self) -> String
pub fn layout_summary(&self) -> String
Return a compact string summary of this view’s layout metadata.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
assert!(view.layout_summary().contains("shape=[2]"));Sourcepub fn assert_col_major_contiguous(&self) -> Result<()>
pub fn assert_col_major_contiguous(&self) -> Result<()>
Assert this view is compact column-major.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
view.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
view is not compact column-major.
Sourcepub fn get(&self, indices: &[usize]) -> Option<&T>
pub fn get(&self, indices: &[usize]) -> Option<&T>
Borrow one host element by logical index.
Returns None for out-of-bounds indices and backend buffers.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.get(&[1]), Some(&2));Sourcepub fn as_slice(&self) -> Result<&'a [T]>
pub fn as_slice(&self) -> Result<&'a [T]>
Borrow the contiguous host slice covered by this view.
Returns an explicit error for backend buffers and for non-contiguous layouts. This method never downloads or materializes backend data.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![2], vec![1], 1, &data)?;
assert_eq!(view.as_slice()?, &[2, 3]);§Errors
Returns crate::Error::RuntimeState when this view wraps a backend
buffer, tenferro_tensor_core::ValidationError::NonContiguousViewAsSlice
when the layout is not compact column-major,
tenferro_tensor_core::ValidationError::InvalidArgument when the view
offset is negative, or crate::Error::Validation with
tenferro_tensor_core::ValidationError::ViewOutOfBounds or
tenferro_tensor_core::ValidationError::IntegerOverflow when the
requested host range is invalid.
Sourcepub fn duplicate(&self) -> Result<TypedTensor<T, R>>where
T: Clone,
pub fn duplicate(&self) -> Result<TypedTensor<T, R>>where
T: Clone,
Explicitly duplicate a compact host view into a new owner.
Backend views require an explicit provider canonicalization or download boundary; this method never transfers or materializes them implicitly.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
let copy = view.duplicate()?;
assert_eq!(copy.as_slice()?, &[1, 2]);§Errors
Returns crate::Error::HostAccess or
ValidationError::NonContiguousViewAsSlice when the view is backend
owned or not contiguous, and ValidationError::InvalidArgument when
the static-rank shape cannot be reconstructed.
Sourcepub fn to_col_major(&self) -> Result<TypedTensor<T, R>>where
T: Clone,
pub fn to_col_major(&self) -> Result<TypedTensor<T, R>>where
T: Clone,
Explicitly copy a host view, including strided/offset views, to a compact owner.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let storage = [1, 4, 2, 5, 3, 6];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked(
[2, 3], [1, 2], 0, &storage,
)?;
let transposed = view.transpose_view([1, 0])?;
assert_eq!(transposed.to_col_major()?.as_slice()?, &[1, 2, 3, 4, 5, 6]);§Errors
Backend-only storage returns crate::Error::RuntimeState; invalid
layout or rank conversion returns crate::Error::Validation.
Sourcepub fn transpose_view(&self, axes: impl AsRef<[usize]>) -> Result<Self>
pub fn transpose_view(&self, axes: impl AsRef<[usize]>) -> Result<Self>
Return a metadata-only axis permutation.
§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [1_i32, 2, 3, 4, 5, 6];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 3], [1, 2], 0, &data)?;
let transposed = view.transpose_view([1, 0])?;
assert_eq!(transposed.shape(), &[3, 2]);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::InvalidPermutationLength,
tenferro_tensor_core::ValidationError::AxisOutOfBounds, or
tenferro_tensor_core::ValidationError::DuplicateAxis when axes is
not a valid permutation of the view rank.
Sourcepub fn slice_view(&self, slices: &[StridedSliceSpec]) -> Result<Self>
pub fn slice_view(&self, slices: &[StridedSliceSpec]) -> Result<Self>
Return a metadata-only slice using one StridedSliceSpec per axis.
§Examples
use tenferro_tensor::{StridedSliceSpec, TypedTensorView};
let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![1], 0, &data)?;
let reversed = view.slice_view(&[StridedSliceSpec::reverse()])?;
assert_eq!(reversed.get(&[0]), Some(&3));§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when the slice
count differs from the view rank,
tenferro_tensor_core::ValidationError::InvalidSliceStep or
tenferro_tensor_core::ValidationError::InvalidSliceBounds for an
invalid slice, tenferro_tensor_core::ValidationError::IntegerOverflow
for slice arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
resulting layout exceeds the backing buffer.
Sourcepub fn slice_axis_view(
&self,
axis: usize,
slice: StridedSliceSpec,
) -> Result<Self>
pub fn slice_axis_view( &self, axis: usize, slice: StridedSliceSpec, ) -> Result<Self>
Return a metadata-only slice along one axis.
§Examples
use tenferro_tensor::{StridedSliceSpec, TypedTensorView};
let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_slice(vec![2, 2], vec![1, 2], 0, &data)?;
assert_eq!(view.slice_axis_view(1, StridedSliceSpec::reverse())?.get(&[0, 0]), Some(&3));§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::AxisOutOfBounds when axis
is outside the view rank, tenferro_tensor_core::ValidationError::InvalidSliceStep
or tenferro_tensor_core::ValidationError::InvalidSliceBounds for an
invalid slice, tenferro_tensor_core::ValidationError::IntegerOverflow
for slice arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
resulting layout exceeds the backing buffer.
Sourcepub fn reshape_view(
&self,
shape: &[usize],
) -> Result<TypedTensorView<'a, T, DynRank, D>>
pub fn reshape_view( &self, shape: &[usize], ) -> Result<TypedTensorView<'a, T, DynRank, D>>
Return a metadata-only dynamic-rank reshape for contiguous column-major views.
§Examples
use tenferro_tensor::TypedTensorView;
let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_slice(vec![2, 2], vec![1, 2], 0, &data)?;
assert_eq!(view.reshape_view(&[4])?.shape(), &[4]);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::NonContiguousViewAsSlice when
the source is not compact column-major,
tenferro_tensor_core::ValidationError::ShapeMismatch (whose
tenferro_tensor_core::ShapeMismatch::ReshapeElementCount source
records the counts) when element counts differ,
tenferro_tensor_core::ValidationError::IntegerOverflow for shape
arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
reshaped view exceeds the backing buffer.
Source§impl<'a, R: TensorRank> TypedTensorView<'a, Complex32, R>
impl<'a, R: TensorRank> TypedTensorView<'a, Complex32, R>
Sourcepub fn as_real_view(&self) -> Result<TypedTensorView<'a, f32, DynRank>>
pub fn as_real_view(&self) -> Result<TypedTensorView<'a, f32, DynRank>>
Borrow this complex view as an interleaved real view without copying.
The result has dynamic rank because reinterpretation prepends the
component axis [2, ...]. Only Complex32 <-> f32 is sealed in this
API; this is representation reinterpretation, not numeric conversion.
§Examples
use tenferro_tensor::{Complex32, TypedTensorView};
let data = [Complex32::new(1.0, 2.0)];
let view = TypedTensorView::from_col_major(&[1], &data)?;
let real = view.as_real_view()?;
assert_eq!(real.shape(), &[2, 1]);
assert_eq!(real.as_slice()?, &[1.0_f32, 2.0]);§Errors
Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.
Source§impl<'a, R: TensorRank> TypedTensorView<'a, Complex64, R>
impl<'a, R: TensorRank> TypedTensorView<'a, Complex64, R>
Sourcepub fn as_real_view(&self) -> Result<TypedTensorView<'a, f64, DynRank>>
pub fn as_real_view(&self) -> Result<TypedTensorView<'a, f64, DynRank>>
Borrow this complex view as an interleaved real view without copying.
The result has dynamic rank because reinterpretation prepends the
component axis [2, ...]. Only Complex64 <-> f64 is sealed in this
API; this is representation reinterpretation, not numeric conversion.
§Examples
use tenferro_tensor::{Complex64, TypedTensorView};
let data = [Complex64::new(1.0, 2.0)];
let view = TypedTensorView::from_col_major(&[1], &data)?;
let real = view.as_real_view()?;
assert_eq!(real.shape(), &[2, 1]);
assert_eq!(real.as_slice()?, &[1.0_f64, 2.0]);§Errors
Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.
Source§impl<'a, R: TensorRank> TypedTensorView<'a, f32, R>
impl<'a, R: TensorRank> TypedTensorView<'a, f32, R>
Sourcepub fn as_complex_view(&self) -> Result<TypedTensorView<'a, Complex32, DynRank>>
pub fn as_complex_view(&self) -> Result<TypedTensorView<'a, Complex32, DynRank>>
Borrow this interleaved real view as a complex view without copying.
The source must have a leading extent and stride of 2 and 1, and
every remaining stride plus the offset must be divisible by 2.
§Examples
use tenferro_tensor::{Complex32, TypedTensorView};
let data = [1.0_f32, 2.0];
let view = TypedTensorView::from_col_major(&[2, 1], &data)?;
let complex = view.as_complex_view()?;
assert_eq!(complex.shape(), &[1]);
assert_eq!(complex.as_slice()?, &[Complex32::new(1.0, 2.0)]);§Errors
Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.
Source§impl<'a, R: TensorRank> TypedTensorView<'a, f64, R>
impl<'a, R: TensorRank> TypedTensorView<'a, f64, R>
Sourcepub fn as_complex_view(&self) -> Result<TypedTensorView<'a, Complex64, DynRank>>
pub fn as_complex_view(&self) -> Result<TypedTensorView<'a, Complex64, DynRank>>
Borrow this interleaved real view as a complex view without copying.
The source must have a leading extent and stride of 2 and 1, and
every remaining stride plus the offset must be divisible by 2.
§Examples
use tenferro_tensor::{Complex64, TypedTensorView};
let data = [1.0_f64, 2.0];
let view = TypedTensorView::from_col_major(&[2, 1], &data)?;
let complex = view.as_complex_view()?;
assert_eq!(complex.shape(), &[1]);
assert_eq!(complex.as_slice()?, &[Complex64::new(1.0, 2.0)]);§Errors
Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.