I'm having a lot of fun learning Python by writing a genetic programming type of application.
I've had some great advice from Torsten Marek, Paul Hankin and Alex Martelli on this site.
The program has 4 main functions:
generate (randomly) an expression tree.
evaluate the fitness of the tree
crossbreed
mutate
As all of generate, cr...
In Cython, the usual raise keyword emits C code that contains a reference to the line and name of the Cython source file, allowing a useful error message to be generated.
However, I haven't seen anything for warnings. Simply calling warnings.warn leaves the interpreter confused as to where the warning came from. I could use PyErr_WarnEx...
I wrote some Python code and it worked fine when using the "python". I then converted it to C using "Cython" and used distutils to compile it to a shared library. I then changed some of the code to Cython so it would run faster. But when I imported the .so module and tried to use the command I had "cdef"ed it said that the command didn't...
I just came across Cython, while I was looking out for ways to optimize Python code. I read various posts on stackoverflow, the python wiki and read the article "General Rules for Optimization".
Cython is something which grasps my interest the most; instead of writing C-code for yourself, you can choose to have other datatypes in your p...
My pyx depends upon a native library
How can I pyximport.install() it? The auto-build in pyxinstall doesn't know to link with the native library, so the build fails...
...
I'm trying to interface a C++ library (pHash) with Python using Cython, but I have trouble with some of the types. The library functions use "unsigned long long" and I can't find a way to declare variables and parameters with this type. I searched for a list of the types that I can use with cdef but I found nothing. Can anyone point me t...
Hi,
I have a number of C functions, and I would like to call them from python. cython seems to be the way to go, but I can't really find an example of how exactly this is done. My C function looks like this:
void calculate_daily ( char *db_name, int grid_id, int year,
double *dtmp, double *dtmn, double *dtmx,
...
Hi folks,
I've been trying to figure out how to wrap the following C functions = compress.c , compress.h.
I tried following the tutorials, but after creating the .pxd file I don't know what to do :|
From what I have understood this is the pxd file that I should have
cdef extern from "compress.h":
size_t compress(void *s_start, v...
I have the following Cython code (adapted from the bpbio project) that does Damerau-Levenenshtein edit-distance calculation:
#---------------------------------------------------------------------------
cdef extern from "stdlib.h":
ctypedef unsigned int size_t
size_t strlen(char *s)
void *malloc(size_t size)
void *calloc(size_t n...
Hello all,
I'm trying to write some cython code to do computations with numpy arrays. Cython seems to not like the [] used in all the examples I've seen to define the datatype and number of dimensions.
For example, I have a file test.pyx:
cimport numpy as np
import numpy as np
ctypedef np.ndarray[np.float64_t, ndim=2] mymatrix
c...
in an effort to solve question #3367795 here on SO i have to cope with a number of subproblems. one of these is: in said algorithm (levenshtein distance), several arrays are allocated in memory and initialized with the lines
cdef char *m1 = <char *>calloc( blen + 2, sizeof( char ) )
cdef char *m2 = <char *>calloc( ble...
I'm attempting to install various python extensions on OS X (10.6.4), with a python.org python (Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)). Consistently running into a problem on the gcc step. Here's a sample from compiling Cython (btw, I'm attempting to install Cython in order to install lxml):
In file included from /usr/includ...
I'm back with another longish question. Having experimented with a number of Python-based Damerau-Levenshtein
edit distance implementations, I finally found the one listed below as editdistance_reference(). It
seems to deliver correct results and appears to have an efficient implementation.
So I set down to convert the code to Cython. o...
Hello Everyone,
Is it possible to optimize speed of a mission critical application developed in Django with Cython
Sorry in advance if it doesn't make sense......as i am new to django.
Recently i have read on the internet that you can use cython and turn a python code to c like speed......so i was wondering is this possible with djan...
I need access to the uint64_t typedef from stdint.h in some wrapper code that I'm writing and I can't figure out how to get it done. The problem is that from what I can tell from the docs, my ctypedef will have to take the form:
ctypedef unsigned long uint64_t
or
ctypedef unsigned long long uint64_t
depending on if WORDSIZE from bi...
I wrote a program that calls a function with the following prototype:
def Process(n):
# the function uses data that is stored as binary files on the hard drive and
# -- based on the value of 'n' -- scans it using functions from numpy & cython.
# the function creates new binary files and saves the results of the scan in...
Hi,
I have a scientific application that I built in Python (the application's 'critical areas' are optimized with Cython, for increased speed).
Every instance of the application is given a text file (with parameters) an an input. The application reads the parameters from the text file and, using data that is stored in the hard drive, r...
or, more correctly, what is the fundamental bug with my classic untrendy non-shader-VBO-stuff?
cdef struct xyz:
float x, y, z
cdef inline void _normal(xyz b,xyz a):
glNormal3f(a.x-b.x,a.y-b.y,a.z-b.z)
cdef inline void _draw_quad(xyz a,xyz b,xyz c,xyz d):
glVertex3f(a.x,a.y,a.z)
glVertex3f(b....
I have a file format (fastq format) that encodes a string of integers as a string where each integer is represented by an ascii code with an offset. Unfortunately, there are two encodings in common use, one with an offset of 33 and the other with an offset of 64. I typically have several 100 million strings of length 80-150 to convert ...
I try to conditionally compile (or generate) to c code from a Cython pxd. I read that I can DEF to define aa value and IF to conditionally generate based on its value, but how can I get this value to get from outside of the pxd file?
Specifically these two cases are interesting for me now:
give some command-line define to Cython, pref...