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
0 answers

Turning Cython code into an executable "Python.h: no such file or directory

I am to developing an SDK for my internship but there a smaller steps which need to be completed first, one of which involves being able to create an executable. We use Python, so my employer wants it to be converted to C code via Cython and then…
user4854287
3
votes
2 answers

High performance variable blurring in very big images using Python

I have a large collection of large images (ex. 15000x15000 pixels) that I would like to blur. I need to blur the images using a distance function, so the further away I move from some areas in the image the more heavier the blurring should be. I…
Chau
  • 5,540
  • 9
  • 65
  • 95
3
votes
1 answer

Optimizing point - circle distance method

I'm implementing a RANSAC algorithm for circle detection in images. I profiled the execution and I get: 13699392 function calls in 799.981 seconds Random listing order was used ncalls tottime percall cumtime percall…
rdbisme
  • 850
  • 1
  • 13
  • 39
3
votes
1 answer

Cython Extension Type inheriting from int cause a MemoryError

I am trying to make an extension type inheriting from int or cython.int. This is necessary for me as I need to be able to use this type as an index for some lists/arrays. Here is the code to reproduce the bug on Python 2.7.9 Win32 (I'm running…
gaborous
  • 15,832
  • 10
  • 83
  • 102
3
votes
1 answer

Cython cannot convert to int?

using Anaconda, Python 3.4 and Win7 64bit, i can't get this running: C Code: int addInts(int a, int b) { return a+b; } PYX file: cdef extern from "square.cpp": int addInts(int, int) def pAddInts(int a, int b): return addInts(a,…
mneuner
  • 433
  • 5
  • 25
3
votes
2 answers

Embedding Cython in C++

I am trying to embed a piece of Cython code in a C++ project, such that I can compile a binary that has no dependencies on Python 2.7 (so users can run the executable without having Python installed). The Cython source is not pure Cython: There is…
pansen
  • 117
  • 1
  • 8
3
votes
2 answers

Passing structured array to Cython, failed (I think it is a Cython bug)

Suppose I have a = np.zeros(2, dtype=[('a', np.int), ('b', np.float, 2)]) a[0] = (2,[3,4]) a[1] = (6,[7,8]) then I define the same Cython structure import numpy as np cimport numpy as np cdef packed struct mystruct: np.int_t a np.float_t…
SDE_Amazon
  • 121
  • 1
  • 8
3
votes
1 answer

Mixin Cython class and SqlAlchemy

Abstract: I have one cython class which represents a business unit. This class is declared in pure cython style. In one project, I need to map the business unit to a database. For doing this I would like to import the .pxd file and "map" it with…
3
votes
2 answers

Reading and writing an array in a file using C functions in cython

I am instantiating a class in cython. I want to declare one of the instance which is an array of float values once by computing it with a given function and save it in a binary file using c functions. For the further call of my class if the input…
Dalek
  • 4,168
  • 11
  • 48
  • 100
3
votes
1 answer

Defining a custom pandas aggregation function using Cython

I have a big DataFrame in pandas with three columns: 'col1' is string, 'col2' and 'col3' are numpy.int64. I need to do a groupby, then apply a custom aggregation function using apply, as follows: pd = pandas.read_csv(...) groups =…
sweeeeeet
  • 1,769
  • 4
  • 26
  • 50
3
votes
1 answer

Use Typed memoryview in cython if dimensions are unknown

I want to use a typed memoryview for optimizing a function, but I don't what would be the argument type. It could be an numpy array or even a scalar. How should I use typed memoryview then?
bewithaman
  • 768
  • 8
  • 16
3
votes
2 answers

Passing primitive pointers to C function from Cython

I am writing a Cython wrapper around a C library we are maintaining. I am getting the following error message: analog.pyx:6:66: Cannot convert 'unsigned short (*)' to Python object Here's the code I am trying to write: cimport company as…
Stephen Rasku
  • 2,554
  • 7
  • 29
  • 51
3
votes
4 answers

Making Cython work with Python 3.4 on Anacondas, Windows 7 64-bit

I have just installed Python 3.4 on my Windows 7 64-bit machine, using Anaconda/Condas. When I run the "hello world" cython example I get this error: [py34] C:\Users\Jon\Documents\GitHub\CythonFunctions\cython_funcs>python setup.py build_ext…
Ginger
  • 8,320
  • 12
  • 56
  • 99
3
votes
1 answer

When and how does cython do boundscheck?

c doesn't do bounds check. So how does cython do the check if it compiles to c? %%cython --annotate cimport cython @cython.boundscheck(True) cpdef myf(): cdef double pd[8] for i in range(100): pd[i] = 0 print pd[i] The above…
colinfang
  • 20,909
  • 19
  • 90
  • 173
3
votes
1 answer

Cython Pointer Inheritance

Problem I have a base class LinkPredictor and a sub class KatzIndex which derives from LinkPredictor in C++. Now I have another class which needs in its constructor a pointer to a LinkPredictor. I want to wrap those classes in Cython to make them…
xZA
  • 153
  • 1
  • 7