@@ -1354,45 +1354,52 @@ 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+ # TODO: Eventually this test should pass
1368+ # expr1 = blosc2.lazyexpr("arange(N) + b")
1369+ # expr2 = blosc2.lazyexpr("a * b + 1")
1370+ # expr = blosc2.lazyexpr("expr1 - expr2")
1371+ # expr_final = blosc2.lazyexpr("expr * expr")
1372+ # nres = (expr * expr)[:]
1373+ # res = expr_final.compute()
1374+ # np.testing.assert_allclose(res[:], nres)
1375+
1376+
1377+ # Test the chaining of multiple persistent lazy expressions
1378+ def test_chain_persistentexpressions ():
1379+ N = 1_000
1380+ dtype = "float64"
1381+ a = blosc2 .linspace (0 , 1 , N * N , dtype = dtype , shape = (N , N ), urlpath = "a.b2nd" , mode = "w" )
1382+ b = blosc2 .linspace (1 , 2 , N * N , dtype = dtype , shape = (N , N ), urlpath = "b.b2nd" , mode = "w" )
1383+ c = blosc2 .linspace (0 , 1 , N , dtype = dtype , shape = (N ,), urlpath = "c.b2nd" , mode = "w" )
1384+
1385+ le1 = a ** 3 + blosc2 .sin (a ** 2 )
1386+ le2 = le1 < c
1387+ le3 = b < 0
1388+ le4 = le2 & le3
1389+
1390+ le1_ = blosc2 .lazyexpr ("a ** 3 + sin(a ** 2)" , {"a" : a })
1391+ le1_ .save ("expr1.b2nd" , mode = "w" )
1392+ myle1 = blosc2 .open ("expr1.b2nd" )
1393+
1394+ le2_ = blosc2 .lazyexpr ("(le1 < c)" , {"le1" : myle1 , "c" : c })
1395+ le2_ .save ("expr2.b2nd" , mode = "w" )
1396+ myle2 = blosc2 .open ("expr2.b2nd" )
1397+
1398+ le3_ = blosc2 .lazyexpr ("(b < 0)" , {"b" : b })
1399+ le3_ .save ("expr3.b2nd" , mode = "w" )
1400+ myle3 = blosc2 .open ("expr3.b2nd" )
1401+
1402+ le4_ = blosc2 .lazyexpr ("(le2 & le3)" , {"le2" : myle2 , "le3" : myle3 })
1403+ le4_ .save ("expr4.b2nd" , mode = "w" )
1404+ myle4 = blosc2 .open ("expr4.b2nd" )
1405+ assert (myle4 [:] == le4 [:]).all ()
0 commit comments