@@ -1629,62 +1629,102 @@ def test_lazylinalg():
1629
1629
npx = x [()]
1630
1630
npy = y [()]
1631
1631
npA = A [()]
1632
+ npB = B [()]
1633
+ npC = C [()]
1634
+ npD = D [()]
1632
1635
1633
1636
# --- concat ---
1634
1637
out = blosc2 .lazyexpr ("concat((x, y), axis=0)" )
1635
- assert out .shape == np .concat ((npx , npy ), axis = 0 ).shape
1638
+ npres = np .concatenate ((npx , npy ), axis = 0 )
1639
+ assert out .shape == npres .shape
1640
+ np .testing .assert_array_almost_equal (out [()], npres )
1636
1641
1637
1642
# --- diagonal ---
1638
1643
out = blosc2 .lazyexpr ("diagonal(A)" )
1639
- assert out .shape == np .diagonal (npA ).shape
1644
+ npres = np .diagonal (npA )
1645
+ assert out .shape == npres .shape
1646
+ np .testing .assert_array_almost_equal (out [()], npres )
1640
1647
1641
1648
# --- expand_dims ---
1642
1649
out = blosc2 .lazyexpr ("expand_dims(x, axis=0)" )
1643
- assert out .shape == (1 ,) + shapes ["x" ]
1650
+ npres = np .expand_dims (npx , axis = 0 )
1651
+ assert out .shape == npres .shape
1652
+ np .testing .assert_array_almost_equal (out [()], npres )
1644
1653
1645
1654
# --- matmul ---
1646
1655
out = blosc2 .lazyexpr ("matmul(A, B)" )
1647
- assert out .shape == (shapes ["A" ][0 ], shapes ["B" ][1 ])
1656
+ npres = np .matmul (npA , npB )
1657
+ assert out .shape == npres .shape
1658
+ np .testing .assert_array_almost_equal (out [()], npres )
1648
1659
1649
1660
# --- matrix_transpose ---
1650
1661
out = blosc2 .lazyexpr ("matrix_transpose(A)" )
1651
- assert out .shape == (shapes ["A" ][1 ], shapes ["A" ][0 ])
1662
+ npres = np .matrix_transpose (npA )
1663
+ assert out .shape == npres .shape
1664
+ np .testing .assert_array_almost_equal (out [()], npres )
1665
+ out = blosc2 .lazyexpr ("C.mT" )
1666
+ npres = C .mT
1667
+ assert out .shape == npres .shape
1668
+ np .testing .assert_array_almost_equal (out [()], npres )
1669
+ out = blosc2 .lazyexpr ("A.T" )
1670
+ npres = npA .T
1671
+ assert out .shape == npres .shape
1672
+ np .testing .assert_array_almost_equal (out [()], npres )
1652
1673
1653
1674
# --- outer ---
1654
1675
out = blosc2 .lazyexpr ("outer(x, y)" )
1655
- assert out .shape == shapes ["x" ] + shapes ["y" ]
1676
+ npres = np .outer (npx , npy )
1677
+ assert out .shape == npres .shape
1678
+ np .testing .assert_array_almost_equal (out [()], npres )
1656
1679
1657
1680
# --- permute_dims ---
1658
1681
out = blosc2 .lazyexpr ("permute_dims(C, axes=(2,0,1))" )
1659
- assert out .shape == (shapes ["C" ][2 ], shapes ["C" ][0 ], shapes ["C" ][1 ])
1682
+ npres = np .transpose (npC , axes = (2 , 0 , 1 ))
1683
+ assert out .shape == npres .shape
1684
+ np .testing .assert_array_almost_equal (out [()], npres )
1660
1685
1661
1686
# --- squeeze ---
1662
1687
out = blosc2 .lazyexpr ("squeeze(D)" )
1663
- assert out .shape == (5 ,)
1688
+ npres = np .squeeze (npD )
1689
+ assert out .shape == npres .shape
1690
+ np .testing .assert_array_almost_equal (out [()], npres )
1691
+
1664
1692
out = blosc2 .lazyexpr ("D.squeeze()" )
1665
- assert out .shape == (5 ,)
1693
+ npres = np .squeeze (npD )
1694
+ assert out .shape == npres .shape
1695
+ np .testing .assert_array_almost_equal (out [()], npres )
1666
1696
1667
1697
# --- stack ---
1668
1698
out = blosc2 .lazyexpr ("stack((x, y), axis=0)" )
1669
- assert out .shape == (2 ,) + shapes ["x" ]
1699
+ npres = np .stack ((npx , npy ), axis = 0 )
1700
+ assert out .shape == npres .shape
1701
+ np .testing .assert_array_almost_equal (out [()], npres )
1670
1702
1671
1703
# --- tensordot ---
1672
1704
out = blosc2 .lazyexpr ("tensordot(A, B, axes=1)" )
1673
- assert out .shape [0 ] == shapes ["A" ][0 ]
1674
- assert out .shape [- 1 ] == shapes ["B" ][- 1 ]
1705
+ npres = np .tensordot (npA , npB , axes = 1 )
1706
+ assert out .shape == npres .shape
1707
+ np .testing .assert_array_almost_equal (out [()], npres )
1675
1708
1676
1709
# --- vecdot ---
1677
1710
out = blosc2 .lazyexpr ("vecdot(x, y)" )
1678
- assert out .shape == np .vecdot (x [()], y [()]).shape
1711
+ npres = np .vecdot (npx , npy )
1712
+ assert out .shape == npres .shape
1713
+ np .testing .assert_array_almost_equal (out [()], npres )
1679
1714
1680
- # batched matmul
1715
+ # --- batched matmul ---
1681
1716
shapes = {
1682
1717
"A" : (1 , 3 , 4 ),
1683
1718
"B" : (3 , 4 , 5 ),
1684
1719
}
1685
1720
s = shapes ["A" ]
1686
1721
A = blosc2 .linspace (0 , np .prod (s ), shape = s )
1722
+ npA = A [()] # actual numpy array
1687
1723
s = shapes ["B" ]
1688
1724
B = blosc2 .linspace (0 , np .prod (s ), shape = s )
1725
+ npB = B [()] # actual numpy array
1726
+
1689
1727
out = blosc2 .lazyexpr ("matmul(A, B)" )
1690
- assert out .shape == (3 , 3 , 5 )
1728
+ npres = np .matmul (npA , npB )
1729
+ assert out .shape == npres .shape
1730
+ np .testing .assert_array_almost_equal (out [()], npres )
0 commit comments