-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.py
More file actions
51 lines (36 loc) · 1.29 KB
/
utils.py
File metadata and controls
51 lines (36 loc) · 1.29 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
from time import time
import logging, inspect
import pickle as pickle
from itertools import islice
import os.path
dir_f = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
folder_pickles = dir_f + "/pickles/"
def returnPathStruc2vec():
return dir_f
def isPickle(fname):
return os.path.isfile(dir_f + '/pickles/' + fname + '.pickle')
def chunks(data, SIZE=10000):
it = iter(data)
for i in range(0, len(data), SIZE):
yield {k: data[k] for k in islice(it, SIZE)}
def partition(lst, n):
division = len(lst) / float(n)
return [lst[int(round(division * i)): int(round(division * (i + 1)))] for i in range(n)]
def restoreVariableFromDisk(name):
logging.debug('Recovering variable...')
t0 = time()
val = None
with open(folder_pickles + name + '.pickle', 'rb') as handle:
val = pickle.load(handle)
t1 = time()
logging.debug('Variable recovered. Time: {}m'.format((t1 - t0) / 60))
return val
def saveVariableOnDisk(f, name):
# print('Saving variable on disk...')
t0 = time()
with open(folder_pickles + name + '.pickle', 'wb') as handle:
pickle.dump(f, handle, protocol=pickle.HIGHEST_PROTOCOL)
t1 = time()
# print('Variable saved. Time: {}m'.format((t1 - t0) / 60))
return