Questions tagged [cython]
Cython is a superset of the Python language for quickly generating Python C extensions.
4,838
questions
0
votes
0
answers
9
views
DLL load failed while importing after building .whl package with cython
I have built a cython package on windows using mingw.
Everything was fine, the only warnings i got during the compilation were:
\__init__.c:126091:13: warning: unknown conversion type character 'z'...
1
vote
1
answer
30
views
Cython compiler - fatal error C1083: Cannot open include file
I followed the following steps to replicate the Classical Music Composition Using State Space Models code.
The inference algorithms for this code are in Cython. To run the notebook, first run:
np....
0
votes
1
answer
30
views
How to fix abrupt program exit in Cython interface to Fortran
Short version
I have old Fortran code I am trying to access by wrapping it through a Cython extension module (have done that already for other Fortran libraries). The code works when called from ...
0
votes
0
answers
33
views
Cython/C++Qt interfacing
I achieved to compile a small test on Cython so that it worked, but I didn't figure out how to interface Cython with QtC++ (in both ways). I remarked that it generates a very long C file and not C++ ...
0
votes
1
answer
25
views
Cython: error while building extension: Microsoft Visual C++ 14.0 or greater is required
Short Description:
I'm trying to build an example cython script, but when I run the python setup.py build_ext --inplace command, I get an error saying that I need MS Visual C++ version 14.0 or greater....
0
votes
1
answer
25
views
Interfacing external C code with duplicate method names using Cython
I want to provide a native interface to some C code from my Python code. For this I decided on Cython.
In this specific case, I have some C files which have duplicate names, resulting in compilation ...
0
votes
1
answer
55
views
Parallel programming in Cython
from numpy.linalg import inv
from numpy import array
def test (A,U,m):
Lambda=array(list(map(lambda x:inv(U)@A[x]@U,(range(m*m)))))
This is a simple code that calculates an array product. How can ...
0
votes
0
answers
31
views
Cython anomalous speed differences when casting variable from float to short?
I've noticed that when attempting to optimize a Cython loop, casting a float to a short take significantly more time for a defined (and ctyped) variable. Here is an example function with OPTION 1 and ...
0
votes
0
answers
28
views
Cython & tox - ModuleNotFoundError on 3.9, but not 3.8
I'm converting some of my scripts in my package to cython to try and speed up execution time, and I'm having some trouble getting it to work with tox.
The tests are passing on 3.8, but on 3.9 I get ...
1
vote
1
answer
45
views
Use Cython / Microsoft Visual C++ Build Tools without admin rights
I was looking for ways to interface C++/Qt projects with Python when I decided I might start learning Cython code.
I found this article from Pycharm's website, saying that the free version does have ...
0
votes
1
answer
51
views
What is visible in an executable built with Cython, in case non-compiled Python code is executed?
When we write Cython code (with types), this will eventually be compiled like C-compiled code and we can't recover the source code (except disassembling but then this is similar to disassembling C ...
0
votes
1
answer
29
views
Edit location of compiled files with setuptools
I am using setuptools to compile a pyx file using Cython using the following code in my setup.py
from Cython.Distutils import build_ext
extensions=[Extension("filtering.filter", "...
0
votes
1
answer
39
views
Cython function in pure python mode returning an list of strings
I am trying to convert the following python function:
def python_compare(a: str, b: str) -> list:
n = len(a)
result = []
for i in range(n):
letter1 = a[i]
letter2 = b[i]
...
2
votes
0
answers
16
views
Using NCCL library from cupy in a cython file (.pyx)
I am trying to import the function and definitions on https://github.com/cupy/cupy/blob/master/cupy_backends/cuda/libs/nccl.pyx
To a pyx file with a cimport, but it is not working.
I would like to ...
0
votes
0
answers
14
views
Sampling without replacement along a 2D grid in Cython without gil (can be in C++)
I have essentially a 2D grid of N by M (i.e. N rows, and M columns). I would like to sample from this grid without replacement in Cython without requiring the GIL. I would want something like this
for ...
0
votes
0
answers
25
views
CUDA C++ cython extension throws "DLL load failed while importing"
I have written a C++ CUDA extension of some linalg in visual studio, and I have created a .dll and .lib file. I have also created a wrapper using cython, but there is obviously some kind of dll ...
0
votes
1
answer
67
views
Fastest way to do loop over 2D arrays in Cython
I am trying to loop over 2 2d arrays in Cython. The arrays have the following shape:
ranges_1 is a 6000x3 array of int64, while ranges_2 is a 2000x2 of int64. This iteration needs to be perfomed ...
0
votes
0
answers
30
views
is it possible to convert the kivy code of python into a cython code for better performance
I am working on the project using kivy gui in python but it's performance is very slow,so is it possible to convert that kivy code in cython for getting better performance as in resposne time of an ...
1
vote
0
answers
56
views
[Cython]How to improve the performance of mapping List[str] to ndarray[int]?
The input is a sequence of str, and the output is a sequence of int by looking up a mapping: Dict[str, int].
For example, if the input is ['foo', 'bar', 'baz'], and the mapping is {'foo': 1, 'bar': 2, ...
0
votes
0
answers
16
views
How to cythonize a Python-ROS2 package in order to hide the source code?
I have a ROS2-python (rclpy) package with multiple subpackages that work together. I would like to cythonize the package in order to hide the source code and just leave the executables to do the job. ...
0
votes
0
answers
89
views
Can somebody explain how to solve this bug?
%%cython
cimport cython
import numpy as np
cimport openmp
from numpy.linalg import inv
from cython.parallel cimport prange
@cython.boundscheck(False)
@cython.wraparound(False)
def ...
1
vote
0
answers
51
views
Migrate Cython driver to Rust FFI
Summary
I have some Cython code to interact with a 3rd party C++ driver library for a USB device. I am able to call the library from Python and open a device session. However, when I try to call the ...
0
votes
0
answers
36
views
How can I include external modules when compiling Python code with Cython?
I have an extension that I compile with cython into the related *.pyd or *.so files, which are then imported into my very basic main.py:
if __name__ == "__main__":
from my_extension ...
0
votes
0
answers
26
views
Returnung an array in Cython [duplicate]
I need to allocate memory for a large buffer, without actually initializing it (it will be used as a result buffer later and every location will be written to, so initialization is just a waste of ...
0
votes
1
answer
53
views
Trouble transitioning to multiprocessing python code to cython
I'm running a program that takes real time data on a Raspberry pi 4. Because the program is quite demanding, the different functionalities are separated into the different cores with Multiprocessing ...
0
votes
0
answers
24
views
Unable to get a pyd file after cythonization Cython Python
Hi trying to implement cython however I do not get a helloworld.pyd file in my directory when I build the cython file. I am running on Windows 10.19043, python version 3.7.9 , cython version 0.29.28 . ...
0
votes
1
answer
31
views
Is there a way to iterate over struct attributes?
Sorry if this has been asked before. It does seem very simple. I am wondering if there is a way to iterate over struct attributes.
E.g.
ctypedef struct Foo:
int a, b
cdef Foo foo = [1, 2]
#...
0
votes
1
answer
34
views
I don't know how to wrap the .c file and.pyx file code
I am beginner in Cython and I am learning it from a book of O’Reilly's Cython and I have an issue in the code that I do not know that how I can wrap the code of .c file (C file) and .pyx file(Cython ...
1
vote
1
answer
33
views
derive class from from sklearn.cluster.KMeans with cython
I like to create a child class of scikit-learns's sklearn.cluster.KMeans and would like to do this in cython for performance reasons. Is this possible?
There is an old issue https://github.com/scikit-...
0
votes
1
answer
40
views
Unwanted error in Cython code in calling the functions of c
I am a beginner in Cython and I am following the official documentation of Cython and in that there is a section called "Calling C functions" and in that it is written that how to import c ...
0
votes
1
answer
18
views
using special function such as __add__ in cython cdef classes
I am wanting to create a cython object that can has convenient operations such as addition multiplication and comparisons. But when I compile such classes they all seem to have a lot of python ...
0
votes
1
answer
34
views
Representing non-contiguous memoryviews with Cython
Quick example to see right away what I am talking about:
import numpy as np
arr = np.arange(10*30, dtype=np.float64).reshape(10, 30)
arr_slice = arr[::2]
arr_tile = arr[:3, :5]
Provided a shape, ...
0
votes
0
answers
28
views
Convert Python BytesIO to C FILE object
I have a C library that is wrapped using Cython. Some functions of the C library are using FILE objects internally which are being worked on with fseek, fputc, etc. Currently the function retrieves a ...
0
votes
0
answers
96
views
cythonize not found on Ubuntu 22.04 after "pip3 install cython"
Command: cythonize rednose/helpers/ekf_sym_pyx.pyx
Error: sh: 1: cythonize: not found
I have recently installed Ubuntu 22.04. I was trying to install https://github.com/commaai/rednose.
Few days back,...
0
votes
0
answers
27
views
How to make python package with cython parts
Hi i'm trying to speed up my python package by rewriting some parts in cython.
I've done it but faced problem with importing and building package.
Link to full code in gihub
Link to my package on pypi
...
0
votes
0
answers
21
views
Why does adding an __init__.py change Cython build_ext --inplace behavior?
This is a toy version of a problem I have. I'm trying to use setuptools to compile some Cython code in place, as part of a larger project.
My topdir is test. It contains:
hello_world.pyx
def say_hi()...
0
votes
0
answers
31
views
is it possible to protect tensorflow training code
Now a days very high power shared GPUs are available for deep learning training at very cheap price. But protecting your training dataset and code is problem there because GPU owner can see your files....
0
votes
0
answers
27
views
How do I properly link python extension modules in C++?
I have a simple example python extenstion I want to use from C/C++. The code is as follows
example.pxy:
from numpy import random
cdef public void somefunc():
print(random.randint(500))
setup.py:
...
0
votes
0
answers
28
views
How to pass numpy array to Cython function correctly and fastly?
I started from the example code for testing, but calling function is way too slow.
Here are codes.
The first cout in Rectangle.cpp comes out about 20 seconds after run python code.
I guess that it ...
0
votes
0
answers
24
views
pip Trouble building wheel while installing web3 [duplicate]
I have been trying to install web3 using pip3 for interacting with a blockchain. Previously, I was able to install some packages by pip3 without any problem. However this time it causes errors while ...
0
votes
0
answers
36
views
Conditions for Cython program to not need to initialize python interpreter
My ultimate goal is to write a multi-threaded c++ program where each class will be run in its own thread, and some of these classes need to call python functions. Ideally the classes which call Python ...
0
votes
0
answers
27
views
cython Memoryviews integer array indexing [duplicate]
I am trying to do the numpy-like integer array indexing in cython. I wonder if cython memoryviews supports this kind of indexing. Thanks.
y = np.arange(35).reshape(5, 7)
y[:3, [1, 3, 2]]
Also, if ...
2
votes
1
answer
36
views
How to declare a c++ tuple in cython
I have a C++ method declared as follow:
std::tuple<std::vector<int>, std::size_t, std::size_t> get_state(); // Should I use a struct and expose the struct instead?
And I would like to ...
1
vote
0
answers
39
views
PyCharm warning with Cython: Expected type 'Type[typeName]', got 'typeName' instead
While writing Cython code using Pycharm 2021.3.2 (Professional Edition), I can't figure how to make these warnings go away or how to disable those specific instances without disabling the entire ...
0
votes
0
answers
39
views
Cython: How to allocate a new array in pure-python with nogil
I want to create a variable length array in pure-python mode with nogil in Cython. For instance, consider the following example:
import numpy as np
import cython
@cython.cfunc
@cython.boundscheck(...
0
votes
0
answers
53
views
Pyomo doesn't load when called via cython
I am trying to compile python code that runs pyomo on a RedHat 6 system, but pyomo.environ will not load. It’s not clear to me that this is a pyomo error because pyomo.environ package loads and runs ...
0
votes
0
answers
44
views
quicksect/quicksect.pyx missing from newer quicksect files
I am trying to install quicksectx for some spaCy work and cannot get it to install properly on a macOS as I get the error
ValueError: 'quicksect/quicksect.pyx' doesn't match any files
I downloaded ...
0
votes
1
answer
30
views
How to define a C++ class destructor with Cython?
cdef cppclass ObjectDef:
string* name_ptr
ObjectDef():
this.name_ptr = new string(b"John")
~ObjectDef(string _name): # <= cython error on "~"
del ...
0
votes
0
answers
24
views
Jupyter Notebook Can't Import my TestPyPI package
I'm new to package publishing and thought I would start with a test one. The only complication it uses a very basic Cython module (the package I actually want to upload is Cython based). The Git is: ...
1
vote
1
answer
50
views
How to apply sqrt to vector in Cython?
Hello I'm really beginner to Cython or C-based language.
I have a problem to get a square of a vector.
I have a vector(each value is double type):
x = [1, 4, 9]
and I want to get:
y = [1, 2, 3]
How ...