You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from micrograd import engine
>>> v = engine.Value(3)
>>> v + 3
Value(data=6, grad=0)
>>> 3 + v
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ps/ugr/micrograd/micrograd/engine.py", line 76, in __radd__
return other + self
File "/home/ps/ugr/micrograd/micrograd/engine.py", line 76, in __radd__
return other + self
File "/home/ps/ugr/micrograd/micrograd/engine.py", line 76, in __radd__
return other + self
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
But modifying __rsub__ and __rtruediv__ can save extra unnecessary calls of __radd__ and __rmul__:
def __rsub__(self, other): # other - self
return (-self) + other
...
def __rtruediv__(self, other): # other / self
return self**-1 * other
In the micrograd engine.py line number 76, the code should be 'return other + self' not 'return self + other'
The text was updated successfully, but these errors were encountered: