Skip to content

Commit 4876eb7

Browse files
JuliaMath#3 (in part)
1 parent ef5aef4 commit 4876eb7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/KahanSummation.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ function cumsum_kbn(v::AbstractVector{T}) where T<:AbstractFloat
8686
end
8787

8888
"""
89-
sum_kbn(A)
89+
sum_kbn([f,] A)
9090
9191
Return the sum of all elements of `A`, using the Kahan-Babuska-Neumaier compensated
92-
summation algorithm for additional accuracy.
92+
summation algorithm for additional accuracy. When a function `f` is supplied, the
93+
result of calling f on each element of `A` is summed.
9394
"""
9495
function sum_kbn(A)
9596
T = @default_eltype(typeof(A))
@@ -113,4 +114,6 @@ function sum_kbn(A)
113114
s - c
114115
end
115116

117+
sum_kbn(f, A) = f.(A)
118+
116119
end # module

0 commit comments

Comments
 (0)