diff options
Diffstat (limited to 'packages/base/src/Internal/IO.hs')
-rw-r--r-- | packages/base/src/Internal/IO.hs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/packages/base/src/Internal/IO.hs b/packages/base/src/Internal/IO.hs index b0f5606..de5eea5 100644 --- a/packages/base/src/Internal/IO.hs +++ b/packages/base/src/Internal/IO.hs | |||
@@ -23,6 +23,7 @@ import Internal.Vectorized | |||
23 | import Text.Printf(printf, PrintfArg, PrintfType) | 23 | import Text.Printf(printf, PrintfArg, PrintfType) |
24 | import Data.List(intersperse,transpose) | 24 | import Data.List(intersperse,transpose) |
25 | import Data.Complex | 25 | import Data.Complex |
26 | import Foreign.Storable | ||
26 | 27 | ||
27 | 28 | ||
28 | -- | Formatting tool | 29 | -- | Formatting tool |
@@ -45,7 +46,7 @@ this function the user can easily define any desired display function: | |||
45 | @disp = putStr . format \" \" (printf \"%.2f\")@ | 46 | @disp = putStr . format \" \" (printf \"%.2f\")@ |
46 | 47 | ||
47 | -} | 48 | -} |
48 | format :: (Element t) => String -> (t -> String) -> Matrix t -> String | 49 | format :: (Storable t) => String -> (t -> String) -> Matrix t -> String |
49 | format sep f m = table sep . map (map f) . toLists $ m | 50 | format sep f m = table sep . map (map f) . toLists $ m |
50 | 51 | ||
51 | {- | Show a matrix with \"autoscaling\" and a given number of decimal places. | 52 | {- | Show a matrix with \"autoscaling\" and a given number of decimal places. |
@@ -81,14 +82,14 @@ dispf d x = sdims x ++ "\n" ++ formatFixed (if isInt x then 0 else d) x | |||
81 | sdims :: Matrix t -> [Char] | 82 | sdims :: Matrix t -> [Char] |
82 | sdims x = show (rows x) ++ "x" ++ show (cols x) | 83 | sdims x = show (rows x) ++ "x" ++ show (cols x) |
83 | 84 | ||
84 | formatFixed :: (Show a, Text.Printf.PrintfArg t, Element t) | 85 | formatFixed :: (Show a, Text.Printf.PrintfArg t, Storable t) |
85 | => a -> Matrix t -> String | 86 | => a -> Matrix t -> String |
86 | formatFixed d x = format " " (printf ("%."++show d++"f")) $ x | 87 | formatFixed d x = format " " (printf ("%."++show d++"f")) $ x |
87 | 88 | ||
88 | isInt :: Matrix Double -> Bool | 89 | isInt :: Matrix Double -> Bool |
89 | isInt = all lookslikeInt . toList . flatten | 90 | isInt = all lookslikeInt . toList . flatten |
90 | 91 | ||
91 | formatScaled :: (Text.Printf.PrintfArg b, RealFrac b, Floating b, Num t, Element b, Show t) | 92 | formatScaled :: (Text.Printf.PrintfArg b, RealFrac b, Floating b, Num t, Storable b, Show t) |
92 | => t -> Matrix b -> [Char] | 93 | => t -> Matrix b -> [Char] |
93 | formatScaled dec t = "E"++show o++"\n" ++ ss | 94 | formatScaled dec t = "E"++show o++"\n" ++ ss |
94 | where ss = format " " (printf fmt. g) t | 95 | where ss = format " " (printf fmt. g) t |
@@ -104,7 +105,7 @@ formatScaled dec t = "E"++show o++"\n" ++ ss | |||
104 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 | 105 | 10 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 |
105 | 106 | ||
106 | -} | 107 | -} |
107 | vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String | 108 | vecdisp :: (Storable t) => (Matrix t -> String) -> Vector t -> String |
108 | vecdisp f v | 109 | vecdisp f v |
109 | = ((show (dim v) ++ " |> ") ++) . (++"\n") | 110 | = ((show (dim v) ++ " |> ") ++) . (++"\n") |
110 | . unwords . lines . tail . dropWhile (not . (`elem` " \n")) | 111 | . unwords . lines . tail . dropWhile (not . (`elem` " \n")) |