How to use the pyccel.ast.core.IndexedVariable function in pyccel

To help you get started, we’ve selected a few pyccel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyccel / pyccel / src_old / syntax_core.py View on Github external
if d_var['shape']:
                if DEBUG:
                    print(("> Found an unallocated variable: ", var_name))
                status = 'unallocated'
                like = allocatable_like(rhs)
            insert_variable(var_name, **d_var)

        if self.trailer is None:
            l = namespace[self.lhs]
        else:
            if isinstance(trailer, TrailerSubscriptList):
                v = namespace[str(self.lhs)]
                if not hasattr(args, '__iter__'):
                    args = [args]

                l = IndexedVariable(v.name, dtype=v.dtype).__getitem__(*args)
            elif isinstance(trailer, TrailerDots):
                # class attribut
                l = namespace[var_name]
            else:
                raise TypeError("Expecting SubscriptList or Dot")

        return AugAssign(l, op, rhs, strict=False, status=status, like=like)
github pyccel / pyccel / pyccel / parser / semantic.py View on Github external
dtype = var.dtype
            shape = var.shape
            prec  = var.precision
            order = var.order
            rank  = var.rank

            if isinstance(var, PythonTuple):
                if not var.is_homogeneous:
                    errors.report(LIST_OF_TUPLES, symbol=var,
                        bounding_box=(self._current_fst_node.lineno, self._current_fst_node.col_offset),
                        severity='error', blocker=self.blocking)
                    dtype = 'int'
                else:
                    dtype = var.dtype

            return IndexedVariable(var, dtype=dtype,
                   shape=shape,prec=prec,order=order,rank=rank).__getitem__(*args)
        else:
            return IndexedVariable(name, dtype=dtype).__getitem__(args)
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
expr = expr.expand()
#    expr = expr.subs({Function('Grad'): Grad})
#    expr = expr.subs({Function('Dot'): Dot})

    d, d_args = _decompose(expr)

    d_expr = {}
    for k,expr in d.items():
        args = list(coords)

        found_vector = False
        for u in d_args[k]:
            if _is_vector(expr, u):
                found_vector = True
                for i in range(0, dim):
                    uofi = IndexedVariable(str(u))[i]
                    ui = Symbol('{0}{1}'.format(u, i+1))
                    expr = expr.subs(uofi, ui)
                    args += [ui]
            else:
                args += [u]

        d_expr[k] = Lambda(args, expr)
        if found_vector:
            d_expr[k], _infos = initialize_weak_form(d_expr[k], dim)

    if len(d_expr) == 1:
        key = d_expr.keys()[0]
        d_expr = d_expr[key]

    info = {}
    info['coords'] = coords
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
def test_3d_4b():
    """Alfven operator."""
    x,y,z = symbols('x y z')

    u = IndexedVariable('u')
    v = IndexedVariable('v')

    b = IndexedVariable('b')

    c0,c1,c2 = symbols('c0 c1 c2')

    a = Lambda((x,y,z,v,u), (  c0 * Dot(u, v)
                             - c1 * Div(u) * Div(v)
                             + c2 *Dot(Curl(Cross(b,u)), Curl(Cross(b,v)))))
    print '> input       := {0}'.format(a)

    expr = gelatize(a, dim=3)
    print '> gelatized   := {0}'.format(expr)

    # TODO: fix, not working
#    expr, info = initialize_weak_form(expr, dim=3)
#    print '> temp form   :='
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
def test_3d_2():
    x,y,z = symbols('x y z')

    u = IndexedVariable('u')
    v = IndexedVariable('v')


    a = Lambda((x,y,z,v,u), Div(u) * Div(v) + 0.2 * Dot(u, v))
    print '> input       := {0}'.format(a)

    expr = gelatize(a, dim=3)
    print '> gelatized   := {0}'.format(expr)

    expr, info = initialize_weak_form(expr, dim=3)
    print '> temp form   :='
    # for a nice printing, we print the dictionary entries one by one
    for key, value in expr.items():
        print '\t\t', key, '\t', value

    expr = normalize_weak_from(expr)
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
def test_3d_2():
    x,y,z = symbols('x y z')

    u = IndexedVariable('u')
    v = IndexedVariable('v')


    a = Lambda((x,y,z,v,u), Div(u) * Div(v) + 0.2 * Dot(u, v))
    print '> input       := {0}'.format(a)

    expr = gelatize(a, dim=3)
    print '> gelatized   := {0}'.format(expr)

    expr, info = initialize_weak_form(expr, dim=3)
    print '> temp form   :='
    # for a nice printing, we print the dictionary entries one by one
    for key, value in expr.items():
        print '\t\t', key, '\t', value

    expr = normalize_weak_from(expr)
    print '> normal form := {0}'.format(expr)
github pyccel / pyccel / pyccel / symbolic / gelato.py View on Github external
args = subs(expr.args, old, new)
        return Function(str(expr.func))(*args)

    if isinstance(expr, Add):
        args = subs(expr._args, old, new)
        return Add(*args)

    if isinstance(expr, Mul):
        args = subs(expr._args, old, new)
        return Mul(*args)

    if isinstance(expr, IndexedElement):
        if str(expr) == str(old):
            if isinstance(new, str):
                indices = expr.indices
                return IndexedVariable(new)[indices]
            else:
                return new

    if isinstance(expr, Variable):
        if str(expr) == str(old):
            return Variable(str(new))

    if isinstance(expr, Symbol):
        if str(expr) == str(old):
            return Symbol(str(new))

    return expr
# ...
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
def test_3d_4a():
    x,y,z = symbols('x y z')

    u = IndexedVariable('u')
    v = IndexedVariable('v')

    b = Tuple(1.0, 0., 0.)

    a = Lambda((x,y,z,v,u), Dot(Curl(Cross(b,u)), Curl(Cross(b,v))) + 0.2 * Dot(u, v))
    print '> input       := {0}'.format(a)

    expr = gelatize(a, dim=3)
    print '> gelatized   := {0}'.format(expr)

    expr, info = initialize_weak_form(expr, dim=3)
    print '> temp form   :='
    # for a nice printing, we print the dictionary entries one by one
    for key, value in expr.items():
        print '\t\t', key, '\t', value
github pyccel / pyccel / pyccel / symbolic / calculus.py View on Github external
def test_2d_2():
    x,y = symbols('x y')

    u = IndexedVariable('u')
    v = IndexedVariable('v')

    a = Lambda((x,y,v,u), Rot(u) * Rot(v) + Div(u) * Div(v) + 0.2 * Dot(u, v))
    print '> input       := {0}'.format(a)

    expr = gelatize(a, dim=2)
    print '> gelatized   := {0}'.format(expr)

    expr, info = initialize_weak_form(expr, dim=2)
    print '> temp form   :='
    # for a nice printing, we print the dictionary entries one by one
    for key, value in expr.items():
        print '\t\t', key, '\t', value

    expr = normalize_weak_from(expr)
    print '> normal form := {0}'.format(expr)