Skip to content

Commit 78ae1ac

Browse files
committed
upgrade for v0.7 and improve code
1 parent dfb21f5 commit 78ae1ac

File tree

14 files changed

+212
-200
lines changed

14 files changed

+212
-200
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.6
7-
# - nightly
6+
- 0.7
7+
- nightly
88
notifications:
99
email: false
1010
after_success:
11-
- julia -e 'Pkg.add("Documenter")'
12-
- julia -e 'cd(Pkg.dir("InverseLaplace")); include(joinpath("docs", "make.jl"))'
1311
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("InverseLaplace")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The InverseLaplace.jl package is licensed under the MIT "Expat" License:
22

3-
> Copyright (c) 2015 2016: John Lapeyre.
3+
> Copyright (c) 2015-2018: John Lapeyre.
44
>
55
> Permission is hereby granted, free of charge, to any person obtaining
66
> a copy of this software and associated documentation files (the

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://jlapeyre.github.io/InverseLaplace.jl/latest)
66
Linux, OSX: [![Build Status](https://travis-ci.org/jlapeyre/InverseLaplace.jl.svg)](https://travis-ci.org/jlapeyre/InverseLaplace.jl)   Windows: [![Build Status](https://ci.appveyor.com/api/projects/status/github/jlapeyre/InverseLaplace.jl?branch=master&svg=true)](https://ci.appveyor.com/project/jlapeyre/inverselaplace-jl)       [![Coverage Status](https://coveralls.io/repos/github/jlapeyre/InverseLaplace.jl/badge.svg?branch=master)](https://coveralls.io/github/jlapeyre/InverseLaplace.jl?branch=master) [![codecov](https://codecov.io/gh/jlapeyre/InverseLaplace.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jlapeyre/InverseLaplace.jl)
77

8-
98
This implements some numerical methods for computing inverse Laplace transforms in Julia.
109

10+
InverseLaplace v0.1.0 is the last version that supports Julia v0.6
11+
1112
See the documentation https://jlapeyre.github.io/InverseLaplace.jl/latest .
1213

1314
Note: A small part of `InverseLaplace.jl` depends on `Optim.jl`, which is currently
14-
broken on Julia v0.7. So `InverseLaplace.jl` is broken on Julia v0.7.
15-
15+
broken on Julia v0.7. So optimization is disabled for `InverseLaplace.jl` versions
16+
greater than v0.1.0
1617

17-
Note: the last version of this module supporting Julia v0.4 is tagged v0.0.2
18+
Note: the last version of this module supporting Julia v0.4 is tagged v0.0.2.
19+
the last version of this module supporting Julia v0.6 is tagged v0.1.0.

REQUIRE

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
julia 0.6
2-
Optim
3-
Compat 0.17.0
1+
julia 0.7-beta
2+
SpecialFunctions
3+
# Optim
4+
AbstractFFTs
5+
FFTW

appveyor.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
environment:
22
matrix:
3-
- JULIAVERSION: "julialang/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIAVERSION: "julialang/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
# - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
6-
# - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
5+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
77

88
branches:
99
only:
@@ -17,9 +17,15 @@ notifications:
1717
on_build_status_changed: false
1818

1919
install:
20+
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
21+
# If there's a newer build queued for the same PR, cancel this one
22+
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
23+
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
24+
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
25+
throw "There are newer queued builds for this pull request, failing early." }
2026
# Download most recent Julia Windows binary
2127
- ps: (new-object net.webclient).DownloadFile(
22-
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
28+
$env:JULIA_URL,
2329
"C:\projects\julia-binary.exe")
2430
# Run installer silently, output to C:\projects\julia
2531
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
@@ -31,4 +37,4 @@ build_script:
3137
Pkg.clone(pwd(), \"InverseLaplace\"); Pkg.build(\"InverseLaplace\")"
3238

3339
test_script:
34-
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"InverseLaplace\")"
40+
- C:\projects\julia\bin\julia -e "Pkg.test(\"InverseLaplace\")"

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
The source repository is [https://github.com/jlapeyre/InverseLaplace.jl](https://github.com/jlapeyre/InverseLaplace.jl).
66

77
This package provides three numerical algorithms for numerically inverting Laplace transforms.
8+
InverseLaplace v0.1.0 is the last version that supports Julia v0.6.
9+
Optimization of the Weeks method is temporarily disabled for Julia v0.7.
810

911
## Contents
1012

src/InverseLaplace.jl

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
VERSION >= v"0.4.0-dev+6521" && __precompile__()
1+
__precompile__()
22

33
module InverseLaplace
44

5-
using Compat
6-
5+
import SpecialFunctions
76
# I have to export everything in order for Documenter.jl to find
87
# the strings. A few hours of work would probably be enough to solve the problem.
98
export ILt, setNterms
10-
export Weeks, WeeksErr, optimize, opteval, setparameters
9+
# export optimize, opteval # Broken at the moment
10+
export Weeks, WeeksErr, setparameters
1111
export Talbot, GWR, ILT
1212
export TransformPair, ILtPair, abserr, iltpair_power
1313
export ilt, talbot, gwr
1414

15-
@compat abstract type AbstractILt end
15+
abstract type AbstractILt end
1616

1717
"""
1818
ft::Talbot = Talbot(func::Function, Nterms::Integer=32)
1919
2020
return `ft`, which estimates the inverse Laplace transform of `func` with
2121
the fixed Talbot algorithm. `ft(t)` evaluates the transform at `t`. You may
22-
want to tune `Nterms` together with `setprecision(BigFloat,x)`.
22+
want to tune `Nterms` together with `setprecision(BigFloat, x)`.
2323
2424
# Example
2525
2626
Compute the inverse transform of the transform of `cos` at argument `pi/2`.
2727
```julia-repl
28-
julia> ft = Talbot(s -> s/(s^2+1), 80);
28+
julia> ft = Talbot(s -> s/(s^2 + 1), 80);
2929
3030
julia> ft(pi/2)
3131
-3.5366510684573195e-5
@@ -42,12 +42,13 @@ julia> Float64(ft(big(pi)/2))
4242
function for complex arguments. The GWR method is, in general, less accurate and
4343
less stable, but does not evaluate the Laplace transform function for complex arguments.
4444
"""
45-
type Talbot{T<:Base.Callable} <: AbstractILt
46-
LSfunc::T # Laplace space function
45+
struct Talbot{T<:Base.Callable} <: AbstractILt
46+
Laplace_space_func::T # Laplace space function
4747
Nterms::Int
4848
end
4949

50-
Talbot(LSfunc::Base.Callable) = Talbot(LSfunc,32)
50+
const talbot_default_num_terms = 32
51+
Talbot(Laplace_space_func::Base.Callable) = Talbot(Laplace_space_func, talbot_default_num_terms)
5152

5253
"""
5354
ft::GWR = GWR(func::Function, Nterms::Integer=16)
@@ -59,18 +60,19 @@ the GWR algorithm. `ft(t)` evaluates the transform at `t`.
5960
6061
Compute the inverse transform of the transform of `cos` at argument `pi/2`.
6162
```
62-
julia> ft = GWR(s -> s/(s^2+1), 16);
63+
julia> ft = GWR(s -> s/(s^2 + 1), 16);
6364
6465
julia> ft(pi/2)
6566
-0.001
6667
```
6768
"""
68-
type GWR{T<:Base.Callable} <: AbstractILt
69-
LSfunc::T # Laplace space function
69+
struct GWR{T<:Base.Callable} <: AbstractILt
70+
Laplace_space_func::T # Laplace space function
7071
Nterms::Int
7172
end
7273

73-
GWR(LSfunc::Base.Callable) = GWR(LSfunc,16)
74+
const gwr_default_num_terms = 16
75+
GWR(Laplace_space_func::Base.Callable) = GWR(Laplace_space_func, gwr_default_num_terms)
7476

7577
"""
7678
ILT(function, Nterms=32)
@@ -80,14 +82,13 @@ This is an alias for the default `Talbot()` method.
8082
ILT(args...) = Talbot(args...)
8183

8284
function Base.show(io::IO, ailt::AbstractILt)
83-
print(io, string(typeof(ailt)), "(Nterms=", ailt.Nterms,')')
85+
print(io, string(typeof(ailt)), "(Nterms=", ailt.Nterms, ')')
8486
end
8587

8688
# TODO get rid of this in favor of above.
8789
# Rely on broadcasting, as well.
88-
89-
type ILt{T<:Base.Callable, V<:Base.Callable} <: AbstractILt
90-
LSfunc::T
90+
struct ILt{T<:Base.Callable, V<:Base.Callable} <: AbstractILt
91+
Laplace_space_func::T
9192
iltfunc::V
9293
Nterms::Int
9394
end
@@ -109,7 +110,7 @@ of `32` may give extremely inaccurate estimates.
109110
## Example
110111
111112
```julia
112-
julia> itr = ILt( s -> 1/(1+s^2), talbot);
113+
julia> itr = ILt( s -> 1/(1 + s^2), talbot);
113114
114115
julia> itr([ pi/4, pi/2, 3*pi/4, -pi])
115116
4-element Array{Float64,1}:
@@ -119,7 +120,7 @@ julia> itr([ pi/4, pi/2, 3*pi/4, -pi])
119120
-3.66676e-12
120121
```
121122
"""
122-
ILt(func,iltfunc) = ILt(func, iltfunc, 32)
123+
ILt(func, iltfunc) = ILt(func, iltfunc, talbot_default_num_terms)
123124

124125
# Make this the default
125126
"""
@@ -128,8 +129,7 @@ ILt(func,iltfunc) = ILt(func, iltfunc, 32)
128129
`ilt` is an alias for the default inverse Laplace transform method `talbot`.
129130
"""
130131
ilt(args...) = talbot(args...)
131-
ILt(func) = ILt(func, talbot, 32)
132-
132+
ILt(func) = ILt(func, talbot, talbot_default_num_terms)
133133

134134
"""
135135
setNterms(ailt::AbstractILt, Nterms::Integer)
@@ -140,18 +140,19 @@ calls `ailt(t)` reflect the new value of `Nterms`.
140140
"""
141141
setNterms(ailt::AbstractILt, N::Integer) = (ailt.Nterms = N)
142142

143-
(ailt::ILt)(t) = ailt.iltfunc(ailt.LSfunc, t, ailt.Nterms)
144-
(ailt::ILt)(t,N) = ailt.iltfunc(ailt.LSfunc, t, N)
143+
## Make the ILT data types callable.
144+
(ailt::ILt)(t) = ailt.iltfunc(ailt.Laplace_space_func, t, ailt.Nterms)
145+
(ailt::ILt)(t,N) = ailt.iltfunc(ailt.Laplace_space_func, t, N)
145146

146-
(ailt::Talbot)(t) = talbot(ailt.LSfunc, t, ailt.Nterms)
147-
(ailt::Talbot)(t, n::Integer) = talbot(ailt.LSfunc, t, n)
147+
(ailt::Talbot)(t) = talbot(ailt.Laplace_space_func, t, ailt.Nterms)
148+
(ailt::Talbot)(t, n::Integer) = talbot(ailt.Laplace_space_func, t, n)
148149

149-
(ailt::GWR)(t) = gwr(ailt.LSfunc, t, ailt.Nterms)
150-
(ailt::GWR)(t, n::Integer) = gwr(ailt.LSfunc, t, n)
150+
(ailt::GWR)(t) = gwr(ailt.Laplace_space_func, t, ailt.Nterms)
151+
(ailt::GWR)(t, n::Integer) = gwr(ailt.Laplace_space_func, t, n)
151152

152153
include("fixed_talbot.jl")
153154
include("gwr.jl")
154155
include("weeks.jl")
155-
include("test.jl")
156+
include("pairtest.jl")
156157

157158
end # module

src/fixed_talbot.jl

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
# Fixed Talbot method
2+
#
13
# Abate, J. and Valkó, P.P.
24
# Multi-precision Laplace transform inversion
35
# International Journal for Numerical Methods in Engineering, Vol. 60 (Iss. 5-7) 2004 pp 979–993
4-
# Fixed Talbot method
56

67
"""
7-
talbot(func::Function, t::AbstractFloat, M::Integer=32)
8+
talbot(func::Function, t::AbstractFloat, M::Integer=talbot_default_num_terms)
89
910
Evaluate the inverse Laplace transform of `func` at the point `t`. Use `M` terms in the algorithm.
1011
For `typeof(t)` is `Float64`, the default for `M` is `32`. For `BigFloat` the default is `64`.
@@ -14,38 +15,38 @@ If `BigFloat` precision is larger than default, try increasing `M`. `talbot is v
1415
# Example
1516
1617
```jldoctest
17-
julia> InverseLaplace.talbot( s -> 1/s^3, 3)
18+
julia> InverseLaplace.talbot( s -> 1/s^3, 3)
1819
4.50000000000153
1920
```
2021
2122
!!! note
2223
This function uses the fixed Talbot method. It evaluates `func` for complex arguments.
2324
"""
2425
function talbot(func, t, M)
25-
bM = convert(typeof(t),M)
26-
r = (2 * bM) / (5*t)
27-
term = (1//2) * exp(r*t) * func(r)
26+
bM = convert(typeof(t), M)
27+
r = (2 * bM) / (5 * t)
28+
term = (1//2) * exp(r * t) * func(r)
2829
for i in 1:M-1
2930
theta = i * (pi/bM)
30-
s = r*theta*(complex(cot(theta),one(theta)))
31-
sigma = theta + (theta*cot(theta)-1)*cot(theta)
32-
term += real(exp(t*s) * complex(one(t),sigma) * func(s))
31+
s = r * theta * (complex(cot(theta), one(theta)))
32+
sigma = theta + (theta * cot(theta) - 1) * cot(theta)
33+
term += real(exp(t * s) * complex(one(t), sigma) * func(s))
3334
end
34-
return term * 2 / (5*t)
35+
return term * 2 / (5 * t)
3536
end
3637

37-
talbot(func,t) = talbot(func,t,32)
38-
talbot(func,t::BigFloat) = talbot(func,t,64)
39-
talbot(func,t::Integer,args...) = talbot(func,BigFloat(t),args...)
38+
talbot(func, t) = talbot(func, t, talbot_default_num_terms)
39+
const talbot_BigFloat_default_num_terms = 64
40+
talbot(func, t::BigFloat) = talbot(func, t, talbot_BigFloat_default_num_terms)
41+
talbot(func, t::Integer, args...) = talbot(func, BigFloat(t), args...)
4042
# Hmm, at some point, one of these routines actually gave a Rational result. Don't recall how.
4143
# But, it can't be talbot.
42-
talbot(func,t::Rational,args...) = talbot(func,BigFloat(t),args...)
44+
talbot(func, t::Rational, args...) = talbot(func, BigFloat(t), args...)
4345

4446
# Operate on an array of values of t. A single function evaluation
4547
# f(s) is used for all t
4648
# This gives more inaccurate results the further values of
4749
# t are from tmax
48-
4950
"""
5051
talbotarr(func, ta::AbstractArray, M)
5152
@@ -56,31 +57,28 @@ than a vectorized application of `talbot`, but is in general, less accurate.
5657
"""
5758
function talbotarr(func, t::AbstractArray, M)
5859
tt = typeof(t[1])
59-
bM = convert(tt,M)
60+
bM = convert(tt, M)
6061
terms = similar(t)
6162
tmax = maximum(t)
62-
r = (2 * bM) / (5*tmax)
63+
r = (2 * bM) / (5 * tmax)
6364
fr = (1//2) * func(r)
6465
for j in 1:length(terms)
65-
terms[j] = exp(r*t[j]) * fr
66+
terms[j] = exp(r * t[j]) * fr
6667
end
6768
for i in 1:M-1
6869
theta = i * (pi/bM)
69-
s = r*theta*(complex(cot(theta),one(theta)))
70-
sigma = theta + (theta*cot(theta)-1)*cot(theta)
71-
fs = complex(one(tt),sigma) * func(s)
70+
s = r * theta * (complex(cot(theta), one(theta)))
71+
sigma = theta + (theta * cot(theta) - 1) * cot(theta)
72+
fs = complex(one(tt), sigma) * func(s)
7273
for j in 1:length(terms)
73-
terms[j] += real(exp(t[j]*s) * fs)
74+
terms[j] += real(exp(t[j] * s) * fs)
7475
end
7576
end
7677
for j in 1:length(terms)
77-
terms[j] *= 2/(5*tmax)
78+
terms[j] *= 2/(5 * tmax)
7879
end
7980
return terms
8081
end
8182

82-
talbotarr(func,t::AbstractArray) = talbotarr(func,t,32)
83-
talbotarr(func,t::Vector{BigFloat}) = talbotarr(func,t,64)
84-
#talbotarr(func,t::T) = talbotarr(func,t,64) where T <: AbstractArray{V} where V <: BigFloat
85-
86-
####
83+
talbotarr(func, t::AbstractArray) = talbotarr(func, t, talbot_default_num_terms)
84+
talbotarr(func, t::Vector{BigFloat}) = talbotarr(func, t, talbot_BigFloat_default_num_terms)

0 commit comments

Comments
 (0)