Copyright | (C) 2016 Marco Zocca |
---|---|
License | GPL-3 (see LICENSE) |
Maintainer | zocca.marco gmail |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.Sparse.SpMatrix
Contents
Description
- data SpMatrix a = SM {}
- sizeStr :: (FDSize f ~ (a1, a2), Sparse f a, Show a2, Show a1) => f a -> String
- zeroSM :: Rows -> Cols -> SpMatrix a
- mkDiagonal :: Int -> [a] -> SpMatrix a
- eye :: Num a => Int -> SpMatrix a
- permutationSM :: Num a => Int -> [IxRow] -> SpMatrix a
- permutPairsSM :: Num a => Int -> [(IxRow, IxRow)] -> SpMatrix a
- mkSubDiagonal :: Int -> Int -> [a] -> SpMatrix a
- insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a
- fromListSM' :: Foldable t => t (IxRow, IxCol, a) -> SpMatrix a -> SpMatrix a
- fromListSM :: Foldable t => (Int, Int) -> t (IxRow, IxCol, a) -> SpMatrix a
- mkSpMR :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Double) -> SpMatrix Double
- mkSpMC :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Complex Double) -> SpMatrix (Complex Double)
- fromListDenseSM :: Int -> [a] -> SpMatrix a
- toListSM :: SpMatrix t -> [(IxRow, IxCol, t)]
- toDenseListSM :: Num t => SpMatrix t -> [(IxRow, IxCol, t)]
- lookupSM :: SpMatrix a -> IxRow -> IxCol -> Maybe a
- lookupWD_SM :: Num a => SpMatrix a -> (IxRow, IxCol) -> a
- (@@!) :: Num a => SpMatrix a -> (IxRow, IxCol) -> a
- filterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a
- extractDiag :: SpMatrix a -> SpMatrix a
- extractSuperDiag :: SpMatrix a -> SpMatrix a
- extractSubDiag :: SpMatrix a -> SpMatrix a
- extractSubmatrixSM :: (Key -> Key) -> (Key -> Key) -> SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a
- extractSubmatrixRebalanceKeys :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a
- extractSubmatrix :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a
- takeRows :: IxRow -> SpMatrix a -> SpMatrix a
- takeCols :: IxCol -> SpMatrix a -> SpMatrix a
- extractColSM :: SpMatrix a -> IxCol -> SpMatrix a
- extractSubColSM :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a
- extractSubColSM_RK :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a
- isValidIxSM :: SpMatrix a -> (Int, Int) -> Bool
- isSquareSM :: SpMatrix a -> Bool
- isDiagonalSM :: SpMatrix a -> Bool
- isLowerTriSM :: Eq a => SpMatrix a -> Bool
- isUpperTriSM :: Eq a => SpMatrix a -> Bool
- isOrthogonalSM :: (Epsilon a, Eq a, MatrixRing (SpMatrix a)) => SpMatrix a -> Bool
- immSM :: SpMatrix t -> IntM (IntM t)
- dimSM :: SpMatrix t -> (Rows, Cols)
- nelSM :: SpMatrix t -> Int
- nrows :: SpMatrix a -> Rows
- ncols :: SpMatrix a -> Cols
- data SMInfo = SMInfo {}
- infoSM :: SpMatrix a -> SMInfo
- nzSM :: SpMatrix a -> Int
- spySM :: Fractional b => SpMatrix a -> b
- nzRow :: SpMatrix a -> Key -> Int
- bwMinSM :: SpMatrix a -> Int
- bwMaxSM :: SpMatrix a -> Int
- bwBoundsSM :: SpMatrix a -> (Int, Int)
- vertStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a
- (-=-) :: SpMatrix a -> SpMatrix a -> SpMatrix a
- horizStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a
- (-||-) :: SpMatrix a -> SpMatrix a -> SpMatrix a
- fromBlocksDiag :: [SpMatrix a] -> SpMatrix a
- ifilterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a
- foldlSM :: (a -> b -> b) -> b -> SpMatrix a -> b
- ifoldlSM :: (Key -> Key -> a -> b -> b) -> b -> SpMatrix a -> b
- countSubdiagonalNZSM :: SpMatrix a -> Int
- subdiagIndicesSM :: SpMatrix a -> [(IxRow, IxCol)]
- sparsifyIM2 :: Epsilon a => IntM (IntM a) -> IntM (IntM a)
- sparsifySM :: Epsilon a => SpMatrix a -> SpMatrix a
- roundZeroOneSM :: Epsilon a => SpMatrix a -> SpMatrix a
- modifyKeysSM' :: (IxRow -> a) -> (IxCol -> b) -> SpMatrix c -> [(a, b, c)]
- modifyKeysSM :: (IxRow -> IxRow) -> (IxCol -> IxCol) -> SpMatrix a -> SpMatrix a
- swapRows :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a
- swapRowsSafe :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a
- transposeSM :: SpMatrix a -> SpMatrix a
- hermitianConj :: Num a => SpMatrix (Complex a) -> SpMatrix (Complex a)
- matScale :: Num a => a -> SpMatrix a -> SpMatrix a
- trace :: Num b => SpMatrix b -> b
- normFrobeniusSM :: (MatrixRing (SpMatrix a), Floating a) => SpMatrix a -> a
- normFrobeniusSMC :: (MatrixRing (SpMatrix (Complex a)), RealFloat a) => SpMatrix (Complex a) -> a
- data MatProd_
- matMat_ :: Num a => MatProd_ -> SpMatrix a -> SpMatrix a -> SpMatrix a
- matMatUnsafeWith :: Num a => (IntM (IntM a1) -> IntM (IntM a)) -> SpMatrix a -> SpMatrix a1 -> SpMatrix a
- matMatSparsified :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a
- (#~#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a
- (#~#^) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a
- (#~^#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a
- contractSub :: Elt a => SpMatrix a -> SpMatrix a -> IxRow -> IxCol -> Int -> a
Sparse Matrix
Instances
Functor SpMatrix # | |
Foldable SpMatrix # | |
Set SpMatrix # | |
FiniteDim SpMatrix # |
|
Num a => SpContainer SpMatrix a # |
|
Sparse SpMatrix a # | |
HasData SpMatrix a # | |
Eq a => Eq (SpMatrix a) # | |
Show a => Show (SpMatrix a) # | |
Num a => AdditiveGroup (SpMatrix a) # |
|
MatrixRing (SpMatrix Double) # | |
MatrixRing (SpMatrix (Complex Double)) # | |
type ScIx SpMatrix # | |
type FDSize SpMatrix # | |
type HDData SpMatrix a # | |
type MatrixNorm (SpMatrix Double) # | |
type MatrixNorm (SpMatrix (Complex Double)) # | |
Creation
Diagonal matrix
mkDiagonal :: Int -> [a] -> SpMatrix a #
Identity matrix
Permutation matrix
permutationSM :: Num a => Int -> [IxRow] -> SpMatrix a #
Permutation matrix from a (possibly incomplete) list of row swaps starting from row 0 e.g. `permutationSM 5 [1,3]` first swaps rows (0, 1) and then rows (1, 3) :
- 0,1,0,0,0
- 0,0,0,1,0
- 0,0,1,0,0
- 1,0,0,0,0
- 0,0,0,0,1
permutPairsSM :: Num a => Int -> [(IxRow, IxRow)] -> SpMatrix a #
Permutation matrix from a (possibly incomplete) list of row pair swaps e.g. `permutPairs 5 [(2,4)]` swaps rows 2 and 4 :
- 1,0,0,0,0
- 0,1,0,0,0
- 0,0,0,0,1
- 0,0,0,1,0
- 0,0,1,0,0
Super- or sub- diagonal matrix
mkSubDiagonal :: Int -> Int -> [a] -> SpMatrix a #
`mkSubDiagonal n o xx` creates a square SpMatrix of size n
with xx
on the o
th subdiagonal
Element insertion
insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a #
Insert an element in a preexisting Spmatrix at the specified indices
fromList
fromListSM' :: Foldable t => t (IxRow, IxCol, a) -> SpMatrix a -> SpMatrix a #
Add to existing SpMatrix using data from list (row, col, value)
fromListSM :: Foldable t => (Int, Int) -> t (IxRow, IxCol, a) -> SpMatrix a #
Create new SpMatrix using data from a Foldable (e.g. a list) in (row, col, value) form
mkSpMC :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Complex Double) -> SpMatrix (Complex Double) #
fromListDenseSM :: Int -> [a] -> SpMatrix a #
Create new SpMatrix assuming contiguous, 0-based indexing of elements
toList
toDenseListSM :: Num t => SpMatrix t -> [(IxRow, IxCol, t)] #
Populate list with SpMatrix contents and populate missing entries with 0
Lookup
lookupWD_SM :: Num a => SpMatrix a -> (IxRow, IxCol) -> a #
Looks up an element in the matrix with a default (if the element is not found, zero is returned)
(@@!) :: Num a => SpMatrix a -> (IxRow, IxCol) -> a #
Zero-default lookup, infix form (no bound checking)
Looks up an element in the matrix with a default (if the element is not found, zero is returned)
Sub-matrices
extractDiag :: SpMatrix a -> SpMatrix a #
Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)
extractSuperDiag :: SpMatrix a -> SpMatrix a #
Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)
extractSubDiag :: SpMatrix a -> SpMatrix a #
Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)
extractSubmatrixSM :: (Key -> Key) -> (Key -> Key) -> SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a #
Extract a submatrix given the specified index bounds, rebalancing keys with the two supplied functions
extractSubmatrixRebalanceKeys :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a #
Extract a submatrix given the specified index bounds NB : subtracts (i1, j1) from the indices
extractSubmatrix :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a #
Extract a submatrix given the specified index bounds NB : submatrix indices are _preserved_
Extract i'th row
Extract j'th column
extractColSM :: SpMatrix a -> IxCol -> SpMatrix a #
Extract whole column
extractSubColSM :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a #
Extract column within a row range
extractSubColSM_RK :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a #
Extract column within a row range, rebalance keys
Predicates
isSquareSM :: SpMatrix a -> Bool #
Is the matrix square?
isDiagonalSM :: SpMatrix a -> Bool #
Is the matrix diagonal?
isLowerTriSM :: Eq a => SpMatrix a -> Bool #
Is the matrix lower/upper triangular?
isUpperTriSM :: Eq a => SpMatrix a -> Bool #
Is the matrix lower/upper triangular?
isOrthogonalSM :: (Epsilon a, Eq a, MatrixRing (SpMatrix a)) => SpMatrix a -> Bool #
Matrix data and metadata
immSM :: SpMatrix t -> IntM (IntM t) #
Data in internal representation (do not export) immSM :: SpMatrix t -> IM.IntMap (IM.IntMap t)
spySM :: Fractional b => SpMatrix a -> b #
Non-zero elements in a row
Bandwidth bounds (min, max)
bwBoundsSM :: SpMatrix a -> (Int, Int) #
Matrix stacking
vertStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a #
Vertical stacking
horizStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a #
Horizontal stacking
fromBlocksDiag :: [SpMatrix a] -> SpMatrix a #
Assembles a square matrix from a list of square matrices, arranging these along the main diagonal
Misc. SpMatrix operations
countSubdiagonalNZSM :: SpMatrix a -> Int #
Count sub-diagonal nonzeros
subdiagIndicesSM :: SpMatrix a -> [(IxRow, IxCol)] #
Filter the index subset that lies below the diagonal (used in the QR decomposition, for example)
Sparsify : remove almost-0 elements (|x| < eps)
sparsifyIM2 :: Epsilon a => IntM (IntM a) -> IntM (IntM a) #
sparsifySM :: Epsilon a => SpMatrix a -> SpMatrix a #
Sparsify an SpMatrix
Value rounding
roundZeroOneSM :: Epsilon a => SpMatrix a -> SpMatrix a #
Round almost-0 and almost-1 to 0 and 1 respectively
modifyKeysSM' :: (IxRow -> a) -> (IxCol -> b) -> SpMatrix c -> [(a, b, c)] #
Modify (row, column) keys, leaving data intact. Be careful when using this! modifyKeysSM' :: (IxRow -> IxRow) -> (IxCol -> IxCol) -> SpMatrix a -> SpMatrix a
modifyKeysSM :: (IxRow -> IxRow) -> (IxCol -> IxCol) -> SpMatrix a -> SpMatrix a #
Primitive algebra operations
Matrix row swap
swapRows :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a #
Swap two rows of a SpMatrix (bounds not checked)
swapRowsSafe :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a #
Swap two rows of a SpMatrix (bounds checked)
Matrix transpose
transposeSM :: SpMatrix a -> SpMatrix a #
transposeSM : Matrix transpose
Multiply matrix by a scalar
Trace
Frobenius norm
normFrobeniusSM :: (MatrixRing (SpMatrix a), Floating a) => SpMatrix a -> a #
normFrobeniusSMC :: (MatrixRing (SpMatrix (Complex a)), RealFloat a) => SpMatrix (Complex a) -> a #
Matrix-matrix product
matMatUnsafeWith :: Num a => (IntM (IntM a1) -> IntM (IntM a)) -> SpMatrix a -> SpMatrix a1 -> SpMatrix a #
Matrix product without dimension checks
Matrix-matrix product, sparsified
matMatSparsified :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a #
After multiplying the two matrices, all elements x
for which `| x | <= eps` are removed.
(#~#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a #
After multiplying the two matrices, all elements x
for which `| x | <= eps` are removed.
Sparsified matrix products of two matrices
(#~#^) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a #
Sparsifying A^T B
(#~^#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a #
Sparsifying A B^T