[Cython] newbie question concerning scope

2009-05-08 Thread Chris Colbert
Hi all, Just recently got into working with cython for speeding up some calculation with numpy. this question, however, has nothing to do with numpy. The following code is valid python: var = 0 def count(n): for i in range(n): var += i return var Translating to cython

Re: [Cython] newbie question concerning scope

2009-05-09 Thread Chris Colbert
I tested that and it works, thanks. Chris On Sat, May 9, 2009 at 3:43 AM, Danilo Freitas dsurvi...@gmail.com wrote: As Stefan said... try: cdef double var = 0.0 def count(int n): cdef int i global var for i in range(n): var += i return var I don't

Re: [Cython] ctypes Vs Cython

2009-05-12 Thread Chris Colbert
What follows is my 0.02, and i'm really new at these two libs so keep in mind I could be completely off base. I'm sure someone will jump in and correct my errors. I think the speed is really going to depend on the nature of your calls into the c library. From the code i've examined, there will

Re: [Cython] ctypes Vs Cython

2009-05-12 Thread Chris Colbert
done compiling a C dll. Chris On Wed, May 13, 2009 at 12:31 AM, Chris Colbert sccolb...@gmail.com wrote: What follows is my 0.02, and i'm really new at these two libs so keep in mind I could be completely off base. I'm sure someone will jump in and correct my errors. I think the speed

[Cython] creating for-loops with no gil?

2009-05-13 Thread Chris Colbert
I'm trying to test writing extensions that release the gil. This simple example is failing cython compilation with errors stating that the count() function requires the gil. Can anyone point me in the right direction? Thanks, Chris # code ## cdef double count(int n) nogil:

Re: [Cython] creating for-loops with no gil?

2009-05-13 Thread Chris Colbert
thanks On Wed, May 13, 2009 at 11:48 AM, Dag Sverre Seljebotn da...@student.matnat.uio.no wrote: Chris Colbert wrote: I'm trying to test writing extensions that release the gil. This simple example is failing cython compilation with errors stating that the count() function requires

Re: [Cython] creating for-loops with no gil?

2009-05-13 Thread Chris Colbert
the gil, and thus waits for count() to return. How do I work this so that I can run a c-function outside the gil and thus make use of the multi-cores on my machine? Thanks! Chris On Wed, May 13, 2009 at 11:58 AM, Chris Colbert sccolb...@gmail.com wrote: thanks On Wed, May 13, 2009 at 11:48 AM

Re: [Cython] creating for-loops with no gil?

2009-05-13 Thread Chris Colbert
Excellent! that did the trick! Thanks Dag! Chris On Wed, May 13, 2009 at 12:16 PM, Dag Sverre Seljebotn da...@student.matnat.uio.no wrote: Chris Colbert wrote: alright i made the change and here is the code: cdef double count(int n) nogil: cdef int i, j, k cdef double out

Re: [Cython] ctypes Vs Cython

2009-05-13 Thread Chris Colbert
so my intitial guess that the problem was with my inability to properly build a dll was correct. After reading (partially) the gcc manual on compiling optimizations i get the following result: Starting Threads no GIL cython: Value: 1999000.00 Time: 8.076570 s no GIL ctypes: Value:

Re: [Cython] help...cython code optimisation

2009-05-14 Thread Chris Colbert
as Dag said, don't use numpy to calculate the trig functions, and don't pass a numpy array as the argument function. Pass 3 floats instead. On Thu, May 14, 2009 at 11:25 AM, Dag Sverre Seljebotn da...@student.matnat.uio.no wrote: OUARDA MEHDI wrote: and here my optimised function from

[Cython] interfacing with OpenCV?

2009-05-17 Thread Chris Colbert
How would I go about interfacing with OpenCV data types in cython? I've read the wiki on interfacing with external C code but didn't fully follow. I'm currently using a ctypes wrapper for OpenCV from python and doing some manipulation there, but I would like to chain together a bunch of

Re: [Cython] interfacing with OpenCV?

2009-05-18 Thread Chris Colbert
You can probably skip the write my functions in a pure C source file step and write them directly in Cython. - Robert i tried doing that today and was running into boat loads of trouble resolving the IplImage data type and header dependencies. This is actually turning out to be quite

Re: [Cython] interfacing with OpenCV?

2009-05-18 Thread Chris Colbert
This error seems like you're not linking to the python library. I would recommend using distutils to compile your files. Can you compile the Cython file print hello This is totally doable from Cython. I can compile and use cython modules that don't depend on external c libraries with

Re: [Cython] interfacing with OpenCV?

2009-05-18 Thread Chris Colbert
On Mon, May 18, 2009 at 7:30 PM, Chris Colbert sccolb...@gmail.com wrote: This error seems like you're not linking to the python library. I would recommend using distutils to compile your files. Can you compile the Cython file print hello This is totally doable from Cython. I can

Re: [Cython] interfacing with OpenCV?

2009-05-18 Thread Chris Colbert
Hoyt, All functions, even external ones, that can be run without the gil need the nogil decorator on the end or cython assumes it needs the gil. E.g. cdef extern from highgui.h: cdef IplImage* cvLoadImage(char* file, int iscolor) nogil cdef int cvNamedWindow(char* name, int

Re: [Cython] interfacing with OpenCV?

2009-05-18 Thread Chris Colbert
yet again: for various reasons, I would like to use both the ctypes wrapper and cython in same program. Specifically I have a ctypes instance of an OpenCV image. I pass the pointer of this image to a cython function which returns a pointer to a new image. I need to get this pointer back into

[Cython] fundamentals question

2009-05-19 Thread Chris Colbert
I think i'm starting to wrap my head around all of this, but I have a question about expose a C data type to python. I'm interfacing with the OpenCV library whose fundamental data structure is an IplImage. Most of the functional code passes around pointers to these types and can do this in cython

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
this message got sent before it was finished. At any rate, am I on the right track here? I'll need a way, at the very least to expose the data buffer of the image to python so I can display on the screen via wxPython. Chris On Tue, May 19, 2009 at 11:29 AM, Chris Colbert sccolb...@gmail.com

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
Do I need to worry about python garbage collecting what I reference through my IplImage*. i.e. when i create my images on the c-level, I alone am responsible for freeing that space when no longer needed correct? Chris ___ Cython-dev mailing list

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
, Lisandro Dalcin dalc...@gmail.com wrote: On Tue, May 19, 2009 at 12:54 PM, Chris Colbert sccolb...@gmail.com wrote: Do I need to worry about python garbage collecting what I reference through my IplImage*. i.e. when i create my images on the c-level, I alone am responsible for freeing

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
how do a pass a pointer to a C datatype to my python extension type constructor? I have the following in my code: in a cdef extern from .h block ## struct _IplImage: filler ctypedef _IplImage IplImage ## extension type declaration ### cdef class PyIplImage: cdef

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
What you can do is allow it to pass in a char* (bytes) object with a length, have a cdef set method, use opaque object pointer wrappers (there was a previous thread about this). i'm not sure I understand what your saying with this ^^^ You could also make a function def

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
...@math.washington.edu wrote: On May 19, 2009, at 2:02 PM, Chris Colbert wrote: What you can do is allow it to pass in a char* (bytes) object with a length, have a cdef set method, use opaque object pointer wrappers (there was a previous thread about this). i'm not sure I understand what your

Re: [Cython] interfacing with OpenCV?

2009-05-19 Thread Chris Colbert
Once you get used to code Cython, and assuming you have some C/C++ background, I bet you will stop using ctypes ;-) .. I think you are right :). In an afternoon, I've got a decent amount of what I need wrapped :) Cheers! Chris ___ Cython-dev

[Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
I know that Cython does an implicit conversion from char* to Python string, but do I need to somehow specify the length of the string? I ask because I have a data buffer of known size (7854000 bytes uint8) but when i pass the pointer to that buffer into python, my string length is only 4617. this

Re: [Cython] fundamentals question

2009-05-19 Thread Chris Colbert
sources... On Tue, May 19, 2009 at 6:22 PM, Chris Colbert sccolb...@gmail.com wrote: True, but it seems a little off to programatically set every attribute one by one every time i create an instance of that type. Is it not recommended to declare a property for every attribute I want

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
Lisandro, Once again, thank you! I think I finally have a tricky question for you now however: I have the OpenCV IplImage class wrapped as so: cdef class IplImage: cdef c_cxcore.IplImage* thisptr #Convienience Functions def show(self): #

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
Any chance that cvQueryFrame() returns an image that you should not free?? that's exactly it (i feel really dumb for having missed it) the first img is likely garbage-collected. Perhaps your Image.__dealloc__ is not doing the right thing in this case? would you suggest setting a private

[Cython] trouble splitting extension type into definition and implementation files

2009-05-20 Thread Chris Colbert
Hi, I have this definition file: cy_cvtypes.pxd # cimport c_cxcore cimport c_highgui cdef class IplImage: cdef c_cxcore.IplImage* thisptr cdef int needs_free ### and the corresponding implementation: cy_cvtypes.pxy ## cimport c_cxcore

Re: [Cython] trouble splitting extension type into definition and implementation files

2009-05-20 Thread Chris Colbert
Ok, so compiling each .pyx file into an individual .pyd worked. Is there a way to properly compile everything into a single .pyd, or should I create a dummy module at the end that imports each individual module when called from python? Chris ___

Re: [Cython] trouble splitting extension type into definition and implementation files

2009-05-21 Thread Chris Colbert
compiled and built into a single .pyd Is that possible? Chris On Wed, May 20, 2009 at 8:35 PM, Greg Ewing greg.ew...@canterbury.ac.nzwrote: Chris Colbert wrote: Is there a way to properly compile everything into a single .pyd, You can use include statements to split a .pyx into multiple files

[Cython] nesting a union or struct within a struct?

2009-05-21 Thread Chris Colbert
Hi, I'm trying to write a wrapper for a C library. The C header from which I am making declaration has this: struct Foo { int blah; union { int Bar; } data; } can this be wrapped in Cython? I've tried: cdef extern from c.h: ctypedef struct Foo:

[Cython] how to pass opaque pointers to functions?

2009-05-21 Thread Chris Colbert
I have certain functions that should accept types of IplImage or CvMat I have the two types declared as inheriting from a generic CvArr as such cdef class CvArr: cdef void* thisptr cdef class IplImage(CvArr): . cdef class CvMat(CvArr): and a function declared like

Re: [Cython] how to pass opaque pointers to functions?

2009-05-21 Thread Chris Colbert
, casting, or void pointers I would greatly appreciate any insight one could give.. Thanks and Cheers! Chris On Thu, May 21, 2009 at 7:05 PM, Chris Colbert sccolb...@gmail.com wrote: I have certain functions that should accept types of IplImage or CvMat I have the two types declared

Re: [Cython] how to pass opaque pointers to functions?

2009-05-21 Thread Chris Colbert
c_CvArr*self.image cdef class CvMat(CvArr): cdef c_CvMat *cvmat def c_CvArr* handle(self): return c_CvArr*self.cvmat Mmm... just a use case for cdef properties managed by calling get/setters in the vtable? On Thu, May 21, 2009 at 9:16 PM, Chris Colbert sccolb...@gmail.com wrote

Re: [Cython] how to pass opaque pointers to functions?

2009-05-21 Thread Chris Colbert
so if I have: cdef class IplImage: cdef c_lib.IplImage* thisptr cdef class CvMat: cdef c_lib.CvMat* thisptr then I can just do this? def exposedPythonFunc(image): where image can be an IplImage or CvMat c_lib.cFunction(image.thisptr) since I know thisptr exists

Re: [Cython] how to pass opaque pointers to functions?

2009-05-21 Thread Chris Colbert
lol, OK thanks! Just for my own education which parts of this will translate to C and which will remain Python after Cython compilation? Chris Worse: def exposedPythonFunc(image): if isinstance(image, IplImage): c_lib.cFunction((IplImageimage).thisptr) elif

Re: [Cython] how to pass opaque pointers to functions?

2009-05-22 Thread Chris Colbert
Ok, I get what your saying. that's a good idea and I think it's a little cleaner than casting during the call. Thanks! Chris On Fri, May 22, 2009 at 10:17 AM, Lisandro Dalcin dalc...@gmail.com wrote: On Fri, May 22, 2009 at 1:49 AM, Chris Colbert sccolb...@gmail.com wrote: is 'handle

Re: [Cython] how to pass opaque pointers to functions?

2009-05-22 Thread Chris Colbert
well, i tried your way Lisandro, and it compiled fine, but upon importing the module, it raised an error along the lines of it appears IplImage is not of the right type. Dag's method works, but I'm still gonna try to find something cleaner. Chris On Fri, May 22, 2009 at 11:05 AM, Chris Colbert

Re: [Cython] how to pass opaque pointers to functions?

2009-05-22 Thread Chris Colbert
, May 22, 2009 at 11:05 AM, Chris Colbert sccolb...@gmail.comwrote: Ok, I get what your saying. that's a good idea and I think it's a little cleaner than casting during the call. Thanks! Chris On Fri, May 22, 2009 at 10:17 AM, Lisandro Dalcin dalc...@gmail.comwrote: On Fri, May 22, 2009

Re: [Cython] how to pass opaque pointers to functions?

2009-05-22 Thread Chris Colbert
alright I figured it out. Lisandro, your method worked perfect. the problem was in my function prototype in the .pxd file. I had to change it to this (fixed the argument types): /* .pxd ***/ cimport c_cxcore cimport c_highgui cdef class CvArr: cdef c_cxcore.CvArr*

Re: [Cython] how to pass opaque pointers to functions?

2009-05-22 Thread Chris Colbert
cdef c_cxcore.CvArr* handle(IplImage) /* .pxy */ cdef class CvArr: cdef c_cxcore.CvArr* handle(self): return self.dummyptr On Fri, May 22, 2009 at 12:20 PM, Chris Colbert sccolb...@gmail.com wrote: alright I figured it out. Lisandro, your method

[Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-26 Thread Chris Colbert
So I'm wrapping the OpenCV library in Cython and its coming along quite nicely (thanks to everyone here for getting me up to speed!), but today I've run across a strange issue where a wrapped function fails for certain values of integer arguments, but a pure c implementation testing the same thing

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-27 Thread Chris Colbert
for that function and I cant see anything wrong. You have any ideas I could try? Thanks! Chris On Wed, May 27, 2009 at 10:49 AM, Lisandro Dalcin dalc...@gmail.com wrote: On Wed, May 27, 2009 at 11:36 AM, Chris Colbert sccolb...@gmail.com wrote: sometimes the docs are a bit dated

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-27 Thread Chris Colbert
: On Wed, May 27, 2009 at 3:09 PM, Chris Colbert sccolb...@gmail.com wrote: Lisandro, Unfortunately, I'm on a windows machine and thus can't use valgrind. Wow... Well, not in a good position to help you... Anyway, Did you build OpenCV with EXACTLY the same compiler your installed Python

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-27 Thread Chris Colbert
Dag, I've listed the code below and added the memory cleanup to the Cython file. Behavior is the same. #---the pure C code which doesnt crash---# #include highgui.h #include cv.h #include cxcore.h #include cxtypes.h int main(void) { IplImage* img, *img2; img =

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-27 Thread Chris Colbert
I think I'm starting to narrow it down. I made the following python extension module by hand and it works. I can pass any value (0, 1, 2, or 3) to the function exttest.test() in python and they all work properly. #- exttest.c -# #include Python.h #include

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-27 Thread Chris Colbert
I should note in the last code example, I manually change the integer and the recompile. i.e. the python arguments passed to the function are irrelevant. Chris On Thu, May 28, 2009 at 1:00 AM, Chris Colbert sccolb...@gmail.com wrote: I think I'm starting to narrow it down. I made

Re: [Cython] python code optimization...misc

2009-05-28 Thread Chris Colbert
Many of the numpy functions (dot in particular) already execute as compiled C extensions. Functions that execute mostly in Python (histogramdd for example) can see a speedup by using Cython. That said, you would be better off building numpy from source against lapack and atlas, this will give you

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-28 Thread Chris Colbert
Alright, I fixed the problem by hacking the Cython generated C file. I removed everything in the IF clause that determined whether the Python Arguments were keyword argument or not and left only the PyTuple_GET_ITEM statements. I then changed the PyMethodDef line like so: old entry:

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-28 Thread Chris Colbert
Bradshaw rober...@math.washington.edu wrote: On May 28, 2009, at 9:16 AM, Chris Colbert wrote: Alright, I fixed the problem by hacking the Cython generated C file. I removed everything in the IF clause that determined whether the Python Arguments were keyword argument or not and left only

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-05-28 Thread Chris Colbert
Just to clarify, I've never used keyword arguments with this function. Chris On Thu, May 28, 2009 at 10:46 PM, Chris Colbert sccolb...@gmail.com wrote: Robert, That's correct. Of course I had to remove all the checks related to Keyword args in the body of the function before it would execute

Re: [Cython] Creating python bindings for C library using Cython

2009-06-01 Thread Chris Colbert
python strings are automagically converted to char* by cython. You can also look at a wrapper i'm building for the OpenCV library. cython-opencv at google code. Chris On Mon, Jun 1, 2009 at 6:38 AM, Amit Sethi amit.pureene...@gmail.comwrote: hi , I guess this needs to go on cython-users but

Re: [Cython] Creating python bindings for C library using Cython

2009-06-01 Thread Chris Colbert
I never mind being corrected/updated/put-in-my-place with such a great answer. So there you have it :) Cheers! On Mon, Jun 1, 2009 at 3:09 PM, Dag Sverre Seljebotn da...@student.matnat.uio.no wrote: Chris Colbert wrote: python strings are automagically converted to char* by cython. I'll

Re: [Cython] Syntax for declaring Cython class variables

2009-06-02 Thread Chris Colbert
to code like this: # foo.pyx cdef int Foo_count = 0 cdef class Foo: def __cinit__(self): global Foo_count Foo_count += 1 On Tue, Jun 2, 2009 at 1:36 PM, Chris Colbert sccolb...@gmail.com wrote: you have to declare the attribute as public. http://docs.cython.org

Re: [Cython] How to build Cython extensions for Windows under Linux or OSX

2009-06-10 Thread Chris Colbert
I think because he was cross compiling these extensions for windows while working in MacOSX or Linux On Wed, Jun 10, 2009 at 10:30 AM, Lisandro Dalcindalc...@gmail.com wrote: Just a couple of comments/questions regarding Windows, an OS I really do not know well :-)... 1) Why did you need

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-06-29 Thread Chris Colbert
Just to be sure... if you look at all the OpenCV headers, can you see __stdcall somewhere? here's the results of a grep: brucewa...@broo:/usr/local/include/opencv$ grep -ir __stdcall * cxtypes.h:#define CV_STDCALL __stdcall highgui.h:#define CV_STDCALL __stdcall ml.h:#define

Re: [Cython] having a weird issue with wrapped function failing in only certain cases

2009-06-29 Thread Chris Colbert
how about both? :) brucewa...@broo:/usr/local/include/opencv$ grep -ir CV_STDCALL * cxcore.h:typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader) cxcore.h:typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int); cxcore.h:typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int);

[Cython] how would I wrap something like this in a .pxd file

2009-07-01 Thread Chris Colbert
In wrapping a C library, I come across many #define statements that I need to use elsewhere. When they simply define a constant, I use an anonymous enum and all is well. But how would I wrap something like this that shown up in a header file that i'm cdef extern'ing from: #define

Re: [Cython] how would I wrap something like this in a .pxd file

2009-07-01 Thread Chris Colbert
Thanks Lisandro, I may just end up declaring each struct like this with a 'pass' and then implementing the fields on the python side (this is how ctypes does it) Cheers! On Wed, Jul 1, 2009 at 3:01 PM, Lisandro Dalcindalc...@gmail.com wrote: On Wed, Jul 1, 2009 at 3:24 PM, Chris

Re: [Cython] how would I wrap something like this in a .pxd file

2009-07-01 Thread Chris Colbert
what about functions defined in a macro where i wont know the return type in advance? such as: #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \ (assert((edge)-vtx[0] == (vertex) || (edge)-vtx[1] == (vertex)), \ (edge)-next[(edge)-vtx[1] == (vertex)])

Re: [Cython] how to allow access to data in a C array?

2009-07-02 Thread Chris Colbert
Thanks Stefan! On Thu, Jul 2, 2009 at 12:32 AM, Stefan Behnelstefan...@behnel.de wrote: Hi, Chris Colbert wrote: I'm thinking this may be what the new array type is for, but i'm not sure. say I have a C struct which I wrap as a class: #mycfile.h struct Foo {        int* data[32

Re: [Cython] On the topic of wrapper classes

2009-07-25 Thread Chris Colbert
+1 On Fri, Jul 24, 2009 at 11:21 AM, Lisandro Dalcindalc...@gmail.com wrote: On Fri, Jul 24, 2009 at 8:53 AM, Robert Bradshawrober...@math.washington.edu wrote: This feels a lot like C++ operator overloading... I'm not a fan of _as_parameter_, but maybe an as foo_t kind of attribute that it

Re: [Cython] Call for hosting of users' mailing list

2009-07-29 Thread Chris Colbert
Well, I have a dreamhost server just sitting around. It only hosts my blog (which is mostly non-existant), but I have ample bandwidth and space. It is however, on a shared box so the performance isnt stellar. The Cython list seems to be lightweight however, so if you want to give it a try (and

[Cython] citing Cython

2009-08-24 Thread Chris Colbert
I'm working on a paper and need to include a citation for Cython, is there a preferred citation, or should I use this entry I found in the sage archives? @manual{cython, Author = {Stefan Behnel, Robert Bradshaw, and Dag Sverre Seljebotn }, Title = {Cython: C-Extensions for Python}, note =

Re: [Cython] citing Cython

2009-08-24 Thread Chris Colbert
}, url= {http://www.cython.org}, year = 2009 } On Mon, Aug 24, 2009 at 4:13 PM, Robert Bradshawrober...@math.washington.edu wrote: On Mon, 24 Aug 2009, Chris Colbert wrote: I'm working on a paper  and need to include a citation for Cython, is there a preferred citation

Re: [Cython] Linking error - 64 bit problem?

2009-08-25 Thread Chris Colbert
I'm no expert, but I would type your input arguments and use the float versions of the math.h functions since your dtypes are floats. On Tue, Aug 25, 2009 at 11:19 AM, Adam Ginsburgadam.ginsb...@colorado.edu wrote: From: Robert Bradshaw rober...@math.washington.edu Subject: Re: [Cython] Linking

Re: [Cython] scipy'09 cython BoF

2009-08-25 Thread Chris Colbert
with regards to replacing weave, would it be possible to just use a function decorator? i.e something like: @cythonize def trivial_func(int i): cdef int j j = i + 1 return j I particularly like the thought of this over weave so that I don't have to switch gears in brain from

Re: [Cython] scipy'09 cython BoF

2009-08-25 Thread Chris Colbert
wait, scratch that idea, that would throw python syntax errors all over the place. I was too quick on the send button... On Tue, Aug 25, 2009 at 5:49 PM, Chris Colbertsccolb...@gmail.com wrote: with regards to replacing weave, would it be possible to just use a function decorator? i.e

Re: [Cython] init function not defined?

2009-09-29 Thread Chris Colbert
Ah, I'm having a stupid day. I need to use the same name for the .so as the source file. Doh! Chris On Tue, Sep 29, 2009 at 3:15 PM, Chris Colbert sccolb...@gmail.com wrote: I'm getting the following error when import a simple cython extension module: ImportError: dynamic module does

[Cython] init function not defined?

2009-09-29 Thread Chris Colbert
I'm getting the following error when import a simple cython extension module: ImportError: dynamic module does not define init function (initcythonsuperquadricfit) the following is how i built the module... doesnt seem there is a problem: brucewa...@broo:~/Desktop/object_reconstruction$ cython

[Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
Normally, when I'm hitting a road block with numpy performance, I port that section to cython and typically see an order of magnitude increase in speed. (this is without disabling bounds checking) In my current case, I'm seeing a slowdown of 2x (with boundschecking disabled) and I'm pretty sure

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
Dag, HTML was too big to attach to the list email, so I sent it to your personal email. Thanks for taking a look! Chris On Tue, Sep 29, 2009 at 4:42 PM, Chris Colbert sccolb...@gmail.com wrote: Dag, Html is attached, all that garbage at the bottom in commented out via a docstring (i

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
-fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/local/lib/python2.6/dist-packages/numpy/core/include/numpy -I/usr/include/python2.6 -o superquadricfit.so superquadricfit.c they both yield the same result On Tue, Sep 29, 2009 at 4:46 PM, Chris Colbert sccolb...@gmail.com wrote: Dag, HTML

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
or better yet, which pow function is numpy using? On Tue, Sep 29, 2009 at 6:21 PM, Chris Colbert sccolb...@gmail.com wrote: No, the python ** gets translated to a pow statement by cython. I think the issue is that for some reason, i'm getting stuck in the gcc slow pow function if i let

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
per loop over 6x improvement just by avoid a few measly pow statements... anyone know why i'm stuck in slowpow? On Tue, Sep 29, 2009 at 6:15 PM, Sturla Molden stu...@molden.no wrote: Sturla Molden skrev: Chris Colbert skrev: and within that loop it is these statements that take the bulk

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
tried that already... no difference... On Tue, Sep 29, 2009 at 6:33 PM, Robert Kern robert.k...@gmail.com wrote: On 2009-09-29 11:21 AM, Chris Colbert wrote: or better yet, which pow function is numpy using? double pow(double, double) from math.h . -- Robert Kern I have come

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
Molden stu...@molden.no wrote: Chris Colbert skrev: No, the python ** gets translated to a pow statement by cython. I think the issue is that for some reason, i'm getting stuck in the gcc slow pow function if i let e2 and e1 be 1 and replace f**2 (which would call pow) with f*f, my

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
. Cheers, Chris On Tue, Sep 29, 2009 at 7:11 PM, Chris Colbert sccolb...@gmail.com wrote: my big issue here is that these two lines of code, are taking more time to execute than the entire function as a pure numpy implementation. And numpy is using the same calls to pow in the background... i

Re: [Cython] some advice on this module regarding performance?

2009-09-29 Thread Chris Colbert
: Chris Colbert skrev: No, the python ** gets translated to a pow statement by cython. I think the issue is that for some reason, i'm getting stuck in the gcc slow pow function if i let e2 and e1 be 1 and replace f**2 (which would call pow) with f*f, my execution time drops

Re: [Cython] some advice on this module regarding performance?

2009-09-30 Thread Chris Colbert
, 2009, at 12:03 PM, Chris Colbert wrote: Actually, yes. The exponents are done specifically in that way to force the sign of the end value. I suppose i could just call abs() on it though I'm sure that abs would be faster than pow, though it's not the squaring that's expensive

[Cython] Is it possible to link to libraries at runtime with Cython

2009-10-07 Thread Chris Colbert
using something similar to ctypes dlopen? I would like to be able to create a wrapper for a library that can built on the client machine without the necessity of the target libraries being present. Then, upon import of the library, the library would check for the presence of the .so's and raise

Re: [Cython] Is it possible to link to libraries at runtime with Cython

2009-10-07 Thread Chris Colbert
Sverre Seljebotn da...@student.matnat.uio.no wrote: Chris Colbert wrote: using something similar to ctypes dlopen? I would like to be able to create a wrapper for a library that can built on the client machine without the necessity of the target libraries being present. Consider having

Re: [Cython] trouble getting a function pointer from ctypes to play nice with Cython...

2009-10-08 Thread Chris Colbert
cytypestest.c $python import cytypestest 1255008817 On Thu, Oct 8, 2009 at 3:05 PM, Chris Colbert sccolb...@gmail.com wrote: Ok, tried both of those methods, and they pass cython compilation, but then I get this error from gcc: brucewa...@broo:~/Desktop$ gcc -shared -pthread -fPIC -fwrapv -O2

[Cython] How do I compare the shape of two numpy arrays for equality?

2009-10-08 Thread Chris Colbert
Since I have a cimport numpy as np at the top of my cython file, array1.shape == array2.shape is only true if array1 IS array2 because .shape return the npy_intp* pointer to the shape array. Is there a way for me check if the values in the shape array are equal (ala python) without having to

Re: [Cython] How do I compare the shape of two numpy arrays for equality?

2009-10-09 Thread Chris Colbert
Fantastic! Thanks! On Fri, Oct 9, 2009 at 8:17 AM, David Warde-Farley d...@cs.toronto.edu wrote: On 8-Oct-09, at 7:38 PM, Chris Colbert wrote: Since I have a cimport numpy as np at the top of my cython file, array1.shape == array2.shape is only true if array1 IS array2 because .shape

[Cython] are numpy arrays automatically passed by reference?

2009-10-10 Thread Chris Colbert
for example if I have something like this: cimport numpy as np cdef void foo(np.ndarray arr): do stuff def bar(np.ndarray arr): foo(arr) is arr getting passed by value or by reference? When I wrap other C libraries, I have to do a foo(cobject) to pass cobject by

[Cython] the cython.org site appears to be down..

2009-10-10 Thread Chris Colbert
I can't connect from germany. just an FYI Cheers, Chris ___ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev

[Cython] would someone mind pointing out the mistake i'm making, i just can't see it

2009-10-12 Thread Chris Colbert
so I have this function: (the print statements are just for debugging) cdef np.npy_intp* clone_array_shape(np.ndarray arr): # the proper way to do this would be to use malloc # to create a new npy_intp* array of the proper size # but then we would have to track it and make a call to

Re: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it

2009-10-12 Thread Chris Colbert
Ah, that would explain it. Thanks! On Mon, Oct 12, 2009 at 10:11 PM, Sturla Molden stu...@molden.no wrote: Chris Colbert skrev: i cant for the life of me, figure out where the error is coming in? Does  anyone see it? You are returning a pointer to local arrays. The pointer is invalid when

Re: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it

2009-10-12 Thread Chris Colbert
Ok, I gotcha. My lack of formal programming training is on display today :) Thanks Sturla and Robert! Chris On Mon, Oct 12, 2009 at 10:12 PM, Robert Kern robert.k...@gmail.com wrote: On 2009-10-12 15:00 PM, Chris Colbert wrote: so I have this function: (the print statements are just

[Cython] bug in numpy.pxd

2009-10-23 Thread Chris Colbert
line 317 in numpy.pxd for Cython 11.3 bint PyArray_ISISCONTIGUOUS(ndarray m) double IS in that definition. Cheers, Chris ___ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev

Re: [Cython] npy_intp in numpy.pxd

2009-10-27 Thread Chris Colbert
On Tue, Oct 27, 2009 at 10:16 PM, Sturla Molden stu...@molden.no wrote: Stéfan van der Walt skrev: As a side note, it may be safer to use the definitions of npy_intp and npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t.  In some earlier versions of Python (e.g., 2.4),

Re: [Cython] modify docstrings at run or compile time

2009-10-30 Thread Chris Colbert
#-- # foo.py #-- from decorator import docdeco @docdeco('''docstring goes here''') def bar(): pass On Thu, Oct 29, 2009 at 1:32 PM, Chris Colbert sccolb...@gmail.com wrote: Hi, I didn't get a response on Cython-users, so i thought I might try here. I tried modifying

Re: [Cython] Releasing the gil in cdef without using cython.cdivision

2009-11-09 Thread Chris Colbert
What was the rationality behind having to explicitly declare C division, versus explicitly declaring python division? Just curious. Cheers! On Mon, Nov 9, 2009 at 5:40 PM, Dag Sverre Seljebotn da...@student.matnat.uio.no wrote: Hi all, Why is it necessary to decorate a pure cdef with

Re: [Cython] Setting cython.cdivision(True) globally

2009-11-09 Thread Chris Colbert
is there an error in that table: ''' cdivision True/False Version = 0.12 If set to True, Cython will adjust the remainder and quotient operators C types to match those of Python ints (which differ when the operands have opposite signs) and raise a ZeroDivisionError when the right operand is

Re: [Cython] Setting cython.cdivision(True) globally

2009-11-09 Thread Chris Colbert
I noticed you just changed the version signature too: Version 0.12 Does that mean we can't turn that off in = 0.12, or must we just explicitly declare it? On Mon, Nov 9, 2009 at 7:54 PM, Robert Bradshaw rober...@math.washington.edu wrote: On Nov 9, 2009, at 10:45 AM, Chris Colbert wrote

Re: [Cython] Right way to create numpy arrays using C-API?

2009-11-14 Thread Chris Colbert
AFAIK, you only have to INCREF the dtype. And only for numpy array creation routines that take a dtype object as an argument (they steal a dtype reference, which is why you have to incref it). On Sun, Nov 15, 2009 at 2:09 AM, Matthew Brett matthew.br...@gmail.com wrote: Hi, I've been spending

Re: [Cython] Right way to create numpy arrays using C-API?

2009-11-14 Thread Chris Colbert
AH I see ok. I should have read more carefully (a little late here). When you commented out the INCREF on the datat, did you also comment out PyArray_Set_BASE? If not, that may have been causing the problem. If you set the base without INCREF'ing the data, then numpy will DECREF that data when

Re: [Cython] Right way to create numpy arrays using C-API?

2009-11-14 Thread Chris Colbert
I forgot a disclaimer: This is all to the best of my knowledge. I'm sure one of the awesome Cython devs will jump in and correct me ;) On Sun, Nov 15, 2009 at 3:04 AM, Chris Colbert sccolb...@gmail.com wrote: AH I see ok. I should have read more carefully (a little late here). When you

  1   2   >