Skip to content

Commit 0d8e583

Browse files
author
Luke Shaw
committed
Working on fixing chaining
1 parent 7045763 commit 0d8e583

2 files changed

Lines changed: 43 additions & 45 deletions

File tree

src/blosc2/lazyexpr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,10 +2678,10 @@ def _new_expr(cls, expression, operands, guess, out=None, where=None, ne_args=No
26782678
_dtype = new_expr.dtype
26792679
_shape = new_expr.shape
26802680
if isinstance(new_expr, blosc2.LazyExpr):
2681-
# Restore the original expression and operands
2682-
new_expr.expression = f"({_expression})" # forcibly add parenthesis
2681+
# DO NOT restore the original expression and operands
2682+
# new_expr.expression = new_expr.expression} #don't have to do anything
26832683
new_expr.expression_tosave = _expression
2684-
new_expr.operands = _operands
2684+
# new_expr.operands = new_expr.operands #don't have to do anything
26852685
new_expr.operands_tosave = operands
26862686
else:
26872687
# An immediate evaluation happened (e.g. all operands are numpy arrays)

tests/ndarray/test_lazyexpr.py

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,45 +1354,43 @@ def test_chain_expressions():
13541354
le3_ = blosc2.lazyexpr("(le2 & (b < 0))", {"le2": le2_, "b": b})
13551355
assert (le3_[:] == le3[:]).all()
13561356

1357-
# TODO: This test should pass eventually
1358-
# le1 = a ** 3 + blosc2.sin(a ** 2)
1359-
# le2 = le1 < c
1360-
# le3 = (b < 0)
1361-
# le4 = le2 & le3
1362-
# le1_ = blosc2.lazyexpr("a ** 3 + sin(a ** 2)", {"a": a})
1363-
# le2_ = blosc2.lazyexpr("(le1 < c)", {"le1": le1_, "c": c})
1364-
# le3_ = blosc2.lazyexpr("(b < 0)", {"b": b})
1365-
# le4_ = blosc2.lazyexpr("(le2 & le3)", {"le2": le2_, "le3": le3_})
1366-
# assert (le4_[:] == le4[:]).all()
1367-
1368-
1369-
# TODO: Test the chaining of multiple persistent lazy expressions
1370-
# def test_chain_persistentexpressions():
1371-
# N = 1_000
1372-
# dtype = "float64"
1373-
# a = blosc2.linspace(0, 1, N * N, dtype=dtype, shape=(N, N), urlpath="a.b2nd", mode="w")
1374-
# b = blosc2.linspace(1, 2, N * N, dtype=dtype, shape=(N, N), urlpath="b.b2nd", mode="w")
1375-
# c = blosc2.linspace(0, 1, N, dtype=dtype, shape=(N,), urlpath="c.b2nd", mode="w")
1376-
#
1377-
# le1 = a ** 3 + blosc2.sin(a ** 2)
1378-
# le2 = le1 < c
1379-
# le3 = (b < 0)
1380-
# le4 = le2 & le3
1381-
#
1382-
# le1_ = blosc2.lazyexpr("a ** 3 + sin(a ** 2)", {"a": a})
1383-
# le1_.save("expr1.b2nd", mode="w")
1384-
# myle1 = blosc2.open("expr1.b2nd")
1385-
#
1386-
# le2_ = blosc2.lazyexpr("(le1 < c)", {"le1": myle1, "c": c})
1387-
# le2_.save("expr2.b2nd", mode="w")
1388-
# myle2 = blosc2.open("expr2.b2nd")
1389-
#
1390-
# le3_ = blosc2.lazyexpr("(b < 0)", {"b": b})
1391-
# le3_.save("expr3.b2nd", mode="w")
1392-
# myle3 = blosc2.open("expr3.b2nd")
1393-
#
1394-
# le4_ = blosc2.lazyexpr("(le2 & le3)", {"le2": myle2, "le3": myle3})
1395-
# le4_.save("expr4.b2nd", mode="w")
1396-
# myle4 = blosc2.open("expr4.b2nd")
1397-
# print((myle4[:] == le4[:]).all())
1398-
#
1357+
le1 = a**3 + blosc2.sin(a**2)
1358+
le2 = le1 < c
1359+
le3 = b < 0
1360+
le4 = le2 & le3
1361+
le1_ = blosc2.lazyexpr("a ** 3 + sin(a ** 2)", {"a": a})
1362+
le2_ = blosc2.lazyexpr("(le1 < c)", {"le1": le1_, "c": c})
1363+
le3_ = blosc2.lazyexpr("(b < 0)", {"b": b})
1364+
le4_ = blosc2.lazyexpr("(le2 & le3)", {"le2": le2_, "le3": le3_})
1365+
assert (le4_[:] == le4[:]).all()
1366+
1367+
1368+
# Test the chaining of multiple persistent lazy expressions
1369+
def test_chain_persistentexpressions():
1370+
N = 1_000
1371+
dtype = "float64"
1372+
a = blosc2.linspace(0, 1, N * N, dtype=dtype, shape=(N, N), urlpath="a.b2nd", mode="w")
1373+
b = blosc2.linspace(1, 2, N * N, dtype=dtype, shape=(N, N), urlpath="b.b2nd", mode="w")
1374+
c = blosc2.linspace(0, 1, N, dtype=dtype, shape=(N,), urlpath="c.b2nd", mode="w")
1375+
1376+
le1 = a**3 + blosc2.sin(a**2)
1377+
le2 = le1 < c
1378+
le3 = b < 0
1379+
le4 = le2 & le3
1380+
1381+
le1_ = blosc2.lazyexpr("a ** 3 + sin(a ** 2)", {"a": a})
1382+
le1_.save("expr1.b2nd", mode="w")
1383+
myle1 = blosc2.open("expr1.b2nd")
1384+
1385+
le2_ = blosc2.lazyexpr("(le1 < c)", {"le1": myle1, "c": c})
1386+
le2_.save("expr2.b2nd", mode="w")
1387+
myle2 = blosc2.open("expr2.b2nd")
1388+
1389+
le3_ = blosc2.lazyexpr("(b < 0)", {"b": b})
1390+
le3_.save("expr3.b2nd", mode="w")
1391+
myle3 = blosc2.open("expr3.b2nd")
1392+
1393+
le4_ = blosc2.lazyexpr("(le2 & le3)", {"le2": myle2, "le3": myle3})
1394+
le4_.save("expr4.b2nd", mode="w")
1395+
myle4 = blosc2.open("expr4.b2nd")
1396+
assert (myle4[:] == le4[:]).all()

0 commit comments

Comments
 (0)