def fa(a, o, n, dtype=None): if dtype is None: t = a.__class__._type_ else: t = dtype s = sizeof(t) return (t * n).from_address(ao(a) + o * s) class x_float(c_float): pass b = convert(rand(10)) a = (x_float * 10)(*b) z = (c_float * 10)(*b) try: u = (c_float * 2).from_address(ao(a[6])) su = sizeof(u._type_) print "0x%8.8x" % ao(u) print "%10.7f %10.7f" % (u[0], u[1]) except TypeError: print "x_float does not work" try: v = fa(a, 6, 2, c_float) sv = sizeof(v._type_) except TypeError:
def compare(a,b): a1 = convert(a) b1 = convert(b) diff = max(abs(a1-b1)) return diff
from numpy.random import rand from ctypes_array import convert ao = addressof def fa(a,o,n,dtype=None): if dtype is None: t = a.__class__._type_ else: t = dtype s = sizeof(t) return (t*n).from_address(ao(a)+o*s) class x_float(c_float): pass b = convert(rand(10)) a = (x_float*10)(*b) z = (c_float*10)(*b) try: u = (c_float*2).from_address(ao(a[6])) su = sizeof(u._type_) print "0x%8.8x" % ao(u) print "%10.7f %10.7f" % (u[0],u[1]) except TypeError: print "x_float does not work" try: v = fa(a,6,2,c_float) sv = sizeof(v._type_) except TypeError: