pyccel.commands.lambdify module

Contents

pyccel.commands.lambdify module#

File describing commands associated with the lambdify function which converts a SymPy expression into a Pyccel-accelerated function.

pyccel.commands.lambdify.lambdify(expr: Expr, args: dict[Symbol, str], *, result_type: str | None = None, use_out=False, **kwargs)[source]#

Convert a SymPy expression into a Pyccel-accelerated function.

Convert a SymPy expression into a function that allows for fast numeric evaluation. This is done using SymPy’s NumPyPrinter to generate code that can be accelerated by Pyccel.

Parameters:
  • expr (sp.Expr) – The SymPy expression that should be returned from the function.

  • args (dict[sp.Symbol, str]) – A dictionary of the arguments of the function being created. The keys are variables representing the arguments that will be passed to the function. The values are the the type annotations for those functions. To use more complex objects (e.g. TypeVars) please use the epyccel keyword argument context_dicts.

  • result_type (str, optional) – The type annotation for the result of the function. This argument is optional but it is recommended to provide it as SymPy expressions do not always evaluate to the expected type. For example if the SymPy expression simplifies to 0 then the default type will be int even if the arguments are floats.

  • use_out (bool, default=False) – If true the function will modify an argument called ‘out’ instead of returning a newly allocated array. If this argument is set then result_type must be provided. This only works if the result is an array type.

  • **kwargs (dict) – Additional arguments that are passed to epyccel.

Returns:

A Pyccel-accelerated function which allows the evaluation of the SymPy expression.

Return type:

func

See also

sympy.lambdify

<https://docs.sympy.org/latest/modules/utilities/lambdify.html>.

epyccel

The function that accelerates the generated code.