sparse-linear-algebra-0.3.1: 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 Source #

Minimal complete definition

mag

Associated Types

type EltMag e :: * Source #

Methods

conj :: e -> e Source #

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

mag :: e -> EltMag e Source #

Magnitude

Instances

Elt Double Source # 

Associated Types

type EltMag Double :: * Source #

Elt Float Source # 

Associated Types

type EltMag Float :: * Source #

RealFloat e => Elt (Complex e) Source # 

Associated Types

type EltMag (Complex e) :: * Source #

Methods

conj :: Complex e -> Complex e Source #

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

Additive group

class AdditiveGroup v where Source #

Minimal complete definition

zeroV, (^+^), negateV

Methods

zeroV :: v Source #

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

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

Add vectors

negateV :: v -> v Source #

Additive inverse

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

Group subtraction

Instances

AdditiveGroup Double Source # 
AdditiveGroup Float Source #

Instances for builtin types

AdditiveGroup (Complex Double) Source # 
AdditiveGroup (Complex Float) Source # 
AdditiveGroup a => AdditiveGroup (SpVector a) Source # 
AdditiveGroup a => AdditiveGroup (SpMatrix a) Source #

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

Minimal complete definition

(.*)

Associated Types

type Scalar v :: * Source #

Methods

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

Scale a vector

Instances

VectorSpace Double Source # 

Associated Types

type Scalar Double :: * Source #

VectorSpace Float Source # 

Associated Types

type Scalar Float :: * Source #

Methods

(.*) :: Scalar Float -> Float -> Float Source #

VectorSpace (Complex Double) Source # 

Associated Types

type Scalar (Complex Double) :: * Source #

VectorSpace (Complex Float) Source # 

Associated Types

type Scalar (Complex Float) :: * Source #

VectorSpace a => VectorSpace (SpVector a) Source # 

Associated Types

type Scalar (SpVector a) :: * Source #

Methods

(.*) :: Scalar (SpVector a) -> SpVector a -> SpVector a Source #

VectorSpace a => VectorSpace (SpMatrix a) Source # 

Associated Types

type Scalar (SpMatrix a) :: * Source #

Methods

(.*) :: Scalar (SpMatrix a) -> SpMatrix a -> SpMatrix a Source #

class VectorSpace v => InnerSpace v where Source #

Adds inner (dot) products.

Minimal complete definition

(<.>)

Methods

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

Inner/dot product

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

Inner product

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

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

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

Vector multiplied by scalar

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

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

Hilbert-space distance function

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

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

Minimal complete definition

norm1, norm2Sq, normP, normalize, normalize2

Associated Types

type Magnitude v :: * Source #

type RealScalar v :: * Source #

Methods

norm1 :: v -> Magnitude v Source #

L1 norm

norm2Sq :: v -> Magnitude v Source #

Euclidean (L2) norm squared

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

Lp norm (p > 0)

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

Normalize w.r.t. Lp norm

normalize2 :: v -> v Source #

Normalize w.r.t. L2 norm

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

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

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

Euclidean (L2) norm

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

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

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

Lp norm (p > 0)

Instances

Normed Double Source # 
Normed Float Source # 
Normed (Complex Double) Source # 
Normed (Complex Float) Source # 
(Normed a, (~) * (Magnitude a) (RealScalar a), (~) * (RealScalar a) (Scalar a)) => Normed (SpVector a) Source # 

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

Infinity-norm (Real)

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

Infinity-norm (Complex)

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

Lp inner product (p > 0)

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

Reciprocal

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

Scale

Matrix ring

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

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 :: * Source #

Methods

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

Matrix-matrix product

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

Matrix times matrix transpose (A B^T)

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

Matrix transpose times matrix (A^T B)

transpose :: m -> m Source #

Matrix transpose (Hermitian conjugate in the Complex case)

normFrobenius :: m -> MatrixNorm m Source #

Frobenius norm

Linear vector space

class VectorSpace v => LinearVectorSpace v where Source #

Minimal complete definition

(#>), (<#)

Associated Types

type MatrixType v :: * Source #

Methods

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

Matrix-vector action

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

Dual matrix-vector action

LinearVectorSpace + Normed

Linear systems

class LinearVectorSpace v => LinearSystem v where Source #

Minimal complete definition

(<\>)

Methods

(<\>) Source #

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

Minimal complete definition

dim

Associated Types

type FDSize f Source #

Methods

dim :: f -> FDSize f Source #

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

Instances

FiniteDim (SpVector a) Source #

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

SpVectors are finite-dimensional vectors

Associated Types

type FDSize (SpVector a) :: * Source #

Methods

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

FiniteDim (SpMatrix a) Source #

SpMatrixes are maps between finite-dimensional spaces

Associated Types

type FDSize (SpMatrix a) :: * Source #

Methods

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

HasData : accessing inner data (do not export)

class HasData f where Source #

Minimal complete definition

nnz, dat

Associated Types

type HDData f Source #

Methods

nnz :: f -> Int Source #

Number of nonzeros

dat :: f -> HDData f Source #

Instances

HasData (SpVector a) Source # 

Associated Types

type HDData (SpVector a) :: * Source #

Methods

nnz :: SpVector a -> Int Source #

dat :: SpVector a -> HDData (SpVector a) Source #

HasData (SpMatrix a) Source # 

Associated Types

type HDData (SpMatrix a) :: * Source #

Methods

nnz :: SpMatrix a -> Int Source #

dat :: SpMatrix a -> HDData (SpMatrix a) Source #

Sparse : sparse datastructures

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

Minimal complete definition

spy

Methods

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

Sparsity (fraction of nonzero elements)

Instances

Sparse (SpVector a) Source # 

Methods

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

Sparse (SpMatrix a) Source # 

Methods

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

Set : types that behave as sets

class Functor f => Set f where Source #

Minimal complete definition

liftU2, liftI2

Methods

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

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

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

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

Instances

Set SpVector Source # 

Methods

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

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

Set SpMatrix Source # 

Methods

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

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

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

class Sparse c => SpContainer c where Source #

Minimal complete definition

scInsert, scLookup, scToList, (@@)

Associated Types

type ScIx c :: * Source #

type ScElem c Source #

Methods

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

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

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

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

Instances

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 Types

type ScIx (SpVector a) :: * Source #

type ScElem (SpVector a) :: * Source #

Num a => SpContainer (SpMatrix a) Source #

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

type ScElem (SpMatrix a) :: * Source #

SparseVector

class SpContainer v => SparseVector v where Source #

Minimal complete definition

svFromList, svFromListDense, svConcat

Associated Types

type SpvIx v :: * Source #

Methods

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

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

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

SparseMatrix

class SpContainer m => SparseMatrix m where Source #

Minimal complete definition

smFromVector, smTranspose, encodeIx, decodeIx

Methods

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

smTranspose :: m -> m Source #

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

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

SparseMatVec

Utilities

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

Lift a real number onto the complex plane