diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-01-16 18:17:53 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-01-16 18:17:53 +0000 |
commit | 3fb3a81e63540497a81b717c615f711ce031c76f (patch) | |
tree | a2f4b09636df3ca904b328b35c140ab4c22be093 /lib/Data/Packed/Matrix.hs | |
parent | b8b9e8a91b51e6689a071dbc05f3da857c762e0d (diff) |
vecdisp, scalar, docs
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 7e197d1..fc988af 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -29,7 +29,7 @@ module Data.Packed.Matrix ( | |||
29 | extractRows, | 29 | extractRows, |
30 | ident, diag, diagRect, takeDiag, | 30 | ident, diag, diagRect, takeDiag, |
31 | liftMatrix, liftMatrix2, | 31 | liftMatrix, liftMatrix2, |
32 | format, dispf, disps, vecdisp, | 32 | format, dispf, disps, |
33 | loadMatrix, saveMatrix, fromFile, fileDimensions, | 33 | loadMatrix, saveMatrix, fromFile, fileDimensions, |
34 | readMatrix, fromArray2D | 34 | readMatrix, fromArray2D |
35 | ) where | 35 | ) where |
@@ -230,7 +230,7 @@ this function the user can easily define any desired display function: | |||
230 | 230 | ||
231 | @import Text.Printf(printf)@ | 231 | @import Text.Printf(printf)@ |
232 | 232 | ||
233 | @disp = putStrLn . format \" \" (printf \"%.2f\")@ | 233 | @disp = putStr . format \" \" (printf \"%.2f\")@ |
234 | 234 | ||
235 | -} | 235 | -} |
236 | format :: (Element t) => String -> (t -> String) -> Matrix t -> String | 236 | format :: (Element t) => String -> (t -> String) -> Matrix t -> String |
@@ -249,11 +249,32 @@ dispC d m = disp m (shfc d) | |||
249 | ------------------------------------------------------------------- | 249 | ------------------------------------------------------------------- |
250 | -- display utilities | 250 | -- display utilities |
251 | 251 | ||
252 | -- | Print a matrix with \"autoscaling\" and a given number of decimal places. | 252 | {- | Show a matrix with \"autoscaling\" and a given number of decimal places. |
253 | |||
254 | @disp = putStr . disps 2 | ||
255 | |||
256 | \> disp $ 120 * (3><4) [1..] | ||
257 | 3x4 E3 | ||
258 | 0.12 0.24 0.36 0.48 | ||
259 | 0.60 0.72 0.84 0.96 | ||
260 | 1.08 1.20 1.32 1.44 | ||
261 | @ | ||
262 | -} | ||
253 | disps :: Int -> Matrix Double -> String | 263 | disps :: Int -> Matrix Double -> String |
254 | disps d x = sdims x ++ " " ++ formatScaled d x | 264 | disps d x = sdims x ++ " " ++ formatScaled d x |
255 | 265 | ||
256 | -- | Print a matrix with a given number of decimal places. | 266 | {- | Show a matrix with a given number of decimal places. |
267 | |||
268 | @disp = putStr . dispf 3 | ||
269 | |||
270 | \> disp (1/3 + ident 4) | ||
271 | 4x4 | ||
272 | 1.333 0.333 0.333 0.333 | ||
273 | 0.333 1.333 0.333 0.333 | ||
274 | 0.333 0.333 1.333 0.333 | ||
275 | 0.333 0.333 0.333 1.333 | ||
276 | @ | ||
277 | -} | ||
257 | dispf :: Int -> Matrix Double -> String | 278 | dispf :: Int -> Matrix Double -> String |
258 | dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x | 279 | dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x |
259 | 280 | ||
@@ -272,7 +293,14 @@ formatScaled dec t = "E"++show o++"\n" ++ ss | |||
272 | o = floor $ maximum $ map (logBase 10 . abs) $ toList $ flatten t | 293 | o = floor $ maximum $ map (logBase 10 . abs) $ toList $ flatten t |
273 | fmt = '%':show (dec+3) ++ '.':show dec ++"f" | 294 | fmt = '%':show (dec+3) ++ '.':show dec ++"f" |
274 | 295 | ||
275 | -- | Print a vector using a function for printing matrices. | 296 | {- | Show a vector using a function for showing matrices. |
297 | |||
298 | @disp = putStr . vecdisp (dispf 2) | ||
299 | |||
300 | \> disp (linspace 10 (0,1)) | ||
301 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 | ||
302 | @ | ||
303 | -} | ||
276 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String | 304 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String |
277 | vecdisp f v | 305 | vecdisp f v |
278 | = ((show (dim v) ++ " |> ") ++) . (++"\n") | 306 | = ((show (dim v) ++ " |> ") ++) . (++"\n") |