8
8
from abc import ABC , abstractmethod
9
9
10
10
import numpy as np
11
+ from traitlets import Callable
11
12
12
13
import blosc2
13
14
@@ -580,20 +581,22 @@ def __getitem__(self, item: slice | list[slice]) -> np.ndarray:
580
581
return self .src [item ]
581
582
582
583
583
- def cengine (func = None , out = None , ** kwargs ): # noqa: C901
584
+ def jit (func : Callable , out = None , ** kwargs ): # noqa: C901
584
585
"""
585
- Wrap a function so that it can be used with the Blosc2 compute engine.
586
+ Prepare a function so that it can be used with the Blosc2 compute engine.
586
587
587
- The inputs can be any combination of NumPy/NDArray arrays and scalars.
588
- The function will be called with the NumPy arrays replaced by
588
+ The inputs of the function can be any combination of NumPy/NDArray arrays
589
+ and scalars. The function will be called with the NumPy arrays replaced by
589
590
:ref:`SimpleProxy` objects, whereas NDArray objects will be used as is.
590
591
591
592
The returned value will be a NumPy array if all arguments are NumPy arrays
592
593
or if not kwargs are provided. Else, the return value will be a NDArray
593
- created using the provided kwargs (or the default ones) .
594
+ created using the provided kwargs.
594
595
595
596
Parameters
596
597
----------
598
+ func: callable
599
+ The function to be prepared for the Blosc2 compute engine.
597
600
out: np.ndarray, NDArray, optional
598
601
The output array where the result will be stored.
599
602
**kwargs: dict, optional
@@ -607,24 +610,15 @@ def cengine(func=None, out=None, **kwargs): # noqa: C901
607
610
-----
608
611
* Although many NumPy functions are supported, some may not be implemented yet.
609
612
If you find a function that is not supported, please open an issue.
610
- * Due to implementation, the `out` and `kwargs` parameters are not supported
611
- for all expressions (e.g. when using a reduction as the last function).
612
- In this case, you can still use the `out` parameter of the reduction function
613
- for some custom control over the output.
614
-
615
- Parameters
616
- ----------
617
- func
618
-
619
- Returns
620
- -------
621
- wrapper
613
+ * `kwargs` parameters are not supported for all expressions (e.g. when using a
614
+ reduction as the last function). In this case, you can still use the `out`
615
+ parameter of the reduction function for some custom control over the output.
622
616
623
617
Examples
624
618
--------
625
619
>>> import numpy as np
626
620
>>> import blosc2
627
- >>> @blosc2.cengine
621
+ >>> @blosc2.jit
628
622
>>> def compute_expression(a, b, c):
629
623
>>> return np.sum(((a ** 3 + np.sin(a * 2)) > 2 * c) & (b > 0), axis=1)
630
624
>>> a = np.arange(20, dtype=np.float32).reshape(4, 5)
0 commit comments