Skip to content

Commit

Permalink
Updates for Julia 1.0 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Aug 27, 2018
1 parent 1ad8910 commit 4df9429
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ language: julia
os:
- linux
julia:
- 0.6
- 1.0
- nightly
notifications:
email: false
#script: # the default script is equivalent to the following
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("KahanSummation"); Pkg.test("KahanSummation"; coverage=true)';
after_success:
- julia -e 'cd(Pkg.dir("KahanSummation")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
- julia -e 'cd(Pkg.dir("KahanSummation")); Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))';
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
- julia -e 'using Pkg; Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))';
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.6
Compat 0.33.0
julia 1.0
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ makedocs(
)

deploydocs(
julia = "0.6",
julia = "1.0",
repo = "github.com/JuliaMath/KahanSummation.jl.git",
target = "build",
deps = nothing,
Expand Down
44 changes: 9 additions & 35 deletions src/KahanSummation.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
# This file contains code that was formerly a part of Julia.
# License is MIT: https://julialang.org/license

VERSION < v"0.7.0-beta2.199" && __precompile__()

module KahanSummation

if VERSION >= v"0.7.0-DEV.3000" # TODO: More specific bound
if isdefined(Base, :sum_kbn) # Deprecated
import Base: sum_kbn, cumsum_kbn
else
export sum_kbn, cumsum_kbn
end
end

if isdefined(Base, Symbol("@default_eltype"))
using Base: @default_eltype
else
macro default_eltype(itr)
quote
Core.Inference.return_type(first, Tuple{$(esc(itr))})
end
end
end

if isdefined(Base, :promote_sys_size_add)
using Base: promote_sys_size_add
else
promote_sys_size_add(x::T) where {T} = Base.r_promote(+, zero(T)::T)
end
export sum_kbn, cumsum_kbn

"""
cumsum_kbn(A, dim::Integer)
Expand Down Expand Up @@ -67,7 +43,7 @@ end
function cumsum_kbn(v::AbstractVector{T}) where T<:AbstractFloat
r = similar(v)
isempty(v) && return r
inds = indices(v, 1)
inds = axes(v, 1)
i1 = first(inds)
s = r[i1] = v[i1]
c = zero(T)
Expand All @@ -92,16 +68,14 @@ Return the sum of all elements of `A`, using the Kahan-Babuska-Neumaier compensa
summation algorithm for additional accuracy.
"""
function sum_kbn(A)
T = @default_eltype(typeof(A))
c = promote_sys_size_add(zero(T)::T)
i = start(A)
if done(A, i)
return c
end
Ai, i = next(A, i)
T = Base.@default_eltype(A)
c = Base.reduce_empty(+, T)
it = iterate(A)
it === nothing && return c
Ai, i = it
s = Ai - c
while !(done(A, i))
Ai, i = next(A, i)
while (it = iterate(A, i)) !== nothing
Ai, i = it
t = s + Ai
if abs(s) >= abs(Ai)
c -= ((s-t) + Ai)
Expand Down
6 changes: 1 addition & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
# License is MIT: https://julialang.org/license

using KahanSummation
using Compat
using Compat.Test

# Shadow the names in Base if they're defined
import KahanSummation: sum_kbn, cumsum_kbn
using Test

@testset "cumsum_kbn" begin
v = [1,1e100,1,-1e100]*1000
Expand Down

0 comments on commit 4df9429

Please sign in to comment.