def substringView(self, i, j): """substringView returns modified view of the input array which represents only the [i:j] substring of each array element. >>> c = fromlist([["this","that"],["another", "one"]]) >>> d = c.substringView(1, 2); d CharArray([['h', 'h'], ['n', 'n']]) >>> d[:] = [["1","2"],["3","4"]]; d CharArray([['1', '2'], ['3', '4']]) >>> c CharArray([['t1is', 't2at'], ['a3other', 'o4e']]) """ n = _na.arange(self._itemsize)[i:j] if len(n) != 0: i = n[0] j = n[-1] + 1 else: i = j = 0 r = self.view() substr_size = j - i if substr_size < 0: substr_size = 0 r._itemsize = substr_size r._byteoffset += i return r
def proveit(N, filename="memmap.dat", pagesize=1024, mode="r"): """proveit is a diagnostic function which creates a file of size 'N', memory maps it, and then reads one byte at 'pagesize' intervals.""" import numarrayall as num import os f = _open(filename, "w+") f.seek(N - 1) f.write("\0") f.close() m = Memmap(filename, mode=mode) n = m[:] a = num.NumArray(buffer=n, shape=(len(n), ), type='Int8') a._map = m hits = num.arange(N // pagesize) * pagesize fetch = a[hits] # force every page into RAM return a
def proveit(N, filename="memmap.dat", pagesize=1024, mode="r"): """proveit is a diagnostic function which creates a file of size 'N', memory maps it, and then reads one byte at 'pagesize' intervals.""" import numarrayall as num import os f = _open(filename, "w+") f.seek(N-1) f.write("\0") f.close() m = Memmap(filename, mode=mode) n = m[:] a = num.NumArray(buffer=n, shape=(len(n),), type='Int8') a._map = m hits = num.arange(N//pagesize)*pagesize fetch = a[ hits ] # force every page into RAM return a