            (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. 

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

;; TODO: Check on cascalog group -- is this the best way? Hammering a
;; vector in place?
(defbufferop [rebuild-lines [width]]
  [tuples]
  [(vector ((apply comp (for [tup tuples]
                          (fn [v] (apply assoc (vec v) tup))))
            (repeat width 0)))])

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


(ns forma.trends
  (:use cascalog.api
        [forma.matrix.utils :only (sparse-vector)]
        [clojure.contrib.math :only (ceil)]
        [clojure.contrib.seq :only (positions)]))

;; ### Time Series Generation
;;
