Skip to main content

MaskedArray

Struct MaskedArray 

Source
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:

  • true means the element is masked (invalid / missing)
  • false means the element is valid

All operations (arithmetic, reductions, ufuncs) respect the mask by skipping masked elements.

Implementations§

Source§

impl<T, D> MaskedArray<T, D>
where T: Element + Copy, D: Dimension,

Source

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.

Source

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>

Source

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.

Source

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>

Source

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.

Source

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.

Source

pub fn data(&self) -> &Array<T, D>

Return a reference to the underlying data array.

Source

pub fn mask(&self) -> &Array<bool, D>

Return a reference to the mask array.

Source

pub fn data_mut(&mut self) -> &mut Array<T, D>

Return a mutable reference to the underlying data array.

Source

pub fn shape(&self) -> &[usize]

Return the shape of the masked array.

Source

pub fn ndim(&self) -> usize

Return the number of dimensions.

Source

pub fn size(&self) -> usize

Return the total number of elements (including masked).

Source

pub fn dim(&self) -> &D

Return the dimension descriptor.

Source

pub fn is_hard_mask(&self) -> bool

Return whether the mask is hardened.

Source

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.

Source

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>
where T: Element + Copy, D: Dimension,

Source

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>
where T: Element + Float, D: Dimension,

Source

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.

Source

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.

Source

pub fn min(&self) -> FerrayResult<T>

Compute the minimum of unmasked elements.

§Errors

Returns FerrayError::InvalidValue if no elements are unmasked.

Source

pub fn max(&self) -> FerrayResult<T>

Compute the maximum of unmasked elements.

§Errors

Returns FerrayError::InvalidValue if no elements are unmasked.

Source

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.

Source

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>
where T: Element + PartialOrd + Copy, D: Dimension,

Source

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.

Source

pub fn argsort(&self) -> FerrayResult<Vec<usize>>

Return the indices that would sort the masked array, with masked elements placed at the end.

Returns a Vec<usize> of indices.

§Errors

Returns an error only for internal failures.

Trait Implementations§

Source§

impl<T: Clone + Element, D: Clone + Dimension> Clone for MaskedArray<T, D>

Source§

fn clone(&self) -> MaskedArray<T, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Element, D: Debug + Dimension> Debug for MaskedArray<T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, D> Freeze for MaskedArray<T, D>
where D: Freeze, <D as Dimension>::NdarrayDim: Freeze,

§

impl<T, D> RefUnwindSafe for MaskedArray<T, D>

§

impl<T, D> Send for MaskedArray<T, D>

§

impl<T, D> Sync for MaskedArray<T, D>

§

impl<T, D> Unpin for MaskedArray<T, D>
where D: Unpin, <D as Dimension>::NdarrayDim: Unpin,

§

impl<T, D> UnsafeUnpin for MaskedArray<T, D>

§

impl<T, D> UnwindSafe for MaskedArray<T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.