You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/03/08 20:30:04 UTC

[GitHub] [incubator-mxnet] gigasquid commented on a change in pull request #14308: [clojure-package][wip] add `->nd-vec` function in `ndarray.clj`

gigasquid commented on a change in pull request #14308: [clojure-package][wip] add `->nd-vec` function in `ndarray.clj`
URL: https://github.com/apache/incubator-mxnet/pull/14308#discussion_r263916984
 
 

 ##########
 File path: contrib/clojure-package/src/org/apache/clojure_mxnet/ndarray.clj
 ##########
 @@ -167,3 +171,36 @@
 
 (defn shape-vec [ndarray]
   (mx-shape/->vec (shape ndarray)))
+
+(s/fdef vec->nd-vec
+        :args (s/cat :v vector? :shape-vec vector?)
+        :ret vector?)
+
+(defn- vec->nd-vec
+  "Convert a vector `v` into a n-dimensional vector given the `shape-vec`
+
+   Ex:
+     (vec->nd-vec [1 2 3] [1 1 3])       ;[[[1 2 3]]]
+     (vec->nd-vec [1 2 3 4 5 6] [2 3 1]) ;[[[1] [2] [3]] [[4] [5] [6]]]
+     (vec->nd-vec [1 2 3 4 5 6] [1 2 3]) ;[[[1 2 3]] [4 5 6]]]
+     (vec->nd-vec [1 2 3 4 5 6] [3 1 2]) ;[[[1 2]] [[3 4]] [[5 6]]]
+     (vec->nd-vec [1 2 3 4 5 6] [3 2])   ;[[1 2] [3 4] [5 6]]"
+  [v [s1 & ss :as shape-vec]]
+  (if-not (seq ss)
+    (vec v)
+    (->> v
+         (partition (/ (count v) s1))
 
 Review comment:
   You will need to use `clojure.core//` instead of just `/` because the ndarray has a definition for the operator in this namespace

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services