Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [cython]

The Cython language is a superset of the Python language, used to quickly generate Python C extensions. You should also tag with Python when using this tag.

4
votes
2answers
46 views

Python command line tool for compiling py files to exec files on Mac

When I used to use a PC I was familiar with py2exe, the mac equivalent I saw most people talking about was py2app — which compiles python to .app files, not .exec files. I was familiar with compiling ...
7
votes
2answers
314 views

Computing the gradient of a function

I have some Python code which uses NumPy which computes gradient of a function and this is a big bottleneck in my application. So, my initial attempt was to try to use Cython to improve the ...
4
votes
3answers
550 views

3D Connected Component in Cython

This is my implementation of 3D connected component algorithm, which I use for a 255x512x512 binary matrix. Although it is written in Cython, it still takes quite some time both for 6-neighbors and 26-...
3
votes
1answer
214 views

Speed up a simple edge connecting algorithm

I have a list of edges and a similar list of links (linking edges) telling which edges to connect (how to order them). Connected edges form polygons and there can be many disconnected polygons (...
1
vote
1answer
43 views

Cythonic Laplacian solving on a 3D regular grid

I have followed to official Cython for NumPy users to make a Laplacian solver on a 3D regular grid with Dirichlet conditions. Right now I'm happy with the results it returns, but I'm wondering if ...
1
vote
0answers
44 views

Calculating the number of matches for a tuple, a pair of nodes and a mapping

For a current node_pair, this program computes the number of variables matches it has. The matches for a node pair combined with a key are stored in a weight_dictionary with keys for each node pair. ...
2
votes
0answers
423 views

Lotto simulator in Python

I wrote a rather inapt lotto simulator in Python, showing how long it would take to win the jackpot. I ran a similar application implemented in C and it is so much faster. I know you can't compare the ...
6
votes
1answer
226 views

Implementation of Adaptive Rejection Sampling in Cython

I am trying to re-write some Fortran code in Cython which is the implementation of the adaptive rejection sampling method. I'd like to use my Cython version eventually in some Python code. I am ...
3
votes
2answers
78 views

Cythonized Sutherland-Hogman algorithm

I want to cythonise the python implementation of the Sutherland-Hogman algorithm. This algorithm updates a list of vertices according to pretty simple rules (being inside or outside an edge, etc.) but ...
12
votes
1answer
456 views

Using lots of regex substitutions to tokenize text

I authored a piece of code that was merged into the nltk codebase. It is full of regex substitutions: ...
3
votes
0answers
332 views

Efficiently writing string comparison functions in Python

Let's say I work for a company that hands out different types of loans. We are getting our loan information from from a big data mart from which I need to calculate some additional things to calculate ...
3
votes
1answer
195 views

Cython code for adaptive binning

Here is my Cython code used for adaptive binning. The calcAdaptiveBinnedRateMap function is called from another Python script. The script is compiled using Cython ...
3
votes
0answers
126 views

Speed up a Gibbs sampler with Cython

I have implemented a Gibbs sampler to generate textured images. According to the beta parameters (array of shape(4)), we can generate various textures. Here is my ...
5
votes
2answers
393 views

Weighted Random Choice

I have a Cython function that takes a list of weights/probabilities (double) and returns a random index into the list. For example: ...
4
votes
0answers
603 views

Cyther: The Cross Platform Cython/Python Compiler (Take 2)

I recently posted an earlier version of this code on Code Review, and now with the given suggestions and many other improvements, I am back. I included the description of exactly what Cyther is ...
8
votes
2answers
1k views

Cyther: The Cross Platform Cython/Python Compiler

The newer version of this question is located here: Cyther: The Cross Platform Cython/Python Compiler (Take 2) I am currently writing a Python library (soon to be published)that automatically ...
11
votes
3answers
571 views

Fast Python spring network solver

I wanted a very simple spring system written in Python. The system would be defined as a simple network of knots, linked by links...
2
votes
2answers
13k views

Efficiently index rows of numpy array by exclusion

I need a function that takes a numpy array and a row number as inputs and returns the array (or copy of the array) excluding the given row. I want to do this as efficiently as possible. ...
6
votes
2answers
1k views

Fastest possible Cython for Black-Scholes algorithm

I started with a pure python implementation, and have been trying to get the performance as close to native C as possible using numpy, numexpr, and cython. Here is the the numpy version that I ...
3
votes
0answers
137 views

Compute the box covering on a graph using CPython

Edit: My initial idea was to use numpy to solve efficiently this problem but after trying without results, someone comment on stackoverflow: "Numpy can speed things up a lot IF your problem is ...
12
votes
1answer
547 views

A big “Game of Life”

Our quest: Create a big simulation for Conway's Game of Life, and record the entire simulation history. Current Approach: Cython is used for an iterate method. The ...
3
votes
1answer
339 views

Chromatic aberration

surface is a pygame.surface object from the Pygame graphics library. It actually runs way faster than I thought it would for a ...
2
votes
1answer
2k views

Reading the bytes of a PDF

I'm quite a newbie in Python and I want to speed up this method since it takes very long time especially when the size of the input file in Mbs. Also, I couldn't figure out how to use Cython in the ...
4
votes
1answer
2k views

Create a list of all strings within hamming distance of a reference string with a given alphabet

For a bioinformatic problem, I found myself wanting to create a list of strings within Hamming distance "k" of a reference sequence. I wanted to do so quickly and pythonically. I've implemented it in ...
4
votes
1answer
130 views

Project Euler #10 in Cython

I'm trying to teach myself some Cython. To do so, I use Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. 2 Find the sum of all the primes below two million. My Cython ...
5
votes
1answer
742 views

Resource-constrained project scheduling

I'm trying to implement an algorithm for a resource-constrained project scheduling problem. I have several resources, resource constraints and all of this is in ...
3
votes
0answers
394 views

Finding cycles in a graph that pass through a vertex at most k times

I have a project that relies on finding all cycles in a graph that pass through a vertex at most k times. Naturally, I'm sticking with the case of k=1 for the sake of development right now. I've come ...
4
votes
1answer
4k views

Fastest computation of N likelihoods on normal distributions

In the context of a Gibbs sampler, I profiled my code and my major bottleneck is the following: I need to compute the likelihood of N points assuming they have been drawn from N normal distributions ...
4
votes
1answer
901 views

BK Tree implementation

I'm working on a system that can search for similar images. This involves being able to search by edit-distance, and as such I've implemented a special data-structure called a BK tree. Some notes here....
3
votes
1answer
66 views

Fast counting of interactions between groups given users interactions and groups assignments

Given: An array c that contains the group assignment of every user (c[i]=4 indicates that user i belongs to group 4) A matrix ...
4
votes
1answer
241 views

Calculating the distance squared between all vertex-pairs of a number of 2D polygons

I have implemented my code using Cython. It is the current bottleneck in my computations. There are two non-numpy functions involved: calculate_2D_dist_squared ...
3
votes
2answers
365 views

Calculating the push or pull force of a molecule at a vertex

The basic idea of the code is to calculate the push or pull force at a vertex, given the number of "push causing molecules" and "pull causing molecules" at a polygon vertex. The code thus mainly ...
3
votes
1answer
504 views

Where is the bottleneck in my Cython code?

The profile tells me it took ~15s to run, but without telling me more. ...
7
votes
3answers
5k views

Understanding the differences: A direct comparison between Cython and C++ [closed]

Introduction: The following two code samples are a direct comparison of performance between Cython and C++. I pieced them together with the help of others-- I barely understand how they work. Their ...
3
votes
0answers
321 views

Cythonized version of FDCT (fast discrete cosine transform) function, ported from Java

This is my Cython code for an FDCT function (invoked here): ...
2
votes
2answers
2k views

Fastest / most efficient random bit indexing in Python

Using Python/Cython, I am trying to construct an efficient way to index boolean values. I have been trying to use the bitarray and/or bitstring packages to construct a fast, non memory intensive way ...
4
votes
2answers
2k views
6
votes
1answer
3k views

Optimize Cython code with np.ndarray contained

Can someone help me further optimize the following Cython code snippets? Specifically, a and b are ...
3
votes
1answer
3k views

Speedup cython dictionary counter

I wrote a simple cython script to optimize the collections.Counter of a dictionary counter and the python zip implementation (the main input is a list of tuples). Is there a way to speed it up? ...
15
votes
2answers
77k views

Fastest way to iterate over Numpy array

I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to ...
4
votes
2answers
1k views

Speeding up a Cython program

I wrote the following piece of Python as a part of a larger system. Profiling reveals that a large amount of time is spent in DocumentFeature.from_string. So far I'...
1
vote
2answers
1k views

Is my Encryption Module Secure? [closed]

I have a simple encryption module that is used to "encrypt" a text file because it contains some passwords. I only need to encrypt it because I need those passwords in my program (they are used to ...