summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/benchmarks.hs30
-rw-r--r--hmatrix.cabal9
-rw-r--r--lib/Numeric/GSL/Matrix.hs31
3 files changed, 30 insertions, 40 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs
index 398d1ce..073a95d 100644
--- a/examples/benchmarks.hs
+++ b/examples/benchmarks.hs
@@ -70,20 +70,34 @@ rot a = (3><3) [ c,0,s
70 70
71manymult n r = foldl1' (<>) (map r angles) 71manymult n r = foldl1' (<>) (map r angles)
72 where angles = toList $ linspace n (0,1) 72 where angles = toList $ linspace n (0,1)
73 -- angles = map (k*) [0..n']
74 -- n' = fromIntegral n - 1
75 -- k = recip n'
73 76
74-------------------------------------------------------------------------------- 77--------------------------------------------------------------------------------
75 78
76bench3 = do 79bench3 = do
77 putStrLn "-------------------------------------------------------" 80 putStrLn "-------------------------------------------------------"
78 putStrLn "foldVector:" 81 putStrLn "foldVector"
79 let v = flatten $ ident 555 :: Vector Double 82 let v = flatten $ ident 500 :: Vector Double
80 print $ vectorMax v -- evaluate it 83 print $ vectorMax v -- evaluate it
81 let getPos k s = if k `rem` 555 < 200 && v@>k > 0 then k:s else s 84 let getPos k s = if k `mod` 500 < 200 && v@>k > 0 then k:s else s
82 time $ print $ sum $ foldVector getPos [] v 85 putStrLn "indices extraction, dim=0.25M:"
83 time $ print $ foldVector (\k s -> w@>k + s) 0.0 w 86 time $ print $ (`divMod` 500) $ maximum $ foldLoop getPos [] (dim v)
84 87 putStrLn "sum, dim=30M:"
85foldVector f s v = go (d - 1) s 88 --time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w)
89 time $ print $ foldVector (\k v s -> v k + s) 0.0 w
90 putStrLn "sum, dim=0.25M:"
91 --time $ print $ foldVector (\k v s -> v k + s) 0.0 v
92 time $ print $ foldLoop (\k s -> v@>k + s) 0.0 (dim v)
93
94-- foldVector is slower if it is used in two places. (!?)
95-- this does not happen with foldLoop
96
97foldLoop f s d = go (d - 1) s
86 where 98 where
87 d = dim v
88 go 0 s = f (0::Int) s 99 go 0 s = f (0::Int) s
89 go !j !s = go (j - 1) (f j s) 100 go !j !s = go (j - 1) (f j s)
101
102foldVector f s v = foldLoop g s (dim v)
103 where g !k !s = f k (v@>) s
diff --git a/hmatrix.cabal b/hmatrix.cabal
index c2ee18a..75e2984 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -25,6 +25,10 @@ flag mkl
25 description: Link with Intel's MKL optimized libraries. 25 description: Link with Intel's MKL optimized libraries.
26 default: False 26 default: False
27 27
28flag gsl
29 description: Link with GSL unoptimized blas.
30 default: False
31
28flag unsafe 32flag unsafe
29 description: Compile the library with bound checking disabled. 33 description: Compile the library with bound checking disabled.
30 default: False 34 default: False
@@ -108,7 +112,10 @@ library
108 else 112 else
109 extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core 113 extra-libraries: gsl mkl_lapack mkl_intel mkl_sequential mkl_core
110 else 114 else
111 extra-libraries: gsl blas lapack 115 if flag(gsl)
116 extra-libraries: gsl gslcblas lapack
117 else
118 extra-libraries: gsl blas lapack
112 119
113 cc-options: -O4 120 cc-options: -O4
114 ghc-prof-options: -auto-all 121 ghc-prof-options: -auto-all
diff --git a/lib/Numeric/GSL/Matrix.hs b/lib/Numeric/GSL/Matrix.hs
index cb3fa8f..f62bb82 100644
--- a/lib/Numeric/GSL/Matrix.hs
+++ b/lib/Numeric/GSL/Matrix.hs
@@ -92,23 +92,6 @@ foreign import ccall "gsl-aux.h eigensystemC" c_eigH :: TCMVCM
92 92
93{- | Singular value decomposition of a real matrix, using /gsl_linalg_SV_decomp_mod/: 93{- | Singular value decomposition of a real matrix, using /gsl_linalg_SV_decomp_mod/:
94 94
95@\> let (u,s,v) = svdg $ 'fromLists' [[1,2,3],[-4,1,7]]
96\
97\> u
980.310 -0.951
990.951 0.310
100\
101\> s
1028.497 2.792
103\
104\> v
105-0.411 -0.785
106 0.185 -0.570
107 0.893 -0.243
108\
109\> u \<\> 'diag' s \<\> 'trans' v
110 1. 2. 3.
111-4. 1. 7.@
112 95
113-} 96-}
114svdg :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double) 97svdg :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
@@ -128,20 +111,6 @@ foreign import ccall "gsl-aux.h svd" c_svd :: TMMVM
128 111
129{- | QR decomposition of a real matrix using /gsl_linalg_QR_decomp/ and /gsl_linalg_QR_unpack/. 112{- | QR decomposition of a real matrix using /gsl_linalg_QR_decomp/ and /gsl_linalg_QR_unpack/.
130 113
131@\> let (q,r) = qr $ 'fromLists' [[1,3,5,7],[2,0,-2,4]]
132\
133\> q
134-0.447 -0.894
135-0.894 0.447
136\
137\> r
138-2.236 -1.342 -0.447 -6.708
139 0. -2.683 -5.367 -4.472
140\
141\> q \<\> r
1421.000 3.000 5.000 7.000
1432.000 0. -2.000 4.000@
144
145-} 114-}
146qr :: Matrix Double -> (Matrix Double, Matrix Double) 115qr :: Matrix Double -> (Matrix Double, Matrix Double)
147qr = qr' . cmat 116qr = qr' . cmat