Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions qual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python -u
#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-

# This file is part of LibEFT, an error-free transformations library
Expand Down Expand Up @@ -42,7 +42,7 @@ def dot (x, y, f=lambda x: x):
rational numbers.
"""
acc = f(0)
for i in xrange(len(x)):
for i in range(len(x)):
acc += f(x[i]) * f(y[i])
return acc

Expand All @@ -68,18 +68,18 @@ def genDot (n, c):
n2 = int(n / 2)
b = math.log(c) / math.log(2)

e = [random() * b/2 for i in xrange(n2)]
e = [random() * b/2 for i in range(n2)]
e[0] = b/2 + 1 # Make sure exponents b/2
e[n2-1] = 0 # and 0 actually occur
for i in xrange(n2):
for i in range(n2):
x[i] = (2*random()-1) * 2**(e[i])
y[i] = (2*random()-1) * 2**(e[i])


# Second half of the vectors such that
# (*) log2( dot (x[1:i], y[1:i]) ) decreases from b/2 to 0
e = linspace (b/2, 0, n-n2)
for i in xrange(n-n2):
for i in range(n-n2):
# Random x[i]
cx = (2*random()-1) * 2**(e[i])
x[i+n2] = cx
Expand All @@ -90,10 +90,10 @@ def genDot (n, c):


# Random permutation of x and y
perm = range(n); shuffle (perm)
perm = [x for x in range(n)]; shuffle (perm)
X = [0] * n
Y = [0] * n
for i in xrange(n):
for i in range(n):
X[i] = x[perm[i]]
Y[i] = y[perm[i]]

Expand Down Expand Up @@ -136,15 +136,15 @@ def twoSum (a, b):
def dot1 (x,y):
acc = 0
accErr = 0
for i in xrange(len(x)):
for i in range(len(x)):
acc, e = twoSum (acc, x[i] * y[i])
accErr += e
return acc + accErr

def dot2 (x,y):
acc = 0
accErr = 0
for i in xrange(len(x)):
for i in range(len(x)):
p, e = twoProd (x[i], y[i])
acc += p
accErr += e
Expand All @@ -153,7 +153,7 @@ def dot2 (x,y):
def dot3 (x,y):
acc = 0
accErr = 0
for i in xrange(len(x)):
for i in range(len(x)):
p, ep = twoProd (x[i], y[i])
acc, es = twoSum (acc, p)
accErr += ep + es
Expand All @@ -167,15 +167,18 @@ def send (cmd, x, y):
p = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
p.stdin.write("%d\n" % len(x))
for i in xrange(len(x)):
p.stdin.write ("%.18e %.18e\n" % (x[i], y[i]))

return float(p.stdout.read())
data=""
data+=("%d\n" % len(x))
for i in range(len(x)):
data+=("%.18e %.18e\n" % (x[i], y[i]))
stdout,stderr=p.communicate(data.encode("ascii"))
res=float(stdout.decode())
return res

def output (f,x):
out = "%.5e " % x
print out,
print(out)
f.write(out)

if __name__ == "__main__":
Expand Down Expand Up @@ -209,7 +212,7 @@ def output (f,x):
r = send ([test, "dot", version], x, y)
output (f, err(r,d))

print "\n",
print("\n")
f.write ("\n")

c *= step
Expand Down