diff options
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 438dabc..d5a287d 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -30,7 +30,7 @@ module Data.Packed.Matrix ( | |||
30 | extractRows, | 30 | extractRows, |
31 | ident, diag, diagRect, takeDiag, | 31 | ident, diag, diagRect, takeDiag, |
32 | liftMatrix, liftMatrix2, liftMatrix2Auto, | 32 | liftMatrix, liftMatrix2, liftMatrix2Auto, |
33 | dispf, disps, dispcf, latexFormat, format, | 33 | dispf, disps, dispcf, vecdisp, latexFormat, format, |
34 | loadMatrix, saveMatrix, fromFile, fileDimensions, | 34 | loadMatrix, saveMatrix, fromFile, fileDimensions, |
35 | readMatrix, fromArray2D | 35 | readMatrix, fromArray2D |
36 | ) where | 36 | ) where |
@@ -314,6 +314,21 @@ formatScaled dec t = "E"++show o++"\n" ++ ss | |||
314 | o = floor $ maximum $ map (logBase 10 . abs) $ toList $ flatten t | 314 | o = floor $ maximum $ map (logBase 10 . abs) $ toList $ flatten t |
315 | fmt = '%':show (dec+3) ++ '.':show dec ++"f" | 315 | fmt = '%':show (dec+3) ++ '.':show dec ++"f" |
316 | 316 | ||
317 | {- | Show a vector using a function for showing matrices. | ||
318 | |||
319 | @disp = putStr . vecdisp ('dispf' 2) | ||
320 | |||
321 | \> disp ('linspace' 10 (0,1)) | ||
322 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 | ||
323 | @ | ||
324 | -} | ||
325 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String | ||
326 | vecdisp f v | ||
327 | = ((show (dim v) ++ " |> ") ++) . (++"\n") | ||
328 | . unwords . lines . tail . dropWhile (not . (`elem` " \n")) | ||
329 | . f . trans . reshape 1 | ||
330 | $ v | ||
331 | |||
317 | -- | Tool to display matrices with latex syntax. | 332 | -- | Tool to display matrices with latex syntax. |
318 | latexFormat :: String -- ^ type of braces: \"matrix\", \"bmatrix\", \"pmatrix\", etc. | 333 | latexFormat :: String -- ^ type of braces: \"matrix\", \"bmatrix\", \"pmatrix\", etc. |
319 | -> String -- ^ Formatted matrix, with elements separated by spaces and newlines | 334 | -> String -- ^ Formatted matrix, with elements separated by spaces and newlines |