-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (23 loc) · 705 Bytes
/
utils.py
File metadata and controls
35 lines (23 loc) · 705 Bytes
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
import logging
def chunk(stream, chunk_size):
buf = []
for item in stream:
buf.append(item)
if len(buf) >= chunk_size:
yield buf
del buf[:]
if len(buf) > 0:
yield buf
def split_column(m, col_sizes):
offset = 0
splits = []
for colsize in col_sizes:
splits.append(m[:, offset:(offset + colsize)])
offset += colsize
assert offset == m.shape[1]
return splits
def config_logging(fname):
logging.basicConfig(level=logging.INFO, format='%(message)s') # re-format to remove prefix 'INFO:root'
fh = logging.FileHandler(fname)
fh.setLevel(logging.INFO)
logging.getLogger("").addHandler(fh)