简体   繁体   中英

What is the run time complexity of pairwise summation?

I read that numpy uses pairwise summation as its default algorithm for calculating the sum (as also confirmed by one of the pull request at numpy github repository)

So for a snippet like the following and in general:

data = np.ones((1000,1000))
sum = np.sum(data)

print(sum)

What is the run time complexity of pairwise summation? Since it follows a greedy approach similar to divide and conquer , it must be on the log scale but I am not sure of the exact equation.

Pairwise summation performs exactly the same number of additions as naive summation.

If you're adding up floating point numbers, though, then a naive summation ends up adding small numbers to big numbers near the end. This causes numbers near the end to suffer larger rounding errors.

For this reason, pairwise summation would be preferred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM