@@ -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)
15231557def test_missing_operator ():
15241558 a = blosc2 .arange (10 , urlpath = "a.b2nd" , mode = "w" )
0 commit comments