File tree Expand file tree Collapse file tree
utbot-python/samples/samples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55class Matrix :
66 def __init__ (self , elements : list [list [float ]]):
77 self .elements = elements
8- self .dim = (len (elements [ 0 ] ), len (elements ))
8+ self .dim = (len (elements ), len (elements [ 0 ] ))
99
1010 def __repr__ (self ):
1111 return str (self .elements )
@@ -29,7 +29,9 @@ def __mul__(self, other):
2929 ]
3030 for i in range (self .dim [1 ])
3131 ])
32- elif isinstance (other , Matrix ):
32+
33+ def __matmul__ (self , other ):
34+ if isinstance (other , Matrix ):
3335 if self .dim [1 ] == other .dim [0 ]:
3436 result = [[0 for _ in range (self .dim [0 ])] * other .dim [1 ]]
3537 for i , j in product (range (self .dim [0 ]), range (other .dim [1 ])):
@@ -42,5 +44,5 @@ def __mul__(self, other):
4244
4345if __name__ == '__main__' :
4446 a = Matrix ([[1 , 2 ]])
45- b = Matrix ([[3 , 4 ]])
46- print (a + b )
47+ b = Matrix ([[3 ], [ 4 ]])
48+ print (a @ b )
You can’t perform that action at this time.
0 commit comments