Fwd: utilities.autowrap.ufuncify fails with symbol lists of length >= 32

24 views
Skip to first unread message

AMiT Kumar

unread,
Jul 1, 2015, 1:05:21 AM7/1/15
to sy...@googlegroups.com
As reported by Mike Roberts here:  https://github.com/sympy/sympy/issues/9593

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 intosympy.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 tozero_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.


AMiT Kumar

Mike Roberts

unread,
Jul 1, 2015, 1:32:02 AM7/1/15
to sy...@googlegroups.com
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.
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.

Jason Moore

unread,
Jul 1, 2015, 1:37:24 AM7/1/15
to sy...@googlegroups.com
I've addressed this at the issue: https://github.com/sympy/sympy/issues/9593
--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/3655b314-fd8e-4945-b397-c4ccadb9b9b1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages