Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix approx=.
Browse files Browse the repository at this point in the history
Include a test of this fix as well.
  • Loading branch information
Taliesin Beynon committed Aug 23, 2018
1 parent d28e068 commit b22bb34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@
(let [arange (sym/arange-with-inference 0)
data (sym/variable "data")
added (sym/+ arange data)
result (range 0. 4.)
result (range 0 4)
data-tmp (ndarray/zeros [4])
exec (sym/bind added (context/default-context) {"data" data-tmp})]
(executor/forward exec)
(is (= 0 (count (executor/grad-arrays exec))))
(is (= result (-> (executor/outputs exec) (first) (ndarray/->vec))))))
(is (approx= 1e-4 result (-> (executor/outputs exec) (first))))))

(deftest test-scalar-pow
(let [data (sym/variable "data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
(if (and (number? x) (number? y))
(let [diff (Math/abs (- x y))]
(< diff tolerance))
(reduce (fn [x y] (and x y))
(map #(approx= tolerance %1 %2) x y))))
(and
(= (count x) (count y))
(reduce (fn [x y] (and x y))
(map #(approx= tolerance %1 %2) x y)))))

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[org.apache.clojure-mxnet.util :as util]
[org.apache.clojure-mxnet.ndarray :as ndarray]
[org.apache.clojure-mxnet.symbol :as sym]
[org.apache.clojure-mxnet.test-util :as test-util]
[clojure.spec.alpha :as s])
(:import (org.apache.mxnet Shape NDArrayFuncReturn NDArray)
(scala.collection Map Set)
Expand Down Expand Up @@ -183,3 +184,10 @@
(deftest test-validate
(is (nil? (util/validate! string? "foo" "Not a string!")))
(is (thrown-with-msg? Exception #"Not a string!" (util/validate! ::x 1 "Not a string!"))))

(deftest test-approx=
(let [data1 [1 1 1 1]
data2 [1 1 1 1 9 9 9 9]
data3 [1 1 1 2]]
(is (not (test-util/approx= 1e-9 data1 data2)))
(is (test-util/approx= 2 data1 data3))))

0 comments on commit b22bb34

Please sign in to comment.