Preparing for second go at release.
This commit is contained in:
parent
7e95669ee7
commit
c6e85b5500
9 changed files with 271 additions and 289 deletions
|
|
@ -5,529 +5,529 @@
|
|||
</head>
|
||||
<body>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
001 (ns sparse-array.core)
|
||||
001 (ns sparse-array.core
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
002 "Operations on sparse arrays.")
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
002
|
||||
003
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
003 (declare put get)
|
||||
004 (declare put get)
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
004
|
||||
005
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
005 (def ^:dynamic *safe-sparse-operations*
|
||||
006 (def ^:dynamic *safe-sparse-operations*
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
006 "Whether spase array operations should be conducted safely, with careful
|
||||
007 "Whether spase array operations should be conducted safely, with careful
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
007 checking of data conventions and exceptions thrown if expectations are not
|
||||
008 checking of data conventions and exceptions thrown if expectations are not
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
008 met. Normally `false`."
|
||||
009 met. Normally `false`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
009 false)
|
||||
010 false)
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
010
|
||||
011
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
011 (defn- unsafe-sparse-operations?
|
||||
012 (defn- unsafe-sparse-operations?
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
012 "returns `true` if `*safe-sparse-operations*` is `false`, and vice versa."
|
||||
013 "returns `true` if `*safe-sparse-operations*` is `false`, and vice versa."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
013 []
|
||||
014 []
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
014 (not (true? *safe-sparse-operations*)))
|
||||
015 (not (true? *safe-sparse-operations*)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
015
|
||||
016
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
016 (defn make-sparse-array
|
||||
017 (defn make-sparse-array
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
017 "Make a sparse array with these `dimensions`. Every member of `dimensions`
|
||||
018 "Make a sparse array with these `dimensions`. Every member of `dimensions`
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
018 must be a keyword; otherwise, `nil` will be returned."
|
||||
019 must be a keyword; otherwise, `nil` will be returned."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
019 [& dimensions]
|
||||
020 [& dimensions]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
020 (when
|
||||
021 (when
|
||||
</span><br/>
|
||||
<span class="partial" title="7 out of 8 forms covered">
|
||||
021 (and (pos? (count dimensions))
|
||||
022 (and (pos? (count dimensions))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
022 (every? keyword? dimensions))
|
||||
023 (every? keyword? dimensions))
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
023 {:dimensions (count dimensions)
|
||||
024 {:dimensions (count dimensions)
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
024 :coord (first dimensions)
|
||||
025 :coord (first dimensions)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
025 :content (if
|
||||
026 :content (if
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
026 (empty? (rest dimensions))
|
||||
027 (empty? (rest dimensions))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
027 :data
|
||||
028 :data
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
028 (rest dimensions))}))
|
||||
029 (rest dimensions))}))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
029
|
||||
030
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
030 (defn- safe-test-or-throw
|
||||
031 (defn- safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
031 "If `v` is truthy or `*safe-sparse-operations*` is false, return `v`;
|
||||
032 "If `v` is truthy or `*safe-sparse-operations*` is false, return `v`;
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
032 otherwise, throw an `ExceptionInfo` with this `message` and the map `m`."
|
||||
033 otherwise, throw an `ExceptionInfo` with this `message` and the map `m`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
033 [v message m]
|
||||
034 [v message m]
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
034 (if-not
|
||||
035 (if-not
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
035 v
|
||||
036 v
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
036 (if
|
||||
037 (if
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
037 *safe-sparse-operations*
|
||||
038 *safe-sparse-operations*
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
038 (throw (ex-info message m))
|
||||
039 (throw (ex-info message m))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
039 v)
|
||||
040 v)
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
040 v))
|
||||
041 v))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
041
|
||||
042
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
042 (defn sparse-array?
|
||||
043 (defn sparse-array?
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
043 "`true` if `x` is a sparse array conforming to the conventions established
|
||||
044 "`true` if `x` is a sparse array conforming to the conventions established
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
044 by this library, else `false`."
|
||||
045 by this library, else `false`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
045 ;; TODO: sparse-array? should not throw exceptions even when
|
||||
046 ;; TODO: sparse-array? should not throw exceptions even when
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
046 ;; *safe-sparse-operations* is true, since we may use to test
|
||||
047 ;; *safe-sparse-operations* is true, since we may use to test
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
047 ;; whether an object is a sparse array. The place to throw the exceptions
|
||||
048 ;; whether an object is a sparse array. The place to throw the exceptions
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
048 ;; (if required) is after it has failed.
|
||||
049 ;; (if required) is after it has failed.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
049 ([x]
|
||||
050 ([x]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
050 (apply
|
||||
051 (apply
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
051 sparse-array?
|
||||
052 sparse-array?
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
052 (cons
|
||||
053 (cons
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
053 x
|
||||
054 x
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
054 (cons
|
||||
055 (cons
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
055 (:coord x)
|
||||
056 (:coord x)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
056 (when
|
||||
057 (when
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
057 (coll? (:content x))
|
||||
058 (coll? (:content x))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
058 (:content x))))))
|
||||
059 (:content x))))))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
059 ([x & axes]
|
||||
060 ([x & axes]
|
||||
</span><br/>
|
||||
<span class="partial" title="16 out of 17 forms covered">
|
||||
060 (and
|
||||
061 (and
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
061 (safe-test-or-throw
|
||||
062 (safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
062 (map? x)
|
||||
063 (map? x)
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
063 "Array must be a map" {:array x})
|
||||
064 "Array must be a map" {:array x})
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
064 (safe-test-or-throw
|
||||
065 (safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="covered" title="13 out of 13 forms covered">
|
||||
065 (and (integer? (:dimensions x)) (pos? (:dimensions x)))
|
||||
066 (and (integer? (:dimensions x)) (pos? (:dimensions x)))
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
066 (str "The value of `:dimensions` must be a positive integer, not " (:dimensions x))
|
||||
067 (str "The value of `:dimensions` must be a positive integer, not " (:dimensions x))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
067 {:array x})
|
||||
068 {:array x})
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
068 (safe-test-or-throw
|
||||
069 (safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
069 (keyword? (:coord x))
|
||||
070 (keyword? (:coord x))
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
070 (str "The value of `:coord` must be a keyword, not " (:coord x))
|
||||
071 (str "The value of `:coord` must be a keyword, not " (:coord x))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
071 {:array x})
|
||||
072 {:array x})
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
072 (safe-test-or-throw
|
||||
073 (safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
073 (= (:coord x) (first axes))
|
||||
074 (= (:coord x) (first axes))
|
||||
</span><br/>
|
||||
<span class="covered" title="10 out of 10 forms covered">
|
||||
074 (str "The value of `:coord` must be " (first axes) ", not " (:coord x))
|
||||
075 (str "The value of `:coord` must be " (first axes) ", not " (:coord x))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
075 {:array x})
|
||||
076 {:array x})
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
076 (if
|
||||
077 (if
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
077 (empty? (rest axes))
|
||||
078 (empty? (rest axes))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
078 (safe-test-or-throw
|
||||
079 (safe-test-or-throw
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
079 (= (:content x) :data)
|
||||
080 (= (:content x) :data)
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
080 "If there are no further axes the value of `:content` must be `:data`"
|
||||
081 "If there are no further axes the value of `:content` must be `:data`"
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
081 {:array x})
|
||||
082 {:array x})
|
||||
</span><br/>
|
||||
<span class="partial" title="4 out of 5 forms covered">
|
||||
082 (and
|
||||
083 (and
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
083 (= (:content x) (rest axes))
|
||||
084 (= (:content x) (rest axes))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
084 (every?
|
||||
085 (every?
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
085 sparse-array?
|
||||
086 sparse-array?
|
||||
</span><br/>
|
||||
<span class="covered" title="12 out of 12 forms covered">
|
||||
086 (map #(x %) (filter integer? (keys x)))))))))
|
||||
087 (map #(x %) (filter integer? (keys x)))))))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
087
|
||||
088
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
088 (defn- unsafe-put
|
||||
089 (defn- unsafe-put
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
089 [array value coordinates]
|
||||
090 [array value coordinates]
|
||||
</span><br/>
|
||||
<span class="partial" title="1 out of 2 forms covered">
|
||||
090 (cond
|
||||
091 (cond
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
091 (every?
|
||||
092 (every?
|
||||
</span><br/>
|
||||
<span class="partial" title="14 out of 15 forms covered">
|
||||
092 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
093 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
093 coordinates)
|
||||
094 coordinates)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
094 (assoc
|
||||
095 (assoc
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
095 array
|
||||
096 array
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
096 (first coordinates)
|
||||
097 (first coordinates)
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
097 (if
|
||||
098 (if
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
098 (= :data (:content array))
|
||||
099 (= :data (:content array))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
099 value
|
||||
100 value
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
100 (apply
|
||||
101 (apply
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
101 put
|
||||
102 put
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
102 (cons
|
||||
103 (cons
|
||||
</span><br/>
|
||||
<span class="partial" title="4 out of 5 forms covered">
|
||||
103 (or
|
||||
104 (or
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
104 (array (first coordinates))
|
||||
105 (array (first coordinates))
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
105 (apply make-sparse-array (:content array)))
|
||||
106 (apply make-sparse-array (:content array)))
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
106 (cons value (rest coordinates))))))))
|
||||
107 (cons value (rest coordinates))))))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
107
|
||||
108
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
108 (defn put
|
||||
109 (defn put
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
109 "Return a sparse array like this `array` but with this `value` at these
|
||||
110 "Return a sparse array like this `array` but with this `value` at these
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
110 `coordinates`. Returns `nil` if any coordinate is invalid."
|
||||
111 `coordinates`. Returns `nil` if any coordinate is invalid."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
111 [array value & coordinates]
|
||||
112 [array value & coordinates]
|
||||
</span><br/>
|
||||
<span class="partial" title="6 out of 7 forms covered">
|
||||
112 (cond
|
||||
113 (cond
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
113 (nil? value)
|
||||
114 (nil? value)
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
114 nil
|
||||
115 nil
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
115 (unsafe-sparse-operations?)
|
||||
116 (unsafe-sparse-operations?)
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
116 (unsafe-put array value coordinates)
|
||||
117 (unsafe-put array value coordinates)
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
117 (not (sparse-array? array))
|
||||
118 (not (sparse-array? array))
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 7 forms covered">
|
||||
118 (throw (ex-info "Sparse array expected" {:array array}))
|
||||
119 (throw (ex-info "Sparse array expected" {:array array}))
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
119 (not= (:dimensions array) (count coordinates))
|
||||
120 (not= (:dimensions array) (count coordinates))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
120 (throw
|
||||
121 (throw
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
121 (ex-info
|
||||
122 (ex-info
|
||||
</span><br/>
|
||||
<span class="covered" title="9 out of 9 forms covered">
|
||||
122 (str "Expected " (:dimensions array) " coordinates; found " (count coordinates))
|
||||
123 (str "Expected " (:dimensions array) " coordinates; found " (count coordinates))
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
123 {:array array
|
||||
124 {:array array
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
124 :coordinates coordinates}))
|
||||
125 :coordinates coordinates}))
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
125 (not
|
||||
126 (not
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
126 (every?
|
||||
127 (every?
|
||||
</span><br/>
|
||||
<span class="partial" title="13 out of 15 forms covered">
|
||||
127 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
128 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
128 coordinates))
|
||||
129 coordinates))
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
129 (throw
|
||||
130 (throw
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
130 (ex-info
|
||||
131 (ex-info
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
131 "Coordinates must be zero or positive integers"
|
||||
132 "Coordinates must be zero or positive integers"
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
132 {:array array
|
||||
133 {:array array
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
133 :coordinates coordinates
|
||||
134 :coordinates coordinates
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 13 forms covered">
|
||||
134 :invalid (remove #(and (pos? %) (integer? %)) coordinates)}))
|
||||
135 :invalid (remove #(and (pos? %) (integer? %)) coordinates)}))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
135 :else
|
||||
136 :else
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
136 (unsafe-put array value coordinates)))
|
||||
137 (unsafe-put array value coordinates)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
137
|
||||
138
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
138 (defn- unsafe-get
|
||||
139 (defn- unsafe-get
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
139 ;; TODO: I am CERTAIN there is a more elegant solution to this.
|
||||
140 ;; TODO: I am CERTAIN there is a more elegant solution to this.
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
140 [array coordinates]
|
||||
141 [array coordinates]
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
141 (let [v (array (first coordinates))]
|
||||
142 (let [v (array (first coordinates))]
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
142 (cond
|
||||
143 (cond
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
143 (= :data (:content array))
|
||||
144 (= :data (:content array))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
144 v
|
||||
145 v
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
145 (nil? v)
|
||||
146 (nil? v)
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
146 nil
|
||||
147 nil
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
147 :else
|
||||
148 :else
|
||||
</span><br/>
|
||||
<span class="covered" title="9 out of 9 forms covered">
|
||||
148 (apply get (cons v (rest coordinates))))))
|
||||
149 (apply get (cons v (rest coordinates))))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
149
|
||||
150
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
150 (defn get
|
||||
151 (defn get
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
151 "Return the value in this sparse `array` at these `coordinates`."
|
||||
152 "Return the value in this sparse `array` at these `coordinates`."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
152 [array & coordinates]
|
||||
153 [array & coordinates]
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
153 (cond
|
||||
154 (cond
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
154 (unsafe-sparse-operations?)
|
||||
155 (unsafe-sparse-operations?)
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
155 (unsafe-get array coordinates)
|
||||
156 (unsafe-get array coordinates)
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
156 (not (sparse-array? array))
|
||||
157 (not (sparse-array? array))
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 7 forms covered">
|
||||
157 (throw (ex-info "Sparse array expected" {:array array}))
|
||||
158 (throw (ex-info "Sparse array expected" {:array array}))
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
158 (not (every?
|
||||
159 (not (every?
|
||||
</span><br/>
|
||||
<span class="partial" title="13 out of 15 forms covered">
|
||||
159 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
160 #(and (integer? %) (or (zero? %) (pos? %)))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
160 coordinates))
|
||||
161 coordinates))
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
161 (throw
|
||||
162 (throw
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
162 (ex-info
|
||||
163 (ex-info
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
163 "Coordinates must be zero or positive integers"
|
||||
164 "Coordinates must be zero or positive integers"
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 5 forms covered">
|
||||
164 {:array array
|
||||
165 {:array array
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
165 :coordinates coordinates
|
||||
166 :coordinates coordinates
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 13 forms covered">
|
||||
166 :invalid (remove #(and (pos? %) (integer? %)) coordinates)}))
|
||||
167 :invalid (remove #(and (pos? %) (integer? %)) coordinates)}))
|
||||
</span><br/>
|
||||
<span class="covered" title="8 out of 8 forms covered">
|
||||
167 (not (= (:dimensions array) (count coordinates)))
|
||||
168 (not (= (:dimensions array) (count coordinates)))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
168 (throw
|
||||
169 (throw
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
169 (ex-info
|
||||
170 (ex-info
|
||||
</span><br/>
|
||||
<span class="covered" title="9 out of 9 forms covered">
|
||||
170 (str "Expected " (:dimensions array) " coordinates; found " (count coordinates))
|
||||
171 (str "Expected " (:dimensions array) " coordinates; found " (count coordinates))
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
171 {:array array
|
||||
172 {:array array
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
172 :coordinates coordinates}))
|
||||
173 :coordinates coordinates}))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
173 :else
|
||||
174 :else
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
174 (unsafe-get array coordinates)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
175
|
||||
175 (unsafe-get array coordinates)))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
176
|
||||
|
|
|
|||
|
|
@ -8,205 +8,214 @@
|
|||
001 (ns sparse-array.extract
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
002 (:require [sparse-array.core :refer :all]))
|
||||
002 "Extracting interesting data from sparse arrays."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
003 (:require [sparse-array.core :refer [*safe-sparse-operations*
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
004 dense-array? dense-dimensions
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
005 make-sparse-array sparse-array?]]))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
003
|
||||
006
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
004 ;;; The whole point of working with sparse arrays is to work with interesting
|
||||
007 ;;; The whole point of working with sparse arrays is to work with interesting
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
005 ;;; subsets of arrays most of which are uninteresting. To extract an
|
||||
008 ;;; subsets of arrays most of which are uninteresting. To extract an
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
006 ;;; interesting subset from an array, we're going to need an extract function.
|
||||
009 ;;; interesting subset from an array, we're going to need an extract function.
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
007
|
||||
010
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
008 (defn- extract-from-sparse
|
||||
011 (defn- extract-from-sparse
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
009 "Return a subset of this sparse `array` comprising all those cells for which
|
||||
012 "Return a subset of this sparse `array` comprising all those cells for which
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
010 this `function` returns a 'truthy' value."
|
||||
013 this `function` returns a 'truthy' value."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
011 [array function]
|
||||
014 [array function]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
012 (reduce
|
||||
015 (reduce
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
013 merge
|
||||
016 merge
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
014 (apply
|
||||
017 (apply
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
015 make-sparse-array
|
||||
018 make-sparse-array
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
016 (cons
|
||||
019 (cons
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
017 (:coord array)
|
||||
020 (:coord array)
|
||||
</span><br/>
|
||||
<span class="covered" title="9 out of 9 forms covered">
|
||||
018 (if (coll? (:content array)) (:content array))))
|
||||
<span class="covered" title="10 out of 10 forms covered">
|
||||
021 (when (coll? (:content array)) (:content array))))
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
019 (map
|
||||
022 (map
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
020 #(if
|
||||
023 #(if
|
||||
</span><br/>
|
||||
<span class="covered" title="5 out of 5 forms covered">
|
||||
021 (= :data (:content array))
|
||||
024 (= :data (:content array))
|
||||
</span><br/>
|
||||
<span class="covered" title="11 out of 11 forms covered">
|
||||
022 (if (function (array %)) {% (array %)})
|
||||
<span class="covered" title="12 out of 12 forms covered">
|
||||
025 (when (function (array %)) {% (array %)})
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
023 (let [v (extract-from-sparse (array %) function)]
|
||||
026 (let [v (extract-from-sparse (array %) function)]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
024 (if
|
||||
027 (if
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
025 (empty?
|
||||
028 (empty?
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
026 (filter integer? (keys v)))
|
||||
029 (filter integer? (keys v)))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
027 nil
|
||||
030 nil
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
028 {% v})))
|
||||
031 {% v})))
|
||||
</span><br/>
|
||||
<span class="covered" title="6 out of 6 forms covered">
|
||||
029 (filter integer? (keys array)))))
|
||||
032 (filter integer? (keys array)))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
030
|
||||
033
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
031 (defn extract-from-dense
|
||||
034 (defn extract-from-dense
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
032 "Return a subset of this dense `array` comprising all those cells for which
|
||||
035 "Return a subset of this dense `array` comprising all those cells for which
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
033 this `function` returns a 'truthy' value. Use these `axes` if provided."
|
||||
036 this `function` returns a 'truthy' value. Use these `axes` if provided."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
034 ([array function]
|
||||
037 ([array function]
|
||||
</span><br/>
|
||||
<span class="covered" title="15 out of 15 forms covered">
|
||||
035 (extract-from-dense array function (map #(keyword (str "i" %)) (range))))
|
||||
038 (extract-from-dense array function (map #(keyword (str "i" %)) (range))))
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
036 ([array function axes]
|
||||
039 ([array function axes]
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
037 (let
|
||||
040 (let
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
038 [dimensions (dense-dimensions array)]
|
||||
041 [dimensions (dense-dimensions array)]
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
039 (reduce
|
||||
042 (reduce
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
040 merge
|
||||
043 merge
|
||||
</span><br/>
|
||||
<span class="covered" title="7 out of 7 forms covered">
|
||||
041 (apply make-sparse-array (take dimensions axes))
|
||||
044 (apply make-sparse-array (take dimensions axes))
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
042 (if
|
||||
045 (if
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
043 (= dimensions 1)
|
||||
046 (= dimensions 1)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
044 (map
|
||||
047 (map
|
||||
</span><br/>
|
||||
<span class="covered" title="9 out of 9 forms covered">
|
||||
045 (fn [i v] (if (function v) (hash-map i v)))
|
||||
<span class="covered" title="10 out of 10 forms covered">
|
||||
048 (fn [i v] (when (function v) (hash-map i v)))
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
046 (range)
|
||||
049 (range)
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
047 array)
|
||||
050 array)
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
048 (map
|
||||
051 (map
|
||||
</span><br/>
|
||||
<span class="covered" title="15 out of 15 forms covered">
|
||||
049 (fn [i v] (if (empty? (filter integer? (keys v))) nil (hash-map i v)))
|
||||
052 (fn [i v] (if (empty? (filter integer? (keys v))) nil (hash-map i v)))
|
||||
</span><br/>
|
||||
<span class="covered" title="2 out of 2 forms covered">
|
||||
050 (range)
|
||||
053 (range)
|
||||
</span><br/>
|
||||
<span class="covered" title="11 out of 11 forms covered">
|
||||
051 (map #(extract-from-dense % function (rest axes)) array)))))))
|
||||
054 (map #(extract-from-dense % function (rest axes)) array)))))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
052
|
||||
055
|
||||
</span><br/>
|
||||
<span class="covered" title="1 out of 1 forms covered">
|
||||
053 (defn extract
|
||||
056 (defn extract
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
054 "Return a sparse subset of this `array` - which may be either sparse or
|
||||
057 "Return a sparse subset of this `array` - which may be either sparse or
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
055 dense - comprising all those cells for which this `function` returns a
|
||||
058 dense - comprising all those cells for which this `function` returns a
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
056 'truthy' value."
|
||||
059 'truthy' value."
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
057 [array function]
|
||||
060 [array function]
|
||||
</span><br/>
|
||||
<span class="partial" title="2 out of 4 forms covered">
|
||||
058 (cond
|
||||
061 (cond
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
059 (sparse-array? array)
|
||||
062 (sparse-array? array)
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
060 (extract-from-sparse array function)
|
||||
063 (extract-from-sparse array function)
|
||||
</span><br/>
|
||||
<span class="covered" title="3 out of 3 forms covered">
|
||||
061 (dense-array? array)
|
||||
064 (dense-array? array)
|
||||
</span><br/>
|
||||
<span class="covered" title="4 out of 4 forms covered">
|
||||
062 (extract-from-dense array function)
|
||||
065 (extract-from-dense array function)
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
063 *safe-sparse-operations*
|
||||
066 *safe-sparse-operations*
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 1 forms covered">
|
||||
064 (throw
|
||||
067 (throw
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
065 (ex-info
|
||||
068 (ex-info
|
||||
</span><br/>
|
||||
<span class="not-tracked" title="0 out of 0 forms covered">
|
||||
066 "Argument passed as `array` is neither sparse nor dense."
|
||||
069 "Argument passed as `array` is neither sparse nor dense."
|
||||
</span><br/>
|
||||
<span class="not-covered" title="0 out of 3 forms covered">
|
||||
067 {:array array}))))
|
||||
070 {:array array}))))
|
||||
</span><br/>
|
||||
<span class="blank" title="0 out of 0 forms covered">
|
||||
068
|
||||
071
|
||||
</span><br/>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue