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
10 import matplotlib
.pyplot
as plt
15 # build/bin/ulp -e .0001 log 0.5 2.0 2345678 | math/tools/plot.py
19 return float.fromhex(s
)
27 # Has to match the format used in ulp.c
28 r
= re
.compile(r
"[^ (]+\(([^ )]*)\) got ([^ ]+) want ([^ ]+) [^ ]+ ulp err ([^ ]+)")
40 elif line
.startswith("PASS") or line
.startswith("FAIL"):
41 # Print the summary line
46 def plot(xs
, gs
, ys
, es
):
48 print("not enough samples")
52 fig
, (ax0
, ax1
) = plt
.subplots(nrows
=2)
53 es
= np
.abs(es
) # ignore the sign
55 ax0
.text(a
+ (b
- a
) * 0.7, emax
* 0.8, "%s\n%g" % (emax
.hex(), emax
))
56 ax0
.plot(xs
, es
, "r.")
58 ax1
.plot(xs
, ys
, "r.", label
="want")
59 ax1
.plot(xs
, gs
, "b.", label
="got")
65 xs
, gs
, ys
, es
= parse(sys
.stdin
)