aboutsummaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2019-07-18 12:00:07 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2019-07-22 17:03:57 +0100
commitd8114c3bdf5f7cab17dffad0751d0bbf46f4530e (patch)
treeb198db3dfb87dee4cda4d855a007042c28ad1a94 /math
parent0af9fce0348b2ce7834499b033d3d75700b3c815 (diff)
downloadarm-optimized-routines-d8114c3bdf5f7cab17dffad0751d0bbf46f4530e.tar.gz
Add ULP error plot script
Simple script to visualize the output of the ulp test tool, e.g. $ build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py
Diffstat (limited to 'math')
-rwxr-xr-xmath/tools/plot.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/math/tools/plot.py b/math/tools/plot.py
new file mode 100755
index 0000000..09c8ec6
--- /dev/null
+++ b/math/tools/plot.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+
+# ULP error plot tool.
+#
+# Copyright (c) 2019, Arm Limited.
+# SPDX-License-Identifier: MIT
+
+import numpy as np
+import matplotlib.pyplot as plt
+import sys
+import re
+
+# example usage:
+# build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py
+
+def fhex(s):
+ return float.fromhex(s)
+
+def parse(f):
+ xs = []
+ ys = []
+ es = []
+ # Has to match the format used in ulp.c
+ r = re.compile(r'[^ (]+\(([^ )]*)\) got [^ ]+ want ([^ ]+) [^ ]+ ulp err ([^ ]+)')
+ for line in f:
+ m = r.match(line)
+ if m:
+ x = fhex(m.group(1))
+ y = fhex(m.group(2))
+ e = float(m.group(3))
+ xs.append(x)
+ ys.append(y)
+ es.append(e)
+ elif line.startswith('PASS') or line.startswith('FAIL'):
+ # Print the summary line
+ print(line)
+ return xs, ys, es
+
+def plot(xs, ys, es):
+ if len(xs) < 2:
+ print('not enough samples')
+ return
+ a = min(xs)
+ b = max(xs)
+ fig, (ax0,ax1) = plt.subplots(nrows=2)
+ es = map(abs, es) # ignore the sign
+ emax = max(es)
+ ax0.text(a+(b-a)*0.7, emax*0.8, '%s\n%g'%(emax.hex(),emax))
+ ax0.plot(xs,es,'rx')
+ ax0.grid()
+ ax1.plot(xs,ys,'rx')
+ ax1.grid()
+ plt.show()
+
+xs, ys, es = parse(sys.stdin)
+plot(xs, ys, es)