Skip to content

sum_kbn(fn, A) (issue 3, in part) #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/KahanSummation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ function sum_kbn(A)
s - c
end

sum_kbn(f, A) = f.(A)
function sum_kbn(f,A)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge the two functions? i.e. define sum_kbn(A) = sum_kbn(identity, A)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is that done? how should I modify latest PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh -- I see~

T = @default_eltype(typeof(A))
c = promote_sys_size_add(zero(T)::T)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to apply the function here as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong type. The output of f might not match the eltype of A.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does one obtain the f mapped eltype from eltype(A)?

i = start(A)
if done(A, i)
return c
end
Ai, i = next(A, i)
s = f(Ai) - c
while !(done(A, i))
Ai, i = next(A, i)
fAi = f(Ai); t = s + fAi
if abs(s) >= abs(fAi)
c -= ((s-t) + fAi)
else
c -= ((fAi-t) + s)
end
s = t
end
s - c
end

end # module