def uniform_sample(self, n, remove): assert n >= 0 ixs = list(sample_n_k(self.length, n)) vals = [] if n > 0: for ix in ixs: val = self._write(ix, 0.0) vals.append(val) if not remove: for ix, val in zip(ixs, vals): self._write(ix, val) return ixs, vals
def uniform_sample(self, n: int, remove: bool) -> Tuple[List[int], List[float]]: assert n >= 0 ixs = list(sample_n_k(self.length, n)) vals: List[float] = [] if n > 0: for ix in ixs: val = self._write(ix, 0.0) assert val is not None vals.append(val) if not remove: for ix, val in zip(ixs, vals): self._write(ix, val) return ixs, vals
def _uniform_sample_indices_and_probabilities( self, n: int) -> Tuple[List[int], List[float]]: indices = list(sample_n_k(len(self.data), n)) probabilities = [1 / len(self)] * len(indices) return indices, probabilities
def sample(self, k): return [self[i] for i in sample_n_k(len(self), k)]
def _uniform_sample_indices_and_probabilities(self, n): indices = list(sample_n_k(len(self.data), n)) probabilities = [1 / len(self)] * len(indices) return indices, probabilities
def test_slow(self): self.samples = [sample_n_k(self.n, self.k) for _ in range(10000)] self.subtest_total_counts() self.subtest_order_counts()
def test_fast(self): self.samples = [sample_n_k(self.n, self.k) for _ in range(200)] self.subtest_constraints()