Skip to content

Commit

Permalink
Make the dimension argument to cumsum_kbn a keyword argument (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jan 4, 2021
1 parent a862dc0 commit d019625
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/KahanSummation.jl
Expand Up @@ -6,17 +6,15 @@ module KahanSummation
export sum_kbn, cumsum_kbn

"""
cumsum_kbn(A, dim::Integer)
cumsum_kbn(A; dims::Integer)
Cumulative sum along a dimension, using the Kahan-Babuska-Neumaier compensated summation
algorithm for additional accuracy.
"""
function cumsum_kbn(A::AbstractArray{T}, axis::Integer) where T<:AbstractFloat
dimsA = size(A)
ndimsA = ndims(A)
axis_size = dimsA[axis]
function cumsum_kbn(A::AbstractArray{T}; dims::Integer) where T<:AbstractFloat
axis_size = size(A, dims)
axis_stride = 1
for i = 1:(axis-1)
for i = 1:dims-1
axis_stride *= size(A, i)
end
axis_size <= 1 && return A
Expand Down Expand Up @@ -87,4 +85,8 @@ function sum_kbn(A)
s - c
end

### Deprecations

Base.@deprecate cumsum_kbn(A, axis) cumsum_kbn(A, dims=axis)

end # module
2 changes: 1 addition & 1 deletion test/runtests.jl
Expand Up @@ -16,7 +16,7 @@ using Test

A = [v reverse(v) v2 reverse(v2)]

c = cumsum_kbn(A, 1)
c = cumsum_kbn(A, dims=1)

@test isequal(c[:,1], cv)
@test isequal(c[:,3], cv2)
Expand Down

0 comments on commit d019625

Please sign in to comment.