Skip to content

Commit 485c462

Browse files
committed
Decorator cengine renamed to jit and added to docs
1 parent f320990 commit 485c462

File tree

7 files changed

+49
-26
lines changed

7 files changed

+49
-26
lines changed

README_DEVELOPERS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ If you want to run the network tests, you can use the following command:
4646

4747
## Documentation
4848

49-
We are using Sphinx for documentation. You can build the documentation by executing
49+
We are using Sphinx for documentation. You can build the documentation by executing:
5050

5151
``` bash
5252
cd doc
5353
rm -rf html _build
5454
python -m sphinx . html
5555
```
56+
[You may need to install the `pandoc` package first: https://pandoc.org/installing.html]
5657

5758
You will find the documentation in the `html` directory.

bench/ndarray/cengine-expr.py renamed to bench/ndarray/jit-expr.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#######################################################################
2+
# Copyright (c) 2019-present, Blosc Development Team <[email protected]>
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under a BSD-style license (found in the
6+
# LICENSE file in the root directory of this source tree)
7+
#######################################################################
8+
9+
# Compute expressions for different array sizes, using the jit decorator.
10+
111
from time import time
212
import blosc2
313
import numpy as np
@@ -44,13 +54,13 @@ def compute_expression_numpy(a, b, c):
4454
print(f"Time to compute with NumExpr: {t1:.5f}")
4555
print(f"Speedup: {tref / t1:.2f}x")
4656

47-
@blosc2.cengine
57+
@blosc2.jit
4858
def compute_expression_nocompr(a, b, c):
4959
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
5060

5161
print("\nUsing NumPy operands...")
5262

53-
@blosc2.cengine(cparams=cparams_out)
63+
@blosc2.jit(cparams=cparams_out)
5464
def compute_expression_compr(a, b, c):
5565
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
5666

@@ -115,7 +125,7 @@ def compute_expression_compr(a, b, c):
115125
# c = blosc2.asarray(nc, cparams=cparams, chunks=chunks, blocks=blocks)
116126
print(f"{a.chunks=}, {a.blocks=}, {a.schunk.cratio=:.2f}x")
117127

118-
@blosc2.cengine(cparams=cparams_out)
128+
@blosc2.jit(cparams=cparams_out)
119129
def compute_expression_compr(a, b, c):
120130
return ((a ** 3 + np.sin(a * 2)) < c) & (b > 0)
121131

bench/ndarray/cengine-reduc.py renamed to bench/ndarray/jit-reduc.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
#######################################################################
2+
# Copyright (c) 2019-present, Blosc Development Team <[email protected]>
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under a BSD-style license (found in the
6+
# LICENSE file in the root directory of this source tree)
7+
#######################################################################
8+
9+
# Compute expressions for different array sizes, using the jit decorator.
10+
111
from time import time
212
import blosc2
313
import numpy as np
4-
import numexpr as ne
514

615
niter = 5
716
# Create some data operands
@@ -36,13 +45,13 @@ def compute_expression_numpy(a, b, c):
3645
tref = time() - t0
3746
print(f"Time to compute with NumPy engine: {tref:.5f}")
3847

39-
@blosc2.cengine
48+
@blosc2.jit
4049
def compute_expression_nocompr(a, b, c):
4150
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1)
4251

4352
print("\nUsing NumPy operands...")
4453

45-
@blosc2.cengine
54+
@blosc2.jit
4655
def compute_expression_compr(a, b, c, out):
4756
return np.sum(((a ** 3 + np.sin(a * 2)) < c) & (b > 0), axis=1, out=out)
4857

doc/reference/decorators.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Decorators
2+
----------
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
8+
.. autofunction:: blosc2.jit

doc/reference/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ API Reference
88
save_load
99
storage
1010
array_operations
11+
decorators
1112
low_level

src/blosc2/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Tuner(Enum):
248248
get_expr_operands,
249249
validate_expr,
250250
)
251-
from .proxy import Proxy, ProxySource, ProxyNDSource, ProxyNDField, SimpleProxy, cengine
251+
from .proxy import Proxy, ProxySource, ProxyNDSource, ProxyNDField, SimpleProxy, jit
252252

253253
from .schunk import SChunk, open
254254

src/blosc2/proxy.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from abc import ABC, abstractmethod
99

1010
import numpy as np
11+
from traitlets import Callable
1112

1213
import blosc2
1314

@@ -580,20 +581,22 @@ def __getitem__(self, item: slice | list[slice]) -> np.ndarray:
580581
return self.src[item]
581582

582583

583-
def cengine(func=None, out=None, **kwargs): # noqa: C901
584+
def jit(func : Callable, out=None, **kwargs): # noqa: C901
584585
"""
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.
586587
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
589590
:ref:`SimpleProxy` objects, whereas NDArray objects will be used as is.
590591
591592
The returned value will be a NumPy array if all arguments are NumPy arrays
592593
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.
594595
595596
Parameters
596597
----------
598+
func: callable
599+
The function to be prepared for the Blosc2 compute engine.
597600
out: np.ndarray, NDArray, optional
598601
The output array where the result will be stored.
599602
**kwargs: dict, optional
@@ -607,24 +610,15 @@ def cengine(func=None, out=None, **kwargs): # noqa: C901
607610
-----
608611
* Although many NumPy functions are supported, some may not be implemented yet.
609612
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.
622616
623617
Examples
624618
--------
625619
>>> import numpy as np
626620
>>> import blosc2
627-
>>> @blosc2.cengine
621+
>>> @blosc2.jit
628622
>>> def compute_expression(a, b, c):
629623
>>> return np.sum(((a ** 3 + np.sin(a * 2)) > 2 * c) & (b > 0), axis=1)
630624
>>> a = np.arange(20, dtype=np.float32).reshape(4, 5)

0 commit comments

Comments
 (0)