Skip to content

Commit 53d4b9d

Browse files
committed
Fix bug in samples/matrix
1 parent 190385c commit 53d4b9d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

utbot-python/samples/samples/matrix.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class 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

4345
if __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)

0 commit comments

Comments
 (0)