cython

How to package a linked DLL and a pyd file into one self contained pyd file?

為{幸葍}努か 提交于 2020-01-12 01:45:34
问题 I am building a python module with Cython that links against a DLL file. In order to succesfully import my module I need to have the DLL in the Windows search path. Otherwise, the typical error message is: ImportError: DLL load failed: The specified module could not be found. Is there a way to packaged the DLL directly into the produced pyd file to make the distribution easier? One example of this is with the OpenCV distribution, where a (huge) pyd file is distributed and is the only file

setup.py for packages that depend on both cython and f2py

浪尽此生 提交于 2020-01-11 23:00:53
问题 I would like to create a setup.py script for a python package with several submodules that depend on both cython and f2py. I have attempted to use setuptools and numpy.distutils, but have so far failed: Using setuptools I am able to compile my cython extensions (and create an installation for the rest of the package) using setuptools. I have, however, been unable to figure out how to use setuptools to generate the f2py extension. After extensive searching, I only found rather old messages

setup.py for packages that depend on both cython and f2py

匆匆过客 提交于 2020-01-11 22:59:12
问题 I would like to create a setup.py script for a python package with several submodules that depend on both cython and f2py. I have attempted to use setuptools and numpy.distutils, but have so far failed: Using setuptools I am able to compile my cython extensions (and create an installation for the rest of the package) using setuptools. I have, however, been unable to figure out how to use setuptools to generate the f2py extension. After extensive searching, I only found rather old messages

Cython compile error C-Libraries Tutorial

荒凉一梦 提交于 2020-01-11 13:09:26
问题 I am currently trying to learn Cython, and started by going through their Tutorial. (Running Debian 8) I am running into problems in the Using C libraries part. Here are my setup.py from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize ext_modules = cythonize([ Extension("queue", ["que.pyx"], libraries=["calg"]) ]) setup( ext_modules=ext_modules ) que.pxd cdef extern from "libcalg/queue.h": ctypedef struct Queue: pass ctypedef void*

Looping through pixels with Cython still slow

非 Y 不嫁゛ 提交于 2020-01-11 11:50:53
问题 I get no speed difference here between regular python code. It says the bottleneck is the last two lines of code in the html file. Is there any way around this? What I am trying to do is loop through pixels and add coordinates where rgb value is below 210 to a list. from PIL import Image import numpy as np import time import cython import cv2 filename = "/home/user/PycharmProjects/Testing/files/file001.png" image = Image.open(filename) size = width, height = image.size image_data = np.asarray

Using Python objects in C++

我怕爱的太早我们不能终老 提交于 2020-01-11 09:46:14
问题 I'm writing a code that calculates the images of nonlinear maps using methods from interval analysis, applies a minkowski sum and repeats for an arbitrary number of iterations. I've written a working code in Python, however I would like to be able to implement some of the more iteration/recursion intensive parts of the algorithm in C++ to benefit from the increased speed. I have used Cython in the past with great results, but I'd like to practice my C++. Also, my objects are complicated

Poor performance of C++ function in Cython

可紊 提交于 2020-01-11 08:19:12
问题 I have this C++ function, which I can call from Python with the code below. The performance is only half compared to running pure C++. Is there a way to get their performance at the same level? I compile both codes with -Ofast -march=native flags. I do not understand where I can lose 50%, because most of the time should be spent in the C++ kernel. Is Cython making a memory copy that I can avoid? namespace diff { void diff_cpp(double* __restrict__ at, const double* __restrict__ a, const double

Cython setup.py for several .pyx

别来无恙 提交于 2020-01-09 19:44:40
问题 I would like to cythonize faster. Code for one .pyx is from distutils.core import setup from Cython.Build import cythonize setup( ext_modules = cythonize("MyFile.pyx") ) What if i want to cythonize several files with ext .pyx, that i will call by their name all .pyx files in a folder What would be python code for the setup.py in both cases ? 回答1: From: https://github.com/cython/cython/wiki/enhancements-distutils_preprocessing # several files with ext .pyx, that i will call by their name from

Make executable file from multiple pyx files using cython

落花浮王杯 提交于 2020-01-09 03:56:05
问题 I am trying to make one unix executable file from my python source files. I have two file, p1.py and p2.py p1.py :- from p2 import test_func print (test_func()) p2.py :- def test_func(): return ('Test') Now, as we can see p1.py is dependent on p2.py . I want to make an executable file by combining two files together. I am using cython. I changed the file names to p1.pyx and p2.pyx respectively. Now, I can make file executable by using cython, cython p1.pyx --embed It will generate a C source

cython: how do you create an array of cdef class

痴心易碎 提交于 2020-01-09 03:51:07
问题 I would like to have a cython array of a cdef class: cdef class Child: cdef int i def do(self): self.i += 1 cdef class Mother: cdef Child[:] array_of_child def __init__(self): for i in range(100): self.array_of_child[i] = Child() 回答1: The answer is no - it is not really possible in a useful way: newsgroup post of essentially the same question It wouldn't be possible to have a direct array (allocated in a single chunk) of Child s. Partly because, if somewhere else ever gets a reference to a