[Pythonmac-SIG] CXX/Numeric problem on MacOSX (was building vpython on MacOSX)

Steve Spicklemire steve@spvi.com
Sun, 24 Feb 2002 09:35:39 -0500


Hi MacPython Folks (and Paul Dubois),

	Sorry for bothering you all again, but I'm getting closer to 
sorting this out, but I think I need another hint. I've got vpython to 
build on MacOSX, and it runs.. mostly.  VPython makes heavy use of the 
Numeric module, and also uses Paul Dubois' CXX extension class system 
for creating python objects with c++. I'm an expert on neither, though I 
have used the Numeric a fair amount.

Below is a simple program that shows the problem. "visual" is the module 
that contains all the vpython stuff, and it does "from Numeric import *" 
so that all the Numeric code is also in the visual module. It also 
imports the cvisualmodule, built on Paul's CXX extension system. There 
is magic in visual.py that calls the correct constructor from 
cvisualmodule when certain functions in the visual namespace are called 
(e.g., curve()). If I run this program with no command line arguments, 
"band" is a simple instance of the dummy class "foo". If I run with a 
command line argument, "band" is an instance of a "curve" object from 
the cvisualmodule extension. The program dies no matter what binary 
operation I perform on two arrays, subtraction, addition, etc. 
Multiplication by a constant doesn't show this problem however, so it's 
something in the use of two arrays.

If band is a simple instance.... this program runs forever (well.. for a 
really long time).

If band is an instance of a curve object, this program fails after an 
indeterminate number of iterations (from tens to thousands, with no 
clear cause). I get e.g.,

[vh10-15:~/Development/vpython/cvisual] steve% python test_wave2.py 1
Visual-2001-12-30
2
band is a curve
iter 1 iter 2 iter 3 iter 4 iter 5 iter 6 iter 7 iter 8 iter 9 iter 10 
iter 11 iter 12 iter 13 iter 14 iter 15 iter 16 iter 17 iter 18 iter 19 
iter 20 iter 21 iter 22 iter 23 iter 24 iter 25 iter 26 iter 27 iter 28 
iter 29 iter 30 iter 31 iter 32 iter 33 iter 34 iter 35 iter 36 iter 37 
iter 38 iter 39 iter 40 iter 41 iter 42 iter 43 iter 44 iter 45 iter 46 
iter 47 iter 48 iter 49 iter 50 iter 51 iter 52 iter 53 iter 54 iter 55 
iter 56 iter 57 iter 58 iter 59 iter 60 iter 61 iter 62 iter 63 iter 64 
iter 65 iter 66 iter 67 iter 68 iter 69 iter 70 iter 71 iter 72 iter 73 
iter 74 iter 75 iter 76 iter 77 iter 78 iter 79 iter 80 iter 81 iter 82 
iter 83 iter 84 iter 85 iter 86 iter 87 iter 88 iter 89 iter 90 iter 91 
iter 92 iter 93 iter 94 iter 95 iter 96 iter 97 iter 98 iter 99 iter 100 
iter 101 iter 102 iter 103 iter 104 iter 105 iter 106 iter 107 iter 108 
iter 109 iter 110 iter 111 iter 112 iter 113 iter 114 iter 115 iter 116 
iter 117 iter 118 iter 119 iter 120 iter 121 iter 122 iter 123 iter 124 
iter 125 iter 126 iter 127 iter 128 iter 129 iter 130 iter 131 iter 132 
iter 133 iter 134 iter 135 iter 136 iter 137 iter 138 iter 139 iter 140 
iter 141 iter 142 iter 143 iter 144 iter 145 iter 146 iter 147 iter 148 
iter 149 iter 150 iter 151 iter 152 iter 153 iter 154 iter 155 iter 156 
iter 157 iter 158 iter 159 iter 160 iter 161 iter 162 iter 163 iter 164 
iter 165 iter 166 iter 167 iter 168 iter 169
Traceback (most recent call last):
   File "test_wave2.py", line 26, in ?
     bleah = band.foo2 - band.foo1
ValueError: unexpected math error


Diggin around I find that this error is generated in the "ufuncmodule" 
of Numeric. If I try to debug this I get to.

The message comes from the math_error() function if ufuncobject, where I 
set a breakpoint.

Breakpoint 2, math_error () at Src/ufuncobject.c:407
(gdb) print errno
$1 = <unknown type>

most unhelpful!

static void math_error() {
=>  if (errno == EDOM)
         PyErr_SetString(PyExc_ValueError, "math domain error");
     else if (errno == ERANGE)
         PyErr_SetString(PyExc_OverflowError, "math range error");
     else
         PyErr_SetString(PyExc_ValueError, "unexpected math error");
}

I'm sure this is some strangeness in the way the CXX stuff builds on 
MacOSX (this code works on Win/Linux/MacOS9). Does anybody have any 
suggestions? (BTW I changed my makefile to use "c++" rather than "cc  
with -lstdc++" and while it "works", the same problem persists.

Anyway.. thanks for any thoughts. ;-)

-steve

import visual

import sys

print len(sys.argv)

class foo:
     pass

if len(sys.argv)<2:
     band = foo()
     print "band is a simple class"
else:
     print "band is a curve"
     band = visual.curve()


band.foo1 = visual.array(10*[1],visual.Float)
band.foo2 = visual.array(10*[2],visual.Float)

i=0

while 1:
     i += 1
     print "iter",i,
     bleah = band.foo2 - band.foo1
     if visual.sum(bleah*bleah) != 10.0:
         print "Hmm. the math is wrong"
     sys.stdout.flush()