diff options
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Data/Packed/Matrix.hs | 18 |
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 | ||
405 | toBlockRows [r] m | r == rows m = [m] | 405 | toBlockRows [r] m |
406 | toBlockRows rs m = map (reshape (cols m)) (takesV szs (flatten m)) | 406 | | r == rows m = [m] |
407 | where szs = map (* cols m) rs | 407 | toBlockRows 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 | ||
409 | toBlockCols [c] m | c == cols m = [m] | 414 | toBlockCols [c] m | c == cols m = [m] |
410 | toBlockCols cs m = map trans . toBlockRows cs . trans $ m | 415 | toBlockCols 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. |
414 | toBlocks :: (Element t) => [Int] -> [Int] -> Matrix t -> [[Matrix t]] | 419 | toBlocks :: (Element t) => [Int] -> [Int] -> Matrix t -> [[Matrix t]] |
415 | toBlocks rs cs m = map (toBlockCols cs) . toBlockRows rs $ m | 420 | toBlocks 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. |