コード例 #1
0
 def __ilshift__(self, A): 
     """ A can be two things :
       * G <<= any_GF_Initializers will init the GFBloc with the initializer
       * G <<= g2 where g2 is a GFBloc will copy g2 into self
     """
     if isinstance(A, self.__class__) : 
         if self is not A : self.copyFrom(A) # otherwise it is useless AND does not work !!
     elif isinstance(A, lazy_expressions.lazy_expr) : # A is a lazy_expression made of GF, scalars, descriptors 
         A2= Descriptors.convert_scalar_to_Const(A)
         def e_t (x) : 
             if not isinstance(x, Descriptors.Base) : return x
             tmp = self.copy()
             x(tmp)
             return tmp
         #e_t2 = self.__lazy_expr_eval_context__()
         self.copyFrom ( lazy_expressions.eval_lazy_expr(e_t, A2) )
     elif isinstance(A, lazy_expressions.lazy_expr_terminal) : #e.g. g<<= SemiCircular (...) 
         self <<= lazy_expressions.lazy_expr(A)
     elif Descriptors.is_scalar(A) : #in the case it is a scalar .... 
         self <<= lazy_expressions.lazy_expr(A)
     elif isinstance(A, GF_Initializers.Base) : # backwards compatibility, deprecated
         A(self)
     else :
         raise RuntimeError, " GF Block : <<= operator : RHS not understood"
     return self
コード例 #2
0
    def __ilshift__(self, A):
        """ A can be two things :
          * G <<= any_GF_Initializers will init the GFBloc with the initializer
          * G <<= g2 where g2 is a GFBloc will copy g2 into self
        """
        if isinstance(A, self.__class__):
            if self is not A:
                self.copyFrom(
                    A)  # otherwise it is useless AND does not work !!
        elif isinstance(
                A, lazy_expressions.lazy_expr
        ):  # A is a lazy_expression made of GF, scalars, descriptors
            A2 = Descriptors.convert_scalar_to_Const(A)

            def e_t(x):
                if not isinstance(x, Descriptors.Base): return x
                tmp = self.copy()
                x(tmp)
                return tmp

            #e_t2 = self.__lazy_expr_eval_context__()
            self.copyFrom(lazy_expressions.eval_lazy_expr(e_t, A2))
        elif isinstance(A, lazy_expressions.lazy_expr_terminal
                        ):  #e.g. g<<= SemiCircular (...)
            self <<= lazy_expressions.lazy_expr(A)
        elif Descriptors.is_scalar(A):  #in the case it is a scalar ....
            self <<= lazy_expressions.lazy_expr(A)
        elif isinstance(
                A,
                GF_Initializers.Base):  # backwards compatibility, deprecated
            A(self)
        else:
            raise RuntimeError, " GF Block : <<= operator : RHS not understood"
        return self
コード例 #3
0
ファイル: Descriptors.py プロジェクト: boujnah-mourad/TRIQS
def convert_scalar_to_Const(expr) : 

  # if the expression is a pure scalar, replace it by Const
  t= expr.get_terminal()
  if is_scalar(t) : return lazy_expr( Const(t) )

  # otherwise : replace all scalar appearing in +/- operations by Const
  def act (tag, childs) : 
        if tag in ["+", "-"] :
            for n,c in enumerate(childs) : 
                t = c.get_terminal()
                if is_scalar(t) : childs[n] =  Const (t)
        return (tag,childs)

  return transform(expr, act)
コード例 #4
0
ファイル: Descriptors.py プロジェクト: xydeng/TRIQS
def convert_scalar_to_Const(expr):

    # if the expression is a pure scalar, replace it by Const
    t = expr.get_terminal()
    if is_scalar(t): return lazy_expr(Const(t))

    # otherwise : replace all scalar appearing in +/- operations by Const
    def act(tag, childs):
        if tag in ["+", "-"]:
            for n, c in enumerate(childs):
                t = c.get_terminal()
                if is_scalar(t): childs[n] = Const(t)
        return (tag, childs)

    return transform(expr, act)