ma

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ma provides numpy.ma-style masked arrays over numgo.Array (numpy/ma/core.py semantics, narrowed to this batch — see docs/design.md §2).

A Masked pairs a data array with a parallel mask: true marks an element as invalid. The mask is always materialized (a []bool whose length equals the data's Size) and is indexed in C order of the data's LOGICAL shape, so it stays aligned no matter what view the underlying data is.

Semantics for this batch:

  • Constructors copy their inputs; operations are pure (new Masked). There are no zero-copy views: shape ops rebuild the mask for the new shape.
  • Element-wise ops OR the operand masks. Div additionally masks positions where the divisor is zero (numpy ma domain behavior: warnings become mask bits, the IEEE value stays in the data).
  • Reductions ignore masked elements. A slice with no unmasked elements yields a NaN value that is itself masked (numpy returns a masked element after RuntimeWarning).
  • ArgMax/ArgMin skip masked entries and return -1 for an all-masked channel (numpy returns a masked index).
  • Any/All consider unmasked values only; a Go bool cannot express numpy's masked answer, so all-masked input gives Any=false, All=true (vacuous).
  • FilledDefault fills with numpy's default fill table for float/complex: 1e20 (complex real part 1e20), matching np.ma.default_fill_value.
  • SetUnmasked writes the value and clears the mask bit; under a hard mask a masked position silently refuses the write (numpy behavior).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Masked

type Masked[T numgo.Number] struct {
	// contains filtered or unexported fields
}

Masked is a data array plus an element mask. mask[i] true means element i (C order of the logical shape) is invalid. The zero value is unusable; use the constructors.

func Concatenate

func Concatenate[T numgo.Number](axis int, as ...*Masked[T]) *Masked[T]

Pure: Concatenate joins masked arrays along axis (negative allowed); masks merge by concatenation.

func FromData

func FromData[T numgo.Number](data *numgo.Array[T], mask []bool) *Masked[T]

Pure: FromData builds a Masked from data and a mask, copying both. The mask length must equal data's Size.

func MaskedAll

func MaskedAll[T numgo.Number](shape ...int) *Masked[T]

Pure: MaskedAll returns a Masked array with every element masked. The data carries zeros (numpy leaves whatever Empty produced; masked anyway).

func MaskedEqual

func MaskedEqual[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedEqual masks elements equal to v.

func MaskedFull

func MaskedFull[T numgo.Number](v T, shape ...int) *Masked[T]

Pure: MaskedFull returns a Masked array filled with v (nomask).

func MaskedGreater

func MaskedGreater[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedGreater masks elements strictly greater than v.

func MaskedGreaterEqual

func MaskedGreaterEqual[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedGreaterEqual masks elements greater than or equal to v.

func MaskedInside

func MaskedInside[T numgo.Number](a *numgo.Array[T], v1, v2 T) *Masked[T]

Pure: MaskedInside masks v1 <= x <= v2 (both inclusive).

func MaskedInvalid

func MaskedInvalid[T numgo.Number](a *numgo.Array[T]) *Masked[T]

Pure: MaskedInvalid masks NaN and ±Inf elements (real and complex parts).

func MaskedLess

func MaskedLess[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedLess masks elements strictly less than v.

func MaskedLessEqual

func MaskedLessEqual[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedLessEqual masks elements less than or equal to v.

func MaskedNotEqual

func MaskedNotEqual[T numgo.Number](a *numgo.Array[T], v T) *Masked[T]

Pure: MaskedNotEqual masks elements not equal to v.

func MaskedOnes

func MaskedOnes[T numgo.Number](shape ...int) *Masked[T]

Pure: MaskedOnes returns a Masked ones array (nomask).

func MaskedOutside

func MaskedOutside[T numgo.Number](a *numgo.Array[T], v1, v2 T) *Masked[T]

Pure: MaskedOutside masks x < v1 or x > v2.

func MaskedWhere

func MaskedWhere[T numgo.Number](cond []bool, a *numgo.Array[T]) *Masked[T]

Pure: MaskedWhere masks cond true positions of a (flat C order).

func MaskedZeros

func MaskedZeros[T numgo.Number](shape ...int) *Masked[T]

Pure: MaskedZeros returns a Masked zeros array (nomask).

func New

func New[T numgo.Number](a *numgo.Array[T]) *Masked[T]

Pure: New returns a masked view-free copy of a with no elements masked (numpy's nomask).

func Reshape

func Reshape[T numgo.Number](m *Masked[T], shape ...int) *Masked[T]

Pure: Reshape re-shapes (at most one -1 dimension); the mask re-indexes in C order of the new shape. Masks are materialized in C order of the logical shape, so for contiguous data the mask carries over verbatim.

func Squeeze

func Squeeze[T numgo.Number](m *Masked[T], axes ...int) *Masked[T]

Pure: Squeeze drops size-1 dimensions (all when no axes given); the mask re-indexes in C order.

func Stack

func Stack[T numgo.Number](axis int, as ...*Masked[T]) *Masked[T]

Pure: Stack joins same-shaped masked arrays along a new axis (negative allowed, ndim+1 positions valid).

func Transpose

func Transpose[T numgo.Number](m *Masked[T], axes ...int) *Masked[T]

Pure: Transpose permutes axes (no axes = reverse); the mask permutes with the data.

func (*Masked[T]) Abs

func (m *Masked[T]) Abs() *Masked[T]

Pure: Abs returns the element-wise absolute value (real |x|, complex |z|).

func (*Masked[T]) Add

func (m *Masked[T]) Add(b *Masked[T]) *Masked[T]

Pure: Add returns the element-wise sum with the masks ORed.

func (*Masked[T]) AddValue

func (m *Masked[T]) AddValue(v T) *Masked[T]

Pure: AddValue adds the scalar v to every element.

func (*Masked[T]) All

func (m *Masked[T]) All() bool

Pure: All reports whether every UNMASKED element is nonzero; masked elements are skipped, so all-masked input is vacuously true.

func (*Masked[T]) Any

func (m *Masked[T]) Any() bool

Pure: Any reports whether any UNMASKED element is nonzero. All-masked input returns false (a bool cannot carry numpy's masked answer).

func (*Masked[T]) ArgMax

func (m *Masked[T]) ArgMax(axis int) []int

Pure: ArgMax returns the coordinate of each unmasked maximum along axis (first occurrence wins ties); an all-masked channel gives -1 (numpy returns a masked index).

func (*Masked[T]) ArgMin

func (m *Masked[T]) ArgMin(axis int) []int

Pure: ArgMin returns the coordinate of each unmasked minimum along axis (first occurrence wins ties); an all-masked channel gives -1.

func (*Masked[T]) Ceil

func (m *Masked[T]) Ceil() *Masked[T]

Pure: Ceil returns the element-wise ceiling (mask propagates only).

func (*Masked[T]) Compressed

func (m *Masked[T]) Compressed() *numgo.Array[T]

Pure: Compressed returns the unmasked elements as a new 1-D array in C order (numpy compressed()); possibly empty.

func (*Masked[T]) Copy

func (m *Masked[T]) Copy() *Masked[T]

Pure: Copy returns an independent copy of data and mask (hard flag kept).

func (*Masked[T]) Cos

func (m *Masked[T]) Cos() *Masked[T]

Pure: Cos returns the element-wise cosine (mask propagates only).

func (*Masked[T]) CountUnmasked

func (m *Masked[T]) CountUnmasked() int

Pure: CountUnmasked returns the number of valid elements.

func (*Masked[T]) CumProd

func (m *Masked[T]) CumProd(axes ...int) *Masked[T]

Pure: CumProd prefixes unmasked products along axes (same convention).

func (*Masked[T]) CumSum

func (m *Masked[T]) CumSum(axes ...int) *Masked[T]

Pure: CumSum prefixes unmasked sums along axes (no axes = C-order prefix over the raveled array); masked positions carry the running value forward without contributing (numpy ma cumsum).

func (*Masked[T]) Data

func (m *Masked[T]) Data() *numgo.Array[T]

Shares data: Data returns the underlying data array.

func (*Masked[T]) Div

func (m *Masked[T]) Div(b *Masked[T]) *Masked[T]

Pure: Div returns the element-wise quotient. Positions where the divisor is zero are additionally masked (numpy ma: divide-by-zero warning becomes a mask bit; the IEEE result stays in the data).

func (*Masked[T]) DivValue

func (m *Masked[T]) DivValue(v T) *Masked[T]

Pure: DivValue divides every element by the scalar v (zero v masks, like Div).

func (*Masked[T]) Exp

func (m *Masked[T]) Exp() *Masked[T]

Pure: Exp returns the element-wise exponential (mask propagates only).

func (*Masked[T]) Filled

func (m *Masked[T]) Filled(fill T) *numgo.Array[T]

Pure: Filled returns a copy of the data with every masked element replaced by fill.

func (*Masked[T]) FilledDefault

func (m *Masked[T]) FilledDefault() *numgo.Array[T]

Pure: FilledDefault fills masked elements with numpy's default fill value for the element type: 1e20 (real part 1e20 for complex), per np.ma.default_fill_value.

func (*Masked[T]) Floor

func (m *Masked[T]) Floor() *Masked[T]

Pure: Floor returns the element-wise floor (mask propagates only).

func (*Masked[T]) HardMask

func (m *Masked[T]) HardMask() *Masked[T]

Chainable: HardMask enables the hard mask: SetUnmasked silently refuses writes to masked positions (numpy hard_mask).

func (*Masked[T]) Log

func (m *Masked[T]) Log() *Masked[T]

Pure: Log returns the natural logarithm; real elements < 0 are masked (Log(0) stays -Inf and unmasked, matching numpy's divide warning domain).

func (*Masked[T]) Log1p

func (m *Masked[T]) Log1p() *Masked[T]

Pure: Log1p returns log(1+x); real elements < -1 are masked.

func (*Masked[T]) Log2

func (m *Masked[T]) Log2() *Masked[T]

Pure: Log2 returns the base-2 logarithm with Log's domain.

func (*Masked[T]) Log10

func (m *Masked[T]) Log10() *Masked[T]

Pure: Log10 returns the base-10 logarithm with Log's domain.

func (*Masked[T]) Mask

func (m *Masked[T]) Mask() []bool

Pure: Mask returns a copy of the mask, C order of the logical shape.

func (*Masked[T]) Max

func (m *Masked[T]) Max(axes ...int) *Masked[T]

Pure: Max folds max along axes over unmasked elements (ties → first).

func (*Masked[T]) MaxKeepdims

func (m *Masked[T]) MaxKeepdims(axes ...int) *Masked[T]

Pure: MaxKeepdims folds max keeping reduced axes as size 1.

func (*Masked[T]) Mean

func (m *Masked[T]) Mean(axes ...int) *Masked[T]

Pure: Mean divides the unmasked sum by the unmasked count along axes.

func (*Masked[T]) MeanKeepdims

func (m *Masked[T]) MeanKeepdims(axes ...int) *Masked[T]

Pure: MeanKeepdims folds the mean keeping reduced axes as size 1.

func (*Masked[T]) Min

func (m *Masked[T]) Min(axes ...int) *Masked[T]

Pure: Min folds min along axes over unmasked elements (ties → first).

func (*Masked[T]) MinKeepdims

func (m *Masked[T]) MinKeepdims(axes ...int) *Masked[T]

Pure: MinKeepdims folds min keeping reduced axes as size 1.

func (*Masked[T]) Mul

func (m *Masked[T]) Mul(b *Masked[T]) *Masked[T]

Pure: Mul returns the element-wise product with the masks ORed.

func (*Masked[T]) MulValue

func (m *Masked[T]) MulValue(v T) *Masked[T]

Pure: MulValue multiplies every element by the scalar v.

func (*Masked[T]) Ndim

func (m *Masked[T]) Ndim() int

Pure: Ndim returns the data's dimension count.

func (*Masked[T]) Neg

func (m *Masked[T]) Neg() *Masked[T]

Pure: Neg returns the element-wise negation.

func (*Masked[T]) Pow

func (m *Masked[T]) Pow(b *Masked[T]) *Masked[T]

Pure: Pow raises m to each element of b with the masks ORed.

func (*Masked[T]) Round

func (m *Masked[T]) Round() *Masked[T]

Pure: Round returns the element-wise round-half-to-even (mask propagates only).

func (*Masked[T]) SetUnmasked

func (m *Masked[T]) SetUnmasked(coords []int, v T) *Masked[T]

In-place: SetUnmasked writes v at coords and clears the mask bit there. A masked position under a hard mask silently refuses the write and is returned unchanged (numpy behavior). Invalid coords panic.

func (*Masked[T]) Shape

func (m *Masked[T]) Shape() []int

Pure: Shape returns a copy of the data's dimensions.

func (*Masked[T]) Sin

func (m *Masked[T]) Sin() *Masked[T]

Pure: Sin returns the element-wise sine (mask propagates only).

func (*Masked[T]) Size

func (m *Masked[T]) Size() int

Pure: Size returns the data's element count (and the mask length).

func (*Masked[T]) SoftMask

func (m *Masked[T]) SoftMask() *Masked[T]

Chainable: SoftMask disables the hard mask (numpy default).

func (*Masked[T]) Sqrt

func (m *Masked[T]) Sqrt() *Masked[T]

Pure: Sqrt returns the element-wise square root; negative real elements are masked (complex input uses the principal branch, no domain).

func (*Masked[T]) Std

func (m *Masked[T]) Std(axes ...int) *Masked[T]

Pure: Std computes the unmasked standard deviation along axes (ddof=0).

func (*Masked[T]) StdDDof

func (m *Masked[T]) StdDDof(ddof int, axes ...int) *Masked[T]

Pure: StdDDof computes the unmasked standard deviation with the given ddof.

func (*Masked[T]) Sub

func (m *Masked[T]) Sub(b *Masked[T]) *Masked[T]

Pure: Sub returns the element-wise difference with the masks ORed.

func (*Masked[T]) SubValue

func (m *Masked[T]) SubValue(v T) *Masked[T]

Pure: SubValue subtracts the scalar v from every element.

func (*Masked[T]) Sum

func (m *Masked[T]) Sum(axes ...int) *Masked[T]

Pure: Sum folds addition along axes over unmasked elements.

func (*Masked[T]) SumKeepdims

func (m *Masked[T]) SumKeepdims(axes ...int) *Masked[T]

Pure: SumKeepdims folds the sum keeping reduced axes as size 1.

func (*Masked[T]) Tan

func (m *Masked[T]) Tan() *Masked[T]

Pure: Tan returns the element-wise tangent (mask propagates only).

func (*Masked[T]) Var

func (m *Masked[T]) Var(axes ...int) *Masked[T]

Pure: Var computes the unmasked population variance (ddof=0) along axes. Complex input panics like the root package (no real result in T).

func (*Masked[T]) VarDDof

func (m *Masked[T]) VarDDof(ddof int, axes ...int) *Masked[T]

Pure: VarDDof computes the unmasked variance with the given ddof.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL