Skip to content

Commit

Permalink
Found exacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Sep 1, 2024
1 parent ac26110 commit 33a17c1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/core/localize.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,16 @@

(define subexprs-fn (eval-progs-real (map prog->spec exprs-list) ctx-list))

; Mutable error hack, this is bad
(define errs
(for/vector #:length (vector-length roots)
([node (in-vector roots)])
(make-vector (pcontext-length (*pcontext*)))))

(define exacts-out
(for/vector #:length (vector-length roots)
([node (in-vector roots)])
(make-vector (pcontext-length (*pcontext*)))))

(for ([(pt ex) (in-pcontext (*pcontext*))]
[pt-idx (in-naturals)])
(define exacts (list->vector (apply subexprs-fn pt)))
Expand All @@ -154,12 +158,17 @@
(vector-ref exacts (vector-member idx roots)))) ; arg's index mapping to exact
(define approx (apply (impl-info f 'fl) argapprox))
(ulp-difference exact approx repr)]))
(vector-set! (vector-ref exacts-out expr-idx) pt-idx exact)
(vector-set! (vector-ref errs expr-idx) pt-idx err)))

(define n 0)
(for/list ([subexprs (in-list subexprss)])
(for*/hash ([subexpr (in-list subexprs)])
(begin0 (values subexpr (vector->list (vector-ref errs n)))
(begin0 (values subexpr
(hasheq 'errs
(vector->list (vector-ref errs n))
'exacts
(vector->list (vector-ref exacts-out n))))
(set! n (add1 n))))))

;; Compute the local error of every subexpression of `prog`
Expand All @@ -168,6 +177,9 @@
(define (local-error-as-tree expr ctx)
(define errs (first (compute-local-errors (list (all-subexpressions expr)) ctx)))
(let loop ([expr expr])
(define expr-info (hash-ref errs expr))
(define err-list (hash-ref expr-info 'errs))
(define exacts-list (hash-ref expr-info 'errs))
(match expr
[(list op args ...) (cons (hash-ref errs expr) (map loop args))]
[_ (list (hash-ref errs expr))])))
[(list op args ...) (cons err-list (map loop args))]
[_ (list err-list)])))

0 comments on commit 33a17c1

Please sign in to comment.