def f(points, result_point, n): i = 0 while i < n: myjitdriver.jit_merge_point(i=i, points=points, n=n, result_point=result_point) x = array_getitem(types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, 0) y = array_getitem(types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, rffi.sizeof(lltype.Signed)) cur_x = array_getitem(types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0) cur_y = array_getitem(types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed)) array_setitem(types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0, cur_x + x) array_setitem(types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed), cur_y + y) i += 1
def f(points, result_point, n): i = 0 while i < n: myjitdriver.jit_merge_point(i=i, points=points, n=n, result_point=result_point) x = array_getitem( types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, 0 ) y = array_getitem( types.slong, rffi.sizeof(lltype.Signed) * 2, points, i, rffi.sizeof(lltype.Signed) ) cur_x = array_getitem( types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0 ) cur_y = array_getitem( types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed) ) array_setitem( types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, 0, cur_x + x ) array_setitem( types.slong, rffi.sizeof(lltype.Signed) * 2, result_point, 0, rffi.sizeof(lltype.Signed), cur_y + y ) i += 1
def test_array_fields(self): POINT = lltype.Struct("POINT", ("x", lltype.Float), ("y", lltype.Float), ) points = lltype.malloc(rffi.CArray(POINT), 2, flavor="raw") points[0].x = 1.0 points[0].y = 2.0 points[1].x = 3.0 points[1].y = 4.0 points = rffi.cast(rffi.CArrayPtr(lltype.Char), points) assert array_getitem(types.double, 16, points, 0, 0) == 1.0 assert array_getitem(types.double, 16, points, 0, 8) == 2.0 assert array_getitem(types.double, 16, points, 1, 0) == 3.0 assert array_getitem(types.double, 16, points, 1, 8) == 4.0 # array_setitem(types.double, 16, points, 0, 0, 10.0) array_setitem(types.double, 16, points, 0, 8, 20.0) array_setitem(types.double, 16, points, 1, 0, 30.0) array_setitem(types.double, 16, points, 1, 8, 40.0) # assert array_getitem(types.double, 16, points, 0, 0) == 10.0 assert array_getitem(types.double, 16, points, 0, 8) == 20.0 assert array_getitem(types.double, 16, points, 1, 0) == 30.0 assert array_getitem(types.double, 16, points, 1, 8) == 40.0 # lltype.free(points, flavor="raw")
def test_array_fields(self): POINT = lltype.Struct( "POINT", ("x", lltype.Float), ("y", lltype.Float), ) points = lltype.malloc(rffi.CArray(POINT), 2, flavor="raw") points[0].x = 1.0 points[0].y = 2.0 points[1].x = 3.0 points[1].y = 4.0 points = rffi.cast(rffi.CArrayPtr(lltype.Char), points) assert array_getitem(types.double, 16, points, 0, 0) == 1.0 assert array_getitem(types.double, 16, points, 0, 8) == 2.0 assert array_getitem(types.double, 16, points, 1, 0) == 3.0 assert array_getitem(types.double, 16, points, 1, 8) == 4.0 # array_setitem(types.double, 16, points, 0, 0, 10.0) array_setitem(types.double, 16, points, 0, 8, 20.0) array_setitem(types.double, 16, points, 1, 0, 30.0) array_setitem(types.double, 16, points, 1, 8, 40.0) # assert array_getitem(types.double, 16, points, 0, 0) == 10.0 assert array_getitem(types.double, 16, points, 0, 8) == 20.0 assert array_getitem(types.double, 16, points, 1, 0) == 30.0 assert array_getitem(types.double, 16, points, 1, 8) == 40.0 # lltype.free(points, flavor="raw")
def _read(self, storage, width, i, offset): if we_are_translated(): res = libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T), width, storage, i, offset) else: res = libffi.array_getitem_T(self.T, width, storage, i, offset) return byteswap(res)
def f(data, n): i = 0 s = rffi.cast(COMPUTE_TYPE, 0) while i < n: myjitdriver.jit_merge_point(n=n, i=i, s=s, data=data) s += rffi.cast(COMPUTE_TYPE, array_getitem(ffitype, rffi.sizeof(TYPE), data, 0, 0)) i += 1 return s
def f(data, n): i = 0 s = rffi.cast(COMPUTE_TYPE, 0) while i < n: myjitdriver.jit_merge_point(n=n, i=i, s=s, data=data) s += rffi.cast( COMPUTE_TYPE, array_getitem(ffitype, rffi.sizeof(TYPE), data, 0, 0)) i += 1 return s
def read(self, storage, width, i, offset): return self.box(libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T), width, storage, i, offset ))
def read_bool(self, storage, width, i, offset): return bool(self.for_computation( libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T), width, storage, i, offset)))
def read(self, storage, width, i, offset): return self.box( libffi.array_getitem(clibffi.cast_type_to_ffitype(self.T), width, storage, i, offset))