-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from 1 commit
ef5aef4
4876eb7
32b1e76
863d46c
d345164
ee5abb3
423929c
3d93013
733f0ea
f8915eb
39bc274
ad48228
03c5bc2
cbbcbcc
5cbd33a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,26 @@ function sum_kbn(A) | |
s - c | ||
end | ||
|
||
sum_kbn(f, A) = f.(A) | ||
function sum_kbn(f,A) | ||
T = @default_eltype(typeof(A)) | ||
c = promote_sys_size_add(zero(T)::T) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to apply the function here as well There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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)
?There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh -- I see~