Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/config.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[setup . (simplify search)]
[localize . (costs errors)]
[generate . (rr taylor simplify proofs)]
[reduce . (regimes avg-error binary-search branch-expressions)]
[reduce . (regimes binary-search branch-expressions)]
[rules
. (arithmetic polynomials
fractions
Expand All @@ -52,6 +52,10 @@
(eprintf "The generate:better-rr option has been removed.\n")
(eprintf " The current recursive rewriter does not support the it.\n")
(eprintf "See <https://herbie.uwplse.org/doc/~a/options.html> for more.\n" *herbie-version*)]
[('reduce 'avg-error)
(eprintf "The reduce:avg-error option has been removed.\n")
(eprintf " Herbie now always uses average error for pruning.\n")
(eprintf "See <herbie://herbie.uwplse.org/doc/~a/options.html> for more.\n" *herbie-version*)]
[(_ _) (void)]))

(define (enable-flag! category flag)
Expand Down
45 changes: 19 additions & 26 deletions src/core/points.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
(define *pcontext* (make-parameter #f))
(struct pcontext (points exacts) #:prefab)

(define (in-pcontext context)
(in-parallel (in-vector (pcontext-points context)) (in-vector (pcontext-exacts context))))
(define (in-pcontext pcontext)
(in-parallel (in-vector (pcontext-points pcontext)) (in-vector (pcontext-exacts pcontext))))

(define (pcontext-length context)
(vector-length (pcontext-points context)))
(define (pcontext-length pcontext)
(vector-length (pcontext-points pcontext)))

(define/contract (mk-pcontext points exacts)
(-> (non-empty-listof (listof any/c)) (non-empty-listof any/c) pcontext?)
Expand All @@ -41,46 +41,39 @@
(for/lists (pts* exs*) ([(pt ex) (in-pcontext pcontext)] other ...) body ...)])
(mk-pcontext pts* exs*)))

(define (split-pcontext context num-a num-b)
(define num-total (vector-length (pcontext-points context)))
(unless (= (+ num-a num-b) num-total)
(error 'split-pcontext "Cannot split pcontext of size ~a into ~a and ~a" num-total num-a num-b))
(match-define (pcontext pts exs) context)
(define (split-pcontext pctx num-a num-b)
(match-define (pcontext pts exs) pctx)
(unless (= (+ num-a num-b) (vector-length pts))
(error 'split-pcontext
"Cannot split pcontext of size ~a into ~a and ~a"
(vector-length pts)
num-a
num-b))
(define-values (pts-a pts-b) (vector-split-at pts num-a))
(define-values (exs-a exs-b) (vector-split-at exs num-a))
(values (pcontext pts-a exs-a) (pcontext pts-b exs-b)))

;; Herbie's standard error measure is the average bits of error across
;; all points in a pcontext.

(define (point-error out exact repr)
(if ((representation-special-value? repr) out)
(+ 1 (expt 2 (representation-total-bits repr)))
(ulp-difference out exact repr)))

(define (average . s)
(/ (apply + s) (length s)))

(define (errors-score e)
(apply (if (flag-set? 'reduce 'avg-error) average max) (map ulps->bits e)))
(apply average (map ulps->bits e)))

(define (errors expr pcontext ctx)
(map first (batch-errors (list expr) pcontext ctx)))

(define ((batch-errors-handler exprs point) e)
(raise e)
(eprintf "Error during batch-errors with exprs:\n")
(for ([expr (in-list exprs)])
(eprintf " ~a\n" expr))
(eprintf "on point ~a\n" point)
(raise e))

(define (batch-errors exprs pcontext ctx)
(define fn (compile-progs exprs ctx))
(define repr (context-repr ctx))
(define special? (representation-special-value? repr))
(define max-error (+ 1 (expt 2 (representation-total-bits repr))))

(for/list ([(point exact) (in-pcontext pcontext)])
(with-handlers ([exn:fail? (batch-errors-handler exprs point)])
(for/list ([out (in-vector (apply fn point))])
(point-error out exact (context-repr ctx))))))
(for/list ([out (in-vector (apply fn point))])
(if (special? out) max-error (ulp-difference out exact repr)))))

;; Herbie <=> JSON conversion for pcontext
;; A JSON pcontext is just a list of lists
Expand Down
Loading