Safe Haskell | None |
---|---|
Language | Haskell98 |
SparseMatrix
Description
Sparse matrices. Original: Agda.Termination.SparseMatrix
We assume the matrices to be very sparse, so we just implement them as sorted association lists.
Synopsis
- data Matrix i b = M (Size i) [(MIx i, b)]
- matrixInvariant :: (Num i, Ix i) => Matrix i b -> Bool
- data Size i = Size {}
- sizeInvariant :: (Ord i, Num i) => Size i -> Bool
- data MIx i = MIx {}
- mIxInvariant :: (Ord i, Num i) => MIx i -> Bool
- fromLists :: (Ord i, Num i, Enum i, HasZero b) => Size i -> [[b]] -> Matrix i b
- fromIndexList :: (Ord i, HasZero b) => Size i -> [(MIx i, b)] -> Matrix i b
- toLists :: (Ord i, Integral i, Enum i, HasZero b, Show i) => Matrix i b -> [[b]]
- size :: Matrix i b -> Size i
- square :: Ix i => Matrix i b -> Bool
- isEmpty :: (Num i, Ix i) => Matrix i b -> Bool
- isSingleton :: (Num i, Ix i, HasZero b) => Matrix i b -> Maybe b
- all :: (a -> Bool) -> Matrix i a -> Bool
- any :: (a -> Bool) -> Matrix i a -> Bool
- add :: Ord i => (a -> a -> a) -> Matrix i a -> Matrix i a -> Matrix i a
- intersectWith :: Ord i => (a -> a -> a) -> Matrix i a -> Matrix i a -> Matrix i a
- zip :: (Ord i, HasZero a) => Matrix i a -> Matrix i a -> Matrix i (a, a)
- mul :: (Enum i, Num i, Ix i, Eq a) => Semiring a -> Matrix i a -> Matrix i a -> Matrix i a
- transpose :: Ord i => Matrix i b -> Matrix i b
- diagonal :: (Enum i, Num i, Ix i, Show i, HasZero b) => Matrix i b -> [b]
- addRow :: (Num i, HasZero b) => b -> Matrix i b -> Matrix i b
- addColumn :: (Num i, HasZero b) => b -> Matrix i b -> Matrix i b
Basic data types
Type of matrices, parameterised on the type of values.
Instances
Functor (Matrix i) Source # | |
(Ord i, Integral i, Enum i, Show i, Show b, HasZero b) => Show (Matrix i b) Source # | |
(Ord i, Eq a, HasZero a) => Eq (Matrix i a) Source # | |
(HasZero b, Ord i, Ord b) => Ord (Matrix i b) Source # | |
Size of a matrix.
Type of matrix indices (row, column).
Generating and creating matrices
fromIndexList :: (Ord i, HasZero b) => Size i -> [(MIx i, b)] -> Matrix i b Source #
Generates a matrix of the given size, using the given generator to generate the rows.
Generates a matrix of the given size.
Constructs a matrix from a list of (index, value)-pairs.
toLists :: (Ord i, Integral i, Enum i, HasZero b, Show i) => Matrix i b -> [[b]] Source #
Converts a matrix to a list of row lists.
Combining and querying matrices
isSingleton :: (Num i, Ix i, HasZero b) => Matrix i b -> Maybe b Source #
Returns 'Just b' iff it is a 1x1 matrix with just one entry b
.
intersectWith :: Ord i => (a -> a -> a) -> Matrix i a -> Matrix i a -> Matrix i a Source #
build the pointwise conjunction intersectWith
f m1 m2m1
and m2
.
Uses f
to combine non-zero values.
Modifying matrices
addRow :: (Num i, HasZero b) => b -> Matrix i b -> Matrix i b Source #
adds a new row to addRow
x mm
, after the rows already
existing in the matrix. All elements in the new row get set to x
.
addColumn :: (Num i, HasZero b) => b -> Matrix i b -> Matrix i b Source #
adds a new column to addColumn
x mm
, after the columns
already existing in the matrix. All elements in the new column get
set to x
.