Julien Danjou | 22 Dec 17:17 2009

Re: Embedding and modules

At 1261434878 time_t, Mark Lodato wrote:
> A few months ago, I came up with a semi-working solution but abandoned
> it because I thought it didn't work.  Now that I look at it again, I
> can't figure out why it didn't work.  So, I'll post it here so that
> you all can test it out.  Please let me know if this solves our
> problems; if it does, we can integrate it into Cython.

Nice hack. I reviewed the initial code you're loading into Python, and
that seems totally fair.

Your example works fine also.

Cython needs indeed a "fix" to set properly the module name (an option
flag maybe?), but you are fixing the bugged import of Python in a
elegant manner. :-)

And I suggest to merge that into Cython.

Thanks,
--

-- 
Julien Danjou
// ᐰ <julien <at> danjou.info>   http://julien.danjou.info
// 9A0D 5FD9 EB42 22F6 8974  C95C A462 B51E C2FE E5CD
// And thinking so much differently.
Simo Salminen | 22 Dec 20:07 2009
Picon

Re: Why I cannot coerce python string to char*?

Ok thanks.

> > How this should work? From documenthttp://docs.cython.org/src/tutorial/strings.html
> > I though this should work.
>
> I can't find any reference to "cdef str" in that document.
>

I misunderstood that type str equals to python string (document says
this: cdef char* other_c_string = py_string).

Francisco | 23 Dec 17:46 2009
Picon

Trouble with enum

Hi.

I'm new to cython and I'm having trouble with enums.

I've a pxd file with these lines among others:

cdef extern from "stuff.h":
	ctypedef long LONG64
	ctypedef unsigned long ULONG64
	enum ns1__MediaType_t:
		ST_LOCAL_HARD_DRIVE_ = 0
		ST_USB_DEVICE_ = 1
		ST_FLASH_MEMORY_ = 2
	enum ns1__MediaOperation_t:
		ST_FILE_COPY_ = 0
		ST_FILE_DELETE_ = 1
		ST_FILE_MOVE_ = 2
		ST_FILE_RENAME_ = 3
		ST_FOLDER_COPY_ = 4
		ST_FOLDER_DELETE_ = 5
		ST_FOLDER_MOVE_ = 6
		ST_FOLDER_RENAME_ = 7
	...

and other pyx file with the same name with some class definitions like
this one:

cdef class MediaFile:
	cdef public object FileName, RelativeStartTime, RelativeEndTime,
O_block, D_block, FontFileName
(Continue reading)

Marko Loparic | 24 Dec 01:12 2009
Picon

converting code from pyrex to cython

Hi,

Could someone please give me some advice on cython usage?

(I feel ashamed for asking questions that are probably not too far
from me somewhere in a "fine manual", but I have a strict deadline so
if there is someone willing to give me some hints to accelerate the
process it would be of great help!)

I did some pyrex code about 3 years ago and now I want to rewrite this
code in cython and add some new stuff. I don't know much about cython
yet. My priority is to get a fast code, everything on the C level,
with the exception of some raise commands. The page
http://wiki.cython.org/tutorials/numpy points me to the -a option
providing the html (a wonderful tool to understand what is going on!).
Here are my questions:

1. For every numpy array, my pyrex code checked the type and the size.
I see I can ask cython to do this task for me (directly in the
function argument list). Do you know how I can check the type of an
array of strings? Its dtype is for instance '|S14'  and 14 is also
passed and an int argument to the function. I could do this in the
Python level

if name_array.dtype != '|S%d' % size:
    raise ...

but I would like to know how to do it in the C level.

2. In general I would like to be able to find the type of the C
(Continue reading)

Robert Bradshaw | 27 Dec 06:02 2009

Re: converting code from pyrex to cython

On Dec 23, 2009, at 4:12 PM, Marko Loparic wrote:

> Hi,
>
> Could someone please give me some advice on cython usage?
>
> (I feel ashamed for asking questions that are probably not too far
> from me somewhere in a "fine manual", but I have a strict deadline so
> if there is someone willing to give me some hints to accelerate the
> process it would be of great help!)
>
> I did some pyrex code about 3 years ago and now I want to rewrite this
> code in cython and add some new stuff.

Hopefully you'll just be able to compile it as is, no need to rewrite.

> I don't know much about cython
> yet. My priority is to get a fast code, everything on the C level,
> with the exception of some raise commands. The page
> http://wiki.cython.org/tutorials/numpy points me to the -a option
> providing the html (a wonderful tool to understand what is going on!).
> Here are my questions:
>
> 1. For every numpy array, my pyrex code checked the type and the size.
> I see I can ask cython to do this task for me (directly in the
> function argument list). Do you know how I can check the type of an
> array of strings? Its dtype is for instance '|S14'  and 14 is also
> passed and an int argument to the function. I could do this in the
> Python level
>
(Continue reading)

Robert Bradshaw | 27 Dec 06:10 2009

Re: Trouble with enum

On Dec 23, 2009, at 8:46 AM, Francisco wrote:

> Hi.
>
> I'm new to cython and I'm having trouble with enums.

[...]

> I don't understand why the attribute of type ns1__MediaType can't be
> accessed from Python.
>
> I'll be very pleased if anyone can explain me what am I doing wrong.
>
> Thankyou in advence.

This is a bug

http://trac.cython.org/cython_trac/ticket/471

We should probably allow reading/assignment as if it was an int-- 
should be an easy fix.

- Robert

André | 28 Dec 17:20 2009
Picon

problem with profiling tutorial

I tried the profiling tutorial example at
http://docs.cython.org/src/tutorial/profiling_tutorial.html but it
generated multiple exceptions like the following:

Exception exceptions.ZeroDivisionError: 'float division' in
'calc_pi.recip_square' ignored

I *think* I understand the cause of these exceptions but I just want
to make sure - as I don't program in C - only in Python.

If I change the value of the argument of approx_pi to 2**16-1,  no
exception is generated.  If I choose 2**16 instead, then one exception
is generated.  Looking inside recip_square(), it has a division of a
square of an integer.   Could it be that, in C, 2**32 (on a 32 bit
machine) becomes 0?    (If so, I would guess that the person who wrote
the tutorial uses a 64-bit computer, which would explain why no such
Exception was noted in the tutorial.)

Any confirmation that this is what is going on, or pointers to the
correct explanation if I am wrong, would be appreciated.

André

Rekveld | 28 Dec 18:49 2009
Picon

Buffer types only allowed as function local variables

Hi,

I was getting 'Buffer types only allowed as function local variables'
errors when I tried to declare my array in the class, rather than in
the method.
I found this question and reply for the same problem:
<http://codespeak.net/pipermail/cython-dev/2009-April/005214.html>

but the last workaround that was mentioned I do not understand well
enough.

Is there sombody who can write the cython code that would do the
following so that I can understand it ?
I think I understand what it means, but I don't know how to do it in
Cython.

(start quote)

 I'm afraid the only solution right now is
to store it as numpy.ndarray and access the data field (i.e.
self.data.data), casted to numpy.float_t*. You must then make sure
you
work with a contiguous array:

     if not data.flags['C_CONTIGUOUS']:
         data = data.copy()
     self.data = data

(end quote)

(Continue reading)

SirVer | 29 Dec 13:35 2009
Picon
Picon

Re: problem with profiling tutorial

André,

that is precisely the case: I've written the tutorial on my CoreDuo
Mac with 64 bit.

Cheers,
Holger

On 28 Dez., 17:20, André <andre.robe... <at> gmail.com> wrote:
> I tried the profiling tutorial example
athttp://docs.cython.org/src/tutorial/profiling_tutorial.htmlbut it
> generated multiple exceptions like the following:
>
> Exception exceptions.ZeroDivisionError: 'float division' in
> 'calc_pi.recip_square' ignored
>
> I *think* I understand the cause of these exceptions but I just want
> to make sure - as I don't program in C - only in Python.
>
> If I change the value of the argument of approx_pi to 2**16-1,  no
> exception is generated.  If I choose 2**16 instead, then one exception
> is generated.  Looking inside recip_square(), it has a division of a
> square of an integer.   Could it be that, in C, 2**32 (on a 32 bit
> machine) becomes 0?    (If so, I would guess that the person who wrote
> the tutorial uses a 64-bit computer, which would explain why no such
> Exception was noted in the tutorial.)
>
> Any confirmation that this is what is going on, or pointers to the
> correct explanation if I am wrong, would be appreciated.
>
(Continue reading)


Gmane