def main(_): # Init os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" np.random.seed(1) random.seed(a=1, version=2) # Load configuration config = get_parameters(reproduce=None, gpu=-1) print(config) # Load Dataset data = KBDataset(config.data) print(data) # tensorflow config #tf_config = tf.ConfigProto(gpu_options=tf.GPUOptions( # visible_device_list=str(config.gpu))) tf_config = tf.ConfigProto() tf_config.gpu_options.allow_growth = True sess = tf.Session(config=tf_config) # Model Loading if config.model == "transe": model = TransE(config, data.nent, data.nrel) else: model = TorusE(config, data.nent, data.nrel) optimizer = tf.train.GradientDescentOptimizer(config.lr) # global_step = tf.Variable(0, name="gb", trainable=False) cal_gradient = optimizer.compute_gradients(model.loss) train_opt = optimizer.apply_gradients(cal_gradient) # Config Saver and Session saver = tf.train.Saver(max_to_keep=100) sess.run(tf.global_variables_initializer()) # Training base.train(data, model, train_opt, config, sess, saver) # Testing base.test(data, model, sess)
def main(argv=None): base.test()
result, fname = wapisp.GetOpenFileName(hPygameWindow) if result: try: with open(fname, "rb") as f: player = pickle.load(f) player.load() LoadPlayer(player) # pManager.getPlayer().load() # LoadMap(pManager.getPlayer().getPos()) except: pass uMenu.release(wm) # Battle if pManager.isBattleNeeded() and not uBattle.isRunning(): isWildWater = base.test(terrain.getProperty(*pManager.getPlayer().getPos()), 4) if isWildWater: if g_cm.getType() == maps.MAP_TYPE_GRASS: g_cm.setType(maps.MAP_TYPE_GRASSWATER) elif g_cm.getType() == maps.MAP_TYPE_ROCK: g_cm.setType(maps.MAP_TYPE_ROCKWATER) else: if g_cm.getType() == maps.MAP_TYPE_GRASSWATER: g_cm.setType(maps.MAP_TYPE_GRASS) elif g_cm.getType() == maps.MAP_TYPE_ROCKWATER: g_cm.setType(maps.MAP_TYPE_ROCK) uBattle.setBackground(g_cm.getBattleBk()) uBattle.setFightingObjects(player, g_cm.getWildPlayer()) uBattle.init(evt, wm) elif evt.isKeyHit(pygame.K_0): uBattle.release(wm) result = uBattle.render(evt, wm)[1] if result is not None and result != 0:
import base from ch5 import EXPECTED, NOT_EXPECTED EXPECTED += [ "mail0 test OK!", "mail1 test OK!", "mail2 test OK!", "mail3 test OK!", ] TEMP = [ "ch6 Usertests passed!", ] if __name__ == '__main__': base.test(EXPECTED + TEMP, NOT_EXPECTED)
import base from ch2 import EXPECTED, NOT_EXPECTED EXPECTED += [ "Test set_priority OK!", r"get_time OK! (\d+)", "Test sleep OK!", r"current time_msec = (\d+)", r"time_msec = (\d+) after sleeping (\d+) ticks, delta = (\d+)ms!", "Test sleep1 passed!", ] if __name__ == '__main__': base.test(EXPECTED, NOT_EXPECTED)
import itertools def isOk(passwd): if base.hasValue(lambda p: p[0] > p[1], base.pairwise(passwd)): return False return max([base.ilen(g) for _, g in itertools.groupby(passwd)]) > 1 def isOk2(passwd): if base.hasValue(lambda p: p[0] > p[1], base.pairwise(passwd)): return False return 2 in [base.ilen(g) for _, g in itertools.groupby(passwd)] def countPasswords(start, end, fn): return base.countIf(fn, map(str, range(start, end))) base.test(isOk('111111'), True) base.test(isOk('223450'), False) base.test(isOk('123789'), False) print('res1', countPasswords(145852, 616942, isOk)) base.test(isOk2('111111'), False) base.test(isOk2('123444'), False) base.test(isOk2('111122'), True) print('res2', countPasswords(145852, 616942, isOk2))
while True: if mem[idx] == 1: mem[mem[idx + 3]] = mem[mem[idx + 1]] + mem[mem[idx + 2]] idx += 4 elif mem[idx] == 2: mem[mem[idx + 3]] = mem[mem[idx + 1]] * mem[mem[idx + 2]] idx += 4 elif mem[idx] == 99: break else: print("crash", idx, mem[idx]) break return mem base.test([30, 1, 1, 4, 2, 5, 6, 0, 99], compute([1, 1, 1, 4, 99, 5, 6, 0, 99])) data[1] = 12 data[2] = 2 print('res1', compute(data)[0]) for noun in range(0, 99): for verb in range(0, 99): data[1] = noun data[2] = verb res = compute(data)[0] if res == 19690720: print('res2', 100 * noun + verb) exit