            [tensorflow-clj.graph.transform :refer :all]
            [tensorflow-clj.util :refer [assoc-not-empty assoc-in-not-empty]]
            [clojure.string :as str]))
+;TODO this is a playground namespace for now
+;pieces will be hacked on here in isolation and then moved out to other namespaces
+;where they can be re-used once they are considered semi-stable
+;much of this code is commented out as I'm just running it once here or there
+;during development. anything that I think *might* be useful will be thrown into a function
+;any functions that prove to have some utility will be grouped and moved to their own ns
 
 (defn def-tensor-nodes [name value dtype dims]
   (let [target (build-node-variable dims dtype :name name)

       :value
       (map (partial parse-variable true))))

(parse-trainable-vars mnist-meta-graph)

(def thing (-> nonsense-graph :node second :attr second :value :tensor :string-val first proto-much/byte-string-to-string))

(time
  (exp/exec-graph-sess-fn
    (fn [graph session]
      (let [nodes (build-nodes-y-mx-b)
            out-node-name (-> nodes last :name)
            tf-nodes (map clj-node->tensorflow-node nodes)
            graph-def {:node tf-nodes
                       :versions {:producer 21}}
            graph-bytes (proto/protobuf-dump proto-much/proto-graph-def graph-def)]
        (.importGraphDef graph graph-bytes)
        (exp/run-graph-thing session {:x [[5.0 12.0]
                                          [2.5 3.4]]
                                      :W [[6.0 1.3]
                                          [0.0 0.0]]
                                      :b [[0.0]]}
                             out-node-name)
        ))))

(time
  (exp/exec-graph-sess-fn
    (fn [graph session]
      (let [y-mx-b-nodes (build-nodes-y-mx-b)
            out-node-1 (-> y-mx-b-nodes last)
            placeholder-node (build-node-placeholder "DT_FLOAT" :name "y_hat")
            softmax-nodes (build-nodes-softmax-cross-entropy-with-logits out-node-1 placeholder-node)
            out-node-2 (-> softmax-nodes last)
            nodes (concat y-mx-b-nodes softmax-nodes)
            tf-nodes (map clj-node->tensorflow-node nodes)
            graph-def {:node tf-nodes
                       :versions {:producer 21}}
            graph-bytes (proto/protobuf-dump proto-much/proto-graph-def graph-def)]
        (.importGraphDef graph graph-bytes)
        (exp/run-graph-thing session {:x [[5.0 12.0]
                                          [2.5 3.4]]
                                      :W [[6.0 1.3]
                                          [0.0 0.0]]
                                      :b [[2.0]]
                                      :y_hat [[5.3 8.5]
                                              [900.24 9.94]]}
                             (-> out-node-1 :name)
                             (-> out-node-2 :name))
        ))))

(time
  (exp/exec-graph-sess-fn
    (fn [graph session]
      (let [y-mx-b-nodes (build-nodes-y-mx-b)
            out-node-1 (-> y-mx-b-nodes last)
            placeholder-node (build-node-placeholder "DT_FLOAT" :name "y_hat")
            softmax-nodes (build-nodes-softmax-cross-entropy-with-logits out-node-1 placeholder-node)
            out-node-2 (-> softmax-nodes last)
            reduce-mean-nodes (build-nodes-reduce-mean out-node-2)
            out-node-3 (-> reduce-mean-nodes last)
            nodes (concat y-mx-b-nodes softmax-nodes reduce-mean-nodes)
            tf-nodes (map clj-node->tensorflow-node nodes)
            graph-def {:node tf-nodes
                       :versions {:producer 21}}
            graph-bytes (proto/protobuf-dump proto-much/proto-graph-def graph-def)]
        (.importGraphDef graph graph-bytes)
        (exp/run-graph-thing session {:x [[5.0 12.0]
                                          [2.5 3.4]]
                                      :W [[6.0 1.3]
                                          [0.0 0.0]]
                                      :b [[2.0]]
                                      :y_hat [[5.3 3.5]
                                              [0.24 3.94]]}
                             (-> out-node-1 :name)
                             (-> out-node-2 :name)
                             (-> out-node-3 :name))
        ))))

(defn build-cast [node dtype])
(defn build-ApplyGradientDescent [variable learning-rate gradient-control])

;(def linreg-graph (proto/protobuf-load proto-much/proto-graph-def (util/slurp-binary "misc/linreg.pb")))
;(-> linreg-graph :node count)
;(mapv :name (-> linreg-graph :node))
;(filter #(= "Identity" (:op %)) (-> linreg-graph :node))
;(map #(str (:name %) " " (:op %) " " (:input %)) (-> linreg-graph :node))
;(def addconst-graph (proto/protobuf-load proto-much/proto-graph-def (util/slurp-binary "misc/addconst.pb")))
;(-> addconst-graph :node count)
;(def nonsense-graph (proto/protobuf-load proto-much/proto-graph-def (util/slurp-binary "misc/nonsense.pb")))
;(def mnist-simple-graph (proto/protobuf-load proto-much/proto-graph-def (util/slurp-binary "misc/mnist_simple.pbtxt")))
;(def mnist-meta-graph (proto/protobuf-load proto-much/proto-meta-graph-def (util/slurp-binary "misc/mnist_simple.model.meta")))
;(-> mnist-meta-graph keys)

(defn parse-node-ref [node-ref]
  (let [[name output] (str/split node-ref #":")]
