From 7f4bd8eb407a61032677e3f8055703519226084f Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Tue, 21 May 2013 13:47:32 +0200 Subject: diagBlock --- lib/Data/Packed/Matrix.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index fe8c159..1b67820 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs @@ -30,7 +30,7 @@ module Data.Packed.Matrix ( (@@>), asRow, asColumn, fromRows, toRows, fromColumns, toColumns, - fromBlocks, toBlocks, toBlocksEvery, + fromBlocks, diagBlock, toBlocks, toBlocksEvery, repmat, flipud, fliprl, subMatrix, takeRows, dropRows, takeColumns, dropColumns, @@ -156,7 +156,19 @@ adaptBlocks ms = ms' where x = m@@>(0,0) g _ _ = error "inconsistent dimensions in fromBlocks" ------------------------------------------------------------ + +-------------------------------------------------------------------------------- + +-- | create a block diagonal matrix +diagBlock :: (Element t, Num t) => [Matrix t] -> Matrix t +diagBlock ms = fromBlocks $ zipWith f ms [0..] + where + f m k = take n $ replicate k z ++ m : repeat z + n = length ms + z = (1><1) [0] + +-------------------------------------------------------------------------------- + -- | Reverse rows flipud :: Element t => Matrix t -> Matrix t -- cgit v1.2.3