sparse-linear-algebra-0.3.1: Numerical computing in native Haskell

Data.Sparse.SpVector

Description

Synopsis

# Sparse Vector

data SpVector a Source #

Constructors

 SV FieldssvDim :: !Int svData :: !(IntM a)

Instances

 Source # Methodsfmap :: (a -> b) -> SpVector a -> SpVector b #(<\$) :: a -> SpVector b -> SpVector a # Source # Methodsfold :: Monoid m => SpVector m -> m #foldMap :: Monoid m => (a -> m) -> SpVector a -> m #foldr :: (a -> b -> b) -> b -> SpVector a -> b #foldr' :: (a -> b -> b) -> b -> SpVector a -> b #foldl :: (b -> a -> b) -> b -> SpVector a -> b #foldl' :: (b -> a -> b) -> b -> SpVector a -> b #foldr1 :: (a -> a -> a) -> SpVector a -> a #foldl1 :: (a -> a -> a) -> SpVector a -> a #toList :: SpVector a -> [a] #null :: SpVector a -> Bool #length :: SpVector a -> Int #elem :: Eq a => a -> SpVector a -> Bool #maximum :: Ord a => SpVector a -> a #minimum :: Ord a => SpVector a -> a #sum :: Num a => SpVector a -> a #product :: Num a => SpVector a -> a # Source # MethodsliftU2 :: (a -> a -> a) -> SpVector a -> SpVector a -> SpVector a Source #liftI2 :: (a -> a -> b) -> SpVector a -> SpVector a -> SpVector b Source # Eq a => Eq (SpVector a) Source # Methods(==) :: SpVector a -> SpVector a -> Bool #(/=) :: SpVector a -> SpVector a -> Bool # Show a => Show (SpVector a) Source # MethodsshowsPrec :: Int -> SpVector a -> ShowS #show :: SpVector a -> String #showList :: [SpVector a] -> ShowS # Elt a => SpContainer (SpVector a) Source # SpVectors are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0) Associated Typestype ScIx (SpVector a) :: * Source #type ScElem (SpVector a) :: * Source # MethodsscInsert :: ScIx (SpVector a) -> ScElem (SpVector a) -> SpVector a -> SpVector a Source #scLookup :: SpVector a -> ScIx (SpVector a) -> Maybe (ScElem (SpVector a)) Source #scToList :: SpVector a -> [(ScIx (SpVector a), ScElem (SpVector a))] Source #(@@) :: SpVector a -> ScIx (SpVector a) -> ScElem (SpVector a) Source # Source # Methodsspy :: Fractional b => SpVector a -> b Source # Source # Associated Typestype HDData (SpVector a) :: * Source # Methodsnnz :: SpVector a -> Int Source #dat :: SpVector a -> HDData (SpVector a) Source # Source # SpVectors form a vector space because they can be multiplied by a scalarSpVectors are finite-dimensional vectors Associated Typestype FDSize (SpVector a) :: * Source # Methodsdim :: SpVector a -> FDSize (SpVector a) Source # (Normed a, (~) * (Magnitude a) (RealScalar a), (~) * (RealScalar a) (Scalar a)) => Normed (SpVector a) Source # Associated Typestype Magnitude (SpVector a) :: * Source #type RealScalar (SpVector a) :: * Source # MethodsnormP :: RealScalar (SpVector a) -> SpVector a -> Magnitude (SpVector a) Source #normalize :: RealScalar (SpVector a) -> SpVector a -> SpVector a Source #norm2' :: SpVector a -> Scalar (SpVector a) Source #norm :: RealScalar (SpVector a) -> SpVector a -> Magnitude (SpVector a) Source # InnerSpace a => InnerSpace (SpVector a) Source # Methods(<.>) :: SpVector a -> SpVector a -> Scalar (SpVector a) Source # Source # Associated Typestype Scalar (SpVector a) :: * Source # Methods(.*) :: Scalar (SpVector a) -> SpVector a -> SpVector a Source # Source # Methods(^+^) :: SpVector a -> SpVector a -> SpVector a Source #(^-^) :: SpVector a -> SpVector a -> SpVector a Source # type ScIx (SpVector a) Source # type ScIx (SpVector a) = Int type ScElem (SpVector a) Source # type ScElem (SpVector a) = a type HDData (SpVector a) Source # type HDData (SpVector a) type FDSize (SpVector a) Source # type FDSize (SpVector a) = Int type MatrixType (SpVector t) Source # type MatrixType (SpVector t) = SpMatrix t type Magnitude (SpVector a) Source # type Magnitude (SpVector a) = Magnitude a type RealScalar (SpVector a) Source # type RealScalar (SpVector a) = RealScalar a type Scalar (SpVector a) Source # type Scalar (SpVector a) = Scalar a

spySV :: Fractional b => SpVector a -> b Source #

SpVector density

nzSV :: SpVector a -> Int Source #

Number of nonzeros

foldlWithKeySV :: (a -> Key -> b -> a) -> a -> SpVector b -> a Source #

foldlWithKeySV' :: (a -> Key -> b -> a) -> a -> SpVector b -> a Source #

dotS :: InnerSpace t => SpVector t -> SpVector t -> Scalar (IntM t) Source #

dotSSafe :: (InnerSpace t, MonadThrow m) => SpVector t -> SpVector t -> m (Scalar (IntM t)) Source #

## Creation

Empty sparse vector (length n, no entries)

singletonSV :: a -> SpVector a Source #

Singleton sparse vector (length 1)

ei :: Num a => Int -> Key -> SpVector a Source #

Canonical basis vector in R^n

mkSpVector :: Epsilon a => Int -> IntMap a -> SpVector a Source #

Sparse vector from an association list while discarding all zero entries

mkSpVR :: Int -> [Double] -> SpVector Double Source #

Dense real SpVector (monomorphic Double)

Dense complex SpVector (monomorphic Double)

fromListDenseSV :: Int -> [a] -> SpVector a Source #

Create new sparse vector, assumin 0-based, contiguous indexing

spVectorDenseIx :: Epsilon a => (Int -> a) -> UB -> [Int] -> SpVector a Source #

Map a function over a range of indices and filter the result (indices and values) to fit in a n-long SpVector

spVectorDenseLoHi :: Epsilon a => (Int -> a) -> UB -> Int -> Int -> SpVector a Source #

", using just the integer bounds of the interval

oneHotSVU :: Num a => Int -> IxRow -> SpVector a Source #

one-hot encoding : oneHotSV n k produces a SpVector of length n having 1 at the k-th position

oneHotSV :: Num a => Int -> IxRow -> SpVector a Source #

onesSV :: Num a => Int -> SpVector a Source #

DENSE vector of 1s

zerosSV :: Num a => Int -> SpVector a Source #

DENSE vector of 0s

constv :: Int -> a -> SpVector a Source #

DENSE vector with constant elements

### Vector-related

Populate a SpVector with the contents of a Vector.

Populate a Vector with the entries of a SpVector, discarding the indices (NB: loses sparsity information).

toVectorDense :: Num a => SpVector a -> Vector a Source #

Populate a Vector with the entries of a SpVector, replacing the missing entries with 0

## Element insertion

insertSpVector :: Key -> a -> SpVector a -> SpVector a Source #

insert element x at index i in a preexisting SpVector; discards out-of-bounds entries

## fromList

fromListSV :: Foldable t => Int -> t (Int, a) -> SpVector a Source #

Create new SpVector using data from a Foldable (e.g. a list) in (index, value) form

createv :: [a] -> SpVector a Source #

vr :: [Double] -> SpVector Double Source #

Create a dense SpVector from a list of Double's

Create a dense SpVector from a list of Complex Double's

## toList

toListSV :: SpVector a -> [(Int, a)] Source #

Populate a list with SpVector contents

toDenseListSV :: Num b => SpVector b -> [b] Source #

To dense list (default = 0)

ifoldSV :: (Key -> a -> b -> b) -> b -> SpVector a -> b Source #

Indexed fold over SpVector

## Lookup

lookupSV :: Key -> SpVector a -> Maybe a Source #

Lookup an index in a SpVector

lookupDefaultSV :: a -> Key -> SpVector a -> a Source #

Lookup an index, return a default value if lookup fails

lookupDenseSV :: Num a => Key -> SpVector a -> a Source #

Lookup an index in a SpVector, returns 0 if lookup fails

## Sub-vectors

Tail elements

headSV :: Num a => SpVector a -> a Source #

takeSV :: Int -> SpVector a -> SpVector a Source #

Keep the first n components of the SpVector (like take for lists)

dropSV :: Int -> SpVector a -> SpVector a Source #

Discard the first n components of the SpVector and rebalance the keys (like drop for lists)

Keep the first n components of the SpVector (like take for lists)

rangeSV :: (Key, Key) -> SpVector a -> SpVector a Source #

Keep a range of entries

concatSV :: SpVector a -> SpVector a -> SpVector a Source #

Concatenate two sparse vectors

filterSV :: (a -> Bool) -> SpVector a -> SpVector a Source #

Filter

ifilterSV :: (Int -> a -> Bool) -> SpVector a -> SpVector a Source #

Indexed filter

# Sparsify : remove almost-0 elements (|x| < eps)

sparsifySV :: Epsilon a => SpVector a -> SpVector a Source #

Sparsify an SpVector

# Orthogonal vector

orthogonalSV :: (Scalar (SpVector t) ~ t, InnerSpace (SpVector t), Fractional t) => SpVector t -> SpVector t Source #

Generate an arbitrary (not random) vector u such that v dot u = 0