Re: [Cython] [cython-users] Recommendations for efficient typed arrays in Cython?
On 02.02.2013 01:23, Greg Ewing wrote: If you're suggesting that 'def object foo' should give Python reference semantics and 'cdef object foo' raw C pointer semantics, No I was not. I was suggesting that static declarations of Python and C variables should have different keywords. Because they behave differently e.g. with respect to reference counting, it can be confusing to new users. For example I was replying to a Cython user who thought anything declared 'cdef' was reference counted. It might not be obvious to a new Cython user what can be put in a Python list and what can be put in an STL vector. "cdef" refers to storage in the generated C, not to the semantics of Cython. But how and where variables are stored in the generated C is an implementation detail. Semantically the difference is between static and dynamic variables. Sturla ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] [cython-users] Recommendations for efficient typed arrays in Cython?
On Mon, Feb 4, 2013 at 4:12 AM, Sturla Molden wrote: > On 02.02.2013 01:23, Greg Ewing wrote: > >> If you're suggesting that 'def object foo' should give Python >> reference semantics and 'cdef object foo' raw C pointer >> semantics, > > > No I was not. > > I was suggesting that static declarations of Python and C variables should > have different keywords. > > Because they behave differently e.g. with respect to reference counting, it > can be confusing to new users. For example I was replying to a Cython user > who thought anything declared 'cdef' was reference counted. It might not be > obvious to a new Cython user what can be put in a Python list and what can > be put in an STL vector. I find the distinction obvious: if Python understands it, it can be put in a Python list. If C++ understands it, it can be put in a STL container. Of course I'm the antithesis of a "new user." We should at least be producing obvious errors. > "cdef" refers to storage in the generated C, not to the semantics of Cython. > But how and where variables are stored in the generated C is an > implementation detail. Semantically the difference is between static and > dynamic variables. I think reference counting is much more of an implementation detail than how and where the variables are stored. When using Cython I hardly ever think about reference counts, it just does the right thing everywhere for me. From a performance perspective, aside from being able to manipulate raw C numeric types, one of the most important features is that functions and variables (both Python and C types) can be statically rather than dynamically bound, and specifying where it should be so. In any case, whether "cdef A a" is reference counted or not depends A in a straightforward manner (it's refcounted if and only if it can be, i.e. A is a subclass of object). Forcing the user to choose between two different forms of "cdef" based on the type of A would be entirely redundant. - Robert ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] [cython-users] Recommendations for efficient typed arrays in Cython?
Sturla Molden wrote: I was replying to a Cython user who thought anything declared 'cdef' was reference counted That's a matter of user education. We can't use syntax to address every possible misconception a user might have. "cdef" refers to storage in the generated C, not to the semantics of Cython. But how and where variables are stored in the generated C is an implementation detail. Not entirely -- you can't access a cdef attribute of an extension type using getattr(), for example. And external C code only has direct access to cdef variables and attributes. -- Greg ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
[Cython] Two generators in one function
Hi everyone, I ran into the following problem using Cython 0.17.4 (current version of Sage). If you try to compile a file with the following function in it: def test_double_gen(L): a = all(x != 0 for x in L) b = all(x != 1 for x in L) return a and b you get errors from the Cython compiler about 'genexpr' being redefined. Error compiling Cython file: ... def test_double_gen(L): a = all(x != 0 for x in L) b = all(x != 1 for x in L) ^ cython_test.pyx:5:14: 'genexpr' already declared Error compiling Cython file: ... def test_double_gen(L): a = all(x != 0 for x in L) ^ cython_test.pyx:4:14: Previous declaration is here Error compiling Cython file: ... def test_double_gen(L): a = all(x != 0 for x in L) b = all(x != 1 for x in L) ^ cython_test.pyx:5:14: 'genexpr' redeclared Are you currently only able to use one inline generator pre function? David ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel