[flang] Use object before converts in fir.dispatch (#68589)
[llvm-project.git] / libc / AOR_v20.02 / math / tools / plot.py
blob9ce6b0308dd57bcb95743bba04b9a3f29f813b5a
1 #!/usr/bin/env python
3 # ULP error plot tool.
5 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 # See https://llvm.org/LICENSE.txt for license information.
7 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 import numpy as np
10 import matplotlib.pyplot as plt
11 import sys
12 import re
14 # example usage:
15 # build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py
18 def fhex(s):
19 return float.fromhex(s)
22 def parse(f):
23 xs = []
24 gs = []
25 ys = []
26 es = []
27 # Has to match the format used in ulp.c
28 r = re.compile(r"[^ (]+\(([^ )]*)\) got ([^ ]+) want ([^ ]+) [^ ]+ ulp err ([^ ]+)")
29 for line in f:
30 m = r.match(line)
31 if m:
32 x = fhex(m.group(1))
33 g = fhex(m.group(2))
34 y = fhex(m.group(3))
35 e = float(m.group(4))
36 xs.append(x)
37 gs.append(g)
38 ys.append(y)
39 es.append(e)
40 elif line.startswith("PASS") or line.startswith("FAIL"):
41 # Print the summary line
42 print(line)
43 return xs, gs, ys, es
46 def plot(xs, gs, ys, es):
47 if len(xs) < 2:
48 print("not enough samples")
49 return
50 a = min(xs)
51 b = max(xs)
52 fig, (ax0, ax1) = plt.subplots(nrows=2)
53 es = np.abs(es) # ignore the sign
54 emax = max(es)
55 ax0.text(a + (b - a) * 0.7, emax * 0.8, "%s\n%g" % (emax.hex(), emax))
56 ax0.plot(xs, es, "r.")
57 ax0.grid()
58 ax1.plot(xs, ys, "r.", label="want")
59 ax1.plot(xs, gs, "b.", label="got")
60 ax1.grid()
61 ax1.legend()
62 plt.show()
65 xs, gs, ys, es = parse(sys.stdin)
66 plot(xs, gs, ys, es)