accelerate-blas-0.2.0.1: Numeric Linear Algebra in Accelerate

Copyright [2017] 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

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
 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 # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN CDouble) -> Exp (KBN CDouble) -> Exp (KBN CDouble) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KBN CFloat) -> Exp (KBN CFloat) -> Exp (KBN CFloat) Source # Elt a => IsProduct Elt (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype ProdRepr (KBN a) :: Type MethodsfromProd :: proxy Elt -> KBN a -> ProdRepr (KBN a)toProd :: proxy Elt -> ProdRepr (KBN a) -> KBN aprod :: proxy Elt -> KBN a -> ProdR Elt (ProdRepr (KBN a)) (Lift Exp a, Elt (Plain a)) => Lift Exp (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (KBN a) :: Type # 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 # Elt a => Elt (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodseltType :: KBN a -> TupleType (EltRepr (KBN a))fromElt :: KBN a -> EltRepr (KBN a)toElt :: EltRepr (KBN a) -> KBN a type EltRepr (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltRepr (KBN a) = (((), EltRepr a), EltRepr a) type ProdRepr (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type ProdRepr (KBN a) = (((), a), a) type Plain (KBN a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (KBN a) = KBN (Plain a)

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
 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 (KB2 CDouble) -> Exp (KB2 CDouble) -> Exp (KB2 CDouble) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (KB2 CFloat) -> Exp (KB2 CFloat) -> Exp (KB2 CFloat) Source # Elt a => IsProduct Elt (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype ProdRepr (KB2 a) :: Type MethodsfromProd :: proxy Elt -> KB2 a -> ProdRepr (KB2 a)toProd :: proxy Elt -> ProdRepr (KB2 a) -> KB2 aprod :: proxy Elt -> KB2 a -> ProdR Elt (ProdRepr (KB2 a)) (Lift Exp a, Elt (Plain a)) => Lift Exp (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (KB2 a) :: Type # 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 # Elt a => Elt (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodseltType :: KB2 a -> TupleType (EltRepr (KB2 a))fromElt :: KB2 a -> EltRepr (KB2 a)toElt :: EltRepr (KB2 a) -> KB2 a type EltRepr (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltRepr (KB2 a) = ((((), EltRepr a), EltRepr a), EltRepr a) type ProdRepr (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type ProdRepr (KB2 a) = ((((), a), a), a) type Plain (KB2 a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (KB2 a) = KB2 (Plain a)

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
 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 (Kahan CDouble) -> Exp (Kahan CDouble) -> Exp (Kahan CDouble) Source # Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Methodsadd :: Exp (Kahan CFloat) -> Exp (Kahan CFloat) -> Exp (Kahan CFloat) Source # Elt a => IsProduct Elt (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype ProdRepr (Kahan a) :: Type MethodsfromProd :: proxy Elt -> Kahan a -> ProdRepr (Kahan a)toProd :: proxy Elt -> ProdRepr (Kahan a) -> Kahan aprod :: proxy Elt -> Kahan a -> ProdR Elt (ProdRepr (Kahan a)) (Lift Exp a, Elt (Plain a)) => Lift Exp (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum Associated Typestype Plain (Kahan a) :: Type # 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 # Elt a => Elt (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum MethodseltType :: Kahan a -> TupleType (EltRepr (Kahan a))fromElt :: Kahan a -> EltRepr (Kahan a)toElt :: EltRepr (Kahan a) -> Kahan a type EltRepr (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type EltRepr (Kahan a) = (((), EltRepr a), EltRepr a) type ProdRepr (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type ProdRepr (Kahan a) = (((), a), a) type Plain (Kahan a) Source # Instance detailsDefined in Data.Array.Accelerate.Numeric.Sum type Plain (Kahan a) = Kahan (Plain a)

Return the result of a Kahan sum.