-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.py
57 lines (49 loc) · 1.04 KB
/
scale.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
from two_sum import two_sum
from two_product import two_product
def robust_scale(e, scale):
"""
robust scale
:param e:
:param scale:
:return:
"""
return scaleLinearExpansion(e, scale)
def scaleLinearExpansion(e, scale):
n = len(e)
if n == 1:
ts = two_product(e[0], scale)
if ts[0]:
return ts
return ts[1],
g = [0] * (2 * n)
q = [0.1, 0.1]
t = [0.1, 0.1]
count = 0
q = list(two_product(e[0], scale))
if q[0]:
g[count] = q[0]
count += 1
for i in range(1, n):
t = two_product(e[i], scale)
pq = q[1]
q = two_sum(pq, t[0])
if q[0]:
g[count] = q[0]
count += 1
a = t[1]
b = q[1]
x = a + b
bv = x - a
y = b - bv
q = list(q)
q[1] = x
if y:
g[count] = y
count += 1
if q[1]:
g[count] = q[1]
count += 1
if count == 0:
g[count] = 0.0
count += 1
return tuple(g[:count])