matrix-0.1: A native implementation of matrix operations.

Safe HaskellNone

Data.Matrix

Contents

Description

Matrix datatype an basic operations.

Synopsis

Matrix type

data Matrix a Source

Instances

Functor Matrix 
Eq a => Eq (Matrix a) 
Num a => Num (Matrix a) 
Show a => Show (Matrix a) 
NFData a => NFData (Matrix a) 

prettyMatrix :: Show a => Matrix a -> StringSource

Display a matrix as a String.

nrows :: Matrix a -> IntSource

Number of rows.

ncols :: Matrix a -> IntSource

Number of columns.

Builders

zeroSource

Arguments

:: Num a 
=> Int

Rows

-> Int

Columns

-> Matrix a 

The zero matrix of the given size.

identity :: Num a => Int -> Matrix aSource

Identity matrix of the given order.

matrixSource

Arguments

:: Int

Rows

-> Int

Columns

-> ((Int, Int) -> a)

Generator function

-> Matrix a 

Generate a matrix from a generator function.

Accessing

getElemSource

Arguments

:: Int

Row

-> Int

Column

-> Matrix a

Matrix

-> a 

Get an element of a matrix.

(!) :: Matrix a -> (Int, Int) -> aSource

Nice alias for getElem.

Manipulating matrices

transpose :: Matrix a -> Matrix aSource

The transpose of a matrix.

extendToSource

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

submatrixSource

Arguments

:: Int

Starting row

-> Int

Ending row

-> Int

Starting column

-> Int

Ending column

-> Matrix a 
-> Matrix a 

Extract a submatrix.

splitBlocksSource

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.