Skip to content

Commit 4922281

Browse files
committed
Fix more bugs
1 parent 82e46ff commit 4922281

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/interpreter/mat_operators.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ print A;
55
A = A .* A;
66
print A;
77
A = A .- B;
8-
print A;
9-
A = A ./ B;
8+
print A;

utils/types.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,26 @@ def __add__(self, other):
6262
if self.value is not None and other.value is not None:
6363
return Int(self.value + other.value)
6464
return Int()
65+
if isinstance(other, Float):
66+
return Float()
6567
raise TypeError()
6668

6769
def __sub__(self, other):
6870
if isinstance(other, Int):
6971
if self.value is not None and other.value is not None:
7072
return Int(self.value - other.value)
7173
return Int()
74+
if isinstance(other, Float):
75+
return Float()
7276
raise TypeError()
7377

7478
def __mul__(self, other):
7579
if isinstance(other, Int):
7680
if self.value is not None and other.value is not None:
7781
return Int(self.value * other.value)
7882
return Int()
83+
if isinstance(other, Float):
84+
return Float()
7985
raise TypeError()
8086

8187
def __truediv__(self, other):
@@ -84,7 +90,9 @@ def __truediv__(self, other):
8490
raise TypeError()
8591

8692
def __neg__(self):
87-
return Int(-self.value)
93+
if self.value is not None:
94+
return Int(-self.value)
95+
return Int()
8896

8997

9098
class Float(Type):
@@ -176,11 +184,11 @@ def __ge__(self, other):
176184
def _mat_op(self, other, op):
177185
new_dims = []
178186
for self_dim, other_dim in zip(self.dims, other.dims):
179-
new_dim = self_dim or other_dim
187+
new_dim = self_dim or other_dim # handle None
180188
if new_dim != self_dim or new_dim != other_dim:
181189
raise TypeError
182190
new_dims.append(new_dim)
183-
return Vector(new_dims, op(self.primitive_type, other.primitive_type))
191+
return Vector(tuple(new_dims), op(self.primitive_type, other.primitive_type))
184192

185193
def mat_add(self, other):
186194
return self._mat_op(other, lambda x, y: x + y)

0 commit comments

Comments
 (0)