-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
62 lines (33 loc) · 1001 Bytes
/
utils.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# encode: utf8
from __future__ import print_function
import numpy as np
def to_array(x):
return np.array(x, dtype=float)
def to_array_list(lst):
return [to_array(x) for x in lst]
def get_unit_vector(dim, idx):
unit = np.zeros(dim)
unit[idx] = 1
return unit
def is_pos(x, eps=1e-10):
return x > eps
def is_neg(x, eps=1e-10):
return x < -eps
def is_zero(x, eps=1e-10):
return abs(x) <= eps
def is_pos_zero(x, eps=1e-10):
return is_pos(x, eps) or is_zero(x, eps)
def is_neg_zero(x, eps=1e-10):
return is_neg(x, eps) or is_zero(x, eps)
def is_pos_all(arr, eps=1e-10):
return all(is_pos(x) for x in arr)
def is_neg_all(arr, eps=1e-10):
return all(is_neg(x) for x in arr)
def is_integer(x, eps=1e-10):
return is_zero(x - round(x))
def is_integer_list(arr, eps=1e-10):
return all(is_integer(i, eps) for i in arr)
def floor_residue(x):
return x - np.floor(x)
def take_index(arr, idxs):
return [arr[i] for i in idxs]