zachgk commented on a change in pull request #12690: [MXNET-1000] get Ndarray
real value and form it from a NDArray
URL: https://github.com/apache/incubator-mxnet/pull/12690#discussion_r248079764
##########
File path: scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala
##########
@@ -509,6 +510,57 @@ object NDArray extends NDArrayBase {
array(sourceArr, shape, null)
}
+ /**
+ * Create a new NDArray based on the structure of source Array
+ * @param sourceArr Array[Array...Array[Float]...]
+ * @param ctx context like to pass in
+ * @return an NDArray with the same shape of the input
+ */
+ def toNDArray(sourceArr: Array[_], ctx : Context = null) : NDArray = {
+ val shape = ArrayBuffer[Int]()
+ shapeGetter(sourceArr, shape, 0)
+ val finalArr = new Array[Float](shape.product)
+ arrayCombiner(sourceArr, finalArr, 0, finalArr.length - 1)
+ array(finalArr, Shape(shape), ctx)
+ }
+
+ private def shapeGetter(sourceArr : Any,
Review comment:
I get using an ArrayBuffer for the array data since it is large. Don't do it
for the shape because it makes everything complicated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services