Hands-on: creating a simple Cython extension

Simple Cython extension

The code for this exercise is located under cython/simple-extension

~/hpc-python$ cd cython/simple-extension

Create a simple Cython module (you can name it e.g. cyt_module.pyx) containing the following function:

def subtract(x, y):
    return x - y

Create then a setup.py file for building the extension module. Try to utilize the module e.g. as

from cyt_module import subtract

subtract(4.5, 2)

in interactive interpreter or in a simple script. Try different argument types.

Share this article:

This article is from the free online course:

Python in High Performance Computing

Partnership for Advanced Computing in Europe (PRACE)