sparse-linear-algebra-0.2.9.2: Numerical computation 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 # Source # SpVectors form a vector space because they can be multiplied by a scalarSpVectors are finite-dimensional vectors Associated Typestype FDSize (SpVector :: * -> *) :: * Source # Methods 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 #scToList :: SpVector a -> [(ScIx SpVector, a)] Source #(@@) :: SpVector a -> ScIx SpVector -> a Source # Source # Methodsspy :: Fractional b => SpVector a -> b Source # Source # Associated Typestype HDData (SpVector :: * -> *) a :: * Source # Methodsnnz :: SpVector a -> Int 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 # Source # Associated Typestype Scalar (SpVector Double) :: * # Methods Source # Associated Typestype Scalar (SpVector (Complex Double)) :: * # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Associated Typestype Magnitude (SpVector Double) :: * Source #type RealScalar (SpVector Double) :: * Source # Methods Source # Associated Typestype Magnitude (SpVector (Complex Double)) :: * Source #type RealScalar (SpVector (Complex Double)) :: * Source # Methods 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 type Scalar (SpVector Double) Source # type Scalar (SpVector Double) = Double type Scalar (SpVector (Complex Double)) Source # type Scalar (SpVector (Complex Double)) = Complex Double type MatrixType (SpVector Double) Source # type MatrixType (SpVector (Complex Double)) Source # type Magnitude (SpVector Double) Source # type Magnitude (SpVector Double) = Double type Magnitude (SpVector (Complex Double)) Source # type Magnitude (SpVector (Complex Double)) = Double type RealScalar (SpVector Double) Source # type RealScalar (SpVector Double) = Double type RealScalar (SpVector (Complex Double)) Source # type RealScalar (SpVector (Complex Double)) = Double

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

SpVector sparsity

nzSV :: SpVector a -> Int Source #

Number of nonzeros

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

dotSSafe :: (InnerSpace (IntM 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

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

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

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