pub struct Array<T: Element, D: Dimension> { /* private fields */ }Expand description
Implementations§
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn broadcast_to(
&self,
target_shape: &[usize],
) -> FerrayResult<ArrayView<'_, T, IxDyn>>
pub fn broadcast_to( &self, target_shape: &[usize], ) -> FerrayResult<ArrayView<'_, T, IxDyn>>
Broadcast this array to the given shape, returning a dynamic-rank view.
Uses stride-0 tricks for virtual expansion — no data is copied.
§Errors
Returns FerrayError::BroadcastFailure if the array cannot be broadcast
to the target shape.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn cast<U: Element>(&self, casting: CastKind) -> FerrayResult<Array<U, D>>where
T: CastTo<U>,
pub fn cast<U: Element>(&self, casting: CastKind) -> FerrayResult<Array<U, D>>where
T: CastTo<U>,
Cast this array to element type U with the given safety check.
This is the general-purpose casting method matching NumPy’s
arr.astype(dtype, casting=...). Unlike AsType::astype (which is
restricted to safe widening), this method permits any cast as long
as can_cast(T::dtype(), U::dtype(), casting) returns true.
§Arguments
casting— controls which casts are permitted:CastKind::No/CastKind::Equiv: onlyT == UallowedCastKind::Safe: information-preserving widening onlyCastKind::SameKind: int↔int, float↔float, etc. (may narrow)CastKind::Unsafe: any cast (the NumPy default)
§Errors
Returns FerrayError::InvalidDtype if the requested cast is not
permitted at the chosen safety level.
§Examples
let a = Array::<f64, Ix1>::from_vec(Ix1::new([3]), vec![1.5, 2.7, -3.9]).unwrap();
// f64 -> i32 truncates per `as` semantics
let b = a.cast::<i32>(CastKind::Unsafe).unwrap();
assert_eq!(b.as_slice().unwrap(), &[1, 2, -3]);Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn add_promoted<U>(
&self,
other: &Array<U, D>,
) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
pub fn add_promoted<U>( &self, other: &Array<U, D>, ) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
Add two arrays after promoting both to their common type.
This is the explicit way to perform mixed-type addition (REQ-24).
Implicit mixed-type + does not compile.
Sourcepub fn sub_promoted<U>(
&self,
other: &Array<U, D>,
) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
pub fn sub_promoted<U>( &self, other: &Array<U, D>, ) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
Subtract two arrays after promoting both to their common type.
Sourcepub fn mul_promoted<U>(
&self,
other: &Array<U, D>,
) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
pub fn mul_promoted<U>( &self, other: &Array<U, D>, ) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
Multiply two arrays after promoting both to their common type.
Sourcepub fn div_promoted<U>(
&self,
other: &Array<U, D>,
) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
pub fn div_promoted<U>( &self, other: &Array<U, D>, ) -> FerrayResult<Array<<T as Promoted<U>>::Output, D>>
Divide two arrays after promoting both to their common type.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn t(&self) -> ArrayView<'_, T, D>
pub fn t(&self) -> ArrayView<'_, T, D>
Transposed view (zero-copy). Reverses the axes.
This is the equivalent of NumPy’s .T property.
Sourcepub fn to_vec_flat(&self) -> Vec<T>
pub fn to_vec_flat(&self) -> Vec<T>
Convert to a flat Vec<T> in logical (row-major) order.
Sourcepub fn to_bytes(&self) -> FerrayResult<&[u8]>where
T: Copy,
pub fn to_bytes(&self) -> FerrayResult<&[u8]>where
T: Copy,
Return the raw bytes of the array data.
Only succeeds if the array is contiguous; returns an error otherwise.
Requires T: Copy to guarantee no padding bytes exist.
Sourcepub fn flags(&self) -> ArrayFlags
pub fn flags(&self) -> ArrayFlags
Return flags describing memory properties.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn iter(&self) -> impl Iterator<Item = &T> + '_
pub fn iter(&self) -> impl Iterator<Item = &T> + '_
Iterate over all elements in logical (row-major) order.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> + '_
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> + '_
Mutably iterate over all elements in logical order.
Sourcepub fn indexed_iter(&self) -> impl Iterator<Item = (Vec<usize>, &T)> + '_
pub fn indexed_iter(&self) -> impl Iterator<Item = (Vec<usize>, &T)> + '_
Iterate with multi-dimensional indices.
Yields (Vec<usize>, &T) pairs in logical order. The index vector
has one entry per dimension.
Delegates to ndarray’s cached indexed_iter, which carries a
typed index through the walk (no per-element divmod on a flat
index as the previous hand-rolled implementation did, see
issue #80). The public Vec<usize> return type forces a single
allocation per yielded element; any further win requires an API
change to a streaming iterator or &[usize] signature.
Sourcepub fn flat(&self) -> impl Iterator<Item = &T> + '_
pub fn flat(&self) -> impl Iterator<Item = &T> + '_
Flat iterator — same as iter() but emphasises logical-order traversal.
Sourcepub fn lanes(
&self,
axis: Axis,
) -> FerrayResult<impl Iterator<Item = ArrayView<'_, T, Ix1>> + '_>
pub fn lanes( &self, axis: Axis, ) -> FerrayResult<impl Iterator<Item = ArrayView<'_, T, Ix1>> + '_>
Iterate over lanes (1-D slices) along the given axis.
For a 2-D array with axis=1, this yields each row.
For axis=0, this yields each column.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Sourcepub fn axis_iter(
&self,
axis: Axis,
) -> FerrayResult<impl Iterator<Item = ArrayView<'_, T, IxDyn>> + '_>where
D::NdarrayDim: RemoveAxis,
pub fn axis_iter(
&self,
axis: Axis,
) -> FerrayResult<impl Iterator<Item = ArrayView<'_, T, IxDyn>> + '_>where
D::NdarrayDim: RemoveAxis,
Iterate over sub-arrays along the given axis.
For a 3-D array with shape [2,3,4] and axis=0, this yields
two 2-D views each of shape [3,4].
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Sourcepub fn axis_iter_mut(
&mut self,
axis: Axis,
) -> FerrayResult<impl Iterator<Item = ArrayViewMut<'_, T, IxDyn>> + '_>where
D::NdarrayDim: RemoveAxis,
pub fn axis_iter_mut(
&mut self,
axis: Axis,
) -> FerrayResult<impl Iterator<Item = ArrayViewMut<'_, T, IxDyn>> + '_>where
D::NdarrayDim: RemoveAxis,
Mutably iterate over sub-arrays along the given axis.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn mapv(&self, f: impl Fn(T) -> T) -> Self
pub fn mapv(&self, f: impl Fn(T) -> T) -> Self
Apply a closure to every element, returning a new array.
The closure receives each element by value (cloned) and must return the same type. For type-changing maps, collect via iterators.
Sourcepub fn mapv_inplace(&mut self, f: impl Fn(T) -> T)
pub fn mapv_inplace(&mut self, f: impl Fn(T) -> T)
Apply a closure to every element in place.
Sourcepub fn zip_mut_with(
&mut self,
other: &Array<T, D>,
f: impl Fn(&mut T, &T),
) -> FerrayResult<()>
pub fn zip_mut_with( &mut self, other: &Array<T, D>, f: impl Fn(&mut T, &T), ) -> FerrayResult<()>
Zip this array mutably with another array of the same shape, applying a closure to each pair of elements.
The closure receives (&mut T, &T) — the first element is from
self and can be modified, the second is from other.
§Errors
Returns FerrayError::ShapeMismatch if shapes differ.
Sourcepub fn fold_axis(
&self,
axis: Axis,
init: T,
fold: impl FnMut(&T, &T) -> T,
) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn fold_axis(
&self,
axis: Axis,
init: T,
fold: impl FnMut(&T, &T) -> T,
) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Fold (reduce) along the given axis.
init provides the initial accumulator value for each lane.
The closure receives (accumulator, &element) and must return
the new accumulator.
Returns an array with one fewer dimension (the folded axis removed). The result is always returned as a dynamic-rank array.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Sourcepub fn map_to<U: Element>(&self, f: impl Fn(T) -> U) -> Array<U, D>
pub fn map_to<U: Element>(&self, f: impl Fn(T) -> U) -> Array<U, D>
Apply a closure elementwise, producing an array of a different type.
Unlike mapv which preserves the element type, this allows
mapping to a different Element type.
Sourcepub fn to_dyn(&self) -> Array<T, IxDyn>
pub fn to_dyn(&self) -> Array<T, IxDyn>
Convert this array to a dynamic-rank Array<T, IxDyn>.
This is a cheap conversion (re-wraps the same data) and is needed
to call functions like crate::manipulation::concatenate which
take dynamic-rank slices.
Sourcepub fn into_dyn(self) -> Array<T, IxDyn>
pub fn into_dyn(self) -> Array<T, IxDyn>
Consume this array and return a dynamic-rank Array<T, IxDyn>.
Like Array::to_dyn but takes ownership to avoid the clone.
Sourcepub fn as_standard_layout(&self) -> CowArray<'_, T, D>
pub fn as_standard_layout(&self) -> CowArray<'_, T, D>
Return a C-contiguous (row-major) version of this array, copying only if the current layout is not already C-contiguous (#351).
Equivalent to NumPy’s np.ascontiguousarray. The returned
CowArray borrows from self when no copy is needed, so this
is a zero-cost guard before BLAS calls, SIMD loops, or FFI that
require row-major storage.
Sourcepub fn as_fortran_layout(&self) -> CowArray<'_, T, D>
pub fn as_fortran_layout(&self) -> CowArray<'_, T, D>
Return a Fortran-contiguous (column-major) version of this array, copying only if the current layout is not already F-contiguous (#351).
Equivalent to NumPy’s np.asfortranarray. The returned
CowArray borrows from self when no copy is needed. 1-D arrays
are borrowed because they are trivially both C- and F-contiguous.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn into_ndarray(self) -> Array<T, D::NdarrayDim>
pub fn into_ndarray(self) -> Array<T, D::NdarrayDim>
Unwrap to the internal ndarray::Array. Crate-internal.
Consume this ferray array and return the underlying
ndarray::Array, preserving shape and layout.
This is the escape hatch for interop with crates that already
work with ndarray (notably numpy/PyO3’s
[PyArray::from_owned_array], which avoids a reshape round-trip).
Calls through to a move — no allocation or copy.
Sourcepub fn from_elem(dim: D, elem: T) -> FerrayResult<Self>
pub fn from_elem(dim: D, elem: T) -> FerrayResult<Self>
Create a new array filled with the given value.
§Errors
Returns FerrayError::InvalidValue if the shape has zero dimensions
but D is a fixed-rank type with nonzero rank, or vice versa.
Sourcepub fn zeros(dim: D) -> FerrayResult<Self>
pub fn zeros(dim: D) -> FerrayResult<Self>
Create a new array filled with zeros.
Sourcepub fn ones(dim: D) -> FerrayResult<Self>
pub fn ones(dim: D) -> FerrayResult<Self>
Create a new array filled with ones.
Sourcepub fn from_vec(dim: D, data: Vec<T>) -> FerrayResult<Self>
pub fn from_vec(dim: D, data: Vec<T>) -> FerrayResult<Self>
Create an array from a flat vector and a shape.
§Errors
Returns FerrayError::ShapeMismatch if data.len() does not equal
the product of the shape dimensions.
Sourcepub fn from_vec_f(dim: D, data: Vec<T>) -> FerrayResult<Self>
pub fn from_vec_f(dim: D, data: Vec<T>) -> FerrayResult<Self>
Create an array from a flat vector with Fortran (column-major) layout.
§Errors
Returns FerrayError::ShapeMismatch if lengths don’t match.
Sourcepub fn from_iter_1d(iter: impl IntoIterator<Item = T>) -> FerrayResult<Self>
pub fn from_iter_1d(iter: impl IntoIterator<Item = T>) -> FerrayResult<Self>
Create a 1-D array from an iterator.
This only makes sense for D = Ix1; for other dimensions,
collect first and use from_vec.
Sourcepub fn layout(&self) -> MemoryLayout
pub fn layout(&self) -> MemoryLayout
Return the memory layout of this array.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Return a mutable raw pointer to the first element.
Sourcepub fn as_slice(&self) -> Option<&[T]>
pub fn as_slice(&self) -> Option<&[T]>
Return the data as a contiguous slice, if the layout allows it.
Sourcepub fn as_slice_mut(&mut self) -> Option<&mut [T]>
pub fn as_slice_mut(&mut self) -> Option<&mut [T]>
Return the data as a contiguous mutable slice, if the layout allows it.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn sum(&self) -> Twhere
T: Add<Output = T>,
pub fn sum(&self) -> Twhere
T: Add<Output = T>,
Sum of all elements (whole-array reduction).
Returns Element::zero() for an empty array.
§Examples
let a = Array::<f64, Ix1>::from_vec(Ix1::new([3]), vec![1.0, 2.0, 3.0]).unwrap();
assert_eq!(a.sum(), 6.0);Sourcepub fn sum_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>
pub fn sum_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>
Sum along the given axis. Returns an array with one fewer dimension.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Sourcepub fn prod(&self) -> Twhere
T: Mul<Output = T>,
pub fn prod(&self) -> Twhere
T: Mul<Output = T>,
Product of all elements.
Returns Element::one() for an empty array.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn min(&self) -> Option<T>
pub fn min(&self) -> Option<T>
Minimum value across the entire array.
Returns None if the array is empty. NaN values follow NumPy semantics:
once a NaN is seen the result stays NaN, detected via self-comparison
(x.partial_cmp(&x).is_none()).
Sourcepub fn max(&self) -> Option<T>
pub fn max(&self) -> Option<T>
Maximum value across the entire array.
Returns None if the array is empty. NaN values propagate per NumPy.
Sourcepub fn min_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn min_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Minimum value along an axis.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim, or
FerrayError::ShapeMismatch if the resulting axis would be empty.
Sourcepub fn max_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn max_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Maximum value along an axis.
See Array::min_axis for error semantics.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn mean(&self) -> Option<T>
pub fn mean(&self) -> Option<T>
Arithmetic mean of all elements. Returns None for an empty array.
Sourcepub fn mean_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn mean_axis(&self, axis: Axis) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Mean along an axis.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn sorted(&self) -> Array<T, Ix1>
pub fn sorted(&self) -> Array<T, Ix1>
Return a sorted 1-D copy of the flattened array in ascending order.
Equivalent to np.sort(a.ravel()). NaN values (for floating-point
element types) are ordered last, matching NumPy’s convention.
For axis-aware sorting or algorithm selection (mergesort, heapsort),
use ferray_stats::sorting::sort.
Sourcepub fn argsort(&self) -> Array<u64, Ix1>
pub fn argsort(&self) -> Array<u64, Ix1>
Return the indices that would sort the flattened array in ascending order.
Equivalent to np.argsort(a.ravel()). The returned indices are
u64 to match NumPy’s default index dtype. NaN values are sent
to the tail of the sort order, matching Array::sorted.
For axis-aware argsort, use ferray_stats::sorting::argsort.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn view_mut(&mut self) -> ArrayViewMut<'_, T, D>
pub fn view_mut(&mut self) -> ArrayViewMut<'_, T, D>
Create a mutable view of this array.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn index_select(
&self,
axis: Axis,
indices: &[isize],
) -> FerrayResult<Array<T, IxDyn>>
pub fn index_select( &self, axis: Axis, indices: &[isize], ) -> FerrayResult<Array<T, IxDyn>>
Select elements along an axis using an array of indices.
This is advanced (fancy) indexing — it always returns a copy.
The result has the same number of dimensions as the input, but
the size along axis is replaced by indices.len().
Negative indices are supported (counting from end).
§Errors
AxisOutOfBoundsifaxis >= ndimIndexOutOfBoundsif any index is out of range
Sourcepub fn boolean_index(
&self,
mask: &Array<bool, D>,
) -> FerrayResult<Array<T, Ix1>>
pub fn boolean_index( &self, mask: &Array<bool, D>, ) -> FerrayResult<Array<T, Ix1>>
Select elements using a boolean mask.
Returns a 1-D array containing elements where mask is true.
This is always a copy.
The mask must be broadcastable to the array’s shape, or have the same total number of elements. When the mask is 1-D and the array is N-D, the mask is applied to the flattened array.
§Errors
ShapeMismatchif mask shape is incompatible
Sourcepub fn boolean_index_flat(
&self,
mask: &Array<bool, Ix1>,
) -> FerrayResult<Array<T, Ix1>>
pub fn boolean_index_flat( &self, mask: &Array<bool, Ix1>, ) -> FerrayResult<Array<T, Ix1>>
Boolean indexing with a flat mask (1-D mask on N-D array).
The mask is applied to the flattened (row-major) array.
§Errors
ShapeMismatchifmask.len() != self.size()
Sourcepub fn boolean_index_assign(
&mut self,
mask: &Array<bool, D>,
value: T,
) -> FerrayResult<()>
pub fn boolean_index_assign( &mut self, mask: &Array<bool, D>, value: T, ) -> FerrayResult<()>
Assign a scalar value to elements selected by a boolean mask.
Equivalent to a[mask] = value in NumPy.
§Errors
ShapeMismatchif mask shape differs from array shape
Sourcepub fn boolean_index_assign_array(
&mut self,
mask: &Array<bool, D>,
values: &Array<T, Ix1>,
) -> FerrayResult<()>
pub fn boolean_index_assign_array( &mut self, mask: &Array<bool, D>, values: &Array<T, Ix1>, ) -> FerrayResult<()>
Assign values from an array to elements selected by a boolean mask.
values must have exactly as many elements as mask has true
entries.
§Errors
ShapeMismatchif mask shape differs or values length mismatches
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> FerrayResult<ArrayView<'_, T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> FerrayResult<ArrayView<'_, T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Index into the array along a given axis, removing that axis.
Equivalent to a[i] for axis 0, or a[:, i] for axis 1, etc.
Returns a view with one fewer dimension (dynamic-rank).
§Errors
AxisOutOfBoundsifaxis >= ndimIndexOutOfBoundsifindexis out of range (supports negative)
Sourcepub fn slice_axis(
&self,
axis: Axis,
spec: SliceSpec,
) -> FerrayResult<ArrayView<'_, T, IxDyn>>
pub fn slice_axis( &self, axis: Axis, spec: SliceSpec, ) -> FerrayResult<ArrayView<'_, T, IxDyn>>
Slice the array along a given axis, returning a view.
The returned view shares data with the source (zero-copy).
§Errors
AxisOutOfBoundsifaxis >= ndimInvalidValueif step is zero
Sourcepub fn slice_axis_mut(
&mut self,
axis: Axis,
spec: SliceSpec,
) -> FerrayResult<ArrayViewMut<'_, T, IxDyn>>
pub fn slice_axis_mut( &mut self, axis: Axis, spec: SliceSpec, ) -> FerrayResult<ArrayViewMut<'_, T, IxDyn>>
Sourcepub fn slice_multi(
&self,
specs: &[SliceSpec],
) -> FerrayResult<ArrayView<'_, T, IxDyn>>
pub fn slice_multi( &self, specs: &[SliceSpec], ) -> FerrayResult<ArrayView<'_, T, IxDyn>>
Multi-axis slicing: apply a slice specification to each axis.
specs must have length equal to ndim(). For axes you don’t
want to slice, pass SliceSpec::full().
§Errors
InvalidValueifspecs.len() != ndim()- Any errors from individual axis slicing
Sourcepub fn insert_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'_, T, IxDyn>>
pub fn insert_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'_, T, IxDyn>>
Insert a new axis of length 1 at the given position.
This is equivalent to np.expand_dims or np.newaxis.
Returns a dynamic-rank view with one more dimension.
§Errors
AxisOutOfBoundsifaxis > ndim
Sourcepub fn remove_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'_, T, IxDyn>>
pub fn remove_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'_, T, IxDyn>>
Remove an axis of length 1.
This is equivalent to np.squeeze for a single axis.
Returns a dynamic-rank view with one fewer dimension.
§Errors
AxisOutOfBoundsifaxis >= ndimInvalidValueif the axis has size != 1
Sourcepub fn flat_index(&self, index: isize) -> FerrayResult<&T>
pub fn flat_index(&self, index: isize) -> FerrayResult<&T>
Index into the array with a flat (linear) index.
Elements are ordered in row-major (C) order. The flat index is converted to a multi-dimensional index via unravel, then stride arithmetic computes the physical offset in O(ndim) time.
§Errors
Returns IndexOutOfBounds if the index is out of range.
Source§impl<T: Element, D: Dimension> Array<T, D>
impl<T: Element, D: Dimension> Array<T, D>
Sourcepub fn put(&mut self, indices: &[isize], values: &[T]) -> FerrayResult<()>
pub fn put(&mut self, indices: &[isize], values: &[T]) -> FerrayResult<()>
Put values into the flattened array at the given indices.
Equivalent to np.put(a, ind, v). Modifies the array in-place.
Indices refer to the flattened (row-major) array.
Values are cycled if fewer than indices.
§Errors
IndexOutOfBoundsif any index is out of rangeInvalidValueif values is empty
Sourcepub fn put_along_axis(
&mut self,
indices: &[isize],
values: &Array<T, IxDyn>,
axis: Axis,
) -> FerrayResult<()>where
D::NdarrayDim: RemoveAxis,
pub fn put_along_axis(
&mut self,
indices: &[isize],
values: &Array<T, IxDyn>,
axis: Axis,
) -> FerrayResult<()>where
D::NdarrayDim: RemoveAxis,
Put values along an axis at specified indices.
For each index position along axis, assigns the values from the
corresponding sub-array of values.
§Errors
AxisOutOfBoundsifaxis >= ndimIndexOutOfBoundsif any index is out of range
Sourcepub fn fill_diagonal(&mut self, val: T)
pub fn fill_diagonal(&mut self, val: T)
Fill the main diagonal of a 2-D (or N-D) array with a value.
For N-D arrays, the diagonal consists of indices where all
index values are equal: a[i, i, ..., i].
Equivalent to np.fill_diagonal(a, val).
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn add_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Add<Output = T>,
pub fn add_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Add<Output = T>,
Elementwise add with NumPy broadcasting across arbitrary ranks.
Returns a dynamic-rank Array<T, IxDyn> so that mixed-rank inputs
(e.g. 1D + 2D) can produce a result whose rank is determined at
runtime. For same-rank inputs prefer the + operator.
§Errors
Returns FerrayError::ShapeMismatch if shapes are not broadcast-compatible.
Sourcepub fn sub_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Sub<Output = T>,
pub fn sub_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Sub<Output = T>,
Elementwise subtract with NumPy broadcasting across arbitrary ranks.
See Array::add_broadcast for details.
Sourcepub fn mul_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Mul<Output = T>,
pub fn mul_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Mul<Output = T>,
Elementwise multiply with NumPy broadcasting across arbitrary ranks.
See Array::add_broadcast for details.
Sourcepub fn div_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Div<Output = T>,
pub fn div_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Div<Output = T>,
Elementwise divide with NumPy broadcasting across arbitrary ranks.
See Array::add_broadcast for details.
Sourcepub fn rem_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Rem<Output = T>,
pub fn rem_broadcast<D2: Dimension>(
&self,
other: &Array<T, D2>,
) -> FerrayResult<Array<T, IxDyn>>where
T: Rem<Output = T>,
Elementwise remainder with NumPy broadcasting across arbitrary ranks.
See Array::add_broadcast for details.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn add_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Add<Output = T>,
pub fn add_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Add<Output = T>,
In-place elementwise add: self[i] += other[i]. other is broadcast
into self.shape(); the destination shape never changes.
Prefer this over self = (&self + &other)? for large arrays — it
avoids allocating a new result buffer.
§Errors
Returns FerrayError::ShapeMismatch if other.shape() cannot be
broadcast into self.shape().
Sourcepub fn sub_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Sub<Output = T>,
pub fn sub_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Sub<Output = T>,
In-place elementwise subtract. See Array::add_inplace.
Sourcepub fn mul_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Mul<Output = T>,
pub fn mul_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Mul<Output = T>,
In-place elementwise multiply. See Array::add_inplace.
Sourcepub fn div_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Div<Output = T>,
pub fn div_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Div<Output = T>,
In-place elementwise divide. See Array::add_inplace.
Sourcepub fn rem_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Rem<Output = T>,
pub fn rem_inplace(&mut self, other: &Array<T, D>) -> FerrayResult<()>where
T: Rem<Output = T>,
In-place elementwise remainder. See Array::add_inplace.
Source§impl<T, D> Array<T, D>
impl<T, D> Array<T, D>
Sourcepub fn copy_from_where<D2: Dimension, D3: Dimension>(
&mut self,
src: &Array<T, D2>,
mask: &Array<bool, D3>,
) -> FerrayResult<()>
pub fn copy_from_where<D2: Dimension, D3: Dimension>( &mut self, src: &Array<T, D2>, mask: &Array<bool, D3>, ) -> FerrayResult<()>
Copy values from src into self at positions where mask is true,
broadcasting both inputs to self.shape().
See copyto_where for the free-function form and full semantics.
§Errors
Returns FerrayError::ShapeMismatch if src or mask cannot be
broadcast into self.shape(). On error self is left untouched.
Trait Implementations§
Source§impl<T, D> AddAssign<T> for Array<T, D>
impl<T, D> AddAssign<T> for Array<T, D>
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<T: Element, D: Dimension> AsRawBuffer for Array<T, D>
impl<T: Element, D: Dimension> AsRawBuffer for Array<T, D>
Source§fn raw_strides_bytes(&self) -> Vec<isize>
fn raw_strides_bytes(&self) -> Vec<isize>
Source§fn is_c_contiguous(&self) -> bool
fn is_c_contiguous(&self) -> bool
Source§fn is_f_contiguous(&self) -> bool
fn is_f_contiguous(&self) -> bool
Source§impl<T: Element, D: Dimension> AsType<D> for Array<T, D>
Available on crate feature std only.
impl<T: Element, D: Dimension> AsType<D> for Array<T, D>
std only.Source§fn astype<U: Element>(&self) -> FerrayResult<Array<U, D>>where
Self: AsTypeInner<U, D>,
fn astype<U: Element>(&self) -> FerrayResult<Array<U, D>>where
Self: AsTypeInner<U, D>,
U, returning a new array. Read moreSource§impl<T, U, D> AsTypeInner<U, D> for Array<T, D>
Available on crate feature std only.Blanket implementation: any T that can PromoteTo can astype.
impl<T, U, D> AsTypeInner<U, D> for Array<T, D>
std only.Blanket implementation: any T that can PromoteTo can astype.
Source§fn astype_inner(&self) -> FerrayResult<Array<U, D>>
fn astype_inner(&self) -> FerrayResult<Array<U, D>>
Source§impl<T, D> DivAssign<T> for Array<T, D>
impl<T, D> DivAssign<T> for Array<T, D>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T, D> MulAssign<T> for Array<T, D>
impl<T, D> MulAssign<T> for Array<T, D>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T, D> RemAssign<T> for Array<T, D>
impl<T, D> RemAssign<T> for Array<T, D>
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%= operation. Read moreSource§impl<T, D> SubAssign<T> for Array<T, D>
impl<T, D> SubAssign<T> for Array<T, D>
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more