| Safe Haskell | None |
|---|
Data.Matrix
Contents
Description
Matrix datatype an basic operations.
- data Matrix a
- prettyMatrix :: Show a => Matrix a -> String
- nrows :: Matrix a -> Int
- ncols :: Matrix a -> Int
- zero :: Num a => Int -> Int -> Matrix a
- identity :: Num a => Int -> Matrix a
- matrix :: Int -> Int -> ((Int, Int) -> a) -> Matrix a
- getElem :: Int -> Int -> Matrix a -> a
- (!) :: Matrix a -> (Int, Int) -> a
- transpose :: Matrix a -> Matrix a
- extendTo :: Num a => Int -> Int -> Matrix a -> Matrix a
- submatrix :: Int -> Int -> Int -> Int -> Matrix a -> Matrix a
- splitBlocks :: Int -> Int -> Matrix a -> (Matrix a, Matrix a, Matrix a, Matrix a)
- (<|>) :: Matrix a -> Matrix a -> Matrix a
- (<->) :: Matrix a -> Matrix a -> Matrix a
- joinBlocks :: (Matrix a, Matrix a, Matrix a, Matrix a) -> Matrix a
Matrix type
Builders
Generate a matrix from a generator function.
Accessing
Manipulating matrices
Arguments
| :: Num a | |
| => Int | Minimal number of rows. |
| -> Int | Minimal number of columns. |
| -> Matrix a | |
| -> Matrix a |
Extend a matrix to a given size adding zeroes. If the matrix already has the required size, nothing happens.
Working with blocks
Splitting blocks
Arguments
| :: Int | Starting row |
| -> Int | Ending row |
| -> Int | Starting column |
| -> Int | Ending column |
| -> Matrix a | |
| -> Matrix a |
Extract a submatrix.
Arguments
| :: Int | Row of the splitting element. |
| -> Int | Column of the splitting element. |
| -> Matrix a | Matrix to split. |
| -> (Matrix a, Matrix a, Matrix a, Matrix a) | (TL,TR,BL,BR) |
Make a block-partition of a matrix using a given element as reference. The element will stay in the bottom-right corner of the top-left corner matrix.
( ) ( | )
( ) ( ... | ... )
( x ) ( x | )
splitBlocks i j ( ) = (-------------) , where x = a_{i,j}
( ) ( | )
( ) ( ... | ... )
( ) ( | )
Note that some blocks can end up empty. We use the following notation for these blocks:
( TL | TR ) (---------) ( BL | BR )
Where T = Top, B = Bottom, L = Left, R = Right.
Implementation is done via slicing of vectors.
Joining blocks
(<|>) :: Matrix a -> Matrix a -> Matrix aSource
Horizontally join two matrices. Visually:
( A ) <|> ( B ) = ( A | B )
Where both matrices A and B have the same number of rows.
(<->) :: Matrix a -> Matrix a -> Matrix aSource
Vertically join two matrices. Visually:
( A )
( A ) <-> ( B ) = ( - )
( B )
Where both matrices A and B have the same number of columns.
joinBlocks :: (Matrix a, Matrix a, Matrix a, Matrix a) -> Matrix aSource
Join blocks of the form detailed in splitBlocks.