   (memory-source-tap
    (for [h (range 3)
          s (range num-samples)
-         l (range num-lines) :let [val {:key s}]]
+         l (range num-lines) :let [val 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]]
+;; Buffer to generate a sparse-vector from idx, val tuple pairs.
+(defbufferop [rebuild-lines [size placeholder]]
   [tuples]
-  [(vector ((apply comp (for [tup tuples]
-                          (fn [v] (apply assoc (vec v) tup))))
-            (repeat width 0)))])
+  [[(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

           (partial apply map vector)
           (partial map (partial partition window 1)))
          (partition window 1 m)))


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