summaryrefslogtreecommitdiff
path: root/lib/LAPACK
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LAPACK')
-rw-r--r--lib/LAPACK/Internal.hs36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/LAPACK/Internal.hs b/lib/LAPACK/Internal.hs
index 4c755bc..2569215 100644
--- a/lib/LAPACK/Internal.hs
+++ b/lib/LAPACK/Internal.hs
@@ -27,6 +27,24 @@ import Foreign.C.String
27foreign import ccall "lapack-aux.h svd_l_R" 27foreign import ccall "lapack-aux.h svd_l_R"
28 dgesvd :: Double ::> Double ::> (Double :> Double ::> IO Int) 28 dgesvd :: Double ::> Double ::> (Double :> Double ::> IO Int)
29 29
30-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix.
31--
32-- @(u,s,v)=svdR m@ so that @m=u \<\> s \<\> 'trans' v@.
33svdR :: Matrix Double -> (Matrix Double, Matrix Double , Matrix Double)
34svdR x@M {rows = r, cols = c} = (u, s, v)
35 where (u,s',v) = svdR' x
36 s | r == c = diag s'
37 | r < c = joinHoriz [diag s' , zeros (r,c-r)]
38 | otherwise = joinVert [diag s' , zeros (r-c,c)]
39 zeros (r,c) = reshape c $ constant (r*c) 0
40
41svdR' x@M {rows = r, cols = c} = unsafePerformIO $ do
42 u <- createMatrix ColumnMajor r r
43 s <- createVector (min r c)
44 v <- createMatrix ColumnMajor c c
45 dgesvd // mat fdat x // mat dat u // vec s // mat dat v // check "svdR" [fdat x]
46 return (u,s,trans v)
47
30----------------------------------------------------------------------------- 48-----------------------------------------------------------------------------
31-- dgesdd 49-- dgesdd
32foreign import ccall "lapack-aux.h svd_l_Rdd" 50foreign import ccall "lapack-aux.h svd_l_Rdd"
@@ -62,11 +80,27 @@ foreign import ccall "lapack-aux.h eig_l_R"
62 dgeev :: Double ::> Double ::> ((Complex Double) :> Double ::> IO Int) 80 dgeev :: Double ::> Double ::> ((Complex Double) :> Double ::> IO Int)
63 81
64----------------------------------------------------------------------------- 82-----------------------------------------------------------------------------
65
66-- dsyev 83-- dsyev
67foreign import ccall "lapack-aux.h eig_l_S" 84foreign import ccall "lapack-aux.h eig_l_S"
68 dsyev :: Double ::> (Double :> Double ::> IO Int) 85 dsyev :: Double ::> (Double :> Double ::> IO Int)
69 86
87-- | Wrapper for LAPACK's /dsyev/, which computes the eigenvalues and right eigenvectors of a symmetric real matrix:
88--
89-- if @(l,v)=eigSl m@ then @m \<\> v = v \<\> diag l@.
90--
91-- The eigenvectors are the columns of v.
92-- The eigenvalues are sorted in descending order (use eigS' for ascending order).
93eigS :: Matrix Double -> (Vector Double, Matrix Double)
94eigS m = (s', fliprl v)
95 where (s,v) = eigS' m
96 s' = fromList . reverse . toList $ s
97
98eigS' (m@M {rows = r}) = unsafePerformIO $ do
99 l <- createVector r
100 v <- createMatrix ColumnMajor r r
101 dsyev // mat fdat m // vec l // mat dat v // check "eigS" [fdat m]
102 return (l,v)
103
70----------------------------------------------------------------------------- 104-----------------------------------------------------------------------------
71-- zheev 105-- zheev
72foreign import ccall "lapack-aux.h eig_l_H" 106foreign import ccall "lapack-aux.h eig_l_H"