sparse-lin-alg-0.3: Small library for effective linear algebra on sparse matrices

Math.LinearAlgebra.Sparse.Vector

Synopsis

# Documentation

·· :: Num α => IntMap α -> IntMap α -> αSource

Dot product of two `IntMap`s (for internal use)

shiftKeys :: Int -> IntMap α -> IntMap αSource

Shifts (re-enumerates) keys of IntMap by given number

addElem :: Maybe α -> Int -> IntMap α -> IntMap αSource

Adds element to the map at given index, shifting all keys after it

delElem :: Int -> IntMap α -> IntMap αSource

Deletes element of the map at given index, shifting all keys after it

partitionMap :: (α -> Bool) -> IntMap α -> (IntMap α, IntMap α)Source

Splits map using predicate and returns a pair with filtered map and re-enumereted second part (that doesn't satisfy predicate). For example:

````>>> ````partitionMap (>0) (fromList [(1,1),(2,-1),(3,-2),(4,3),(5,-4)])
```( fromList [(1,1),(4,3)], fromList [(1,-1),(2,-2),(3,-4)] )
```

type SVec α = IntMap αSource

Type of internal vector storage

data SparseVector α Source

Sparse vector is just indexed map of non-zero values

Constructors

 SV Fieldsdim :: Intreal size of vector (with zeroes) vec :: SVec αIntMap storing non-zero values

Instances

 Functor SparseVector `fmap` applies given function on vector non-zero values Foldable SparseVector fold functions are applied to non-zero values Eq α => Eq (SparseVector α) (Eq α, Num α) => Num (SparseVector α) `Num` operators like `(*)`, `(+)` and `(-)` work on sparse vectors like `zipWith (…)` works on lists, except size of result is maximum of arguments sizes. `signum`, `abs` and `negate` work through `fmap`, so usual `Num` laws are satisfied (such as `(signum v)*(abs v) == v`. `fromInteger` constructs a vector with single element. So, ````>>> ````3 + (sparseList [0,2,1]) ```sparseList [3,2,1] ``` (Show α, Eq α, Num α) => Show (SparseVector α) Shows size and filled vector (but without zeroes) Monoid (SparseVector α) Monoid `mappend` operation works like concatenation of two vectors (indexes of second are shifted by length of first)

Sets vector's size

Vector of zero size with no values

Vector of given size with no non-zero values

Checks if vector has no non-zero values (i.e. is empty)

singVec :: (Eq α, Num α) => α -> SparseVector αSource

Vector of length 1 with given value

(.>) :: (Eq α, Num α) => α -> SparseVector α -> SparseVector αSource

This is like cons (`:`) operator for lists.

`x .> v = singVec x <> v`

partitionVec :: Num α => (α -> Bool) -> SparseVector α -> (SparseVector α, SparseVector α)Source

Splits vector using predicate and returns a pair with filtered values and re-enumereted second part (that doesn't satisfy predicate). For example:

````>>> ````partitionVec (>0) (sparseList [0,1,-1,2,3,0,-4,5,-6,0,7])
```( sparseList [0,1,0,2,3,0,0,5,0,0,7], sparseList [-1,-4,-6] )
```

(!) :: Num α => SparseVector α -> Index -> αSource

Looks up an element in the vector (if not found, zero is returned)

eraseInVec :: Num α => SparseVector α -> Index -> SparseVector αSource

Deletes element of vector at given index (size of vector doesn't change)

vecIns :: (Eq t, Num t) => SparseVector t -> (Index, t) -> SparseVector tSource

fillVec :: Num α => SparseVector α -> [α]Source

Returns plain list with all zeroes restored

sparseList :: (Num α, Eq α) => [α] -> SparseVector αSource

Converts plain list to sparse vector, throwing out all zeroes

showSparseList :: (Show α, Eq α, Num α) => [α] -> StringSource

showNonZero :: (Eq a, Num a, Show a) => a -> [Char]Source

dot :: (Eq α, Num α) => SparseVector α -> SparseVector α -> αSource

Dot product of two sparse vectors

· :: (Eq α, Num α) => SparseVector α -> SparseVector α -> αSource

Unicode alias for `dot`