Ejemplo n.º 1
0
    def __mul__(self, arg):

        if descriptors.is_lazy(arg):
          return lazy_expressions.make_lazy(self) * arg
        else:
          res = self.copy()
          res *= arg
          return res
Ejemplo n.º 2
0
 def __idiv__(self, arg):
     """ If arg is a scalar, simple scalar multiplication
     """
     if descriptors.is_lazy(arg): return lazy_expressions.make_lazy(self) / arg
     if descriptors.is_scalar(arg):
         self.data /= arg
         self.tail /= arg
     else:
         raise RuntimeError, " argument type not recognized in imul for %s"%arg
     return self
Ejemplo n.º 3
0
 def __imul__(self, arg):
     if descriptor_base.is_lazy(arg):
         return lazy_expressions.make_lazy(self) * arg
     # If arg is a Gf
     if isinstance(arg, Gf):
         assert type(self.mesh) == type(
             arg.mesh
         ), "Can not multiply two Gf with meshes of different type"
         assert self.mesh == arg.mesh, "Can not use in-place multiplication for two Gf with different mesh"
         self.__imul__impl(arg)
     elif isinstance(arg, numbers.Number):
         self._data[:] *= arg
     else:
         assert False, "Invalid operand type for Gf in-place multiplication"
     return self
Ejemplo n.º 4
0
 def __iadd__(self, arg):
     if descriptor_base.is_lazy(arg):
         return lazy_expressions.make_lazy(self) + arg
     if isinstance(arg, Gf):
         assert type(self.mesh) == type(
             arg.mesh), "Can not add two Gf with meshes of different type"
         assert self.mesh == arg.mesh, "Can not add two Gf with different mesh"
         self._data += arg._data
     else:
         if self._target_rank != 2 and not isinstance(arg, np.ndarray):
             self._data[:] += arg
         elif self._target_rank == 2:
             wrapped_aux._iadd_g_matrix_scalar(self, arg)
         else:
             raise NotImplemented
     return self
Ejemplo n.º 5
0
 def __imul__(self, arg):
     if descriptor_base.is_lazy(arg):
         return lazy_expressions.make_lazy(self) * arg
     # If arg is a Gf
     if isinstance(arg, Gf):
         assert type(self.mesh) == type(
             arg.mesh
         ), "Can not multiply two Gf with meshes of different type"
         assert self.mesh == arg.mesh, "Can not use in-place multiplication for two Gf with different mesh"
         self.__imul__impl(arg)
     elif isinstance(arg, numbers.Number):
         self._data[:] *= arg
     elif isinstance(arg, np.ndarray):
         assert len(
             arg.shape) == 2, "Multiplication only supported for matrices"
         assert len(
             self.target_shape
         ) == 2, "Multiplication only supported for matrix_valued Gfs"
         self.data[:] = np.dot(self.data, arg)
     else:
         assert False, "Invalid operand type for Gf in-place multiplication"
     return self
Ejemplo n.º 6
0
 def __idiv__(self, arg):
     if descriptor_base.is_lazy(arg):
         return lazy_expressions.make_lazy(self) / arg
     self._data[:] /= arg
     return self
def div_precall(self, y):
    if descriptor_base.is_lazy(y): return lazy_expressions.make_lazy(self) / y
Ejemplo n.º 8
0
    def __rmul__(self, arg):

        if descriptors.is_lazy(arg):
          return arg * lazy_expressions.make_lazy(self)
        elif descriptors.is_scalar(arg):
          return self.__mul__(arg)
Ejemplo n.º 9
0
 def __sub__(self, y):
     if descriptors.is_lazy(y): return lazy_expressions.make_lazy(self) - y
     c = self.copy()
     return self.__sub_isub_impl(c,y,True)