Created
October 12, 2023 03:24
-
-
Save marii-moe/c168f287b75438c468c7da4c9d653b18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kahan_sum(xs): | |
sum=np.array(0.,dtype=np.float16) | |
prev_sum=np.array(0.,dtype=np.float16) | |
ε=np.array(0.,dtype=np.float16) | |
for x in xs: | |
v=x-ε | |
prev_sum=sum | |
sum+=v #prev_sum+x-ε+new_ε | |
ε=sum-prev_sum-v #(prev_sum+x-ε+new_ε)-(prev_sum)-(x-ε)=new_ε | |
return sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new errors are generated on adding sum and a new x