cython

how to measure cython execute time to compare with c

how to measure cython execute time to compare with c Question: I was trying to compare c and cython runtime and decide on which one should I choose for my project. So I tested a simple calculation with both. but I couldn’t find any good answer to how to measure cython execute time to compare …

Total answers: 2

Subtype Polymorphism is broken in Cython v30.0.0a11?

Subtype Polymorphism is broken in Cython v30.0.0a11? Question: Trying to pass an instance of a derived class to a function which accepts instances of the superclass gives an error in Cython v3.0.0a11: test.pyx: class MyInt(int): pass def takes_int(a: int): pass try.py: from test import takes_int, MyInt takes_int(MyInt(1)) try.py OUTPUT: Traceback (most recent call last): File …

Total answers: 1

SO module found by Cython not found by Python3

SO module found by Cython not found by Python3 Question: I have a simple pyx file: $ cat helloworld.pyx print("hello world in pyx file to be converted to so file by cython.") I have created an .so module using Cython. The directory contains following files: $ ls -ltrh total 140K -rw-r–r– 1 cardio cardio 177 …

Total answers: 1

Workaround for Cython bindings library to C++ that lacks nullary constructor?

Workaround for Cython bindings library to C++ that lacks nullary constructor? Question: I’m working on a set of Cython bindings to expose a C++ compression library in python. The library uses the Pimpl pattern and, in particular, has no default empty constructors. I’m wrestling with using a class method that returns a CompressionConfig object, which …

Total answers: 2

cl : Command line warning D9002 : ignoring unknown option "-O3"

cl : Command line warning D9002 : ignoring unknown option "-O3" Question: I want to build a project that uses various flags by type -O3 -Wall -std=c++11 using cython, but I get an error: cl : Command line warning D9002 : ignoring unknown option Maybe it is possible to replace compilation with VS with Cmake, …

Total answers: 1

Can Cython .so files be used in C?

Can Cython .so files be used in C? Question: I used Cython recently and discovered that it outputs a .so file. Can I use the .so file in my C program and if so, how do I implement that? Asked By: stephen telian || Source Answers: Yes, assuming that the SO file exports its internal …

Total answers: 1

Cython: error while building extension: Microsoft Visual C++ 14.0 or greater is required

Cython: error while building extension: Microsoft Visual C++ 14.0 or greater is required Question: 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. I’ve tried a lot of the …

Total answers: 2

PIP failed to build package cytoolz

PIP failed to build package cytoolz Question: I’m trying to install eth-brownie using ‘pipx install eth-brownie’ but I get an error saying pip failed to build package: cytoolz Some possibly relevant errors from pip install: buildlib.win-amd64-3.10cytoolzfunctoolz.cp310-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\link.exe’ failed with exit code 1120 …

Total answers: 4

How can I use 'prange' in Cython?

How can I use 'prange' in Cython? Question: I’m trying to solve a two-dimensional Ising model with a Monte Carlo approach. As it is slow, I used Cython to accelerate the code execution. I would like to push it even further and parallelize the Cython code. My idea is to split the two-dimensional lattice in …

Total answers: 2

Filtering (reducing) a NumPy Array

Filtering (reducing) a NumPy Array Question: Suppose I have a NumPy array arr that I want to element-wise filter (reduce) depending on the truth value of a (broadcastable) function, e.g. I want to get only values below a certain threshold value k: def cond(x): return x < k There are a couple of methods, e.g.: …

Total answers: 1