
[英]Torch: Why is this collate function so much faster than this other one?
[英]Why are numpy and torch so much faster than R for matrix multiplication?
在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倍?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.