Class LinearCombinations.DotK
- java.lang.Object
-
- org.apache.commons.numbers.examples.jmh.core.LinearCombinations.BaseLinearCombination
-
- org.apache.commons.numbers.examples.jmh.core.LinearCombinations.DotK
-
- All Implemented Interfaces:
LinearCombination.FourD,LinearCombination.ND,LinearCombination.ThreeD,LinearCombination.TwoD
- Enclosing class:
- LinearCombinations
public static final class LinearCombinations.DotK extends LinearCombinations.BaseLinearCombination implements LinearCombination.TwoD, LinearCombination.ThreeD, LinearCombination.FourD
Computes linear combinations accurately using the DotK algorithm of Ogita et al for K-fold precision of the sum.It is based on the 2005 paper Accurate Sum and Dot Product by Takeshi Ogita, Siegfried M. Rump, and Shin'ichi Oishi published in SIAM J. Sci. Comput.
Note: It is possible to use this class to compute 2-fold precision. In this case the round-off parts of the dot-product are stored in an array and summed. The
LinearCombinations.Dot2sclass provides an alternative faster implementation that sums the round-off parts during processing to avoid array allocation overhead. The results will not be identical due to a different order for the summation of the round-off parts.The number of operations will scale with
k. When computing the small linear combinationsLinearCombination.TwoD,LinearCombination.ThreeDandLinearCombination.FourDusing akvalue too large will result in more operations than the number used byLinearCombinations.ExtendedPrecision. For a smalln-dimension linear combinations the valuek = n+1will have the same number of operations asLinearCombinations.ExtendedPrecisionand users should switch to theLinearCombinations.ExtendedPrecisionclass. For example 3D combinations should usekup to 3 or else switch to usingLinearCombinations.ExtendedPrecision. This rule does not apply to theNDimplementations asLinearCombinations.ExtendedPrecisioneliminates redundant operations on zeros. In this case equivalent performance will be observed whenk <= n+1. Choice of implementation must consider performance and accuracy on real-world data.
-
-
Field Summary
Fields Modifier and Type Field Description static LinearCombinations.DotKDOT_3An instance computing 3-fold precision.static LinearCombinations.DotKDOT_4An instance computing 4-fold precision.static LinearCombinations.DotKDOT_5An instance computing 5-fold precision.static LinearCombinations.DotKDOT_6An instance computing 6-fold precision.static LinearCombinations.DotKDOT_7An instance computing 7-fold precision.
-
Constructor Summary
Constructors Constructor Description DotK(int k)Instantiates a new dot K.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doublecomputeValue(double[] a, double[] b)Compute the sum of the products of two sequences of factors with high accuracy.doublevalue(double a1, double b1, double a2, double b2)Compute the sum of the products of two sequences of factors.doublevalue(double a1, double b1, double a2, double b2, double a3, double b3)Compute the sum of the products of two sequences of factors.doublevalue(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4)Compute the sum of the products of two sequences of factors.-
Methods inherited from class org.apache.commons.numbers.examples.jmh.core.LinearCombinations.BaseLinearCombination
value
-
-
-
-
Field Detail
-
DOT_3
public static final LinearCombinations.DotK DOT_3
An instance computing 3-fold precision.
-
DOT_4
public static final LinearCombinations.DotK DOT_4
An instance computing 4-fold precision.
-
DOT_5
public static final LinearCombinations.DotK DOT_5
An instance computing 5-fold precision.
-
DOT_6
public static final LinearCombinations.DotK DOT_6
An instance computing 6-fold precision.
-
DOT_7
public static final LinearCombinations.DotK DOT_7
An instance computing 7-fold precision.
-
-
Method Detail
-
computeValue
protected double computeValue(double[] a, double[] b)Compute the sum of the products of two sequences of factors with high accuracy. The input arrays will have a length of at least 2; the lengths will be the same.- Specified by:
computeValuein classLinearCombinations.BaseLinearCombination- Parameters:
a- Factors.b- Factors.- Returns:
- \( \sum_i a_i b_i \).
-
value
public double value(double a1, double b1, double a2, double b2)Compute the sum of the products of two sequences of factors.- Specified by:
valuein interfaceLinearCombination.TwoD- Parameters:
a1- First factor of the first term.b1- Second factor of the first term.a2- First factor of the second term.b2- Second factor of the second term.- Returns:
- \( a_1 b_1 + a_2 b_2 \)
-
value
public double value(double a1, double b1, double a2, double b2, double a3, double b3)Compute the sum of the products of two sequences of factors.- Specified by:
valuein interfaceLinearCombination.ThreeD- Parameters:
a1- First factor of the first term.b1- Second factor of the first term.a2- First factor of the second term.b2- Second factor of the second term.a3- First factor of the third term.b3- Second factor of the third term.- Returns:
- \( a_1 b_1 + a_2 b_2 + a_3 b_3 \)
-
value
public double value(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4)Compute the sum of the products of two sequences of factors.- Specified by:
valuein interfaceLinearCombination.FourD- Parameters:
a1- First factor of the first term.b1- Second factor of the first term.a2- First factor of the second term.b2- Second factor of the second term.a3- First factor of the third term.b3- Second factor of the third term.a4- First factor of the fourth term.b4- Second factor of the fourth term.- Returns:
- \( a_1 b_1 + a_2 b_2 + a_3 b_3 + a_4 b_4 \)
-
-