Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Matrix = Matrix {}
- valid :: Matrix -> Bool
- fromList :: [[Double]] -> Matrix
- toList :: Matrix -> [[Double]]
- generate :: Int -> Int -> (Int -> Int -> Double) -> Matrix
- empty :: Matrix
- null :: Matrix -> Bool
- square :: Matrix -> Bool
- zero :: Int -> Int -> Matrix
- ones :: Int -> Int -> Matrix
- identity :: Int -> Matrix
- constant :: Int -> Int -> Double -> Matrix
- cols :: Matrix -> Int
- rows :: Matrix -> Int
- (!) :: Matrix -> (Int, Int) -> Double
- coeff :: Int -> Int -> Matrix -> Double
- unsafeCoeff :: Int -> Int -> Matrix -> Double
- minCoeff :: Matrix -> Double
- maxCoeff :: Matrix -> Double
- col :: Int -> Matrix -> [Double]
- row :: Int -> Matrix -> [Double]
- block :: Int -> Int -> Int -> Int -> Matrix -> Matrix
- topRows :: Int -> Matrix -> Matrix
- bottomRows :: Int -> Matrix -> Matrix
- leftCols :: Int -> Matrix -> Matrix
- rightCols :: Int -> Matrix -> Matrix
- norm :: Matrix -> Double
- squaredNorm :: Matrix -> Double
- determinant :: Matrix -> Double
- add :: Matrix -> Matrix -> Matrix
- sub :: Matrix -> Matrix -> Matrix
- mul :: Matrix -> Matrix -> Matrix
- inverse :: Matrix -> Matrix
- adjoint :: Matrix -> Matrix
- conjugate :: Matrix -> Matrix
- transpose :: Matrix -> Matrix
- normalize :: Matrix -> Matrix
- modify :: (forall s. MMatrix s -> ST s ()) -> Matrix -> Matrix
- thaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m))
- freeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix
- unsafeThaw :: PrimMonad m => Matrix -> m (MMatrix (PrimState m))
- unsafeFreeze :: PrimMonad m => MMatrix (PrimState m) -> m Matrix
- unsafeWith :: Matrix -> (CInt -> CInt -> Ptr CDouble -> IO a) -> IO a
Matrix type
Matrix class to be used in pure computations, uses column major memory layout
Matrix conversions
fromList :: [[Double]] -> Matrix Source
Construct matrix from a list of rows, column count is detected as maximum row length. Missing values are filled with 0
generate :: Int -> Int -> (Int -> Int -> Double) -> Matrix Source
Create matrix using generator function f :: row -> col -> val
Standard matrices and special cases
constant :: Int -> Int -> Double -> Matrix Source
Matrix where all coeffs are filled with given value
Accessing matrix data
unsafeCoeff :: Int -> Int -> Matrix -> Double Source
Unsafe version of coeff function. No bounds check performed so SEGFAULT possible
block :: Int -> Int -> Int -> Int -> Matrix -> Matrix Source
Extract rectangular block from matrix defined by startRow startCol blockRows blockCols
bottomRows :: Int -> Matrix -> Matrix Source
Bottom n rows of matrix
Matrix properties
norm :: Matrix -> Double Source
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.
squaredNorm :: Matrix -> Double Source
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.
determinant :: Matrix -> Double Source
The determinant of the matrix
Matrix operations
add :: Matrix -> Matrix -> Matrix Source
Adding two matrices by adding the corresponding entries together
Matrix transformations
inverse :: Matrix -> Matrix Source
Inverse of the matrix
For small fixed sizes up to 4x4, this method uses cofactors. In the general case, this method uses class PartialPivLU
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.