            (partial apply map vector)
            (partial map (partial partition window 1)))
           (partition window 1 m)))
+
+
+;; I think that I might be able to tag pixels as "edges", based on a
+;; combination of pixel value and length of groups. If I can get all
+;; of the edge pixels aggregated together... that would be a big win!
+;;
+;; Can we extend this to deal with the whole world, by calculating the
+;; global pixel sample and line? One issue would be that edges
+;; sometimes wouldn't be met be anything on the other side.
+;;
+;; ACTUALLY -- this is a problem now, and if we solve it, we solve the
+;; whole mess. 

        (:sort ?line ?sample)
        (mod ?sample group-length :> ?subidx)
        (quot ?sample group-length :> ?line-group)
        (rebuild-lines [group-length] ?subidx ?val :> ?full-line))))

(defn run-line-aggretator
  "Takes a samples and line generator, and stitches lines back
  together. "
  []
  (let [agg-lines (group-lines 20 1)]
    (?<- (stdout)
         [?tile-h ?tile-v ?line ?line-group ?full-line]
         (points ?tile-h ?tile-v ?sample ?line ?val)
         (agg-lines ?line ?sample ?val :> ?line-group ?full-line))))


;; TODO: -- documentation on why we do this. Nearest neighbor analysis links.
(defn walk-matrix

  (memory-source-tap
   (for [h (range 3)
         s (range num-samples)
         l (range num-lines) :let [val s]]
     [h 1 s l val])))

;; Buffer to generate a sparse-vector from idx, val tuple pairs.
(defbufferop [rebuild-lines [size placeholder]]
  [tuples]
  [[(sparse-vector size tuples placeholder)]])

;; TODO: document the line-length, num-groups business. Right now, if
;; I'm not mistaken, we need num-groups to divide evenly into
