在Python中:
>>> import numpy as np
>>> x0=np.random.rand(3000,3000)
>>> t=time.perf_counter(); y0=np.matmul(x0,x0); time.perf_counter()-t
0.8358144999947399
>>> import torch
>>> x=torch.rand(3000,3000)
>>> t=time.perf_counter(); y0=np.matmul(x,x); time.perf_counter()-t
0.4304323000833392
在R中:
> a=matrix(runif(9000000), 3000, 3000)
> a1=a%*%a
> system.time({a1=a%*%a})
user system elapsed
16.53 0.04 16.57
为什么numpy和火炬的差异是20倍?