Re: [Numpy-discussion] numpy and cython in pure python mode

2009-09-23 Thread Sebastian Haase
Thanks for all the replies !

On Wed, Sep 23, 2009 at 4:55 AM, Dag Sverre Seljebotn
 wrote:
> Robert Kern wrote:
>> On Tue, Sep 22, 2009 at 01:33, Sebastian Haase  wrote:
>>
>>> Hi,
>>> I'm not subscribed to the cython list - hoping enough people would
>>> care to justify my post here:
>>>
> The post might be justified, but it is a question of available knowledge
> as well. I nearly missed this post here. The Cython user list is on:
>
> http://groups.google.com/group/cython-users
>
>>> I know that cython's numpy is still getting better and better over
>>> time, but is it already today possible to have numpy support when
>>> using Cython in "pure python" mode?
>>> I like the idea of being able to develop and debug code "the python
>>> way" -- and then just switching on the cython-overdrive mode.
>>> (Otherwise I have very good experience using C/C++ with appropriate
>>> typemaps, and I don't mind the C syntax)
>>>
>>> I only recently learned about the "pure python" mode on the sympy list
>>> (and at the EuroScipy2009 workshop).
>>> My understanding is that Cython's pure Python mode could be "played"
>>> in two ways:
>>> a) either not having a .pyx-file at all and putting everything into a
>>> py-file (using the "import cython" stuff)
>>> or b) putting only cython specific declaration in to a pyx file having
>>> the same basename as the py-file next to it.
>>>
> That should be a pxd file with the same basename. And I think that mode
> should work. b), that is.

That is really good news !   A short example would be very helpful,
since the "pure python mode" documentation is very sparse. I found
that one wiki page to be very good - but obviously it's not a complete
reference.

>
> Sturla's note on the memory view syntax doesn't apply as that's not in a
> released version of Cython yet, and won't be until 0.12.1 or 0.13. But
> that could be made to support Python mode a).
>
Using an svn version would be fine with me, however the mentioned
syntax (thanks Sturla) looks quite awkward/unnatural.


> Finally there's been some recent discussion on cython-dev about a tool
> which can take a pyx file as input and output pure Python.
This would probably only be a second-to-best solution because it would
effectively double the source code. (However, eventually such a tool
could run behind the scene and import the pyx-converted py file on the
fly -- in which case it would be transparent ...)

>>
>>> One more: there is no way on reload cython-modules (yet),  right ?
>>>
>>
>> Correct. There is no way to reload any extension module.
>>
> This can be worked around (in most situations that arise in practice) by
> compiling the module with a new name each time and importing things from
> it though. Sage already kind of support it (for the %attach feature
> only), and there are patches around for pyximport in Cython that's just
> lacking testing and review. Since pyximport lacks a test suite
> altogether, nobody seems to ever get around to that.
>
I read something like this in the archives, thanks for the update.
Will those patches be applied to svn - even if untested so far... ?



> Dag Sverre

Thanks Dag.

-- Sebastian Haase
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy and cython in pure python mode

2009-09-23 Thread Dag Sverre Seljebotn
Robert Kern wrote:
> On Tue, Sep 22, 2009 at 01:33, Sebastian Haase  wrote:
>   
>> Hi,
>> I'm not subscribed to the cython list - hoping enough people would
>> care to justify my post here:
>> 
The post might be justified, but it is a question of available knowledge 
as well. I nearly missed this post here. The Cython user list is on:

http://groups.google.com/group/cython-users

>> I know that cython's numpy is still getting better and better over
>> time, but is it already today possible to have numpy support when
>> using Cython in "pure python" mode?
>> I like the idea of being able to develop and debug code "the python
>> way" -- and then just switching on the cython-overdrive mode.
>> (Otherwise I have very good experience using C/C++ with appropriate
>> typemaps, and I don't mind the C syntax)
>>
>> I only recently learned about the "pure python" mode on the sympy list
>> (and at the EuroScipy2009 workshop).
>> My understanding is that Cython's pure Python mode could be "played"
>> in two ways:
>> a) either not having a .pyx-file at all and putting everything into a
>> py-file (using the "import cython" stuff)
>> or b) putting only cython specific declaration in to a pyx file having
>> the same basename as the py-file next to it.
>> 
That should be a pxd file with the same basename. And I think that mode 
should work. b), that is.

Sturla's note on the memory view syntax doesn't apply as that's not in a 
released version of Cython yet, and won't be until 0.12.1 or 0.13. But 
that could be made to support Python mode a).

Finally there's been some recent discussion on cython-dev about a tool 
which can take a pyx file as input and output pure Python.
>   
>> One more: there is no way on reload cython-modules (yet),  right ?
>> 
>
> Correct. There is no way to reload any extension module.
>   
This can be worked around (in most situations that arise in practice) by 
compiling the module with a new name each time and importing things from 
it though. Sage already kind of support it (for the %attach feature 
only), and there are patches around for pyximport in Cython that's just 
lacking testing and review. Since pyximport lacks a test suite 
altogether, nobody seems to ever get around to that.

Dag Sverre
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy and cython in pure python mode

2009-09-22 Thread Robert Kern
On Tue, Sep 22, 2009 at 01:33, Sebastian Haase  wrote:
> Hi,
> I'm not subscribed to the cython list - hoping enough people would
> care to justify my post here:
>
> I know that cython's numpy is still getting better and better over
> time, but is it already today possible to have numpy support when
> using Cython in "pure python" mode?
> I like the idea of being able to develop and debug code "the python
> way" -- and then just switching on the cython-overdrive mode.
> (Otherwise I have very good experience using C/C++ with appropriate
> typemaps, and I don't mind the C syntax)
>
> I only recently learned about the "pure python" mode on the sympy list
> (and at the EuroScipy2009 workshop).
> My understanding is that Cython's pure Python mode could be "played"
> in two ways:
> a) either not having a .pyx-file at all and putting everything into a
> py-file (using the "import cython" stuff)
> or b) putting only cython specific declaration in to a pyx file having
> the same basename as the py-file next to it.

I'm pretty sure that you need Cython syntax that is not supported by
the pure-Python mode in order to use numpy arrays effectively.

> One more: there is no way on reload cython-modules (yet),  right ?

Correct. There is no way to reload any extension module.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy and cython in pure python mode

2009-09-22 Thread Sturla Molden
Sebastian Haase skrev:
> I know that cython's numpy is still getting better and better over
> time, but is it already today possible to have numpy support when
> using Cython in "pure python" mode?
>   
I'm not sure. There is this odd memoryview syntax:

import cython
view = cython.int[:,:](my2darray)

print view[3,4] # fast when compiled, according to Sverre



S.M.



___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion