Hi, all. I’m a newbie to PyTorch and have a question.
I have been trying to generate random numbers from uniform distribution and I recently found that torch.rand() works much faster than numpy.random.rand().
For example, I run a following script
setup1 = """
import numpy as np
import torch

def test1():
  y = torch.FloatTensor(np.random.rand(128, 25000))
"""

setup2 = """
import torch

def test2():
  y = torch.rand(128, 25000)
"""

if __name__ == "__main__":
  import timeit

  print(timeit.timeit("test1()", setup=setup1, number=100))
  print(timeit.timeit("test2()", setup=setup2, number=100))

and then I got a following output
14.177617023233324
1.8277414003387094

It means torch.rand() is much faster than numpy.random.rand(), but I still don’t understand why it is.
I’d be very grateful if someone could tell me why.
Thanks.