Skip to content

Commit 96712e9

Browse files
committed
Continue to separate nets from xfnets
1 parent d7e0108 commit 96712e9

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/net/n01se/hassle/net.cljc

+12-16
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
[label trees]
1212
(letfn [(walk-trees [net-map trees super-path]
1313
(reduce
14-
(fn [net-map [tree-type id sub-trees xf label]]
14+
(fn [net-map [tree-type id sub-trees value label]]
1515
(let [node-path [tree-type id]]
1616
(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)
1919

2020
(not (nil? label))
2121
(assoc-in (conj node-path :label) label)
@@ -30,9 +30,8 @@
3030
(normalize-inputs trees)))]
3131
(walk-trees {:label label} trees nil)))
3232

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)
3635
root-paths (for [k (-> orig-net-map roots keys)]
3736
[roots k])]
3837

@@ -68,22 +67,22 @@
6867
(defn input [k] (list :input k #{}))
6968
(defn output [k inputs] (list :output k (assert-no-outputs inputs)))
7069

71-
(defn node* [label xf inputs]
70+
(defn node* [label value inputs]
7271
(list :node
7372
(gensym 'n)
7473
(assert-no-outputs inputs)
75-
xf
74+
value
7675
label))
7776

78-
(defn embed [net-xf input-map]
79-
(-> net-xf
77+
(defn embed [net-map input-map]
78+
(-> net-map
8079
(postwalk
8180
:output
82-
(fn [[node-type node-id] {xf :xf label :label} input-xfs]
81+
(fn [[node-type node-id] {value :value label :label} inputs]
8382
(condp = node-type
8483
: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))))
8786
:output))
8887

8988
;; printing/debugging
@@ -99,6 +98,3 @@
9998
(map (fn [[k {:keys [inputs]}]]
10099
[k :inputs (compact-paths inputs)])
101100
(:output net-map)))))
102-
103-
(defn pr-net [net-xf]
104-
(compact-net-map (net-xf)))

src/net/n01se/hassle/xfnet.cljc

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,12 @@
8888
(def input net/input)
8989
(def output net/output)
9090
(def node* net/node*)
91-
(def embed net/embed)
92-
(def postwalk net/postwalk)
91+
92+
(defn embed [xfn input-map]
93+
(net/embed (xfn) input-map))
94+
95+
(defn postwalk [xfn roots update-fn]
96+
(net/postwalk (xfn) roots update-fn))
97+
98+
(defn pr-xfn [xfn]
99+
(net/compact-net-map (xfn)))

0 commit comments

Comments
 (0)