diff options
Diffstat (limited to 'lib/Numeric/Matrix.hs')
-rw-r--r-- | lib/Numeric/Matrix.hs | 53 |
1 files changed, 5 insertions, 48 deletions
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs index 7bb79f3..bab5a27 100644 --- a/lib/Numeric/Matrix.hs +++ b/lib/Numeric/Matrix.hs | |||
@@ -15,40 +15,20 @@ | |||
15 | -- Stability : provisional | 15 | -- Stability : provisional |
16 | -- Portability : portable | 16 | -- Portability : portable |
17 | -- | 17 | -- |
18 | -- Numeric instances and functions for 'Matrix'. | ||
19 | -- In the context of the standard numeric operators, one-component | ||
20 | -- vectors and matrices automatically expand to match the dimensions of the other operand. | ||
21 | -- | ||
22 | -- Provides instances of standard classes 'Show', 'Read', 'Eq', | 18 | -- Provides instances of standard classes 'Show', 'Read', 'Eq', |
23 | -- 'Num', 'Fractional', and 'Floating' for 'Matrix'. | 19 | -- 'Num', 'Fractional', and 'Floating' for 'Matrix'. |
24 | -- | 20 | -- |
21 | -- In arithmetic operations one-component | ||
22 | -- vectors and matrices automatically expand to match the dimensions of the other operand. | ||
23 | |||
25 | ----------------------------------------------------------------------------- | 24 | ----------------------------------------------------------------------------- |
26 | 25 | ||
27 | module Numeric.Matrix ( | 26 | module Numeric.Matrix ( |
28 | -- * Basic functions | ||
29 | module Data.Packed.Matrix, | ||
30 | module Numeric.Vector, | ||
31 | -- * Matrix creation | ||
32 | diag, ident, | ||
33 | -- * matrix operations | ||
34 | ctrans, | ||
35 | optimiseMult, | ||
36 | -- * Operators | ||
37 | (<>), (<\>), | ||
38 | -- * IO | ||
39 | dispf, disps, dispcf, vecdisp, latexFormat, format, | ||
40 | loadMatrix, saveMatrix, fromFile, fileDimensions, | ||
41 | readMatrix | ||
42 | ) where | 27 | ) where |
43 | 28 | ||
44 | ------------------------------------------------------------------- | 29 | ------------------------------------------------------------------- |
45 | 30 | ||
46 | import Data.Packed.Matrix | 31 | import Numeric.Container |
47 | import Numeric.Vector | ||
48 | import Numeric.Chain | ||
49 | import Numeric.MatrixBoot | ||
50 | import Numeric.IO | ||
51 | import Numeric.LinearAlgebra.Algorithms | ||
52 | 32 | ||
53 | ------------------------------------------------------------------- | 33 | ------------------------------------------------------------------- |
54 | 34 | ||
@@ -90,26 +70,3 @@ instance (Floating a, Container Vector a, Floating (Vector a), Fractional (Matri | |||
90 | (**) = liftMatrix2Auto (**) | 70 | (**) = liftMatrix2Auto (**) |
91 | sqrt = liftMatrix sqrt | 71 | sqrt = liftMatrix sqrt |
92 | pi = (1><1) [pi] | 72 | pi = (1><1) [pi] |
93 | |||
94 | -------------------------------------------------------- | ||
95 | |||
96 | class Mul a b c | a b -> c where | ||
97 | infixl 7 <> | ||
98 | -- | Matrix-matrix, matrix-vector, and vector-matrix products. | ||
99 | (<>) :: Product t => a t -> b t -> c t | ||
100 | |||
101 | instance Mul Matrix Matrix Matrix where | ||
102 | (<>) = mXm | ||
103 | |||
104 | instance Mul Matrix Vector Vector where | ||
105 | (<>) m v = flatten $ m <> (asColumn v) | ||
106 | |||
107 | instance Mul Vector Matrix Vector where | ||
108 | (<>) v m = flatten $ (asRow v) <> m | ||
109 | |||
110 | -------------------------------------------------------- | ||
111 | |||
112 | -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD). | ||
113 | (<\>) :: (Field a) => Matrix a -> Vector a -> Vector a | ||
114 | infixl 7 <\> | ||
115 | m <\> v = flatten (linearSolveSVD m (reshape 1 v)) | ||