diff --git a/doc/reference/array.rst b/doc/reference/array.rst new file mode 100644 index 00000000..6d114cb4 --- /dev/null +++ b/doc/reference/array.rst @@ -0,0 +1,23 @@ +.. _Array: + +Array +===== + +Minimal typing protocol for array-like objects compatible with blosc2. + +This protocol describes the basic interface required by blosc2 arrays. +It is implemented by blosc2 classes (:ref:`NDArray`, :ref:`NDField`, +:ref:`LazyArray`, :ref:`C2Array`, :ref:`ProxyNDSource`...) +and is compatible with NumPy arrays and other array-like containers +(e.g., PyTorch, TensorFlow, Dask, Zarr, ...). + +.. currentmodule:: blosc2 + +.. autoclass:: Array + + :Special Methods: + + .. autosummary:: + + __len__ + __getitem__ diff --git a/doc/reference/classes.rst b/doc/reference/classes.rst index 0b688a71..1d9de69f 100644 --- a/doc/reference/classes.rst +++ b/doc/reference/classes.rst @@ -7,11 +7,12 @@ Main Classes ------------ .. autosummary:: - SChunk NDArray NDField LazyArray C2Array + Array + SChunk DictStore TreeStore EmbedStore @@ -23,14 +24,15 @@ Main Classes .. toctree:: :maxdepth: 1 - schunk ndarray ndfield + lazyarray + c2array + array + schunk dict_store tree_store embed_store - lazyarray - c2array proxy proxysource proxyndsource diff --git a/src/blosc2/__init__.py b/src/blosc2/__init__.py index 01bd8bd5..bc8794cb 100644 --- a/src/blosc2/__init__.py +++ b/src/blosc2/__init__.py @@ -392,6 +392,7 @@ def _raise(exc): ) from .ndarray import ( + Array, NDArray, NDField, Operand, diff --git a/src/blosc2/dict_store.py b/src/blosc2/dict_store.py index 48c421b5..bb104080 100644 --- a/src/blosc2/dict_store.py +++ b/src/blosc2/dict_store.py @@ -214,7 +214,7 @@ def estore(self) -> EmbedStore: """Access the underlying EmbedStore.""" return self._estore - def __setitem__(self, key: str, value: np.ndarray | blosc2.NDArray | SChunk | C2Array) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node to the DictStore.""" if isinstance(value, np.ndarray): value = blosc2.asarray(value, cparams=self.cparams, dparams=self.dparams) diff --git a/src/blosc2/embed_store.py b/src/blosc2/embed_store.py index b876d7dc..61dd3447 100644 --- a/src/blosc2/embed_store.py +++ b/src/blosc2/embed_store.py @@ -159,7 +159,7 @@ def _ensure_capacity(self, needed_bytes: int) -> None: new_size = max(required_size, int(self._store.shape[0] * 1.5)) self._store.resize((new_size,)) - def __setitem__(self, key: str, value: np.ndarray | blosc2.NDArray | SChunk | C2Array) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node to the embed store.""" if self.mode == "r": raise ValueError("Cannot set items in read-only mode.") diff --git a/src/blosc2/lazyexpr.py b/src/blosc2/lazyexpr.py index 6a51b2ed..7bd85f54 100644 --- a/src/blosc2/lazyexpr.py +++ b/src/blosc2/lazyexpr.py @@ -288,7 +288,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray: @abstractmethod def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blosc2.NDArray: """ - Return an :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`. + Return a :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`. Parameters ---------- @@ -337,9 +337,9 @@ def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blo pass @abstractmethod - def __getitem__(self, item: int | slice | Sequence[slice]) -> blosc2.NDArray: + def __getitem__(self, item: int | slice | Sequence[slice]) -> np.ndarray: """ - Return a NumPy.ndarray containing the evaluation of the :ref:`LazyArray`. + Return a numpy.ndarray containing the evaluation of the :ref:`LazyArray`. Parameters ---------- @@ -392,7 +392,7 @@ def save(self, **kwargs: Any) -> None: Notes ----- - * All the operands of the LazyArray must be Python scalars, :ref:`NDArray`, :ref:`C2Array` or :ref:`Proxy`. + * All the operands of the LazyArray must be Python scalars, or :ref:`blosc2.Array` objects. * If an operand is a :ref:`Proxy`, keep in mind that Python-Blosc2 will only be able to reopen it as such if its source is a :ref:`SChunk`, :ref:`NDArray` or a :ref:`C2Array` (see :func:`blosc2.open` notes section for more info). @@ -507,14 +507,12 @@ def convert_inputs(inputs): return [] inputs_ = [] for obj in inputs: - if not isinstance( - obj, np.ndarray | blosc2.NDArray | blosc2.NDField | blosc2.C2Array - ) and not np.isscalar(obj): + if not isinstance(obj, blosc2.Array) and not np.isscalar(obj): try: obj = np.asarray(obj) except Exception: print( - "Inputs not being np.ndarray, NDArray, NDField, C2Array or Python scalar objects" + "Inputs not being np.ndarray, Array or Python scalar objects" " should be convertible to np.ndarray." ) raise @@ -687,9 +685,9 @@ def visit_Call(self, node): def conserve_functions( # noqa: C901 expression: str, - operands_old: dict[str, blosc2.NDArray | blosc2.LazyExpr], - operands_new: dict[str, blosc2.NDArray | blosc2.LazyExpr], -) -> tuple[str, dict[str, blosc2.NDArray]]: + operands_old: dict[str, blosc2.Array], + operands_new: dict[str, blosc2.Array], +) -> tuple[str, dict[str, blosc2.Array]]: """ Given an expression in string form, return its operands. @@ -2029,7 +2027,7 @@ def chunked_eval( # noqa: C901 _getitem: bool, optional Indicates whether the expression is being evaluated for a getitem operation. Default is False. - _output: NDArray or np.ndarray, optional + _output: blosc2.Array, optional The output array to store the result. _ne_args: dict, optional Additional arguments to be passed to `numexpr.evaluate()` function. @@ -3252,7 +3250,7 @@ def info(self): def info_items(self): inputs = {} for key, value in self.inputs_dict.items(): - if isinstance(value, np.ndarray | blosc2.NDArray | blosc2.C2Array): + if isinstance(value, blosc2.Array): inputs[key] = f"<{value.__class__.__name__}> {value.shape} {value.dtype}" else: inputs[key] = str(value) @@ -3378,7 +3376,7 @@ def save(self, **kwargs): def lazyudf( func: Callable[[tuple, np.ndarray, tuple[int]], None], - inputs: tuple | list | None, + inputs: Sequence[Any] | None, dtype: np.dtype, shape: tuple | list | None = None, chunked_eval: bool = True, @@ -3396,11 +3394,11 @@ def lazyudf( in :paramref:`inputs`. - `output`: The buffer to be filled as a multidimensional numpy.ndarray. - `offset`: The multidimensional offset corresponding to the start of the block being computed. - inputs: tuple or list or None - The sequence of inputs. Supported inputs are: - NumPy.ndarray, :ref:`NDArray`, :ref:`NDField`, :ref:`C2Array`. - Any other object is supported too, and will be passed as is to the user-defined function. - If not needed, this can be empty, but `shape` must be provided. + inputs: Sequence[Any] or None + The sequence of inputs. Besides objects compliant with the blosc2.Array protocol, + any other object is supported too, and it will be passed as-is to the + user-defined function. If not needed, this can be empty, but `shape` must + be provided. dtype: np.dtype The resulting ndarray dtype in NumPy format. shape: tuple, optional @@ -3482,9 +3480,9 @@ def seek_operands(names, local_dict=None, global_dict=None, _frame_depth: int = def lazyexpr( - expression: str | bytes | LazyExpr | blosc2.NDArray, + expression: str | bytes | LazyArray | blosc2.NDArray, operands: dict | None = None, - out: blosc2.NDArray | np.ndarray = None, + out: blosc2.Array = None, where: tuple | list | None = None, local_dict: dict | None = None, global_dict: dict | None = None, @@ -3496,15 +3494,15 @@ def lazyexpr( Parameters ---------- - expression: str or bytes or LazyExpr - The expression to evaluate. This can be any valid expression that can be - ingested by numexpr. If a LazyExpr is passed, the expression will be + expression: str or bytes or LazyExpr or NDArray + The expression to evaluate. This can be any valid expression that numexpr + can ingest. If a LazyExpr is passed, the expression will be updated with the new operands. - operands: dict - The dictionary with operands. Supported values are NumPy.ndarray, - Python scalars, :ref:`NDArray`, :ref:`NDField` or :ref:`C2Array` instances. + operands: dict[blosc2.Array], optional + The dictionary with operands. Supported values are Python scalars, + or any instance that is blosc2.Array compliant. If None, the operands will be seeked in the local and global dictionaries. - out: NDArray or np.ndarray, optional + out: blosc2.Array, optional The output array where the result will be stored. If not provided, a new NumPy array will be created and returned. where: tuple, list, optional @@ -3633,9 +3631,9 @@ def evaluate( ex: str, local_dict: dict | None = None, global_dict: dict | None = None, - out: np.ndarray | blosc2.NDArray = None, + out: blosc2.Array = None, **kwargs: Any, -) -> np.ndarray | blosc2.NDArray: +) -> blosc2.Array: """ Evaluate a string expression using the Blosc2 compute engine. @@ -3659,7 +3657,7 @@ def evaluate( global_dict: dict, optional The global dictionary to use when looking for operands in the expression. If not provided, the global dictionary of the caller will be used. - out: NDArray or np.ndarray, optional + out: blosc2.Array, optional The output array where the result will be stored. If not provided, a new NumPy array will be created and returned. kwargs: Any, optional @@ -3667,7 +3665,7 @@ def evaluate( Returns ------- - out: NumPy or NDArray + out: blosc2.Array The result of the expression evaluation. If out is provided, the result will be stored in out and returned at the same time. diff --git a/src/blosc2/linalg.py b/src/blosc2/linalg.py index d7f85d3b..1ea0617e 100644 --- a/src/blosc2/linalg.py +++ b/src/blosc2/linalg.py @@ -15,7 +15,7 @@ from collections.abc import Sequence -def matmul(x1: blosc2.NDArray | np.ndarray, x2: blosc2.NDArray, **kwargs: Any) -> blosc2.NDArray: +def matmul(x1: blosc2.Array, x2: blosc2.NDArray, **kwargs: Any) -> blosc2.NDArray: """ Computes the matrix product between two Blosc2 NDArrays. @@ -417,7 +417,7 @@ def vecdot(x1: blosc2.NDArray, x2: blosc2.NDArray, axis: int = -1, **kwargs) -> def permute_dims( - arr: blosc2.NDArray | np.ndarray, axes: tuple[int] | list[int] | None = None, **kwargs: Any + arr: blosc2.Array, axes: tuple[int] | list[int] | None = None, **kwargs: Any ) -> blosc2.NDArray: """ Permutes the axes (dimensions) of an array. @@ -566,7 +566,7 @@ def transpose(x, **kwargs: Any) -> blosc2.NDArray: return permute_dims(x, **kwargs) -def matrix_transpose(arr: blosc2.NDArray | np.ndarray, **kwargs: Any) -> blosc2.NDArray: +def matrix_transpose(arr: blosc2.Array, **kwargs: Any) -> blosc2.NDArray: """ Transposes a matrix (or a stack of matrices). diff --git a/src/blosc2/ndarray.py b/src/blosc2/ndarray.py index 722db50b..113c7f86 100644 --- a/src/blosc2/ndarray.py +++ b/src/blosc2/ndarray.py @@ -16,7 +16,7 @@ from collections import OrderedDict, namedtuple from functools import reduce from itertools import product -from typing import TYPE_CHECKING, Any, NamedTuple +from typing import TYPE_CHECKING, Any, NamedTuple, Protocol, runtime_checkable from numpy.exceptions import ComplexWarning @@ -38,6 +38,42 @@ NUMPY_GE_2_0 = np.__version__ >= "2.0" +@runtime_checkable +class Array(Protocol): + """ + A typing protocol for array-like objects with basic array interface. + + This protocol describes the basic interface required by blosc2 arrays. + It is implemented by blosc2 classes (:ref:`NDArray`, :ref:`NDField`, + :ref:`LazyArray`, :ref:`C2Array`, :ref:`ProxyNDSource`...) + and is compatible with NumPy arrays and other array-like containers + (e.g., PyTorch, TensorFlow, Dask, Zarr, ...). + """ + + @property + def dtype(self) -> Any: + """The data type of the array.""" + ... + + @property + def shape(self) -> tuple[int, ...]: + """The shape of the array.""" + ... + + @property + def ndim(self) -> int: + """The number of dimensions of the array.""" + ... + + def __len__(self) -> int: + """The length of the array.""" + ... + + def __getitem__(self, key: Any) -> Any: + """Get items from the array.""" + ... + + def is_documented_by(original): def wrapper(target): target.__doc__ = original.__doc__ @@ -264,7 +300,7 @@ def get_flat_slices( def reshape( - src: NDArray | NDField | blosc2.LazyArray | blosc2.C2Array, + src: blosc2.Array, shape: tuple | list, c_order: bool = True, **kwargs: Any, @@ -370,43 +406,32 @@ def reshape( def _check_allowed_dtypes( - value: bool - | int - | float - | str - | blosc2.NDArray - | blosc2.NDField - | blosc2.C2Array - | blosc2.Proxy - | blosc2.LazyExpr, + value: bool | int | float | str | blosc2.Array, ): - if not ( - isinstance( - value, - blosc2.LazyExpr - | blosc2.NDArray - | blosc2.NDField - | blosc2.C2Array - | blosc2.Proxy - | blosc2.ProxyNDField - | blosc2.SimpleProxy - | np.ndarray, - ) - or np.isscalar(value) - ): + def _is_array_like(v: Any) -> bool: + try: + # Try Protocol runtime check first (works when possible) + if isinstance(v, blosc2.Array): + return True + except Exception: + # Some runtime contexts may raise (or return False) — fall back to duck typing + pass + # Structural fallback: common minimal array interface + return hasattr(v, "shape") and hasattr(v, "dtype") and callable(getattr(v, "__getitem__", None)) + + if not (_is_array_like(value) or np.isscalar(value)): raise RuntimeError( - "Expected LazyExpr, NDArray, NDField, C2Array, Proxy, np.ndarray or scalar instances" - f" and you provided a '{type(value)}' instance" + f"Expected blosc2.Array or scalar instances and you provided a '{type(value)}' instance" ) def sum( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the sum of array elements over a given axis. @@ -458,12 +483,12 @@ def sum( def mean( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the arithmetic mean along the specified axis. @@ -494,13 +519,13 @@ def mean( def std( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | bool: +) -> blosc2.Array | int | float | bool: """ Return the standard deviation along the specified axis. @@ -553,13 +578,13 @@ def std( def var( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, ddof: int = 0, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | bool: +) -> blosc2.Array | int | float | bool: """ Return the variance along the specified axis. @@ -595,12 +620,12 @@ def var( def prod( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, dtype: np.dtype | str = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the product of array elements over a given axis. @@ -635,11 +660,11 @@ def prod( def min( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the minimum along a given axis. @@ -683,11 +708,11 @@ def min( def max( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | int | float | complex | bool: +) -> blosc2.Array | int | float | complex | bool: """ Return the maximum along a given axis. @@ -726,11 +751,11 @@ def max( def any( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | bool: +) -> blosc2.Array | bool: """ Test whether any array element along a given axis evaluates to True. @@ -767,11 +792,11 @@ def any( def all( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + ndarr: blosc2.Array, axis: int | tuple[int] | None = None, keepdims: bool = False, **kwargs: Any, -) -> np.ndarray | NDArray | bool: +) -> blosc2.Array | bool: """ Test whether all array elements along a given axis evaluate to True. @@ -800,7 +825,7 @@ def all( return ndarr.all(axis=axis, keepdims=keepdims, **kwargs) -def sin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sin(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the trigonometric sine, element-wise. @@ -835,7 +860,7 @@ def sin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "sin", None)) -def cos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def cos(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Trigonometric cosine, element-wise. @@ -870,7 +895,7 @@ def cos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "cos", None)) -def tan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def tan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the trigonometric tangent, element-wise. @@ -906,7 +931,7 @@ def tan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "tan", None)) -def sqrt(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sqrt(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the non-negative square-root of an array, element-wise. @@ -941,7 +966,7 @@ def sqrt(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "sqrt", None)) -def sinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def sinh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Hyperbolic sine, element-wise. @@ -976,7 +1001,7 @@ def sinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "sinh", None)) -def cosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def cosh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the hyperbolic cosine, element-wise. @@ -1011,7 +1036,7 @@ def cosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "cosh", None)) -def tanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def tanh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the hyperbolic tangent, element-wise. @@ -1046,7 +1071,7 @@ def tanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "tanh", None)) -def arcsin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arcsin(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse sine, element-wise. @@ -1084,7 +1109,7 @@ def arcsin(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl asin = arcsin # alias -def arccos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arccos(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse cosine, element-wise. @@ -1122,7 +1147,7 @@ def arccos(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl acos = arccos # alias -def arctan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arctan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse tangent, element-wise. @@ -1160,9 +1185,7 @@ def arctan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> bl atan = arctan # alias -def arctan2( - ndarr1: NDArray | NDField | blosc2.C2Array, ndarr2: NDArray | NDField | blosc2.C2Array, / -) -> blosc2.LazyExpr: +def arctan2(ndarr1: blosc2.Array, ndarr2: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the element-wise arc tangent of ``ndarr1 / ndarr2`` choosing the quadrant correctly. @@ -1206,7 +1229,7 @@ def arctan2( atan2 = arctan2 # alias -def arcsinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arcsinh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic sine, element-wise. @@ -1244,7 +1267,7 @@ def arcsinh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b asinh = arcsinh # alias -def arccosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arccosh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic cosine, element-wise. @@ -1282,7 +1305,7 @@ def arccosh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b acosh = arccosh # alias -def arctanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def arctanh(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the inverse hyperbolic tangent, element-wise. @@ -1320,7 +1343,7 @@ def arctanh(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> b atanh = arctanh # alias -def exp(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def exp(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate the exponential of all elements in the input array. @@ -1355,7 +1378,7 @@ def exp(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "exp", None)) -def expm1(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def expm1(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate ``exp(ndarr) - 1`` for all elements in the array. @@ -1390,7 +1413,7 @@ def expm1(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "expm1", None)) -def log(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Compute the natural logarithm, element-wise. @@ -1424,7 +1447,7 @@ def log(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "log", None)) -def log10(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log10(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the base 10 logarithm of the input array, element-wise. @@ -1458,7 +1481,7 @@ def log10(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "log10", None)) -def log1p(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log1p(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the natural logarithm of one plus the input array, element-wise. @@ -1492,7 +1515,7 @@ def log1p(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "log1p", None)) -def log2(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def log2(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the base 2 logarithm of the input array, element-wise. @@ -1514,7 +1537,7 @@ def log2(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "log2", None)) -def conj(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def conj(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the complex conjugate, element-wise. @@ -1548,7 +1571,7 @@ def conj(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "conj", None)) -def real(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def real(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the real part of the complex array, element-wise. @@ -1582,7 +1605,7 @@ def real(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "real", None)) -def imag(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def imag(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return the imaginary part of the complex array, element-wise. @@ -1616,9 +1639,7 @@ def imag(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blos return blosc2.LazyExpr(new_op=(ndarr, "imag", None)) -def contains( - ndarr: NDArray | NDField | blosc2.C2Array, value: str | bytes | NDArray | NDField | blosc2.C2Array, / -) -> blosc2.LazyExpr: +def contains(ndarr: blosc2.Array, value: str | bytes | blosc2.Array, /) -> blosc2.LazyExpr: """ Check if the array contains a specified value. @@ -1652,7 +1673,7 @@ def contains( return blosc2.LazyExpr(new_op=(ndarr, "contains", value)) -def abs(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def abs(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Calculate the absolute value element-wise. @@ -1686,7 +1707,7 @@ def abs(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc return blosc2.LazyExpr(new_op=(ndarr, "abs", None)) -def isnan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isnan(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for not-a-number values element-wise. @@ -1718,7 +1739,7 @@ def isnan(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "isnan", None)) -def isfinite(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isfinite(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for finite values element-wise. @@ -1750,7 +1771,7 @@ def isfinite(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> return blosc2.LazyExpr(new_op=(ndarr, "isfinite", None)) -def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +def isinf(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: """ Return True/False for infinite values element-wise. @@ -1782,7 +1803,7 @@ def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo return blosc2.LazyExpr(new_op=(ndarr, "isinf", None)) -# def nonzero(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blosc2.LazyExpr: +# def nonzero(ndarr: blosc2.Array, /) -> blosc2.LazyExpr: # """ # Return indices of nonzero values. @@ -1804,9 +1825,7 @@ def isinf(ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, /) -> blo # return ndarr.__ne__(0) -def count_nonzero( - ndarr: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, axis: int | Sequence[int] | None = None -) -> int: +def count_nonzero(ndarr: blosc2.Array, axis: int | Sequence[int] | None = None) -> int: """ Return number of nonzero values along axes. @@ -1832,8 +1851,8 @@ def count_nonzero( def equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i == x2_i for each element x1_i of the input array x1 @@ -1841,10 +1860,10 @@ def equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1860,8 +1879,8 @@ def equal( def not_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i != x2_i for each element x1_i of the input array x1 @@ -1869,10 +1888,10 @@ def not_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1888,8 +1907,8 @@ def not_equal( def less_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i <= x2_i for each element x1_i of the input array x1 @@ -1897,10 +1916,10 @@ def less_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1916,8 +1935,8 @@ def less_equal( def less( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i < x2_i for each element x1_i of the input array x1 @@ -1925,10 +1944,10 @@ def less( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1944,8 +1963,8 @@ def less( def greater_equal( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i >= x2_i for each element x1_i of the input array x1 @@ -1953,10 +1972,10 @@ def greater_equal( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -1972,8 +1991,8 @@ def greater_equal( def greater( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the truth value of x1_i > x2_i for each element x1_i of the input array x1 @@ -1981,10 +2000,10 @@ def greater( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2000,8 +2019,8 @@ def greater( def multiply( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i * x2_i for each element x1_i of the input array x1 @@ -2009,10 +2028,10 @@ def multiply( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2028,8 +2047,8 @@ def multiply( def divide( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i / x2_i for each element x1_i of the input array x1 @@ -2037,10 +2056,10 @@ def divide( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2056,8 +2075,8 @@ def divide( def nextafter( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Returns the next representable floating-point value for each element x1_i of the input @@ -2065,10 +2084,10 @@ def nextafter( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1 and have same data type. Returns @@ -2084,8 +2103,8 @@ def nextafter( def hypot( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the square root of the sum of squares for each element x1_i of the input array @@ -2093,10 +2112,10 @@ def hypot( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued floating point dtype. Returns @@ -2112,8 +2131,8 @@ def hypot( def copysign( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Composes a floating-point value with the magnitude of x1_i and the sign of x2_i @@ -2121,10 +2140,10 @@ def copysign( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued floating point dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued floating point dtype. Returns @@ -2140,8 +2159,8 @@ def copysign( def maximum( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the maximum value for each element x1_i of the input array x1 relative to the @@ -2149,10 +2168,10 @@ def maximum( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued dtype. Returns @@ -2168,8 +2187,8 @@ def maximum( def minimum( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the minimum value for each element x1_i of the input array x1 relative to the @@ -2177,10 +2196,10 @@ def minimum( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. Real-valued dtype. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Real-valued dtype. Returns @@ -2195,13 +2214,13 @@ def minimum( return blosc2.LazyExpr(new_op=(x1, "minimum", x2)) -def reciprocal(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def reciprocal(x: blosc2.Array) -> blosc2.LazyExpr: """ Computes the value of 1/x1_i for each element x1_i of the input array x1. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array, floating-point data type. Returns @@ -2216,14 +2235,14 @@ def reciprocal(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc return 1.0 / x -def floor(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def floor(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the greatest (i.e., closest to +infinity) integer-valued number that is not greater than x_i. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2238,14 +2257,14 @@ def floor(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz return blosc2.LazyExpr(new_op=(x, "floor", None)) -def ceil(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def ceil(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the smallest (i.e., closest to -infinity) integer-valued number that is not smaller than x_i. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2260,14 +2279,14 @@ def ceil(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Lazy return blosc2.LazyExpr(new_op=(x, "ceil", None)) -def trunc(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def trunc(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the closest to 0 integer-valued number. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued data type. Returns @@ -2282,7 +2301,7 @@ def trunc(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz return blosc2.LazyExpr(new_op=(x, "trunc", None)) -def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def signbit(x: blosc2.Array) -> blosc2.LazyExpr: """ Determines whether the sign bit is set for each element x_i of the input array x. @@ -2291,7 +2310,7 @@ def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any real-valued floating-point data type. Returns @@ -2306,13 +2325,13 @@ def signbit(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L return blosc2.LazyExpr(new_op=(x, "signbit", None)) -def sign(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def sign(x: blosc2.Array) -> blosc2.LazyExpr: """ Returns an indication of the sign of a number for each element x_i of the input array x. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any numeric data type. Returns @@ -2327,13 +2346,13 @@ def sign(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Lazy return blosc2.LazyExpr(new_op=(x, "sign", None)) -def round(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def round(x: blosc2.Array) -> blosc2.LazyExpr: """ Rounds each element x_i of the input array x to the nearest integer-valued number. Parameters ---------- - x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x: blosc2.Array First input array. May have any numeric data type. Returns @@ -2349,8 +2368,8 @@ def round(x: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.Laz def floor_divide( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i // x2_i for each element x1_i of the input array x1 @@ -2358,10 +2377,10 @@ def floor_divide( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any real-valued data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any real-valued data type. Returns @@ -2377,8 +2396,8 @@ def floor_divide( def add( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i + x2_i for each element x1_i of the input array x1 @@ -2386,10 +2405,10 @@ def add( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2405,8 +2424,8 @@ def add( def subtract( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr, + x1: blosc2.Array, + x2: blosc2.Array, ) -> blosc2.LazyExpr: """ Computes the value of x1_i - x2_i for each element x1_i of the input array x1 @@ -2414,10 +2433,10 @@ def subtract( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2432,13 +2451,13 @@ def subtract( return x1 - x2 -def square(x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.LazyExpr: +def square(x1: blosc2.Array) -> blosc2.LazyExpr: """ Computes the value of x1_i**2 for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2454,8 +2473,8 @@ def square(x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr) -> blosc2.L def pow( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i**x2_i for each element x1_i of the input array x1 and x2_i @@ -2463,10 +2482,10 @@ def pow( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2482,8 +2501,8 @@ def pow( def logical_xor( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i ^ x2_i for each element x1_i of the input array x1 and x2_i @@ -2491,10 +2510,10 @@ def logical_xor( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1, boolean. Returns @@ -2512,8 +2531,8 @@ def logical_xor( def logical_and( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i & x2_i for each element x1_i of the input array x1 and x2_i @@ -2521,10 +2540,10 @@ def logical_and( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Boolean. Returns @@ -2542,8 +2561,8 @@ def logical_and( def logical_or( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i | x2_i for each element x1_i of the input array x1 and x2_i @@ -2551,10 +2570,10 @@ def logical_or( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, boolean. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, boolean. Returns @@ -2572,14 +2591,14 @@ def logical_or( def logical_not( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of ~x1_i for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array Input array, boolean. Returns @@ -2597,8 +2616,8 @@ def logical_not( def bitwise_xor( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i ^ x2_i for each element x1_i of the input array x1 and x2_i @@ -2606,10 +2625,10 @@ def bitwise_xor( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1, integer or boolean. Returns @@ -2625,8 +2644,8 @@ def bitwise_xor( def bitwise_and( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i & x2_i for each element x1_i of the input array x1 and x2_i @@ -2634,10 +2653,10 @@ def bitwise_and( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. Integer or boolean. Returns @@ -2653,8 +2672,8 @@ def bitwise_and( def bitwise_or( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of x1_i | x2_i for each element x1_i of the input array x1 and x2_i @@ -2662,10 +2681,10 @@ def bitwise_or( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer or boolean. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer or boolean. Returns @@ -2681,14 +2700,14 @@ def bitwise_or( def bitwise_invert( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the value of ~x1_i for each element x1_i of the input array x1. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array Input array, integer or boolean. Returns @@ -2704,8 +2723,8 @@ def bitwise_invert( def bitwise_right_shift( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Shifts the bits of each element x1_i of the input array x1 to the right according to @@ -2716,10 +2735,10 @@ def bitwise_right_shift( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer. Returns ------- @@ -2734,8 +2753,8 @@ def bitwise_right_shift( def bitwise_left_shift( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Shifts the bits of each element x1_i of the input array x1 to the left by appending x2_i @@ -2745,10 +2764,10 @@ def bitwise_left_shift( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array, integer. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1, integer. Returns @@ -2764,14 +2783,14 @@ def bitwise_left_shift( def positive( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the numerical positive of each element x_i (i.e., out_i = +x_i) of the input array x. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2787,14 +2806,14 @@ def positive( def negative( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Computes the numerical negative of each element x_i (i.e., out_i = -x_i) of the input array x. Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. Returns @@ -2810,8 +2829,8 @@ def negative( def remainder( - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr | int | float | complex, + x1: blosc2.Array | int | float | complex, + x2: blosc2.Array | int | float | complex, ) -> blosc2.LazyExpr: """ Returns the remainder of division for each element x1_i of the input array x1 and the @@ -2821,10 +2840,10 @@ def remainder( Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any data type. - x2: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2: blosc2.Array Second input array. Must be compatible with x1. May have any data type. Returns @@ -2840,21 +2859,23 @@ def remainder( def clip( - x: NDArray, min: int | float | NDArray | None = None, max: int | float | NDArray | None = None + x: blosc2.Array, + min: int | float | blosc2.Array | None = None, + max: int | float | blosc2.Array | None = None, ) -> NDArray: """ Clamps each element x_i of the input array x to the range [min, max]. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have a real-valued data type. - min: int | float | NDArray | None + min: int | float | blosc2.Array | None Lower-bound of the range to which to clamp. If None, no lower bound must be applied. Default: None. - max: int | float | NDArray | None + max: int | float | blosc2.Array | None Upper-bound of the range to which to clamp. If None, no upper bound must be applied. Default: None. @@ -2872,7 +2893,7 @@ def chunkwise_clip(inputs, output, offset): return blosc2.lazyudf(chunkwise_clip, (x, min, max), dtype=x.dtype, shape=x.shape) -def logaddexp(x1: int | float | NDArray, x2: int | float | NDArray) -> NDArray: +def logaddexp(x1: int | float | blosc2.Array, x2: int | float | blosc2.Array) -> NDArray: """ Calculates the logarithm of the sum of exponentiations log(exp(x1) + exp(x2)) for each element x1_i of the input array x1 with the respective element x2_i of the @@ -2880,10 +2901,10 @@ def logaddexp(x1: int | float | NDArray, x2: int | float | NDArray) -> NDArray: Parameters ---------- - x1: NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x1: blosc2.Array First input array. May have any real-valued floating-point data type. - x2:NDArray | NDField | blosc2.C2Array | blosc2.LazyExpr + x2:blosc2.Array Second input array. Must be compatible with x1. May have any real-valued floating-point data type. @@ -3063,13 +3084,13 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): return NotImplemented # if not implemented in numexpr will default to NumPy - def __add__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __add__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) if blosc2.result_type(value, self) == blosc2.bool_: return blosc2.LazyExpr(new_op=(value, "|", self)) return blosc2.LazyExpr(new_op=(self, "+", value)) - def __iadd__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __iadd__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__add__(value) @is_documented_by(negative) @@ -3084,86 +3105,86 @@ def __pos__(self) -> blosc2.LazyExpr: def __mod__(self, other) -> blosc2.LazyExpr: return remainder(self, other) - def __radd__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __radd__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__add__(value) - def __sub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __sub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "-", value)) - def __isub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __isub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "-", value)) - def __rsub__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rsub__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "-", self)) @is_documented_by(multiply) - def __mul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __mul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) # catch special case of multiplying two bools (not implemented in numexpr) if blosc2.result_type(value, self) == blosc2.bool_: return blosc2.LazyExpr(new_op=(value, "&", self)) return blosc2.LazyExpr(new_op=(self, "*", value)) - def __imul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __imul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__mul__(value) - def __rmul__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rmul__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__mul__(value) - def __truediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __truediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "/", value)) - def __itruediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __itruediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: return self.__truediv__(value) - def __rtruediv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rtruediv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "/", self)) @is_documented_by(floor_divide) - def __floordiv__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __floordiv__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "//", value)) - def __lt__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __lt__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "<", value)) - def __le__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __le__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "<=", value)) - def __gt__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __gt__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, ">", value)) - def __ge__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ge__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, ">=", value)) - def __eq__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /): + def __eq__(self, value: int | float | blosc2.Array, /): _check_allowed_dtypes(value) if blosc2._disable_overloaded_equal: return self is value return blosc2.LazyExpr(new_op=(self, "==", value)) - def __ne__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ne__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "!=", value)) - def __pow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __pow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "**", value)) - def __ipow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __ipow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "**", value)) - def __rpow__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __rpow__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(value, "**", self)) @@ -3172,7 +3193,7 @@ def __abs__(self) -> blosc2.LazyExpr: return abs(self) @is_documented_by(bitwise_and) - def __and__(self, value: int | float | NDArray | NDField | blosc2.C2Array, /) -> blosc2.LazyExpr: + def __and__(self, value: int | float | blosc2.Array, /) -> blosc2.LazyExpr: _check_allowed_dtypes(value) return blosc2.LazyExpr(new_op=(self, "&", value)) @@ -4681,8 +4702,8 @@ def array_from_ffi_ptr(array_ptr) -> NDArray: def where( condition: blosc2.LazyExpr | NDArray, - x: NDArray | NDField | np.ndarray | int | float | complex | bool | str | bytes | None = None, - y: NDArray | NDField | np.ndarray | int | float | complex | bool | str | bytes | None = None, + x: blosc2.Array | int | float | complex | bool | str | bytes | None = None, + y: blosc2.Array | int | float | complex | bool | str | bytes | None = None, ) -> blosc2.LazyExpr: """ Return elements chosen from `x` or `y` depending on `condition`. @@ -5553,9 +5574,7 @@ def save(array: NDArray, urlpath: str, contiguous=True, **kwargs: Any) -> None: array.save(urlpath, contiguous, **kwargs) -def asarray( - array: Sequence | np.ndarray | blosc2.C2Array | NDArray, copy: bool | None = None, **kwargs: Any -) -> NDArray: +def asarray(array: Sequence | blosc2.Array, copy: bool | None = None, **kwargs: Any) -> NDArray: """Convert the `array` to an `NDArray`. Parameters @@ -5564,7 +5583,7 @@ def asarray( An array supporting numpy array interface. copy: bool | None, optional - Whether or not to copy the input. If True, the function copies. + Whether to copy the input. If True, the function copies. If False, raise a ValueError if copy is necessary. If None and input is NDArray, avoid copy by returning lazyexpr. Default: None. @@ -5658,7 +5677,7 @@ def asarray( def astype( - array: Sequence | np.ndarray | NDArray | blosc2.C2Array, + array: Sequence | blosc2.Array, dtype, casting: str = "unsafe", copy: bool = True, @@ -5669,7 +5688,7 @@ def astype( Parameters ---------- - array: Sequence | np.ndarray | NDArray | blosc2.C2Array + array: Sequence | blosc2.Array The array to be cast to a different type. dtype: DType-like The desired data type to cast to. @@ -5785,7 +5804,7 @@ def get_slice_nchunks( return blosc2_ext.schunk_get_slice_nchunks(schunk, key) -def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: +def indices(array: blosc2.Array, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: """ Return the indices of a sorted array following the specified order. @@ -5793,7 +5812,7 @@ def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) Parameters ---------- - array: :ref:`NDArray` + array: :ref:`blosc2.Array` The (structured) array to be sorted. order: str, list of str, optional Specifies which fields to compare first, second, etc. A single @@ -5820,7 +5839,7 @@ def indices(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) return larr.indices(order).compute(**kwargs) -def sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: +def sort(array: blosc2.Array, order: str | list[str] | None = None, **kwargs: Any) -> NDArray: """ Return a sorted array following the specified order. @@ -5828,7 +5847,7 @@ def sort(array: NDArray, order: str | list[str] | None = None, **kwargs: Any) -> Parameters ---------- - array: :ref:`NDArray` + array: :ref:`blosc2.Array` The (structured) array to be sorted. order: str, list of str, optional Specifies which fields to compare first, second, etc. A single @@ -5947,7 +5966,7 @@ def __getitem__(self, key: int | slice | Sequence[slice]) -> np.ndarray: # And return the field return nparr[self.field] - def __setitem__(self, key: int | slice | Sequence[slice], value: np.ndarray | NDArray | NDField) -> None: + def __setitem__(self, key: int | slice | Sequence[slice], value: blosc2.Array) -> None: """ Set a slice of :paramref:`self` to a value. @@ -5955,12 +5974,12 @@ def __setitem__(self, key: int | slice | Sequence[slice], value: np.ndarray | ND ---------- key: int or slice or Sequence[slice] The slice to be set. - value: np.ndarray or NDArray or NDField + value: blosc2.Array The value to be set. """ if isinstance(key, str): raise TypeError("This array is a NDField; use a structured NDArray for bool expressions") - if isinstance(value, (NDField, NDArray)): + if not isinstance(value, np.ndarray): value = value[:] # Get the values in the parent NDArray nparr = self.ndarr[key] @@ -6009,13 +6028,13 @@ def __setitem__(self, selection, input) -> np.ndarray: # return NotImplementedError -def empty_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def empty_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an uninitialized array with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6036,13 +6055,13 @@ def empty_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.empty(shape=x.shape, dtype=dtype, **kwargs) -def ones_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def ones_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an array of ones with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6063,13 +6082,13 @@ def ones_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.ones(shape=x.shape, dtype=dtype, **kwargs) -def zeros_like(x: NDArray, dtype=None, **kwargs) -> NDArray: +def zeros_like(x: blosc2.Array, dtype=None, **kwargs) -> NDArray: """ Returns an array of zeros with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. dtype (Optional): @@ -6090,13 +6109,13 @@ def zeros_like(x: NDArray, dtype=None, **kwargs) -> NDArray: return blosc2.zeros(shape=x.shape, dtype=dtype, **kwargs) -def full_like(x: NDArray, fill_value: bool | int | float | complex, dtype=None, **kwargs) -> NDArray: +def full_like(x: blosc2.Array, fill_value: bool | int | float | complex, dtype=None, **kwargs) -> NDArray: """ Returns an array filled with a value with the same shape as an input array x. Parameters ---------- - x : NDArray + x : blosc2.Array Input array from which to derive the output array shape. fill_value: bool | int | float | complex @@ -6120,13 +6139,13 @@ def full_like(x: NDArray, fill_value: bool | int | float | complex, dtype=None, return blosc2.full(shape=x.shape, fill_value=fill_value, dtype=dtype, **kwargs) -def take(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int | None = None) -> NDArray: +def take(x: blosc2.Array, indices: blosc2.Array, axis: int | None = None) -> NDArray: """ Returns elements of an array along an axis. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have one or more dimensions (axes). indices: array-like @@ -6159,13 +6178,13 @@ def take(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int | None = return blosc2.asarray(x[key]) -def take_along_axis(x: NDArray, indices: NDArray[int] | np.ndarray[int], axis: int = -1) -> NDArray: +def take_along_axis(x: blosc2.Array, indices: blosc2.Array, axis: int = -1) -> NDArray: """ Returns elements of an array along an axis. Parameters ---------- - x: NDArray + x: blosc2.Array Input array. Should have one or more dimensions (axes). indices: array-like @@ -6311,14 +6330,14 @@ def get_intersecting_chunks(_slice, shape, chunks): ) # chunk is whole array so just return full tuple to do loop once -def broadcast_to(arr, shape): +def broadcast_to(arr: blosc2.Array, shape: tuple[int, ...]) -> NDArray: """ Broadcast an array to a new shape. Warning: Computes a lazyexpr, so probably a bit suboptimal Parameters ---------- - array: NDArray + arr: blosc2.Array The array to broadcast. shape: tuple @@ -6329,16 +6348,16 @@ def broadcast_to(arr, shape): broadcast: NDArray A new array with the given shape. """ - return (arr + blosc2.zeros(shape, dtype=arr.dtype)).compute() # return lazyexpr quickly + return (arr + blosc2.zeros(shape, dtype=arr.dtype)).compute() -def meshgrid(*arrays: NDArray, indexing: str = "xy") -> Sequence[NDArray]: +def meshgrid(*arrays: blosc2.Array, indexing: str = "xy") -> Sequence[NDArray]: """ Returns coordinate matrices from coordinate vectors. Parameters ---------- - arrays: NDArray + *arrays: blosc2.Array An arbitrary number of one-dimensional arrays representing grid coordinates. Each array should have the same numeric data type. indexing: str diff --git a/src/blosc2/tree_store.py b/src/blosc2/tree_store.py index ad4c0c6e..e6bf5fdb 100644 --- a/src/blosc2/tree_store.py +++ b/src/blosc2/tree_store.py @@ -8,15 +8,18 @@ import contextlib import os from collections.abc import Iterator, MutableMapping +from typing import TYPE_CHECKING import numpy as np import blosc2 -from blosc2.c2array import C2Array from blosc2.dict_store import DictStore -from blosc2.ndarray import NDArray from blosc2.schunk import SChunk +if TYPE_CHECKING: + from blosc2.c2array import C2Array + from blosc2.ndarray import NDArray + class vlmetaProxy(MutableMapping): """Proxy for SChunk.vlmeta to control access and slicing. @@ -223,7 +226,7 @@ def _validate_key(self, key: str) -> str: return key - def __setitem__(self, key: str, value: np.ndarray | NDArray | C2Array | SChunk) -> None: + def __setitem__(self, key: str, value: blosc2.Array | SChunk) -> None: """Add a node with hierarchical key validation. Parameters