GSEGUtils.base_arrays
See BaseArrays for background motivation.
Pydantic-validated numpy-array base classes.
Provides BaseArray and its subclasses (NumericMixins,
FixedLengthArray, BaseVector, HomogeneousArray,
ArrayNx2, ArrayNx3). Each class behaves like a NumPy array via
the __array_interface__ protocol while gaining Pydantic-level field
validation, dataclass-style declarations, and standard arithmetic / comparison
dunders.
- class GSEGUtils.base_arrays.BaseArray
-
Abstract Pydantic-validated wrapper around a NumPy array.
Subclasses inherit the strict validation config and the
__array_interface__proxy. Concrete subclasses constrainarrto a more specific shape / dtype vianumpydantic.NDArrayannotations and (optionally) override_coerce_array()to add extra coercion.Subclassable array supporting all shapes and numeric/boolean dtypes.
- Parameters:
arr (ArrayT) – Input array data
- arr: ArrayT
Contains the raw numpy ndarray data
- property base: bool'>)] | None
Return the base array if this array is a view, otherwise
None.- Return type:
ArrayT | None
- view(dtype=None, _type=None)
Return a view of the underlying array.
- Parameters:
dtype (numpy.dtype, optional) – Target dtype for the view; defaults to the current dtype.
_type (type, optional) – Sub-type of
numpy.ndarrayto construct; defaults to the current array type.
- Return type:
ArrayT
- min(**kwargs)
Return
self.arr.min(**kwargs).See
numpy.min()for the supported keyword arguments.- Parameters:
**kwargs (dict[str, Any]) – Forwarded to
numpy.ndarray.min().- Return type:
Any
- max(**kwargs)
Return
self.arr.max(**kwargs).See
numpy.max()for the supported keyword arguments.- Parameters:
**kwargs (dict[str, Any]) – Forwarded to
numpy.ndarray.max().- Return type:
Any
- copy(array=None, *, deep=True, update=None, **kwargs)
Return a copy of this object.
Supports deep / shallow copies and per-field overrides via
update.- Parameters:
array (ArrayT | Self | None, optional) – If set, directly passed as the
arrattribute in the new instance.deep (bool, optional) – Whether to deep-copy non-
arrfields. DefaultTrue.update (dict[str, Any], optional) – Per-field overrides applied to the new instance.
**kwargs (dict[str, Any]) – Reserved for subclass overrides.
self (Self)
- Return type:
Self
- class GSEGUtils.base_arrays.NumericMixins
Bases:
BaseArrayAdds Python arithmetic / in-place / logical dunders that delegate to
self.arr.Binary operators return a fresh wrapper of the same type via
BaseArray.copy(); in-place operators mutateself.arrand returnself.Initialize a subclassable numeric/logical array wrapper.
- Parameters:
arr (ArrayT) – Input array data.
- class GSEGUtils.base_arrays.FixedLengthArray
Bases:
NumericMixinsRow-oriented array wrapper with
sample/reduce/extracthelpers.Suitable bases for per-row-typed data such as 3D coordinate sets, RGB triplets, or generic vectors-of-vectors.
Initialize a row-indexable array wrapper.
- Parameters:
arr (ArrayT) – Input array data.
- create_mask(selection)
Convert a NumPy index into a boolean per-row mask.
- Parameters:
selection (IndexLike) – A slice, integer, integer array, or boolean array.
- Returns:
Boolean mask of length
len(self).- Return type:
Vector_Bool_T
- Raises:
ValueError – If a boolean mask is provided with the wrong length.
- sample(index)
Return a fresh wrapper containing only the rows selected by
index.- Parameters:
index (IndexLike) – Anything accepted by
create_mask().- Returns:
A deep copy holding only the selected rows.
- Return type:
Self
- reduce(index)
Mutate
self.arrto keep only the rows selected byindex.- Parameters:
index (IndexLike) – Anything accepted by
create_mask().- Return type:
None
- extract(index)
Split rows: return the selected rows and reduce
selfto the rest.- Parameters:
index (IndexLike) – Anything accepted by
create_mask().- Returns:
A new wrapper holding the selected rows.
selfis mutated in-place to keep only the un-selected rows.- Return type:
Self
- class GSEGUtils.base_arrays.BaseVector
Bases:
FixedLengthArray1-D variant of
FixedLengthArraywith a vector-shape contract onarr.Initialize a shape-validated 1-D array wrapper.
- Parameters:
arr (VectorT) – Input array data.
- arr: VectorT
Contains the raw numpy ndarray data
- class GSEGUtils.base_arrays.HomogeneousArray
Bases:
FixedLengthArrayRow-array wrapper that exposes a homogeneous-coordinate view via
H.Initialize a homogeneous-coordinate-aware row array.
- Parameters:
arr (ArrayT) – Input array data.
- property H: bool'>)]
Return the homogeneous-coordinate form of
self.arr.- Returns:
self.arrwith an extra all-ones column appended on the right.- Return type:
ArrayT
- class GSEGUtils.base_arrays.ArrayNx2
Bases:
HomogeneousArrayShape-validated
Nx2array.- Parameters:
arr (Array_Nx2_T) – Input array data.
Initialize an
Nx2shape-validated array.- arr: Array_Nx2_T
Contains the raw numpy ndarray data
- class GSEGUtils.base_arrays.ArrayNx3
Bases:
HomogeneousArrayShape-validated
Nx3array.- Parameters:
arr (Array_Nx3_Float_T) – Input array data.
Initialize an
Nx3shape-validated array.- arr: Array_Nx3_Float_T
Contains the raw numpy ndarray data