Questions tagged [cython]

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

cython
Filter by
Sorted by
Tagged with
2 votes
0 answers
54 views

Why is the time identical for Cython and Python versions of function?

I am just starting out learning about Cython. I have some code written in pure Python, and started to convert it to Cython. The first function is below (both versions). I expected Cython to be faster, ...
msm1089's user avatar
  • 1,374
3 votes
2 answers
4k views

Exception handling in cython

I have two .pyx files - bar.pyx and baz.pyx. I want to combine them into a single .so file. In baz.pyx I have a function baz that should do some checks and raise an exception if something goes wrong. ...
Tzoiker's user avatar
  • 1,372
1 vote
0 answers
298 views

Casting int pointer (array) to int typed-memoryview in Cython throws ValueError at runtime

Problem Description I have this function: def test(unsigned int N): cdef int *my_arr = <int *> malloc(N * sizeof(int)) cdef int[:] new_arr = <int[:N]>my_arr free(my_arr) When ...
ciclopez's user avatar
  • 138
1 vote
1 answer
114 views

Cython: How to convert C macro containing assignments

Say I have the following C macros that I'm trying to convert to Cython. The issue is that the 2nd and 3rd modify the value of their arguments. How to convert this to an equivalent in Cython? Example (...
Pierre D's user avatar
  • 25.5k
0 votes
0 answers
157 views

Error with netCDF4 when using Pyinstaller to create an exe from a .py

I made a small program in Jupyter that uses the following libraries: import pandas as pd import datetime #import pvlib forecast models from pvlib.forecast import RAP I made it on jupyter and it runs ...
flmrck's user avatar
  • 1
2 votes
2 answers
3k views

Fastest way to concatenate slices of numpy array

I have a large number of small numpy arrays (groups) of different sizes, and I want to concatenate an arbitrary subset of these groups as fast as possible. The solution I originaly came up with is to ...
pavel gramovich's user avatar
2 votes
1 answer
2k views

Compiling with Cython using OpenMP on macOS

I'm on macOS Mojave 10.14.6 and I'm trying to compile some required extensions modules in c and c++ from this repository with: python setup.py build_ext --inplace which gives me the following error: ...
vanessaxenia's user avatar
2 votes
0 answers
56 views

How to convert a 2D numpy array into an array of pointers in Cython? [duplicate]

I would like to wrap a C/C++ function with the following signature using Cython. // my_tool.h float func(const float** points, int n, int m) { float result = 0.; // ... for (int i=0; i<...
normanius's user avatar
  • 9,326
1 vote
1 answer
155 views

The Cython closure_freelist_size option

One of the more obscure Cython compiler options is closure_freelist_size, which defaults to 8. According to the documentation, this is the number of function closure instances to keep in a freelist ...
jmd_dk's user avatar
  • 12.7k
0 votes
1 answer
38 views

Package pxd defintions from different installed packages

I have an installed python module with cython extensions. Now I am writing a second (different) cython module that wants to import extensions from the installed cython module. However, it is not able ...
cvanelteren's user avatar
  • 1,683
2 votes
0 answers
182 views

Cython ImportError in Jupyter

I'm trying to use Cython in a Jupyter Notebook but keep encountering an error along the lines of ImportError: dynamic module does not define module export function (...
caaag's user avatar
  • 21
0 votes
1 answer
320 views

Cython Extern C++ Function

I'm trying to extern a c++ function to cython. Here is my code (all files are in the same directory) function.cpp int cfunc(int x){ return x; } wrapper.pyx cdef extern from "function.cpp&...
Hansen Young's user avatar
2 votes
1 answer
1k views

Buildozer can't find Cython

When I lauch buildozer -v android debug or buildozer android debug Buildozer returns: Cython (cython) not found, please install it. So I try to install Cython with sudo pip3 install Cython but it ...
Snakiron's user avatar
  • 473
2 votes
1 answer
496 views

How to use Sphinx in a Python project that depends on being built in place?

I have a large mostly Python project that I am trying to document. Part of this project is dependent on C++ source code which is made accessible via Cython. When running the code like normal it runs ...
GeneralCode's user avatar
2 votes
0 answers
45 views

How to load a custom Python module utilizing some program's symbols into that program?

I'm creating a custom Python module for a C application and the Python interpreter that runs in it. I have a problem, was trying with SWIG and now with Cython, and the result is the same: Traceback (...
psprint's user avatar
  • 359
4 votes
0 answers
1k views

Accessing a c++ vector/array from python via cython

I am wrapping a c++ program via cython and would like to make a vector from this program available in Python. I have written a getter method for the vector, which works fine except that it returns a ...
Samufi's user avatar
  • 2,565
0 votes
1 answer
125 views

Python C Extension

I am having issues returning a 2D array from a C extension back to Python. When I allocate memory using malloc the returned data is rubbish. When I just initialise an array like sol_matrix[nt][nvar] ...
Steven Taggart's user avatar
-1 votes
1 answer
266 views

Accessing C++ template class in cython

I have a template class called List defined in a file called containers.h: #include <iostream> #include <vector> namespace containers { template <class T> class List { ...
lol cubes's user avatar
  • 125
1 vote
1 answer
124 views

Cython : mitr argument of scipy.optimize.cython_optimize.brentq function - What is this argument used for?

mitr argument is a argument of the function scipy.optimize.cython_optimize.brentq that is set to 10 on the reference guide https://docs.scipy.org/doc/scipy/reference/optimize.cython_optimize.html. How ...
Ricardo Gonçalves Molinari's user avatar
0 votes
1 answer
102 views

Don't know how to optimize the code with Cython

I'm new on trying to optimize with cython and I need some help because I know I can optimize more but I don't know how. Firstly what I did was declare the variables in C, however a lot of them are ...
Ton Borrell's user avatar
5 votes
1 answer
1k views

Using clang with Cython

I coerced Cython to use clang by specifying the CC environment variable: import os os.environ['CC'] = 'clang' I have a standard build: EXT_MODULES = [Extension('example.src.ex', ...
Katie's user avatar
  • 958
2 votes
1 answer
107 views

Cython: Workaround scipy.optimize.cython_optimize.brentq argument ctype to work with class methods ctype

I'm trying to use the root finder scipy.optimize.cython_optimize.brentq inside a class, but the first argument of this function accepts only the type ctypedef double (*callback_type)(double, void*) ...
Ricardo Gonçalves Molinari's user avatar
0 votes
1 answer
86 views

Cython pyx modification for multidimensional numpy input with memory views

My current input of a function wrapped from a c++ class is a one dimensional numpy array, e.g., func(np.array([1,2,3])) for which my cython description in the pyx looks like the following: def func(...
Alejandro's user avatar
  • 939
0 votes
1 answer
476 views

Using Custom C functions with Pandas (an easy way)

Is there a way to have custom C functions act over a pandas DF? I know I can wrap a c function in a python function and use that over row wise iteration, for instance, but that seems inefficient. I ...
Warlax56's user avatar
  • 1,160
0 votes
1 answer
401 views

Cython optimization slow

I am trying to optimize the following python code with cython: from cython cimport boundscheck, wraparound @boundscheck(False) @wraparound(False) def cython_color2gray(numpy.ndarray[numpy.uint8_t, ...
Myrthe's user avatar
  • 45
0 votes
1 answer
426 views

Program using parallelism crashing: Discarding owned Python object not allowed without gil

%%cython from threading import Thread import time def countdown(n): while n > 0: n -= 1 COUNT = 10000000 start = time.time() t1 = Thread(target=countdown,args=(COUNT/2,)) t2 = Thread(...
Sanskar Jethi's user avatar
1 vote
3 answers
222 views

What is the best way to check of an object is an Enum in Cython?

I am looking for a Cythonic way (yes, Cython) to check if an object is of type Enum. Specifically, I want to distinguish between ints and IntEnums. I am looking for something like: cdef extern from &...
Darko's user avatar
  • 599
2 votes
0 answers
86 views

Why i have Cython magic name error after linux reinstallation?

I am facing a problem with Cython. I have a jupyter notebook with a lot of computation. I wrote Python + Cython code a few days ago. Everything worked. But yesterday I reinstalled my linux, installed ...
SantonioTheFirst's user avatar
0 votes
0 answers
278 views

Error when Compiling Cython into 32bit app

I have python code that I am using Cython to convert to C (in order to call from C# 32bit application). When I use MSVC x86 Native Tool Command prompt to run: python setup.py build_ext --inplace --...
OpusPyhton's user avatar
1 vote
1 answer
484 views

import a full c enum using cython automatically

im using cython to import c enums from .h file to my python code (the goal is to have one place that will include the enums for both of my programs). so i have my enums.h file: typedef enum Numbers{ ...
Finci's user avatar
  • 108
4 votes
2 answers
2k views

pickle a cython class containing __cinit__ : __setstate__ vs __reduce__?

I'm working on making some cython objects pickeable and have a question about using __setstate_ vs __reduce__. It seems that when you pickle.loads() an object with a __setstate__ method and also a ...
chris's user avatar
  • 1,312
2 votes
1 answer
401 views

ModuleNotFound when trying to install Python Extension Module (Cython) inside the same package specified in setup.py

I have a Cython extension module for a Python project I want to install to the same namespace as the project on installation. When I try to specify in the extension to install it inside the package ...
Levi Naden's user avatar
1 vote
2 answers
774 views

Is there a way to call a cdef class method that has non-pythonic arguments?

Effectively, I am cleaning up a cython module that has many globally scoped functions and variables. I thought cdef classes would be a great way to package some of these functions. But I ran into an ...
Todd Sierens's user avatar
0 votes
1 answer
929 views

Importing cython file in python, using pyximport results in the ImportError: because of distutils.error.CompilerError

I have forked scikit-learn github code from https://github.com/scikit-learn/scikit-learn. I want to debug this file: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/cluster/...
user3924729's user avatar
1 vote
1 answer
810 views

How can I solve "undefined reference error to" error in cython when using MinGW-w64?

I am new to Cython and I am trying to convert a python file to a C file and then to an executable using Cython, but after generating the C file when I try to compile it using GCC in Windows I get a ...
AnonymousK's user avatar
0 votes
1 answer
279 views

Distribute embed-cython-compiled .exe and run another machine without python

I have a small pyqt5 project written in python. I generate .cpp file using cython --embed , compiled with MSVC and it is working in my machine with no problem but I want to distribute .exe with no ...
scorp's user avatar
  • 25
1 vote
1 answer
791 views

Django+Cython import cython module in django app views [duplicate]

a newbie to django and Cython. I am creating an app in django and need to import function in views.py from cythonized module. following is views.py inside my app. from django.shortcuts import render ...
Amit Jha's user avatar
1 vote
1 answer
513 views

Determining path of the translated cython pyx source file

I have a cython source file in which I would like to import the local python module. This cython source file is translated using cython (python3 syntax) into a c++ source, which in turn is compiled ...
Wojciech J. Migda's user avatar
5 votes
0 answers
648 views

Passing python objects to C Gstreamer functions, using Cython

I'm using Python3.6 with GStreamer-1.0 and PyGObject (for python access) to read video frames from a camera (tiscamera). The frames are gotten via python code and eventually I get a GstBuffer: import ...
yoel's user avatar
  • 305
5 votes
0 answers
5k views

Cython error while installing pandas from setup.py

Facing some errors related to cython while installing pandas from setup.py. Unable to fix that error. I'm trying to install the library offline with setup.py [16/40] Cythonizing pandas\_libs/reduction....
user avatar
2 votes
0 answers
597 views

No module named error. How to import function from .pyx file in python from different directories rooted to same directory?

I am running code from main.py. Following is my directory structure: I'm using Python 3.6 and Linux. PackA PackB PackC _main.py PackD ...
user3924729's user avatar
3 votes
1 answer
536 views

Python C/C++ Wrappers versus Pure C/C++ Performance [closed]

I've been doing some projects in computer graphics that have revolved around using open source libraries written and C/C++ that were then turned into wrappers for python. I want to know if the ...
Areisner's user avatar
  • 105
2 votes
0 answers
267 views

How is the number of threads available to a library function (which is written in Fortran) set in Python?

Problem Summary: The custom Python library PYFEAST (https://github.com/empter/PYFEAST) is a library which allows users to call the Fortran FEAST libraries (https://arxiv.org/pdf/2002.04807.pdf) which ...
John Tiessen's user avatar
1 vote
0 answers
733 views

Optimize Python dictionarys look-up in Cython

I'm trying to improve the speed of this function in Cython, because is the main function of an algorithm. cpdef float _cost(list path, int lenth, dict time, dict cost): cdef: float ...
Rubiales Alberto's user avatar
2 votes
1 answer
275 views

How to share a C-singleton between multiple C-extensions

I have a static library (or a bunch of c/cpp-files for that matter) which contains a singleton and is used by/linked to two different C-extensions. However, the singleton from the C-library doesn't ...
ead's user avatar
  • 33.7k
0 votes
1 answer
531 views

Wrapping C function with void pointer as argument using Cython

I am learning C library wrapping in cython. I compiled a couple of simple C function and header files using cython and now am trying to run another example which is more complicated one than previous ...
Derik's user avatar
  • 57
0 votes
1 answer
2k views

Error with using cython "fatal error C1083; Cannot open include file: 'io.h': No such file or directory" [duplicate]

Today I tried to compile a file with cython. I downloaded vs_buildtools 2019 and eventually tried installing almost everything within "C++ build tools", still not working. Here are some ...
Abraham Reinhardt's user avatar
5 votes
2 answers
492 views

Cython: How to sort the contents of one vector by another vector?

I'm trying to sort two C++ vectors in Cython, one by the contents of itself and one by the contents of the first vector. cimport cython from libcpp.vector cimport vector from libcpp.algorithm cimport ...
narcissa's user avatar
  • 351
0 votes
0 answers
259 views

How import function from C++ inside Cython class?

I'm learning Cython and I'm trying to define a class that uses a C++ function that I created. After almost two days reading docs and trying I Always have an error. This is the error trace: /home/...
Rubiales Alberto's user avatar
0 votes
0 answers
32 views

Cython: return double * heap array from cython function to python as a 1D np.ndarray [duplicate]

I am trying to generate time series noise. My noise array are ~350,000 in size so they must be heap allocated. How can I return my heap allocated array back to the python code that called the function ...
Danny Diaz's user avatar

1
21 22
23
24 25
107