[SciPy-dev] Weave/blitz element index type-error (?)

keith roscoe k.roscoe at freeuk.com
Tue Mar 26 09:29:31 CST 2002


Dear all,

When trying to directly access the elements of a 2D Numeric array (
passed to weave.inline as a blitz array), I get a compilation failure 
when using type 'unsigned int'  for the element index.  However, using 
type 'int' for the index compiles and executes perfectly.  

Blitz doesn't have this limitation when used in a stand-alone C++ 
program, which leads me to believe it may be a bug.

But the weave compilation doesn't fail for 1D arrays though, so I'm 
hoping that it's my understanding that's at fault.

At the end of the message is some code that exhibits this behaviour.  
Change the value of _break_compilation to 1 to make the compilation 
fail.

Regards,

Keith


My setup:

Python:  2.2
Numeric: 20.3
weave:   CVS  (affects 0.2.3 also)



# -------------- Start of problematic code ----

import Numeric
import weave

"""
Demonstrates weave compilation failure when indexing type is
unsigned for 2D arrays.
Toggle '_break_compilation' flag to show bug.

Working output (_break_compilation == 0)
---------------------------------------

Before weave:
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]

After weave:
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 9 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]

Fails to compile for _break_compilation != 1

"""

# set to 0 for working code, set to 1 to break it.
_break_compilation = 0


def main():
a = Numeric.zeros((5, 5))

if _break_compilation:
index_type = "unsigned int"
else:
index_type = "int"

print "Before weave:"
print a

code = \
"""
typedef %s index_type;

const index_type middle = 2;

a(middle, middle) = 9;
""" % index_type

weave.inline(code, ['a',],
type_converters = weave.converters.blitz)

print "\nAfter weave:"
print a


if __name__ == '__main__':
main()




More information about the Scipy-dev mailing list