summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-06-11 13:51:52 +0200
committerAlberto Ruiz <aruiz@um.es>2014-06-11 13:51:52 +0200
commit641ee77e6d41cc7f6b1f883b4834164a93bbb306 (patch)
treee1c6ce1854bf5ac8c9c138ccb3d9783e24298f46 /packages/base/src/Data/Packed/Matrix.hs
parent084e87f7279463b0171505cb8ec25f977ffcfe85 (diff)
admit empty cols in toBlocks
Diffstat (limited to 'packages/base/src/Data/Packed/Matrix.hs')
-rw-r--r--packages/base/src/Data/Packed/Matrix.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/packages/base/src/Data/Packed/Matrix.hs b/packages/base/src/Data/Packed/Matrix.hs
index 2acb31a..2420c94 100644
--- a/packages/base/src/Data/Packed/Matrix.hs
+++ b/packages/base/src/Data/Packed/Matrix.hs
@@ -402,9 +402,14 @@ compat' m1 m2 = s1 == (1,1) || s2 == (1,1) || s1 == s2
402 402
403------------------------------------------------------------ 403------------------------------------------------------------
404 404
405toBlockRows [r] m | r == rows m = [m] 405toBlockRows [r] m
406toBlockRows rs m = map (reshape (cols m)) (takesV szs (flatten m)) 406 | r == rows m = [m]
407 where szs = map (* cols m) rs 407toBlockRows rs m
408 | cols m > 0 = map (reshape (cols m)) (takesV szs (flatten m))
409 | otherwise = map g rs
410 where
411 szs = map (* cols m) rs
412 g k = (k><0)[]
408 413
409toBlockCols [c] m | c == cols m = [m] 414toBlockCols [c] m | c == cols m = [m]
410toBlockCols cs m = map trans . toBlockRows cs . trans $ m 415toBlockCols cs m = map trans . toBlockRows cs . trans $ m
@@ -412,7 +417,12 @@ toBlockCols cs m = map trans . toBlockRows cs . trans $ m
412-- | Partition a matrix into blocks with the given numbers of rows and columns. 417-- | Partition a matrix into blocks with the given numbers of rows and columns.
413-- The remaining rows and columns are discarded. 418-- The remaining rows and columns are discarded.
414toBlocks :: (Element t) => [Int] -> [Int] -> Matrix t -> [[Matrix t]] 419toBlocks :: (Element t) => [Int] -> [Int] -> Matrix t -> [[Matrix t]]
415toBlocks rs cs m = map (toBlockCols cs) . toBlockRows rs $ m 420toBlocks rs cs m
421 | ok = map (toBlockCols cs) . toBlockRows rs $ m
422 | otherwise = error $ "toBlocks: bad partition: "++show rs++" "++show cs
423 ++ " "++shSize m
424 where
425 ok = sum rs <= rows m && sum cs <= cols m && all (>=0) rs && all (>=0) cs
416 426
417-- | Fully partition a matrix into blocks of the same size. If the dimensions are not 427-- | Fully partition a matrix into blocks of the same size. If the dimensions are not
418-- a multiple of the given size the last blocks will be smaller. 428-- a multiple of the given size the last blocks will be smaller.