pub struct MaskedArray<T: Element, D: Dimension> { /* private fields */ }Expand description
A masked array that pairs data with a boolean mask.
Each element position has a corresponding mask bit:
truemeans the element is masked (invalid / missing)falsemeans the element is valid
All operations (arithmetic, reductions, ufuncs) respect the mask by skipping masked elements.
The fill_value field is the replacement value for masked positions when
the masked array participates in operations or when MaskedArray::filled
is called without an explicit override. It defaults to T::zero().
§Nomask sentinel (#506)
When a MaskedArray is constructed via MaskedArray::from_data
the mask is logically “all-false” but is NOT allocated as a full
Array<bool, D> up front — the lazy OnceLock inside stores
nothing until the first call to MaskedArray::mask. For arrays
that never touch their mask (e.g. masked ops that short-circuit
via MaskedArray::has_real_mask), this saves a full bool-sized
allocation proportional to the data size.
The .mask() accessor still returns &Array<bool, D> so all
existing code continues to work unchanged; the cost is one
lazy allocation on first access. Hot-path code that wants to
avoid the materialization should check has_real_mask() first
and skip any mask work when it returns false.
Implementations§
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn prod(&self) -> FerrayResult<T>
pub fn prod(&self) -> FerrayResult<T>
Product of unmasked elements. Returns T::one() for the all-masked case.
§Errors
Returns an error only for internal failures.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn cumsum_flat(&self) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn cumsum_flat(&self) -> FerrayResult<MaskedArray<T, Ix1>>
Cumulative sum over unmasked elements (mask propagates: each output position carries the same mask as the input). Masked positions contribute zero to the running total.
§Errors
Returns an error if internal array construction fails.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn cumprod_flat(&self) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn cumprod_flat(&self) -> FerrayResult<MaskedArray<T, Ix1>>
Cumulative product over unmasked elements (mask propagates). Masked positions contribute one to the running product.
§Errors
Returns an error if internal array construction fails.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn argmin(&self) -> FerrayResult<usize>
pub fn argmin(&self) -> FerrayResult<usize>
Flat index of the minimum unmasked element.
§Errors
Returns FerrayError::InvalidValue if every element is masked.
Sourcepub fn argmax(&self) -> FerrayResult<usize>
pub fn argmax(&self) -> FerrayResult<usize>
Flat index of the maximum unmasked element.
§Errors
Returns FerrayError::InvalidValue if every element is masked.
Sourcepub fn ptp(&self) -> FerrayResult<T>where
T: Sub<Output = T>,
pub fn ptp(&self) -> FerrayResult<T>where
T: Sub<Output = T>,
Peak-to-peak range over unmasked elements (max - min).
§Errors
Returns FerrayError::InvalidValue if every element is masked.
Source§impl<T, D> MaskedArray<T, D>where
T: Element + Copy + PartialOrd + FromPrimitive + Add<Output = T> + Div<Output = T>,
D: Dimension,
impl<T, D> MaskedArray<T, D>where
T: Element + Copy + PartialOrd + FromPrimitive + Add<Output = T> + Div<Output = T>,
D: Dimension,
Sourcepub fn median(&self) -> FerrayResult<T>
pub fn median(&self) -> FerrayResult<T>
Median of unmasked elements (interpolated between the two middle values for an even count).
§Errors
Returns FerrayError::InvalidValue if every element is masked.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn average(&self, weights: Option<&Array<T, D>>) -> FerrayResult<T>
pub fn average(&self, weights: Option<&Array<T, D>>) -> FerrayResult<T>
Weighted average of unmasked elements.
weights must be Some(Array<T, D>) of the same shape as self,
or None (delegates to MaskedArray::mean).
§Errors
Returns FerrayError::ShapeMismatch if weights shape differs, or
FerrayError::InvalidValue if the weight sum over unmasked
elements is zero (or every element is masked).
Sourcepub fn anom(&self) -> FerrayResult<MaskedArray<T, D>>
pub fn anom(&self) -> FerrayResult<MaskedArray<T, D>>
Anomaly array: self - mean(self). Returns a masked array of the
same shape with the same mask.
Equivalent to numpy.ma.anom.
§Errors
Returns FerrayError::InvalidValue if every element is masked.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn clip(&self, a_min: T, a_max: T) -> FerrayResult<MaskedArray<T, D>>
pub fn clip(&self, a_min: T, a_max: T) -> FerrayResult<MaskedArray<T, D>>
Clip each unmasked element to [a_min, a_max]. Masked elements
pass through unchanged. Equivalent to numpy.ma.clip.
§Errors
Returns an error if internal array construction fails.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn repeat(&self, repeats: usize) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn repeat(&self, repeats: usize) -> FerrayResult<MaskedArray<T, Ix1>>
Repeat each unmasked element repeats times along the flat axis.
Always returns a 1-D masked array.
Equivalent to numpy.ma.repeat(arr, repeats) with default flat axis.
§Errors
Returns an error if internal array construction fails.
Sourcepub fn atleast_1d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn atleast_1d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
Promote to at least 1-D. Scalar (0-D) becomes shape (1,).
§Errors
Returns an error if internal array construction fails.
Sourcepub fn atleast_2d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn atleast_2d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
Promote to at least 2-D. 0-D → (1,1); 1-D (N,) → (1, N).
§Errors
Returns an error if internal array construction fails.
Sourcepub fn atleast_3d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn atleast_3d(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
Promote to at least 3-D. See atleast_3d for the rank ladder.
§Errors
Returns an error if internal array construction fails.
Sourcepub fn expand_dims(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn expand_dims(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Insert an axis of length 1 at the given position.
§Errors
Returns FerrayError::AxisOutOfBounds if axis > ndim.
Source§impl<T> MaskedArray<T, Ix2>
impl<T> MaskedArray<T, Ix2>
Sourcepub fn diagonal(&self, k: isize) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn diagonal(&self, k: isize) -> FerrayResult<MaskedArray<T, Ix1>>
Extract the k-th diagonal of a 2-D masked array as a 1-D masked array.
Equivalent to numpy.ma.diagonal for the 2-D case.
§Errors
Returns an error if internal array construction fails.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn ma_dot_flat(&self, other: &MaskedArray<T, D>) -> FerrayResult<T>
pub fn ma_dot_flat(&self, other: &MaskedArray<T, D>) -> FerrayResult<T>
Inner product of two masked arrays as flat 1-D vectors. Masked positions on either side contribute zero.
§Errors
Returns FerrayError::ShapeMismatch if total element counts differ.
Source§impl<T> MaskedArray<T, Ix2>
impl<T> MaskedArray<T, Ix2>
Sourcepub fn trace(&self, k: isize) -> FerrayResult<T>
pub fn trace(&self, k: isize) -> FerrayResult<T>
Trace (sum of diagonal) of a 2-D masked array. Masked diagonal elements contribute zero.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn filled(&self, fill_value: T) -> FerrayResult<Array<T, D>>
pub fn filled(&self, fill_value: T) -> FerrayResult<Array<T, D>>
Return a regular array with masked positions replaced by fill_value.
Unmasked positions retain their original data values.
§Errors
Returns an error only for internal failures.
Sourcepub fn filled_default(&self) -> FerrayResult<Array<T, D>>
pub fn filled_default(&self) -> FerrayResult<Array<T, D>>
Return a regular array with masked positions replaced by the array’s
stored MaskedArray::fill_value.
Equivalent to NumPy’s arr.filled() with no argument. Use MaskedArray::filled
to override the fill value for a single call.
§Errors
Returns an error only for internal failures.
Sourcepub fn compressed(&self) -> FerrayResult<Array<T, Ix1>>
pub fn compressed(&self) -> FerrayResult<Array<T, Ix1>>
Return a 1-D array containing only the unmasked elements.
The order is the logical (row-major) iteration order of the original array, with masked elements removed.
§Errors
Returns an error only for internal failures.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn into_data(self) -> Array<T, D>
pub fn into_data(self) -> Array<T, D>
Consume the masked array and return its underlying data array, dropping the mask.
Use MaskedArray::filled_default (or MaskedArray::filled) if
you want masked positions replaced by a sentinel value before
dropping the mask.
Sourcepub fn apply_unary<F>(&self, f: F) -> FerrayResult<Self>
pub fn apply_unary<F>(&self, f: F) -> FerrayResult<Self>
Apply a unary function to the underlying data and re-attach the mask, propagating it to the result.
The function f is called on the entire data array — masked
positions are processed alongside unmasked ones, but their values
in the result are immediately overwritten with the masked array’s
fill_value. This matches NumPy’s __array_ufunc__ semantics where
ufuncs run over the raw data and the mask is propagated separately.
§Example
// Apply ferray-ufunc::sin to a masked f64 array:
let result = ma.apply_unary(|arr| ferray_ufunc::sin(arr))?;§Errors
Forwards any error from f.
Sourcepub fn apply_unary_to<U, F>(
&self,
f: F,
default_for_masked: U,
) -> FerrayResult<MaskedArray<U, D>>
pub fn apply_unary_to<U, F>( &self, f: F, default_for_masked: U, ) -> FerrayResult<MaskedArray<U, D>>
Apply a unary function that maps T -> U, propagating the mask.
This is the type-changing variant of MaskedArray::apply_unary,
useful for predicates like isnan that return Array<bool, D> from
Array<T, D>. Masked positions in the result hold the explicitly
supplied default_for_masked value.
§Errors
Forwards any error from f. Returns FerrayError::ShapeMismatch if
f produces an array with a different shape.
Sourcepub fn apply_binary<F>(&self, other: &Self, f: F) -> FerrayResult<Self>
pub fn apply_binary<F>(&self, other: &Self, f: F) -> FerrayResult<Self>
Apply a binary function to two masked arrays, propagating the mask union. Both inputs must have the same shape.
The function f is called on the underlying data of both inputs
(no broadcasting — use crate::masked_add-style functions for
that). The result mask is the OR of the two input masks; masked
positions in the data are overwritten with the receiver’s fill_value.
§Example
let result = a.apply_binary(&b, |x, y| ferray_ufunc::power(x, y))?;§Errors
Returns FerrayError::ShapeMismatch if shapes differ. Forwards any
error from f.
Source§impl<T: Element + Copy, D: Dimension> MaskedArray<T, D>
impl<T: Element + Copy, D: Dimension> MaskedArray<T, D>
Sourcepub fn reshape(
&self,
new_shape: &[usize],
) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn reshape( &self, new_shape: &[usize], ) -> FerrayResult<MaskedArray<T, IxDyn>>
Return a new MaskedArray with the given shape.
Equivalent to numpy.ma.reshape(a, new_shape). The result is a
dynamic-rank MaskedArray<T, IxDyn>. The total element count
must match; mask and data are reshaped in lockstep so their
logical positions remain aligned. The fill_value and
hard_mask flag are preserved.
§Errors
FerrayError::ShapeMismatchifnew_shape’s product does not equalself.size().
Sourcepub fn ravel(&self) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn ravel(&self) -> FerrayResult<MaskedArray<T, Ix1>>
Return a 1-D MaskedArray with the same total element count.
Equivalent to numpy.ma.ravel(a). Preserves fill_value and
hard_mask.
Sourcepub fn flatten(&self) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn flatten(&self) -> FerrayResult<MaskedArray<T, Ix1>>
Alias for MaskedArray::ravel.
Equivalent to numpy.ma.flatten(a).
Sourcepub fn transpose(
&self,
axes: Option<&[usize]>,
) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn transpose( &self, axes: Option<&[usize]>, ) -> FerrayResult<MaskedArray<T, IxDyn>>
Return a transposed MaskedArray by permuting axes.
When axes is None, reverses the axis order (equivalent to
numpy.ma.transpose(a) or a.T). When Some(ax), uses the
supplied permutation. Both data and mask are permuted together
so their logical positions remain aligned.
Returns a dynamic-rank result because the permutation is chosen at runtime.
§Errors
FerrayError::InvalidValueifaxesis the wrong length or not a valid permutation.
Sourcepub fn t(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn t(&self) -> FerrayResult<MaskedArray<T, IxDyn>>
Return a transposed MaskedArray with reversed axis order.
Shorthand for self.transpose(None), equivalent to NumPy’s
.T property.
Sourcepub fn squeeze(
&self,
axis: Option<usize>,
) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn squeeze( &self, axis: Option<usize>, ) -> FerrayResult<MaskedArray<T, IxDyn>>
Remove size-1 axes from the masked array.
Equivalent to numpy.ma.squeeze(a). When axis is None,
removes every axis whose length is 1. When Some(ax), only
the specified axis (which must have length 1) is removed.
The single-axis restriction mirrors ferray_core::manipulation::squeeze
— chain multiple calls if you need to drop several axes.
Source§impl<T: Element + Copy, D: Dimension> MaskedArray<T, D>
impl<T: Element + Copy, D: Dimension> MaskedArray<T, D>
Sourcepub fn get_flat(&self, flat_idx: usize) -> FerrayResult<(T, bool)>
pub fn get_flat(&self, flat_idx: usize) -> FerrayResult<(T, bool)>
Get a single element by flat (row-major) index.
Returns Ok((value, is_masked)) where is_masked is true
when the mask bit at that position is set. Returns an error if
the index is out of bounds.
Returning the raw (T, bool) pair lets callers decide what to
do with masked values instead of forcing a fill-value
substitution — if you want the NumPy-style masked scalar
behavior, check is_masked and fall back to self.fill_value().
§Errors
FerrayError::IndexOutOfBoundsifflat_idx >= self.size().
Sourcepub fn boolean_index(
&self,
bool_mask: &Array<bool, D>,
) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn boolean_index( &self, bool_mask: &Array<bool, D>, ) -> FerrayResult<MaskedArray<T, Ix1>>
Select elements where bool_mask is true.
Equivalent to a[bool_mask] in NumPy boolean indexing. Returns
a 1-D MaskedArray containing only positions where the
supplied bool_mask is true; each selected position carries
through both its value and its original mask bit. The
bool_mask must have exactly the same shape as self.
§Errors
FerrayError::ShapeMismatchifbool_mask.shape() != self.shape().
Sourcepub fn take(&self, indices: &[usize]) -> FerrayResult<MaskedArray<T, Ix1>>where
D: Dimension,
pub fn take(&self, indices: &[usize]) -> FerrayResult<MaskedArray<T, Ix1>>where
D: Dimension,
Fancy index selection from a 1-D MaskedArray.
Equivalent to a[indices] in NumPy fancy indexing (restricted
to 1-D because higher-rank fancy indexing has NumPy-specific
broadcasting semantics that would be easy to get subtly wrong).
Returns a new 1-D MaskedArray whose elements are picked from
self at the supplied flat positions.
Each result position carries through both the selected value and its original mask bit.
§Errors
FerrayError::IndexOutOfBoundsif any index is out of range.
Source§impl<T: Element, D: Dimension> MaskedArray<T, D>
impl<T: Element, D: Dimension> MaskedArray<T, D>
Sourcepub const fn harden_mask(&mut self) -> FerrayResult<()>
pub const fn harden_mask(&mut self) -> FerrayResult<()>
Harden the mask: prevent subsequent assignments from clearing mask bits.
After this call, any attempt to set a mask bit to false via
set_mask_flat or set_mask will be silently ignored.
§Errors
This function does not currently error but returns Result for API
consistency.
Sourcepub const fn soften_mask(&mut self) -> FerrayResult<()>
pub const fn soften_mask(&mut self) -> FerrayResult<()>
Soften the mask: allow subsequent assignments to clear mask bits.
§Errors
This function does not currently error but returns Result for API
consistency.
Source§impl<T: Element, D: Dimension> MaskedArray<T, D>
impl<T: Element, D: Dimension> MaskedArray<T, D>
Sourcepub fn new(data: Array<T, D>, mask: Array<bool, D>) -> FerrayResult<Self>
pub fn new(data: Array<T, D>, mask: Array<bool, D>) -> FerrayResult<Self>
Create a new masked array from data and mask arrays.
The fill_value defaults to T::zero(). Use MaskedArray::with_fill_value
to set a custom replacement value.
§Errors
Returns FerrayError::ShapeMismatch if data and mask shapes differ.
Sourcepub fn from_data(data: Array<T, D>) -> FerrayResult<Self>
pub fn from_data(data: Array<T, D>) -> FerrayResult<Self>
Create a masked array with no masked elements (all-false mask).
Does NOT allocate the mask up front — the array is in the
nomask-sentinel state (#506) until MaskedArray::mask is
explicitly called. For code that only uses data() or
short-circuits via MaskedArray::has_real_mask, this saves
a full-sized bool allocation.
§Errors
Always returns Ok — the FerrayResult is preserved for API
parity with the previous eager implementation.
Sourcepub const fn has_real_mask(&self) -> bool
pub const fn has_real_mask(&self) -> bool
Return true if this masked array holds a real (explicitly
provided or materialized) mask. Returns false when the array
is in the nomask-sentinel state and the mask is logically
all-false.
Hot-path iteration code should branch on this flag to skip
mask scanning entirely when it returns false (#506).
Sourcepub const fn fill_value(&self) -> Twhere
T: Copy,
pub const fn fill_value(&self) -> Twhere
T: Copy,
Return the fill value used to replace masked positions.
See MaskedArray::with_fill_value for setting it.
Sourcepub fn with_fill_value(self, fill_value: T) -> Self
pub fn with_fill_value(self, fill_value: T) -> Self
Set the fill value, returning the modified array.
The fill value is used by MaskedArray::filled (when called
without an explicit override) and by arithmetic operations as the
replacement for masked positions in the result data.
Sourcepub fn set_fill_value(&mut self, fill_value: T)
pub fn set_fill_value(&mut self, fill_value: T)
Replace the fill value in place.
Sourcepub fn mask(&self) -> &Array<bool, D>
pub fn mask(&self) -> &Array<bool, D>
Return a reference to the mask array.
If the array is in the nomask-sentinel state (constructed via
MaskedArray::from_data or otherwise) this lazily allocates
a full all-false Array<bool, D> and caches it for subsequent
calls. Use MaskedArray::has_real_mask to check whether the
mask is known to be trivial first, and skip calling .mask()
entirely on the hot path when you can.
Sourcepub fn mask_opt(&self) -> Option<&Array<bool, D>>
pub fn mask_opt(&self) -> Option<&Array<bool, D>>
Return a reference to the mask array if one has been
materialized, or None when the array is still in the
nomask-sentinel state.
Unlike MaskedArray::mask, this does NOT trigger lazy
allocation — it’s the fast-path query for hot code that
wants to branch on whether any mask bits are set (#506).
Sourcepub const fn data_mut(&mut self) -> &mut Array<T, D>
pub const fn data_mut(&mut self) -> &mut Array<T, D>
Return a mutable reference to the underlying data array.
Sourcepub const fn is_hard_mask(&self) -> bool
pub const fn is_hard_mask(&self) -> bool
Return whether the mask is hardened.
Sourcepub fn set_mask_flat(
&mut self,
flat_idx: usize,
value: bool,
) -> FerrayResult<()>
pub fn set_mask_flat( &mut self, flat_idx: usize, value: bool, ) -> FerrayResult<()>
Set a mask value at a flat index.
If the mask is hardened, only true (masking) is allowed; attempts to
clear a mask bit are silently ignored.
Setting a mask bit materializes the lazy nomask sentinel into a
real mask array (#506) — if you set even one bit, the full
Array<bool, D> is allocated.
§Errors
Returns FerrayError::IndexOutOfBounds if flat_idx >= size.
Sourcepub fn set_mask(&mut self, new_mask: Array<bool, D>) -> FerrayResult<()>
pub fn set_mask(&mut self, new_mask: Array<bool, D>) -> FerrayResult<()>
Replace the mask with a new one.
If the mask is hardened, only bits that are true in both the old and
new masks (or newly set to true) are allowed; cleared bits are ignored.
Passing a new mask always materializes the array out of the nomask-sentinel state — the stored mask becomes the provided one (possibly unioned with the existing mask if hardened).
§Errors
Returns FerrayError::ShapeMismatch if shapes differ.
Return true when this masked array’s underlying mask is
structurally shared with at least one other MaskedArray.
After a clone() the original and the clone share the same
mask via Arc until one of them mutates it (copy-on-write, #512).
Hot-path code can use this to reason about memory sharing —
shares_mask() == false means the mask is uniquely owned and
can be mutated without affecting any other MaskedArray.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn count(&self) -> FerrayResult<usize>
pub fn count(&self) -> FerrayResult<usize>
Count the number of unmasked (valid) elements.
§Errors
This function does not currently error but returns Result for API
consistency.
Sourcepub fn count_axis(&self, axis: usize) -> FerrayResult<Array<u64, IxDyn>>
pub fn count_axis(&self, axis: usize) -> FerrayResult<Array<u64, IxDyn>>
Count the number of unmasked elements per lane along axis.
Returns a plain Array<u64, IxDyn> (not masked, since count is
always defined) with the reduced axis removed.
§Errors
Returns FerrayError::AxisOutOfBounds if axis >= ndim.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn sum(&self) -> FerrayResult<T>
pub fn sum(&self) -> FerrayResult<T>
Compute the sum of unmasked elements.
Returns zero if all elements are masked.
§Errors
Returns an error only for internal failures.
Sourcepub fn mean(&self) -> FerrayResult<T>
pub fn mean(&self) -> FerrayResult<T>
Compute the mean of unmasked elements.
Returns NaN if no elements are unmasked.
§Errors
Returns an error only for internal failures.
Sourcepub fn min(&self) -> FerrayResult<T>
pub fn min(&self) -> FerrayResult<T>
Compute the minimum of unmasked elements.
NaN values in unmasked elements are propagated (returns NaN), matching NumPy.
§Errors
Returns FerrayError::InvalidValue if no elements are unmasked.
Sourcepub fn max(&self) -> FerrayResult<T>
pub fn max(&self) -> FerrayResult<T>
Compute the maximum of unmasked elements.
NaN values in unmasked elements are propagated (returns NaN), matching NumPy.
§Errors
Returns FerrayError::InvalidValue if no elements are unmasked.
Sourcepub fn var(&self) -> FerrayResult<T>
pub fn var(&self) -> FerrayResult<T>
Compute the variance of unmasked elements (population variance, ddof=0).
Returns NaN if no elements are unmasked.
§Errors
Returns an error only for internal failures.
Sourcepub fn std(&self) -> FerrayResult<T>
pub fn std(&self) -> FerrayResult<T>
Compute the standard deviation of unmasked elements (population, ddof=0).
Returns NaN if no elements are unmasked.
§Errors
Returns an error only for internal failures.
Sourcepub fn sum_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn sum_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Sum unmasked elements along axis. Returns a masked array with the
reduced axis removed; lanes that are entirely masked produce a
masked output position holding fill_value.
Sourcepub fn mean_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn mean_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Mean of unmasked elements along axis. All-masked lanes are masked
in the output.
Sourcepub fn min_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn min_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Min of unmasked elements along axis. NaN-propagating per NumPy.
Sourcepub fn max_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn max_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Max of unmasked elements along axis. NaN-propagating per NumPy.
Sourcepub fn var_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn var_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Population variance (ddof=0) of unmasked elements along axis.
Sourcepub fn std_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
pub fn std_axis(&self, axis: usize) -> FerrayResult<MaskedArray<T, IxDyn>>
Population standard deviation (ddof=0) of unmasked elements along axis.
Source§impl<T, D> MaskedArray<T, D>
impl<T, D> MaskedArray<T, D>
Sourcepub fn sort(&self) -> FerrayResult<MaskedArray<T, Ix1>>
pub fn sort(&self) -> FerrayResult<MaskedArray<T, Ix1>>
Sort the masked array (flattened), placing masked elements at the end.
Returns a new 1-D MaskedArray where:
- Unmasked elements are sorted in ascending order
- Masked elements come after all unmasked elements
§Errors
Returns an error only for internal failures.
Trait Implementations§
Source§impl<T, D> Add<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray + &MaskedArray — elementwise add with mask union.
impl<T, D> Add<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray + &MaskedArray — elementwise add with mask union.
Source§type Output = Result<MaskedArray<T, D>, FerrayError>
type Output = Result<MaskedArray<T, D>, FerrayError>
+ operator.Source§impl<T: Element, D: Dimension> AsRef<Array<T, D>> for MaskedArray<T, D>
impl<T: Element, D: Dimension> AsRef<Array<T, D>> for MaskedArray<T, D>
Source§fn as_ref(&self) -> &Array<T, D>
fn as_ref(&self) -> &Array<T, D>
Borrow the underlying data array, dropping the mask.
This lets you pass a &MaskedArray<T, D> to any function that takes
&Array<T, D>, but the mask is not consulted — masked positions
will be processed like normal data. Use MaskedArray::apply_unary
or MaskedArray::apply_binary when you want mask propagation.
§Example
let ma = MaskedArray::new(data, mask).unwrap();
// Pass through a function that operates on `&Array<T, D>`:
let arr_ref: &Array<f64, Ix1> = ma.as_ref();
assert_eq!(arr_ref.shape(), &[3]);Source§impl<T, D> Div<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray / &MaskedArray — elementwise divide with mask union.
impl<T, D> Div<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray / &MaskedArray — elementwise divide with mask union.
Source§type Output = Result<MaskedArray<T, D>, FerrayError>
type Output = Result<MaskedArray<T, D>, FerrayError>
/ operator.Source§impl<T: Element + Copy, D: Dimension> From<MaskedArray<T, D>> for Array<T, D>
impl<T: Element + Copy, D: Dimension> From<MaskedArray<T, D>> for Array<T, D>
Source§fn from(ma: MaskedArray<T, D>) -> Self
fn from(ma: MaskedArray<T, D>) -> Self
Consume a MaskedArray and return its underlying data array,
discarding the mask. Equivalent to calling ma.into_data().
Requires T: Copy because the underlying data buffer is cloned;
use MaskedArray::filled / MaskedArray::filled_default for a
mask-aware materialization with custom fill semantics.
Source§impl<T: Element, D: Dimension> MaskAware<T, D> for MaskedArray<T, D>
impl<T: Element, D: Dimension> MaskAware<T, D> for MaskedArray<T, D>
Source§impl<T, D> Mul<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray * &MaskedArray — elementwise multiply with mask union.
impl<T, D> Mul<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray * &MaskedArray — elementwise multiply with mask union.
Source§type Output = Result<MaskedArray<T, D>, FerrayError>
type Output = Result<MaskedArray<T, D>, FerrayError>
* operator.Source§impl<T, D> Sub<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray - &MaskedArray — elementwise subtract with mask union.
impl<T, D> Sub<&MaskedArray<T, D>> for &MaskedArray<T, D>
&MaskedArray - &MaskedArray — elementwise subtract with mask union.
Source§type Output = Result<MaskedArray<T, D>, FerrayError>
type Output = Result<MaskedArray<T, D>, FerrayError>
- operator.