lanking520 commented on a change in pull request #11477: Copy profiler examples 
to new location for CI
URL: https://github.com/apache/incubator-mxnet/pull/11477#discussion_r199022241
 
 

 ##########
 File path: 
scala-package/examples/src/main/scala/org/apache/mxnet/examples/profiler/ProfilerNDArray.scala
 ##########
 @@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mxnet.examples.profiler
+
+import org.kohsuke.args4j.{CmdLineParser, Option}
+import org.slf4j.LoggerFactory
+import scala.collection.JavaConverters._
+import java.io.File
+import org.apache.mxnet.Profiler
+import org.apache.mxnet.Random
+import org.apache.mxnet.Shape
+import org.apache.mxnet.NDArray
+import org.apache.mxnet.Context
+
+/**
+ * @author Depeng Liang
+ */
+object ProfilerNDArray {
+  private val logger = LoggerFactory.getLogger(classOf[ProfilerNDArray])
+
+  def testBroadcast(): Unit = {
+    val sampleNum = 1000
+    def testBroadcastTo(): Unit = {
+      for (i <- 0 until sampleNum) {
+        val nDim = scala.util.Random.nextInt(2) + 1
+        val targetShape = Shape((0 until nDim).map(i => 
scala.util.Random.nextInt(10) + 1))
+        val shape = targetShape.toArray.map { s =>
+            if (scala.util.Random.nextInt(2) == 1) 1
+            else s
+        }
+        val dat = NDArray.empty(shape: _*)
+        val randomRet = (0 until shape.product)
+          .map(r => scala.util.Random.nextFloat() - 0.5f).toArray
+        dat.set(randomRet)
+        val ndArrayRet = NDArray.broadcast_to(Map("shape" -> 
targetShape))(dat).get
 
 Review comment:
   Can you try to use NDArray.api.broadcast_to in here?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to