Git Product home page Git Product logo

cython-lib-template's Introduction

cython-lib-template

A small template that wrap C code into python using cython, and integrate the extensions into an installable module. Developed around python 3.x.

A cython pyx file is included that implements a few C functions which can accept and return standard python data types and numpy ndarrays. These are compiled, wrapped, and integrated into the module using a standard setup.py script.

In addition to concrete examples of cython syntax, this repo also illustrates a working project structure with a working setup.py configuration (using setuptools) for Python projects with C extension modules, along with basic unit tests (together with a working Travis-CI config).

Build the lib

First, install cython (using pip or from a package manager) if you don't already have them. pip install cython

Then just run python setup.py develop to build the project in-place.

The module (with its wrapped C functions c_hello) will then be importable in python:

>>> from cython_lib import c_hello, factorial

Wrapped example functions

2 examples functions are defined in wrapped.pyx:

  • A direct wrapping of a simple C "hello world" function, implemented in cfunc.c
  • A C function to compute the factorial of a python integer, built using Cython syntax.

Benchmarks

For a quick benchmark of the two ndarray functions listed, run python3 test_lib.py.

$ python3 test_lib.py
[+] cython finished : 0.0001804828643798828 s
[+] python finished : 2.987328052520752 s

cython-lib-template's People

Contributors

sanix-darker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.