Пример #1
0
 def __rsub__(self, other):
     """Subtract a self from a scalar or vector"""
     if is_scalar(other):
         return self.__neg__().increment(other)
     elif isinstance(other, list):
         return DVec(other).axpy(-1, self)
     else:
         raise Exception('Invalid argument')
Пример #2
0
 def __isub__(self, other):
     if is_scalar(other):
         libamino.aa_dmat_inc(self, -other)
         return self
     if isinstance(other, DMat):
         libamino.aa_dmat_axpy(-1, other, self)
         return self
     else:
         raise TypeError('Cannot increment matrix with %s' % type(other))
Пример #3
0
 def __sub__(self, other):
     """Subtract a scalar or vector from self"""
     if isinstance(other, DVec):
         return DVec(self).axpy(-1, other)
     elif isinstance(other, list):
         return self.__sub__(DVec(other))
     elif is_scalar(other):
         return DVec(self).increment(-other)
     else:
         raise Exception('Invalid argument')
Пример #4
0
 def __iadd__(self, other):
     """Add a scalar or vector to self"""
     if isinstance(other, DVec):
         return self.axpy(1, other)
     elif isinstance(other, list):
         return self.axpy(1, DVec(other))
     elif is_scalar(other):
         return self.increment(other)
     else:
         raise Exception('Invalid argument')
Пример #5
0
 def __mul__(self, other):
     if is_scalar(other):
         return DMat(self).__imul__(other)
     elif isinstance(other, DVec):
         y = DVec(self._rows)
         y.gemv(CBLAS_NO_TRANS, 1, self, other, 0)
         return y
     elif isinstance(other, list):
         return self * DVec(other)
     elif isinstance(other, DMat):
         A, B = self, other
         C = DMat((A._rows, B._cols))
         return C.gemm(CBLAS_NO_TRANS, CBLAS_NO_TRANS, 1, A, B, 1)
     else:
         raise TypeError('Cannot multiply matrix with %s' % type(other))
Пример #6
0
 def __rsub__(self, other):
     if is_scalar(other):
         return self.__neg__().__iadd__(other)
     else:
         raise TypeError('Cannot subtract matrix with %s' % type(other))
Пример #7
0
 def __sub__(self, other):
     if is_scalar(other) or isinstance(other, DMat):
         return DMat(self).__isub__(other)
     else:
         raise TypeError('Cannot subtract matrix with %s' % type(other))
Пример #8
0
 def __radd__(self, other):
     if is_scalar(other):
         return DMat(self).__iadd__(other)
     else:
         raise TypeError('Cannot add matrix add %s' % type(other))
Пример #9
0
 def __rmul__(self, other):
     if is_scalar(other):
         return DMat(self).__imul__(other)
     else:
         raise TypeError('Cannot multiply matrix with %s' % type(other))
Пример #10
0
 def __imul__(self, other):
     if is_scalar(other):
         libamino.aa_dmat_scal(self, other)
         return self
     else:
         raise TypeError('Cannot cale matrix with %s' % type(other))