summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2013-03-17 23:11:08 -0400
committerBen Gamari <bgamari.foss@gmail.com>2013-03-17 23:11:08 -0400
commita1b41bc023c0ac44b130c6092e886525d6411b86 (patch)
treeae84b364c6d0cd6fc4ec68e564c37f5baec4b453 /lib/Data/Packed/Matrix.hs
parent1c920c8bed07646272d859c8d5ad1a77cbf98cd9 (diff)
Matrix: Implement mapMatrixWithIndex independently
Previously this was piggybacking off of mapMatrixWithIndexM which would overflow the stack with large input
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 48b2279..68971ff 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -395,11 +395,12 @@ mapMatrixWithIndexM g m = fmap (reshape c) . mapVectorWithIndexM (mk c g) . flat
395 , 10.0, 111.0, 12.0 395 , 10.0, 111.0, 12.0
396 , 20.0, 21.0, 122.0 ]@ 396 , 20.0, 21.0, 122.0 ]@
397 -} 397 -}
398mapMatrixWithIndex :: (Foreign.Storable.Storable t, 398mapMatrixWithIndex :: (Foreign.Storable.Storable t,
399 Element a, Num a) => 399 Element a, Num a) =>
400 ((Int, Int) -> a -> t) -> Matrix a -> Matrix t 400 ((Int, Int) -> a -> t) -> Matrix a -> Matrix t
401mapMatrixWithIndex g = head . mapMatrixWithIndexM (\a b -> [g a b]) 401mapMatrixWithIndex g m = reshape c $ mapVectorWithIndex (mk c g) $ flatten m
402 where
403 c = cols m
402 404
403mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b 405mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b
404mapMatrix f = liftMatrix (mapVector f) 406mapMatrix f = liftMatrix (mapVector f)
405