def __mul__(self, other): if isinstance(other, Array): result = self._new_like_me(_get_common_dtype(self, other)) self._elwise_multiply(result, self, other) return result else: result = self._new_like_me() self._axpbz(result, other, self, 0) return result
def __pow__(self, other): """Exponentiation by a scalar or elementwise by another :class:`Array`. """ if isinstance(other, Array): assert self.shape == other.shape result = self._new_like_me(_get_common_dtype(self, other)) self._pow_array(result, self, other) else: result = self._new_like_me() self._pow_scalar(result, self, other) return result
def __sub__(self, other): """Substract an array from an array or a scalar from an array.""" if isinstance(other, Array): result = self._new_like_me(_get_common_dtype(self, other)) self._axpbyz(result, 1, self, -1, other) return result else: # subtract a scalar if other == 0: return self else: result = self._new_like_me() self._axpbz(result, 1, self, -other) return result
def __add__(self, other): """Add an array with an array or an array with a scalar.""" if isinstance(other, Array): # add another vector result = self._new_like_me(_get_common_dtype(self, other)) self._axpbyz(result, 1, self, 1, other) return result else: # add a scalar if other == 0: return self else: result = self._new_like_me() self._axpbz(result, 1, self, other) return result
def __div__(self, other): """Divides an array by an array or a scalar:: x = self / n """ if isinstance(other, Array): result = self._new_like_me(_get_common_dtype(self, other)) self._div(result, self, other) else: if other == 1: return self else: # create a new array for the result result = self._new_like_me() self._axpbz(result, 1/other, self, 0) return result
def __rdiv__(self,other): """Divides an array by a scalar or an array:: x = n / self """ if isinstance(other, Array): result = self._new_like_me(_get_common_dtype(self, other)) other._div(result, self) else: if other == 1: return self else: # create a new array for the result result = self._new_like_me() self._rdiv_scalar(result, self, other) return result
def mul_add(self, selffac, other, otherfac, queue=None): """Return `selffac * self + otherfac*other`. """ result = self._new_like_me(_get_common_dtype(self, other)) self._axpbyz(result, selffac, self, otherfac, other) return result