diff options
Diffstat (limited to 'lib/Numeric/IO.hs')
-rw-r--r-- | lib/Numeric/IO.hs | 35 |
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..] | ||
45 | 3x4 E3 | 43 | 3x4 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 | -} |
51 | disps :: Int -> Matrix Double -> String | 49 | disps :: Int -> Matrix Double -> String |
52 | disps d x = sdims x ++ " " ++ formatScaled d x | 50 | disps 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..] | ||
58 | 3x4 | ||
59 | 1.00 1.50 2.00 2.50 | ||
60 | 3.00 3.50 4.00 4.50 | ||
61 | 5.00 5.50 6.00 6.50 | ||
57 | 62 | ||
58 | \> disp (1/3 + ident 4) | ||
59 | 4x4 | ||
60 | 1.333 0.333 0.333 0.333 | ||
61 | 0.333 1.333 0.333 0.333 | ||
62 | 0.333 0.333 1.333 0.333 | ||
63 | 0.333 0.333 0.333 1.333 | ||
64 | @ | ||
65 | -} | 63 | -} |
66 | dispf :: Int -> Matrix Double -> String | 64 | dispf :: Int -> Matrix Double -> String |
67 | dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x | 65 | dispf 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)) | ||
87 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 | 83 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 |
88 | @ | 84 | |
89 | -} | 85 | -} |
90 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String | 86 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String |
91 | vecdisp f v | 87 | vecdisp 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 | -} | ||
98 | latexFormat :: String -- ^ type of braces: \"matrix\", \"bmatrix\", \"pmatrix\", etc. | 99 | latexFormat :: 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 |