Exemple #1
0
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 LazyExpr(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)
Exemple #2
0
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 LazyExpr( 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)