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.
11
votes
3answers
162 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...
9
votes
2answers
33k 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 ...
8
votes
3answers
3k 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 ...
8
votes
1answer
190 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 ...
6
votes
2answers
211 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 ...
6
votes
2answers
219 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 ...
5
votes
1answer
800 views
Optimize Cython code with np.ndarray contained
Can someone help me further optimize the following Cython code snippets? Specifically, a and b are ...
5
votes
1answer
189 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 ...
4
votes
2answers
59 views
Cython: Weighted Random Choice
I have a Cython function the takes a list of weights/probabilities (double) and returns a random index into the list.
For example
...
4
votes
1answer
83 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 ...
4
votes
2answers
745 views
4
votes
0answers
192 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 ...
3
votes
2answers
349 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
2answers
768 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'...
3
votes
1answer
260 views
Where is the bottleneck in my Cython code?
The profile tells me it took ~15s to run, but without telling me more.
...
3
votes
1answer
353 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 ...
3
votes
1answer
56 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 ...
3
votes
1answer
79 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 ...
3
votes
1answer
476 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
178 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
0answers
74 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 ...
2
votes
2answers
284 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.
...
2
votes
2answers
529 views
Is my Encryption Module Secure?
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 ...
2
votes
1answer
118 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 ...
2
votes
2answers
1k 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 ...
2
votes
1answer
1k 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?
...
2
votes
0answers
94 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 ...
2
votes
0answers
179 views
Cythonized version of FDCT (fast discrete cosine transform) function, ported from Java
This is my Cython code for an FDCT function (invoked here):
...
1
vote
1answer
548 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 ...