From f10d9b2eaf71339acc16fb184e455cc8b1f42867 Mon Sep 17 00:00:00 2001 From: Carin Meier Date: Mon, 4 Feb 2019 19:23:40 -0500 Subject: [PATCH] rewrote the concat test to avoid flaky failures (#14049) ran 10000 times with no failures --- .../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 c97711b5fed6..3b97190854b4 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]