Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add radd, rsub and rmul #31

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tinynumpy/tinynumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

from math import sqrt
from copy import copy, deepcopy
from collections.abc import Iterable
from collections import Iterable
import operator

import tinynumpy.tinylinalg as linalg
Expand Down Expand Up @@ -764,10 +764,6 @@ def __eq__(self, other):
out[:] = [i1==i2 for (i1, i2) in zip(self.flat, other.flat)]
return out


###########################################################################
# Added some more basic functions to support in place and normal
# mathematical operations like additions, substractions ...
def __add__(self, other):
'''classic addition
'''
Expand All @@ -781,6 +777,9 @@ def __add__(self, other):
out[:] = [i+j for (i,j) in zip(self.flat, other.flat)]
return out

def __radd__(self, other):
return self.__add__(other)

def __sub__(self, other):
if (isinstance(other, int) or isinstance(other, float)) :
out = empty(self.shape, self.dtype)
Expand All @@ -792,6 +791,9 @@ def __sub__(self, other):
out[:] = [i-j for (i,j) in zip(self.flat, other.flat)]
return out

def __rsub__(self, other):
return self.__sub__(other)

def __mul__(self, other):
'''multiply element-wise with array or float/scalar'''
if (isinstance(other, int) or isinstance(other, float)) :
Expand All @@ -804,6 +806,9 @@ def __mul__(self, other):
out[:] = [i*j for (i,j) in zip(self.flat, other.flat)]
return out

def __rmul__(self, other):
return self.__mul__(other)

def __div__(self, other):
'''divide element-wise with array or float/scalar'''
if (isinstance(other, int) or isinstance(other, float)) :
Expand Down