[Cython] class optimisations (Re: [cython-users] How to pass Cython flags from Distutils?)

2012-04-03 Thread Stefan Behnel
[moving this discussion from cython-users to cython-devel]

Robert Bradshaw, 03.04.2012 09:43:
> On Mon, Apr 2, 2012 at 11:01 PM, Stefan Behnel wrote:
>> Robert Bradshaw, 03.04.2012 07:51:
>>> auto_cpdef is expiremental
>>
>> Is that another word for "deprecated"?
> 
> No, it's another word for "incomplete."

Ah, just a typo then.


> Can something be deprecated if
> it was never even finished? It's probably something we should
> eventually do by default as an optimization, at least for methods, as
> well as letting compiled classes become cdef classes (minus the
> semantic idiosyncrasies) whenever possible (can we always detect this?

We can at least start with the "obviously safe" cases, assuming we find
any. A "__slots__" field would be a good indicator, for example. And when
we get extension types to have a __dict__, that should fix a lot of the
differences already.


> What about subclasses that want to multiply-inherit?

You can inherit from multiple extension types in a Python type, and classes
with more than one parent aren't candidates anyway. So this doesn't
restrict us.


> It may still be
> an option worth finishing up, making it easy to automatically take a
> (slightly-incompatible) step towards static binding.

Yes, the option could be extended to include classes at some point, before
we go for more automatic default optimisations. That would keep the changes
explicit at the beginning.

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


[Cython] Bug report with 0.16 RC

2012-04-03 Thread Wes McKinney
I don't have a Trac account yet, but wanted to report this bug with
the 0.16 RC. This function worked fine under 0.15.1:


@cython.wraparound(False)
@cython.boundscheck(False)
def is_lexsorted(list list_of_arrays):
cdef:
int i
Py_ssize_t n, nlevels
int32_t k, cur, pre
ndarray arr

nlevels = len(list_of_arrays)
n = len(list_of_arrays[0])

cdef int32_t **vecs =  malloc(nlevels * sizeof(int32_t*))
for i from 0 <= i < nlevels:
vecs[i] =  ( list_of_arrays[i]).data
# assume uniqueness??

for i from 1 <= i < n:
for k from 0 <= k < nlevels:
cur = vecs[k][i]
pre = vecs[k][i-1]
if cur == pre:
continue
elif cur > pre:
break
else:
return False
free(vecs)
return True

gives this error:

python setup.py build_ext --inplace
running build_ext
cythoning pandas/src/tseries.pyx to pandas/src/tseries.c

Error compiling Cython file:

...
nlevels = len(list_of_arrays)
n = len(list_of_arrays[0])

cdef int32_t **vecs =  malloc(nlevels * sizeof(int32_t*))
for i from 0 <= i < nlevels:
vecs[i] =  ( list_of_arrays[i]).data
  ^


pandas/src/groupby.pyx:120:59: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(tseries.pyx:1:0)
StatListNode.stats[52] = StatListNode(groupby.pyx:4:0)
StatListNode.stats[6] = CompilerDirectivesNode(groupby.pyx:109:0)
CompilerDirectivesNode.body = StatListNode(groupby.pyx:109:0)
StatListNode.stats[0] = DefNode(groupby.pyx:109:0,
modifiers = [...]/0,
name = u'is_lexsorted',
num_required_args = 1,
py_wrapper_required = True,
reqd_kw_flags_cname = '0',
used = True)
File 'Nodes.py', line 342, in analyse_expressions:
StatListNode(groupby.pyx:110:4,
is_terminator = True)
File 'Nodes.py', line 342, in analyse_expressions:
StatListNode(groupby.pyx:119:4)
File 'Nodes.py', line 6054, in analyse_expressions:
ForFromStatNode(groupby.pyx:119:4,
relation1 = u'<=',
relation2 = u'<')
File 'Nodes.py', line 342, in analyse_expressions:
StatListNode(groupby.pyx:120:18)
File 'Nodes.py', line 4778, in analyse_expressions:
SingleAssignmentNode(groupby.pyx:120:18)
File 'Nodes.py', line 4883, in analyse_types:
SingleAssignmentNode(groupby.pyx:120:18)
File 'ExprNodes.py', line 7079, in analyse_types:
TypecastNode(groupby.pyx:120:18,
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 4274, in analyse_types:
AttributeNode(groupby.pyx:120:59,
attribute = u'data',
initialized_check = True,
is_attribute = 1,
member = u'data',
needs_none_check = True,
op = '->',
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 4360, in analyse_as_ordinary_attribute:
AttributeNode(groupby.pyx:120:59,
attribute = u'data',
initialized_check = True,
is_attribute = 1,
member = u'data',
needs_none_check = True,
op = '->',
result_is_used = True,
use_managed_ref = True)
File 'ExprNodes.py', line 4436, in analyse_attribute:
AttributeNode(groupby.pyx:120:59,
attribute = u'data',
initialized_check = True,
is_attribute = 1,
member = u'data',
needs_none_check = True,
op = '->',
result_is_used = True,
use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/home/wesm/code/repos/cython/Cython/Compiler/ExprNodes.py",
line 4436, in analyse_attribute
replacement_node = numpy_transform_attribute_node(self)
  File "/home/wesm/code/repos/cython/Cython/Compiler/NumpySupport.py",
line 18, in numpy_transform_attribute_node
numpy_pxd_scope = node.obj.entry.type.scope.parent_scope
AttributeError: 'TypecastNode' object has no attribute 'entry'
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel