haskell-numerics / hmatrix

Linear algebra and numerical computation
381 stars 104 forks source link

why is invocation of <.> so slow? #295

Closed GeorgeCo closed 5 years ago

GeorgeCo commented 5 years ago

Why is invocation of <.> so slow? On MacOS 10.14.4 ghc --version The Glorious Glasgow Haskell Compilation System, version 8.6.5 ghc-pkg list|grep hmatrix hmatrix-0.19.0.0 bash-3.2$ ghci -framework Accelerate ghci -framework Accelerate GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) (0.00 secs, 0 bytes) Loaded GHCi configuration from /Users/gcolpitts/.ghci Prelude> import Numeric.LinearAlgebra Prelude Numeric.LinearAlgebra> a <- flatten <$> randn 1 (10^8) a <- flatten <$> randn 1 (10^8) (0.43 secs, 75,352 bytes) Prelude Numeric.LinearAlgebra> b <- flatten <$> randn 1 (10^8) b <- flatten <$> randn 1 (10^8) (0.00 secs, 73,088 bytes) Prelude Numeric.LinearAlgebra> a <.> b a <.> b 5536.2096881159905 (7.45 secs, 1,600,097,328 bytes) Prelude Numeric.LinearAlgebra> a <.> b a <.> b 5536.2096881159905 (0.13 secs, 95,104 bytes) a <- flatten <$> randn 1 (10^8) a <- flatten <$> randn 1 (10^8) (0.00 secs, 73,128 bytes) Prelude Numeric.LinearAlgebra> b <- flatten <$> randn 1 (10^8) b <- flatten <$> randn 1 (10^8) (0.00 secs, 73,088 bytes) Prelude Numeric.LinearAlgebra> a <.> b a <.> b -21704.785933812655 (7.45 secs, 1,600,098,288 bytes)

GeorgeCo commented 5 years ago

It seems it is the allocation of the large vectors that is slow. It would be good to know if there is a way to make that faster but I will submit a new issue for that. I believe that the options to make allocation faster would be GHC options to increase the size of the nursery and/or heap. So if I do have any issues it won't be here with hmatrix.