   [dimensions]
   (let [stripped (->> (mapv vector (:shape dimensions) (:strides dimensions))
                       (remove (fn [[shp str]]
-                                (= 1 (long shp)))))]
+                                (and (number? shp)
+                                     (= 1 (long shp))))))]
     (if (= 0 (count stripped))
       {:shape [1] :strides [1]}
       (let [reverse-stripped (reverse stripped)
             reverse-stripped (reduce (fn [reverse-stripped [[cur-shp cur-stride]
                                                             [last-shp last-stride]]]
-                                       (if (= (long cur-stride)
-                                              (* (long last-shp) (long last-stride)))
+                                       ;;If the dimension is direct and the stride lines up.
+                                       (if (and (number? last-shp)
+                                                (= (long cur-stride)
+                                                   (* (long last-shp) (long last-stride))))
                                          (let [[str-shp str-str] (last reverse-stripped)]
                                            (vec (concat (drop-last reverse-stripped)
-                                                        [[(* (long str-shp) (long cur-shp)) str-str]])))
+                                                        [[(* (long str-shp) (long cur-shp))
+                                                          str-str]])))
                                          (conj reverse-stripped [cur-shp cur-stride])))
                                      [(first reverse-stripped)]
                                      (map vector (rest reverse-stripped) reverse-stripped))



(defn select
  "Limited implementation of the core.matrix select function call.
Same rules apply *Except* if you pass in an array of numbers for a dimension
then they must be contiguous and monotonically increasing (a proper inclusive range).
This is due to limitations of the current gpu implementation and a strong reluctance
to add complexity there.  There must be an entry for every dimension of the tensor.
see:
https://cloojure.github.io/doc/core.matrix/clojure.core.matrix.html#var-select"
  [dimensions & args]



(defn dimensions
  "A dimension is a map with at least a shape (vector of integers or index buffers) and
  potentially another vector of dimension names.  By convention the first member of the shape is
  the slowest changing and the last member of the shape is the most rapidly changing.  There can
  also be optionally a companion vector of names which name each dimension.  Names are used when
  doing things that are dimension aware such as a 2d convolution.  Shape is the same as a
  core-matrix shape."
  [shape & {:keys [names strides]}]
  (let [strides (extend-strides shape strides)
        sorted-shape-stride (->> (map vector shape strides)
                                 (sort-by second >))
        max-stride (apply max 0 (map second sorted-shape-stride))
        elem-count (apply * 1 (drop 1 (map (comp disambiguate-shape-entry first)
                                           sorted-shape-stride)))]
    (when-not-error (<= (long elem-count)
                        (long max-stride))
      "Stride appears to be too small for element count"
