summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2013-05-21 13:30:45 +0200
committerAlberto Ruiz <aruiz@um.es>2013-05-21 13:30:45 +0200
commitc5606c622cebf265ae0bb3ea32a9f2ebf2f3a79f (patch)
tree7b3b202eb267e84f7815bf8b3cc1dbae51228476 /lib/Data/Packed/Matrix.hs
parent6b2f191ea8d6665996070bf6b3e5b4109584dcab (diff)
merge develop, fix conflicts
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index c1a9b24..fe8c159 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -46,6 +46,7 @@ import Data.Array
46 46
47import Data.List(transpose,intersperse) 47import Data.List(transpose,intersperse)
48import Foreign.Storable(Storable) 48import Foreign.Storable(Storable)
49import Control.Monad(liftM)
49 50
50------------------------------------------------------------------- 51-------------------------------------------------------------------
51 52
@@ -351,7 +352,11 @@ toBlocksEvery r c m = toBlocks rs cs m where
351 352
352------------------------------------------------------------------- 353-------------------------------------------------------------------
353 354
354mk c g = \k v -> g (divMod k c) v 355-- Given a column number and a function taking matrix indexes, returns
356-- a function which takes vector indexes (that can be used on the
357-- flattened matrix).
358mk :: Int -> ((Int, Int) -> t) -> (Int -> t)
359mk c g = \k -> g (divMod k c)
355 360
356{- | 361{- |
357 362
@@ -364,9 +369,8 @@ m[1,1] = 5
364m[1,2] = 6@ 369m[1,2] = 6@
365-} 370-}
366mapMatrixWithIndexM_ 371mapMatrixWithIndexM_
367 :: (Element a, Num a, 372 :: (Element a, Num a, Monad m) =>
368 Functor f, Monad f) => 373 ((Int, Int) -> a -> m ()) -> Matrix a -> m ()
369 ((Int, Int) -> a -> f ()) -> Matrix a -> f ()
370mapMatrixWithIndexM_ g m = mapVectorWithIndexM_ (mk c g) . flatten $ m 374mapMatrixWithIndexM_ g m = mapVectorWithIndexM_ (mk c g) . flatten $ m
371 where 375 where
372 c = cols m 376 c = cols m
@@ -380,11 +384,9 @@ Just (3><3)
380 , 20.0, 21.0, 122.0 ]@ 384 , 20.0, 21.0, 122.0 ]@
381-} 385-}
382mapMatrixWithIndexM 386mapMatrixWithIndexM
383 :: (Foreign.Storable.Storable t, 387 :: (Element a, Storable b, Monad m) =>
384 Element a, Num a, 388 ((Int, Int) -> a -> m b) -> Matrix a -> m (Matrix b)
385 Functor f, Monad f) => 389mapMatrixWithIndexM g m = liftM (reshape c) . mapVectorWithIndexM (mk c g) . flatten $ m
386 ((Int, Int) -> a -> f t) -> Matrix a -> f (Matrix t)
387mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flatten $ m
388 where 390 where
389 c = cols m 391 c = cols m
390 392
@@ -395,10 +397,10 @@ mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flat
395 , 10.0, 111.0, 12.0 397 , 10.0, 111.0, 12.0
396 , 20.0, 21.0, 122.0 ]@ 398 , 20.0, 21.0, 122.0 ]@
397 -} 399 -}
398mapMatrixWithIndex :: (Foreign.Storable.Storable t, 400mapMatrixWithIndex
399 Element a, Num a) => 401 :: (Element a, Storable b) =>
400 ((Int, Int) -> a -> t) -> Matrix a -> Matrix t 402 ((Int, Int) -> a -> b) -> Matrix a -> Matrix b
401mapMatrixWithIndex g m = reshape c $ mapVectorWithIndex (mk c g) $ flatten m 403mapMatrixWithIndex g m = reshape c . mapVectorWithIndex (mk c g) . flatten $ m
402 where 404 where
403 c = cols m 405 c = cols m
404 406