header = """
import numarray, foo, numarray.memory as memory
"""

cmds = """
print "foo.in_f:"
foo.in_f(a)
print "foo.in_c:"
foo.in_c(a)
print "foo.in_out_comma_f:"
a1, b1 = foo.in_out_comma_f(a, b); print str(a1); print str(b1)
print "foo.in_out_comma_c:"
a1, b1 = foo.in_out_comma_c(a, b); print str(a1); print str(b1)
# print "foo.in_out_c:"
# foo.in_out_c(a,b); print str(b)
# foo.in_out_f(a,b); print str(b)
# b = foo.out_c(b); print str(b)
# b = foo.out_f(b); print str(b)
"""

def tryone(s, name):
    import commands
    f = open("cmds.py","w")
    f.write(s)
    f.close()
    results = commands.getoutput("python cmds.py")
    if results is not None:
        print name+": ===============================>"
        print results
    
def testall():
    arrays = """
a = numarray.arange(80., shape=(8,10))
b = a.copy()
"""
    tryone(header+arrays+cmds, "standard")
    
    arrays = """
a = numarray.arange(80., shape=(8,10))
a.byteswap()
a.togglebyteorder()
b = numarray.arange(80., shape=(8,10))
b.byteswap()
b.togglebyteorder()
"""
    tryone(header+arrays+cmds, "byteswapped")

    arrays = """
a0 = numarray.arange(80., shape=(8,10))
a  = numarray.NumArray(shape=(90,), type='Float64')
a._shape = (8,10)
a._strides = (80, 8)
a._byteoffset = 1
a[:]  = a0
print a
b  = numarray.NumArray(shape=(90,), type='Float64')
b._shape = (8, 10)
b._strides = (80, 8)
b._byteoffset = 1
b[:]  = a0
print b
"""
    tryone(header+arrays+cmds, "misaligned")

    arrays = """
a0 = numarray.arange(80., shape=(8,10))
a = numarray.arange(320., shape=(32,10))[::4,:]
a[:] = a0
b = numarray.arange(320., shape=(32,10))[::4,:]
b[:] = a0
assert a.iscontiguous() == 0
"""
    tryone(header+arrays+cmds, "strided")
    
if __name__ == "__main__":
    testall()
