Struct rten_tensor::TensorBase
source · pub struct TensorBase<T, S: AsRef<[T]>, L: MutLayout> { /* private fields */ }Expand description
The base type for multi-dimensional arrays. This consists of storage for elements, plus a layout which maps from a multi-dimensional array index to a storage offset. This base type is not normally used directly but instead through a type alias which selects the storage type and layout.
The storage can be owned (like a Vec<T>), borrowed (like &[T]) or
mutably borrowed (like &mut [T]). The layout can have a dimension count
that is determined statically (ie. forms part of the tensor’s type), see
NdLayout or is only known at runtime, see DynLayout.
Implementations§
source§impl<T, S: AsRef<[T]>, L: MutLayout> TensorBase<T, S, L>
impl<T, S: AsRef<[T]>, L: MutLayout> TensorBase<T, S, L>
sourcepub fn from_data(shape: L::Index<'_>, data: S) -> TensorBase<T, S, L>
pub fn from_data(shape: L::Index<'_>, data: S) -> TensorBase<T, S, L>
Construct a new tensor from a given shape and storage.
Panics if the data length does not match the product of shape.
sourcepub fn try_from_data(
shape: L::Index<'_>,
data: S
) -> Result<TensorBase<T, S, L>, FromDataError>
pub fn try_from_data( shape: L::Index<'_>, data: S ) -> Result<TensorBase<T, S, L>, FromDataError>
Construct a new tensor from a given shape and storage.
This will fail if the data length does not match the product of shape.
sourcepub fn from_data_with_strides(
shape: L::Index<'_>,
data: S,
strides: L::Index<'_>
) -> Result<TensorBase<T, S, L>, FromDataError>
pub fn from_data_with_strides( shape: L::Index<'_>, data: S, strides: L::Index<'_> ) -> Result<TensorBase<T, S, L>, FromDataError>
Construct a new tensor from a given shape and storage, and custom strides.
This will fail if the data length is incorrect for the shape and stride combination, or if the strides lead to overlap (see OverlapPolicy). See also TensorBase::from_slice_with_strides which is a similar method for immutable views that does allow overlapping strides.
sourcepub fn into_dyn(self) -> TensorBase<T, S, DynLayout>
pub fn into_dyn(self) -> TensorBase<T, S, DynLayout>
Convert the current tensor into a dynamic rank tensor without copying any data.
source§impl<T, S: AsRef<[T]> + AsMut<[T]>, L: MutLayout> TensorBase<T, S, L>
impl<T, S: AsRef<[T]> + AsMut<[T]>, L: MutLayout> TensorBase<T, S, L>
sourcepub fn axis_iter_mut(&mut self, dim: usize) -> AxisIterMut<'_, T, L> ⓘ
pub fn axis_iter_mut(&mut self, dim: usize) -> AxisIterMut<'_, T, L> ⓘ
Return an iterator over mutable slices of this tensor along a given axis. Each view yielded has one dimension fewer than the current layout.
sourcepub fn axis_chunks_mut(
&mut self,
dim: usize,
chunk_size: usize
) -> AxisChunksMut<'_, T, L> ⓘ
pub fn axis_chunks_mut( &mut self, dim: usize, chunk_size: usize ) -> AxisChunksMut<'_, T, L> ⓘ
Return an iterator over mutable slices of this tensor along a given
axis. Each view yielded has the same rank as this tensor, but the
dimension dim will only have chunk_size entries.
sourcepub fn apply<F: Fn(&T) -> T>(&mut self, f: F)
pub fn apply<F: Fn(&T) -> T>(&mut self, f: F)
Replace each element in this tensor with the result of applying f to
the element.
sourcepub fn as_dyn_mut(&mut self) -> TensorBase<T, &mut [T], DynLayout>
pub fn as_dyn_mut(&mut self) -> TensorBase<T, &mut [T], DynLayout>
Return a mutable view of this tensor with a dynamic dimension count.
sourcepub fn copy_from<S2: AsRef<[T]>>(&mut self, other: &TensorBase<T, S2, L>)
pub fn copy_from<S2: AsRef<[T]>>(&mut self, other: &TensorBase<T, S2, L>)
Copy elements from another tensor into this tensor.
This tensor and other must have the same shape.
sourcepub fn data_mut(&mut self) -> Option<&mut [T]>
pub fn data_mut(&mut self) -> Option<&mut [T]>
Return the data in this tensor as a slice if it is contiguous.
sourcepub fn data_mut_ptr(&mut self) -> *mut T
pub fn data_mut_ptr(&mut self) -> *mut T
Return a raw pointer to the tensor’s underlying data.
sourcepub fn fill(&mut self, value: T)where
T: Clone,
pub fn fill(&mut self, value: T)where
T: Clone,
Replace all elements of this tensor with value.
sourcepub fn get_mut<I: AsIndex<L>>(&mut self, index: I) -> Option<&mut T>
pub fn get_mut<I: AsIndex<L>>(&mut self, index: I) -> Option<&mut T>
Return a mutable reference to the element at index, or None if the
index is invalid.
sourcepub unsafe fn get_unchecked_mut<I: AsIndex<L>>(&mut self, index: I) -> &mut T
pub unsafe fn get_unchecked_mut<I: AsIndex<L>>(&mut self, index: I) -> &mut T
Return the element at a given index, without performing any bounds- checking.
§Safety
The caller must ensure that the index is valid for the tensor’s shape.
sourcepub fn inner_iter_mut<const N: usize>(&mut self) -> InnerIterMut<'_, T, L, N> ⓘ
pub fn inner_iter_mut<const N: usize>(&mut self) -> InnerIterMut<'_, T, L, N> ⓘ
Return a mutable iterator over the N innermost dimensions of this tensor.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Return a mutable iterator over the elements of this tensor, in their logical order.
sourcepub fn lanes_mut(&mut self, dim: usize) -> LanesMut<'_, T> ⓘ
pub fn lanes_mut(&mut self, dim: usize) -> LanesMut<'_, T> ⓘ
Return an iterator over mutable 1D slices of this tensor along a given dimension.
sourcepub fn nd_view_mut<const N: usize>(
&mut self
) -> TensorBase<T, &mut [T], NdLayout<N>>
pub fn nd_view_mut<const N: usize>( &mut self ) -> TensorBase<T, &mut [T], NdLayout<N>>
Return a view of this tensor with a static dimension count.
Panics if self.ndim() != N.
sourcepub fn permuted_mut(
&mut self,
order: L::Index<'_>
) -> TensorBase<T, &mut [T], L>
pub fn permuted_mut( &mut self, order: L::Index<'_> ) -> TensorBase<T, &mut [T], L>
Permute the order of dimensions according to the given order.
See AsView::permuted.
sourcepub fn reshaped_mut<SH: IntoLayout>(
&mut self,
shape: SH
) -> TensorBase<T, &mut [T], SH::Layout>
pub fn reshaped_mut<SH: IntoLayout>( &mut self, shape: SH ) -> TensorBase<T, &mut [T], SH::Layout>
Change the layout of the tensor without moving any data.
See AsView::reshaped.
sourcepub fn slice_mut<const M: usize, R: IntoSliceItems>(
&mut self,
range: R
) -> NdTensorViewMut<'_, T, M>
pub fn slice_mut<const M: usize, R: IntoSliceItems>( &mut self, range: R ) -> NdTensorViewMut<'_, T, M>
Slice this tensor and return a static-rank view with M dimensions.
Use AsView::slice_dyn instead if the number of dimensions in the returned view is unknown at compile time.
Panics if the dimension count is not M.
sourcepub fn slice_mut_dyn<R: IntoSliceItems>(
&mut self,
range: R
) -> TensorViewMut<'_, T>
pub fn slice_mut_dyn<R: IntoSliceItems>( &mut self, range: R ) -> TensorViewMut<'_, T>
Slice this tensor and return a dynamic-rank view.
sourcepub fn try_slice_mut<R: IntoSliceItems>(
&mut self,
range: R
) -> Result<TensorViewMut<'_, T>, SliceError>
pub fn try_slice_mut<R: IntoSliceItems>( &mut self, range: R ) -> Result<TensorViewMut<'_, T>, SliceError>
Slice this tensor and return a dynamic-rank view.
Fails if the range has more dimensions than the view or is out of bounds for any dimension.
sourcepub fn view_mut(&mut self) -> TensorBase<T, &mut [T], L>where
L: Clone,
pub fn view_mut(&mut self) -> TensorBase<T, &mut [T], L>where
L: Clone,
Return a mutable view of this tensor.
sourcepub fn weakly_checked_view_mut(&mut self) -> WeaklyCheckedView<T, &mut [T], L>
pub fn weakly_checked_view_mut(&mut self) -> WeaklyCheckedView<T, &mut [T], L>
Return a mutable view that performs only “weak” checking when indexing, this is faster but can hide bugs. See WeaklyCheckedView.
source§impl<T, L: Clone + MutLayout> TensorBase<T, Vec<T>, L>
impl<T, L: Clone + MutLayout> TensorBase<T, Vec<T>, L>
sourcepub fn arange(start: T, end: T, step: Option<T>) -> TensorBase<T, Vec<T>, L>
pub fn arange(start: T, end: T, step: Option<T>) -> TensorBase<T, Vec<T>, L>
Create a new 1D tensor filled with an arithmetic sequence of values
in the range [start, end) separated by step. If step is omitted,
it defaults to 1.
sourcepub fn from_vec(vec: Vec<T>) -> TensorBase<T, Vec<T>, L>
pub fn from_vec(vec: Vec<T>) -> TensorBase<T, Vec<T>, L>
Create a new 1D tensor from a Vec<T>.
sourcepub fn clip_dim(&mut self, dim: usize, range: Range<usize>)where
T: Copy,
pub fn clip_dim(&mut self, dim: usize, range: Range<usize>)where
T: Copy,
Clip dimension dim to [range.start, range.end). The new size for
the dimension must be <= the old size.
This currently requires T: Copy to support efficiently moving data
from the new start offset to the beginning of the element buffer.
sourcepub fn into_data(self) -> Vec<T>where
T: Clone,
pub fn into_data(self) -> Vec<T>where
T: Clone,
Consume self and return the underlying data as a contiguous tensor.
See also TensorBase::to_vec.
sourcepub fn into_non_contiguous_data(self) -> Vec<T>
pub fn into_non_contiguous_data(self) -> Vec<T>
Consume self and return the underlying data in whatever order the elements are currently stored.
sourcepub fn into_shape<S: IntoLayout>(
self,
shape: S
) -> TensorBase<T, Vec<T>, S::Layout>where
T: Clone,
pub fn into_shape<S: IntoLayout>(
self,
shape: S
) -> TensorBase<T, Vec<T>, S::Layout>where
T: Clone,
Consume self and return a new contiguous tensor with the given shape.
This avoids copying the data if it is already contiguous.
sourcepub fn from_fn<F: FnMut(L::Index<'_>) -> T, Idx>(
shape: L::Index<'_>,
f: F
) -> TensorBase<T, Vec<T>, L>
pub fn from_fn<F: FnMut(L::Index<'_>) -> T, Idx>( shape: L::Index<'_>, f: F ) -> TensorBase<T, Vec<T>, L>
Create a new tensor with a given shape and values generated by calling
f repeatedly.
Each call to f will receive an element index and should return the
corresponding value. If the function does not need this index, use
from_simple_fn instead, as it is faster.
sourcepub fn from_simple_fn<F: FnMut() -> T>(
shape: L::Index<'_>,
f: F
) -> TensorBase<T, Vec<T>, L>
pub fn from_simple_fn<F: FnMut() -> T>( shape: L::Index<'_>, f: F ) -> TensorBase<T, Vec<T>, L>
Create a new tensor with a given shape and values generated by calling
f repeatedly.
sourcepub fn from_scalar(value: T) -> TensorBase<T, Vec<T>, L>
pub fn from_scalar(value: T) -> TensorBase<T, Vec<T>, L>
Create a new 0D tensor from a scalar value.
sourcepub fn full(shape: L::Index<'_>, value: T) -> TensorBase<T, Vec<T>, L>where
T: Clone,
pub fn full(shape: L::Index<'_>, value: T) -> TensorBase<T, Vec<T>, L>where
T: Clone,
Create a new tensor with a given shape and all elements set to value.
sourcepub fn full_in<A: Alloc>(
alloc: A,
shape: L::Index<'_>,
value: T
) -> TensorBase<T, Vec<T>, L>where
T: Clone,
pub fn full_in<A: Alloc>(
alloc: A,
shape: L::Index<'_>,
value: T
) -> TensorBase<T, Vec<T>, L>where
T: Clone,
Variant of full which accepts an allocator.
sourcepub fn make_contiguous(&mut self)where
T: Clone,
pub fn make_contiguous(&mut self)where
T: Clone,
Make the underlying data in this tensor contiguous.
This means that after calling make_contiguous, the elements are
guaranteed to be stored in the same order as the logical order in
which iter yields elements. This method is cheap if the storage is
already contiguous.
sourcepub fn rand<R: RandomSource<T>>(
shape: L::Index<'_>,
rand_src: &mut R
) -> TensorBase<T, Vec<T>, L>
pub fn rand<R: RandomSource<T>>( shape: L::Index<'_>, rand_src: &mut R ) -> TensorBase<T, Vec<T>, L>
Create a new tensor with a given shape and elements populated using
numbers generated by rand_src.
sourcepub fn zeros(shape: L::Index<'_>) -> TensorBase<T, Vec<T>, L>
pub fn zeros(shape: L::Index<'_>) -> TensorBase<T, Vec<T>, L>
Create a new tensor with a given shape, with all elements set to their default value (ie. zero for numeric types).
sourcepub fn zeros_in<A: Alloc>(
alloc: A,
shape: L::Index<'_>
) -> TensorBase<T, Vec<T>, L>
pub fn zeros_in<A: Alloc>( alloc: A, shape: L::Index<'_> ) -> TensorBase<T, Vec<T>, L>
Variant of zeros which accepts an allocator.
sourcepub fn uninit(
shape: L::Index<'_>
) -> TensorBase<MaybeUninit<T>, Vec<MaybeUninit<T>>, L>where
MaybeUninit<T>: Clone,
pub fn uninit(
shape: L::Index<'_>
) -> TensorBase<MaybeUninit<T>, Vec<MaybeUninit<T>>, L>where
MaybeUninit<T>: Clone,
Return a new tensor containing uninitialized elements.
The caller must initialize elements and then call
assume_init to convert to an initialized
Tensor<T>.
sourcepub fn uninit_in<A: Alloc>(
alloc: A,
shape: L::Index<'_>
) -> TensorBase<MaybeUninit<T>, Vec<MaybeUninit<T>>, L>
pub fn uninit_in<A: Alloc>( alloc: A, shape: L::Index<'_> ) -> TensorBase<MaybeUninit<T>, Vec<MaybeUninit<T>>, L>
Variant of uninit which accepts an allocator.
source§impl<T, S: AsRef<[MaybeUninit<T>]> + AssumeInit, L: Clone + MutLayout> TensorBase<MaybeUninit<T>, S, L>
impl<T, S: AsRef<[MaybeUninit<T>]> + AssumeInit, L: Clone + MutLayout> TensorBase<MaybeUninit<T>, S, L>
sourcepub unsafe fn assume_init(self) -> TensorBase<T, <S as AssumeInit>::Output, L>
pub unsafe fn assume_init(self) -> TensorBase<T, <S as AssumeInit>::Output, L>
Convert a tensor of potentially uninitialized elements to one of initialized elements.
The tensor or view must be contiguous and this method will panic if it is not. This restriction avoids hazards with converting a view to initialized if it does not address all elements in the underlying storage.
See also MaybeUninit::assume_init.
§Safety
The caller must guarantee that all elements in this tensor have been
initialized before calling assume_init.
sourcepub fn init_from<S2: AsRef<[T]>>(
self,
other: &TensorBase<T, S2, L>
) -> TensorBase<T, <S as AssumeInit>::Output, L>
pub fn init_from<S2: AsRef<[T]>>( self, other: &TensorBase<T, S2, L> ) -> TensorBase<T, <S as AssumeInit>::Output, L>
Initialize this tensor with data from another view.
This tensor and other must have the same shape.
source§impl<'a, T, L: Clone + MutLayout> TensorBase<T, &'a [T], L>
impl<'a, T, L: Clone + MutLayout> TensorBase<T, &'a [T], L>
pub fn axis_iter(&self, dim: usize) -> AxisIter<'a, T, L> ⓘ
pub fn axis_chunks(&self, dim: usize, chunk_size: usize) -> AxisChunks<'a, T, L> ⓘ
sourcepub fn as_dyn(&self) -> TensorBase<T, &'a [T], DynLayout>
pub fn as_dyn(&self) -> TensorBase<T, &'a [T], DynLayout>
Return a view of this tensor with a dynamic dimension count.
See AsView::as_dyn.
sourcepub fn broadcast<S: IntoLayout>(
&self,
shape: S
) -> TensorBase<T, &'a [T], S::Layout>where
L: BroadcastLayout<S::Layout>,
pub fn broadcast<S: IntoLayout>(
&self,
shape: S
) -> TensorBase<T, &'a [T], S::Layout>where
L: BroadcastLayout<S::Layout>,
Broadcast this view to another shape.
See AsView::broadcast.
sourcepub fn broadcast_iter(&self, shape: &[usize]) -> BroadcastIter<'a, T> ⓘ
pub fn broadcast_iter(&self, shape: &[usize]) -> BroadcastIter<'a, T> ⓘ
Return an iterator over elements as if this tensor was broadcast to another shape.
sourcepub fn data(&self) -> Option<&'a [T]>
pub fn data(&self) -> Option<&'a [T]>
Return the data in this tensor as a slice if it is contiguous, ie.
the order of elements in the slice is the same as the logical order
yielded by iter, and there are no gaps.
pub fn get<I: AsIndex<L>>(&self, index: I) -> Option<&'a T>
sourcepub fn non_contiguous_data(&self) -> &'a [T]
pub fn non_contiguous_data(&self) -> &'a [T]
Return this view’s underlying data as a slice.
Unlike the data method, this method does not check if the storage
is contiguous in memory (ie. elements are stored in the same order as
returned by iter, with no gaps).
Note there is no safe equivalent of this method for mutable views because this could lead to overlapping mutable slices.
sourcepub fn from_slice_with_strides(
shape: L::Index<'_>,
data: &'a [T],
strides: L::Index<'_>
) -> Result<TensorBase<T, &'a [T], L>, FromDataError>
pub fn from_slice_with_strides( shape: L::Index<'_>, data: &'a [T], strides: L::Index<'_> ) -> Result<TensorBase<T, &'a [T], L>, FromDataError>
Create a new view with a given shape and data slice, and custom strides.
If you do not need to specify custom strides, use TensorBase::from_data instead. This method is similar to TensorBase::from_data_with_strides, but allows strides that lead to internal overlap (see OverlapPolicy).
sourcepub unsafe fn get_unchecked<I: AsIndex<L>>(&self, index: I) -> &'a T
pub unsafe fn get_unchecked<I: AsIndex<L>>(&self, index: I) -> &'a T
Return the element at a given index, without performing any bounds- checking.
§Safety
The caller must ensure that the index is valid for the tensor’s shape.
sourcepub fn inner_iter<const N: usize>(&self) -> InnerIter<'a, T, L, N> ⓘ
pub fn inner_iter<const N: usize>(&self) -> InnerIter<'a, T, L, N> ⓘ
Return an iterator over the inner N dimensions of this tensor.
See AsView::inner_iter.
sourcepub fn item(&self) -> Option<&'a T>
pub fn item(&self) -> Option<&'a T>
Return the scalar value in this tensor if it has one element.
sourcepub fn iter(&self) -> Iter<'a, T> ⓘ
pub fn iter(&self) -> Iter<'a, T> ⓘ
Return an iterator over elements of this tensor in their logical order.
See AsView::iter.
sourcepub fn lanes(&self, dim: usize) -> Lanes<'a, T> ⓘ
pub fn lanes(&self, dim: usize) -> Lanes<'a, T> ⓘ
Return an iterator over 1D slices of this tensor along a given dimension.
See AsView::lanes.
sourcepub fn nd_view<const N: usize>(&self) -> TensorBase<T, &'a [T], NdLayout<N>>
pub fn nd_view<const N: usize>(&self) -> TensorBase<T, &'a [T], NdLayout<N>>
Return a view of this tensor with a static dimension count.
Panics if self.ndim() != N.
sourcepub fn permuted(&self, order: L::Index<'_>) -> TensorBase<T, &'a [T], L>
pub fn permuted(&self, order: L::Index<'_>) -> TensorBase<T, &'a [T], L>
Permute the axes of this tensor according to order.
See AsView::permuted.
sourcepub fn reshaped<S: IntoLayout>(
&self,
shape: S
) -> TensorBase<T, &'a [T], S::Layout>
pub fn reshaped<S: IntoLayout>( &self, shape: S ) -> TensorBase<T, &'a [T], S::Layout>
Change the shape of this tensor without copying data.
See AsView::reshaped.
sourcepub fn slice<const M: usize, R: IntoSliceItems>(
&self,
range: R
) -> NdTensorView<'a, T, M>
pub fn slice<const M: usize, R: IntoSliceItems>( &self, range: R ) -> NdTensorView<'a, T, M>
Slice this tensor and return a static-rank view. See AsView::slice.
sourcepub fn slice_dyn<R: IntoSliceItems>(&self, range: R) -> TensorView<'a, T>
pub fn slice_dyn<R: IntoSliceItems>(&self, range: R) -> TensorView<'a, T>
Slice this tensor and return a dynamic-rank view. See AsView::slice_dyn.
sourcepub fn slice_iter(&self, range: &[SliceItem]) -> Iter<'a, T> ⓘ
pub fn slice_iter(&self, range: &[SliceItem]) -> Iter<'a, T> ⓘ
See AsView::slice_iter.
sourcepub fn squeezed(&self) -> TensorView<'a, T>
pub fn squeezed(&self) -> TensorView<'a, T>
Remove all size-one dimensions from this tensor.
See AsView::squeezed.
sourcepub fn to_contiguous(&self) -> TensorBase<T, Cow<'a, [T]>, L>where
T: Clone,
pub fn to_contiguous(&self) -> TensorBase<T, Cow<'a, [T]>, L>where
T: Clone,
Return a view of this tensor with elements stored in contiguous order.
If the data is already contiguous, no copy is made, otherwise the elements are copied into a new buffer in contiguous order.
sourcepub fn to_slice(&self) -> Cow<'a, [T]>where
T: Clone,
pub fn to_slice(&self) -> Cow<'a, [T]>where
T: Clone,
Return the underlying data as a flat slice if the tensor is contiguous, or a copy of the data as a flat slice otherwise.
See AsView::to_slice.
sourcepub fn transposed(&self) -> TensorBase<T, &'a [T], L>
pub fn transposed(&self) -> TensorBase<T, &'a [T], L>
Reverse the order of dimensions in this tensor. See AsView::transposed.
pub fn try_slice_dyn<R: IntoSliceItems>( &self, range: R ) -> Result<TensorView<'a, T>, SliceError>
sourcepub fn view(&self) -> TensorBase<T, &'a [T], L>
pub fn view(&self) -> TensorBase<T, &'a [T], L>
Return a read-only view of this tensor. See AsView::view.
pub fn weakly_checked_view(&self) -> WeaklyCheckedView<T, &'a [T], L>
source§impl<T, S: AsRef<[T]>, const N: usize> TensorBase<T, S, NdLayout<N>>
impl<T, S: AsRef<[T]>, const N: usize> TensorBase<T, S, NdLayout<N>>
sourcepub fn get_array<const M: usize>(&self, base: [usize; N], dim: usize) -> [T; M]
pub fn get_array<const M: usize>(&self, base: [usize; N], dim: usize) -> [T; M]
Load an array of M elements from successive entries of a tensor along
the dim axis.
eg. If base is [0, 1, 2], dim=0 and M = 4 this will return an
array with values from indices [0, 1, 2], [1, 1, 2] … [3, 1, 2].
Panics if any of the array indices are out of bounds.
source§impl<T> TensorBase<T, Vec<T>, DynLayout>
impl<T> TensorBase<T, Vec<T>, DynLayout>
source§impl<'a, T> TensorBase<T, &'a [T], DynLayout>
impl<'a, T> TensorBase<T, &'a [T], DynLayout>
source§impl<'a, T> TensorBase<T, &'a mut [T], DynLayout>
impl<'a, T> TensorBase<T, &'a mut [T], DynLayout>
Trait Implementations§
source§impl<T, S: AsRef<[T]>, L: MutLayout + Clone> AsView for TensorBase<T, S, L>
impl<T, S: AsRef<[T]>, L: MutLayout + Clone> AsView for TensorBase<T, S, L>
§type Layout = L
type Layout = L
[usize; N] or &[usize]) as this view.source§fn iter(&self) -> Iter<'_, T> ⓘ
fn iter(&self) -> Iter<'_, T> ⓘ
source§fn data(&self) -> Option<&[Self::Elem]>
fn data(&self) -> Option<&[Self::Elem]>
source§fn insert_axis(&mut self, index: usize)where
L: ResizeLayout,
fn insert_axis(&mut self, index: usize)where
L: ResizeLayout,
source§fn merge_axes(&mut self)where
L: ResizeLayout,
fn merge_axes(&mut self)where
L: ResizeLayout,
source§fn map<F, U>(&self, f: F) -> TensorBase<U, Vec<U>, L>
fn map<F, U>(&self, f: F) -> TensorBase<U, Vec<U>, L>
f to each
element in this tensor.source§fn view(&self) -> TensorBase<T, &[T], L>
fn view(&self) -> TensorBase<T, &[T], L>
source§fn get<I: AsIndex<L>>(&self, index: I) -> Option<&Self::Elem>
fn get<I: AsIndex<L>>(&self, index: I) -> Option<&Self::Elem>
None if the
index is invalid.source§unsafe fn get_unchecked<I: AsIndex<L>>(&self, index: I) -> &T
unsafe fn get_unchecked<I: AsIndex<L>>(&self, index: I) -> &T
source§fn to_vec(&self) -> Vec<T>where
T: Clone,
fn to_vec(&self) -> Vec<T>where
T: Clone,
source§fn to_vec_in<A: Alloc>(&self, alloc: A) -> Vec<T>where
T: Clone,
fn to_vec_in<A: Alloc>(&self, alloc: A) -> Vec<T>where
T: Clone,
to_vec which takes an output buffer as
an argument.source§fn to_shape<SH: IntoLayout>(
&self,
shape: SH
) -> TensorBase<Self::Elem, Vec<Self::Elem>, SH::Layout>where
T: Clone,
fn to_shape<SH: IntoLayout>(
&self,
shape: SH
) -> TensorBase<Self::Elem, Vec<Self::Elem>, SH::Layout>where
T: Clone,
source§fn as_dyn(&self) -> TensorBase<Self::Elem, &[Self::Elem], DynLayout>
fn as_dyn(&self) -> TensorBase<Self::Elem, &[Self::Elem], DynLayout>
source§fn axis_chunks(
&self,
dim: usize,
chunk_size: usize
) -> AxisChunks<'_, Self::Elem, Self::Layout> ⓘ
fn axis_chunks( &self, dim: usize, chunk_size: usize ) -> AxisChunks<'_, Self::Elem, Self::Layout> ⓘ
source§fn axis_iter(&self, dim: usize) -> AxisIter<'_, Self::Elem, Self::Layout> ⓘ
fn axis_iter(&self, dim: usize) -> AxisIter<'_, Self::Elem, Self::Layout> ⓘ
source§fn broadcast<S: IntoLayout>(
&self,
shape: S
) -> TensorBase<Self::Elem, &[Self::Elem], S::Layout>
fn broadcast<S: IntoLayout>( &self, shape: S ) -> TensorBase<Self::Elem, &[Self::Elem], S::Layout>
source§fn broadcast_iter(&self, shape: &[usize]) -> BroadcastIter<'_, Self::Elem> ⓘ
fn broadcast_iter(&self, shape: &[usize]) -> BroadcastIter<'_, Self::Elem> ⓘ
shape. Read moresource§fn inner_iter<const N: usize>(
&self
) -> InnerIter<'_, Self::Elem, Self::Layout, N> ⓘ
fn inner_iter<const N: usize>( &self ) -> InnerIter<'_, Self::Elem, Self::Layout, N> ⓘ
source§fn item(&self) -> Option<&Self::Elem>
fn item(&self) -> Option<&Self::Elem>
source§fn lanes(&self, dim: usize) -> Lanes<'_, Self::Elem> ⓘ
fn lanes(&self, dim: usize) -> Lanes<'_, Self::Elem> ⓘ
source§fn nd_view<const N: usize>(
&self
) -> TensorBase<Self::Elem, &[Self::Elem], NdLayout<N>>
fn nd_view<const N: usize>( &self ) -> TensorBase<Self::Elem, &[Self::Elem], NdLayout<N>>
source§fn permuted(
&self,
order: Self::Index<'_>
) -> TensorBase<Self::Elem, &[Self::Elem], Self::Layout>
fn permuted( &self, order: Self::Index<'_> ) -> TensorBase<Self::Elem, &[Self::Elem], Self::Layout>
dims.source§fn reshaped<S: IntoLayout>(
&self,
shape: S
) -> TensorBase<Self::Elem, &[Self::Elem], S::Layout>
fn reshaped<S: IntoLayout>( &self, shape: S ) -> TensorBase<Self::Elem, &[Self::Elem], S::Layout>
source§fn transposed(&self) -> TensorBase<Self::Elem, &[Self::Elem], Self::Layout>
fn transposed(&self) -> TensorBase<Self::Elem, &[Self::Elem], Self::Layout>
source§fn try_slice_dyn<R: IntoSliceItems>(
&self,
range: R
) -> Result<TensorView<'_, Self::Elem>, SliceError>
fn try_slice_dyn<R: IntoSliceItems>( &self, range: R ) -> Result<TensorView<'_, Self::Elem>, SliceError>
source§fn slice<const M: usize, R: IntoSliceItems>(
&self,
range: R
) -> NdTensorView<'_, Self::Elem, M>
fn slice<const M: usize, R: IntoSliceItems>( &self, range: R ) -> NdTensorView<'_, Self::Elem, M>
M dimensions. Read moresource§fn slice_dyn<R: IntoSliceItems>(&self, range: R) -> TensorView<'_, Self::Elem>
fn slice_dyn<R: IntoSliceItems>(&self, range: R) -> TensorView<'_, Self::Elem>
source§fn slice_iter(&self, range: &[SliceItem]) -> Iter<'_, Self::Elem> ⓘ
fn slice_iter(&self, range: &[SliceItem]) -> Iter<'_, Self::Elem> ⓘ
source§fn squeezed(&self) -> TensorView<'_, Self::Elem>
fn squeezed(&self) -> TensorView<'_, Self::Elem>
source§fn weakly_checked_view(
&self
) -> WeaklyCheckedView<Self::Elem, &[Self::Elem], Self::Layout>
fn weakly_checked_view( &self ) -> WeaklyCheckedView<Self::Elem, &[Self::Elem], Self::Layout>
view[<index>]. See WeaklyCheckedView for an explanation.source§impl<T, S: AsRef<[T]> + Clone, L: MutLayout + Clone> Clone for TensorBase<T, S, L>
impl<T, S: AsRef<[T]> + Clone, L: MutLayout + Clone> Clone for TensorBase<T, S, L>
source§fn clone(&self) -> TensorBase<T, S, L>
fn clone(&self) -> TensorBase<T, S, L>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a, T, L: Clone + MutLayout, const N: usize> From<&'a [T; N]> for TensorBase<T, &'a [T], L>
impl<'a, T, L: Clone + MutLayout, const N: usize> From<&'a [T; N]> for TensorBase<T, &'a [T], L>
source§impl<T: Clone + Scalar, L: MutLayout, const D0: usize, const D1: usize, const D2: usize> From<[[[T; D2]; D1]; D0]> for TensorBase<T, Vec<T>, L>
impl<T: Clone + Scalar, L: MutLayout, const D0: usize, const D1: usize, const D2: usize> From<[[[T; D2]; D1]; D0]> for TensorBase<T, Vec<T>, L>
source§impl<T: Clone + Scalar, L: MutLayout, const D0: usize, const D1: usize> From<[[T; D1]; D0]> for TensorBase<T, Vec<T>, L>
impl<T: Clone + Scalar, L: MutLayout, const D0: usize, const D1: usize> From<[[T; D1]; D0]> for TensorBase<T, Vec<T>, L>
source§impl<T: Clone + Scalar, L: MutLayout, const D0: usize> From<[T; D0]> for TensorBase<T, Vec<T>, L>
impl<T: Clone + Scalar, L: MutLayout, const D0: usize> From<[T; D0]> for TensorBase<T, Vec<T>, L>
source§impl<T, S: AsRef<[T]>, const N: usize> From<TensorBase<T, S, NdLayout<N>>> for TensorBase<T, S, DynLayout>
impl<T, S: AsRef<[T]>, const N: usize> From<TensorBase<T, S, NdLayout<N>>> for TensorBase<T, S, DynLayout>
source§fn from(tensor: TensorBase<T, S, NdLayout<N>>) -> Self
fn from(tensor: TensorBase<T, S, NdLayout<N>>) -> Self
source§impl<T, L: Clone + MutLayout> FromIterator<T> for TensorBase<T, Vec<T>, L>
impl<T, L: Clone + MutLayout> FromIterator<T> for TensorBase<T, Vec<T>, L>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> TensorBase<T, Vec<T>, L>
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> TensorBase<T, Vec<T>, L>
Create a new 1D tensor filled with an arithmetic sequence of values
in the range [start, end) separated by step. If step is omitted,
it defaults to 1.
source§impl<T, S: AsRef<[T]> + AsMut<[T]>, L: MutLayout, I: AsIndex<L>> IndexMut<I> for TensorBase<T, S, L>
impl<T, S: AsRef<[T]> + AsMut<[T]>, L: MutLayout, I: AsIndex<L>> IndexMut<I> for TensorBase<T, S, L>
source§impl<T, S: AsRef<[T]>, L: MutLayout> Layout for TensorBase<T, S, L>
impl<T, S: AsRef<[T]>, L: MutLayout> Layout for TensorBase<T, S, L>
source§fn stride(&self, dim: usize) -> usize
fn stride(&self, dim: usize) -> usize
dim.source§fn try_offset(&self, index: Self::Index<'_>) -> Option<usize>
fn try_offset(&self, index: Self::Index<'_>) -> Option<usize>
None if the index is out
of bounds along any dimension.source§fn offset_unchecked(&self, index: Self::Index<'_>) -> usize
fn offset_unchecked(&self, index: Self::Index<'_>) -> usize
source§fn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
source§fn is_broadcast(&self) -> bool
fn is_broadcast(&self) -> bool
source§fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
source§fn can_broadcast_with(&self, shape: &[usize]) -> bool
fn can_broadcast_with(&self, shape: &[usize]) -> bool
shape as part of a binary operation. Read more