diff options
author | Alberto Ruiz <aruiz@um.es> | 2013-05-21 13:47:32 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2013-05-21 13:47:32 +0200 |
commit | 7f4bd8eb407a61032677e3f8055703519226084f (patch) | |
tree | 9aba8b3f99e9f8475786c22c57b77fde822bd257 /lib/Data/Packed | |
parent | 2cd153900a470f174fc65f597f9c8a40d0700ab9 (diff) |
diagBlock
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 16 |
1 files changed, 14 insertions, 2 deletions
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 ( | |||
30 | (@@>), | 30 | (@@>), |
31 | asRow, asColumn, | 31 | asRow, asColumn, |
32 | fromRows, toRows, fromColumns, toColumns, | 32 | fromRows, toRows, fromColumns, toColumns, |
33 | fromBlocks, toBlocks, toBlocksEvery, | 33 | fromBlocks, diagBlock, toBlocks, toBlocksEvery, |
34 | repmat, | 34 | repmat, |
35 | flipud, fliprl, | 35 | flipud, fliprl, |
36 | subMatrix, takeRows, dropRows, takeColumns, dropColumns, | 36 | subMatrix, takeRows, dropRows, takeColumns, dropColumns, |
@@ -156,7 +156,19 @@ adaptBlocks ms = ms' where | |||
156 | x = m@@>(0,0) | 156 | x = m@@>(0,0) |
157 | g _ _ = error "inconsistent dimensions in fromBlocks" | 157 | g _ _ = error "inconsistent dimensions in fromBlocks" |
158 | 158 | ||
159 | ----------------------------------------------------------- | 159 | |
160 | -------------------------------------------------------------------------------- | ||
161 | |||
162 | -- | create a block diagonal matrix | ||
163 | diagBlock :: (Element t, Num t) => [Matrix t] -> Matrix t | ||
164 | diagBlock ms = fromBlocks $ zipWith f ms [0..] | ||
165 | where | ||
166 | f m k = take n $ replicate k z ++ m : repeat z | ||
167 | n = length ms | ||
168 | z = (1><1) [0] | ||
169 | |||
170 | -------------------------------------------------------------------------------- | ||
171 | |||
160 | 172 | ||
161 | -- | Reverse rows | 173 | -- | Reverse rows |
162 | flipud :: Element t => Matrix t -> Matrix t | 174 | flipud :: Element t => Matrix t -> Matrix t |