How to use the pyccel.ast.basic.Basic.__new__ 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
def __new__(cls, expr):
        # TODO: check that the variable is allocatable
        if not iterable(expr):
            expr = Tuple(expr)
        return Basic.__new__(cls, expr)
github pyccel / pyccel / pyccel / ast / builtins.py View on Github external
def __new__(cls, *args):
        if not isinstance(args, (tuple, list, Tuple)):
            raise TypeError('args must be an iterable')
        elif len(args) < 2:
            raise ValueError('args must be of length > 2')
        return Basic.__new__(cls, *args)
github pyccel / pyccel / pyccel / ast / core.py View on Github external
if lhs_is_mat:
                if not rhs_is_mat:
                    raise ValueError('Cannot assign a scalar to a matrix.'
                            )
                elif lhs.shape != rhs.shape:
                    raise ValueError("Dimensions of lhs and rhs don't align."
                            )
            elif rhs_is_mat and not lhs_is_mat:
                raise ValueError('Cannot assign a matrix to a scalar.')

        if isinstance(op, str):
            op = operator(op)
        elif op not in list(op_registry.values()):
            raise TypeError('Unrecognized Operator')

        return Basic.__new__(
            cls,
            lhs,
            op,
            rhs,
            status,
            like,
            )
github pyccel / pyccel / pyccel / functional / ast.py View on Github external
for i in length:
                    n *= i

            else:
                n = length

            var = Dummy()
            stmts += [Assign(var, n)]

        else:
            msg = 'not available for {}'.format(type(generator))
            raise NotImplementedError(msg)

        stmts = Tuple(*stmts)

        return Basic.__new__(cls, var, stmts)
github pyccel / pyccel / pyccel / functional / ast.py View on Github external
variables = []
            # ...

            # ...
            body = [OMP_Parallel( clauses, variables, body )]
            # ...

            # TODO this is a hack to handle the last comment after a loop, so that
            #      it can be parsed and added to the For
            body += [Pass()]
        # ...

        decs = Tuple(*decs)
        body = Tuple(*body)

        return Basic.__new__( cls, decs, body )
github pyccel / pyccel / pyccel / ast / core.py View on Github external
def __new__(cls, expr):

        # TODO: check that the variable is allocatable

        if not iterable(expr):
            expr = Tuple(expr, sympify=False)
        return Basic.__new__(cls, expr)
github pyccel / pyccel / pyccel / ast / core.py View on Github external
def __new__(cls, arg, func):

        if not isinstance(arg, (ValuedArgument, ValuedVariable)):
            raise TypeError('Expecting a ValuedArgument or ValuedVariable'
                            )

        if not isinstance(func, FunctionDef):
            raise TypeError('Expecting a FunctionDef')

        return Basic.__new__(cls, arg, func)
github pyccel / pyccel / pyccel / functional / ast.py View on Github external
if private_vars:
                clauses += [OMP_Private(*private_vars)]
            # ...

            # ...
            assert(len(body) == 1)
            loop = body[0]
            body = [OMP_For(loop, Tuple(*clauses), nowait)]
            # ...
        # ...

        decs = Tuple(*decs)
        body = Tuple(*body)

        return Basic.__new__( cls, generator, decs, body, private_vars )
github pyccel / pyccel / pyccel / ast / core.py View on Github external
lhs_is_mat = hasattr(lhs, 'shape') and not isinstance(lhs,
                    Indexed)
            rhs_is_mat = hasattr(rhs, 'shape') and not isinstance(rhs,
                    Indexed)

            # If lhs and rhs have same structure, then this assignment is ok

            if lhs_is_mat:
                if not rhs_is_mat:
                    raise ValueError('Cannot assign a scalar to a matrix.')
                elif lhs.shape != rhs.shape:
                    raise ValueError("Dimensions of lhs and rhs don't align.")
            elif rhs_is_mat and not lhs_is_mat:
                raise ValueError('Cannot assign a matrix to a scalar.')
        return Basic.__new__(cls, lhs, rhs, status, like)
github pyccel / pyccel / pyccel / ast / core.py View on Github external
return i
            else:
                raise TypeError('Expecting a string, Symbol DottedName, given {}'.format(type(i)))

        _target = []
        if isinstance(target, (str, Symbol, DottedName, AsName)):
            _target = [_format(target)]
        elif iterable(target):
            for i in target:
                _target.append(_format(i))
        target = Tuple(*_target, sympify=False)

        if not source is None:
            source = _format(source)

        return Basic.__new__(cls, target, source)