diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed.hs | 2 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 36 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 44 |
3 files changed, 41 insertions, 41 deletions
diff --git a/lib/Data/Packed.hs b/lib/Data/Packed.hs index 668d2f7..53aced9 100644 --- a/lib/Data/Packed.hs +++ b/lib/Data/Packed.hs | |||
@@ -27,7 +27,7 @@ import Data.Complex | |||
27 | import Data.Packed.Internal | 27 | import Data.Packed.Internal |
28 | 28 | ||
29 | -- | conversion utilities | 29 | -- | conversion utilities |
30 | class (Field e) => Container c e where | 30 | class (Element e) => Container c e where |
31 | toComplex :: RealFloat e => (c e, c e) -> c (Complex e) | 31 | toComplex :: RealFloat e => (c e, c e) -> c (Complex e) |
32 | fromComplex :: RealFloat e => c (Complex e) -> (c e, c e) | 32 | fromComplex :: RealFloat e => c (Complex e) -> (c e, c e) |
33 | comp :: RealFloat e => c e -> c (Complex e) | 33 | comp :: RealFloat e => c e -> c (Complex e) |
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index f63ee52..fbab33c 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -84,17 +84,17 @@ type Mt t s = Int -> Int -> Ptr t -> s | |||
84 | -- type t ::> s = Mt t s | 84 | -- type t ::> s = Mt t s |
85 | 85 | ||
86 | -- | the inverse of 'Data.Packed.Matrix.fromLists' | 86 | -- | the inverse of 'Data.Packed.Matrix.fromLists' |
87 | toLists :: (Field t) => Matrix t -> [[t]] | 87 | toLists :: (Element t) => Matrix t -> [[t]] |
88 | toLists m = partit (cols m) . toList . cdat $ m | 88 | toLists m = partit (cols m) . toList . cdat $ m |
89 | 89 | ||
90 | -- | creates a Matrix from a list of vectors | 90 | -- | creates a Matrix from a list of vectors |
91 | fromRows :: Field t => [Vector t] -> Matrix t | 91 | fromRows :: Element t => [Vector t] -> Matrix t |
92 | fromRows vs = case common dim vs of | 92 | fromRows vs = case common dim vs of |
93 | Nothing -> error "fromRows applied to [] or to vectors with different sizes" | 93 | Nothing -> error "fromRows applied to [] or to vectors with different sizes" |
94 | Just c -> reshape c (join vs) | 94 | Just c -> reshape c (join vs) |
95 | 95 | ||
96 | -- | extracts the rows of a matrix as a list of vectors | 96 | -- | extracts the rows of a matrix as a list of vectors |
97 | toRows :: Field t => Matrix t -> [Vector t] | 97 | toRows :: Element t => Matrix t -> [Vector t] |
98 | toRows m = toRows' 0 where | 98 | toRows m = toRows' 0 where |
99 | v = cdat m | 99 | v = cdat m |
100 | r = rows m | 100 | r = rows m |
@@ -103,11 +103,11 @@ toRows m = toRows' 0 where | |||
103 | | otherwise = subVector k c v : toRows' (k+c) | 103 | | otherwise = subVector k c v : toRows' (k+c) |
104 | 104 | ||
105 | -- | Creates a matrix from a list of vectors, as columns | 105 | -- | Creates a matrix from a list of vectors, as columns |
106 | fromColumns :: Field t => [Vector t] -> Matrix t | 106 | fromColumns :: Element t => [Vector t] -> Matrix t |
107 | fromColumns m = trans . fromRows $ m | 107 | fromColumns m = trans . fromRows $ m |
108 | 108 | ||
109 | -- | Creates a list of vectors from the columns of a matrix | 109 | -- | Creates a list of vectors from the columns of a matrix |
110 | toColumns :: Field t => Matrix t -> [Vector t] | 110 | toColumns :: Element t => Matrix t -> [Vector t] |
111 | toColumns m = toRows . trans $ m | 111 | toColumns m = toRows . trans $ m |
112 | 112 | ||
113 | 113 | ||
@@ -152,18 +152,18 @@ where r is the desired number of rows.) | |||
152 | , 9.0, 10.0, 11.0, 12.0 ]@ | 152 | , 9.0, 10.0, 11.0, 12.0 ]@ |
153 | 153 | ||
154 | -} | 154 | -} |
155 | reshape :: Field t => Int -> Vector t -> Matrix t | 155 | reshape :: Element t => Int -> Vector t -> Matrix t |
156 | reshape c v = matrixFromVector RowMajor c v | 156 | reshape c v = matrixFromVector RowMajor c v |
157 | 157 | ||
158 | singleton x = reshape 1 (fromList [x]) | 158 | singleton x = reshape 1 (fromList [x]) |
159 | 159 | ||
160 | -- | application of a vector function on the flattened matrix elements | 160 | -- | application of a vector function on the flattened matrix elements |
161 | liftMatrix :: (Field a, Field b) => (Vector a -> Vector b) -> Matrix a -> Matrix b | 161 | liftMatrix :: (Element a, Element b) => (Vector a -> Vector b) -> Matrix a -> Matrix b |
162 | liftMatrix f MC { cols = c, cdat = d } = matrixFromVector RowMajor c (f d) | 162 | liftMatrix f MC { cols = c, cdat = d } = matrixFromVector RowMajor c (f d) |
163 | liftMatrix f MF { cols = c, fdat = d } = matrixFromVector ColumnMajor c (f d) | 163 | liftMatrix f MF { cols = c, fdat = d } = matrixFromVector ColumnMajor c (f d) |
164 | 164 | ||
165 | -- | application of a vector function on the flattened matrices elements | 165 | -- | application of a vector function on the flattened matrices elements |
166 | liftMatrix2 :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t | 166 | liftMatrix2 :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t |
167 | liftMatrix2 f m1 m2 | 167 | liftMatrix2 f m1 m2 |
168 | | not (compat m1 m2) = error "nonconformant matrices in liftMatrix2" | 168 | | not (compat m1 m2) = error "nonconformant matrices in liftMatrix2" |
169 | | otherwise = case m1 of | 169 | | otherwise = case m1 of |
@@ -176,8 +176,8 @@ compat m1 m2 = rows m1 == rows m2 && cols m1 == cols m2 | |||
176 | 176 | ||
177 | ---------------------------------------------------------------- | 177 | ---------------------------------------------------------------- |
178 | 178 | ||
179 | -- | Optimized matrix computations are provided for elements in the Field class. | 179 | -- | Optimized matrix computations are provided for elements in the Element class. |
180 | class (Storable a, Floating a) => Field a where | 180 | class (Storable a, Floating a) => Element a where |
181 | constantD :: a -> Int -> Vector a | 181 | constantD :: a -> Int -> Vector a |
182 | transdata :: Int -> Vector a -> Int -> Vector a | 182 | transdata :: Int -> Vector a -> Int -> Vector a |
183 | multiplyD :: Matrix a -> Matrix a -> Matrix a | 183 | multiplyD :: Matrix a -> Matrix a -> Matrix a |
@@ -186,14 +186,14 @@ class (Storable a, Floating a) => Field a where | |||
186 | -> Matrix a -> Matrix a | 186 | -> Matrix a -> Matrix a |
187 | diagD :: Vector a -> Matrix a | 187 | diagD :: Vector a -> Matrix a |
188 | 188 | ||
189 | instance Field Double where | 189 | instance Element Double where |
190 | constantD = constantR | 190 | constantD = constantR |
191 | transdata = transdataR | 191 | transdata = transdataR |
192 | multiplyD = multiplyR | 192 | multiplyD = multiplyR |
193 | subMatrixD = subMatrixR | 193 | subMatrixD = subMatrixR |
194 | diagD = diagR | 194 | diagD = diagR |
195 | 195 | ||
196 | instance Field (Complex Double) where | 196 | instance Element (Complex Double) where |
197 | constantD = constantC | 197 | constantD = constantC |
198 | transdata = transdataC | 198 | transdata = transdataC |
199 | multiplyD = multiplyC | 199 | multiplyD = multiplyC |
@@ -202,7 +202,7 @@ instance Field (Complex Double) where | |||
202 | 202 | ||
203 | ------------------------------------------------------------------ | 203 | ------------------------------------------------------------------ |
204 | 204 | ||
205 | (>|<) :: (Field a) => Int -> Int -> [a] -> Matrix a | 205 | (>|<) :: (Element a) => Int -> Int -> [a] -> Matrix a |
206 | r >|< c = f where | 206 | r >|< c = f where |
207 | f l | dim v == r*c = matrixFromVector ColumnMajor c v | 207 | f l | dim v == r*c = matrixFromVector ColumnMajor c v |
208 | | otherwise = error $ "inconsistent list size = " | 208 | | otherwise = error $ "inconsistent list size = " |
@@ -260,13 +260,13 @@ foreign import ccall safe "auxi.h multiplyC" | |||
260 | -> Int -> Int -> Ptr (Complex Double) | 260 | -> Int -> Int -> Ptr (Complex Double) |
261 | -> IO Int | 261 | -> IO Int |
262 | 262 | ||
263 | multiply' :: (Field a) => MatrixOrder -> Matrix a -> Matrix a -> Matrix a | 263 | multiply' :: (Element a) => MatrixOrder -> Matrix a -> Matrix a -> Matrix a |
264 | multiply' RowMajor a b = multiplyD a b | 264 | multiply' RowMajor a b = multiplyD a b |
265 | multiply' ColumnMajor a b = trans $ multiplyD (trans b) (trans a) | 265 | multiply' ColumnMajor a b = trans $ multiplyD (trans b) (trans a) |
266 | 266 | ||
267 | 267 | ||
268 | -- | matrix product | 268 | -- | matrix product |
269 | multiply :: (Field a) => Matrix a -> Matrix a -> Matrix a | 269 | multiply :: (Element a) => Matrix a -> Matrix a -> Matrix a |
270 | multiply = multiplyD | 270 | multiply = multiplyD |
271 | 271 | ||
272 | ---------------------------------------------------------------------- | 272 | ---------------------------------------------------------------------- |
@@ -287,7 +287,7 @@ subMatrixC (r0,c0) (rt,ct) x = | |||
287 | reshape (2*cols x) . asReal . cdat $ x | 287 | reshape (2*cols x) . asReal . cdat $ x |
288 | 288 | ||
289 | -- | Extracts a submatrix from a matrix. | 289 | -- | Extracts a submatrix from a matrix. |
290 | subMatrix :: Field a | 290 | subMatrix :: Element a |
291 | => (Int,Int) -- ^ (r0,c0) starting position | 291 | => (Int,Int) -- ^ (r0,c0) starting position |
292 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix | 292 | -> (Int,Int) -- ^ (rt,ct) dimensions of submatrix |
293 | -> Matrix a -- ^ input matrix | 293 | -> Matrix a -- ^ input matrix |
@@ -313,7 +313,7 @@ diagC = diagAux c_diagC "diagC" | |||
313 | foreign import ccall "auxi.h diagC" c_diagC :: TCVCM | 313 | foreign import ccall "auxi.h diagC" c_diagC :: TCVCM |
314 | 314 | ||
315 | -- | creates a square matrix with the given diagonal | 315 | -- | creates a square matrix with the given diagonal |
316 | diag :: Field a => Vector a -> Matrix a | 316 | diag :: Element a => Vector a -> Matrix a |
317 | diag = diagD | 317 | diag = diagD |
318 | 318 | ||
319 | ------------------------------------------------------------------------ | 319 | ------------------------------------------------------------------------ |
@@ -340,7 +340,7 @@ foreign import ccall safe "auxi.h constantC" | |||
340 | @> constant 2 7 | 340 | @> constant 2 7 |
341 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ | 341 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ |
342 | -} | 342 | -} |
343 | constant :: Field a => a -> Int -> Vector a | 343 | constant :: Element a => a -> Int -> Vector a |
344 | constant = constantD | 344 | constant = constantD |
345 | 345 | ||
346 | -------------------------------------------------------------------------- | 346 | -------------------------------------------------------------------------- |
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index a705975..e96500f 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -14,7 +14,7 @@ | |||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | 15 | ||
16 | module Data.Packed.Matrix ( | 16 | module Data.Packed.Matrix ( |
17 | Field, | 17 | Element, |
18 | Matrix,rows,cols, | 18 | Matrix,rows,cols, |
19 | (><), | 19 | (><), |
20 | trans, | 20 | trans, |
@@ -41,13 +41,13 @@ import Data.List(transpose,intersperse) | |||
41 | import Data.Array | 41 | import Data.Array |
42 | 42 | ||
43 | -- | creates a matrix from a vertical list of matrices | 43 | -- | creates a matrix from a vertical list of matrices |
44 | joinVert :: Field t => [Matrix t] -> Matrix t | 44 | joinVert :: Element t => [Matrix t] -> Matrix t |
45 | joinVert ms = case common cols ms of | 45 | joinVert ms = case common cols ms of |
46 | Nothing -> error "joinVert on matrices with different number of columns" | 46 | Nothing -> error "joinVert on matrices with different number of columns" |
47 | Just c -> reshape c $ join (map cdat ms) | 47 | Just c -> reshape c $ join (map cdat ms) |
48 | 48 | ||
49 | -- | creates a matrix from a horizontal list of matrices | 49 | -- | creates a matrix from a horizontal list of matrices |
50 | joinHoriz :: Field t => [Matrix t] -> Matrix t | 50 | joinHoriz :: Element t => [Matrix t] -> Matrix t |
51 | joinHoriz ms = trans. joinVert . map trans $ ms | 51 | joinHoriz ms = trans. joinVert . map trans $ ms |
52 | 52 | ||
53 | {- | Creates a matrix from blocks given as a list of lists of matrices: | 53 | {- | Creates a matrix from blocks given as a list of lists of matrices: |
@@ -63,15 +63,15 @@ joinHoriz ms = trans. joinVert . map trans $ ms | |||
63 | , -1.0, -1.0, -1.0, -1.0, 0.0, 7.0, 0.0 | 63 | , -1.0, -1.0, -1.0, -1.0, 0.0, 7.0, 0.0 |
64 | , -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 2.0 ]@ | 64 | , -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 2.0 ]@ |
65 | -} | 65 | -} |
66 | fromBlocks :: Field t => [[Matrix t]] -> Matrix t | 66 | fromBlocks :: Element t => [[Matrix t]] -> Matrix t |
67 | fromBlocks = joinVert . map joinHoriz | 67 | fromBlocks = joinVert . map joinHoriz |
68 | 68 | ||
69 | -- | Reverse rows | 69 | -- | Reverse rows |
70 | flipud :: Field t => Matrix t -> Matrix t | 70 | flipud :: Element t => Matrix t -> Matrix t |
71 | flipud m = fromRows . reverse . toRows $ m | 71 | flipud m = fromRows . reverse . toRows $ m |
72 | 72 | ||
73 | -- | Reverse columns | 73 | -- | Reverse columns |
74 | fliprl :: Field t => Matrix t -> Matrix t | 74 | fliprl :: Element t => Matrix t -> Matrix t |
75 | fliprl m = fromColumns . reverse . toColumns $ m | 75 | fliprl m = fromColumns . reverse . toColumns $ m |
76 | 76 | ||
77 | ------------------------------------------------------------ | 77 | ------------------------------------------------------------ |
@@ -84,7 +84,7 @@ fliprl m = fromColumns . reverse . toColumns $ m | |||
84 | , 0.0, 5.0, 0.0, 0.0 | 84 | , 0.0, 5.0, 0.0, 0.0 |
85 | , 0.0, 0.0, 5.0, 0.0 ]@ | 85 | , 0.0, 0.0, 5.0, 0.0 ]@ |
86 | -} | 86 | -} |
87 | diagRect :: (Field t, Num t) => Vector t -> Int -> Int -> Matrix t | 87 | diagRect :: (Element t, Num t) => Vector t -> Int -> Int -> Matrix t |
88 | diagRect s r c | 88 | diagRect s r c |
89 | | dim s < min r c = error "diagRect" | 89 | | dim s < min r c = error "diagRect" |
90 | | r == c = diag s | 90 | | r == c = diag s |
@@ -93,11 +93,11 @@ diagRect s r c | |||
93 | where zeros (r,c) = reshape c $ constantD 0 (r*c) | 93 | where zeros (r,c) = reshape c $ constantD 0 (r*c) |
94 | 94 | ||
95 | -- | extracts the diagonal from a rectangular matrix | 95 | -- | extracts the diagonal from a rectangular matrix |
96 | takeDiag :: (Field t) => Matrix t -> Vector t | 96 | takeDiag :: (Element t) => Matrix t -> Vector t |
97 | takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] | 97 | takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] |
98 | 98 | ||
99 | -- | creates the identity matrix of given dimension | 99 | -- | creates the identity matrix of given dimension |
100 | ident :: Field a => Int -> Matrix a | 100 | ident :: Element a => Int -> Matrix a |
101 | ident n = diag (constant 1 n) | 101 | ident n = diag (constant 1 n) |
102 | 102 | ||
103 | ------------------------------------------------------------ | 103 | ------------------------------------------------------------ |
@@ -112,7 +112,7 @@ ident n = diag (constant 1 n) | |||
112 | This is the format produced by the instances of Show (Matrix a), which | 112 | This is the format produced by the instances of Show (Matrix a), which |
113 | can also be used for input. | 113 | can also be used for input. |
114 | -} | 114 | -} |
115 | (><) :: (Field a) => Int -> Int -> [a] -> Matrix a | 115 | (><) :: (Element a) => Int -> Int -> [a] -> Matrix a |
116 | r >< c = f where | 116 | r >< c = f where |
117 | f l | dim v == r*c = matrixFromVector RowMajor c v | 117 | f l | dim v == r*c = matrixFromVector RowMajor c v |
118 | | otherwise = error $ "inconsistent list size = " | 118 | | otherwise = error $ "inconsistent list size = " |
@@ -122,16 +122,16 @@ r >< c = f where | |||
122 | ---------------------------------------------------------------- | 122 | ---------------------------------------------------------------- |
123 | 123 | ||
124 | -- | Creates a matrix with the first n rows of another matrix | 124 | -- | Creates a matrix with the first n rows of another matrix |
125 | takeRows :: Field t => Int -> Matrix t -> Matrix t | 125 | takeRows :: Element t => Int -> Matrix t -> Matrix t |
126 | takeRows n mat = subMatrix (0,0) (n, cols mat) mat | 126 | takeRows n mat = subMatrix (0,0) (n, cols mat) mat |
127 | -- | Creates a copy of a matrix without the first n rows | 127 | -- | Creates a copy of a matrix without the first n rows |
128 | dropRows :: Field t => Int -> Matrix t -> Matrix t | 128 | dropRows :: Element t => Int -> Matrix t -> Matrix t |
129 | dropRows n mat = subMatrix (n,0) (rows mat - n, cols mat) mat | 129 | dropRows n mat = subMatrix (n,0) (rows mat - n, cols mat) mat |
130 | -- |Creates a matrix with the first n columns of another matrix | 130 | -- |Creates a matrix with the first n columns of another matrix |
131 | takeColumns :: Field t => Int -> Matrix t -> Matrix t | 131 | takeColumns :: Element t => Int -> Matrix t -> Matrix t |
132 | takeColumns n mat = subMatrix (0,0) (rows mat, n) mat | 132 | takeColumns n mat = subMatrix (0,0) (rows mat, n) mat |
133 | -- | Creates a copy of a matrix without the first n columns | 133 | -- | Creates a copy of a matrix without the first n columns |
134 | dropColumns :: Field t => Int -> Matrix t -> Matrix t | 134 | dropColumns :: Element t => Int -> Matrix t -> Matrix t |
135 | dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat | 135 | dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat |
136 | 136 | ||
137 | ---------------------------------------------------------------- | 137 | ---------------------------------------------------------------- |
@@ -141,7 +141,7 @@ dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat | |||
141 | @\> flatten ('ident' 3) | 141 | @\> flatten ('ident' 3) |
142 | 9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ | 142 | 9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ |
143 | -} | 143 | -} |
144 | flatten :: Field t => Matrix t -> Vector t | 144 | flatten :: Element t => Matrix t -> Vector t |
145 | flatten = cdat | 145 | flatten = cdat |
146 | 146 | ||
147 | {- | Creates a 'Matrix' from a list of lists (considered as rows). | 147 | {- | Creates a 'Matrix' from a list of lists (considered as rows). |
@@ -152,20 +152,20 @@ flatten = cdat | |||
152 | , 3.0, 4.0 | 152 | , 3.0, 4.0 |
153 | , 5.0, 6.0 ]@ | 153 | , 5.0, 6.0 ]@ |
154 | -} | 154 | -} |
155 | fromLists :: Field t => [[t]] -> Matrix t | 155 | fromLists :: Element t => [[t]] -> Matrix t |
156 | fromLists = fromRows . map fromList | 156 | fromLists = fromRows . map fromList |
157 | 157 | ||
158 | -- | creates a 1-row matrix from a vector | 158 | -- | creates a 1-row matrix from a vector |
159 | asRow :: Field a => Vector a -> Matrix a | 159 | asRow :: Element a => Vector a -> Matrix a |
160 | asRow v = reshape (dim v) v | 160 | asRow v = reshape (dim v) v |
161 | 161 | ||
162 | -- | creates a 1-column matrix from a vector | 162 | -- | creates a 1-column matrix from a vector |
163 | asColumn :: Field a => Vector a -> Matrix a | 163 | asColumn :: Element a => Vector a -> Matrix a |
164 | asColumn v = reshape 1 v | 164 | asColumn v = reshape 1 v |
165 | 165 | ||
166 | ----------------------------------------------------- | 166 | ----------------------------------------------------- |
167 | 167 | ||
168 | fromArray2D :: (Field e) => Array (Int, Int) e -> Matrix e | 168 | fromArray2D :: (Element e) => Array (Int, Int) e -> Matrix e |
169 | fromArray2D m = (r><c) (elems m) | 169 | fromArray2D m = (r><c) (elems m) |
170 | where ((r0,c0),(r1,c1)) = bounds m | 170 | where ((r0,c0),(r1,c1)) = bounds m |
171 | r = r1-r0+1 | 171 | r = r1-r0+1 |
@@ -201,7 +201,7 @@ this function the user can easily define any desired display function: | |||
201 | @disp = putStrLn . format \" \" (printf \"%.2f\")@ | 201 | @disp = putStrLn . format \" \" (printf \"%.2f\")@ |
202 | 202 | ||
203 | -} | 203 | -} |
204 | format :: (Field t) => String -> (t -> String) -> Matrix t -> String | 204 | format :: (Element t) => String -> (t -> String) -> Matrix t -> String |
205 | format sep f m = dsp' sep . map (map f) . toLists $ m | 205 | format sep f m = dsp' sep . map (map f) . toLists $ m |
206 | 206 | ||
207 | disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m | 207 | disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m |
@@ -217,7 +217,7 @@ readMatrix :: String -> Matrix Double | |||
217 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines | 217 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines |
218 | 218 | ||
219 | -- | rearranges the rows of a matrix according to the order given in a list of integers. | 219 | -- | rearranges the rows of a matrix according to the order given in a list of integers. |
220 | extractRows :: Field t => [Int] -> Matrix t -> Matrix t | 220 | extractRows :: Element t => [Int] -> Matrix t -> Matrix t |
221 | extractRows l m = fromRows $ extract (toRows $ m) l | 221 | extractRows l m = fromRows $ extract (toRows $ m) l |
222 | where extract l is = [l!!i |i<-is] | 222 | where extract l is = [l!!i |i<-is] |
223 | 223 | ||
@@ -231,5 +231,5 @@ extractRows l m = fromRows $ extract (toRows $ m) l | |||
231 | , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]@ | 231 | , 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ]@ |
232 | 232 | ||
233 | -} | 233 | -} |
234 | repmat :: (Field t) => Matrix t -> Int -> Int -> Matrix t | 234 | repmat :: (Element t) => Matrix t -> Int -> Int -> Matrix t |
235 | repmat m r c = fromBlocks $ partit c $ replicate (r*c) m \ No newline at end of file | 235 | repmat m r c = fromBlocks $ partit c $ replicate (r*c) m \ No newline at end of file |