|
Data.Packed.Matrix | Portability | portable | Stability | provisional | Maintainer | Alberto Ruiz <aruiz@um.es> |
|
|
|
Description |
A Matrix representation suitable for numerical computations using LAPACK and GSL.
|
|
Synopsis |
|
class (Storable a, Floating a) => Element a | | data Matrix t | | rows :: Matrix t -> Int | | cols :: Matrix t -> Int | | (><) :: Element a => Int -> Int -> [a] -> Matrix a | | trans :: Matrix t -> Matrix t | | reshape :: Element t => Int -> Vector t -> Matrix t | | flatten :: Element t => Matrix t -> Vector t | | fromLists :: Element t => [[t]] -> Matrix t | | toLists :: Element t => Matrix t -> [[t]] | | (@@>) :: Storable t => Matrix t -> (Int, Int) -> t | | asRow :: Element a => Vector a -> Matrix a | | asColumn :: Element a => Vector a -> Matrix a | | fromRows :: Element t => [Vector t] -> Matrix t | | toRows :: Element t => Matrix t -> [Vector t] | | fromColumns :: Element t => [Vector t] -> Matrix t | | toColumns :: Element t => Matrix t -> [Vector t] | | fromBlocks :: Element t => [[Matrix t]] -> Matrix t | | repmat :: Element t => Matrix t -> Int -> Int -> Matrix t | | flipud :: Element t => Matrix t -> Matrix t | | fliprl :: Element t => Matrix t -> Matrix t | | subMatrix :: Element a => (Int, Int) -> (Int, Int) -> Matrix a -> Matrix a | | takeRows :: Element t => Int -> Matrix t -> Matrix t | | dropRows :: Element t => Int -> Matrix t -> Matrix t | | takeColumns :: Element t => Int -> Matrix t -> Matrix t | | dropColumns :: Element t => Int -> Matrix t -> Matrix t | | extractRows :: Element t => [Int] -> Matrix t -> Matrix t | | ident :: Element a => Int -> Matrix a | | diag :: Element a => Vector a -> Matrix a | | diagRect :: (Element t, Num t) => Vector t -> Int -> Int -> Matrix t | | takeDiag :: Element t => Matrix t -> Vector t | | liftMatrix :: (Element a, Element b) => (Vector a -> Vector b) -> Matrix a -> Matrix b | | liftMatrix2 :: (Element t, Element a, Element b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t | | format :: Element t => String -> (t -> String) -> Matrix t -> String | | loadMatrix :: FilePath -> IO (Matrix Double) | | saveMatrix :: FilePath -> String -> Matrix Double -> IO () | | fromFile :: FilePath -> (Int, Int) -> IO (Matrix Double) | | fileDimensions :: FilePath -> IO (Int, Int) | | readMatrix :: String -> Matrix Double | | fromArray2D :: Element e => Array (Int, Int) e -> Matrix e |
|
|
Documentation |
|
|
Auxiliary class.
| | Instances | |
|
|
|
Matrix representation suitable for GSL and LAPACK computations.
| Instances | Container Matrix Double | (Linear Vector a, Container Matrix a) => Linear Matrix a | Joinable Vector Matrix | Joinable Matrix Vector | Joinable Matrix Matrix | Mul Vector Matrix Vector | Mul Matrix Vector Vector | Mul Matrix Matrix Matrix | Container Matrix (Complex Double) | (Eq a, Element a) => Eq (Matrix a) | (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floating (Matrix a) | (Linear Vector a, Fractional (Vector a), Num (Matrix a)) => Fractional (Matrix a) | (Linear Matrix a, Num (Vector a)) => Num (Matrix a) | (Element a, Read a) => Read (Matrix a) | (Show a, Element a) => Show (Matrix a) | (Element a, Arbitrary a) => Arbitrary (Matrix a) | Normed (Matrix Double) | Normed (Matrix (Complex Double)) |
|
|
|
|
|
|
|
|
An easy way to create a matrix:
> (2><3)[1..6]
(2><3)
[ 1.0, 2.0, 3.0
, 4.0, 5.0, 6.0 ] This is the format produced by the instances of Show (Matrix a), which
can also be used for input.
The input list is explicitly truncated, so that it can
safely be used with lists that are too long (like infinite lists).
Example:
> (2>|<3)[1..]
(2><3)
[ 1.0, 2.0, 3.0
, 4.0, 5.0, 6.0 ] |
|
|
Matrix transpose.
|
|
|
Creates a matrix from a vector by grouping the elements in rows with the desired number of columns. (GNU-Octave groups by columns. To do it you can define reshapeF r = trans . reshape r
where r is the desired number of rows.)
> reshape 4 (fromList [1..12])
(3><4)
[ 1.0, 2.0, 3.0, 4.0
, 5.0, 6.0, 7.0, 8.0
, 9.0, 10.0, 11.0, 12.0 ] |
|
|
Creates a vector by concatenation of rows
> flatten (ident 3)
9 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0] |
|
|
Creates a Matrix from a list of lists (considered as rows).
> fromLists [[1,2],[3,4],[5,6]]
(3><2)
[ 1.0, 2.0
, 3.0, 4.0
, 5.0, 6.0 ] |
|
|
the inverse of Data.Packed.Matrix.fromLists
|
|
|
Reads a matrix position.
|
|
|
creates a 1-row matrix from a vector
|
|
|
creates a 1-column matrix from a vector
|
|
|
creates a Matrix from a list of vectors
|
|
|
extracts the rows of a matrix as a list of vectors
|
|
|
Creates a matrix from a list of vectors, as columns
|
|
|
Creates a list of vectors from the columns of a matrix
|
|
|
Creates a matrix from blocks given as a list of lists of matrices:
> let a = diag $ fromList [5,7,2]
> let b = reshape 4 $ constant (-1) 12
> fromBlocks [[a,b],[b,a]]
(6><7)
[ 5.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0
, 0.0, 7.0, 0.0, -1.0, -1.0, -1.0, -1.0
, 0.0, 0.0, 2.0, -1.0, -1.0, -1.0, -1.0
, -1.0, -1.0, -1.0, -1.0, 5.0, 0.0, 0.0
, -1.0, -1.0, -1.0, -1.0, 0.0, 7.0, 0.0
, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 2.0 ] |
|
|
creates matrix by repetition of a matrix a given number of rows and columns
> repmat (ident 2) 2 3 :: Matrix Double
(4><6)
[ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0
, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] |
|
|
Reverse rows
|
|
|
Reverse columns
|
|
|
|
|
|
Creates a matrix with the first n rows of another matrix
|
|
|
Creates a copy of a matrix without the first n rows
|
|
|
Creates a matrix with the first n columns of another matrix
|
|
|
Creates a copy of a matrix without the first n columns
|
|
|
rearranges the rows of a matrix according to the order given in a list of integers.
|
|
|
creates the identity matrix of given dimension
|
|
|
Creates a square matrix with a given diagonal.
|
|
|
creates a rectangular diagonal matrix
> diagRect (constant 5 3) 3 4 :: Matrix Double
(3><4)
[ 5.0, 0.0, 0.0, 0.0
, 0.0, 5.0, 0.0, 0.0
, 0.0, 0.0, 5.0, 0.0 ] |
|
|
extracts the diagonal from a rectangular matrix
|
|
|
application of a vector function on the flattened matrix elements
|
|
|
application of a vector function on the flattened matrices elements
|
|
|
Creates a string from a matrix given a separator and a function to show each entry. Using
this function the user can easily define any desired display function:
import Text.Printf(printf) disp = putStrLn . format " " (printf "%.2f") |
|
|
Loads a matrix from an ASCII file formatted as a 2D table.
|
|
|
|
|
|
Loads a matrix from an ASCII file (the number of rows and columns must be known in advance).
|
|
|
obtains the number of rows and columns in an ASCII data file
(provisionally using unix's wc).
|
|
|
reads a matrix from a string containing a table of numbers.
|
|
|
|
Produced by Haddock version 2.6.0 |