[Cython] How to define C-consts in python module scope

2011-07-18 Thread Vitja Makarov
cdef enum:
 EV_READ  = 1
 EV_WRITE = 2

Is there a way to put this constants into module dict?
I want to access this constants from pure python code, I tried this way:

globals()['EV_READ'] = EV_READ
globals()['EV_WRITE'] = EV_WRITE

But I don't like it, is there any other way?

-- 
vitja.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Any news from the IronPython port?

2011-07-18 Thread Jason McCampbell
Hi Stefan,

Definitely not buried for good, though we haven't made a lot of changes
recently. :)  We used it for porting SciPy to .NET and re-wrote a large
number of the SciPy C module implementations in Cython.  It is generally
stable and produces good code within the set of features that were needed
(by no means has feature parity with the CPython version).

In general, I have been quite happy with the results given that it is
possible to generate interfaces for two Python implementations from a single
source.  Of course, it is not free.  One can, in general, not take a
NumPy-heavy Cython file and just generate source code for IronPython.
 Because IronPython and NumPy for .NET do not share any common C APIs we had
to wrap some of the APIs and in other cases switch to using Python notation
and/or call the new Python-independent NumPy core API (present only in the
refactored version).

Overall, I think it's a good start and holds some promise for generating
re-targetable native wrappings, but there is still plenty of work to do to
make it more accessible.

Regards,
Jason


On Mon, Jul 18, 2011 at 1:40 AM, Stefan Behnel  wrote:

> Hi,
>
> subject says it all. The port to IronPython appears to run completely in
> stealth mode, so I wonder if it has become any usable yet, or if the project
> was already swept under the carpet and buried for good.
>
> Stefan
> __**_
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/**mailman/listinfo/cython-devel
>



-- 
*Jason McCampbell*
Enthought, Inc.
512.536.1057 (Office)
512.850.6069 (Mobile)
jmccampb...@enthought.com
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Any news from the IronPython port?

2011-07-18 Thread Matthew Brett
Hi,

On Mon, Jul 18, 2011 at 3:45 PM, Jason McCampbell
 wrote:
> Hi Stefan,
> Definitely not buried for good, though we haven't made a lot of changes
> recently. :)  We used it for porting SciPy to .NET and re-wrote a large
> number of the SciPy C module implementations in Cython.

That sounds very useful.   Can these re-writings be proposed as merges
into the scipy tree?   Did you have time to benchmark the
implementations?

Thanks a lot,

Matthew
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Lisandro Dalcin
On 18 July 2011 06:38, Vitja Makarov  wrote:
> cdef enum:
>     EV_READ  = 1
>     EV_WRITE = 2
>
> Is there a way to put this constants into module dict?
> I want to access this constants from pure python code, I tried this way:
>
> globals()['EV_READ'] = EV_READ
> globals()['EV_WRITE'] = EV_WRITE
>
> But I don't like it, is there any other way?
>

cdef public enum:
EV_READ  = 1
EV_WRITE = 2

However, I do not like it, because I would like to use "public" for
other meaning (API generation). Also note that using "public" will
trigger the generation of a header file.

Perhaps we should support "cpdef enum: ..."


-- 
Lisandro Dalcin
---
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Chris Colbert
On Mon, Jul 18, 2011 at 12:14 PM, Lisandro Dalcin  wrote:

> On 18 July 2011 06:38, Vitja Makarov  wrote:
> > cdef enum:
> > EV_READ  = 1
> > EV_WRITE = 2
> >
> > Is there a way to put this constants into module dict?
> > I want to access this constants from pure python code, I tried this way:
> >
> > globals()['EV_READ'] = EV_READ
> > globals()['EV_WRITE'] = EV_WRITE
> >
> > But I don't like it, is there any other way?
> >
>
> cdef public enum:
> EV_READ  = 1
>EV_WRITE = 2
>
> However, I do not like it, because I would like to use "public" for
> other meaning (API generation). Also note that using "public" will
> trigger the generation of a header file.
>
> Perhaps we should support "cpdef enum: ..."
>
>
>
cpdef enum would be awesome.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Vitja Makarov
2011/7/18 Lisandro Dalcin :
> On 18 July 2011 06:38, Vitja Makarov  wrote:
>> cdef enum:
>>     EV_READ  = 1
>>     EV_WRITE = 2
>>
>> Is there a way to put this constants into module dict?
>> I want to access this constants from pure python code, I tried this way:
>>
>> globals()['EV_READ'] = EV_READ
>> globals()['EV_WRITE'] = EV_WRITE
>>
>> But I don't like it, is there any other way?
>>
>
> cdef public enum:
>    EV_READ  = 1
>    EV_WRITE = 2
>
> However, I do not like it, because I would like to use "public" for
> other meaning (API generation). Also note that using "public" will
> trigger the generation of a header file.
>

This header breaks my code, I have ev.pyx that includes ev.h,
actually I can change that to  but I don't like it this way too..

And it actually produces bad code for me:

/* "ev.pxd":3
 * cimport libev
 *
 * cdef api enum: # <<
 * EV_NONE  = libev.EV_NONE
 * EV_READ  = libev.EV_READ
 */
enum  {

  /* "ev.pxd":6
 * EV_NONE  = libev.EV_NONE
 * EV_READ  = libev.EV_READ
 * EV_WRITE = libev.EV_WRITE # <<
 *
 * cdef:
 */
  EV_NONE = EV_NONE,
  EV_READ = EV_READ,
  EV_WRITE = EV_WRITE
};


> Perhaps we should support "cpdef enum: ..."
>

Yes, that would be nice.

-- 
vitja.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Vitja Makarov
2011/7/18 Chris Colbert :
>
>
> On Mon, Jul 18, 2011 at 12:14 PM, Lisandro Dalcin  wrote:
>>
>> On 18 July 2011 06:38, Vitja Makarov  wrote:
>> > cdef enum:
>> >     EV_READ  = 1
>> >     EV_WRITE = 2
>> >
>> > Is there a way to put this constants into module dict?
>> > I want to access this constants from pure python code, I tried this way:
>> >
>> > globals()['EV_READ'] = EV_READ
>> > globals()['EV_WRITE'] = EV_WRITE
>> >
>> > But I don't like it, is there any other way?
>> >
>>
>> cdef public enum:
>>    EV_READ  = 1
>>    EV_WRITE = 2
>>
>> However, I do not like it, because I would like to use "public" for
>> other meaning (API generation). Also note that using "public" will
>> trigger the generation of a header file.
>>
>> Perhaps we should support "cpdef enum: ..."
>>
>>
>
> cpdef enum would be awesome.

I've created pull request:

https://github.com/cython/cython/pull/45


-- 
vitja.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Robert Bradshaw
Trevor King and I discussed this quite a while back, but every time I
got around to looking at his code (I don't think he ever created a
formal pull request) something came up. The idea was that we could
support cpdef structs and extern functions as well.

On Mon, Jul 18, 2011 at 2:38 AM, Vitja Makarov  wrote:
> cdef enum:
>     EV_READ  = 1
>     EV_WRITE = 2
>
> Is there a way to put this constants into module dict?
> I want to access this constants from pure python code, I tried this way:
>
> globals()['EV_READ'] = EV_READ
> globals()['EV_WRITE'] = EV_WRITE
>
> But I don't like it, is there any other way?
>
> --
> vitja.
> ___
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Greg Ewing

Chris Colbert wrote:


cdef public enum:
   EV_READ  = 1
   EV_WRITE = 2

However, I do not like it, because I would like to use "public" for
other meaning (API generation).


My suggestion is

  cdef exposed enum:
...

--
Greg
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Robert Bradshaw
On Mon, Jul 18, 2011 at 4:34 PM, Greg Ewing  wrote:
> Chris Colbert wrote:
>
>>    cdef public enum:
>>       EV_READ  = 1
>>       EV_WRITE = 2
>>
>>    However, I do not like it, because I would like to use "public" for
>>    other meaning (API generation).
>
> My suggestion is
>
>  cdef exposed enum:
>    ...

I agree, public is an overloaded word. This meaning is analogous to
its use for cdef class members. Perhaps we should use "api" for api
generation, and public used for Python-level access, with cpdef being
the preferred form for declaring Python-accessible types.

- Robert
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Any news from the IronPython port?

2011-07-18 Thread Robert Bradshaw
On Mon, Jul 18, 2011 at 7:45 AM, Jason McCampbell
 wrote:
> Hi Stefan,
> Definitely not buried for good, though we haven't made a lot of changes
> recently. :)  We used it for porting SciPy to .NET and re-wrote a large
> number of the SciPy C module implementations in Cython.  It is generally
> stable and produces good code within the set of features that were needed
> (by no means has feature parity with the CPython version).
> In general, I have been quite happy with the results given that it is
> possible to generate interfaces for two Python implementations from a single
> source.  Of course, it is not free.  One can, in general, not take a
> NumPy-heavy Cython file and just generate source code for IronPython.
>  Because IronPython and NumPy for .NET do not share any common C APIs we had
> to wrap some of the APIs and in other cases switch to using Python notation
> and/or call the new Python-independent NumPy core API (present only in the
> refactored version).
> Overall, I think it's a good start and holds some promise for generating
> re-targetable native wrappings, but there is still plenty of work to do to
> make it more accessible.
> Regards,
> Jason

Thanks for the status update--is the code available somewhere (e.g. as
a forked git repo)? Is it something that would be worth merging, or at
this point is it mostly hacked up to just do what you need it to for
SciPy?

- Robert
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Vitja Makarov
2011/7/18 Robert Bradshaw :
> Trevor King and I discussed this quite a while back, but every time I
> got around to looking at his code (I don't think he ever created a
> formal pull request) something came up. The idea was that we could
> support cpdef structs and extern functions as well.
>

That's interesting, I think I shouldn't hurry with my pull request.

2011/7/19 Robert Bradshaw :
> On Mon, Jul 18, 2011 at 4:34 PM, Greg Ewing  
> wrote:
>> My suggestion is
>>
>>  cdef exposed enum:
>>    ...
>
> I agree, public is an overloaded word. This meaning is analogous to
> its use for cdef class members. Perhaps we should use "api" for api
> generation, and public used for Python-level access, with cpdef being
> the preferred form for declaring Python-accessible types.
>

It seems to me that cpdef is more cythonic but exposed could be used
in this case:

cdef extern from "ev.h":
exposed enum:
EV_READ
EV_WRITE

-- 
vitja.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Robert Bradshaw
On Mon, Jul 18, 2011 at 10:24 PM, Vitja Makarov  wrote:
> 2011/7/18 Robert Bradshaw :
>> Trevor King and I discussed this quite a while back, but every time I
>> got around to looking at his code (I don't think he ever created a
>> formal pull request) something came up. The idea was that we could
>> support cpdef structs and extern functions as well.
>>
>
> That's interesting, I think I shouldn't hurry with my pull request.
>
> 2011/7/19 Robert Bradshaw :
>> On Mon, Jul 18, 2011 at 4:34 PM, Greg Ewing  
>> wrote:
>>> My suggestion is
>>>
>>>  cdef exposed enum:
>>>    ...
>>
>> I agree, public is an overloaded word. This meaning is analogous to
>> its use for cdef class members. Perhaps we should use "api" for api
>> generation, and public used for Python-level access, with cpdef being
>> the preferred form for declaring Python-accessible types.
>>
>
> It seems to me that cpdef is more cythonic but exposed could be used
> in this case:
>
> cdef extern from "ev.h":
>    exposed enum:
>        EV_READ
>        EV_WRITE

I'd rather avoid adding another keyword unless it is truly necessary.

- Robert
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] How to define C-consts in python module scope

2011-07-18 Thread Vitja Makarov
2011/7/19 Robert Bradshaw :
> On Mon, Jul 18, 2011 at 10:24 PM, Vitja Makarov  
> wrote:
>> 2011/7/18 Robert Bradshaw :
>>> Trevor King and I discussed this quite a while back, but every time I
>>> got around to looking at his code (I don't think he ever created a
>>> formal pull request) something came up. The idea was that we could
>>> support cpdef structs and extern functions as well.
>>>
>>
>> That's interesting, I think I shouldn't hurry with my pull request.
>>
>> 2011/7/19 Robert Bradshaw :
>>> On Mon, Jul 18, 2011 at 4:34 PM, Greg Ewing  
>>> wrote:
 My suggestion is

  cdef exposed enum:
    ...
>>>
>>> I agree, public is an overloaded word. This meaning is analogous to
>>> its use for cdef class members. Perhaps we should use "api" for api
>>> generation, and public used for Python-level access, with cpdef being
>>> the preferred form for declaring Python-accessible types.
>>>
>>
>> It seems to me that cpdef is more cythonic but exposed could be used
>> in this case:
>>
>> cdef extern from "ev.h":
>>    exposed enum:
>>        EV_READ
>>        EV_WRITE
>
> I'd rather avoid adding another keyword unless it is truly necessary.
>

I agree.

Is Trevor's branch ready for merge?
I see last commit was made in march
https://github.com/wking/cython/commits/cdef-enums-stucts-and-unions


-- 
vitja.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel