summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/IO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/IO.hs')
-rw-r--r--packages/base/src/Internal/IO.hs9
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
23import Text.Printf(printf, PrintfArg, PrintfType) 23import Text.Printf(printf, PrintfArg, PrintfType)
24import Data.List(intersperse,transpose) 24import Data.List(intersperse,transpose)
25import Data.Complex 25import Data.Complex
26import 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-}
48format :: (Element t) => String -> (t -> String) -> Matrix t -> String 49format :: (Storable t) => String -> (t -> String) -> Matrix t -> String
49format sep f m = table sep . map (map f) . toLists $ m 50format 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
81sdims :: Matrix t -> [Char] 82sdims :: Matrix t -> [Char]
82sdims x = show (rows x) ++ "x" ++ show (cols x) 83sdims x = show (rows x) ++ "x" ++ show (cols x)
83 84
84formatFixed :: (Show a, Text.Printf.PrintfArg t, Element t) 85formatFixed :: (Show a, Text.Printf.PrintfArg t, Storable t)
85 => a -> Matrix t -> String 86 => a -> Matrix t -> String
86formatFixed d x = format " " (printf ("%."++show d++"f")) $ x 87formatFixed d x = format " " (printf ("%."++show d++"f")) $ x
87 88
88isInt :: Matrix Double -> Bool 89isInt :: Matrix Double -> Bool
89isInt = all lookslikeInt . toList . flatten 90isInt = all lookslikeInt . toList . flatten
90 91
91formatScaled :: (Text.Printf.PrintfArg b, RealFrac b, Floating b, Num t, Element b, Show t) 92formatScaled :: (Text.Printf.PrintfArg b, RealFrac b, Floating b, Num t, Storable b, Show t)
92 => t -> Matrix b -> [Char] 93 => t -> Matrix b -> [Char]
93formatScaled dec t = "E"++show o++"\n" ++ ss 94formatScaled 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
10410 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00 10510 |> 0.00 0.11 0.22 0.33 0.44 0.56 0.67 0.78 0.89 1.00
105 106
106-} 107-}
107vecdisp :: (Element t) => (Matrix t -> String) -> Vector t -> String 108vecdisp :: (Storable t) => (Matrix t -> String) -> Vector t -> String
108vecdisp f v 109vecdisp 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"))