diff options
Diffstat (limited to 'lib/LAPACK/Internal.hs')
-rw-r--r-- | lib/LAPACK/Internal.hs | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/lib/LAPACK/Internal.hs b/lib/LAPACK/Internal.hs new file mode 100644 index 0000000..4c755bc --- /dev/null +++ b/lib/LAPACK/Internal.hs | |||
@@ -0,0 +1,112 @@ | |||
1 | {-# OPTIONS_GHC -fglasgow-exts #-} | ||
2 | ----------------------------------------------------------------------------- | ||
3 | -- | | ||
4 | -- Module : LAPACK.Internal | ||
5 | -- Copyright : (c) Alberto Ruiz 2006-7 | ||
6 | -- License : GPL-style | ||
7 | -- | ||
8 | -- Maintainer : Alberto Ruiz (aruiz at um dot es) | ||
9 | -- Stability : provisional | ||
10 | -- Portability : portable (uses FFI) | ||
11 | -- | ||
12 | -- Wrappers for a few LAPACK functions (<http://www.netlib.org/lapack>). | ||
13 | -- | ||
14 | ----------------------------------------------------------------------------- | ||
15 | |||
16 | module LAPACK.Internal where | ||
17 | |||
18 | import Data.Packed.Internal.Vector | ||
19 | import Data.Packed.Internal.Matrix | ||
20 | import Complex | ||
21 | import Foreign | ||
22 | import Foreign.C.Types | ||
23 | import Foreign.C.String | ||
24 | |||
25 | ----------------------------------------------------------------------------- | ||
26 | -- dgesvd | ||
27 | foreign import ccall "lapack-aux.h svd_l_R" | ||
28 | dgesvd :: Double ::> Double ::> (Double :> Double ::> IO Int) | ||
29 | |||
30 | ----------------------------------------------------------------------------- | ||
31 | -- dgesdd | ||
32 | foreign import ccall "lapack-aux.h svd_l_Rdd" | ||
33 | dgesdd :: Double ::> Double ::> (Double :> Double ::> IO Int) | ||
34 | |||
35 | ----------------------------------------------------------------------------- | ||
36 | -- zgesvd | ||
37 | foreign import ccall "lapack-aux.h svd_l_C" | ||
38 | zgesvd :: (Complex Double) ::> (Complex Double) ::> (Double :> (Complex Double) ::> IO Int) | ||
39 | |||
40 | ----------------------------------------------------------------------------- | ||
41 | -- zgeev | ||
42 | foreign import ccall "lapack-aux.h eig_l_C" | ||
43 | zgeev :: (Complex Double) ::> (Complex Double) ::> ((Complex Double) :> (Complex Double) ::> IO Int) | ||
44 | |||
45 | -- | Wrapper for LAPACK's /zgeev/, which computes the eigenvalues and right eigenvectors of a general complex matrix: | ||
46 | -- | ||
47 | -- if @(l,v)=eigC m@ then @m \<\> v = v \<\> diag l@. | ||
48 | -- | ||
49 | -- The eigenvectors are the columns of v. | ||
50 | -- The eigenvalues are not sorted. | ||
51 | eigC :: Matrix (Complex Double) -> (Vector (Complex Double), Matrix (Complex Double)) | ||
52 | eigC (m@M {rows = r}) = unsafePerformIO $ do | ||
53 | l <- createVector r | ||
54 | v <- createMatrix ColumnMajor r r | ||
55 | dummy <- createMatrix ColumnMajor 1 1 | ||
56 | zgeev // mat fdat m // mat dat dummy // vec l // mat dat v // check "eigC" [fdat m] | ||
57 | return (l,v) | ||
58 | |||
59 | ----------------------------------------------------------------------------- | ||
60 | -- dgeev | ||
61 | foreign import ccall "lapack-aux.h eig_l_R" | ||
62 | dgeev :: Double ::> Double ::> ((Complex Double) :> Double ::> IO Int) | ||
63 | |||
64 | ----------------------------------------------------------------------------- | ||
65 | |||
66 | -- dsyev | ||
67 | foreign import ccall "lapack-aux.h eig_l_S" | ||
68 | dsyev :: Double ::> (Double :> Double ::> IO Int) | ||
69 | |||
70 | ----------------------------------------------------------------------------- | ||
71 | -- zheev | ||
72 | foreign import ccall "lapack-aux.h eig_l_H" | ||
73 | zheev :: (Complex Double) ::> (Double :> (Complex Double) ::> IO Int) | ||
74 | |||
75 | ----------------------------------------------------------------------------- | ||
76 | -- dgesv | ||
77 | foreign import ccall "lapack-aux.h linearSolveR_l" | ||
78 | dgesv :: Double ::> Double ::> Double ::> IO Int | ||
79 | |||
80 | ----------------------------------------------------------------------------- | ||
81 | -- zgesv | ||
82 | foreign import ccall "lapack-aux.h linearSolveC_l" | ||
83 | zgesv :: (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int | ||
84 | |||
85 | ----------------------------------------------------------------------------------- | ||
86 | -- dgels | ||
87 | foreign import ccall "lapack-aux.h linearSolveLSR_l" | ||
88 | dgels :: Double ::> Double ::> Double ::> IO Int | ||
89 | |||
90 | -- | 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'. | ||
91 | linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double | ||
92 | linearSolveLSR a b = subMatrix (0,0) (cols a, cols b) $ linearSolveLSR_l a b | ||
93 | |||
94 | linearSolveLSR_l a@(M {rows = m, cols = n}) b@(M {cols = nrhs}) = unsafePerformIO $ do | ||
95 | r <- createMatrix ColumnMajor (max m n) nrhs | ||
96 | dgels // mat fdat a // mat fdat b // mat dat r // check "linearSolveLSR" [fdat a, fdat b] | ||
97 | return r | ||
98 | |||
99 | ----------------------------------------------------------------------------------- | ||
100 | -- zgels | ||
101 | foreign import ccall "lapack-aux.h linearSolveLSC_l" | ||
102 | zgels :: (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int | ||
103 | |||
104 | ----------------------------------------------------------------------------------- | ||
105 | -- dgelss | ||
106 | foreign import ccall "lapack-aux.h linearSolveSVDR_l" | ||
107 | dgelss :: Double -> Double ::> Double ::> Double ::> IO Int | ||
108 | |||
109 | ----------------------------------------------------------------------------------- | ||
110 | -- zgelss | ||
111 | foreign import ccall "lapack-aux.h linearSolveSVDC_l" | ||
112 | zgelss :: Double -> (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int | ||