uxarray.utils.computing.dot_fma

Contents

uxarray.utils.computing.dot_fma#

uxarray.utils.computing.dot_fma(v1, v2)#

Calculate the dot product of two vectors using the FMA (fused multiply- add) operation.

This implementation leverages the FMA operation to provide a more accurate result. Currently the ComptDot product algorithm is used, which provides a relative error of approvimately u + n^2u^2cond(v1 dot v2), where u is 0.5 ulps, n is the length of the vectors, and cond(v1 dot v2) is the condition number of the naive dot product of v1 and v2. This operatin takes approvimately 3 + 10 * n flops, where n is the length of the vectors.

Parameters:
  • v1 (list of float) – The first vector.

  • v2 (list of float) – The second vector. Must be the same length as v1.

Returns:

The dot product of the two vectors.

Return type:

float

Raises:

ValueError – If the input vectors v1 and v2 are not of the same length.

Examples

>>> dot_fma([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])
32.0

References

S. Graillat, Ph. Langlois, and N. Louvet. “Accurate dot products with FMA.” Presented at RNC 7, 2007, Nancy, France. DALI-LP2A Laboratory, University of Perpignan, France. [Poster](https://www-pequan.lip6.fr/~graillat/papers/posterRNC7.pdf)