Questions tagged [cython]

Cython is a superset of the Python language for quickly generating Python C extensions.

Cython is a superset of the Python language for quickly generating Python C/C++ extensions. Cython is a pidgin language of Python and C/C++. Unlike pure Python, Cython code is not directly interpreted by the Python interpreter, but is instead used to generate C/C++ code. The generated C/C++ code can then be compiled into a C/C++-extension, which then can be imported by Python code.

Cython syntax was originally based on Python 2, with added type declarations à la C/C++, however, its syntax now supports both Python 2 and 3 language features. Additionally, Cython is capable of generating C/C++ extension code compatible with either Python 2 or Python 3. Its syntax now allows the use of advanced C++ constructs such as template and stl container. Finally, thanks to static typing, Cython code generally executes much faster than Python code.

Cython is freely available under the open source Apache License.

The latest release of Cython is 3.0 alpha 5 (released 2020-05-19). Cython is available from the PyPI package index repository.

5220 questions
3
votes
1 answer

Passing a cython function vs a cython method to scipy.integrate

I am trying work out how to use cython to speed up a calculation involving integration that is done within a class I have defined. I'm trying to understand better how cython works with user-defined python classes. I'd like to understand more about…
alexabate
  • 143
  • 2
  • 10
3
votes
1 answer

Cython: Initialize Structured Numpy Array ValueError

I want to use Cython to speed up my Python code in analogy to the Cython's Numpy tutorial. I give you a MWE of what I intended: Test Function: import pyximport pyximport.install() import CythonModule2 as cm2 print cm2.read_data() Cython Module…
strpeter
  • 2,562
  • 3
  • 27
  • 48
3
votes
1 answer

how to build whole python project with cython

I have a PySide project with many modules, files and folders. I also used Numpy, Matplotlib and many other modules. I want to build this project with cython. The code is pure python, and i want cython to add all dependencies together, just like when…
Elteroooo
  • 2,913
  • 3
  • 33
  • 40
3
votes
2 answers

Issue with Kivy and Buildozer

I am currently using python 2.7.9. I've tried reinstalling cython and updating all the dependencies but it didn't work. I don't know what the problem is with Buildozer or Cython. The app is running properly directly from terminal. #error Do not use…
3
votes
1 answer

Fast indexing: Cython with numpy array of bool and str

I am trying to speed up a Python script. I have profiled the code and re-factored quite a lot already in pure Python. It seems that I am still spending a lot of time in accessing some numpy arrays in a way that looks…
VincentH
  • 1,009
  • 4
  • 13
  • 24
3
votes
1 answer

Regenerate cython extension with distutils

I have a cython file that generates a different .c file depending on whether it's been compiled for python 2 or python 3. That is: from .mp_utils import PY3 if PY3: builtin = (int, float, str, complex) else: builtin = (int, float, str,…
JaviMerino
  • 619
  • 10
  • 18
3
votes
1 answer

Shared memory with Cython multiprocessing

I am trying to define an Array in shared memory with Cython and the multiprocessing package. However, I am not able to declare this array in the .pxd file. The simple test code is as follows. I have a Cython class Data with the variable my_data.…
Rijk
  • 45
  • 3
3
votes
1 answer

Docker: How to run cython_extensions?

FROM ubuntu:14.04.2 RUN rm /bin/sh && ln -s /bin/bash /bin/sh RUN apt-get -y update && apt-get upgrade -y RUN apt-get install python build-essential python-dev python-pip python-setuptools -y RUN apt-get install libxml2-dev libxslt1-dev python-dev…
Houman
  • 64,245
  • 87
  • 278
  • 460
3
votes
2 answers

Speed up mathematical calculations in Python

I am currently trying to optimise a program. The major bottlenecks are actually fairly simple one-line calculations operating on numpy arrays, eg: (p-1) * c**(p-1)/(v_dt+c)**p (p & c here are floats and v_dt a ~500 long numpy array of float) This…
BJH
  • 443
  • 1
  • 5
  • 11
3
votes
1 answer

Workflow for modifying large cython projects

I need to make some modifications to scikit-learn, including changes to the cython code. I haven't worked on cython before, so could do with some guidance - so far I have got all the dependencies going in a python virtualenv, and cloned and…
N. McA.
  • 4,796
  • 4
  • 35
  • 60
3
votes
1 answer

Debug Cython with python-dbg fails with undefined symbol: Py_InitModule4_64

I am trying to debug a small cython project following the instructions from the official Cython page. but the command: python-dbg setup.py build_ext --inplace fails with the error below. I have seen responses to a similar issue here but I don't…
manolo__
  • 31
  • 4
3
votes
1 answer

no member pylint errors on calls to cython

Is there anyway to automatically whitelist modules with a specific name? I am having issues with no member calls from cython and would like to auto whitelist. Pylint is failing to find member so at this point I want to name modules with a specific…
Michael WS
  • 2,450
  • 4
  • 24
  • 46
3
votes
1 answer

What's wrong with my Cython?

I tried to write a Cython wrapper around the C++ library http://primesieve.org/ It wraps a single function count. So far, it installs correctly python setup.py install, but when I import primesieve the function primesieve.count is missing. Any…
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
3
votes
0 answers

Cython nested prange doesn't work

I am trying to make use of prange to run my loop in parallel. I am using nested prange. But during debugging I get not desired results. This is my code: %%cython # distutils: language = c++ # distutils: extra_compile_args = -fopenmp # distutils:…
warmspringwinds
  • 1,147
  • 2
  • 14
  • 31
3
votes
1 answer

efficient sign function in python for case of periodic boundary conditions

I have cython code I'm using to speed up a bottleneck in an otherwise pure python calculation. I have a pair of points in a periodic box of length Lbox (1d case is fine for this question). I need to compute the sign of y-x, and I need to flip this…
aph
  • 1,765
  • 2
  • 19
  • 34