def originalRandom(self): ladders = [[1, 38], [4, 14], [9, 31], [21, 42], [28, 84], [36, 44], [51, 67], [71, 91], [80, 100]] snakes = [[16, 6], [47, 26], [49, 11], [56, 53], [62, 19], [64, 60], [87, 24], [93, 73], [95, 75], [98, 78]] ele1 = [] ele2 = [] ele3 = [] ele4 = [] for x in ladders: ele1.append(x[0]) ele2.append(x[1]) for x in snakes: ele3.append(x[0]) ele4.append(x[1]) random.shuffle(ele1) random.shuffle(ele2) random.shuffle(ele3) random.shuffle(ele4) la = list(more_itertools.zip_equal(ele1, ele2)) sn = list(more_itertools.zip_equal(ele3, ele4)) sl = [list(x) for x in la] sn = [list(x) for x in sn] for ele in sn: if ele[0] < ele[1]: ele[0], ele[1] = ele[1], ele[0] for ele in sl: if ele[0] > ele[1]: ele[0], ele[1] = ele[1], ele[0] return sn + sl
def test_reagent_config(db, config_cls, obj, db_access, key, expected, info, monkeypatch, mock_plugins): db.name = '/path/to/db' config = config_cls(obj) layer = one(config.load()) if db_access == 'cache': layer.db = db if db_access.startswith('obj'): attr = db_access.split('.')[1] if '.' in db_access else 'db' setattr(obj, attr, db) if db_access == 'load': monkeypatch.setattr(freezerbox.model, 'load_db', lambda: db) else: monkeypatch.setattr(freezerbox.model, 'load_db', lambda: NotImplemented) log = Log() values = list(layer.iter_values(key, log)) assert values == expected for actual, pattern in zip_equal(log.err.info_strs, info): Matches(pattern).assert_matches(actual)
def forward(self, latent, noises=None): if noises is None: noises = [None] * (1 + len(self.synthesiser)) assert len(noises) == 1 + len(self.synthesiser) style = self.mapping(latent) image = self.start(len(style), noise=noises[0]) for level, noise in zip_equal(self.synthesiser, noises[1:]): image = level(image, style) return self.output(image)
def test_product_configs(db, config_cls, products, products_attr, key, expected, info, error, mock_plugins): db.name = 'path/to/db' if not products: products = db.keys() obj = MockObj() if products_attr: setattr(obj, products_attr, [db[k].make_intermediate(i) for k, i in products.items()]) config = config_cls(obj) layer = one(config.load()) with error: log = Log() values = list(layer.iter_values(key, log)) pprint(log.err.info_strs) assert values == expected for actual, pattern in zip_equal(log.err.info_strs, info): Matches(pattern).assert_matches(actual)
def zip(*iterables, strict=False): if strict: return zip_equal(*iterables) else: return __builtins__.zip(*iterables)
def iter_plots(labels, img, divs): for label, (i, j) in mi.zip_equal(labels, mi.pairwise(divs)): yield label, img[i+1:j,1:-1]