Skip to content

Commit 79834d1

Browse files
committed
Merge branch 'main' into explanations-endpoint-revised
2 parents 4eff2ff + 697848d commit 79834d1

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; This example is taken from the Image Processing domain and referred to
2+
; as "Logarithmic Transform". This in its basic form is used to bring out
3+
; details in dark parts of an image. This instantiation of the idea is for 1D
4+
; as opposed to 2D images.
5+
6+
(FPCore (c x y)
7+
:name "Logarithmic Transform"
8+
:alt
9+
(* c (log1p (* (expm1 x) y)))
10+
11+
(* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))

src/core/egg-herbie.rkt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@
207207
(define (egraph-eclasses egraph-data)
208208
(egraph_get_eclasses (egraph-data-egraph-pointer egraph-data)))
209209

210+
(define empty-u32vec (make-u32vector 0))
211+
210212
;; Extracts the nodes of an e-class as a vector
211213
;; where each enode is either a symbol, number, or list
212214
(define (egraph-get-eclass egraph-data id)
@@ -217,7 +219,7 @@
217219
(for ([enode (in-vector eclass)]
218220
[i (in-naturals)])
219221
(when (and (symbol? enode) (not (hash-has-key? egg->herbie enode)))
220-
(vector-set! eclass i (cons enode (make-u32vector 0)))))
222+
(vector-set! eclass i (cons enode empty-u32vec))))
221223
eclass)
222224

223225
(define (egraph-find egraph-data id)
@@ -1204,36 +1206,21 @@
12041206
(define root-ids (egraph-add-exprs egg-graph exprs ctx))
12051207

12061208
; run the schedule
1207-
(define rule-apps (make-hash))
12081209
(define egg-graph*
1209-
(for/fold ([egg-graph egg-graph]) ([instr (in-list schedule)])
1210-
(match-define (cons rules params) instr)
1210+
(for/fold ([egg-graph egg-graph]) ([(rules params) (in-dict schedule)])
12111211
; run rules in the egraph
12121212
(define egg-rules (expand-rules rules))
12131213
(define-values (egg-graph* iteration-data) (egraph-run-rules egg-graph egg-rules params))
12141214

12151215
; get cost statistics
1216-
(for/fold ([time 0])
1217-
([iter (in-list iteration-data)]
1218-
[i (in-naturals)])
1216+
(for ([iter (in-list iteration-data)]
1217+
[i (in-naturals)])
12191218
(define cnt (iteration-data-num-nodes iter))
12201219
(define cost (apply + (map (λ (id) (egraph-get-cost egg-graph* id i)) root-ids)))
1221-
(define new-time (+ time (iteration-data-time iter)))
1222-
(timeline-push! 'egraph i cnt cost new-time)
1223-
new-time)
1224-
1225-
;; get rule statistics
1226-
(for ([(egg-rule ffi-rule) (in-dict egg-rules)])
1227-
(define count (egraph-get-times-applied egg-graph* ffi-rule))
1228-
(define canon-name (hash-ref (*canon-names*) (rule-name egg-rule)))
1229-
(hash-update! rule-apps canon-name (curry + count) count))
1220+
(timeline-push! 'egraph i cnt cost (iteration-data-time iter)))
12301221

12311222
egg-graph*))
12321223

1233-
; report rule statistics
1234-
(for ([(name count) (in-hash rule-apps)])
1235-
(when (> count 0)
1236-
(timeline-push! 'rules (~a name) count)))
12371224
; root eclasses may have changed
12381225
(define root-ids* (map (lambda (id) (egraph-find egg-graph* id)) root-ids))
12391226
; return what we need

0 commit comments

Comments
 (0)