@@ -1543,15 +1543,15 @@ def test_sign():
15431543 tensor = get_tensor (R = 4 , num_charges = 1 , dtype = np .float64 )
15441544 backend = symmetric_backend .SymmetricBackend ()
15451545 res = backend .sign (tensor )
1546- np .testing .assert_allclose (res .data , np .sign (tensor .data ))
1546+ np .testing .assert_allclose (res .data , np .sign (tensor .data ))
15471547
15481548def test_abs ():
15491549 tensor = get_tensor (R = 4 , num_charges = 1 , dtype = np .float64 )
15501550 backend = symmetric_backend .SymmetricBackend ()
15511551 res = backend .abs (tensor )
1552- np .testing .assert_allclose (res .data , np .abs (tensor .data ))
1552+ np .testing .assert_allclose (res .data , np .abs (tensor .data ))
1553+
15531554
1554-
15551555@pytest .mark .parametrize ('dtype' , [np .float64 , np .complex128 ])
15561556@pytest .mark .parametrize ('x0' , [True , False ])
15571557@pytest .mark .parametrize ('ncv' , [None , 40 ])
@@ -1644,3 +1644,64 @@ def test_gmres_raises():
16441644 backend .gmres (lambda x : x , b , x0 = mps , tol = - 0.001 )
16451645 with pytest .raises (ValueError , match = "atol = " ):
16461646 backend .gmres (lambda x : x , b , x0 = mps , atol = - 0.001 )
1647+
1648+
1649+
1650+ @pytest .mark .parametrize ("dtype" , np_tensordot_dtypes )
1651+ @pytest .mark .parametrize ("num_charges" , [1 , 2 ])
1652+ def test_matmul (dtype , num_charges ):
1653+ np .random .seed (10 )
1654+ backend = symmetric_backend .SymmetricBackend ()
1655+ D = 100
1656+ c1 = BaseCharge (
1657+ np .random .randint (- 5 , 6 , (D , num_charges )),
1658+ charge_types = [U1Charge ] * num_charges )
1659+ c2 = BaseCharge (
1660+ np .random .randint (- 5 , 6 , (D , num_charges )),
1661+ charge_types = [U1Charge ] * num_charges )
1662+ c3 = BaseCharge (
1663+ np .random .randint (- 5 , 6 , (D , num_charges )),
1664+ charge_types = [U1Charge ] * num_charges )
1665+ charges1 = [c1 , c2 ]
1666+ charges2 = [c2 , c3 ]
1667+ flows1 = [False , True ]
1668+ flows2 = [False , True ]
1669+ inds1 = [Index (charges1 [n ], flows1 [n ]) for n in range (2 )]
1670+ inds2 = [Index (charges2 [n ], flows2 [n ]) for n in range (2 )]
1671+ A = BlockSparseTensor .random (indices = inds1 , dtype = dtype )
1672+ B = BlockSparseTensor .random (indices = inds2 , dtype = dtype )
1673+
1674+ actual = backend .matmul (A , B )
1675+ expected = A @ B
1676+ np .testing .assert_allclose (expected .data , actual .data )
1677+ assert np .all ([
1678+ charge_equal (expected ._charges [n ], actual ._charges [n ])
1679+ for n in range (len (actual ._charges ))
1680+ ])
1681+
1682+
1683+ def test_matmul_raises ():
1684+ dtype = np .float64
1685+ num_charges = 1
1686+ np .random .seed (10 )
1687+ backend = symmetric_backend .SymmetricBackend ()
1688+ D = 100
1689+ c1 = BaseCharge (
1690+ np .random .randint (- 5 , 6 , (D , num_charges )),
1691+ charge_types = [U1Charge ] * num_charges )
1692+ c2 = BaseCharge (
1693+ np .random .randint (- 5 , 6 , (D , num_charges )),
1694+ charge_types = [U1Charge ] * num_charges )
1695+ c3 = BaseCharge (
1696+ np .random .randint (- 5 , 6 , (D , num_charges )),
1697+ charge_types = [U1Charge ] * num_charges )
1698+ charges1 = [c1 , c2 , c3 ]
1699+ charges2 = [c2 , c3 ]
1700+ flows1 = [False , True , False ]
1701+ flows2 = [False , True ]
1702+ inds1 = [Index (charges1 [n ], flows1 [n ]) for n in range (3 )]
1703+ inds2 = [Index (charges2 [n ], flows2 [n ]) for n in range (2 )]
1704+ A = BlockSparseTensor .random (indices = inds1 , dtype = dtype )
1705+ B = BlockSparseTensor .random (indices = inds2 , dtype = dtype )
1706+ with pytest .raises (ValueError , match = "inputs to" ):
1707+ _ = backend .matmul (A , B )
0 commit comments