pyccel.ast.functionalexpr module#

class pyccel.ast.functionalexpr.FunctionalFor(loops, expr=None, lhs=None, indices=None, index=None, *, target_type=None, operations=None, conditions)[source]#

Bases: TypedAstNode

Represents a generator expression.

Represents any generator expression e.g: a = [i for i in range(10)]

Parameters:
  • loops (CodeBlock/For) – The loops contained in the expression.

  • expr (PyccelAstNode) – The expression at the origin of the expression E.g. ‘i’ for ‘[i for i in range(10)]’.

  • lhs (Variable) – The variable to which the result is assigned.

  • indices (list of Variable) – All iterator targets for the for loops.

  • index (Variable) –

    Index of result in rhs E.g.: >>> a = [i in range(1,10,2)]

    is translated to: >>> Dummy_0 = 0 >>> for i in range(1,10,2): >>> a[Dummy_0]=i >>> Dummy_0 += 1

    Index is Dummy_0.

  • target_type (PyccelSymbol, optional) – The type of the result of the functional for. This is useful at the syntactic stage to pass along the final type of the lhs (list/set/array/etc).

  • operations (dict) – A dictionary mapping each type of comprehension (e.g. list, array, etc.) to the operation used for populating it.

  • conditions (list[If|None]) – A list of filter conditions corresponding to each for-loop in the comprehension. Each element of this list is either an If instance that describes the filtering condition for that loop, or None if no condition is applied in that loop.

property conditions#

A list of filter conditions for each loop in the comprehension.

If not None, each element of this list is either an If instance that describes the filtering condition for that loop, or None if no condition is applied. These conditions collectively determine whether each item produced by the loops is included in the final result.

Returns:

The list of filter conditions for each for-loop in the comprehension, or None if not specified.

Return type:

list[If|None], or None

property expr#
property index#
property indices#
property lhs#
property loops#
property operations#

A dictionary mapping each type of comprehension to the operation used for populating it.

For example, for list comprehensions we might use {'list': 'append'}, and for NumPy arrays, (which require a fixed size at compile time), we might use {'numpy_array': [Assign_node]}. This mapping allows the code generator to select the appropriate operation when building the final data structure from the comprehension.

Returns:

A dictionary that maps comprehension types (e.g. ‘list’, ‘numpy_array’) to the corresponding operation (append call, assign, etc.).

Return type:

dict

property target_type#

The type of the result of the functional for.

The type of the result of the functional for. This is useful at the syntactic stage to pass along the final type of the lhs (list/set/array/etc).

class pyccel.ast.functionalexpr.FunctionalMax(loops, expr=None, lhs=None, indices=None, index=None, *, target_type=None, operations=None, conditions)[source]#

Bases: GeneratorComprehension

Represents a call to max for a list argument >>> max([i in range(5)])

name = 'max'#
class pyccel.ast.functionalexpr.FunctionalMin(loops, expr=None, lhs=None, indices=None, index=None, *, target_type=None, operations=None, conditions)[source]#

Bases: GeneratorComprehension

Represents a call to min for a list argument >>> min([i in range(5)])

name = 'min'#
class pyccel.ast.functionalexpr.FunctionalSum(loops, expr=None, lhs=None, indices=None, index=None, *, target_type=None, operations=None, conditions)[source]#

Bases: GeneratorComprehension

Represents a call to sum for a list argument >>> sum([i in range(5)])

name = 'sum'#
class pyccel.ast.functionalexpr.GeneratorComprehension(loops, expr=None, lhs=None, indices=None, index=None, *, target_type=None, operations=None, conditions)[source]#

Bases: FunctionalFor

Super class for all functions which reduce generator expressions to scalars

class pyccel.ast.functionalexpr.MaxLimit(class_type)[source]#

Bases: TypedAstNode

A class representing the largest usable value for a given type.

A class representing the largest usable value for a given type. This is particularly useful with FunctionalMin.

Parameters:

class_type (FixedSizeNumericType) – The type whose maximum limit is represented by an instance of this class.

class pyccel.ast.functionalexpr.MinLimit(class_type)[source]#

Bases: TypedAstNode

A class representing the smallest usable value for a given type.

A class representing the smallest usable value for a given type. This is particularly useful with FunctionalMax.

Parameters:

class_type (FixedSizeNumericType) – The type whose minimum limit is represented by an instance of this class.