@@ -739,3 +739,45 @@ def test_broadcast_right_multiplication_raises():
739739 tensor2 = ChargeArray .random (indices = indices )
740740 with pytest .raises (ValueError ):
741741 backend .broadcast_right_multiplication (tensor1 , tensor2 )
742+
743+
744+ @pytest .mark .parametrize ("dtype" , [np .float64 , np .complex128 ])
745+ @pytest .mark .parametrize ("num_charges" , [1 , 2 ])
746+ def test_broadcast_left_multiplication (dtype , num_charges ):
747+ np .random .seed (10 )
748+ backend = symmetric_backend .SymmetricBackend ()
749+ Ds = [10 , 30 , 24 ]
750+ R = len (Ds )
751+ indices = [
752+ Index (
753+ BaseCharge (
754+ np .random .randint (- 5 , 6 , (num_charges , Ds [n ])),
755+ charge_types = [U1Charge ] * num_charges ), False ) for n in range (R )
756+ ]
757+
758+ tensor1 = ChargeArray .random (indices = [indices [0 ]], dtype = dtype )
759+ tensor2 = backend .randn (indices , dtype = dtype )
760+ t1dense = tensor1 .todense ()
761+ t2dense = tensor2 .todense ()
762+ out = backend .broadcast_left_multiplication (tensor1 , tensor2 )
763+ dense = np .reshape (t1dense , (10 , 1 , 1 )) * t2dense
764+ np .testing .assert_allclose (out .todense (), dense )
765+
766+
767+ def test_broadcast_left_multiplication_raises ():
768+ np .random .seed (10 )
769+ backend = symmetric_backend .SymmetricBackend ()
770+ num_charges = 1
771+ Ds = [10 , 30 , 24 ]
772+ R = len (Ds )
773+ indices = [
774+ Index (
775+ BaseCharge (
776+ np .random .randint (- 5 , 6 , (num_charges , Ds [n ])),
777+ charge_types = [U1Charge ] * num_charges ), False ) for n in range (R )
778+ ]
779+
780+ tensor1 = ChargeArray .random (indices = indices )
781+ tensor2 = backend .randn (indices )
782+ with pytest .raises (ValueError ):
783+ backend .broadcast_left_multiplication (tensor1 , tensor2 )
0 commit comments