diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-10-24 09:42:36 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-10-24 09:42:36 +0000 |
commit | 2e441c3f4d08da050540256164456e18519d22ef (patch) | |
tree | faae9372692ac8b618337b3e97f8ff9d44df2d08 /lib/Data/Packed | |
parent | 9c65a03f4e2b3b09f6f2ac606c5b22f6df9cea14 (diff) |
documentation
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 12 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 8 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 77906dc..605a6f3 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -48,12 +48,14 @@ import Data.List(transpose) | |||
48 | - we could carry both the matrix and its (lazily computed) transpose. | 48 | - we could carry both the matrix and its (lazily computed) transpose. |
49 | This may save some transpositions, but it is necessary to keep track of the | 49 | This may save some transpositions, but it is necessary to keep track of the |
50 | data which is actually computed to be used by functions like the matrix product | 50 | data which is actually computed to be used by functions like the matrix product |
51 | which admit both orders. Therefore, maybe it is better to have something like | 51 | which admit both orders. |
52 | viewC and viewF, which may actually perform a transpose if required. | ||
53 | 52 | ||
54 | - but if we need the transposed data and it is not in the structure, we must make | 53 | - but if we need the transposed data and it is not in the structure, we must make |
55 | sure that we touch the same foreignptr that is used in the computation. Access | 54 | sure that we touch the same foreignptr that is used in the computation. |
56 | to such pointer cannot be made by creating a new vector. | 55 | |
56 | - a reasonable solution is using two constructors for a matrix. Transposition just | ||
57 | "flips" the constructor. Actual data transposition is not done if followed by a | ||
58 | matrix product or another transpose. | ||
57 | 59 | ||
58 | -} | 60 | -} |
59 | 61 | ||
@@ -66,7 +68,7 @@ data Matrix t = MC { rows :: Int, cols :: Int, cdat :: Vector t, fdat :: Vector | |||
66 | -- MC: preferred by C, fdat may require a transposition | 68 | -- MC: preferred by C, fdat may require a transposition |
67 | -- MF: preferred by LAPACK, cdat may require a transposition | 69 | -- MF: preferred by LAPACK, cdat may require a transposition |
68 | 70 | ||
69 | -- | matrix transpose | 71 | -- | Matrix transpose. |
70 | trans :: Matrix t -> Matrix t | 72 | trans :: Matrix t -> Matrix t |
71 | trans MC {rows = r, cols = c, cdat = d, fdat = dt } = MF {rows = c, cols = r, fdat = d, cdat = dt } | 73 | trans MC {rows = r, cols = c, cdat = d, fdat = dt } = MF {rows = c, cols = r, fdat = d, cdat = dt } |
72 | trans MF {rows = r, cols = c, fdat = d, cdat = dt } = MC {rows = c, cols = r, cdat = d, fdat = dt } | 74 | trans MF {rows = r, cols = c, fdat = d, cdat = dt } = MC {rows = c, cols = r, cdat = d, fdat = dt } |
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index e94d038..a705975 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -193,6 +193,14 @@ dsp' sep as = unlines . map unwords' $ transpose mtp where | |||
193 | pad n str = replicate (n - length str) ' ' ++ str | 193 | pad n str = replicate (n - length str) ' ' ++ str |
194 | unwords' = concat . intersperse sep | 194 | unwords' = concat . intersperse sep |
195 | 195 | ||
196 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using | ||
197 | this function the user can easily define any desired display function: | ||
198 | |||
199 | @import Text.Printf(printf)@ | ||
200 | |||
201 | @disp = putStrLn . format \" \" (printf \"%.2f\")@ | ||
202 | |||
203 | -} | ||
196 | format :: (Field t) => String -> (t -> String) -> Matrix t -> String | 204 | format :: (Field t) => String -> (t -> String) -> Matrix t -> String |
197 | format sep f m = dsp' sep . map (map f) . toLists $ m | 205 | format sep f m = dsp' sep . map (map f) . toLists $ m |
198 | 206 | ||