diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra/LAPACK.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/LAPACK.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/LAPACK.hs b/lib/Numeric/LinearAlgebra/LAPACK.hs index 8bc2492..56945d7 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK.hs +++ b/lib/Numeric/LinearAlgebra/LAPACK.hs | |||
@@ -14,6 +14,7 @@ | |||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | 15 | ||
16 | module Numeric.LinearAlgebra.LAPACK ( | 16 | module Numeric.LinearAlgebra.LAPACK ( |
17 | multiplyR, multiplyC, | ||
17 | svdR, svdRdd, svdC, | 18 | svdR, svdRdd, svdC, |
18 | eigC, eigR, eigS, eigH, eigS', eigH', | 19 | eigC, eigR, eigS, eigH, eigS', eigH', |
19 | linearSolveR, linearSolveC, | 20 | linearSolveR, linearSolveC, |
@@ -35,6 +36,33 @@ import Numeric.GSL.Vector(vectorMapValR, FunCodeSV(Scale)) | |||
35 | import Complex | 36 | import Complex |
36 | import Foreign | 37 | import Foreign |
37 | import Foreign.C.Types (CInt) | 38 | import Foreign.C.Types (CInt) |
39 | import Control.Monad(when) | ||
40 | |||
41 | ----------------------------------------------------------------------------------- | ||
42 | |||
43 | foreign import ccall "LAPACK/lapack-aux.h multiplyR" dgemmc :: CInt -> CInt -> TMMM | ||
44 | foreign import ccall "LAPACK/lapack-aux.h multiplyC" zgemmc :: CInt -> CInt -> TCMCMCM | ||
45 | |||
46 | isT MF{} = 0 | ||
47 | isT MC{} = 1 | ||
48 | |||
49 | tt x@MF{} = x | ||
50 | tt x@MC{} = trans x | ||
51 | |||
52 | multiplyAux f st a b = unsafePerformIO $ do | ||
53 | when (cols a /= rows b) $ error $ "inconsistent dimensions in matrix product "++ | ||
54 | show (rows a,cols a) ++ " x " ++ show (rows b, cols b) | ||
55 | s <- createMatrix ColumnMajor (rows a) (cols b) | ||
56 | app3 (f (isT a) (isT b)) mat (tt a) mat (tt b) mat s st | ||
57 | return s | ||
58 | |||
59 | -- | Matrix product based on BLAS's /dgemm/. | ||
60 | multiplyR :: Matrix Double -> Matrix Double -> Matrix Double | ||
61 | multiplyR a b = multiplyAux dgemmc "dgemmc" a b | ||
62 | |||
63 | -- | Matrix product based on BLAS's /zgemm/. | ||
64 | multiplyC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double) | ||
65 | multiplyC a b = multiplyAux zgemmc "zgemmc" a b | ||
38 | 66 | ||
39 | ----------------------------------------------------------------------------- | 67 | ----------------------------------------------------------------------------- |
40 | foreign import ccall "LAPACK/lapack-aux.h svd_l_R" dgesvd :: TMMVM | 68 | foreign import ccall "LAPACK/lapack-aux.h svd_l_R" dgesvd :: TMMVM |