Skip to content

brainhops._core.typing

Type hints shared across the package.

Internal module

brainhops._core.typing is an internal module. It is documented only to explain the type hints that appear in the public interface, and it should not be imported or relied upon. It may change or disappear without notice.

Attributes

Const module-attribute

Const: TypeAlias = Annotated[T, Frozen(), NoInit()]

Field that is frozen and cannot be set through the constructor.

HiddenConst module-attribute

HiddenConst: TypeAlias = Annotated[Const[T], NoRepr()]

Constant field that is also hidden from the generated __repr__.

npscalar module-attribute

npscalar: TypeAlias = T | ndarray[tuple[()], dtype[T]]

Scalar, given either as a plain value or as a 0-d array.

npvector module-attribute

npvector: TypeAlias = ndarray[tuple[int], dtype[T]]

One-dimensional NumPy array, converted from an array of any backend.

A scalar becomes a vector of one element. An array with more dimensions is refused, unless its extra leading dimensions have length one, in which case they are removed.

npmatrix module-attribute

npmatrix: TypeAlias = ndarray[tuple[int, int], dtype[T]]

Two-dimensional NumPy array, converted from an array of any backend.

A scalar becomes a matrix of one element and a vector becomes a matrix of one row. An array with more dimensions, such as a stack of matrices, is refused, unless its extra leading dimensions have length one, in which case they are removed.

Clip module-attribute

Clip: TypeAlias = (
    float
    | tuple[float, float]
    | Sequence[tuple[float, float]]
    | None
)

Voxel margin: symmetric scalar, shared pair, per-axis pairs, or None.

Shape module-attribute

Shape: TypeAlias = tuple[int, ...]

Any shape.

ShapeLike module-attribute

ShapeLike: TypeAlias = Iterable[int]

Any shape-like object, such as a list or a tuple.

NativeNumber module-attribute

NativeNumber: TypeAlias = bool | int | float | complex

Native number values.

Functions:

is_instance_or_subclass

is_instance_or_subclass(
    obj: Any, cls: type | tuple[type, ...]
) -> bool

Return whether an object is an instance or a subclass of a class.

Classes are tested with issubclass and other objects with isinstance, so the function returns False for unrelated classes and for objects such as None.