summaryrefslogtreecommitdiff
path: root/lib/LAPACK.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-22 17:33:17 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-22 17:33:17 +0000
commit978e6d038239af50d70bae2c303f4e45b1879b7a (patch)
tree571b2060f388d0693820f808b40089acb100a5d9 /lib/LAPACK.hs
parent989bdf7e88c13500bd1986dcde36f6cc4f467efb (diff)
refactoring
Diffstat (limited to 'lib/LAPACK.hs')
-rw-r--r--lib/LAPACK.hs55
1 files changed, 15 insertions, 40 deletions
diff --git a/lib/LAPACK.hs b/lib/LAPACK.hs
index dc9eda1..602f5df 100644
--- a/lib/LAPACK.hs
+++ b/lib/LAPACK.hs
@@ -26,13 +26,12 @@ import Data.Packed.Internal.Vector
26import Data.Packed.Internal.Matrix 26import Data.Packed.Internal.Matrix
27import Data.Packed.Vector 27import Data.Packed.Vector
28import Data.Packed.Matrix 28import Data.Packed.Matrix
29import GSL.Vector(scale)
29import Complex 30import Complex
30import Foreign 31import Foreign
31 32
32----------------------------------------------------------------------------- 33-----------------------------------------------------------------------------
33-- dgesvd 34foreign import ccall "LAPACK/lapack-aux.h svd_l_R" dgesvd :: TMMVM
34foreign import ccall "LAPACK/lapack-aux.h svd_l_R"
35 dgesvd :: TMMVM -- Double ::> Double ::> (Double :> Double ::> IO Int)
36 35
37-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix. 36-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix.
38-- 37--
@@ -48,9 +47,7 @@ svdR' x@M {rows = r, cols = c} = unsafePerformIO $ do
48 return (u,s,trans v) 47 return (u,s,trans v)
49 48
50----------------------------------------------------------------------------- 49-----------------------------------------------------------------------------
51-- dgesdd 50foreign import ccall "LAPACK/lapack-aux.h svd_l_Rdd" dgesdd :: TMMVM
52foreign import ccall "LAPACK/lapack-aux.h svd_l_Rdd"
53 dgesdd :: TMMVM --Double ::> Double ::> (Double :> Double ::> IO Int)
54 51
55-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix. 52-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix.
56-- 53--
@@ -66,9 +63,7 @@ svdRdd' x@M {rows = r, cols = c} = unsafePerformIO $ do
66 return (u,s,trans v) 63 return (u,s,trans v)
67 64
68----------------------------------------------------------------------------- 65-----------------------------------------------------------------------------
69-- zgesvd 66foreign import ccall "LAPACK/lapack-aux.h svd_l_C" zgesvd :: TCMCMVCM
70foreign import ccall "LAPACK/lapack-aux.h svd_l_C"
71 zgesvd :: TCMCMVCM -- (Complex Double) ::> (Complex Double) ::> (Double :> (Complex Double) ::> IO Int)
72 67
73-- | Wrapper for LAPACK's /zgesvd/, which computes the full svd decomposition of a complex matrix. 68-- | Wrapper for LAPACK's /zgesvd/, which computes the full svd decomposition of a complex matrix.
74-- 69--
@@ -85,9 +80,7 @@ svdC' x@M {rows = r, cols = c} = unsafePerformIO $ do
85 return (u,s,trans v) 80 return (u,s,trans v)
86 81
87----------------------------------------------------------------------------- 82-----------------------------------------------------------------------------
88-- zgeev 83foreign import ccall "LAPACK/lapack-aux.h eig_l_C" zgeev :: TCMCMCVCM
89foreign import ccall "LAPACK/lapack-aux.h eig_l_C"
90 zgeev :: TCMCMCVCM -- (Complex Double) ::> (Complex Double) ::> ((Complex Double) :> (Complex Double) ::> IO Int)
91 84
92-- | Wrapper for LAPACK's /zgeev/, which computes the eigenvalues and right eigenvectors of a general complex matrix: 85-- | Wrapper for LAPACK's /zgeev/, which computes the eigenvalues and right eigenvectors of a general complex matrix:
93-- 86--
@@ -106,9 +99,7 @@ eigC (m@M {rows = r})
106 return (l,v) 99 return (l,v)
107 100
108----------------------------------------------------------------------------- 101-----------------------------------------------------------------------------
109-- dgeev 102foreign import ccall "LAPACK/lapack-aux.h eig_l_R" dgeev :: TMMCVM
110foreign import ccall "LAPACK/lapack-aux.h eig_l_R"
111 dgeev :: TMMCVM -- Double ::> Double ::> ((Complex Double) :> Double ::> IO Int)
112 103
113-- | Wrapper for LAPACK's /dgeev/, which computes the eigenvalues and right eigenvectors of a general real matrix: 104-- | Wrapper for LAPACK's /dgeev/, which computes the eigenvalues and right eigenvectors of a general real matrix:
114-- 105--
@@ -139,12 +130,10 @@ fixeig ((r1:+i1):(r2:+i2):r) (v1:v2:vs)
139 | r1 == r2 && i1 == (-i2) = toComplex (v1,v2) : toComplex (v1,scale (-1) v2) : fixeig r vs 130 | r1 == r2 && i1 == (-i2) = toComplex (v1,v2) : toComplex (v1,scale (-1) v2) : fixeig r vs
140 | otherwise = comp v1 : fixeig ((r2:+i2):r) (v2:vs) 131 | otherwise = comp v1 : fixeig ((r2:+i2):r) (v2:vs)
141 132
142scale r v = fromList [r] `outer` v 133-- scale r v = fromList [r] `outer` v
143 134
144----------------------------------------------------------------------------- 135-----------------------------------------------------------------------------
145-- dsyev 136foreign import ccall "LAPACK/lapack-aux.h eig_l_S" dsyev :: TMVM
146foreign import ccall "LAPACK/lapack-aux.h eig_l_S"
147 dsyev :: TMVM -- Double ::> (Double :> Double ::> IO Int)
148 137
149-- | Wrapper for LAPACK's /dsyev/, which computes the eigenvalues and right eigenvectors of a symmetric real matrix: 138-- | Wrapper for LAPACK's /dsyev/, which computes the eigenvalues and right eigenvectors of a symmetric real matrix:
150-- 139--
@@ -166,9 +155,7 @@ eigS' (m@M {rows = r})
166 return (l,v) 155 return (l,v)
167 156
168----------------------------------------------------------------------------- 157-----------------------------------------------------------------------------
169-- zheev 158foreign import ccall "LAPACK/lapack-aux.h eig_l_H" zheev :: TCMVCM
170foreign import ccall "LAPACK/lapack-aux.h eig_l_H"
171 zheev :: TCMVCM -- (Complex Double) ::> (Double :> (Complex Double) ::> IO Int)
172 159
173-- | Wrapper for LAPACK's /zheev/, which computes the eigenvalues and right eigenvectors of a hermitian complex matrix: 160-- | Wrapper for LAPACK's /zheev/, which computes the eigenvalues and right eigenvectors of a hermitian complex matrix:
174-- 161--
@@ -190,9 +177,7 @@ eigH' (m@M {rows = r})
190 return (l,v) 177 return (l,v)
191 178
192----------------------------------------------------------------------------- 179-----------------------------------------------------------------------------
193-- dgesv 180foreign import ccall "LAPACK/lapack-aux.h linearSolveR_l" dgesv :: TMMM
194foreign import ccall "LAPACK/lapack-aux.h linearSolveR_l"
195 dgesv :: TMMM -- Double ::> Double ::> Double ::> IO Int
196 181
197-- | Wrapper for LAPACK's /dgesv/, which solves a general real linear system (for several right-hand sides) internally using the lu decomposition. 182-- | Wrapper for LAPACK's /dgesv/, which solves a general real linear system (for several right-hand sides) internally using the lu decomposition.
198linearSolveR :: Matrix Double -> Matrix Double -> Matrix Double 183linearSolveR :: Matrix Double -> Matrix Double -> Matrix Double
@@ -204,9 +189,7 @@ linearSolveR a@(M {rows = n1, cols = n2}) b@(M {rows = r, cols = c})
204 | otherwise = error "linearSolveR of nonsquare matrix" 189 | otherwise = error "linearSolveR of nonsquare matrix"
205 190
206----------------------------------------------------------------------------- 191-----------------------------------------------------------------------------
207-- zgesv 192foreign import ccall "LAPACK/lapack-aux.h linearSolveC_l" zgesv :: TCMCMCM
208foreign import ccall "LAPACK/lapack-aux.h linearSolveC_l"
209 zgesv :: TCMCMCM -- (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int
210 193
211-- | Wrapper for LAPACK's /zgesv/, which solves a general complex linear system (for several right-hand sides) internally using the lu decomposition. 194-- | Wrapper for LAPACK's /zgesv/, which solves a general complex linear system (for several right-hand sides) internally using the lu decomposition.
212linearSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double) 195linearSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)
@@ -218,9 +201,7 @@ linearSolveC a@(M {rows = n1, cols = n2}) b@(M {rows = r, cols = c})
218 | otherwise = error "linearSolveC of nonsquare matrix" 201 | otherwise = error "linearSolveC of nonsquare matrix"
219 202
220----------------------------------------------------------------------------------- 203-----------------------------------------------------------------------------------
221-- dgels 204foreign import ccall "LAPACK/lapack-aux.h linearSolveLSR_l" dgels :: TMMM
222foreign import ccall "LAPACK/lapack-aux.h linearSolveLSR_l"
223 dgels :: TMMM -- Double ::> Double ::> Double ::> IO Int
224 205
225-- | Wrapper for LAPACK's /dgels/, which obtains the least squared error solution of an overconstrained real linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDR'. 206-- | Wrapper for LAPACK's /dgels/, which obtains the least squared error solution of an overconstrained real linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDR'.
226linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double 207linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double
@@ -232,9 +213,7 @@ linearSolveLSR_l a@(M {rows = m, cols = n}) b@(M {cols = nrhs}) = unsafePerformI
232 return r 213 return r
233 214
234----------------------------------------------------------------------------------- 215-----------------------------------------------------------------------------------
235-- zgels 216foreign import ccall "LAPACK/lapack-aux.h linearSolveLSC_l" zgels :: TCMCMCM
236foreign import ccall "LAPACK/lapack-aux.h linearSolveLSC_l"
237 zgels :: TCMCMCM -- (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int
238 217
239-- | Wrapper for LAPACK's /zgels/, which obtains the least squared error solution of an overconstrained complex linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDC'. 218-- | Wrapper for LAPACK's /zgels/, which obtains the least squared error solution of an overconstrained complex linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDC'.
240linearSolveLSC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double) 219linearSolveLSC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)
@@ -246,9 +225,7 @@ linearSolveLSC_l a@(M {rows = m, cols = n}) b@(M {cols = nrhs}) = unsafePerformI
246 return r 225 return r
247 226
248----------------------------------------------------------------------------------- 227-----------------------------------------------------------------------------------
249-- dgelss 228foreign import ccall "LAPACK/lapack-aux.h linearSolveSVDR_l" dgelss :: Double -> TMMM
250foreign import ccall "LAPACK/lapack-aux.h linearSolveSVDR_l"
251 dgelss :: Double -> TMMM -- Double ::> Double ::> Double ::> IO Int
252 229
253-- | Wrapper for LAPACK's /dgelss/, which obtains the minimum norm solution to a real linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSR'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used. 230-- | Wrapper for LAPACK's /dgelss/, which obtains the minimum norm solution to a real linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSR'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.
254linearSolveSVDR :: Maybe Double -- ^ rcond 231linearSolveSVDR :: Maybe Double -- ^ rcond
@@ -264,9 +241,7 @@ linearSolveSVDR_l rcond a@(M {rows = m, cols = n}) b@(M {cols = nrhs}) = unsafeP
264 return r 241 return r
265 242
266----------------------------------------------------------------------------------- 243-----------------------------------------------------------------------------------
267-- zgelss 244foreign import ccall "LAPACK/lapack-aux.h linearSolveSVDC_l" zgelss :: Double -> TCMCMCM
268foreign import ccall "LAPACK/lapack-aux.h linearSolveSVDC_l"
269 zgelss :: Double -> TCMCMCM -- (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int
270 245
271-- | Wrapper for LAPACK's /zgelss/, which obtains the minimum norm solution to a complex linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSC'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used. 246-- | Wrapper for LAPACK's /zgelss/, which obtains the minimum norm solution to a complex linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSC'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.
272linearSolveSVDC :: Maybe Double -- ^ rcond 247linearSolveSVDC :: Maybe Double -- ^ rcond