Skip to content

Commit 538ced3

Browse files
committed
Add a test for '-1 + a. Fixes #579.
1 parent 9fb52c1 commit 538ced3

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ endif()
6464

6565
FetchContent_Declare(miniexpr
6666
GIT_REPOSITORY https://github.com/Blosc/miniexpr.git
67-
GIT_TAG 4bf12c8d5eac4c2022db8567d7b3cee44a963c9c
67+
GIT_TAG 1bd8d0cfe92b63ad463cd28783e824b5e64afea8
6868
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../miniexpr
6969
)
7070
FetchContent_MakeAvailable(miniexpr)

tests/ndarray/test_lazyexpr.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,40 @@ def wrapped_set_pref_expr(self, expression, inputs, fp_accuracy, aux_reduc=None,
15191519
lazyexpr_mod.try_miniexpr = old_try_miniexpr
15201520

15211521

1522+
@pytest.mark.skipif(blosc2.IS_WASM, reason="miniexpr fast path is not available on WASM")
1523+
def test_lazyexpr_unary_negative_literal_matches_subtraction(monkeypatch):
1524+
import importlib
1525+
1526+
lazyexpr_mod = importlib.import_module("blosc2.lazyexpr")
1527+
old_try_miniexpr = lazyexpr_mod.try_miniexpr
1528+
lazyexpr_mod.try_miniexpr = True
1529+
1530+
original_set_pref_expr = blosc2.NDArray._set_pref_expr
1531+
captured = {"calls": 0, "exprs": []}
1532+
1533+
def wrapped_set_pref_expr(self, expression, inputs, fp_accuracy, aux_reduc=None, jit=None):
1534+
captured["calls"] += 1
1535+
expr = expression.decode("utf-8") if isinstance(expression, bytes) else expression
1536+
captured["exprs"].append(expr)
1537+
return original_set_pref_expr(self, expression, inputs, fp_accuracy, aux_reduc, jit=jit)
1538+
1539+
monkeypatch.setattr(blosc2.NDArray, "_set_pref_expr", wrapped_set_pref_expr)
1540+
1541+
try:
1542+
na = np.arange(32 * 32, dtype=np.int64).reshape(32, 32)
1543+
a = blosc2.asarray(na, chunks=(16, 16), blocks=(8, 8))
1544+
1545+
left = blosc2.lazyexpr("-1 + a", operands={"a": a}).compute()
1546+
right = blosc2.lazyexpr("a - 1", operands={"a": a}).compute()
1547+
1548+
np.testing.assert_equal(left[...], right[...])
1549+
np.testing.assert_equal(left[...], na - 1)
1550+
assert captured["calls"] >= 1
1551+
assert any("-1" in expr for expr in captured["exprs"])
1552+
finally:
1553+
lazyexpr_mod.try_miniexpr = old_try_miniexpr
1554+
1555+
15221556
# Test the LazyExpr when some operands are missing (e.g. removed file)
15231557
def test_missing_operator():
15241558
a = blosc2.arange(10, urlpath="a.b2nd", mode="w")

0 commit comments

Comments
 (0)