|
11 | 11 | [label trees]
|
12 | 12 | (letfn [(walk-trees [net-map trees super-path]
|
13 | 13 | (reduce
|
14 |
| - (fn [net-map [tree-type id sub-trees xf label]] |
| 14 | + (fn [net-map [tree-type id sub-trees value label]] |
15 | 15 | (let [node-path [tree-type id]]
|
16 | 16 | (cond-> net-map
|
17 |
| - (not (nil? xf)) |
18 |
| - (assoc-in (conj node-path :xf) xf) |
| 17 | + (not (nil? value)) |
| 18 | + (assoc-in (conj node-path :value) value) |
19 | 19 |
|
20 | 20 | (not (nil? label))
|
21 | 21 | (assoc-in (conj node-path :label) label)
|
|
30 | 30 | (normalize-inputs trees)))]
|
31 | 31 | (walk-trees {:label label} trees nil)))
|
32 | 32 |
|
33 |
| -(defn postwalk [net-xf roots update-fn] |
34 |
| - (let [orig-net-map (net-xf) |
35 |
| - kids (case roots :input :outputs :inputs) |
| 33 | +(defn postwalk [orig-net-map roots update-fn] |
| 34 | + (let [kids (case roots :input :outputs :inputs) |
36 | 35 | root-paths (for [k (-> orig-net-map roots keys)]
|
37 | 36 | [roots k])]
|
38 | 37 |
|
|
68 | 67 | (defn input [k] (list :input k #{}))
|
69 | 68 | (defn output [k inputs] (list :output k (assert-no-outputs inputs)))
|
70 | 69 |
|
71 |
| -(defn node* [label xf inputs] |
| 70 | +(defn node* [label value inputs] |
72 | 71 | (list :node
|
73 | 72 | (gensym 'n)
|
74 | 73 | (assert-no-outputs inputs)
|
75 |
| - xf |
| 74 | + value |
76 | 75 | label))
|
77 | 76 |
|
78 |
| -(defn embed [net-xf input-map] |
79 |
| - (-> net-xf |
| 77 | +(defn embed [net-map input-map] |
| 78 | + (-> net-map |
80 | 79 | (postwalk
|
81 | 80 | :output
|
82 |
| - (fn [[node-type node-id] {xf :xf label :label} input-xfs] |
| 81 | + (fn [[node-type node-id] {value :value label :label} inputs] |
83 | 82 | (condp = node-type
|
84 | 83 | :input (input-map node-id)
|
85 |
| - :node (node* label xf (set input-xfs)) |
86 |
| - :output (set input-xfs)))) |
| 84 | + :node (node* label value (set inputs)) |
| 85 | + :output (set inputs)))) |
87 | 86 | :output))
|
88 | 87 |
|
89 | 88 | ;; printing/debugging
|
|
99 | 98 | (map (fn [[k {:keys [inputs]}]]
|
100 | 99 | [k :inputs (compact-paths inputs)])
|
101 | 100 | (:output net-map)))))
|
102 |
| - |
103 |
| -(defn pr-net [net-xf] |
104 |
| - (compact-net-map (net-xf))) |
0 commit comments