sparse-linear-algebra-0.2.9.2: Numerical computation in native Haskell

Data.Sparse.SpMatrix

Description

Synopsis

Sparse Matrix

data SpMatrix a Source #

Constructors

 SM FieldssmDim :: !(Rows, Cols) smData :: !(IntM (IntM a))

Instances

 Source # Methodsfmap :: (a -> b) -> SpMatrix a -> SpMatrix b #(<\$) :: a -> SpMatrix b -> SpMatrix a # Source # Methodsfold :: Monoid m => SpMatrix m -> m #foldMap :: Monoid m => (a -> m) -> SpMatrix a -> m #foldr :: (a -> b -> b) -> b -> SpMatrix a -> b #foldr' :: (a -> b -> b) -> b -> SpMatrix a -> b #foldl :: (b -> a -> b) -> b -> SpMatrix a -> b #foldl' :: (b -> a -> b) -> b -> SpMatrix a -> b #foldr1 :: (a -> a -> a) -> SpMatrix a -> a #foldl1 :: (a -> a -> a) -> SpMatrix a -> a #toList :: SpMatrix a -> [a] #null :: SpMatrix a -> Bool #length :: SpMatrix a -> Int #elem :: Eq a => a -> SpMatrix a -> Bool #maximum :: Ord a => SpMatrix a -> a #minimum :: Ord a => SpMatrix a -> a #sum :: Num a => SpMatrix a -> a #product :: Num a => SpMatrix a -> a # Source # MethodsliftU2 :: (a -> a -> a) -> SpMatrix a -> SpMatrix a -> SpMatrix a Source #liftI2 :: (a -> a -> b) -> SpMatrix a -> SpMatrix a -> SpMatrix b Source # Source # SpMatrixes are maps between finite-dimensional spaces Associated Typestype FDSize (SpMatrix :: * -> *) :: * Source # Methods Source # SpMatrixes are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0) Associated Typestype ScIx (SpMatrix :: * -> *) :: * Source # MethodsscInsert :: ScIx SpMatrix -> a -> SpMatrix a -> SpMatrix a Source #scToList :: SpMatrix a -> [(ScIx SpMatrix, a)] Source #(@@) :: SpMatrix a -> ScIx SpMatrix -> a Source # Source # Methodsspy :: Fractional b => SpMatrix a -> b Source # Source # Associated Typestype HDData (SpMatrix :: * -> *) a :: * Source # Methodsnnz :: SpMatrix a -> Int Source # Eq a => Eq (SpMatrix a) Source # Methods(==) :: SpMatrix a -> SpMatrix a -> Bool #(/=) :: SpMatrix a -> SpMatrix a -> Bool # Show a => Show (SpMatrix a) Source # MethodsshowsPrec :: Int -> SpMatrix a -> ShowS #show :: SpMatrix a -> String #showList :: [SpMatrix a] -> ShowS # Num a => AdditiveGroup (SpMatrix a) Source # SpMatrixes form an additive group, in that they can have an invertible associtative operation (matrix sum) Methods(^+^) :: SpMatrix a -> SpMatrix a -> SpMatrix a #negateV :: SpMatrix a -> SpMatrix a #(^-^) :: SpMatrix a -> SpMatrix a -> SpMatrix a # Source # Associated Typestype MatrixNorm (SpMatrix Double) :: * Source # Methods Source # Associated Typestype MatrixNorm (SpMatrix (Complex Double)) :: * Source # Methods type ScIx SpMatrix Source # type ScIx SpMatrix = (Rows, Cols) type FDSize SpMatrix Source # type FDSize SpMatrix = (Rows, Cols) type HDData SpMatrix a Source # type HDData SpMatrix a type MatrixNorm (SpMatrix Double) Source # type MatrixNorm (SpMatrix Double) = Double type MatrixNorm (SpMatrix (Complex Double)) Source # type MatrixNorm (SpMatrix (Complex Double)) = Double

sizeStr :: (FDSize f ~ (a1, a2), Sparse f a, Show a2, Show a1) => f a -> String Source #

Creation

zeroSM :: Rows -> Cols -> SpMatrix a Source #

zeroSM m n : Empty SpMatrix of size (m, n)

Diagonal matrix

mkDiagonal :: Int -> [a] -> SpMatrix a Source #

Identity matrix

eye :: Num a => Int -> SpMatrix a Source #

eye n : identity matrix of rank n

Permutation matrix

permutationSM :: Num a => Int -> [IxRow] -> SpMatrix a Source #

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 Source #

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 Source #

mkSubDiagonal n o xx creates a square SpMatrix of size n with xx on the oth subdiagonal

Element insertion

insertSpMatrix :: IxRow -> IxCol -> a -> SpMatrix a -> SpMatrix a Source #

Insert an element in a preexisting Spmatrix at the specified indices

fromList

fromListSM' :: Foldable t => t (IxRow, IxCol, a) -> SpMatrix a -> SpMatrix a Source #

Add to existing SpMatrix using data from list (row, col, value)

fromListSM :: Foldable t => (Int, Int) -> t (IxRow, IxCol, a) -> SpMatrix a Source #

Create new SpMatrix using data from list (row, col, value)

mkSpMR :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Double) -> SpMatrix Double Source #

mkSpMC :: Foldable t => (Int, Int) -> t (IxRow, IxCol, Complex Double) -> SpMatrix (Complex Double) Source #

fromListDenseSM :: Int -> [a] -> SpMatrix a Source #

Create new SpMatrix assuming contiguous, 0-based indexing of elements

toList

toListSM :: SpMatrix t -> [(IxRow, IxCol, t)] Source #

Populate list with SpMatrix contents

toDenseListSM :: Num t => SpMatrix t -> [(IxRow, IxCol, t)] Source #

Populate list with SpMatrix contents and populate missing entries with 0

Lookup

lookupSM :: SpMatrix a -> IxRow -> IxCol -> Maybe a Source #

lookupWD_SM :: Num a => SpMatrix a -> (IxRow, IxCol) -> a Source #

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 Source #

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

filterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a Source #

Indexed filtering function

Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)

Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)

Diagonal, subdiagonal, superdiagonal partitions of a SpMatrix (useful for writing preconditioners)

extractSubmatrixSM :: (Key -> Key) -> (Key -> Key) -> SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a Source #

Extract a submatrix given the specified index bounds, rebalancing keys with the two supplied functions

extractSubmatrixRebalanceKeys :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a Source #

Extract a submatrix given the specified index bounds NB : subtracts (i1, j1) from the indices

extractSubmatrix :: SpMatrix a -> (IxRow, IxRow) -> (IxCol, IxCol) -> SpMatrix a Source #

Extract a submatrix given the specified index bounds NB : submatrix indices are _preserved_

takeRows :: IxRow -> SpMatrix a -> SpMatrix a Source #

takeCols :: IxCol -> SpMatrix a -> SpMatrix a Source #

Extract j'th column

extractColSM :: SpMatrix a -> IxCol -> SpMatrix a Source #

Extract whole column

extractSubColSM :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a Source #

Extract column within a row range

extractSubColSM_RK :: SpMatrix a -> IxCol -> (IxRow, IxRow) -> SpMatrix a Source #

Extract column within a row range, rebalance keys

Predicates

isValidIxSM :: SpMatrix a -> (Int, Int) -> Bool Source #

Are the supplied indices within matrix bounds?

Is the matrix square?

Is the matrix diagonal?

isLowerTriSM :: Eq a => SpMatrix a -> Bool Source #

Is the matrix lower/upper triangular?

isUpperTriSM :: Eq a => SpMatrix a -> Bool Source #

Is the matrix lower/upper triangular?

immSM :: SpMatrix t -> IntM (IntM t) Source #

Data in internal representation (do not export) immSM :: SpMatrix t -> IM.IntMap (IM.IntMap t)

dimSM :: SpMatrix t -> (Rows, Cols) Source #

(Number of rows, Number of columns)

nelSM :: SpMatrix t -> Int Source #

Number of rows times number of columns

nrows :: SpMatrix a -> Rows Source #

Number of rows

ncols :: SpMatrix a -> Cols Source #

Number of columns

data SMInfo Source #

Constructors

 SMInfo FieldssmNz :: Int smSpy :: Double

Instances

 Source # Methods(==) :: SMInfo -> SMInfo -> Bool #(/=) :: SMInfo -> SMInfo -> Bool # Source # MethodsshowsPrec :: Int -> SMInfo -> ShowS #showList :: [SMInfo] -> ShowS #

Matrix stacking

vertStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Vertical stacking

(-=-) :: SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Vertical stacking

horizStackSM :: SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Horizontal stacking

(-||-) :: SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Horizontal stacking

fromBlocksDiag :: [SpMatrix a] -> SpMatrix a Source #

Assembles a square matrix from a list of square matrices, arranging these along the main diagonal

Misc. SpMatrix operations

ifilterSM :: (Key -> Key -> a -> Bool) -> SpMatrix a -> SpMatrix a Source #

Indexed filter over SpMatrix

foldlSM :: (a -> b -> b) -> b -> SpMatrix a -> b Source #

Left fold over SpMatrix

ifoldlSM :: (Key -> Key -> a -> b -> b) -> b -> SpMatrix a -> b Source #

Indexed left fold over SpMatrix

Count sub-diagonal nonzeros

subdiagIndicesSM :: SpMatrix a -> [(IxRow, IxCol)] Source #

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) Source #

sparsifySM :: Epsilon a => SpMatrix a -> SpMatrix a Source #

Sparsify an SpMatrix

Value rounding

roundZeroOneSM :: Epsilon a => SpMatrix a -> SpMatrix a Source #

Round almost-0 and almost-1 to 0 and 1 respectively

modifyKeysSM' :: (IxRow -> a) -> (IxCol -> b) -> SpMatrix c -> [(a, b, c)] Source #

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 Source #

Primitive algebra operations

Matrix row swap

swapRows :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a Source #

Swap two rows of a SpMatrix (bounds not checked)

swapRowsSafe :: IxRow -> IxRow -> SpMatrix a -> SpMatrix a Source #

Swap two rows of a SpMatrix (bounds checked)

Matrix transpose

transposeSM : Matrix transpose

hermitianConj :: Num a => SpMatrix (Complex a) -> SpMatrix (Complex a) Source #

Hermitian conjugate

Multiply matrix by a scalar

matScale :: Num a => a -> SpMatrix a -> SpMatrix a Source #

Trace

trace :: Num b => SpMatrix b -> b Source #

Matrix-matrix product

data MatProd_ Source #

Internal implementation

Constructors

 AB ABt

Instances

 Source # Methods Source # MethodsshowList :: [MatProd_] -> ShowS #

matMatUnsafeWith :: Num a => (IntM (IntM a1) -> IntM (IntM a)) -> SpMatrix a -> SpMatrix a1 -> SpMatrix a Source #

Matrix product without dimension checks

Matrix-matrix product, sparsified

matMatSparsified :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Removes all elements x for which | x | <= eps)

(#~#) :: (MatrixRing (SpMatrix a), Epsilon a) => SpMatrix a -> SpMatrix a -> SpMatrix a Source #

Removes all elements x for which | x | <= eps)

Partial inner product

contractSub :: Elt a => SpMatrix a -> SpMatrix a -> IxRow -> IxCol -> Int -> a Source #

Contract row i of A with column j of B up to an index n, i.e. summing over repeated indices: Aij Bjk , for j in [0 .. n]