[Cython] Supporting new and old NumPy C API

2013-11-05 Thread Frédéric Bastien
Hi,

As you probably know, cython generated c code use the old NumPy C API,
so when we compile them with newer version of NumPy this generate
warnings.

In Theano we compile many different module during the user script. So
this cause many warning being printed to the users, so we updated
Theano to work with newer and older NumPy without warning.

As we disable the old NumPy C API, we are not able to compile the
cython generated code. So I manually updated the cython code to work
with the new and old api.

I did a post on the numpy mailing list that explain how I did this, in
case someone want to tackle this problem in Cython:
http://mail.scipy.org/pipermail/numpy-discussion/2013-November/068209.html

Frédéric Bastien
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


[Cython] Bug report: some incorrect typed memoryview indexing operations cause crashes

2013-11-05 Thread James Sanders
If I try to compile the following with the current master version:

def buggy(int N, double[:] x):
x[0, N-1]

I get a crash.  This only seems to happen when too many indices are used,
and at least one of them is an expression involving a variable (for
example, things like x[0, N] and x[0, 2-1] don't cause crashes).  Here is
the full output (this probably isn't related, but I'm also a bit confused
about all these "non-trivial type declarators" warnings, which keep
appearing in code I thought was working correctly):

warning: View.MemoryView:410:43: Non-trivial type declarators in shared
declaration.
warning: View.MemoryView:583:32: Non-trivial type declarators in shared
declaration.
warning: View.MemoryView:588:32: Non-trivial type declarators in shared
declaration.
warning: View.MemoryView:1020:20: Non-trivial type declarators in shared
declaration.
warning: View.MemoryView:1020:28: Non-trivial type declarators in shared
declaration.
warning: View.MemoryView:1020:38: Non-trivial type declarators in shared
declaration.

Error compiling Cython file:
--
--
...
def buggy(int N, double[:] x):
x[0, N-1]
 ^


bug.pyx:2:10: Too many indices specified for type double[:]

Error compiling Cython file:

...
def buggy(int N, double[:] x):
x[0, N-1]
 ^


bug.pyx:2:10: Compiler crash in OptimizeBuiltinCalls

ModuleNode.body = StatListNode(bug.pyx:1:0)
StatListNode.stats[0] = DefNode(bug.pyx:1:0,
modifiers = [...]/0,
name = 'buggy',
num_required_args = 2,
py_wrapper_required = True,
reqd_kw_flags_cname = '0',
used = True)
DefNode.body = StatListNode(bug.pyx:2:5)
StatListNode.stats[0] = ExprStatNode(bug.pyx:2:5)
ExprStatNode.expr = IndexNode(bug.pyx:2:5,
use_managed_ref = True)
IndexNode.index = TupleNode(bug.pyx:2:5,
is_sequence_constructor = 1,
result_is_used = True,
use_managed_ref = True)
TupleNode.args[1] = SubNode(bug.pyx:2:10,
infix = True,
operator = '-',
result_is_used = True,
use_managed_ref = True)

Compiler crash traceback from this point on:
  File "Visitor.py", line 170, in
Cython.Compiler.Visitor.TreeVisitor._visit
(/home/.../cython/Cython/Compiler/Visitor.c:4122)
  File "Visitor.py", line 505, in
Cython.Compiler.Visitor.MethodDispatcherTransform.visit_BinopNode
(/home/.../cython/Cython/Compiler/Visitor.c:9459)
  File "Visitor.py", line 516, in
Cython.Compiler.Visitor.MethodDispatcherTransform._visit_binop_node
(/home/.../cython/Cython/Compiler/Visitor.c:9613)
AttributeError: 'NoneType' object has no attribute 'is_builtin_type'
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel