Hi friends, please allow me to introduce myself. My name is Mike Roberts. I am a computer science PhD student at Stanford. I've been using sympy recently to help me solve some fun optimization problems.

I have encountered some unexpected behavior in the sympy.utilities.autowrap module. I believe I am running into an undocumented hard-coded limit on the number of symbols I can pass into sympy.utilities.autowrap.ufuncify(...). Here is the code snippet that demonstrates the unexpected behavior I'm seeing.

from pylab import *

import sympy

import sympy.utilities.autowrap

zero_expr = sympy.sympify("0")

num_syms = 31

syms = [ sympy.Symbol("x_%02d"%i) for i in range(num_syms) ]

vals = zeros(len(syms))

zero_expr_ufuncify = sympy.utilities.autowrap.ufuncify(args=syms,expr=zero_expr,backend="numpy",verbose=True)

# works

print zero_expr_ufuncify(*vals)

print

num_syms = 31

syms = [ sympy.Symbol("x_%099d"%i) for i in range(num_syms) ]

vals = zeros(len(syms))

zero_expr_ufuncify = sympy.utilities.autowrap.ufuncify(args=syms,expr=zero_expr,backend="numpy",verbose=True)

# also works

print zero_expr_ufuncify(*vals)

print

num_syms = 32

syms = [ sympy.Symbol("x_%02d"%i) for i in range(num_syms) ]

vals = zeros(len(syms))

zero_expr_ufuncify = sympy.utilities.autowrap.ufuncify(args=syms,expr=zero_expr,backend="numpy",verbose=True)

# doesn't work

print "about to evaluate ufunc with 32 args..."

print zero_expr_ufuncify(*vals)

print

The first two calls to zero_expr_ufuncify(*vals) behave as expected, returning 0.0. But the last call to zero_expr_ufuncify(*vals) causes a segmentation fault. The exact error I'm getting is as follows.

Segmentation fault: 11

The only difference between these calls is that sympy.utilities.autowrap.ufuncify(...) was called with symbol lists of different lengths. For both behaves-as-expected calls, the corresponding symbol list is of length 31. For the does-not-behave-as-expected call, the corresponding symbol list is of length 32.

Note that the second call has a corresponding symbol list of length 31, but the symbols have very long names. Since this call behaves as expected, I believe this is not a problem of the generated C code having too many ASCII characters on a single line.

Note that I also found a post describing a similar issue on the Google Group. However, the code example from the Google Group is targeting a Fortran backend. Therefore, I believe the issue on the Google Group is different to the one I'm reporting here.

https://groups.google.com/forum/#!searchin/sympy/ufuncify/sympy/kgzcR8Qu7s4/RAGTw7A0I3oJ

I'm running sympy 0.7.6-1, which I installed via the Canopy Package Manager on OSX Yosemite 10.10.3, 64 bit.

You received this message because you are subscribed to the Google Groups "sympy" group.

To unsubscribe from this group and stop receiving emails from it, send an email to

.

.

.

.

.