-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtools.py
executable file
·30 lines (27 loc) · 1.1 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def cartesian_product(sequences):
# TODO: Rename this. It's not good that we have two functions
# called "product" and "cartesian_product", of which "product"
# computes cartesian products, while "cartesian_product" does not.
# This isn't actually a proper cartesian product because we
# concatenate lists, rather than forming sequences of atomic elements.
# We could probably also use something like
# map(itertools.chain, product(*sequences))
# but that does not produce the same results
if not sequences:
yield []
else:
temp = list(cartesian_product(sequences[1:]))
for item in sequences[0]:
for sequence in temp:
yield item + sequence
def get_peak_memory_in_kb():
try:
# This will only work on Linux systems.
with open("/proc/self/status") as status_file:
for line in status_file:
parts = line.split()
if parts[0] == "VmPeak:":
return int(parts[1])
except IOError:
pass
raise Warning("warning: could not determine peak memory")