summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hmatrix.cabal5
-rw-r--r--lib/Numeric/Container.hs15
-rw-r--r--lib/Numeric/HMatrix.hs117
-rw-r--r--lib/Numeric/HMatrix/Data.hs (renamed from lib/Numeric/LinearAlgebra/Data.hs)54
-rw-r--r--lib/Numeric/HMatrix/Devel.hs (renamed from lib/Numeric/LinearAlgebra/Data/Devel.hs)7
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs9
6 files changed, 157 insertions, 50 deletions
diff --git a/hmatrix.cabal b/hmatrix.cabal
index adf06fc..f47629f 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -107,8 +107,9 @@ library
107 Data.Packed.ST, 107 Data.Packed.ST,
108 Data.Packed.Development 108 Data.Packed.Development
109 Graphics.Plot, 109 Graphics.Plot,
110 Numeric.LinearAlgebra.Data 110 Numeric.HMatrix,
111 Numeric.LinearAlgebra.Data.Devel 111 Numeric.HMatrix.Data,
112 Numeric.HMatrix.Devel
112 other-modules: Data.Packed.Internal, 113 other-modules: Data.Packed.Internal,
113 Data.Packed.Internal.Common, 114 Data.Packed.Internal.Common,
114 Data.Packed.Internal.Signatures, 115 Data.Packed.Internal.Signatures,
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 5339c7e..d1ce588 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -105,28 +105,35 @@ cdot u v = udot (conj u) v
105class Contraction a b c | a b -> c, a c -> b, b c -> a 105class Contraction a b c | a b -> c, a c -> b, b c -> a
106 where 106 where
107 infixl 7 <> 107 infixl 7 <>
108 {- | matrix-matrix product, matrix-vector product, unconjugated dot product 108 {- | Matrix-matrix product, matrix-vector product, and unconjugated dot product
109 109
110>>> let a = (3><4) [1..] :: Matrix Double 110>>> let a = (3><4) [1..] :: Matrix Double
111
112>>> a 111>>> a
113(3><4) 112(3><4)
114 [ 1.0, 2.0, 3.0, 4.0 113 [ 1.0, 2.0, 3.0, 4.0
115 , 5.0, 6.0, 7.0, 8.0 114 , 5.0, 6.0, 7.0, 8.0
116 , 9.0, 10.0, 11.0, 12.0 ] 115 , 9.0, 10.0, 11.0, 12.0 ]
117 116
117matrix × matrix:
118
118>>> disp 2 (a <> trans a) 119>>> disp 2 (a <> trans a)
1193x3 1203x3
120 30 70 110 121 30 70 110
121 70 174 278 122 70 174 278
122110 278 446 123110 278 446
123 124
125matrix × vector:
126
124>>> a <> fromList [1,0,2,-1::Double] 127>>> a <> fromList [1,0,2,-1::Double]
125fromList [3.0,11.0,19.0] 128fromList [3.0,11.0,19.0]
126 129
130vector × matrix:
131
127>>> fromList [1,2,3::Double] <> a 132>>> fromList [1,2,3::Double] <> a
128fromList [38.0,44.0,50.0,56.0] 133fromList [38.0,44.0,50.0,56.0]
129 134
135unconjugated dot product:
136
130>>> fromList [1,i] <> fromList[2*i+1,3] 137>>> fromList [1,i] <> fromList[2*i+1,3]
1311.0 :+ 5.0 1381.0 :+ 5.0
132 139
@@ -160,9 +167,9 @@ instance LSDiv Matrix Matrix where
160 167
161-------------------------------------------------------- 168--------------------------------------------------------
162 169
163{- | dot product : @u · v = 'cdot' u v@ 170{- | Dot product : @u · v = 'cdot' u v@
164 171
165 unicode 0x00b7, Alt-Gr . 172 (unicode 0x00b7, Alt-Gr .)
166 173
167>>> fromList [1,i] · fromList[2*i+1,3] 174>>> fromList [1,i] · fromList[2*i+1,3]
1681.0 :+ (-1.0) 1751.0 :+ (-1.0)
diff --git a/lib/Numeric/HMatrix.hs b/lib/Numeric/HMatrix.hs
new file mode 100644
index 0000000..8e0b4a2
--- /dev/null
+++ b/lib/Numeric/HMatrix.hs
@@ -0,0 +1,117 @@
1-----------------------------------------------------------------------------
2{- |
3Module : Numeric.HMatrix
4Copyright : (c) Alberto Ruiz 2006-14
5License : GPL
6
7Maintainer : Alberto Ruiz
8Stability : provisional
9
10This module reexports the most common Linear Algebra functions.
11
12-}
13-----------------------------------------------------------------------------
14module Numeric.HMatrix (
15
16 -- * Basic types and data processing
17 module Numeric.HMatrix.Data,
18
19 -- | The standard numeric classes are defined elementwise.
20 --
21 -- >>> fromList [1,2,3] * fromList [3,0,-2 :: Double]
22 -- fromList [3.0,0.0,-6.0]
23 --
24 -- In arithmetic operations single-element vectors and matrices automatically
25 -- expand to match the dimensions of the other operand.
26 --
27 -- >>> 2 * ident 3
28 -- 2 * ident 3 :: Matrix Double
29 -- (3><3)
30 -- [ 2.0, 0.0, 0.0
31 -- , 0.0, 2.0, 0.0
32 -- , 0.0, 0.0, 2.0 ]
33 --
34
35 -- * Products
36 (<>), (·), outer, kronecker, cross,
37 optimiseMult, scale,
38 sumElements, prodElements, absSum,
39
40 -- * Linear Systems
41 (<\>),
42 linearSolve,
43 linearSolveLS,
44 linearSolveSVD,
45 luSolve,
46 cholSolve,
47
48 -- * Inverse and pseudoinverse
49 inv, pinv, pinvTol,
50
51 -- * Determinant and rank
52 rcond, rank, ranksv,
53 det, invlndet,
54
55 -- * Singular value decomposition
56 svd,
57 fullSVD,
58 thinSVD,
59 compactSVD,
60 singularValues,
61 leftSV, rightSV,
62
63 -- * Eigensystems
64 eig, eigSH, eigSH',
65 eigenvalues, eigenvaluesSH, eigenvaluesSH',
66 geigSH',
67
68 -- * QR
69 qr, rq,
70
71 -- * Cholesky
72 chol, cholSH, mbCholSH,
73
74 -- * Hessenberg
75 hess,
76
77 -- * Schur
78 schur,
79
80 -- * LU
81 lu, luPacked,
82
83 -- * Matrix functions
84 expm,
85 sqrtm,
86 matFunc,
87
88 -- * Nullspace
89 nullspacePrec,
90 nullVector,
91 nullspaceSVD,
92 null1, null1sym,
93
94 orth,
95
96 -- * Norms
97 norm1, norm2, normInf,
98
99 -- * Correlation and Convolution
100 corr, conv, corrMin, corr2, conv2,
101
102 -- * Random arrays
103 rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample,
104
105 -- * Misc
106 meanCov, peps, relativeError, haussholder
107) where
108
109import Numeric.HMatrix.Data
110
111import Numeric.Matrix()
112import Numeric.Vector()
113import Numeric.Container
114import Numeric.LinearAlgebra.Algorithms
115import Numeric.LinearAlgebra.Util
116
117
diff --git a/lib/Numeric/LinearAlgebra/Data.hs b/lib/Numeric/HMatrix/Data.hs
index a3639d5..49dad10 100644
--- a/lib/Numeric/LinearAlgebra/Data.hs
+++ b/lib/Numeric/HMatrix/Data.hs
@@ -1,16 +1,19 @@
1-------------------------------------------------------------------------------- 1--------------------------------------------------------------------------------
2{- | 2{- |
3Module : Numeric.LinearAlgebra.Data 3Module : Numeric.HMatrix.Data
4Copyright : (c) Alberto Ruiz 2014 4Copyright : (c) Alberto Ruiz 2014
5License : GPL 5License : GPL
6 6
7Maintainer : Alberto Ruiz 7Maintainer : Alberto Ruiz
8Stability : provisional 8Stability : provisional
9 9
10Basic data processing.
11
10-} 12-}
11-------------------------------------------------------------------------------- 13--------------------------------------------------------------------------------
12 14
13module Numeric.LinearAlgebra.Data( 15module Numeric.HMatrix.Data(
16
14 -- * Vector 17 -- * Vector
15 -- | 1D arrays are storable vectors from the vector package. 18 -- | 1D arrays are storable vectors from the vector package.
16 19
@@ -19,58 +22,34 @@ module Numeric.LinearAlgebra.Data(
19 -- * Matrix 22 -- * Matrix
20 Matrix, (><), size, (@@>), trans, ctrans, 23 Matrix, (><), size, (@@>), trans, ctrans,
21 24
22 -- * Construction functions 25 -- * Construction
23
24 scalar, konst, build, assoc, accum, linspace, -- ones, zeros, 26 scalar, konst, build, assoc, accum, linspace, -- ones, zeros,
25 27
28 -- * Diagonal
29 ident, diag, diagl, diagRect, takeDiag,
30
26 -- * Data manipulation 31 -- * Data manipulation
27
28 fromList, toList, subVector, takesV, vjoin, 32 fromList, toList, subVector, takesV, vjoin,
29
30 flatten, reshape, asRow, asColumn, row, col, 33 flatten, reshape, asRow, asColumn, row, col,
31 34 fromRows, toRows, fromColumns, toColumns, fromLists, toLists, fromArray2D,
32 fromRows, toRows, fromColumns, toColumns, fromLists, toLists,
33
34 takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud, 35 takeRows, dropRows, takeColumns, dropColumns, subMatrix, (?), (¿), fliprl, flipud,
35 36
36 -- * Diagonal matrices 37 -- * Block matrix
37
38 ident, diag, diagl, diagRect, takeDiag,
39
40 -- * Block matrices
41
42 fromBlocks, (¦), (——), diagBlock, repmat, toBlocks, toBlocksEvery, 38 fromBlocks, (¦), (——), diagBlock, repmat, toBlocks, toBlocksEvery,
43 39
44 -- * Mapping functions 40 -- * Mapping functions
45
46 conj, cmap, step, cond, 41 conj, cmap, step, cond,
47 42
48 -- * Find elements 43 -- * Find elements
49
50 find, maxIndex, minIndex, maxElement, minElement, atIndex, 44 find, maxIndex, minIndex, maxElement, minElement, atIndex,
51 45
52 -- * Products
53
54 (<>), (·), outer, kronecker, cross,
55 sumElements, prodElements, absSum,
56 optimiseMult,
57
58 corr, conv, corrMin, corr2, conv2,
59
60 (<\>),
61
62 -- * Random arrays
63
64 rand, randn, RandDist(..), randomVector, gaussianSample, uniformSample,
65
66 -- * IO 46 -- * IO
67
68 disp, dispf, disps, dispcf, vecdisp, latexFormat, format, 47 disp, dispf, disps, dispcf, vecdisp, latexFormat, format,
69 loadMatrix, saveMatrix, fromFile, fileDimensions, 48 loadMatrix, saveMatrix, fromFile, fileDimensions,
70 readMatrix, 49 readMatrix,
71 fscanfVector, fprintfVector, freadVector, fwriteVector, 50 fscanfVector, fprintfVector, freadVector, fwriteVector,
72 51
73-- * Element conversion 52-- * Conversion
74 Convert(..), 53 Convert(..),
75 Complexable(), 54 Complexable(),
76 RealElement(), 55 RealElement(),
@@ -79,13 +58,12 @@ module Numeric.LinearAlgebra.Data(
79 58
80 IndexOf, 59 IndexOf,
81 60
82 module Data.Complex,
83
84 -- * Misc 61 -- * Misc
85 scale, meanCov, arctan2, 62 arctan2,
86 rows, cols, 63 rows, cols,
87 separable, 64 separable,
88 fromArray2D 65
66 module Data.Complex
89 67
90) where 68) where
91 69
diff --git a/lib/Numeric/LinearAlgebra/Data/Devel.hs b/lib/Numeric/HMatrix/Devel.hs
index 88c980c..37bf826 100644
--- a/lib/Numeric/LinearAlgebra/Data/Devel.hs
+++ b/lib/Numeric/HMatrix/Devel.hs
@@ -1,6 +1,6 @@
1-------------------------------------------------------------------------------- 1--------------------------------------------------------------------------------
2{- | 2{- |
3Module : Numeric.LinearAlgebra.Data.Devel 3Module : Numeric.HMatrix.Devel
4Copyright : (c) Alberto Ruiz 2014 4Copyright : (c) Alberto Ruiz 2014
5License : GPL 5License : GPL
6 6
@@ -12,7 +12,7 @@ The library can be easily extended using the tools in this module.
12-} 12-}
13-------------------------------------------------------------------------------- 13--------------------------------------------------------------------------------
14 14
15module Numeric.LinearAlgebra.Data.Devel( 15module Numeric.HMatrix.Devel(
16 -- * FFI helpers 16 -- * FFI helpers
17 -- | Sample usage, to upload a perspective matrix to a shader. 17 -- | Sample usage, to upload a perspective matrix to a shader.
18 -- 18 --
@@ -51,7 +51,7 @@ module Numeric.LinearAlgebra.Data.Devel(
51 liftMatrix, liftMatrix2, liftMatrix2Auto, 51 liftMatrix, liftMatrix2, liftMatrix2Auto,
52 52
53 -- * Misc 53 -- * Misc
54 Element, Container, Product, Contraction, LSDiv 54 Element, Container, Product, Contraction, LSDiv, Field
55) where 55) where
56 56
57import Data.Packed.Foreign 57import Data.Packed.Foreign
@@ -59,5 +59,6 @@ import Data.Packed.Development
59import Data.Packed.ST 59import Data.Packed.ST
60import Numeric.Container(Container,Contraction,LSDiv,Product) 60import Numeric.Container(Container,Contraction,LSDiv,Product)
61import Data.Packed 61import Data.Packed
62import Numeric.LinearAlgebra.Algorithms(Field)
62 63
63 64
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 7c1c032..de9cb00 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -21,6 +21,8 @@ imported from "Numeric.LinearAlgebra.LAPACK".
21 21
22-} 22-}
23----------------------------------------------------------------------------- 23-----------------------------------------------------------------------------
24{-# OPTIONS_HADDOCK hide #-}
25
24 26
25module Numeric.LinearAlgebra.Algorithms ( 27module Numeric.LinearAlgebra.Algorithms (
26-- * Supported types 28-- * Supported types
@@ -85,8 +87,9 @@ import Data.Array
85import Numeric.ContainerBoot 87import Numeric.ContainerBoot
86 88
87 89
88{- | Class used to define generic linear algebra computations for both real and complex matrices. Only double precision is supported in this version (we can 90{- | Generic linear algebra functions for double precision real and complex matrices.
89transform single precision objects using 'single' and 'double'). 91
92(Single precision data can be converted using 'single' and 'double').
90 93
91-} 94-}
92class (Product t, 95class (Product t,
@@ -438,7 +441,7 @@ i = 0:+1
438 441
439----------------------------------------------------------------------- 442-----------------------------------------------------------------------
440 443
441-- | The nullspace of a matrix from its SVD decomposition. 444-- | The nullspace of a matrix from its precomputed SVD decomposition.
442nullspaceSVD :: Field t 445nullspaceSVD :: Field t
443 => Either Double Int -- ^ Left \"numeric\" zero (eg. 1*'eps'), 446 => Either Double Int -- ^ Left \"numeric\" zero (eg. 1*'eps'),
444 -- or Right \"theoretical\" matrix rank. 447 -- or Right \"theoretical\" matrix rank.