Skip to content

Commit 0946c43

Browse files
committed
Use the samplers
1 parent 2b9d671 commit 0946c43

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

src/syntax/test-rules.rkt

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,15 @@
1010

1111
;; WARNING: These aren't treated as preconditions, they are only used for range inference
1212
(define *conditions*
13-
`([acosh-def . (>= x 1)]
14-
[atanh-def . (< (fabs x) 1)]
15-
[asin-acos . (<= -1 x 1)]
16-
[acos-asin . (<= -1 x 1)]
17-
[acosh-2 . (>= x 1)]
18-
[asinh-2 . (>= x 0)]
19-
[sinh-acosh . (> (fabs x) 1)]
20-
[sinh-atanh . (< (fabs x) 1)]
21-
[cosh-atanh . (< (fabs x) 1)]
22-
[tanh-acosh . (> (fabs x) 1)]
23-
;; These next three unquote the pi computation so that range analysis will work
24-
[asin-sin-s . (<= (fabs x) ,(/ pi 2))]
25-
[acos-cos-s . (<= 0 x ,pi)]
26-
[atan-tan-s . (<= (fabs x) ,(/ pi 2))]))
13+
`([asinh-2 . (>= x 0)]
14+
;; These next three approximate pi so that range analysis will work
15+
[asin-sin-s . (<= (fabs x) 1.5708)]
16+
[acos-cos-s . (<= 0 x 3.1415)]
17+
[atan-tan-s . (<= (fabs x) 1.5708)]))
2718

2819
(define (ival-ground-truth fv p repr)
29-
(λ (x) (ival-eval (eval-prog `(λ ,fv ,p) 'ival repr) x repr)))
20+
(define prog (eval-prog `(λ ,fv ,p) 'ival repr))
21+
(λ (x) (ival-eval prog x repr)))
3022

3123
(define ((with-hiprec f) x)
3224
(parameterize ([bf-precision 2000]) (apply f x)))
@@ -41,19 +33,11 @@
4133
(define repr (get-representation* otype))
4234

4335
(define make-point
44-
(let ([sample (make-sampler
45-
repr
46-
`(λ ,fv ,(dict-ref *conditions* name 'TRUE))
47-
`(λ ,fv ,p1)
48-
`(λ ,fv ,p2))])
49-
(λ ()
50-
(if (dict-has-key? *conditions* name)
51-
(sample)
52-
(for/list ([v fv] [i (in-naturals)])
53-
(match (dict-ref (rule-itypes test-rule) v)
54-
['real (sample-double)]
55-
['complex (make-rectangular (sample-double) (sample-double))]
56-
[rname (random-generate (get-representation rname))]))))))
36+
(make-sampler
37+
repr
38+
`(λ ,fv ,(dict-ref *conditions* name 'TRUE))
39+
`(λ ,fv ,p1)
40+
`(λ ,fv ,p2)))
5741

5842
(define points (for/list ([n (in-range num-test-points)]) (make-point)))
5943
(define prog1 (ground-truth fv p1 repr))
@@ -71,8 +55,13 @@
7155
(with-check-info (['point (map cons fv pt)] ['method (object-name ground-truth)]
7256
['input v1] ['output v2])
7357
(check-eq? (ulp-difference v1 v2 repr) 1))))
74-
(when (< (length errs) (/ num-test-points 10))
75-
(fail-check "Not enough points sampled to test rule")))
58+
(define usable-fraction (/ (length errs) num-test-points))
59+
(cond
60+
[(< usable-fraction 1/10)
61+
(fail-check "Not enough points sampled to test rule")]
62+
[(< usable-fraction 8/10)
63+
(eprintf "~a: ~a% of points usable\n" name
64+
(~r (* 100 usable-fraction) #:precision '(= 1)))]))
7665

7766
(define (check-rule-fp-safe test-rule)
7867
(match-define (rule name p1 p2 itypes otype) test-rule)

0 commit comments

Comments
 (0)