@@ -913,23 +913,35 @@ def test_mul(lop):
913
913
914
914
915
915
def test_matmul (lop ):
916
- import numpy
916
+ class MatmulClass :
917
+ def __init__ (self , value ):
918
+ self .value = value
917
919
918
- one = numpy .array ((1 , 2 , 3 ))
919
- two = numpy .array ((2 , 3 , 4 ))
920
- assert one @ two == 20
920
+ def __matmul__ (self , other ):
921
+ return self .value * other .value
921
922
922
- one = lop .Proxy (lambda : numpy .array ((1 , 2 , 3 )))
923
- two = lop .Proxy (lambda : numpy .array ((2 , 3 , 4 )))
924
- assert one @ two == 20
923
+ def __rmatmul__ (self , other ):
924
+ return other + self .value
925
925
926
- one = lop . Proxy ( lambda : numpy . array (( 1 , 2 , 3 )) )
927
- two = numpy . array (( 2 , 3 , 4 ) )
928
- assert one @ two == 20
926
+ one = MatmulClass ( 123 )
927
+ two = MatmulClass ( 234 )
928
+ assert one @ two == 28782
929
929
930
- one = numpy .array ((1 , 2 , 3 ))
931
- two = lop .Proxy (lambda : numpy .array ((2 , 3 , 4 )))
932
- assert one @ two == 20
930
+ one = lop .Proxy (lambda : MatmulClass (123 ))
931
+ two = lop .Proxy (lambda : MatmulClass (234 ))
932
+ assert one @ two == 28782
933
+
934
+ one = lop .Proxy (lambda : MatmulClass (123 ))
935
+ two = MatmulClass (234 )
936
+ assert one @ two == 28782
937
+
938
+ one = 123
939
+ two = lop .Proxy (lambda : MatmulClass (234 ))
940
+ assert one @ two == 357
941
+
942
+ one = lop .Proxy (lambda : 123 )
943
+ two = lop .Proxy (lambda : MatmulClass (234 ))
944
+ assert one @ two == 357
933
945
934
946
935
947
def test_div (lop ):
0 commit comments