summaryrefslogtreecommitdiff
path: root/lib/Numeric/IO.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
committerAlberto Ruiz <aruiz@um.es>2014-04-30 16:10:20 +0200
commitcf1379fed234cf99b2ccce6d9311bfc5c58ef4a3 (patch)
tree2532837500eb98af048404e33018fa88d8a7f535 /lib/Numeric/IO.hs
parentb8b7b47450a1007d4d8c77bb7d04e2744c3bfcd4 (diff)
improved documentation
Diffstat (limited to 'lib/Numeric/IO.hs')
-rw-r--r--lib/Numeric/IO.hs35
1 files changed, 18 insertions, 17 deletions
diff --git a/lib/Numeric/IO.hs b/lib/Numeric/IO.hs
index dacfa8b..57275ac 100644
--- a/lib/Numeric/IO.hs
+++ b/lib/Numeric/IO.hs
@@ -39,29 +39,27 @@ format sep f m = table sep . map (map f) . toLists $ m
39 39
40{- | Show a matrix with \"autoscaling\" and a given number of decimal places. 40{- | Show a matrix with \"autoscaling\" and a given number of decimal places.
41 41
42@disp = putStr . disps 2 42>>> putStr . disps 2 $ 120 * (3><4) [1..]
43
44\> disp $ 120 * (3><4) [1..]
453x4 E3 433x4 E3
46 0.12 0.24 0.36 0.48 44 0.12 0.24 0.36 0.48
47 0.60 0.72 0.84 0.96 45 0.60 0.72 0.84 0.96
48 1.08 1.20 1.32 1.44 46 1.08 1.20 1.32 1.44
49@ 47
50-} 48-}
51disps :: Int -> Matrix Double -> String 49disps :: Int -> Matrix Double -> String
52disps d x = sdims x ++ " " ++ formatScaled d x 50disps d x = sdims x ++ " " ++ formatScaled d x
53 51
54{- | Show a matrix with a given number of decimal places. 52{- | Show a matrix with a given number of decimal places.
55 53
56@disp = putStr . dispf 3 54>>> dispf 2 (1/3 + ident 3)
55"3x3\n1.33 0.33 0.33\n0.33 1.33 0.33\n0.33 0.33 1.33\n"
56
57>>> putStr . dispf 2 $ (3><4)[1,1.5..]
583x4
591.00 1.50 2.00 2.50
603.00 3.50 4.00 4.50
615.00 5.50 6.00 6.50
57 62
58\> disp (1/3 + ident 4)
594x4
601.333 0.333 0.333 0.333
610.333 1.333 0.333 0.333
620.333 0.333 1.333 0.333
630.333 0.333 0.333 1.333
64@
65-} 63-}
66dispf :: Int -> Matrix Double -> String 64dispf :: Int -> Matrix Double -> String
67dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x 65dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x
@@ -81,11 +79,9 @@ formatScaled dec t = "E"++show o++"\n" ++ ss
81 79
82{- | Show a vector using a function for showing matrices. 80{- | Show a vector using a function for showing matrices.
83 81
84@disp = putStr . vecdisp ('dispf' 2) 82>>> putStr . vecdisp (dispf 2) $ linspace 10 (0,1)
85
86\> disp ('linspace' 10 (0,1))
8710 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 8310 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00
88@ 84
89-} 85-}
90vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String 86vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String
91vecdisp f v 87vecdisp f v
@@ -94,7 +90,12 @@ vecdisp f v
94 . f . trans . reshape 1 90 . f . trans . reshape 1
95 $ v 91 $ v
96 92
97-- | Tool to display matrices with latex syntax. 93{- | Tool to display matrices with latex syntax.
94
95>>> latexFormat "bmatrix" (dispf 2 $ ident 2)
96"\\begin{bmatrix}\n1 & 0\n\\\\\n0 & 1\n\\end{bmatrix}"
97
98-}
98latexFormat :: String -- ^ type of braces: \"matrix\", \"bmatrix\", \"pmatrix\", etc. 99latexFormat :: String -- ^ type of braces: \"matrix\", \"bmatrix\", \"pmatrix\", etc.
99 -> String -- ^ Formatted matrix, with elements separated by spaces and newlines 100 -> String -- ^ Formatted matrix, with elements separated by spaces and newlines
100 -> String 101 -> String