diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2013-03-17 23:11:08 -0400 |
---|---|---|
committer | Ben Gamari <bgamari.foss@gmail.com> | 2013-03-17 23:11:08 -0400 |
commit | a1b41bc023c0ac44b130c6092e886525d6411b86 (patch) | |
tree | ae84b364c6d0cd6fc4ec68e564c37f5baec4b453 /lib/Data | |
parent | 1c920c8bed07646272d859c8d5ad1a77cbf98cd9 (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')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 7 |
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 | -} |
398 | mapMatrixWithIndex :: (Foreign.Storable.Storable t, | 398 | mapMatrixWithIndex :: (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 |
401 | 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 | ||
402 | 404 | ||
403 | mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b | 405 | mapMatrix :: (Storable a, Storable b) => (a -> b) -> Matrix a -> Matrix b |
404 | mapMatrix f = liftMatrix (mapVector f) | 406 | mapMatrix f = liftMatrix (mapVector f) |
405 | |||