   [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 dense?
  [{:keys [shape strides]}]
  (if (= 1 (count shape))
    (= 1 (long (first strides)))
    (let [[shape strides] (->> (map vector shape strides)
                               (remove #(= 1 (first %)))
                               (sort-by second >)
                               ((fn [shp-strd]
                                  [(mapv first shp-strd)
                                   (mapv second shp-strd)])))
          max-stride (first strides)
          shape-num (apply * 1 (drop 1 shape))]
      (= max-stride shape-num))))


(defn access-increasing?
  "Are these dimensions setup such a naive seq through the data will be accessing memory in order.
This is necessary for external library interfaces (blas, cudnn).  An example would be after almost any
transpose that is not made concrete (copied) this condition will probably not hold."
  [{:keys [shape strides]}]
  (apply >= strides))


(defn ->most-rapidly-changing-dimension
  "Get the size of the most rapidly changing dimension"
  ^long [{:keys [shape]}]
  (last shape))


(defn ->least-rapidly-changing-dimension
  "Get the size of the least rapidly changing dimension"
  ^long [{:keys [shape]}]
  (first shape))


(defn elem-idx->addr



(defn in-place-reshape
  "Return new dimensions that correspond to an in-place reshape.  This is a very difficult
  algorithm to get correct as it needs to take into account changing strides and dense vs
  non-dense dimensions."
  [existing-dims shape]
  (let [new-dims (dimensions shape)]
    (when-not-error (<= (ecount new-dims)
