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 2017/12/27 09:53:10 UTC

[GitHub] edmBernard commented on issue #9209: Speed between Ndarry and Numpy

edmBernard commented on issue #9209: Speed between Ndarry and Numpy
URL: https://github.com/apache/incubator-mxnet/issues/9209#issuecomment-354087204
 
 
   on my pc with your script I got 
   8s for nd.array on cpu and 15s for np array on cpu:
   ```python3
   import numpy as np
   import mxnet as mx
   import time
   
   def argmax_nd():
       gpu_device = mx.cpu(0)
       t = time.time()
       for i in xrange(100):
           with mx.Context(gpu_device):
               nd_a = mx.nd.array(np.random.randint(10, size=(176, 176, 100)))
               nd_a -= mx.nd.min(nd_a, axis=(0, 1))
               nd_a /= (mx.nd.sum(nd_a, axis=(0, 1)) + 1e-8)
               b = 0.38 * nd_a + mx.nd.ones(nd_a.shape) * (1 - 0.38)
               c = b.reshape((-1, nd_a.shape[2]))
               d = mx.nd.argmax(c, axis=0)
               y = d / 176 - 176/2.
               x = d % 176 - 176/2.
               m = x.asnumpy()
               n = y.asnumpy()
       print 'argmax time: ', time.time() - t
   
   def argmax_np():
       t = time.time()
       for i in xrange(100):
           np_a = np.random.randint(10, size=(176, 176, 100)).astype(float)
           np_a -= np.min(np_a, axis=(0, 1))
           np_a /= (np.sum(np_a, axis=(0, 1)) + 1e-8)
           b = 0.38 * np_a + np.ones(np_a.shape) * (1 - 0.38)
           c = b.reshape((-1, np_a.shape[2]))
           d = np.argmax(c, axis=0)
           y = d / 176 - 176/2.
           x = d % 176 - 176/2.
       print 'argmax time: ', time.time() - t
   
   
   argmax_np()
   argmax_nd()
   ```

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


With regards,
Apache Git Services