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

Copyright(c) Marco Zocca 2017
LicenseGPL-3 (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) #

Additive group

class AdditiveGroup v where #

Minimal complete definition

zeroV, (^+^), negateV, (^-^)

Methods

zeroV :: v #

The zero element: identity for '(^+^)'

(^+^) :: v -> v -> v infixl 6 #

Add vectors

negateV :: v -> v #

Additive inverse

(^-^) :: v -> v -> v infixl 6 #

Group subtraction

Instances

Num a => AdditiveGroup (SpMatrix a) #

SpMatrixes form an additive group, in that they can have an invertible associtative operation (matrix sum)

Vector space v.

class (AdditiveGroup v, Num (Scalar v)) => VectorSpace v where #

Minimal complete definition

(.*)

Associated Types

type Scalar v :: * #

Methods

(.*) :: Scalar v -> v -> v infixr 7 #

Scale a vector

class (VectorSpace v, AdditiveGroup (Scalar v)) => InnerSpace v where #

Adds inner (dot) products.

Minimal complete definition

(<.>)

Methods

(<.>) :: v -> v -> Scalar v #

Inner/dot product

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

Inner product

(./) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v infixr 7 #

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

(*.) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v infixl 7 #

Vector multiplied by scalar

cvx :: VectorSpace v => Scalar v -> v -> v -> v #

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

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)

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

(<\>) #

Arguments

:: (MonadIO m, MonadThrow m) 
=> MatrixType v

System matrix

-> v

Right-hand side

-> m v

Result

Solve a linear system; uses GMRES internally as default method

FiniteDim : finite-dimensional objects

class FiniteDim f where #

Minimal complete definition

dim

Associated Types

type FDSize f #

Methods

dim :: f -> FDSize f #

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

Instances

FiniteDim (SpVector a) #

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

SpVectors are finite-dimensional vectors

Associated Types

type FDSize (SpVector a) :: * #

Methods

dim :: SpVector a -> FDSize (SpVector a) #

FiniteDim (SpMatrix a) #

SpMatrixes are maps between finite-dimensional spaces

Associated Types

type FDSize (SpMatrix a) :: * #

Methods

dim :: SpMatrix a -> FDSize (SpMatrix a) #

HasData : accessing inner data (do not export)

class HasData f where #

Minimal complete definition

nnz, dat

Associated Types

type HDData f #

Methods

nnz :: f -> Int #

Number of nonzeros

dat :: f -> HDData f #

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

Sparse : sparse datastructures

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

Minimal complete definition

spy

Methods

spy :: Fractional b => f -> 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 #

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 => SpContainer c where #

Minimal complete definition

scInsert, scLookup, scToList, (@@)

Associated Types

type ScIx c :: * #

type ScElem c #

Methods

scInsert :: ScIx c -> ScElem c -> c -> c #

scLookup :: c -> ScIx c -> Maybe (ScElem c) #

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

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

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 a) :: * #

type ScElem (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 a) :: * #

type ScElem (SpMatrix a) :: * #

SparseVector

class SpContainer v => SparseVector v where #

Minimal complete definition

svFromList, svFromListDense, svConcat

Associated Types

type SpvIx v :: * #

Methods

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

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

svConcat :: Foldable t => t v -> v #

SparseMatrix

class SpContainer m => SparseMatrix m where #

Minimal complete definition

smFromVector, smTranspose, encodeIx, decodeIx

Methods

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

smTranspose :: m -> m #

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

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

SparseMatVec

Utilities

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

Lift a real number onto the complex plane