22 sys.path.append(os.getcwd())
25 print (
'VARIOUS TYPES MAPPING:')
26 datatypes = [np.object, np.int8, np.bool, np.byte, np.short, np.int16, np.int, np.long, np.int32, np.int64, np.longlong, np.float, np.float32, np.double, np.float64]
29 print (
'-----' + str(dt) +
'-------')
30 libdemo.printArray(a,
False)
33 print (
'UNSIGNED TYPES:')
34 unsignedtypes = [np.uint8, np.ubyte, np.ushort, np.uint16, np.uint, np.uint32, np.uint64, np.ulonglong]
35 for dt
in unsignedtypes:
37 print (
'-----' + str(dt) +
'-------')
38 libdemo.printArray(a,
False)
40 print (
'PRINTING CONTENTS:')
41 a = np.arange(2*3*4, dtype = np.int32).reshape(2,3,4)
42 print (
'PRINT IN PYTHON:')
44 print (
'PRINT c++ DEMO:')
45 libdemo.printArray(a,
True)
47 a = np.asarray([
'hello',
'python',
'wrapper!'], dtype = np.object)
48 print (
'PRINT IN PYTHON:')
50 print (
'PRINT c++ DEMO:')
51 libdemo.printArray(a,
True)
54 print (
'PRINTING CONVERTED ARRAY:')
55 a = np.arange(2*3*4, dtype = np.int32).reshape(2,3,4)
56 libdemo.printConvertedArray_int(a)
67 for fun
in [libdemo.int_to_str, libdemo.char_to_str, libdemo.float_to_str, libdemo.double_to_str]:
68 locals()[fun.__name__] = wrap_to_str(fun)
70 print (
'TESTING SCALAR CONVERSION:')
71 types = [np.int8, np.byte, np.short, np.int16, np.int, np.long, np.int32, np.int64, np.longlong, np.uint8, np.ubyte, np.ushort, np.uint16, np.uint, np.uint32, np.uint64, np.ulonglong, np.float, np.float32, np.double, np.float64]
73 a = np.asarray((42,), dtype = dt)[0]
74 print (
'%s: as int: %s, as char: %s, as float: %s, as double: %s' % (str(dt), int_to_str(a), char_to_str(a), float_to_str(a), double_to_str(a)))
76 print (
'RETURNING ARRAY FROM CPP:')
77 a = libdemo.ReturnedFromCPP()
83 print (
'PERFORMANCE TEST:')
85 import matplotlib.pyplot
as pyplot
88 print (
'TEST: '+str(fun.__name__))
89 sizes = [1000, 10000, 100000, 1000000]
92 a1 = np.arange(s, dtype = np.float32)
93 a2 = np.ones(s, dtype = np.float32)
100 times.append(np.average(tavg))
101 return sizes, np.asarray(times)
103 sz, perfArrayT = PerfTest(libdemo.SumArrayT)
105 sz, perfBoostArray = PerfTest(libdemo.SumNumericArray)
108 pyplot.plot(sz, perfBoostArray / perfArrayT)
109 pyplot.gca().set(xlabel =
'Array Size', ylabel =
'Relative Compute Time')
object zeros(int rank, const Py_ssize_t *dims, int type)
Creates a new ndarray filled with zeros.