Can anyone tell me the algorithm used by the sum() function. I discovered that sum() in numpy uses the pairwise algorithm. I don’t think torch uses it or the Kahan algorithm but maybe I’m wrong. Does anyone know for sure?

The reason I’m asking is because I want to write the torch.sum() function in C. I have tried many summation algorithms that are intended to reduce the precision errors that occur when using floating point numbers: kahan (variations), pairwise, sortfirst, recursivesum, etc. None of my C programs gave the same results as torch.sum().

Should anyone want to try, here is the data set I’m using:

[ 7.8045e-05, -2.6427e-05, 1.2772e-05, 9.2774e-05, 4.3943e-05,

1.5254e-04, -1.2603e-05, -2.4027e-04, 9.0581e-06, 7.7683e-06,

-5.3032e-06, 1.3365e-04, 9.2983e-05, 8.4483e-05, 8.1089e-05,

9.9249e-05, -1.6948e-04, 3.3411e-06, -2.6907e-05, 1.1957e-04,

4.8341e-05, -2.1752e-04, 3.5117e-05, 2.0250e-04, -6.8962e-05,

-2.2960e-05, -1.5692e-04, -1.4009e-04, 1.3505e-05, -8.7326e-05,

-5.3032e-06, -1.3066e-04]

I will appreciate any ideas.