Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rev_slice_range(self):
r = range(-8, 8)
self.assertRangesEqual(r[::-1], range(7, -9, -1))
self.assertRangesEqual(r[:2:-1], range(7, -6, -1))
self.assertRangesEqual(r[:-2:-1], range(7, 6, -1))
self.assertRangesEqual(r[2::-1], range(-6, -9, -1))
self.assertRangesEqual(r[-2::-1], range(6, -9, -1))
self.assertRangesEqual(r[-2:2:-1], range(6, -6, -1))
def test_stepped_slice_range(self):
r = range(-8, 8)
self.assertRangesEqual(r[::2], range(-8, 8, 2))
self.assertRangesEqual(r[:2:2], range(-8, -6, 2))
self.assertRangesEqual(r[:-2:2], range(-8, 6, 2))
self.assertRangesEqual(r[2::2], range(-6, 8, 2))
self.assertRangesEqual(r[-2::2], range(6, 8, 2))
self.assertRangesEqual(r[2:-2:2], range(-6, 6, 2))
def test_slice_range(self):
r = range(-8, 8)
self.assertRangesEqual(r[:], range(-8, 8))
self.assertRangesEqual(r[:2], range(-8, -6))
self.assertRangesEqual(r[:-2], range(-8, 6))
self.assertRangesEqual(r[2:], range(-6, 8))
self.assertRangesEqual(r[-2:], range(6, 8))
self.assertRangesEqual(r[2:-2], range(-6, 6))
def test_stepped_slice_rev_range(self):
r = range(8, -8, -1)
self.assertRangesEqual(r[::2], range(8, -8, -2))
self.assertRangesEqual(r[:2:2], range(8, 6, -2))
self.assertRangesEqual(r[:-2:2], range(8, -6, -2))
self.assertRangesEqual(r[2::2], range(6, -8, -2))
self.assertRangesEqual(r[-2::2], range(-6, -8, -2))
self.assertRangesEqual(r[2:-2:2], range(6, -6, -2))
`word` before tokenization.
:return: Tuple of n-gram strings.
"""
if ignore is not None:
word = word.replace(ignore, '')
if len(word) == 0:
return tuple()
if n > 1:
word = ' {} '.format(word)
if positional:
# These are 1-indexed.
return ('{} {}'.format(i + 1, word[i:i + n])
for i in range(len(word) - n + 1))
else:
return (word[i:i + n] for i in range(len(word) - n + 1))
else:
old_dur = None
if (
change == u"idd"
and gv.sd[u"idd"]
and len(p[u"duration_sec"]) == 1 # changed from !idd -> idd
):
old_dur = p[u"duration_sec"][0]
p[u"duration_sec"][0] = 0
if gv.sd[u"nst"] > len(p[u"duration_sec"]):
p[u"duration_sec"].extend(
[0] * (gv.sd[u"nst"] - len(p[u"duration_sec"]))
)
if old_dur:
for b in range(
len(p[u"station_mask"])
): # set duration to old_dur for each active station.
for s in range(8):
if p[u"station_mask"][b] & 1 << s:
p[u"duration_sec"][b * 8 + s] = old_dur
elif gv.sd["nst"] < len(p[u"duration_sec"]):
p[u"duration_sec"] = p[u"duration_sec"][: gv.sd[u"nst"]]
if change == u"nbrd": # change length of p["station_mask"]
if gv.sd[u"nbrd"] > len(p[u"station_mask"]):
p[u"station_mask"].extend(
[0] * (gv.sd[u"nbrd"] - len(p[u"station_mask"]))
)
elif gv.sd[u"nbrd"] < len(p[u"station_mask"]):
p[u"station_mask"] = p[u"station_mask"][: gv.sd[u"nbrd"]]
jsave(gv.pd, u"programData")
def reverse_complement(self, number):
"""
Calculate the reverse complement of a DNA sequence in a binary
representation.
:arg int number: Binary representation of a DNA sequence.
:return: Binary representation of the reverse complement of the
sequence corresponding to `number`.
:rtype: int
"""
number = ~number
result = 0x00
for i in range(self.length):
result = (result << 2) | (number & 0x03)
number >>= 2
return result
:return: a TT of dimension N - M
"""
N = t.d
assert np.all(0 <= np.array(modes))
assert np.all(np.array(modes) < N)
if not hasattr(modes, '__len__'):
modes = [modes]
assert len(modes) == len(set(modes)) # Modes may not be repeated
assert 1 <= len(modes) <= N
if centered or normalized:
central_cores = []
cores = tt.vector.to_list(t)
for n in range(N):
if n in modes:
central_cores.append(np.repeat(np.mean(cores[n], axis=1, keepdims=True), cores[n].shape[1], axis=1))
else:
central_cores.append(cores[n])
central = t - tt.vector.from_list(central_cores)
if centered:
if order == 1:
moments = copy.deepcopy(central)
else:
moments = tt.multifuncrs2([central], lambda x: x**order, eps=eps, verb=verbose, **kwargs)
else:
if order == 1:
moments = copy.deepcopy(t)
else:
moments = tt.multifuncrs2([t], lambda x: x**order, eps=eps, verb=verbose, **kwargs)
cores = tt.vector.to_list(moments)
def _init_planting(self):
"""
Initialize the planting inversion.
"""
p = np.zeros(self.nparams, dtype=np.float)
for s in self.seeds:
p[s.index] = s.prop
neighbors = []
nonzero = np.nonzero(p)[0]
for s, seed in enumerate(self.seeds):
tmp = seed.neighbors.difference(nonzero)
for i in range(s):
tmp = tmp.difference(neighbors[i])
neighbors.append(tmp)
misfit = math.sqrt(self.value(p))
compactness = 0
goal = self.shape_of_anomaly(p) + self.mu*compactness
return p, neighbors, misfit, compactness, goal
def add(s):
cpu_times = process.cpu_times()
cpu = cpu_times.user + cpu_times.system
mem = process.memory_info().rss / 2 ** 20 # In Mb
step = Timestep(episode, time.time() - start, cpu, mem, s)
print(step)
timeline.append(step)
if mem > FLAGS.mem_limit:
raise MemoryError("%s Mb mem limit exceeded" % FLAGS.mem_limit)
try:
add("Started process")
controller = proc.controller
for _ in range(FLAGS.episodes):
map_inst = maps.get(random.choice(FLAGS.map))
create = sc_pb.RequestCreateGame(
realtime=False, disable_fog=False, random_seed=episode,
local_map=sc_pb.LocalMap(map_path=map_inst.path,
map_data=map_inst.data(run_config)))
create.player_setup.add(type=sc_pb.Participant)
create.player_setup.add(type=sc_pb.Computer, race=races[FLAGS.race],
difficulty=sc_pb.CheatInsane)
join = sc_pb.RequestJoinGame(race=races[FLAGS.race], options=interface)
controller.create_game(create)
add("Created game on %s" % map_inst.name)
controller.join_game(join)
add("Joined game")
for i in range(2000):
controller.step(16)