Robert Bradshaw wrote:
> On Jul 23, 2009, at 11:23 PM, Jason Grout wrote:
> 
>> Is it possible to support the any() and all() functions?  I'm using  
>> the
>> most recent version of Cython in Sage, so forgive me if it is already
>> supported in Cython, but just not in Sage's version yet.
> 
> It's working for me...
> 
> {{{
> %cython
> print any([0,0,1,0]), all([0,0,1,0])
> ///
> (True, False)
> }}}
> 


Not if you use comprehension-like syntax.  Can Cython support that in 
the same way it supports list/set/dict comprehensions?

Note that in lots of cases, having any/all only support lists kind of 
defeats the purpose of the short-cutting.

{{{id=0|
%cython
print all(i>=0 for i in range(10))
print any(i<0 for i in range(10))
///

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File 
"/home/sage/sagenb/sage_notebook/worksheets/jason3/174/code/4.py", line 
6, in <module>
 
_support_.cython_import_all("/home/sage/sagenb/sage_notebook/worksheets/jason3/174/code/sage5.spyx",
 
globals())
   File 
"/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/server/support.py",
 
line 411, in cython_import_all
     create_local_c_file=create_local_c_file)
   File 
"/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/server/support.py",
 
line 388, in cython_import
     create_local_c_file=create_local_c_file)
   File 
"/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/misc/cython.py",
 
line 367, in cython
     raise RuntimeError, "Error converting %s to C:\n%s\n%s"%(filename, 
log, err)
RuntimeError: Error converting 
/home/sage/sagenb/sage_notebook/worksheets/jason3/174/code/sage5.spyx to C:


Error converting Pyrex file to C:
------------------------------------------------------------
...

include "interrupt.pxi"  # ctrl-c interrupt block support
include "stdsage.pxi"  # ctrl-c interrupt block support

include "cdefs.pxi"
print all(i>=0 for i in range(10))
               ^
------------------------------------------------------------

/home/worksheet/.sage/temp/sagenb/18730/spyx/_home_sage_sagenb_sage_notebook_worksheets_jason3_174_code_sage5_spyx/_home_sage_sagenb_sage_notebook_worksheets_jason3_174_code_sage5_spyx_0.pyx:6:15:
 
Expected ')'
}}}

{{{id=1|
print all(i>=0 for i in range(10))
print any(i<0 for i in range(10))
///

True
False
}}}







>> I realize that it probably would be easy to write such functions, but
>> since they are standard python functions, it would be nice if they  
>> were
>> recognized by Cython.  It would be super nice if they were *fast*  
>> too :).
> 
> This was actually discussed recently, and yes, we'd like to support  
> this kind of thing. It shouldn't be too hard to do either. However,  
> it's hard to see how one would get faster than the builtin  
> implementations of all and any, short of getting rid of the Python call.

Okay.  It would be enough for me if it just didn't error out on seeing 
any/all with comprehension like syntax.  Then I wouldn't have to 
obfuscate my code when converting from python.


Thanks!

Jason

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to