def test_bigarray_indexing_pageedge(): shape = (10, PS-1) data = arange(mul(shape), dtype=uint32).view(uint8) # NOTE 4 times bigger than uint8 f = BigFile_Data_RO(data, PS) fh = f.fileh_open() A = BigArray(shape, uint8, fh) # bigarray with test data and shape A_ = data[:mul(shape)].reshape(shape) # ndarray ----//---- # AA[key] -> assert array_equal(A[key], A_[key]) AA = DoubleCheck(A, A_) AA[0] AA[1] # tail of page0 - page1 AA[1:2] # ---- // ---- AA[1:2:-1] # [] AA[1:0] # [] AA[1:0:-1] # tail of page0 - page1 shape = (10, PS+1) f = BigFile_Data_RO(data, PS) fh = f.fileh_open() A = BigArray(shape, uint8, fh) A_ = data[:mul(shape)].reshape(shape) AA = DoubleCheck(A, A_) AA[0] # page0 - head of page1 AA[0:1] # ---- // ---- AA[0:1:-1] # [] AA[1:0] # [] AA[1:0:-1] # page0 - head of page1
def _init0(self, shape, dtype_, order): self._dtype = dtype(dtype_) self._shape = shape self._order = order # TODO +offset ? # TODO +strides ? # order -> stride_in_items(i) ordering = {"C": lambda i: mul(shape[i + 1 :]), "F": lambda i: mul(shape[:i])} Si = ordering.get(order) if Si is None: raise NotImplementedError("Order %s not supported" % order) # shape, dtype -> ._stridev # TODO take dtype.alignment into account ? self._stridev = tuple(Si(i) * self._dtype.itemsize for i in range(len(shape)))
def test_mul(): assert mul([1]) == 1 assert mul([1], 5) == 5 assert mul([0], 5) == 0 assert mul([1,2,3,4,5]) == 120 assert mul([1,2,3,4,5,6]) == 720 # check it does not overflow assert mul([1<<30, 1<<30, 1<<30]) == 1<<90
def test_bigarray_indexing_Nd(): # shape of tested array - all primes, total size for uint32 ~ 7 2M pages # XXX even less dimensions (to speed up tests)? shape = tuple(reversed( (17,23,101,103) )) # test data - all items are unique - so we can check array by content # NOTE +PS so that BigFile_Data has no problem loading last blk # (else data slice will be smaller than buf) data = arange(mul(shape) + PS, dtype=uint32) f = BigFile_Data_RO(data, PS) fh = f.fileh_open() for order in ('C', 'F'): A = BigArray(shape, uint32, fh, order=order) # bigarray with test data and shape A_ = data[:mul(shape)].reshape(shape, order=order) # ndarray ----//---- # AA[key] -> A[key], A_[key] AA = DoubleGet(A, A_) # now just go over combinations of various slice at each dimension, and see # whether slicing result is the same ndarray would do. for idx in idx_to_test(shape): a, a_ = AA[idx] assert array_equal(a, a_) # any part of index out of range # - element access -> raises IndexError # - slice access -> empty for idxpos in range(len(shape)): idx = [0]*len(shape) # idx -> tuple(idx) # ( list would mean advanced indexing - not what we want ) idxt = lambda : tuple(idx) # valid access element access idx[idxpos] = shape[idxpos] - 1 # 0, 0, 0, Ni-1, 0 ,0, 0 a, a_ = AA[idxt()] assert array_equal(a, a_) # out-of-range element access idx[idxpos] = shape[idxpos] # 0, 0, 0, Ni , 0 ,0, 0 raises(IndexError, 'A [idxt()]') raises(IndexError, 'A_[idxt()]') # out-of-range slice access idx[idxpos] = slice(shape[idxpos], # 0, 0, 0, Ni:Ni+1 , 0 ,0, 0 shape[idxpos]+1) a, a_ = AA[idxt()] assert array_equal(a, a_) assert a .size == 0 assert a_.size == 0 # TODO ... -> expanded (0,1,2,negative), rejected if many # TODO newaxis # TODO nidx < len(shape) # TODO empty slice in major row, empty slice in secondary row """
def size(self): return mul(self._shape)