summaryrefslogtreecommitdiff
path: root/packages/base/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r--packages/base/src/Data/Packed/Internal/Matrix.hs3
-rw-r--r--packages/base/src/Data/Packed/Matrix.hs6
-rw-r--r--packages/base/src/Data/Packed/Numeric.hs24
3 files changed, 28 insertions, 5 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Matrix.hs b/packages/base/src/Data/Packed/Internal/Matrix.hs
index 91a9466..150b978 100644
--- a/packages/base/src/Data/Packed/Internal/Matrix.hs
+++ b/packages/base/src/Data/Packed/Internal/Matrix.hs
@@ -253,7 +253,8 @@ compat m1 m2 = rows m1 == rows m2 && cols m1 == cols m2
253 operations for selected element types. 253 operations for selected element types.
254 It provides unoptimised defaults for any 'Storable' type, 254 It provides unoptimised defaults for any 'Storable' type,
255 so you can create instances simply as: 255 so you can create instances simply as:
256 @instance Element Foo@. 256
257 >instance Element Foo
257-} 258-}
258class (Storable a) => Element a where 259class (Storable a) => Element a where
259 subMatrixD :: (Int,Int) -- ^ (r0,c0) starting position 260 subMatrixD :: (Int,Int) -- ^ (r0,c0) starting position
diff --git a/packages/base/src/Data/Packed/Matrix.hs b/packages/base/src/Data/Packed/Matrix.hs
index 6445ce4..70b9232 100644
--- a/packages/base/src/Data/Packed/Matrix.hs
+++ b/packages/base/src/Data/Packed/Matrix.hs
@@ -284,7 +284,7 @@ fromLists = fromRows . map fromList
284-- [ 1.0, 2.0, 3.0, 4.0, 5.0 ] 284-- [ 1.0, 2.0, 3.0, 4.0, 5.0 ]
285-- 285--
286asRow :: Storable a => Vector a -> Matrix a 286asRow :: Storable a => Vector a -> Matrix a
287asRow v = reshape (dim v) v 287asRow = trans . asColumn
288 288
289-- | creates a 1-column matrix from a vector 289-- | creates a 1-column matrix from a vector
290-- 290--
@@ -297,7 +297,7 @@ asRow v = reshape (dim v) v
297-- , 5.0 ] 297-- , 5.0 ]
298-- 298--
299asColumn :: Storable a => Vector a -> Matrix a 299asColumn :: Storable a => Vector a -> Matrix a
300asColumn = trans . asRow 300asColumn v = reshape 1 v
301 301
302 302
303 303
@@ -476,7 +476,7 @@ mapMatrixWithIndexM g m = liftM (reshape c) . mapVectorWithIndexM (mk c g) . fla
476 476
477{- | 477{- |
478 478
479>>> mapMatrixWithIndex (\\(i,j) v -> 100*v + 10*fromIntegral i + fromIntegral j) (ident 3:: Matrix Double) 479>>> mapMatrixWithIndex (\(i,j) v -> 100*v + 10*fromIntegral i + fromIntegral j) (ident 3:: Matrix Double)
480(3><3) 480(3><3)
481 [ 100.0, 1.0, 2.0 481 [ 100.0, 1.0, 2.0
482 , 10.0, 111.0, 12.0 482 , 10.0, 111.0, 12.0
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs
index 7aa53f1..6027f43 100644
--- a/packages/base/src/Data/Packed/Numeric.hs
+++ b/packages/base/src/Data/Packed/Numeric.hs
@@ -160,7 +160,29 @@ instance Mul Vector Matrix Vector where
160 160
161-------------------------------------------------------------------------------- 161--------------------------------------------------------------------------------
162 162
163-- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD) 163{- | Least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD)
164
165@
166a = (3><2)
167 [ 1.0, 2.0
168 , 2.0, 4.0
169 , 2.0, -1.0 ]
170@
171
172@
173v = vector [13.0,27.0,1.0]
174@
175
176>>> let x = a <\> v
177>>> x
178fromList [3.0799999999999996,5.159999999999999]
179
180>>> a #> x
181fromList [13.399999999999999,26.799999999999997,1.0]
182
183It also admits multiple right-hand sides stored as columns in a matrix.
184
185-}
164infixl 7 <\> 186infixl 7 <\>
165(<\>) :: (LSDiv c, Field t) => Matrix t -> c t -> c t 187(<\>) :: (LSDiv c, Field t) => Matrix t -> c t -> c t
166(<\>) = linSolve 188(<\>) = linSolve