You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by cm...@apache.org on 2019/02/05 00:24:00 UTC

[incubator-mxnet] branch master updated: rewrote the concat test to avoid flaky failures (#14049)

This is an automated email from the ASF dual-hosted git repository.

cmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new ac962cd  rewrote the concat test to avoid flaky failures (#14049)
ac962cd is described below

commit ac962cd3efee4be01bc0a000948e86fbe1aa02fd
Author: Carin Meier <cm...@gigasquidsoftware.com>
AuthorDate: Mon Feb 4 19:23:40 2019 -0500

    rewrote the concat test to avoid flaky failures (#14049)
    
    ran 10000 times with no failures
---
 .../org/apache/clojure_mxnet/operator_test.clj     | 35 ++++++----------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/contrib/clojure-package/test/org/apache/clojure_mxnet/operator_test.clj b/contrib/clojure-package/test/org/apache/clojure_mxnet/operator_test.clj
index c97711b..3b97190 100644
--- a/contrib/clojure-package/test/org/apache/clojure_mxnet/operator_test.clj
+++ b/contrib/clojure-package/test/org/apache/clojure_mxnet/operator_test.clj
@@ -51,33 +51,16 @@
         (is (= out-grad grad))))))
 
 (deftest test-concat
-  (let [shape-vecs [[2 2] [3 2]]
-        x (sym/variable "x")
-        y (sym/variable "y")
-        out (sym/concat "conc" nil [x y] {:dim 0})
-        arr (mapv #(ndarray/empty %) shape-vecs)
-        arr-np (mapv #(ndarray/copy %) arr)
-        arr-grad (map #(ndarray/empty %) shape-vecs)
-        arg-names (sym/list-arguments out)
-        grad-map (zipmap arg-names arr-grad)
-        args (sym/list-arguments out)
-        [arg-shapes out-shapes aux-shapes] (sym/infer-shape out (zipmap args shape-vecs))
-        out-shape-vec (first out-shapes)
-        out-grad (ndarray/empty out-shape-vec)
-        exec1 (sym/bind out (context/default-context) arr grad-map)
-        out1 (-> (executor/forward exec1)
+  (let [a (sym/variable "a")
+      b (sym/variable "b")
+      c (sym/concat "conc" nil [a b] {:dim 0})
+      exec (sym/bind c (context/default-context) {"a" (ndarray/array [1 2] [2 1])
+                                                  "b" (ndarray/array [3 4] [2 1])})
+      output (-> (executor/forward exec)
                  (executor/outputs)
-                 (first))
-        ret (ndarray/concatenate arr)]
-    (is (= out1 ret))
-
-    ;;backward
-    (ndarray/copy-to out1 out-grad)
-    (ndarray/+= out-grad 1)
-    (executor/backward exec1 out-grad)
-    (let [grads arr-grad
-          np-grads arr-np]
-      (is (= grads (mapv #(ndarray/+ % 1) np-grads))))))
+                 (first))]
+    (is (= [1.0 2.0 3.0 4.0] (ndarray/->vec output)))
+    (is (= [4 1] (ndarray/shape-vec output)))))
 
 (defn check-regression [model forward-fn backward-fn]
   (let [shape-vec [3 1]