fixed with one return x
MODIFY
test/test_tensor.py
test/test_tensor.py
@@ -11,6 +11,14 @@ W_init = np.random.randn(3,3).astype(np.float32)
m_init = np.random.randn(1,3).astype(np.float32)
class TestTinygrad(unittest.TestCase):
+ def test_plus_equals(self):
+ a = Tensor.randn(10,10)
+ b = Tensor.randn(10,10)
+ c = a + b
+ val1 = c.numpy()
+ a += b
+ val2 = a.numpy()
+ np.testing.assert_allclose(val1, val2)
def test_backward_pass(self):
def test_tinygrad():

MODIFY
tinygrad/tensor.py
tinygrad/tensor.py
@@ -103,6 +103,7 @@ class Tensor:
x = Tensor(x)
assert self.shape == x.shape
self.data = x.data
+ return x
@property
def shape(self):
@@ -246,8 +247,7 @@ class Tensor:
k += y.shape[i]
ret = self.slice(arg=s[0])
for ts,y in zip(s[1:], args[1:]):
- # TODO: investigate why += doesn't work here
- ret = ret + y.slice(arg=ts)
+ ret += y.slice(arg=ts)
return ret
def pad2d(self, padding):

fixed with one return x