为什么 numpy 和 torch 在矩阵乘法方面比 R 快得多?

use*_*264 5 python performance numpy r torch

在 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
Run Code Online (Sandbox Code Playgroud)

在 R 中:

> a=matrix(runif(9000000), 3000, 3000)
> a1=a%*%a
> system.time({a1=a%*%a})
   user  system elapsed 
  16.53    0.04   16.57
Run Code Online (Sandbox Code Playgroud)

为什么 numpy 的差异是 20 倍,而 Torch 的差异是 40 倍?