Hoogle Search
Within LTS Haskell 24.58 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
Matrix datatype and operations. Every provided example has been tested. Run cabal test for further tests.
-
matrix Data.Matrix Type of matrices. Elements can be of any type. Rows and columns are indexed starting by 1. This means that, if m :: Matrix a and i,j :: Int, then m ! (i,j) is the element in the i-th row and j-th column of m.
forceMatrix :: Matrix a -> Matrix amatrix Data.Matrix O(rows*cols). Similar to force. It copies the matrix content dropping any extra memory. Useful when using submatrix from a big matrix.
getMatrixAsVector :: Matrix a -> Vector amatrix Data.Matrix O(rows*cols). Transform a Matrix to a Vector of size rows*cols. This is equivalent to get all the rows of the matrix using getRow and then append them, but far more efficient.
matrix :: Int -> Int -> ((Int, Int) -> a) -> Matrix amatrix Data.Matrix O(rows*cols). Generate a matrix from a generator function. Example of usage:
( 1 0 -1 -2 ) ( 3 2 1 0 ) ( 5 4 3 2 ) matrix 4 4 $ \(i,j) -> 2*i - j = ( 7 6 5 4 )
minorMatrix :: Int -> Int -> Matrix a -> Matrix amatrix Data.Matrix O(rows*cols). Remove a row and a column from a matrix. Example:
( 1 2 3 ) ( 4 5 6 ) ( 1 3 ) minorMatrix 2 2 ( 7 8 9 ) = ( 7 9 )
multStrassenMixed :: Num a => Matrix a -> Matrix a -> Matrix amatrix Data.Matrix Mixed Strassen's matrix multiplication.
permMatrix :: Num a => Int -> Int -> Int -> Matrix amatrix Data.Matrix O(rows*cols). Permutation matrix.
permMatrix n i j = i j n 1 ( 1 0 ... 0 ... 0 ... 0 0 ) 2 ( 0 1 ... 0 ... 0 ... 0 0 ) ( ... ... ... ) i ( 0 0 ... 0 ... 1 ... 0 0 ) ( ... ... ... ) j ( 0 0 ... 1 ... 0 ... 0 0 ) ( ... ... ... ) ( 0 0 ... 0 ... 0 ... 1 0 ) n ( 0 0 ... 0 ... 0 ... 0 1 )
When i == j it reduces to identity n.prettyMatrix :: Show a => Matrix a -> Stringmatrix Data.Matrix Display a matrix as a String using the Show instance of its elements.
scaleMatrix :: Num a => a -> Matrix a -> Matrix amatrix Data.Matrix Scale a matrix by a given factor. Example:
( 1 2 3 ) ( 2 4 6 ) ( 4 5 6 ) ( 8 10 12 ) scaleMatrix 2 ( 7 8 9 ) = ( 14 16 18 )