How to use the pyccel.ast.basic.Basic 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 / pyccel / ast / core.py View on Github external
return self.base.dtype

    @property
    def precision(self):
        return self.base.precision

    @property
    def order(self):
        return self.base.order

    def _eval_subs(self, old, new):
        return self



class String(Basic):

    """Represents the String"""

    def __new__(cls, arg):
        if not isinstance(arg, str):
            raise TypeError('arg must be of type str')
        return Basic.__new__(cls, arg)

    @property
    def arg(self):
        return self._args[0]

    def __str__(self):
        return self.arg
github pyccel / pyccel / pyccel / functional / datatypes.py View on Github external
#!/usr/bin/python
# -*- coding: utf-8 -*-

from sympy import Tuple, IndexedBase

from pyccel.ast.basic import Basic
from pyccel.ast.core  import Variable, For, Range, Assign, Len
from pyccel.codegen.utilities import random_string


#=========================================================================
class BasicTypeVariable(Basic):
    _tag  = None

    @property
    def tag(self):
        return self._tag

#=========================================================================
class TypeVariable(BasicTypeVariable):
    def __new__( cls, var, rank=0 ):
        assert(isinstance(var, (Variable, TypeVariable)))

        dtype          = var.dtype
        rank           = var.rank + rank
        is_stack_array = var.is_stack_array
        order          = var.order
        precision      = var.precision
github pyccel / pyccel / pyccel / ast / core.py View on Github external
args.append(fi)
                if len(args) == 1:
                    arg = args[0]
                    m = Lambda(arg, m(arg, evaluate=False))
                else:
                    m = Lambda(args, m(*args, evaluate=False))

            ls.append(m)

        return ls


# TODO: Should Declare have an optional init value for each var?


class Declare(Basic):
    """Represents a variable declaration in the code.

    dtype : DataType
        The type for the declaration.
    variable(s)
        A single variable or an iterable of Variables. If iterable, all
        Variables must be of the same type.
    intent: None, str
        one among {'in', 'out', 'inout'}
    value: Expr
        variable value
    static: bool
        True for a static declaration of an array.

    Examples
github pyccel / pyccel / pyccel / ast / core.py View on Github external
def __new__(cls, lhs, rhs):
        return Basic.__new__(cls, lhs, rhs)

    def _sympystr(self, printer):
        sstr = printer.doprint
        return '{0} := {1}'.format(sstr(self.lhs), sstr(self.rhs))

    @property
    def lhs(self):
        return self._args[0]

    @property
    def rhs(self):
        return self._args[1]

class SymbolicAssign(Basic):
    """Represents symbolic aliasing for code generation. An alias is any statement of the
    form `lhs := rhs` where

    lhs : Symbol

    rhs : Range

    Examples

    >>> from sympy import Symbol
    >>> from pyccel.ast.core import SymbolicAssign
    >>> from pyccel.ast.core import Range
    >>> r = Range(0, 3)
    >>> y = Symbol('y')
    >>> SymbolicAssign(y, r)
github pyccel / pyccel / pyccel / ast / core.py View on Github external
    @property
    def imports(self):
        return self._args[6]

    @property
    def modules(self):
        return self._args[7]

    @property
    def declarations(self):
        return [Declare(i.dtype, i) for i in self.variables]



class For(Basic):
    """Represents a 'for-loop' in the code.

    Expressions are of the form:
        "for target in iter:
            body..."

    target : symbol
        symbol representing the iterator
    iter : iterable
        iterable object. for the moment only Range is used
    body : sympy expr
        list of statements representing the body of the For statement.

    Examples

    >>> from sympy import symbols, MatrixSymbol
github pyccel / pyccel / pyccel / functional / semantic.py View on Github external
def __len__(self):
        return len(self.arguments)

class Product(Basic):
    def __new__( cls, *args ):
        return Basic.__new__(cls, args)

    @property
    def arguments(self):
        return self._args[0]

    def __len__(self):
        return len(self.arguments)

#=========================================================================
class Reduce(Basic):
    """."""

    def __new__( cls, func, target ):

        return Basic.__new__(cls, func, target)

    @property
    def func(self):
        return self._args[0]

    @property
    def target(self):
        return self._args[1]

#=========================================================================
def sanitize(expr):
github pyccel / pyccel / pyccel / ast / core.py View on Github external
    @property
    def bodies(self):
        b = []
        for i in self._args:
            b.append( i[1])
        return b


class IfTernaryOperator(If):

    """class for the Ternery operator"""

    pass

class StarredArguments(Basic):
    def __new__(cls, args):
        return Basic.__new__(cls, args)

    @property
    def args_var(self):
        return self._args[0]


def is_simple_assign(expr):
    if not isinstance(expr, Assign):
        return False

    assignable = [Variable, IndexedVariable, IndexedElement]
    assignable += [sp_Integer, sp_Float]
    assignable = tuple(assignable)
    if isinstance(expr.rhs, assignable):
github pyccel / pyccel / pyccel / ast / core.py View on Github external
def __new__(cls, *args):
        for a in args:
            if not isinstance(a, Import):
                raise TypeError('Expecting an Import statement')
        return Basic.__new__(cls, *args)

    @property
    def imports(self):
        return self._args

    def _sympystr(self, printer):
        sstr = printer.doprint
        return '\n'.join(sstr(n) for n in self.imports)


class Load(Basic):

    """Similar to 'importlib' in python. In addition, we can also provide the
    functions we want to import.

    Parameters
    ----------
    module: str, DottedName
        name of the module to load.

    funcs: str, list, tuple, Tuple
        a string representing the function to load, or a list of strings.

    as_lambda: bool
        load as a Lambda expression, if True

    nargs: int
github pyccel / pyccel / pyccel / ast / core.py View on Github external
return Basic.__new__(cls, body, iterator, stmts)

    @property
    def body(self):
        return self._args[0]

    @property
    def iterator(self):
        return self._args[1]

    @property
    def stmts(self):
        return self._args[2]


class SymbolicPrint(Basic):

    """Represents a print function of symbolic expressions in the code.

    Parameters
    ----------
    expr : sympy expr
        The expression to return.

    Examples
    --------
    >>> from sympy import symbols
    >>> from pyccel.ast.core import Print
    >>> n,m = symbols('n,m')
    >>> Print(('results', n,m))
    Print((results, n, m))
    """
github pyccel / pyccel / pyccel / ast / core.py View on Github external
    @property
    def is_list(self):
        return self._args[1]

    def _sympystr(self, printer):
        sstr = printer.doprint

        args = '+'.join(sstr(arg) for arg in self.args)

        return args




class Slice(Basic):

    """Represents a slice in the code.

    Parameters
    ----------
    start : Symbol or int
        starting index

    end : Symbol or int
        ending index

    Examples
    --------
    >>> from sympy import symbols
    >>> from pyccel.ast.core import Slice
    >>> m, n = symbols('m, n', integer=True)