pub struct Tensor<T, S = DynRank, A = Global>where
S: Shape,
A: Allocator,{ /* private fields */ }Expand description
Dense multidimensional array.
Implementations§
Source§impl<T, S, A> Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> Tensor<T, S, A>where
S: Shape,
A: Allocator,
Sourcepub fn append(&mut self, other: &mut Tensor<T, S, A>)
pub fn append(&mut self, other: &mut Tensor<T, S, A>)
Moves all elements from another array into the array along the first dimension.
If the array is empty, it is reshaped to match the shape of the other array.
§Panics
Panics if the inner dimensions do not match, if the rank is not the same and at least 1, or if the first dimension is not dynamically-sized.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the array can hold without reallocating.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the array, removing all values.
If the array type has dynamic rank, the rank is set to 1.
Note that this method has no effect on the allocated capacity of the array.
§Panics
Panics if the default array length for the layout mapping is not zero.
Sourcepub fn drain<R>(&mut self, range: R) -> IntoExpr<Drain<'_, T, S, A>>where
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> IntoExpr<Drain<'_, T, S, A>>where
R: RangeBounds<usize>,
Removes the specified range from the array along the first dimension, and returns the removed range as an expression.
§Panics
Panics if the rank is not at least 1, or if the first dimension is not dynamically-sized.
Sourcepub fn expand<I>(&mut self, expr: I)
pub fn expand<I>(&mut self, expr: I)
Appends an expression to the array along the first dimension with broadcasting, cloning elements if needed.
If the array is empty, it is reshaped to match the shape of the expression.
§Panics
Panics if the inner dimensions do not match, if the rank is not the same and at least 1, or if the first dimension is not dynamically-sized.
Sourcepub fn into_dyn(self) -> Tensor<T, DynRank, A>
pub fn into_dyn(self) -> Tensor<T, DynRank, A>
Converts the array into an array with dynamic rank.
Sourcepub fn into_flat(self) -> Tensor<T, (usize,), A>
pub fn into_flat(self) -> Tensor<T, (usize,), A>
Converts the array into a one-dimensional array.
Sourcepub fn into_mapping<R>(self) -> Tensor<T, R, A>where
R: Shape,
pub fn into_mapping<R>(self) -> Tensor<T, R, A>where
R: Shape,
Converts the array into a remapped array.
§Panics
Panics if the shape is not matching static rank or constant-sized dimensions.
Sourcepub fn into_scalar(self) -> T
pub fn into_scalar(self) -> T
Converts an array with a single element into the contained value.
§Panics
Panics if the array length is not equal to one.
Sourcepub fn into_shape<I>(
self,
shape: I,
) -> Tensor<T, <I as IntoShape>::IntoShape, A>where
I: IntoShape,
pub fn into_shape<I>(
self,
shape: I,
) -> Tensor<T, <I as IntoShape>::IntoShape, A>where
I: IntoShape,
Converts the array into a reshaped array, which must have the same length.
At most one dimension can have dynamic size usize::MAX, and is then inferred
from the other dimensions and the array length.
§Examples
use mdarray::{tensor, view};
let t = tensor![[1, 2, 3], [4, 5, 6]];
assert_eq!(t.into_shape([!0, 2]), view![[1, 2], [3, 4], [5, 6]]);§Panics
Panics if the array length is changed.
Sourcepub fn map<F>(self, f: F) -> Tensor<T, S, A>where
F: FnMut(T) -> T,
pub fn map<F>(self, f: F) -> Tensor<T, S, A>where
F: FnMut(T) -> T,
Returns the array with the given closure applied to each element.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least the additional number of elements in the array.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for the additional number of elements in the array.
Sourcepub fn resize(&mut self, new_dims: &[usize], value: T)
pub fn resize(&mut self, new_dims: &[usize], value: T)
Resizes the array to the new shape, creating new elements with the given value.
Sourcepub fn resize_with<F>(&mut self, new_dims: &[usize], f: F)
pub fn resize_with<F>(&mut self, new_dims: &[usize], f: F)
Resizes the array to the new shape, creating new elements from the given closure.
Sourcepub unsafe fn set_mapping(&mut self, new_mapping: DenseMapping<S>)
pub unsafe fn set_mapping(&mut self, new_mapping: DenseMapping<S>)
Forces the array layout mapping to the new mapping.
§Safety
All elements within the array length must be initialized.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the array with a lower bound.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the array as much as possible.
Sourcepub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>]
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>]
Returns the remaining spare capacity of the array as a slice of MaybeUninit<T>.
The returned slice can be used to fill the array with data, before marking
the data as initialized using the set_shape method.
Sourcepub fn truncate(&mut self, size: usize)
pub fn truncate(&mut self, size: usize)
Shortens the array along the first dimension, keeping the first size indices.
If size is greater or equal to the current dimension size, this has no effect.
Note that this method has no effect on the allocated capacity of the array.
§Panics
Panics if the rank is not at least 1, or if the first dimension is not dynamically-sized.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least the additional number of elements in the array.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for the additional number of elements in the array.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Source§impl<T, S> Tensor<T, S>where
S: Shape,
impl<T, S> Tensor<T, S>where
S: Shape,
Sourcepub fn from_elem<I>(shape: I, elem: T) -> Tensor<T, S>
pub fn from_elem<I>(shape: I, elem: T) -> Tensor<T, S>
Creates an array from the given element.
Sourcepub fn from_fn<I, F>(shape: I, f: F) -> Tensor<T, S>
pub fn from_fn<I, F>(shape: I, f: F) -> Tensor<T, S>
Creates an array with the results from the given function.
Sourcepub unsafe fn from_raw_parts(
ptr: *mut T,
mapping: DenseMapping<S>,
capacity: usize,
) -> Tensor<T, S>
pub unsafe fn from_raw_parts( ptr: *mut T, mapping: DenseMapping<S>, capacity: usize, ) -> Tensor<T, S>
Creates an array from raw components of another array.
§Safety
The pointer must be a valid allocation given the shape and capacity.
Sourcepub fn into_raw_parts(self) -> (*mut T, DenseMapping<S>, usize)
pub fn into_raw_parts(self) -> (*mut T, DenseMapping<S>, usize)
Decomposes an array into its raw components.
Sourcepub fn new() -> Tensor<T, S>
pub fn new() -> Tensor<T, S>
Creates a new, empty array.
§Panics
Panics if the default array length for the layout mapping is not zero.
Sourcepub fn uninit<I>(shape: I) -> Tensor<MaybeUninit<T>, S>where
I: IntoShape<IntoShape = S>,
pub fn uninit<I>(shape: I) -> Tensor<MaybeUninit<T>, S>where
I: IntoShape<IntoShape = S>,
Creates an array with uninitialized elements.
Sourcepub fn with_capacity(capacity: usize) -> Tensor<T, S>
pub fn with_capacity(capacity: usize) -> Tensor<T, S>
Creates a new, empty array with the specified capacity.
§Panics
Panics if the default array length for the layout mapping is not zero.
Source§impl<T, S, A> Tensor<MaybeUninit<T>, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> Tensor<MaybeUninit<T>, S, A>where
S: Shape,
A: Allocator,
Sourcepub unsafe fn assume_init(self) -> Tensor<T, S, A>
pub unsafe fn assume_init(self) -> Tensor<T, S, A>
Converts the array element type from MaybeUninit<T> to T.
§Safety
All elements in the array must be initialized, or the behavior is undefined.
Methods from Deref<Target = Slice<T, S>>§
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Returns a mutable pointer to the array buffer.
Sourcepub fn assign<I>(&mut self, expr: I)
pub fn assign<I>(&mut self, expr: I)
Assigns an expression to the array slice with broadcasting, cloning elements if needed.
§Panics
Panics if the expression cannot be broadcast to the shape of the array slice.
Sourcepub fn at(&self, index: usize) -> View<'_, T, <S as Shape>::Tail, L>
pub fn at(&self, index: usize) -> View<'_, T, <S as Shape>::Tail, L>
Returns an array view after indexing the first dimension.
§Panics
Panics if the index is out of bounds, or if the rank is not at least 1.
Sourcepub fn at_mut(&mut self, index: usize) -> ViewMut<'_, T, <S as Shape>::Tail, L>
pub fn at_mut(&mut self, index: usize) -> ViewMut<'_, T, <S as Shape>::Tail, L>
Returns a mutable array view after indexing the first dimension.
§Panics
Panics if the index is out of bounds, or if the rank is not at least 1.
Sourcepub fn axis_at<A>(
&self,
axis: A,
index: usize,
) -> View<'_, T, <A as Axis>::Remove<S>, <<A as Axis>::Init<S> as Shape>::Layout<L>>where
A: Axis,
pub fn axis_at<A>(
&self,
axis: A,
index: usize,
) -> View<'_, T, <A as Axis>::Remove<S>, <<A as Axis>::Init<S> as Shape>::Layout<L>>where
A: Axis,
Returns an array view after indexing the specified dimension.
If the dimension to be indexed is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array view has the same layout as the input.
§Panics
Panics if the dimension or the index is out of bounds.
Sourcepub fn axis_at_mut<A>(
&mut self,
axis: A,
index: usize,
) -> ViewMut<'_, T, <A as Axis>::Remove<S>, <<A as Axis>::Init<S> as Shape>::Layout<L>>where
A: Axis,
pub fn axis_at_mut<A>(
&mut self,
axis: A,
index: usize,
) -> ViewMut<'_, T, <A as Axis>::Remove<S>, <<A as Axis>::Init<S> as Shape>::Layout<L>>where
A: Axis,
Returns a mutable array view after indexing the specified dimension.
If the dimension to be indexed is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array view has the same layout as the input.
§Panics
Panics if the dimension or the index is out of bounds.
Sourcepub fn axis_expr<A>(&self, axis: A) -> AxisExpr<'_, T, S, L, A>where
A: Axis,
pub fn axis_expr<A>(&self, axis: A) -> AxisExpr<'_, T, S, L, A>where
A: Axis,
Returns an expression that gives array views iterating over the specified dimension.
If the dimension to be iterated over is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array views have the same layout as the input.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn axis_expr_mut<A>(&mut self, axis: A) -> AxisExprMut<'_, T, S, L, A>where
A: Axis,
pub fn axis_expr_mut<A>(&mut self, axis: A) -> AxisExprMut<'_, T, S, L, A>where
A: Axis,
Returns a mutable expression that gives array views iterating over the specified dimension.
If the dimension to be iterated over is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array views have the same layout as the input.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn col(&self, index: usize) -> View<'_, T, (<S as Shape>::Head,), Strided>
pub fn col(&self, index: usize) -> View<'_, T, (<S as Shape>::Head,), Strided>
Returns an array view for the specified column.
§Panics
Panics if the rank is not equal to 2, or if the index is out of bounds.
Sourcepub fn col_mut(
&mut self,
index: usize,
) -> ViewMut<'_, T, (<S as Shape>::Head,), Strided>
pub fn col_mut( &mut self, index: usize, ) -> ViewMut<'_, T, (<S as Shape>::Head,), Strided>
Returns a mutable array view for the specified column.
§Panics
Panics if the rank is not equal to 2, or if the index is out of bounds.
Sourcepub fn cols(&self) -> Lanes<'_, T, S, L, Cols>
pub fn cols(&self) -> Lanes<'_, T, S, L, Cols>
Returns an expression that gives column views iterating over the other dimensions.
§Panics
Panics if the rank is not at least 2.
Sourcepub fn cols_mut(&mut self) -> LanesMut<'_, T, S, L, Cols>
pub fn cols_mut(&mut self) -> LanesMut<'_, T, S, L, Cols>
Returns a mutable expression that gives column views iterating over the other dimensions.
§Panics
Panics if the rank is not at least 2.
Sourcepub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
pub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
Returns true if the array slice contains an element with the given value.
Sourcepub fn diag(&self, index: isize) -> View<'_, T, (usize,), Strided>
pub fn diag(&self, index: isize) -> View<'_, T, (usize,), Strided>
Returns an array view for the given diagonal of the array slice,
where index > 0 is above and index < 0 is below the main diagonal.
§Panics
Panics if the rank is not equal to 2, or if the absolute index is larger than the number of columns or rows.
Sourcepub fn diag_mut(&mut self, index: isize) -> ViewMut<'_, T, (usize,), Strided>
pub fn diag_mut(&mut self, index: isize) -> ViewMut<'_, T, (usize,), Strided>
Returns a mutable array view for the given diagonal of the array slice,
where index > 0 is above and index < 0 is below the main diagonal.
§Panics
Panics if the rank is not equal to 2, or if the absolute index is larger than the number of columns or rows.
Sourcepub fn dim(&self, index: usize) -> usize
pub fn dim(&self, index: usize) -> usize
Returns the number of elements in the specified dimension.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn expr_mut(&mut self) -> ViewMut<'_, T, S, L>
pub fn expr_mut(&mut self) -> ViewMut<'_, T, S, L>
Returns a mutable expression over the array slice.
Sourcepub fn fill(&mut self, value: T)where
T: Clone,
pub fn fill(&mut self, value: T)where
T: Clone,
Fills the array slice with elements by cloning value.
Sourcepub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
pub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
Fills the array slice with elements returned by calling a closure repeatedly.
Sourcepub fn flatten(&self) -> View<'_, T, (usize,), L>
pub fn flatten(&self) -> View<'_, T, (usize,), L>
Returns a one-dimensional array view of the array slice.
§Panics
Panics if the array layout is not uniformly strided.
Sourcepub fn flatten_mut(&mut self) -> ViewMut<'_, T, (usize,), L>
pub fn flatten_mut(&mut self) -> ViewMut<'_, T, (usize,), L>
Returns a mutable one-dimensional array view over the array slice.
§Panics
Panics if the array layout is not uniformly strided.
Sourcepub unsafe fn get_unchecked<I>(
&self,
index: I,
) -> &<I as SliceIndex<T, S, L>>::Outputwhere
I: SliceIndex<T, S, L>,
pub unsafe fn get_unchecked<I>(
&self,
index: I,
) -> &<I as SliceIndex<T, S, L>>::Outputwhere
I: SliceIndex<T, S, L>,
Returns a reference to an element or a subslice, without doing bounds checking.
§Safety
The index must be within bounds of the array slice.
Sourcepub unsafe fn get_unchecked_mut<I>(
&mut self,
index: I,
) -> &mut <I as SliceIndex<T, S, L>>::Outputwhere
I: SliceIndex<T, S, L>,
pub unsafe fn get_unchecked_mut<I>(
&mut self,
index: I,
) -> &mut <I as SliceIndex<T, S, L>>::Outputwhere
I: SliceIndex<T, S, L>,
Returns a mutable reference to an element or a subslice, without doing bounds checking.
§Safety
The index must be within bounds of the array slice.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Returns true if the array strides are consistent with contiguous memory layout.
Sourcepub fn iter_mut(&mut self) -> Iter<ViewMut<'_, T, S, L>>
pub fn iter_mut(&mut self) -> Iter<ViewMut<'_, T, S, L>>
Returns a mutable iterator over the array slice.
Sourcepub fn lanes<A>(&self, axis: A) -> Lanes<'_, T, S, L, A>where
A: Axis,
pub fn lanes<A>(&self, axis: A) -> Lanes<'_, T, S, L, A>where
A: Axis,
Returns an expression that gives array views over the specified dimension, iterating over the other dimensions.
If the dimension to give array views over is know at compile time, the resulting shape will maintain a constant-sized dimension. Furthermore, if it is the last dimension the resulting array views have the same layout as the input.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn lanes_mut<A>(&mut self, axis: A) -> LanesMut<'_, T, S, L, A>where
A: Axis,
pub fn lanes_mut<A>(&mut self, axis: A) -> LanesMut<'_, T, S, L, A>where
A: Axis,
Returns a mutable expression that gives array views over the specified dimension, iterating over the other dimensions.
If the dimension to give array views over is know at compile time, the resulting shape will maintain a constant-sized dimension. Furthermore, if it is the last dimension the resulting array views have the same layout as the input.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn outer_expr(&self) -> AxisExpr<'_, T, S, L, Const<0>>
pub fn outer_expr(&self) -> AxisExpr<'_, T, S, L, Const<0>>
Returns an expression that gives array views iterating over the first dimension.
Iterating over the first dimension results in array views with the same layout as the input.
§Panics
Panics if the rank is not at least 1.
Sourcepub fn outer_expr_mut(&mut self) -> AxisExprMut<'_, T, S, L, Const<0>>
pub fn outer_expr_mut(&mut self) -> AxisExprMut<'_, T, S, L, Const<0>>
Returns a mutable expression that gives array views iterating over the first dimension.
Iterating over the first dimension results in array views with the same layout as the input.
§Panics
Panics if the rank is not at least 1.
Sourcepub fn permute<I>(
&self,
perm: I,
) -> View<'_, T, <<I as IntoShape>::IntoShape as Permutation>::Shape<S>, <<I as IntoShape>::IntoShape as Permutation>::Layout<L>>
pub fn permute<I>( &self, perm: I, ) -> View<'_, T, <<I as IntoShape>::IntoShape as Permutation>::Shape<S>, <<I as IntoShape>::IntoShape as Permutation>::Layout<L>>
Returns an array view with the dimensions permuted.
If the permutation is an identity permutation and known at compile time, the
resulting array view has the same layout as the input. For example, permuting
with (Const::<0>, Const::<1>) will maintain the layout while permuting with
[0, 1] gives strided layout.
§Panics
Panics if the permutation is not valid.
Sourcepub fn permute_mut<I>(
&mut self,
perm: I,
) -> ViewMut<'_, T, <<I as IntoShape>::IntoShape as Permutation>::Shape<S>, <<I as IntoShape>::IntoShape as Permutation>::Layout<L>>
pub fn permute_mut<I>( &mut self, perm: I, ) -> ViewMut<'_, T, <<I as IntoShape>::IntoShape as Permutation>::Shape<S>, <<I as IntoShape>::IntoShape as Permutation>::Layout<L>>
Returns a mutable array view with the dimensions permuted.
If the permutation is an identity permutation and known at compile time, the
resulting array view has the same layout as the input. For example, permuting
with (Const::<0>, Const::<1>) will maintain the layout while permuting with
[0, 1] gives strided layout.
§Panics
Panics if the permutation is not valid.
Sourcepub fn remap<R, K>(&self) -> View<'_, T, R, K>
pub fn remap<R, K>(&self) -> View<'_, T, R, K>
Returns a remapped array view of the array slice.
§Panics
Panics if the memory layout is not compatible with the new array layout.
Sourcepub fn remap_mut<R, K>(&mut self) -> ViewMut<'_, T, R, K>
pub fn remap_mut<R, K>(&mut self) -> ViewMut<'_, T, R, K>
Returns a mutable remapped array view of the array slice.
§Panics
Panics if the memory layout is not compatible with the new array layout.
Sourcepub fn reorder(
&self,
) -> View<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
👎Deprecated
pub fn reorder( &self, ) -> View<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
Returns a reordered array view of the array slice.
This method is deprecated, use transpose instead.
Sourcepub fn reorder_mut(
&mut self,
) -> ViewMut<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
👎Deprecated
pub fn reorder_mut( &mut self, ) -> ViewMut<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
Returns a mutable reordered array view of the array slice.
This method is deprecated, use transpose_mut instead.
Sourcepub fn reshape<I>(
&self,
shape: I,
) -> View<'_, T, <I as IntoShape>::IntoShape, L>where
I: IntoShape,
pub fn reshape<I>(
&self,
shape: I,
) -> View<'_, T, <I as IntoShape>::IntoShape, L>where
I: IntoShape,
Returns a reshaped array view of the array slice.
At most one dimension can have dynamic size usize::MAX, and is then inferred
from the other dimensions and the array length.
§Examples
use mdarray::view;
let v = view![[1, 2, 3], [4, 5, 6]];
assert_eq!(v.reshape([!0, 2]), view![[1, 2], [3, 4], [5, 6]]);§Panics
Panics if the array length is changed, or if the memory layout is not compatible.
Sourcepub fn reshape_mut<I>(
&mut self,
shape: I,
) -> ViewMut<'_, T, <I as IntoShape>::IntoShape, L>where
I: IntoShape,
pub fn reshape_mut<I>(
&mut self,
shape: I,
) -> ViewMut<'_, T, <I as IntoShape>::IntoShape, L>where
I: IntoShape,
Returns a mutable reshaped array view of the array slice.
At most one dimension can have dynamic size usize::MAX, and is then inferred
from the other dimensions and the array length.
See the reshape method above for examples.
§Panics
Panics if the array length is changed, or if the memory layout is not compatible.
Sourcepub fn row(
&self,
index: usize,
) -> View<'_, T, (<<S as Shape>::Tail as Shape>::Head,), L>
pub fn row( &self, index: usize, ) -> View<'_, T, (<<S as Shape>::Tail as Shape>::Head,), L>
Returns an array view for the specified row.
§Panics
Panics if the rank is not equal to 2, or if the index is out of bounds.
Sourcepub fn row_mut(
&mut self,
index: usize,
) -> ViewMut<'_, T, (<<S as Shape>::Tail as Shape>::Head,), L>
pub fn row_mut( &mut self, index: usize, ) -> ViewMut<'_, T, (<<S as Shape>::Tail as Shape>::Head,), L>
Returns a mutable array view for the specified row.
§Panics
Panics if the rank is not equal to 2, or if the index is out of bounds.
Sourcepub fn rows(&self) -> Lanes<'_, T, S, L, Rows>
pub fn rows(&self) -> Lanes<'_, T, S, L, Rows>
Returns an expression that gives row views iterating over the other dimensions.
§Panics
Panics if the rank is not at least 1.
Sourcepub fn rows_mut(&mut self) -> LanesMut<'_, T, S, L, Rows>
pub fn rows_mut(&mut self) -> LanesMut<'_, T, S, L, Rows>
Returns a mutable expression that gives row views iterating over the other dimensions.
§Panics
Panics if the rank is not at least 1.
Sourcepub fn split_at(
&self,
mid: usize,
) -> (View<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>, View<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>)
pub fn split_at( &self, mid: usize, ) -> (View<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>, View<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>)
Divides an array slice into two at an index along the first dimension.
§Panics
Panics if the split point is larger than the number of elements in that dimension, or if the rank is not at least 1.
Sourcepub fn split_at_mut(
&mut self,
mid: usize,
) -> (ViewMut<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>, ViewMut<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>)
pub fn split_at_mut( &mut self, mid: usize, ) -> (ViewMut<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>, ViewMut<'_, T, <Const<0> as Axis>::Insert<usize, <Const<0> as Axis>::Remove<S>>, L>)
Divides a mutable array slice into two at an index along the first dimension.
§Panics
Panics if the split point is larger than the number of elements in that dimension, or if the rank is not at least 1.
Sourcepub fn split_axis_at<A>(
&self,
axis: A,
mid: usize,
) -> (View<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>, View<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>)where
A: Axis,
pub fn split_axis_at<A>(
&self,
axis: A,
mid: usize,
) -> (View<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>, View<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>)where
A: Axis,
Divides an array slice into two at an index along the specified dimension.
If the dimension to be divided is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array views have the same layout as the input.
§Panics
Panics if the split point is larger than the number of elements in that dimension, or if the dimension is out of bounds.
Sourcepub fn split_axis_at_mut<A>(
&mut self,
axis: A,
mid: usize,
) -> (ViewMut<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>, ViewMut<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>)where
A: Axis,
pub fn split_axis_at_mut<A>(
&mut self,
axis: A,
mid: usize,
) -> (ViewMut<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>, ViewMut<'_, T, <A as Axis>::Insert<usize, <A as Axis>::Remove<S>>, <<A as Axis>::Init<S> as Shape>::Layout<L>>)where
A: Axis,
Divides a mutable array slice into two at an index along the specified dimension.
If the dimension to be divided is know at compile time, the resulting array shape will maintain constant-sized dimensions. Furthermore, if it is the first dimension the resulting array views have the same layout as the input.
§Panics
Panics if the split point is larger than the number of elements in that dimension, or if the dimension is out of bounds.
Sourcepub fn stride(&self, index: usize) -> isize
pub fn stride(&self, index: usize) -> isize
Returns the distance between elements in the specified dimension.
§Panics
Panics if the dimension is out of bounds.
Sourcepub fn swap<I, J>(&mut self, a: I, b: J)where
I: SliceIndex<T, S, L, Output = T>,
J: SliceIndex<T, S, L, Output = T>,
pub fn swap<I, J>(&mut self, a: I, b: J)where
I: SliceIndex<T, S, L, Output = T>,
J: SliceIndex<T, S, L, Output = T>,
Sourcepub fn swap_axis<A>(&mut self, axis: A, a: usize, b: usize)where
A: Axis,
pub fn swap_axis<A>(&mut self, axis: A, a: usize, b: usize)where
A: Axis,
Swaps the elements in two subarrays after indexing the specified dimension.
§Panics
Panics if a or b are out of bounds.
Sourcepub fn to_array(&self) -> Array<T, S>where
T: Clone,
S: ConstShape,
pub fn to_array(&self) -> Array<T, S>where
T: Clone,
S: ConstShape,
Copies the array slice into a new array.
Sourcepub fn to_tensor(&self) -> Tensor<T, S>where
T: Clone,
pub fn to_tensor(&self) -> Tensor<T, S>where
T: Clone,
Copies the array slice into a new array.
Sourcepub fn transpose(
&self,
) -> View<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
pub fn transpose( &self, ) -> View<'_, T, <S as Shape>::Reverse, <<S as Shape>::Tail as Shape>::Layout<L>>
Returns a transposed array view of the array slice, where the dimensions are reversed.
Trait Implementations§
Source§impl<T, S, A, I> AddAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> AddAssign<I> for Tensor<T, S, A>
Source§fn add_assign(&mut self, rhs: I)
fn add_assign(&mut self, rhs: I)
+= operation. Read moreSource§impl<T, S, A> Apply<T> for Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> Apply<T> for Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§type ZippedWith<I: IntoExpression, F: FnMut((T, <I as IntoIterator>::Item)) -> T> = Tensor<T, S, A>
type ZippedWith<I: IntoExpression, F: FnMut((T, <I as IntoIterator>::Item)) -> T> = Tensor<T, S, A>
Source§fn apply<F>(self, f: F) -> Tensor<T, S, A>where
F: FnMut(T) -> T,
fn apply<F>(self, f: F) -> Tensor<T, S, A>where
F: FnMut(T) -> T,
Source§impl<'a, T, U, S, A> Apply<U> for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, U, S, A> Apply<U> for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§type Output<F: FnMut(&'a T) -> U> = Map<<&'a Tensor<T, S, A> as IntoExpression>::IntoExpr, F>
type Output<F: FnMut(&'a T) -> U> = Map<<&'a Tensor<T, S, A> as IntoExpression>::IntoExpr, F>
Source§type ZippedWith<I: IntoExpression, F: FnMut((&'a T, <I as IntoIterator>::Item)) -> U> = Map<Zip<<&'a Tensor<T, S, A> as IntoExpression>::IntoExpr, <I as IntoExpression>::IntoExpr>, F>
type ZippedWith<I: IntoExpression, F: FnMut((&'a T, <I as IntoIterator>::Item)) -> U> = Map<Zip<<&'a Tensor<T, S, A> as IntoExpression>::IntoExpr, <I as IntoExpression>::IntoExpr>, F>
Source§fn apply<F>(self, f: F) -> <&'a Tensor<T, S, A> as Apply<U>>::Output<F>
fn apply<F>(self, f: F) -> <&'a Tensor<T, S, A> as Apply<U>>::Output<F>
Source§impl<'a, T, U, S, A> Apply<U> for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, U, S, A> Apply<U> for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§type Output<F: FnMut(&'a mut T) -> U> = Map<<&'a mut Tensor<T, S, A> as IntoExpression>::IntoExpr, F>
type Output<F: FnMut(&'a mut T) -> U> = Map<<&'a mut Tensor<T, S, A> as IntoExpression>::IntoExpr, F>
Source§type ZippedWith<I: IntoExpression, F: FnMut((&'a mut T, <I as IntoIterator>::Item)) -> U> = Map<Zip<<&'a mut Tensor<T, S, A> as IntoExpression>::IntoExpr, <I as IntoExpression>::IntoExpr>, F>
type ZippedWith<I: IntoExpression, F: FnMut((&'a mut T, <I as IntoIterator>::Item)) -> U> = Map<Zip<<&'a mut Tensor<T, S, A> as IntoExpression>::IntoExpr, <I as IntoExpression>::IntoExpr>, F>
Source§fn apply<F>(self, f: F) -> <&'a mut Tensor<T, S, A> as Apply<U>>::Output<F>
fn apply<F>(self, f: F) -> <&'a mut Tensor<T, S, A> as Apply<U>>::Output<F>
Source§impl<T, S, A, I> BitAndAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> BitAndAssign<I> for Tensor<T, S, A>
Source§fn bitand_assign(&mut self, rhs: I)
fn bitand_assign(&mut self, rhs: I)
&= operation. Read moreSource§impl<T, S, A, I> BitOrAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> BitOrAssign<I> for Tensor<T, S, A>
Source§fn bitor_assign(&mut self, rhs: I)
fn bitor_assign(&mut self, rhs: I)
|= operation. Read moreSource§impl<T, S, A, I> BitXorAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> BitXorAssign<I> for Tensor<T, S, A>
Source§fn bitxor_assign(&mut self, rhs: I)
fn bitxor_assign(&mut self, rhs: I)
^= operation. Read moreSource§impl<T, S, A> BorrowMut<Slice<T, S>> for Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> BorrowMut<Slice<T, S>> for Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§fn borrow_mut(&mut self) -> &mut Slice<T, S>
fn borrow_mut(&mut self) -> &mut Slice<T, S>
Source§impl<T, S, A, I> DivAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> DivAssign<I> for Tensor<T, S, A>
Source§fn div_assign(&mut self, rhs: I)
fn div_assign(&mut self, rhs: I)
/= operation. Read moreSource§impl<'a, T, A> Extend<&'a T> for Tensor<T, (usize,), A>where
T: Copy,
A: Allocator,
impl<'a, T, A> Extend<&'a T> for Tensor<T, (usize,), A>where
T: Copy,
A: Allocator,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, A> Extend<T> for Tensor<T, (usize,), A>where
A: Allocator,
impl<T, A> Extend<T> for Tensor<T, (usize,), A>where
A: Allocator,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<&[[[[[[T; F]; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U, V)>
impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<&[[[[[[T; F]; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U, V)>
Source§impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<&[[[[[T; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U)>
impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<&[[[[[T; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U)>
Source§impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> From<&[[[[T; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W)>
impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> From<&[[[[T; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W)>
Source§impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> From<&[[[T; C]; B]; A]> for Tensor<T, (X, Y, Z)>
impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> From<&[[[T; C]; B]; A]> for Tensor<T, (X, Y, Z)>
Source§impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<[[[[[[T; F]; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U, V)>
impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<[[[[[[T; F]; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U, V)>
Source§impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[T; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U)>
impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[T; E]; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W, U)>
Source§impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[T; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W)>
impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[T; D]; C]; B]; A]> for Tensor<T, (X, Y, Z, W)>
Source§impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> From<[[[T; C]; B]; A]> for Tensor<T, (X, Y, Z)>
impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> From<[[[T; C]; B]; A]> for Tensor<T, (X, Y, Z)>
Source§impl<T, S> FromExpression<T, S> for Tensor<T, S>where
S: Shape,
impl<T, S> FromExpression<T, S> for Tensor<T, S>where
S: Shape,
Source§fn from_expr<I>(expr: I) -> Tensor<T, S>where
I: IntoExpression<Item = T, Shape = S>,
fn from_expr<I>(expr: I) -> Tensor<T, S>where
I: IntoExpression<Item = T, Shape = S>,
Source§impl<T> FromIterator<T> for Tensor<T, (usize,)>
impl<T> FromIterator<T> for Tensor<T, (usize,)>
Source§impl<'a, T, S, A> IntoExpression for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, S, A> IntoExpression for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<'a, T, S, A> IntoExpression for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, S, A> IntoExpression for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<T, S, A> IntoExpression for Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> IntoExpression for Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<'a, T, S, A> IntoIterator for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, S, A> IntoIterator for &'a Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<'a, T, S, A> IntoIterator for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<'a, T, S, A> IntoIterator for &'a mut Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<T, S, A> IntoIterator for Tensor<T, S, A>where
S: Shape,
A: Allocator,
impl<T, S, A> IntoIterator for Tensor<T, S, A>where
S: Shape,
A: Allocator,
Source§impl<T, S, A, I> MulAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> MulAssign<I> for Tensor<T, S, A>
Source§fn mul_assign(&mut self, rhs: I)
fn mul_assign(&mut self, rhs: I)
*= operation. Read moreSource§impl<T, S, A, I> RemAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> RemAssign<I> for Tensor<T, S, A>
Source§fn rem_assign(&mut self, rhs: I)
fn rem_assign(&mut self, rhs: I)
%= operation. Read moreSource§impl<T, S, A, I> ShlAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> ShlAssign<I> for Tensor<T, S, A>
Source§fn shl_assign(&mut self, rhs: I)
fn shl_assign(&mut self, rhs: I)
<<= operation. Read moreSource§impl<T, S, A, I> ShrAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> ShrAssign<I> for Tensor<T, S, A>
Source§fn shr_assign(&mut self, rhs: I)
fn shr_assign(&mut self, rhs: I)
>>= operation. Read moreSource§impl<T, S, A, I> SubAssign<I> for Tensor<T, S, A>
impl<T, S, A, I> SubAssign<I> for Tensor<T, S, A>
Source§fn sub_assign(&mut self, rhs: I)
fn sub_assign(&mut self, rhs: I)
-= operation. Read moreSource§impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> TryFrom<Tensor<T, (X, Y, Z)>> for [[[T; C]; B]; A]
impl<T, X, Y, Z, const A: usize, const B: usize, const C: usize> TryFrom<Tensor<T, (X, Y, Z)>> for [[[T; C]; B]; A]
Source§impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> TryFrom<Tensor<T, (X, Y, Z, W)>> for [[[[T; D]; C]; B]; A]
impl<T, X, Y, Z, W, const A: usize, const B: usize, const C: usize, const D: usize> TryFrom<Tensor<T, (X, Y, Z, W)>> for [[[[T; D]; C]; B]; A]
Source§impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> TryFrom<Tensor<T, (X, Y, Z, W, U)>> for [[[[[T; E]; D]; C]; B]; A]
impl<T, X, Y, Z, W, U, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> TryFrom<Tensor<T, (X, Y, Z, W, U)>> for [[[[[T; E]; D]; C]; B]; A]
Source§impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> TryFrom<Tensor<T, (X, Y, Z, W, U, V)>> for [[[[[[T; F]; E]; D]; C]; B]; A]
impl<T, X, Y, Z, W, U, V, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> TryFrom<Tensor<T, (X, Y, Z, W, U, V)>> for [[[[[[T; F]; E]; D]; C]; B]; A]
Source§type Error = Tensor<T, (X, Y, Z, W, U, V)>
type Error = Tensor<T, (X, Y, Z, W, U, V)>
impl<T, S, A> Eq for Tensor<T, S, A>
impl<T, S> Owned<T, S> for Tensor<T, S>where
S: Shape,
Auto Trait Implementations§
impl<T, S, A> Freeze for Tensor<T, S, A>where
S: Freeze,
impl<T, S, A> RefUnwindSafe for Tensor<T, S, A>
impl<T, S, A> Send for Tensor<T, S, A>
impl<T, S, A> Sync for Tensor<T, S, A>
impl<T, S, A> Unpin for Tensor<T, S, A>
impl<T, S, A> UnwindSafe for Tensor<T, S, A>
Blanket Implementations§
Source§impl<'short, T, Target> AsGeneralizedMut<'short, &'short mut Target> for T
impl<'short, T, Target> AsGeneralizedMut<'short, &'short mut Target> for T
fn as_generalized_mut(&'short mut self) -> &'short mut Target
Source§impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
fn as_generalized_ref(&'short self) -> &'short Target
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoCloned<T> for T
impl<T> IntoCloned<T> for 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.