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.
Implementations§
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 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: Element, D: Dimension> MaskedArray<T, D>
impl<T: Element, D: Dimension> MaskedArray<T, D>
Sourcepub fn harden_mask(&mut self) -> FerrayResult<()>
pub 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 fn soften_mask(&mut self) -> FerrayResult<()>
pub 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.
§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).
§Errors
Returns an error if the mask array cannot be created.
Sourcepub fn data_mut(&mut self) -> &mut Array<T, D>
pub fn data_mut(&mut self) -> &mut Array<T, D>
Return a mutable reference to the underlying data array.
Sourcepub fn is_hard_mask(&self) -> bool
pub 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.
§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.
§Errors
Returns FerrayError::ShapeMismatch if shapes differ.
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.
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.
§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.
§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.
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.