eigen-1.1.3: Eigen C++ library (linear algebra: matrices, vectors, numerical solvers).

Data.Eigen.Matrix

Synopsis

Matrix type

data Matrix Source

constant Matrix class to be used in pure computations, uses the same column major memory layout as Eigen MatrixXd

Constructors

 Matrix Fieldsm_rows :: Int m_cols :: Int m_vals :: Vector CDouble

Instances

 Num Matrix only the following functions are defined for Num instance: (*), (+), (-) Show Matrix pretty prints the matrix

Matrix conversions

fromList :: [[Double]] -> Matrix Source

construct matrix from a list of rows, column count is detected as maximum row length

toList :: Matrix -> [[Double]] Source

converts matrix to a list of its rows

generate :: Int -> Int -> (Int -> Int -> Double) -> Matrix Source

craete matrix using generator function f :: row -> col -> val

Standard matrices and special cases

empty 0x0 matrix

zero :: Int -> Int -> Matrix Source

matrix where all coeff are 0

ones :: Int -> Int -> Matrix Source

matrix where all coeff are 1

square matrix with 1 on main diagonal and 0 elsewhere

constant :: Int -> Int -> Double -> Matrix Source

matrix where all coeffs are filled with given value

Accessing matrix data

number of columns for the matrix

number of rows for the matrix

coeff :: Int -> Int -> Matrix -> Double Source

matrix coefficient at specific row and col

the minimum of all coefficients of matrix

the maximum of all coefficients of matrix

col :: Int -> Matrix -> [Double] Source

list of coefficients for the given col

row :: Int -> Matrix -> [Double] Source

list of coefficients for the given row

block :: Int -> Int -> Int -> Int -> Matrix -> Matrix Source

extract rectangular block from matrix defined by startRow startCol blockRows blockCols

top n rows of matrix

bottom n rows of matrix

left n columns of matrix

right n columns of matrix

Matrix properties

for vectors, the l2 norm, and for matrices the Frobenius norm. In both cases, it consists in the square root of the sum of the square of all the matrix entries. For vectors, this is also equals to the square root of the dot product of this with itself.

for vectors, the squared l2 norm, and for matrices the Frobenius norm. In both cases, it consists in the sum of the square of all the matrix entries. For vectors, this is also equals to the dot product of this with itself.

the determinant of the matrix

return a - b

return a + b

return a * b

Matrix transformations

inverse of the matrix

For small fixed sizes up to 4x4, this method uses cofactors. In the general case, this method uses class PartialPivLU

conjugate of the matrix

transpose of the matrix

nomalize the matrix by deviding it on its norm

modify :: (forall s. MMatrix s -> ST s ()) -> Matrix -> Matrix Source

Apply a destructive operation to a matrix. The operation will be performed in place if it is safe to do so and will modify a copy of the matrix otherwise.

Mutable matrices

thaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m)) Source

Yield a mutable copy of the immutable matrix

freeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix Source

Yield an immutable copy of the mutable matrix

unsafeThaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m)) Source

Unsafely convert an immutable matrix to a mutable one without copying. The immutable matrix may not be used after this operation.

unsafeFreeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix Source

Unsafe convert a mutable matrix to an immutable one without copying. The mutable matrix may not be used after this operation.