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

Copyright(c) Marco Zocca 2017
LicenseGPL-style (see the file LICENSE)
Maintainerzocca marco gmail
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Numeric.LinearAlgebra.Class

Contents

Description

Typeclasses for linear algebra and related concepts

Synopsis

Matrix and vector elements (optionally Complex)

class (Eq e, Fractional e, Floating e, Num (EltMag e), Ord (EltMag e)) => Elt e where #

Minimal complete definition

mag

Associated Types

type EltMag e :: * #

Methods

conj :: e -> e #

Complex conjugate, or identity function if its input is real-valued

mag :: e -> EltMag e #

Magnitude

Instances

Elt Double # 

Associated Types

type EltMag Double :: * #

Methods

conj :: Double -> Double #

mag :: Double -> EltMag Double #

Elt Float # 

Associated Types

type EltMag Float :: * #

Methods

conj :: Float -> Float #

mag :: Float -> EltMag Float #

RealFloat e => Elt (Complex e) # 

Associated Types

type EltMag (Complex e) :: * #

Methods

conj :: Complex e -> Complex e #

mag :: Complex e -> EltMag (Complex e) #

Vector space

(.*) :: VectorSpace v => Scalar v -> v -> v #

Scale a vector

(./) :: (VectorSpace v, Fractional (Scalar v)) => v -> Scalar v -> v #

Scale a vector by the reciprocal of a number (e.g. for normalization)

cvx :: (VectorSpace e, Num (Scalar e)) => Scalar e -> e -> e -> e #

Convex combination of two vectors (NB: 0 <= a <= 1).

Hilbert space (inner product)

dot :: InnerSpace v => v -> v -> Scalar v #

Inner product

Hilbert-space distance function

hilbertDistSq :: InnerSpace v => v -> v -> Scalar v #

`hilbertDistSq x y = || x - y ||^2` computes the squared L2 distance between two vectors

Normed vector spaces

class (InnerSpace v, Num (RealScalar v), Eq (RealScalar v), Epsilon (Magnitude v), Show (Magnitude v), Ord (Magnitude v)) => Normed v where #

Minimal complete definition

norm1, norm2Sq, normP, normalize, normalize2

Associated Types

type Magnitude v :: * #

type RealScalar v :: * #

Methods

norm1 :: v -> Magnitude v #

L1 norm

norm2Sq :: v -> Magnitude v #

Euclidean (L2) norm squared

normP :: RealScalar v -> v -> Magnitude v #

Lp norm (p > 0)

normalize :: RealScalar v -> v -> v #

Normalize w.r.t. Lp norm

normalize2 :: v -> v #

Normalize w.r.t. L2 norm

normalize2' :: Floating (Scalar v) => v -> v #

Normalize w.r.t. norm2' instead of norm2

norm2 :: Floating (Magnitude v) => v -> Magnitude v #

Euclidean (L2) norm

norm2' :: Floating (Scalar v) => v -> Scalar v #

Euclidean (L2) norm; returns a Complex (norm :+ 0) for Complex-valued vectors

norm :: Floating (Magnitude v) => RealScalar v -> v -> Magnitude v #

Lp norm (p > 0)

Instances

Normed Double # 
Normed (Complex Double) # 
Normed (SpVector Double) # 
Normed (SpVector (Complex Double)) # 

normInftyR :: (Foldable t, Ord a) => t a -> a #

Infinity-norm (Real)

normInftyC :: (Foldable t, RealFloat a, Functor t) => t (Complex a) -> a #

Infinity-norm (Complex)

dotLp :: (Set t, Foldable t, Floating a) => a -> t a -> t a -> a #

Lp inner product (p > 0)

reciprocal :: (Functor f, Fractional b) => f b -> f b #

Reciprocal

scale :: (Num b, Functor f) => b -> f b -> f b #

Scale

Matrix ring

class (AdditiveGroup m, Epsilon (MatrixNorm m)) => MatrixRing m where #

A matrix ring is any collection of matrices over some ring R that form a ring under matrix addition and matrix multiplication

Minimal complete definition

(##), (##^), transpose, normFrobenius

Associated Types

type MatrixNorm m :: * #

Methods

(##) :: m -> m -> m #

Matrix-matrix product

(##^) :: m -> m -> m #

Matrix times matrix transpose (A B^T)

(#^#) :: m -> m -> m #

Matrix transpose times matrix (A^T B)

transpose :: m -> m #

Matrix transpose (Hermitian conjugate in the Complex case)

normFrobenius :: m -> MatrixNorm m #

Frobenius norm

Linear vector space

class (VectorSpace v, MatrixRing (MatrixType v)) => LinearVectorSpace v where #

Minimal complete definition

(#>), (<#)

Associated Types

type MatrixType v :: * #

Methods

(#>) :: MatrixType v -> v -> v #

Matrix-vector action

(<#) :: v -> MatrixType v -> v #

Dual matrix-vector action

LinearVectorSpace + Normed

type V v = (LinearVectorSpace v, Normed v) #

Linear systems

class LinearVectorSpace v => LinearSystem v where #

Minimal complete definition

(<\>)

Methods

(<\>) :: (MonadIO m, MonadThrow m) => MatrixType v -> v -> m v #

Solve a linear system; uses GMRES internally as default method

FiniteDim : finite-dimensional objects

class Functor f => FiniteDim f where #

Minimal complete definition

dim

Associated Types

type FDSize f :: * #

Methods

dim :: f a -> FDSize f #

Dimension (i.e. Int for SpVector, (Int, Int) for SpMatrix)

Instances

FiniteDim SpVector #

SpVectors form a vector space because they can be multiplied by a scalar

SpVectors are finite-dimensional vectors

Associated Types

type FDSize (SpVector :: * -> *) :: * #

Methods

dim :: SpVector a -> FDSize SpVector #

FiniteDim SpMatrix #

SpMatrixes are maps between finite-dimensional spaces

Associated Types

type FDSize (SpMatrix :: * -> *) :: * #

Methods

dim :: SpMatrix a -> FDSize SpMatrix #

class FiniteDim' f where #

Minimal complete definition

dim'

Associated Types

type FDSize' f :: * #

Methods

dim' :: f -> FDSize' f #

HasData : accessing inner data (do not export)

class HasData f a where #

Minimal complete definition

nnz, dat

Associated Types

type HDData f a :: * #

Methods

nnz :: f a -> Int #

Number of nonzeros

dat :: f a -> HDData f a #

Instances

HasData SpVector a # 

Associated Types

type HDData (SpVector :: * -> *) a :: * #

Methods

nnz :: SpVector a -> Int #

dat :: SpVector a -> HDData SpVector a #

HasData SpMatrix a # 

Associated Types

type HDData (SpMatrix :: * -> *) a :: * #

Methods

nnz :: SpMatrix a -> Int #

dat :: SpMatrix a -> HDData SpMatrix a #

class HasData' f where #

Minimal complete definition

nnz', dat'

Associated Types

type HDD f :: * #

Methods

nnz' :: f -> Int #

dat' :: f -> HDD f #

Sparse : sparse datastructures

class (FiniteDim f, HasData f a) => Sparse f a where #

Minimal complete definition

spy

Methods

spy :: Fractional b => f a -> b #

Sparsity (fraction of nonzero elements)

Instances

Sparse SpVector a # 

Methods

spy :: Fractional b => SpVector a -> b #

Sparse SpMatrix a # 

Methods

spy :: Fractional b => SpMatrix a -> b #

class (FiniteDim' f, HasData' f) => Sparse' f where #

Minimal complete definition

spy'

Methods

spy' :: Fractional b => f -> b #

Set : types that behave as sets

class Functor f => Set f where #

Minimal complete definition

liftU2, liftI2

Methods

liftU2 :: (a -> a -> a) -> f a -> f a -> f a #

Union binary lift : apply function on _union_ of two "sets"

liftI2 :: (a -> a -> b) -> f a -> f a -> f b #

Intersection binary lift : apply function on _intersection_ of two "sets"

Instances

Set SpVector # 

Methods

liftU2 :: (a -> a -> a) -> SpVector a -> SpVector a -> SpVector a #

liftI2 :: (a -> a -> b) -> SpVector a -> SpVector a -> SpVector b #

Set SpMatrix # 

Methods

liftU2 :: (a -> a -> a) -> SpMatrix a -> SpMatrix a -> SpMatrix a #

liftI2 :: (a -> a -> b) -> SpMatrix a -> SpMatrix a -> SpMatrix b #

SpContainer : sparse container datastructures. Insertion, lookup, toList, lookup with 0 default

class Sparse c a => SpContainer c a where #

Minimal complete definition

scInsert, scLookup, scToList, (@@)

Associated Types

type ScIx c :: * #

Methods

scInsert :: ScIx c -> a -> c a -> c a #

scLookup :: c a -> ScIx c -> Maybe a #

scToList :: c a -> [(ScIx c, a)] #

(@@) :: c a -> ScIx c -> a #

Instances

Elt a => SpContainer SpVector a #

SpVectors are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0)

Associated Types

type ScIx (SpVector :: * -> *) :: * #

Methods

scInsert :: ScIx SpVector -> a -> SpVector a -> SpVector a #

scLookup :: SpVector a -> ScIx SpVector -> Maybe a #

scToList :: SpVector a -> [(ScIx SpVector, a)] #

(@@) :: SpVector a -> ScIx SpVector -> a #

Num a => SpContainer SpMatrix a #

SpMatrixes are sparse containers too, i.e. any specific component may be missing (so it is assumed to be 0)

Associated Types

type ScIx (SpMatrix :: * -> *) :: * #

Methods

scInsert :: ScIx SpMatrix -> a -> SpMatrix a -> SpMatrix a #

scLookup :: SpMatrix a -> ScIx SpMatrix -> Maybe a #

scToList :: SpMatrix a -> [(ScIx SpMatrix, a)] #

(@@) :: SpMatrix a -> ScIx SpMatrix -> a #

class SpContainer' c where #

Minimal complete definition

scInsert', scLookup', scToList'

Associated Types

type ScIx' c :: * #

Methods

scInsert' :: ScIx' c -> a -> c -> c #

scLookup' :: c -> ScIx' c -> Maybe a #

scToList' :: c -> [a] #

SparseVector

class SpContainer v e => SparseVector v e where #

Minimal complete definition

svFromList, svFromListDense, svConcat

Associated Types

type SpvIx v :: * #

Methods

svFromList :: Int -> [(SpvIx v, e)] -> v e #

svFromListDense :: Int -> [e] -> v e #

svConcat :: Foldable t => t (v e) -> v e #

SparseMatrix

class SpContainer m e => SparseMatrix m e where #

Minimal complete definition

smFromVector, smTranspose, encodeIx, decodeIx

Methods

smFromVector :: LexOrd -> (Int, Int) -> Vector (IxRow, IxCol, e) -> m e #

smTranspose :: m e -> m e #

encodeIx :: m e -> LexOrd -> (IxRow, IxCol) -> LexIx #

decodeIx :: m e -> LexOrd -> LexIx -> (IxRow, IxCol) #

SparseMatVec

Utilities

toC :: Num a => a -> Complex a #

Lift a real number onto the complex plane