def slicer(start, length, slicelen): length = min(len(self) - start, length) slicelen = min(length, slicelen) buf = np.empty(slicelen, dtype=dtype) if rightclosed: return Seq.map((lambda s: g_rightclosed(s, buf, cuts)), covariate.slicer(start, length, slicelen)) else: return Seq.map( (lambda s: g_leftclosed(s, buf, cuts, levelcount - 1)), covariate.slicer(start, length, slicelen))
def __call__(self, start, length, slicelen): assert start >= 0 and start < len(self.vector) length = min(length, len(self.vector) - start) slicelen = min(length, slicelen) state = start, length, slicelen def f(from_to): return self.vector[from_to[0]:from_to[1]] return Seq.map(f, Seq.from_next(state, next_slice_indices))
def __call__(self, start, length, slicelen): dtypes = [f.slicer.dtype for f in self.factors] alluint8 = all([d == np.uint8 for d in dtypes]) dtype = np.uint8 if alluint8 else np.uint16 k = len(self.factors) buf = np.empty((k, slicelen), dtype=dtype) def f(slices): n = len(slices[0]) for i in range(k): if dtypes[i] == dtype: buf[i, :n] = slices[i] else: buf[i, :n] = slices[i].astype(dtype) if n == slicelen: return buf else: return buf[:, :n] return Seq.map( f, Seq.zip(*[f.slicer(start, length, slicelen) for f in self.factors]))
def slicer(start, length, slicelen): length = min(self._length - start, length) slicelen = min(length, slicelen) buf = np.ones(slicelen, dtype = np.uint8) return Seq.map((lambda x: buf[x[0]:x[1]]), Seq.from_next((start, length, slicelen), ch.next_slice_indices))
def f(start, length, slicelen): buf = np.empty(slicelen, dtype=np.float32) return Seq.map((lambda s: g(s, buf)), vslicer(start, length, slicelen))
def slice(start, length, slicelen): buf = np.empty(slicelen, dtype = np.float32) return Seq.map((lambda slice: g_parse(slice, buf, parsed)), basefactor.slicer(start, length, slicelen))