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

Data.Sparse.SpMatrix

Description

Synopsis

# Sparse Matrix

data SpMatrix a Source #

Constructors

 SM FieldssmDim :: (Rows, Cols) smData :: IntMap (IntMap a)

Instances

 Source # Methodsfmap :: (a -> b) -> SpMatrix a -> SpMatrix b #(<\$) :: a -> SpMatrix b -> SpMatrix a # Source # MethodsliftU2 :: (a -> a -> a) -> SpMatrix a -> SpMatrix a -> SpMatrix a Source #liftI2 :: (a -> b -> c) -> SpMatrix a -> SpMatrix b -> SpMatrix c Source # Source # SpMatrixes are maps between finite-dimensional spaces Associated Typestype FDSize (SpMatrix :: * -> *) :: * Source # Methods Source # SpMatrixes form a ring, in that they can be added and possess a zero element Methodszero :: Num a => SpMatrix a Source #(^+^) :: Num a => SpMatrix a -> SpMatrix a -> SpMatrix a Source #one :: Num a => SpMatrix a Source #(^*^) :: Num a => SpMatrix a -> SpMatrix a -> SpMatrix a Source # 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 #(@@) :: SpMatrix a -> ScIx SpMatrix -> a Source # Source # Methodsspy :: Fractional b => SpMatrix a -> b Source # Source # Associated Typestype HDData (SpMatrix :: * -> *) a :: * Source # Methods 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 # 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 = IntMap (IntMap a)

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

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

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

## toList

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?

isOrthogonalSM :: (Eq a, Epsilon a) => SpMatrix a -> Bool Source #

Is the matrix orthogonal? i.e. Q^t ## Q == I

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

Data in internal representation (do not export)

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

## Misc. SpMatrix operations

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

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 => IntMap (IntMap a) -> IntMap (IntMap 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

# 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

## Multiply matrix by a scalar

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

## Matrix-matrix product

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

## Matrix-matrix product, sparsified

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

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

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

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

### Sparsified matrix products of two matrices

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

A^T B

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

A B^T

## Partial inner product

contractSub :: Num 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]