def _parsevals(self, value): if isinstance(value, StructuredArray): return [value._arrs[n].copy() for n in self._arrs.keys()] if not iterable(value): return value value = ll(value) if not iterable(value[0]): return np.asarray(value) value = smap(value, lambda x: np.asarray(ll(x))) if not len(set(smap(value, len))) == 1: raise ValueError('input arrays not in the same size') return value
def asMatrix(val: Iterable[Iterable], nrow: Optional[int] = None, ncol: Optional[int] = None, rownames: Optional[Iterable] = None, colnames: Optional[Iterable] = None) -> robj.Matrix: if not (isinstance(val, np.ndarray) and val.ndim == 2): val = np.asarray(smap(val, ll)) if missing(nrow) and missing(ncol): nrow, ncol = val.shape matx = robj.r.matrix(val, nrow=nrow, ncol=ncol) if available(rownames): matx.rownames = robj.StrVector(np.asarray(ll(rownames), dtype=str)) if available(colnames): matx.colnames = robj.StrVector(np.asarray(ll(colnames), dtype=str)) return matx
def asVector(val: Iterable, names: Optional[Iterable] = None) -> robj.Vector: val = np.asarray(ll(val)) vect = { 'i': robj.IntVector, 'u': robj.IntVector, 'f': robj.FloatVector, 'b': robj.BoolVector, 'S': robj.StrVector, 'U': robj.StrVector, }.get(val.dtype.kind, lambda x: None)(val) if missing(vect): raise TypeError(f'unknown vector type [{val.dtype.kind}]') if available(names): vect.names = robj.StrVector(np.asarray(ll(names), dtype=str)) return vect
def _parsevals(self, value): if isinstance(value, Table): return value._dmatx.astype(self.dtype) if isinstance(value, np.ndarray): return value.astype(self.dtype) if not iterable(value): return value value = ll(value) if not iterable(value[0]): return np.asarray(value, dtype = self.dtype) value = np.asarray(value if isinstance(value, np.ndarray) and value.ndim == 2 else smap(value, ll), dtype = self.dtype) return value
def mapexec(self, params: Optional[Iterable[Sequence]] = None, stdin: Optional[Iterable[Union[bytes, str]]] = None, timeout: Optional[int] = None, nthreads: Optional[int] = None, nprocs: Optional[int] = None) -> List[Tuple[int, List[str]]]: if available(params): params = ll(params) if available(stdin): stdin = ll(stdin) if available(params) and available( stdin) and len(params) != len(stdin): raise RuntimeError('parameters and stdins size not match') if missing(params) and missing(stdin): raise RuntimeError('both parameters and stdins are missing') n = len(params) mpms = [(p, s, timeout) for p, s in zip(optional(params, [None] * n), optional(stdin, [None] * n))] _map = partial(pmap, nprocs = nprocs) if available(nprocs) else \ partial(tmap, nthreads = nthreads) if available(nthreads) else smap return _map(mpms, self._exec)
def __init__(self, binary: Union[str, Path], shell: bool = False, normcodes: Union[int, Iterable[int]] = 0, mute: bool = False): self._bin = self.which(binary) if missing(self._bin): raise RuntimeError(f'binary executable [{binary}] not reachable') self._shell = shell self._ncode = (normcodes, ) if isinstance(normcodes, int) else ll(normcodes) self._mute = mute
def _parsevals(value, arrayonly=False): if isinstance(value, NamedIndex): val = value._names elif iterable(value): val = np.asarray(ll(value), dtype=object) if checkany(val, lambda x: not isstring(x)): raise TypeError('index names must be string') else: if arrayonly: raise TypeError('index names must be an array') if not isstring(value): raise TypeError('index name must be a string') val = value return val