def f(d): bc = d * rffi.sizeof(rffi.SIGNED) va = alloc_raw_storage(bc, zero=True) vb = alloc_raw_storage(bc, zero=True) vc = alloc_raw_storage(bc, zero=True) x = 1 for i in range(d): j = i * rffi.sizeof(rffi.SIGNED) raw_storage_setitem(va, j, rffi.cast(rffi.SIGNED, i)) raw_storage_setitem(vb, j, rffi.cast(rffi.SIGNED, i)) i = 0 while i < bc: myjitdriver.jit_merge_point() a = raw_storage_getitem(rffi.SIGNED, va, i) b = raw_storage_getitem(rffi.SIGNED, vb, i) c = a + b raw_storage_setitem(vc, i, rffi.cast(rffi.SIGNED, c)) i += 1 * rffi.sizeof(rffi.SIGNED) res = 0 for i in range(d): res += raw_storage_getitem(rffi.SIGNED, vc, i * rffi.sizeof(rffi.SIGNED)) free_raw_storage(va) free_raw_storage(vb) free_raw_storage(vc) return res
def test_float_int32_casts(self): myjitdriver = JitDriver(greens=[], reds='auto', vectorize=True) def f(bytecount, va, vb, vc): i = 0 j = 0 while j < bytecount: myjitdriver.jit_merge_point() a = raw_storage_getitem(rffi.DOUBLE, va, j) b = raw_storage_getitem(rffi.INT, vb, i) c = a + rffi.cast(rffi.DOUBLE, b) raw_storage_setitem(vc, j, c) i += 4 j += 8 count = 32 va = alloc_raw_storage(8 * count, zero=True) vb = alloc_raw_storage(4 * count, zero=True) for i, v in enumerate([1.0, 2.0, 3.0, 4.0] * (count / 4)): raw_storage_setitem(va, i * 8, rffi.cast(rffi.DOUBLE, v)) for i, v in enumerate([-1, -2, -3, -4] * (count / 4)): raw_storage_setitem(vb, i * 4, rffi.cast(rffi.INT, v)) vc = alloc_raw_storage(8 * count, zero=True) self.meta_interp(f, [8 * count, va, vb, vc], vec=True) for i in range(count): assert raw_storage_getitem(rffi.DOUBLE, vc, i * 8) == 0.0 free_raw_storage(va) free_raw_storage(vb) free_raw_storage(vc)
def test_float_int32_casts(self): myjitdriver = JitDriver(greens = [], reds = 'auto', vectorize=True) def f(bytecount, va, vb, vc): i = 0 j = 0 while j < bytecount: myjitdriver.jit_merge_point() a = raw_storage_getitem(rffi.DOUBLE,va,j) b = raw_storage_getitem(rffi.INT,vb,i) c = a+rffi.cast(rffi.DOUBLE,b) raw_storage_setitem(vc, j, c) i += 4 j += 8 count = 32 va = alloc_raw_storage(8*count, zero=True) vb = alloc_raw_storage(4*count, zero=True) for i,v in enumerate([1.0,2.0,3.0,4.0]*(count/4)): raw_storage_setitem(va, i*8, rffi.cast(rffi.DOUBLE,v)) for i,v in enumerate([-1,-2,-3,-4]*(count/4)): raw_storage_setitem(vb, i*4, rffi.cast(rffi.INT,v)) vc = alloc_raw_storage(8*count, zero=True) self.meta_interp(f, [8*count, va, vb, vc], vec=True) for i in range(count): assert raw_storage_getitem(rffi.DOUBLE,vc,i*8) == 0.0 free_raw_storage(va) free_raw_storage(vb) free_raw_storage(vc)
def new(self, values, type, size=None, zero=True): bytecount = rffi.sizeof(type) if not values: array = alloc_raw_storage(size*bytecount, zero=zero) self.arrays.append(array) return array else: size = len(values)*bytecount array = alloc_raw_storage(size, zero=zero) for i,v in enumerate(values): raw_storage_setitem(array, i*bytecount, rffi.cast(type,v)) self.arrays.append(array) return array
def new(self, values, type, size=None, zero=True): bytecount = rffi.sizeof(type) if not values: array = alloc_raw_storage(size * bytecount, zero=zero) self.arrays.append(array) return array else: size = len(values) * bytecount array = alloc_raw_storage(size, zero=zero) for i, v in enumerate(values): raw_storage_setitem(array, i * bytecount, rffi.cast(type, v)) self.arrays.append(array) return array
def __init__(self, size, dtype): self.storage = alloc_raw_storage(size) self.gcstruct = V_OBJECTSTORE self.dtype = dtype self.size = size self.flags = (NPY.ARRAY_C_CONTIGUOUS | NPY.ARRAY_F_CONTIGUOUS | NPY.ARRAY_WRITEABLE | NPY.ARRAY_ALIGNED)
def __init__(self, index_stride_size, stride_size, size): start = 0 dtype = descriptor.get_dtype_cache(space).w_longdtype indexes = dtype.itemtype.malloc(size * dtype.elsize) values = alloc_raw_storage(size * stride_size, track_allocation=False) Repr.__init__(self, dtype.elsize, stride_size, size, values, indexes, start, start)
def test_untranslated_storage_unaligned(monkeypatch): monkeypatch.setattr(rawstorage, 'misaligned_is_fine', False) r = alloc_raw_storage(15) raw_storage_setitem_unaligned(r, 3, 1<<30) res = raw_storage_getitem_unaligned(lltype.Signed, r, 3) assert res == 1<<30 raw_storage_setitem_unaligned(r, 3, 3.14) res = raw_storage_getitem_unaligned(lltype.Float, r, 3) assert res == 3.14 free_raw_storage(r)
def test_untranslated_storage_unaligned(monkeypatch): monkeypatch.setattr(rawstorage, 'misaligned_is_fine', False) r = alloc_raw_storage(15) raw_storage_setitem_unaligned(r, 3, 1 << 30) res = raw_storage_getitem_unaligned(lltype.Signed, r, 3) assert res == 1 << 30 raw_storage_setitem_unaligned(r, 3, 3.14) res = raw_storage_getitem_unaligned(lltype.Float, r, 3) assert res == 3.14 free_raw_storage(r)
def test_untranslated_storage(): r = alloc_raw_storage(37) raw_storage_setitem(r, 8, 1 << 30) res = raw_storage_getitem(lltype.Signed, r, 8) assert res == 1 << 30 raw_storage_setitem(r, 8, 3.14) res = raw_storage_getitem(lltype.Float, r, 8) assert res == 3.14 py.test.raises(AlignmentError, raw_storage_getitem, lltype.Signed, r, 3) py.test.raises(AlignmentError, raw_storage_setitem, r, 3, 42.5) free_raw_storage(r)
def test_untranslated_storage(): r = alloc_raw_storage(37) raw_storage_setitem(r, 8, 1<<30) res = raw_storage_getitem(lltype.Signed, r, 8) assert res == 1<<30 raw_storage_setitem(r, 8, 3.14) res = raw_storage_getitem(lltype.Float, r, 8) assert res == 3.14 py.test.raises(AlignmentError, raw_storage_getitem, lltype.Signed, r, 3) py.test.raises(AlignmentError, raw_storage_setitem, r, 3, 42.5) free_raw_storage(r)
def allocBuf(size): buf = lltype.malloc(cConfig["buf_t"], flavor="raw", zero=True) buf.c_base = alloc_raw_storage(size) rffi.setintfield(buf, "c_len", size) return buf
def f(): p = alloc_raw_storage(15, track_allocation=False, zero=True) raw_storage_setitem(p, 3, 24) res = raw_storage_getitem(lltype.Signed, p, 3) free_raw_storage(p, track_allocation=False) return res
def f(): p = alloc_raw_storage(15) raw_storage_setitem(p, 5, rffi.cast(rffi.UCHAR, 254)) res = raw_storage_getitem(rffi.UCHAR, p, 5) free_raw_storage(p) return rffi.cast(lltype.Signed, res)
def f(): p = alloc_raw_storage(15) raw_storage_setitem(p, 4, 2.4e15) res = raw_storage_getitem(lltype.Float, p, 4) free_raw_storage(p) return res
def allocCB(handle, size, buf): buf.c_base = alloc_raw_storage(size) rffi.setintfield(buf, "c_len", size)
def __init__(self, stride_size, size): start = 0 values = alloc_raw_storage(size * stride_size, track_allocation=False) Repr.__init__(self, stride_size, size, values, start)
def f(i): r = alloc_raw_storage(24) raw_storage_setitem(r, 8, i) res = raw_storage_getitem(lltype.Signed, r, 8) free_raw_storage(r) return res != i
def allocCB(handle, size, buf): # This is almost certainly the right thing to pass to alloc_cb buf.c_base = alloc_raw_storage(size) rffi.setintfield(buf, "c_len", size)
def f(v): r = alloc_raw_storage(24) raw_storage_setitem_unaligned(r, 3, v) res = raw_storage_getitem_unaligned(lltype.Float, r, 3) free_raw_storage(r) return res != v
def test_untranslated_storage(): r = alloc_raw_storage(15) raw_storage_setitem(r, 3, 1<<30) res = raw_storage_getitem(lltype.Signed, r, 3) free_raw_storage(r) assert res == 1<<30
def __init__(self, size, dtype): self.storage = alloc_raw_storage(size) self.gcstruct = V_OBJECTSTORE self.dtype = dtype self.size = size
def __init__(self, size, dtype): self.storage = alloc_raw_storage(size) self.dtype = dtype self.size = size
def f(): p = alloc_raw_storage(15) raw_storage_setitem(p, 3, 24) res = raw_storage_getitem(lltype.Signed, p, 3) free_raw_storage(p) return res