Skip to content

Commit 7d52393

Browse files
committed
Merge branch 'main' of github.com:Blosc/python-blosc2
2 parents adf6c45 + 33cf5cd commit 7d52393

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ repos:
1616
- id: trailing-whitespace
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.13.0
19+
rev: v0.13.3
2020
hooks:
2121
- id: ruff-check
2222
args: ["--fix", "--show-fixes"]
2323
- id: ruff-format
2424
exclude: ^bench/
2525

2626
- repo: https://github.com/adamchainz/blacken-docs
27-
rev: 1.19.1
27+
rev: 1.20.0
2828
hooks:
2929
- id: blacken-docs
3030
additional_dependencies: [black==24.*]

ANNOUNCE.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ which matches NumPy behaviour.
1010

1111
You can think of Python-Blosc2 3.x as an extension of NumPy/numexpr that:
1212

13-
- Can deal with ndarrays compressed using first-class codecs & filters.
13+
- Can deal with NDArray compressed objects using first-class codecs & filters.
1414
- Performs many kind of math expressions, including reductions, indexing...
15+
- Supports multi-threading and SIMD acceleration (via numexpr).
16+
- Can operate with data from other libraries (like PyTables, h5py, Zarr, Dask, etc).
1517
- Supports NumPy ufunc mechanism: mix and match NumPy and Blosc2 computations.
1618
- Integrates with Numba and Cython via UDFs (User Defined Functions).
1719
- Adheres to modern NumPy casting rules way better than numexpr.
18-
- Performs linear algebra operations (like ``blosc2.matmul()``).
20+
- Performs linear algebra operations (like ``blosc2.tensordot()``).
1921

2022
Install it with::
2123

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# Example on how to use xarray containers as operands in Blosc2 expressions
10+
# Note that there is no special support for xarray in Blosc2; the techniques
11+
# below works for any object that implements the Array protocol (i.e. having
12+
# a shape and dtype attributes, and a __getitem__ method and a __len__ method.
13+
14+
import numpy as np
15+
import xarray
16+
17+
import blosc2
18+
19+
20+
class NewObj(blosc2.Array):
21+
def __init__(self, a):
22+
self.a = a
23+
24+
@property
25+
def shape(self):
26+
return self.a.shape
27+
28+
@property
29+
def dtype(self):
30+
return self.a.dtype
31+
32+
def __getitem__(self, key):
33+
return self.a[key]
34+
35+
def __len__(self):
36+
return len(self.a)
37+
38+
39+
a = np.arange(100, dtype=np.int64).reshape(10, 10)
40+
res = a + np.sin(a) + np.hypot(a, a) + 1
41+
42+
a = xarray.DataArray(a) # supported natively by blosc2; no copies
43+
b = NewObj(a) # minimal Array protocol implementation; no copies
44+
assert isinstance(b, blosc2.Array) # any Array compliant object works
45+
c = blosc2.asarray(a) # convert into a blosc2.NDArray; data is copied
46+
d = blosc2.SimpleProxy(a) # SimpleProxy conversion; no copies
47+
# Define a lazy expression (defer computation until needed)
48+
lb = blosc2.lazyexpr("a + sin(b) + hypot(c, d) + 1")
49+
50+
# Check!
51+
np.testing.assert_array_equal(lb[:], res)
52+
# One can also evaluate the expression directly (eager computation)
53+
resb2 = blosc2.evaluate("a + sin(b) + hypot(c, d) + 1")
54+
np.testing.assert_array_equal(resb2, res)

src/blosc2/core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,13 @@ def set_nthreads(nthreads: int) -> int:
920920
921921
Notes
922922
-----
923+
The number of threads can also be set via the ``BLOSC_NTHREADS`` environment
924+
variable (e.g., ``export BLOSC_NTHREADS=1``). Additionally, you may want to set
925+
``NUMEXPR_NUM_THREADS`` (e.g., ``export NUMEXPR_NUM_THREADS=1``) as well since
926+
numexpr is used under the hood when performing some operations. Note that
927+
this function only sets the number of threads used by Blosc, not the number
928+
of threads used by numexpr.
929+
923930
The maximum number of threads for Blosc is :math:`2^{31} - 1`. In some
924931
cases, Blosc gets better results if you set the number of threads
925932
to a value slightly below your number of cores

0 commit comments

Comments
 (0)