piyushghai 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_r250423216
 
 

 ##########
 File path: 
scala-package/core/src/test/scala/org/apache/mxnet/NDArraySuite.scala
 ##########
 @@ -85,6 +89,47 @@ class NDArraySuite extends FunSuite with BeforeAndAfterAll 
with Matchers {
     assert(ndarray.toArray === Array(1f, 2f, 3f, 4f))
   }
 
+  test("create NDArray based on Java Matrix") {
+    def arrayGen(num : Any) : Array[Any] = {
+      val arrayBuf = num match {
+        case f: Float =>
+          val arr = ArrayBuffer[Array[Float]]()
+          for (_ <- 0 until 100) arr += Array(1.0f, 1.0f, 1.0f, 1.0f)
+          arr
+        case d: Double =>
+          val arr = ArrayBuffer[Array[Double]]()
+          for (_ <- 0 until 100) arr += Array(1.0d, 1.0d, 1.0d, 1.0d)
+          arr
+        case _ => throw new IllegalArgumentException(s"Unsupported Type 
${num.getClass}")
+      }
+      Array(
+        Array(
+          arrayBuf.toArray
+        ),
+        Array(
+          arrayBuf.toArray
+        )
+      )
+    }
+    val floatData = 1.0f
+    var nd = NDArray.toNDArray(arrayGen(floatData))
+    require(nd.shape == Shape(2, 1, 100, 4))
+    val arr2 = Array(1.0f, 1.0f, 1.0f, 1.0f)
+    nd = NDArray.toNDArray(arr2)
+    require(nd.shape == Shape(4))
+    val doubleData = 1.0d
+    nd = NDArray.toNDArray(arrayGen(doubleData))
+    require(nd.shape == Shape(2, 1, 100, 4))
+    require(nd.dtype == DType.Float64)
+  }
+
+  test("test Visualize") {
+    var nd = NDArray.ones(Shape(1, 2, 1000, 1))
+    require(nd.toString.split("\n").length == 33)
 
 Review comment:
   Should we compare the string representations as well ? 

----------------------------------------------------------------
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

Reply via email to