pyccel package

Subpackages

Submodules

pyccel.decorators module

pyccel.decorators.lambdify(f)[source]
pyccel.decorators.python(f)[source]
pyccel.decorators.sympy(f)[source]
pyccel.decorators.types(*args, **kw)[source]

pyccel.epyccel module

class pyccel.epyccel.ContextPyccel(name, context_folder='', output_folder='')[source]

Bases: object

Class for interactive use of Pyccel. It can be used within an IPython session, Jupyter Notebook or ipyccel command line.

compile(**settings)[source]

Convert to Fortran and compile the context.

constants
folder
functions
imports

Returns available imports from the context as a string.

insert_constant(d, value=None)[source]

Inserts constants in the namespace.

d: str, dict
an identifier string or a dictionary of the form {‘a’: value_a, ‘b’: value_b} where a and b are the constants identifiers and value_a, value_b their associated values.
value: int, float, complex, str
value used if d is a string
insert_function(func, types, kind='function', results=None)[source]

Inserts a function in the namespace.

name
os_folder
pyccel.epyccel.clean_extension_module(ext_mod, py_mod_name)[source]

Clean Python extension module by moving functions contained in f2py’s “mod_[py_mod_name]” automatic attribute to one level up (module level). “mod_[py_mod_name]” attribute is then completely removed from the module.

ext_mod : types.ModuleType
Python extension module created by f2py from pyccel-generated Fortran.
py_mod_name : str
Name of the original (pure Python) module.
pyccel.epyccel.compile_fortran(source, modulename, extra_args='', libs=[], compiler=None, mpi=False, includes=[])[source]

use f2py to compile a source code. We ensure here that the f2py used is the right one with respect to the python/numpy version, which is not the case if we run directly the command line f2py …

pyccel.epyccel.epyccel(func, inputs=None, verbose=False, modules=[], libs=[], name=None, context=None, compiler=None, mpi=False, static=None)[source]

Pyccelize a python function and wrap it using f2py.

func: function, str
a Python function or source code defining the function
inputs: str, list, tuple, dict
inputs can be the function header as a string, or a list/tuple of strings or the globals() dictionary
verbose: bool
talk more
modules: list, tuple
list of dependencies
libs: list, tuple
list of libraries
name: str
name of the function, if it is given as a string
context: ContextPyccel, list/tuple
a Pyccel context for user defined functions and other dependencies needed to compile func. it also be a list/tuple of ContextPyccel
static: list/tuple
a list of ‘static’ functions as strings

Examples

The following example shows how to use Pyccel within an IPython session

>>> #$ header procedure static f_static(int [:]) results(int)
>>> def f_static(x):
>>>     y = x[0] - 1
>>>     return y
>>> from test_epyccel import epyccel
>>> f = epyccel(f_static, globals()) # appending IPython history
>>> header = '#$ header procedure static f_static(int [:]) results(int)'
>>> f = epyccel(f_static, header) # giving the header explicitly

Now, f is a Fortran function that has been wrapped. It is compatible with numpy and you can call it

>>> import numpy as np
>>> x = np.array([3, 4, 5, 6], dtype=int)
>>> y = f(x)

You can also call it with a list instead of numpy arrays

>>> f([3, 4, 5])
2
pyccel.epyccel.epyccel_mpi(mod, comm, root=0)[source]

Collective version of epyccel for modules: root process generates Fortran code, compiles it and creates a shared library (extension module), which is then loaded by all processes in the communicator.

mod : types.ModuleType
Python module to be pyccelized.
comm: mpi4py.MPI.Comm
MPI communicator where extension module will be made available.
root: int
Rank of process responsible for code generation.
fmod : types.ModuleType
Python extension module.
pyccel.epyccel.get_source_function(func)[source]

Module contents