summaryrefslogtreecommitdiff
path: root/lib/LAPACK/Internal.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LAPACK/Internal.hs')
-rw-r--r--lib/LAPACK/Internal.hs112
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
16module LAPACK.Internal where
17
18import Data.Packed.Internal.Vector
19import Data.Packed.Internal.Matrix
20import Complex
21import Foreign
22import Foreign.C.Types
23import Foreign.C.String
24
25-----------------------------------------------------------------------------
26-- dgesvd
27foreign import ccall "lapack-aux.h svd_l_R"
28 dgesvd :: Double ::> Double ::> (Double :> Double ::> IO Int)
29
30-----------------------------------------------------------------------------
31-- dgesdd
32foreign import ccall "lapack-aux.h svd_l_Rdd"
33 dgesdd :: Double ::> Double ::> (Double :> Double ::> IO Int)
34
35-----------------------------------------------------------------------------
36-- zgesvd
37foreign import ccall "lapack-aux.h svd_l_C"
38 zgesvd :: (Complex Double) ::> (Complex Double) ::> (Double :> (Complex Double) ::> IO Int)
39
40-----------------------------------------------------------------------------
41-- zgeev
42foreign 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.
51eigC :: Matrix (Complex Double) -> (Vector (Complex Double), Matrix (Complex Double))
52eigC (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
61foreign import ccall "lapack-aux.h eig_l_R"
62 dgeev :: Double ::> Double ::> ((Complex Double) :> Double ::> IO Int)
63
64-----------------------------------------------------------------------------
65
66-- dsyev
67foreign import ccall "lapack-aux.h eig_l_S"
68 dsyev :: Double ::> (Double :> Double ::> IO Int)
69
70-----------------------------------------------------------------------------
71-- zheev
72foreign import ccall "lapack-aux.h eig_l_H"
73 zheev :: (Complex Double) ::> (Double :> (Complex Double) ::> IO Int)
74
75-----------------------------------------------------------------------------
76-- dgesv
77foreign import ccall "lapack-aux.h linearSolveR_l"
78 dgesv :: Double ::> Double ::> Double ::> IO Int
79
80-----------------------------------------------------------------------------
81-- zgesv
82foreign import ccall "lapack-aux.h linearSolveC_l"
83 zgesv :: (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int
84
85-----------------------------------------------------------------------------------
86-- dgels
87foreign 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'.
91linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double
92linearSolveLSR a b = subMatrix (0,0) (cols a, cols b) $ linearSolveLSR_l a b
93
94linearSolveLSR_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
101foreign import ccall "lapack-aux.h linearSolveLSC_l"
102 zgels :: (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int
103
104-----------------------------------------------------------------------------------
105-- dgelss
106foreign import ccall "lapack-aux.h linearSolveSVDR_l"
107 dgelss :: Double -> Double ::> Double ::> Double ::> IO Int
108
109-----------------------------------------------------------------------------------
110-- zgelss
111foreign import ccall "lapack-aux.h linearSolveSVDC_l"
112 zgelss :: Double -> (Complex Double) ::> (Complex Double) ::> (Complex Double) ::> IO Int