有趣的是,Data.Array.Repa 实际上比 hmatrix 快,这是出乎意料的,因为 hmatrix 是使用 LAPACK 实现的。这是因为 Repa 使用了未装箱的类型吗?
import Data.Array.Repa
import Data.Array.Repa.Algorithms.Matrix
main = do
let
a = fromListUnboxed (Z:.1000:.1000::DIM2) $ replicate (1000*1000) 1.0 :: Array U DIM2 Double
b = fromListUnboxed (Z:.1000:.1000::DIM2) $ replicate (1000*1000) 1.0 :: Array U DIM2 Double
m <- (a `mmultP` b)
print $ m!(Z:.900:.900)
1核
运行时间:7.011s 2核运行时间:3.975s
import Numeric.LinearAlgebra
import Numeric.LinearAlgebra.LAPACK
main = do
let
a = (1000><1000) $ replicate (1000*1000) 1.0
b = (1000><1000) $ replicate (1000*1000) 1.0
print $ (a `multiplyR` b) @@> (900,900)
运行时间:20.714s