diff options
author | Alberto Ruiz <aruiz@um.es> | 2013-03-19 10:27:29 -0700 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2013-03-19 10:27:29 -0700 |
commit | 55db8511c95a4e5ef0904940dff2a9a36696c8f6 (patch) | |
tree | c1bc4545d7e68e1be5deda703b3d45f948daa9e5 /lib | |
parent | 55edd1062e41e58c702e8049849e44333c8c83d7 (diff) | |
parent | 167ee54f28248d55da72bcb22c3335f8448efcfa (diff) |
Merge pull request #35 from bgamari/master
A few fixes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index ca96c50..c1a9b24 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -46,7 +46,6 @@ import Data.Array | |||
46 | 46 | ||
47 | import Data.List(transpose,intersperse) | 47 | import Data.List(transpose,intersperse) |
48 | import Foreign.Storable(Storable) | 48 | import Foreign.Storable(Storable) |
49 | import Control.Arrow((***)) | ||
50 | 49 | ||
51 | ------------------------------------------------------------------- | 50 | ------------------------------------------------------------------- |
52 | 51 | ||
@@ -158,7 +157,7 @@ adaptBlocks ms = ms' where | |||
158 | 157 | ||
159 | ----------------------------------------------------------- | 158 | ----------------------------------------------------------- |
160 | 159 | ||
161 | -- | Reverse rows | 160 | -- | Reverse rows |
162 | flipud :: Element t => Matrix t -> Matrix t | 161 | flipud :: Element t => Matrix t -> Matrix t |
163 | flipud m = fromRows . reverse . toRows $ m | 162 | flipud m = fromRows . reverse . toRows $ m |
164 | 163 | ||
@@ -273,7 +272,7 @@ Hilbert matrix of order N: | |||
273 | buildMatrix :: Element a => Int -> Int -> ((Int, Int) -> a) -> Matrix a | 272 | buildMatrix :: Element a => Int -> Int -> ((Int, Int) -> a) -> Matrix a |
274 | buildMatrix rc cc f = | 273 | buildMatrix rc cc f = |
275 | fromLists $ map (map f) | 274 | fromLists $ map (map f) |
276 | $ map (\ ri -> map (\ ci -> (ri, ci)) [0 .. (cc - 1)]) [0 .. (rc - 1)] | 275 | $ map (\ ri -> map (\ ci -> (ri, ci)) [0 .. (cc - 1)]) [0 .. (rc - 1)] |
277 | 276 | ||
278 | ----------------------------------------------------- | 277 | ----------------------------------------------------- |
279 | 278 | ||
@@ -284,7 +283,7 @@ fromArray2D m = (r><c) (elems m) | |||
284 | c = c1-c0+1 | 283 | c = c1-c0+1 |
285 | 284 | ||
286 | 285 | ||
287 | -- | rearranges the rows of a matrix according to the order given in a list of integers. | 286 | -- | rearranges the rows of a matrix according to the order given in a list of integers. |
288 | extractRows :: Element t => [Int] -> Matrix t -> Matrix t | 287 | extractRows :: Element t => [Int] -> Matrix t -> Matrix t |
289 | extractRows l m = fromRows $ extract (toRows m) l | 288 | extractRows l m = fromRows $ extract (toRows m) l |
290 | where extract l' is = [l'!!i |i<-is] | 289 | where extract l' is = [l'!!i |i<-is] |
@@ -352,9 +351,9 @@ toBlocksEvery r c m = toBlocks rs cs m where | |||
352 | 351 | ||
353 | ------------------------------------------------------------------- | 352 | ------------------------------------------------------------------- |
354 | 353 | ||
355 | mk c g = \k v -> g ((fromIntegral *** fromIntegral) (divMod k c)) v | 354 | mk c g = \k v -> g (divMod k c) v |
356 | 355 | ||
357 | {- | | 356 | {- | |
358 | 357 | ||
359 | @ghci> mapMatrixWithIndexM_ (\\(i,j) v -> printf \"m[%.0f,%.0f] = %.f\\n\" i j v :: IO()) ((2><3)[1 :: Double ..]) | 358 | @ghci> mapMatrixWithIndexM_ (\\(i,j) v -> printf \"m[%.0f,%.0f] = %.f\\n\" i j v :: IO()) ((2><3)[1 :: Double ..]) |
360 | m[0,0] = 1 | 359 | m[0,0] = 1 |
@@ -367,8 +366,8 @@ m[1,2] = 6@ | |||
367 | mapMatrixWithIndexM_ | 366 | mapMatrixWithIndexM_ |
368 | :: (Element a, Num a, | 367 | :: (Element a, Num a, |
369 | Functor f, Monad f) => | 368 | Functor f, Monad f) => |
370 | ((a, a) -> a -> f ()) -> Matrix a -> f () | 369 | ((Int, Int) -> a -> f ()) -> Matrix a -> f () |
371 | mapMatrixWithIndexM_ g m = mapVectorWithIndexM_ (mk c g) . flatten $ m | 370 | mapMatrixWithIndexM_ g m = mapVectorWithIndexM_ (mk c g) . flatten $ m |
372 | where | 371 | where |
373 | c = cols m | 372 | c = cols m |
374 | 373 | ||
@@ -381,11 +380,11 @@ Just (3><3) | |||
381 | , 20.0, 21.0, 122.0 ]@ | 380 | , 20.0, 21.0, 122.0 ]@ |
382 | -} | 381 | -} |
383 | mapMatrixWithIndexM | 382 | mapMatrixWithIndexM |
384 | :: (Foreign.Storable.Storable t, | 383 | :: (Foreign.Storable.Storable t, |
385 | Element a, Num a, | 384 | Element a, Num a, |
386 | Functor f, Monad f) => | 385 | Functor f, Monad f) => |
387 | ((a, a) -> a -> f t) -> Matrix a -> f (Matrix t) | 386 | ((Int, Int) -> a -> f t) -> Matrix a -> f (Matrix t) |
388 | mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flatten $ m | 387 | mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flatten $ m |
389 | where | 388 | where |
390 | c = cols m | 389 | c = cols m |
391 | 390 | ||
@@ -396,11 +395,12 @@ mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flat | |||
396 | , 10.0, 111.0, 12.0 | 395 | , 10.0, 111.0, 12.0 |
397 | , 20.0, 21.0, 122.0 ]@ | 396 | , 20.0, 21.0, 122.0 ]@ |
398 | -} | 397 | -} |
399 | mapMatrixWithIndex :: (Foreign.Storable.Storable t, | 398 | mapMatrixWithIndex :: (Foreign.Storable.Storable t, |
400 | Element a, Num a) => | 399 | Element a, Num a) => |
401 | ((a, a) -> a -> t) -> Matrix a -> Matrix t | 400 | ((Int, Int) -> a -> t) -> Matrix a -> Matrix t |
402 | mapMatrixWithIndex g = head . mapMatrixWithIndexM (\a b -> [g a b]) | 401 | mapMatrixWithIndex g m = reshape c $ mapVectorWithIndex (mk c g) $ flatten m |
402 | where | ||
403 | c = cols m | ||
403 | 404 | ||
404 | mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b | 405 | mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b |
405 | mapMatrix f = liftMatrix (mapVector f) | 406 | mapMatrix f = liftMatrix (mapVector f) |
406 | |||