Per-instance extra scope variables

NOT DONE!, only draft, I got another idea... :-)

The reason for this madness

To access NumPy arrays, strides must be looked up and divided by the datatype size. I can see three :

This can mostly be considered a hack.

, in order to be able to implement enhancements/operators/ambitious for NumPy arrays without expecting too complex optimizations of the Cython compiler. The full NumPy problem will be described at the bottom, but the spec comes first.

Please be patient and you'll hopefully see why at the bottom...

Description

This is done:

To allow a scopevars block within a cdef class:

.pxd:

ctypedef class Foo:
    char* complex_buffer

    scopevars:
        int info

.pyx:

cdef class Foo:
    def __enterscope__(self):
        scope(self).info = self.complex_buffer[34] // 4

    def bar(self): print scope(self).info

When using this type now, the following happens:

Foo f = ...
f.info()

is transformed by the ScopeVarsTransformer to:

Foo f = ...
int _scopetmp_f_info
_scopetmp_f_info = f.complex_buffer[34] // 34
print _scopetmp_f_info

Why?

enhancements/scopevars (last edited 2009-03-01 01:02:24 by localhost)