accelerate-blas-0.3.0.0: Numeric Linear Algebra in Accelerate
Copyright [2017..2020] Trevor L. McDonell BSD3 Trevor L. McDonell experimental non-portable (GHC extensions) None Haskell2010

Data.Array.Accelerate.Numeric.Sum

Description

Functions for summing floating point numbers more accurately than the straightforward sum operation.

In the worst case, the sum function accumulates error at a rate proportional to the number of values being summed. The algorithms in this module implement different methods of compensated summation, which reduce the accumulation of numeric error so that it grows much more slowly than the number of inputs (e.g. logarithmically), or remains constant.

Synopsis

# Summation type class

class (Elt a, Elt (s a)) => Summation s a where Source #

A class for the summation of floating-point numbers

Methods

add :: Exp (s a) -> Exp (s a) -> Exp (s a) Source #

Add a value to the sum

zero :: Exp (s a) Source #

The identity of the summation

into :: Proxy s -> Exp a -> Exp (s a) Source #

Insert a value into the summation

from :: Proxy s -> Exp (s a) -> Exp a Source #

Summarise the result of summation

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (Kahan Double) -> Exp (Kahan Double) -> Exp (Kahan Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (Kahan Float) -> Exp (Kahan Float) -> Exp (Kahan Float) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KB2 Double) -> Exp (KB2 Double) -> Exp (KB2 Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KB2 Float) -> Exp (KB2 Float) -> Exp (KB2 Float) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN Double) -> Exp (KBN Double) -> Exp (KBN Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN Float) -> Exp (KBN Float) -> Exp (KBN Float) Source #

sum :: (Summation s a, Shape sh) => Proxy s -> Acc (Array (sh :. Int) a) -> Acc (Array sh a) Source #

Sum an array using a particular compensation scheme.

>>> let xs = [1.0, 1.0e100, 1.0, -1.0e100] :: [Double]
>>> Prelude.sum xs
0.0

>>> let ys = fromList (Z:.4) [1.0, 1.0e100, 1.0, -1.0e100] :: Vector Double
>>> sum kbn (use ys)
Scalar Z [2.0]


# Kahan-Babuška-Neumaier summation

data KBN a Source #

Kahan-Babuška-Neumaier summation. This is a little more computationally costly than plain Kahan summation, but is always at least as accurate.

Constructors

 KBN a a

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN Double) -> Exp (KBN Double) -> Exp (KBN Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN Float) -> Exp (KBN Float) -> Exp (KBN Float) Source # (Lift Exp a, Elt (Plain a)) => Lift Exp (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (KBN a) # Methodslift :: KBN a -> Exp (Plain (KBN a)) # Elt a => Unlift Exp (KBN (Exp a)) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsunlift :: Exp (Plain (KBN (Exp a))) -> KBN (Exp a) # Show a => Show (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodsshowsPrec :: Int -> KBN a -> ShowS #show :: KBN a -> String #showList :: [KBN a] -> ShowS # Generic (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Rep (KBN a) :: Type -> Type # Methodsfrom :: KBN a -> Rep (KBN a) x #to :: Rep (KBN a) x -> KBN a # Elt a => Elt (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype EltR (KBN a) MethodseltR :: TypeR (EltR (KBN a))tagsR :: [TagR (EltR (KBN a))]fromElt :: KBN a -> EltR (KBN a)toElt :: EltR (KBN a) -> KBN a type Rep (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Rep (KBN a) = D1 ('MetaData "KBN" "Data.Array.Accelerate.Numeric.Sum" "accelerate-blas-0.3.0.0-IRq6DVbbLwW1AzZhg3bG28" 'False) (C1 ('MetaCons "KBN" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) type EltR (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltR (KBN a) = GEltR () (Rep (KBN a)) type Plain (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (KBN a) = KBN (Plain a)

pattern KBN_ :: Elt a => Exp a -> Exp a -> Exp (KBN a) Source #

Return the result of a Kahan-Babuška-Neumaier sum.

# Order-2 Kahan-Babuška summation

data KB2 a Source #

Second-order Kahan-Babuška summation. This is more computationally costly than Kahan-Babuška-Neumaier summation. Its advantage is that it can lose less precision (in admittedly obscure cases).

This method compensates for error in both the sum and the first-order compensation term, hence the use of "second order" in the name.

Constructors

 KB2 a a a

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KB2 Double) -> Exp (KB2 Double) -> Exp (KB2 Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KB2 Float) -> Exp (KB2 Float) -> Exp (KB2 Float) Source # (Lift Exp a, Elt (Plain a)) => Lift Exp (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (KB2 a) # Methodslift :: KB2 a -> Exp (Plain (KB2 a)) # Elt a => Unlift Exp (KB2 (Exp a)) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsunlift :: Exp (Plain (KB2 (Exp a))) -> KB2 (Exp a) # Show a => Show (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodsshowsPrec :: Int -> KB2 a -> ShowS #show :: KB2 a -> String #showList :: [KB2 a] -> ShowS # Generic (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Rep (KB2 a) :: Type -> Type # Methodsfrom :: KB2 a -> Rep (KB2 a) x #to :: Rep (KB2 a) x -> KB2 a # Elt a => Elt (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype EltR (KB2 a) MethodseltR :: TypeR (EltR (KB2 a))tagsR :: [TagR (EltR (KB2 a))]fromElt :: KB2 a -> EltR (KB2 a)toElt :: EltR (KB2 a) -> KB2 a type Rep (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Rep (KB2 a) = D1 ('MetaData "KB2" "Data.Array.Accelerate.Numeric.Sum" "accelerate-blas-0.3.0.0-IRq6DVbbLwW1AzZhg3bG28" 'False) (C1 ('MetaCons "KB2" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))) type EltR (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltR (KB2 a) = GEltR () (Rep (KB2 a)) type Plain (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (KB2 a) = KB2 (Plain a)

pattern KB2_ :: Elt a => Exp a -> Exp a -> Exp a -> Exp (KB2 a) Source #

Return the result of a second-order Kahan-Babuška sum.

# Kahan summation

data Kahan a Source #

Kahan summation. This is the least accurate of the compensated summation methods. This summation method is included only for completeness.

Constructors

 Kahan a a

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (Kahan Double) -> Exp (Kahan Double) -> Exp (Kahan Double) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (Kahan Float) -> Exp (Kahan Float) -> Exp (Kahan Float) Source # (Lift Exp a, Elt (Plain a)) => Lift Exp (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (Kahan a) # Methodslift :: Kahan a -> Exp (Plain (Kahan a)) # Elt a => Unlift Exp (Kahan (Exp a)) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsunlift :: Exp (Plain (Kahan (Exp a))) -> Kahan (Exp a) # Show a => Show (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodsshowsPrec :: Int -> Kahan a -> ShowS #show :: Kahan a -> String #showList :: [Kahan a] -> ShowS # Generic (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Rep (Kahan a) :: Type -> Type # Methodsfrom :: Kahan a -> Rep (Kahan a) x #to :: Rep (Kahan a) x -> Kahan a # Elt a => Elt (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype EltR (Kahan a) MethodseltR :: TypeR (EltR (Kahan a))tagsR :: [TagR (EltR (Kahan a))]fromElt :: Kahan a -> EltR (Kahan a)toElt :: EltR (Kahan a) -> Kahan a type Rep (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Rep (Kahan a) = D1 ('MetaData "Kahan" "Data.Array.Accelerate.Numeric.Sum" "accelerate-blas-0.3.0.0-IRq6DVbbLwW1AzZhg3bG28" 'False) (C1 ('MetaCons "Kahan" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) type EltR (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltR (Kahan a) = GEltR () (Rep (Kahan a)) type Plain (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (Kahan a) = Kahan (Plain a)

pattern Kahan_ :: Elt a => Exp a -> Exp a -> Exp (Kahan a) Source #

Return the result of a Kahan sum.