Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
aeee83b
Very preliminary attempt to use the miniexpr library
FrancescAlted Dec 8, 2025
8358c59
Upgrade version of miniexpr
FrancescAlted Dec 12, 2025
0483cd1
Using me_compile_chunk in register prefilter
FrancescAlted Dec 12, 2025
f1986cc
Use me_dtype_from_numpy and others
FrancescAlted Dec 12, 2025
8c6249d
First preliminary version that works with miniexpr (for simple cases)
FrancescAlted Dec 12, 2025
cd0c4da
miniexpr prefilter doesn't hold the gil anymore
FrancescAlted Dec 13, 2025
42189d9
miniexpr prefilter finally works in multithread mode!
FrancescAlted Dec 13, 2025
a2a7259
Fix a compilation error on linux
FrancescAlted Dec 13, 2025
f599cdb
Be more conservative for blocksize in apple silicon
FrancescAlted Dec 13, 2025
3bf54c9
Add a comparsion against numexpr
FrancescAlted Dec 13, 2025
ef9dc80
Update to latest miniexpr sources
FrancescAlted Dec 17, 2025
e345d9c
Fix a leak
FrancescAlted Dec 17, 2025
655efec
Add a comparison against NumPy
FrancescAlted Dec 17, 2025
1d56614
Selectively try miniexpr, if possible
FrancescAlted Dec 17, 2025
cd26133
Create a new context for each input
FrancescAlted Dec 18, 2025
b3742f8
Updated to latest miniexpr (bools as result of comparsions)
FrancescAlted Dec 21, 2025
36065c3
Fixed many things with miniexpr backend
FrancescAlted Dec 21, 2025
232e485
More defensive protection when calling C funcs
FrancescAlted Dec 21, 2025
6da99ae
Disable parallel mode for numba
FrancescAlted Dec 21, 2025
ac430ac
Better examplanation on why we disable parallel
FrancescAlted Dec 22, 2025
c51f528
Fix many issues with type casting in miniexpr
FrancescAlted Dec 23, 2025
4be0758
Add inverse hyperbolic funcs
FrancescAlted Dec 23, 2025
0abfb65
Add conj and imag complex funcs
FrancescAlted Dec 23, 2025
d1d922e
Add more functions to miniexpr
FrancescAlted Dec 23, 2025
620c980
New where() func in miniexpr
FrancescAlted Dec 23, 2025
5545a81
Support for windows
FrancescAlted Dec 23, 2025
d88dcbb
Changing to clang-cl on win
FrancescAlted Dec 23, 2025
d65f2dc
Upgrade version of miniexpr
FrancescAlted Dec 24, 2025
147cb80
Changing MSVC to clang-cl on win (II)
FrancescAlted Dec 24, 2025
9e8f677
Changing MSVC to clang-cl on win (III)
FrancescAlted Dec 24, 2025
8e5ed3b
Changing MSVC to clang-cl on win (IV)
FrancescAlted Dec 24, 2025
9ac57e9
Changing MSVC to clang-cl on win (V)
FrancescAlted Dec 24, 2025
1a473f5
Changing MSVC to clang-cl on win (VI)
FrancescAlted Dec 24, 2025
07cd2d8
Changing MSVC to clang-cl on win (VII)
FrancescAlted Dec 24, 2025
3170053
Changing MSVC to clang-cl on win (VIII)
FrancescAlted Dec 24, 2025
d194bd6
Changing MSVC to clang-cl on win (IX)
FrancescAlted Dec 24, 2025
426876a
Changing MSVC to clang-cl on win (X)
FrancescAlted Dec 24, 2025
639d483
Changing MSVC to clang-cl on win (XI)
FrancescAlted Dec 24, 2025
c35159f
Clang is detected now! Cleanup logs
FrancescAlted Dec 24, 2025
d189614
Changing MSVC to clang-cl on win (XII)
FrancescAlted Dec 24, 2025
c64af49
Changing MSVC to clang-cl on win (XIII)
FrancescAlted Dec 24, 2025
b7bf114
Changing MSVC to clang-cl on win (XIV)
FrancescAlted Dec 24, 2025
6d0d2b8
Remove llvm forced installation
FrancescAlted Dec 24, 2025
6d81b09
Link with clang_rt
FrancescAlted Dec 24, 2025
a2c955e
We are requring C11
FrancescAlted Dec 24, 2025
167be9e
We are requring C11; this time globally.
FrancescAlted Dec 24, 2025
f1ff22e
Debugging a test crash on win
FrancescAlted Dec 24, 2025
37dae78
Go back to require C11 in th extension only
FrancescAlted Dec 24, 2025
7296e48
Use sscache to accelerate builds in CI
FrancescAlted Dec 24, 2025
4e1475c
Add instructions on how to accelerate local builds
FrancescAlted Dec 24, 2025
7b3b663
Run tests in single thread mode for windows
FrancescAlted Dec 24, 2025
92f7df8
Add more info about accelerated builds
FrancescAlted Dec 24, 2025
9c2a902
Debugging on CI windows...
FrancescAlted Dec 24, 2025
eb1007a
Deactivate miniexpr on windows
FrancescAlted Dec 24, 2025
c04a299
Use clang-cl and others bells and wisthels
FrancescAlted Dec 24, 2025
e2ab03f
Further .yml simplications
FrancescAlted Dec 24, 2025
340fccd
Simplified cmake config
FrancescAlted Dec 24, 2025
8155136
Add notes about new clang-cl dependency on windows
FrancescAlted Dec 24, 2025
f07a7f5
Updated to latest miniexpr sources
FrancescAlted Dec 31, 2025
12f0a29
Testing multithreaded reductions
FrancescAlted Jan 2, 2026
068d423
Some fixes and experiments
FrancescAlted Jan 2, 2026
fb9f296
Clear output buffer
FrancescAlted Jan 2, 2026
47cdf2a
Add a benchmark for reductions (preliminary)
FrancescAlted Jan 2, 2026
999a1b6
Upgrade to latest openzl commit in c-blosc2
FrancescAlted Jan 3, 2026
5ceba21
Optimization for dispose outputs in reductions
FrancescAlted Jan 3, 2026
d7b0f21
Allow miniexpr to take care of reductions with multi-operand expressions
FrancescAlted Jan 3, 2026
8bce9f4
Improvements in reduction benchs
FrancescAlted Jan 3, 2026
4834614
More complex expression in bench
FrancescAlted Jan 3, 2026
ec65a7d
Update to latest miniexpr, and some nicer stats in benchs
FrancescAlted Jan 4, 2026
54748a3
Minor fix
FrancescAlted Jan 4, 2026
e70a31a
Improved conditions determining when miniexpr can enter into action
FrancescAlted Jan 4, 2026
58baecc
Benefit Intel architectures for now
FrancescAlted Jan 4, 2026
eb43bf2
New (faster) way of evaluating with miniexpr
FrancescAlted Jan 5, 2026
07ccba9
Use the new version of miniexpr as a library
FrancescAlted Jan 8, 2026
a179ea1
Relax precision checking for tan in miniexpr
FrancescAlted Jan 8, 2026
4e65f59
Only attempt to compile the static version of miniexpr
FrancescAlted Jan 8, 2026
cda72e2
Set Position Independent Code when compiling miniexpr
FrancescAlted Jan 8, 2026
a604af2
Remove torch as a test requirement (too heavy dependency)
FrancescAlted Jan 8, 2026
ac019cb
Deactivate openzl on wasm platforms (requires too advanced C11)
FrancescAlted Jan 8, 2026
d521d4b
More fixing issues on windows
FrancescAlted Jan 8, 2026
677cfe6
Protect tests that depend on torch
FrancescAlted Jan 8, 2026
e55bf99
More granularity in protecting tests requiring torch
FrancescAlted Jan 8, 2026
65d2738
Fix result checks
FrancescAlted Jan 8, 2026
891c9ae
Fix result checks
FrancescAlted Jan 8, 2026
a05ed3c
Fetch the latest commit only
FrancescAlted Jan 8, 2026
55d5e8f
Fix PATH parsing issues on win
FrancescAlted Jan 8, 2026
e099898
miniexpr is not designed for WASM (it does not support multithreading)
FrancescAlted Jan 8, 2026
c4367ef
Disabling miniexpr for windows, as it has some issues yet
FrancescAlted Jan 8, 2026
57de907
Hook for ignoring transient request failures for tests requiring network
FrancescAlted Jan 8, 2026
651e6aa
Switch to openzl branch in c-blosc2
FrancescAlted Jan 9, 2026
5b7afed
Switch to *add_openzl* branch in c-blosc2
FrancescAlted Jan 9, 2026
eb9d40a
Improvements in miniexpr prefilter for more broader use cases
FrancescAlted Jan 9, 2026
3be7455
Allow to run miniexpr is more cases (specially 1-dim)
FrancescAlted Jan 10, 2026
4f5a969
Added a note about same dtypes in expressions
FrancescAlted Jan 10, 2026
ff53849
Miniexpr now correctly detects that it does not support nested mixed-…
FrancescAlted Jan 12, 2026
3c639ed
Return int64 for reductions of bools
FrancescAlted Jan 13, 2026
f9c0324
Broaden the use cases for miniexpr to all 1-dim cases
FrancescAlted Jan 13, 2026
f07b60b
Better offset calculation for incomplete chunks at the end
FrancescAlted Jan 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
build_wheels:
name: Build and test on ${{ matrix.os }}${{ matrix.numpy-version && format(' (numpy {0})', matrix.numpy-version) || '' }}
runs-on: ${{ matrix.os }}
env:
CMAKE_GENERATOR: Ninja
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
Expand All @@ -30,15 +32,65 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install sccache (Windows)
if: runner.os == 'Windows'
run: choco install sccache --yes

- name: Cache sccache (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: C:\Users\runneradmin\AppData\Local\sccache
key: sccache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
sccache-${{ runner.os }}-

- name: Cache pip (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: C:\Users\runneradmin\AppData\Local\pip\Cache
key: pip-${{ runner.os }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
pip-${{ runner.os }}-

- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@master

- name: Add LLVM to PATH (Windows)
if: runner.os == 'Windows'
run: echo "C:\\Program Files\\LLVM\\bin" >> $env:GITHUB_PATH

- name: Install specific numpy version
if: matrix.numpy-version
run: pip install "numpy==${{ matrix.numpy-version }}.*"

- name: Build
- name: Build (Windows)
if: runner.os == 'Windows'
id: build_windows
run: pip install -e .[test]
env:
CMAKE_C_COMPILER_LAUNCHER: sccache
CMAKE_CXX_COMPILER_LAUNCHER: sccache
SCCACHE_DIR: C:\Users\runneradmin\AppData\Local\sccache
CC: clang-cl
CXX: clang-cl
CMAKE_BUILD_PARALLEL_LEVEL: 8
SKBUILD_PARALLEL_LEVEL: 8

- name: Build (non-Windows)
if: runner.os != 'Windows'
id: build_non_windows
run: pip install -e .[test]

- name: Test
- name: Test (Windows)
if: runner.os == 'Windows'
run: python -m pytest -m "not heavy and (network or not network)"
# env:
# BLOSC_NTHREADS: "1"
# NUMEXPR_NUM_THREADS: "1"
# OMP_NUM_THREADS: "1"

- name: Test (non-Windows)
if: runner.os != 'Windows'
run: python -m pytest -m "not heavy and (network or not network)"
9 changes: 9 additions & 0 deletions .github/workflows/cibuildwheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ env:
# Skip PyPy wheels for now (numexpr needs some adjustments first)
# musllinux takes too long to build, and it's not worth it for now
CIBW_SKIP: "pp* *musllinux* *-win32"
# Use explicit generator/compiler env vars; CMAKE_ARGS with spaces is not split on Windows.
CIBW_ENVIRONMENT_WINDOWS: >-
CMAKE_GENERATOR=Ninja
CC=clang-cl
CXX=clang-cl
jobs:

Expand Down Expand Up @@ -77,6 +82,10 @@ jobs:
id: ninja
uses: turtlesec-no/get-ninja@main

- name: Add LLVM to PATH (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: echo "C:\\Program Files\\LLVM\\bin" >> $env:GITHUB_PATH

- name: Install MSVC amd64
uses: ilammy/msvc-dev-cmd@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
env:
CIBW_BUILD: ${{ matrix.cibw_build }}
CMAKE_ARGS: "-DWITH_OPTIM=OFF"
DEACTIVATE_OPENZL: "1"
CIBW_TEST_COMMAND: "pytest {project}/tests/ndarray/test_reductions.py"
strategy:
matrix:
Expand Down
70 changes: 69 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
cmake_minimum_required(VERSION 3.15.0)

if(WIN32)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE STRING "" FORCE)
endif()


if(WIN32 AND CMAKE_GENERATOR MATCHES "Visual Studio")
if(NOT DEFINED CMAKE_GENERATOR_TOOLSET)
set(CMAKE_GENERATOR_TOOLSET "ClangCL" CACHE STRING "Use ClangCL toolset for C99/C11 support on Windows." FORCE)
endif()
endif()

project(python-blosc2)

if(WIN32 AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
message(FATAL_ERROR "Windows builds require clang-cl. Set CC/CXX to clang-cl or configure CMake with -T ClangCL.")
endif()
# Specifying Python version below is tricky, but if you don't specify the minimum version here,
# it would not consider python3 when looking for the executable. This is problematic since Fedora
# does not include a python symbolic link to python3.
Expand All @@ -23,11 +40,55 @@ add_custom_command(
"${CMAKE_CURRENT_SOURCE_DIR}/src/blosc2/blosc2_ext.pyx" --output-file blosc2_ext.c
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/blosc2/blosc2_ext.pyx"
VERBATIM)

# ...and add it to the target
Python_add_library(blosc2_ext MODULE blosc2_ext.c WITH_SOABI)

# We need to link against NumPy
target_link_libraries(blosc2_ext PRIVATE Python::NumPy)

# Fetch and build miniexpr library
include(FetchContent)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(MINIEXPR_BUILD_SHARED OFF CACHE BOOL "Build miniexpr shared library" FORCE)
set(MINIEXPR_BUILD_TESTS OFF CACHE BOOL "Build miniexpr tests" FORCE)
set(MINIEXPR_BUILD_EXAMPLES OFF CACHE BOOL "Build miniexpr examples" FORCE)
set(MINIEXPR_BUILD_BENCH OFF CACHE BOOL "Build miniexpr benchmarks" FORCE)

FetchContent_Declare(miniexpr
GIT_REPOSITORY https://github.com/Blosc/miniexpr.git
GIT_TAG sleef # latest SIMD additions
# In case you want to use a local copy of miniexpr for development, uncomment the line below
# SOURCE_DIR "/Users/faltet/blosc/miniexpr"
)
FetchContent_MakeAvailable(miniexpr)

# Link against miniexpr static library
target_link_libraries(blosc2_ext PRIVATE miniexpr_static)

target_compile_features(blosc2_ext PRIVATE c_std_11)
if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang")
execute_process(
COMMAND "${CMAKE_C_COMPILER}" -print-resource-dir
OUTPUT_VARIABLE _clang_resource_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(_clang_resource_dir)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_clang_builtins "${_clang_resource_dir}/lib/windows/clang_rt.builtins-x86_64.lib")
else()
set(_clang_builtins "${_clang_resource_dir}/lib/windows/clang_rt.builtins-i386.lib")
endif()
if(EXISTS "${_clang_builtins}")
target_link_libraries(blosc2_ext PRIVATE "${_clang_builtins}")
endif()
unset(_clang_builtins)
endif()
unset(_clang_resource_dir)
endif()

if(DEFINED ENV{USE_SYSTEM_BLOSC2})
set(USE_SYSTEM_BLOSC2 ON)
endif()
Expand All @@ -44,13 +105,20 @@ else()
set(BUILD_EXAMPLES OFF CACHE BOOL "Build C-Blosc2 examples")
set(BUILD_BENCHMARKS OFF CACHE BOOL "Build C-Blosc2 benchmarks")
set(BUILD_FUZZERS OFF CACHE BOOL "Build C-Blosc2 fuzzers")
if(DEFINED ENV{DEACTIVATE_OPENZL})
set(DEACTIVATE_OPENZL ON CACHE BOOL "Do not include support for the OpenZL library.")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# we want the binaries of the C-Blosc2 library to go into the wheels
set(BLOSC_INSTALL ON)
include(FetchContent)
FetchContent_Declare(blosc2
GIT_REPOSITORY https://github.com/Blosc/c-blosc2
GIT_TAG 5a2b0ed9c4d801230c118fbc5811817055b5a3f5 # v2.22.0
# GIT_TAG 9d250c2201f6e385c56a372b08037f7debc6fa1b # openzl (disposable output)
GIT_TAG add_openzl
GIT_SHALLOW TRUE # fetch only the latest commit (only works with a branch in GIT_TAG)
# in case you want to use a local copy of c-blosc2 for development, uncomment the line below
# SOURCE_DIR "/Users/faltet/blosc/c-blosc2"
)
FetchContent_MakeAvailable(blosc2)
include_directories("${blosc2_SOURCE_DIR}/include")
Expand Down
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ Conda users can install from conda-forge:
conda install -c conda-forge python-blosc2
Windows note
============

When building from source on Windows, clang-cl is required (OpenZL depends on C11 support).
Make sure LLVM is on PATH and use the Ninja generator, for example::

CMAKE_GENERATOR=Ninja
CC=clang-cl
CXX=clang-cl
pip install -e .

Documentation
=============

Expand Down
41 changes: 41 additions & 0 deletions README_DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ You are done!
pip install . # add -e for editable mode
```

On Windows, clang-cl is required (OpenZL depends on C11 support). Make sure LLVM
is on PATH and build with Ninja, for example:

```bash
CMAKE_GENERATOR=Ninja \
CC=clang-cl \
CXX=clang-cl \
pip install -e .
```

There are situations where you may want to build the C-Blosc2 library separately, for example, when debugging issues in the C library. In that case, let's assume you have the C-Blosc2 library installed in `/usr/local`:

```bash
Expand All @@ -38,6 +48,37 @@ LD_LIBRARY_PATH=/usr/local/lib pytest

That's it! You can now proceed to the testing section.

### Speeding up local builds (sccache + Ninja)

If you do frequent local rebuilds, sccache can significantly speed up C/C++ rebuilds.

```bash
brew install sccache ninja
```

Then run:

```bash
CMAKE_GENERATOR=Ninja \
CMAKE_C_COMPILER=clang \
CMAKE_CXX_COMPILER=clang++ \
CMAKE_C_COMPILER_LAUNCHER=sccache \
CMAKE_CXX_COMPILER_LAUNCHER=sccache \
CMAKE_BUILD_PARALLEL_LEVEL=8 \
SKBUILD_PARALLEL_LEVEL=8 \
SKBUILD_BUILD_DIR=build \
pip install -e .
```

Using `SKBUILD_BUILD_DIR` keeps a stable build directory between runs, which
improves incremental rebuilds and sccache hit rates.

Check cache stats with:

```bash
sccache --show-stats
```

## Testing

We are using pytest for testing. You can run the tests by executing
Expand Down
47 changes: 47 additions & 0 deletions bench/ndarray/miniexpr-eval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from time import time
import blosc2
import numpy as np
import numexpr as ne

N = 10_000
# dtype= np.int32
dtype= np.float32
# dtype= np.float64
cparams = blosc2.CParams(codec=blosc2.Codec.BLOSCLZ, clevel=1)

t0 = time()
# a = blosc2.ones((N, N), dtype=dtype, cparams=cparams)
# a = blosc2.arange(np.prod((N, N)), shape=(N, N), dtype=dtype, cparams=cparams)
a = blosc2.linspace(0., 1., np.prod((N, N)), shape=(N, N), dtype=dtype, cparams=cparams)
print(f"Time to create data: {(time() - t0) * 1000 :.4f} ms")
t0 = time()
b = a.copy()
c = a.copy()
print(f"Time to copy data: {(time() - t0) * 1000 :.4f} ms")

t0 = time()
res = (2 * a**2 - 3 * b + c + 1.2).compute(cparams=cparams)
t = time() - t0
print(f"Time to evaluate: {t * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(a.nbytes * 4 / 1e9) / t:.2f}")
# print(res.info)

na = a[:]
nb = b[:]
nc = c[:]

t0 = time()
nres = 2 * na**2 - 3 * nb + nc + 1.2
nt = time() - t0
print(f"Time to evaluate with NumPy: {nt * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(na.nbytes * 4 / 1e9) / nt:.2f}")
print(f"Speedup Blosc2 vs NumPy: {nt / t:.2f}x")
np.testing.assert_allclose(res, nres, rtol=1e-5)

t0 = time()
neres = ne.evaluate("2 * na**2 - 3 * nb + nc + 1.2")
net = time() - t0
print(f"Time to evaluate with NumExpr: {net * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(na.nbytes * 4 / 1e9) / net:.2f}")
print(f"Speedup Blosc2 vs NumExpr: {net / t:.2f}x")
np.testing.assert_allclose(res, neres, rtol=1e-5)
49 changes: 49 additions & 0 deletions bench/ndarray/miniexpr-reduct-sum-multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from time import time
import blosc2
import numpy as np
import numexpr as ne

N = 10_000
dtype= np.float32
cparams = blosc2.CParams(codec=blosc2.Codec.BLOSCLZ, clevel=1)

t0 = time()
#a = blosc2.ones((N, N), dtype=dtype, cparams=cparams)
#a = blosc2.arange(np.prod((N, N)), shape=(N, N), dtype=dtype, cparams=cparams)
a = blosc2.linspace(0., 1., np.prod((N, N)), shape=(N, N), dtype=dtype, cparams=cparams)
#rng = np.random.default_rng(1234)
#a = rng.integers(0, 2, size=(N, N), dtype=dtype)
#a = blosc2.asarray(a, cparams=cparams, urlpath="a.b2nd", mode="w")
print(f"Time to create data: {(time() - t0) * 1000 :.4f} ms")
t0 = time()
b = a.copy()
c = a.copy()
print(f"Time to copy data: {(time() - t0) * 1000 :.4f} ms")

t0 = time()
res = blosc2.sum(2 * a**2 - 3 * b + c + 1.2)
t = time() - t0
print(f"Time to evaluate: {t * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(a.nbytes * 3 / 1e9) / t:.2f}")
print("Result:", res, "Mean:", res / (N * N))

na = a[:]
nb = b[:]
nc = c[:]

t0 = time()
nres = np.sum(2 * na**2 - 3 * nb + nc + 1.2)
nt = time() - t0
print(f"Time to evaluate with NumPy: {nt * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(na.nbytes * 3 / 1e9) / nt:.2f}")
print("Result:", nres, "Mean:", nres / (N * N))
print(f"Speedup Blosc2 vs NumPy: {nt / t:.2f}x")
assert np.allclose(res, nres)

t0 = time()
neres = ne.evaluate("sum(2 * na**2 - 3 * nb + nc + 1.2)")
net = time() - t0
print(f"Time to evaluate with NumExpr: {net * 1000 :.4f} ms", end=" ")
print(f"Speed (GB/s): {(na.nbytes * 3 / 1e9) / net:.2f}")
print("Result:", neres, "Mean:", neres / (N * N))
print(f"Speedup Blosc2 vs NumExpr: {net / t:.2f}x")
Loading
Loading