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

Copyright (C) 2016 Marco Zocca GPL-3 (see LICENSE) zocca.marco gmail provisional portable None Haskell2010

Data.Sparse.SpVector

Description

Synopsis

# Sparse Vector

data SpVector a Source #

Constructors

 SV FieldssvDim :: Int svData :: IntMap 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 -> b -> c) -> SpVector a -> SpVector b -> SpVector c Source # Source # SpVectors are finite-dimensional vectors Associated Typestype FDSize (SpVector :: * -> *) :: * Source # Methods Source # Since SpVectors form a Hilbert space, we can define a norm for them Methodsnorm :: (Floating a, Eq a) => a -> SpVector a -> a Source # Source # SpVectors form a Hilbert space, in that we can define an inner product over them Methodsdot :: Num a => SpVector a -> SpVector a -> a Source # Source # SpVectors form a vector space because they can be multiplied by a scalar Methods(.*) :: Num a => a -> SpVector a -> SpVector a Source # Source # Methodszero :: Num a => SpVector a Source #(^+^) :: Num a => SpVector a -> SpVector a -> SpVector a Source #one :: Num a => SpVector a Source #(^*^) :: Num a => SpVector a -> SpVector a -> SpVector a Source # 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 :: * -> *) :: * Source # MethodsscInsert :: ScIx SpVector -> a -> SpVector a -> SpVector a Source #(@@) :: SpVector a -> ScIx SpVector -> a Source # Source # Methodsspy :: Fractional b => SpVector a -> b Source # Source # Associated Typestype HDData (SpVector :: * -> *) a :: * Source # Methods 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 # type ScIx SpVector Source # type ScIx SpVector = Int type FDSize SpVector Source # type FDSize SpVector = Int type HDData SpVector a Source # type HDData SpVector a = IntMap a

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

SpVector sparsity

nzSV :: SpVector a -> Int Source #

Number of nonzeros

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

create a sparse vector from an association list while discarding all zero entries

mkSpVectorD :: Epsilon a => Int -> [a] -> SpVector a Source #

", from logically dense array (consecutive indices)

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

### 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 :: Int -> a -> SpVector a -> SpVector a Source #

insert element x at index i in a preexisting SpVector

## fromList

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

## toList

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

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)

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

# Orthogonal vector

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