From 1e462ba6f292a0e360a35c2a6a4ab99e653f50ad Mon Sep 17 00:00:00 2001 From: Marcelo Forets Date: Sat, 11 Aug 2018 07:07:48 -0300 Subject: [PATCH] Fix some 0.7 dependency warnings in function signatures Fix 0.7 depwarns in function signatures. --- src/Expokit.jl | 15 +++++++++++---- src/chbv.jl | 12 ++++++------ src/expmv.jl | 17 +++++++++-------- src/phimv.jl | 18 ++++++++++-------- test/runtests.jl | 2 +- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/Expokit.jl b/src/Expokit.jl index 1f67b92..9786d36 100644 --- a/src/Expokit.jl +++ b/src/Expokit.jl @@ -11,11 +11,18 @@ R.B. Sidje, ACM Trans. Math. Softw., 24(1):130-156, 1998 (or its """ module Expokit -using Compat -import Compat.view +using Compat, Compat.LinearAlgebra +import Compat:view, String +const LinearAlgebra = Compat.LinearAlgebra -const axpy! = Base.LinAlg.axpy! -const expm! = Base.LinAlg.expm! +if VERSION < v"0.7-" + nothing +else + using LinearAlgebra, SparseArrays +end + +const axpy! = LinearAlgebra.axpy! +const expm! = LinearAlgebra.expm! include("expmv.jl") include("padm.jl") diff --git a/src/chbv.jl b/src/chbv.jl index f9188e8..236b83d 100644 --- a/src/chbv.jl +++ b/src/chbv.jl @@ -54,13 +54,13 @@ Calculate matrix exponential acting on some vector using the Chebyshev method. This Julia implementation is based on Expokit's CHBV Matlab code by Roger B. Sidje, see below. ---- +--- y = chbv( H, x ) CHBV computes the direct action of the matrix exponential on a vector: y = exp(H) * x. It uses the partial fraction expansion of the uniform rational Chebyshev approximation of type (14,14). - About 14-digit accuracy is expected if the matrix H is symmetric + About 14-digit accuracy is expected if the matrix H is symmetric negative definite. The algorithm may behave poorly otherwise. See also PADM, EXPOKIT. @@ -68,14 +68,14 @@ Roger B. Sidje, see below. EXPOKIT: Software Package for Computing Matrix Exponentials. ACM - Transactions On Mathematical Software, 24(1):130-156, 1998 """ -function chbv{T}(A, vec::Vector{T}) +function chbv(A, vec::Vector{T}) where {T} result = convert(Vector{promote_type(eltype(A), T)}, copy(vec)) return chbv!(result, A, vec) end -chbv!{T}(A, vec::Vector{T}) = chbv!(vec, A, copy(vec)) +chbv!(A, vec::Vector{T}) where {T} = chbv!(vec, A, copy(vec)) -function chbv!{T<:Real}(w::Vector{T}, A, vec::Vector{T}) +function chbv!(w::Vector{T}, A, vec::Vector{T}) where {T<:Real} p = min(length(θ), length(α)) scale!(copy!(w, vec), α0) @inbounds for i = 1:p @@ -84,7 +84,7 @@ function chbv!{T<:Real}(w::Vector{T}, A, vec::Vector{T}) return w end -function chbv!{T<:Complex}(w::Vector{T}, A, vec::Vector{T}) +function chbv!(w::Vector{T}, A, vec::Vector{T}) where {T<:Complex} p = min(length(θ), length(α)) scale!(copy!(w, vec), α0) t = [θ; θconj] diff --git a/src/expmv.jl b/src/expmv.jl index b48a42e..7ee5f6c 100644 --- a/src/expmv.jl +++ b/src/expmv.jl @@ -24,24 +24,25 @@ using the Krylov subspace approximation. See R.B. Sidje, ACM Trans. Math. Softw., 24(1):130-156, 1998 and http://www.maths.uq.edu.au/expokit """ -function expmv{T}( t::Number, +function expmv( t::Number, A, vec::Vector{T}; tol::Real=1e-7, m::Int=min(30, size(A, 1)), - norm=Base.norm, anorm=default_anorm(A)) + norm=Base.norm, anorm=default_anorm(A)) where {T} + result = convert(Vector{promote_type(eltype(A), T, typeof(t))}, copy(vec)) expmv!(t, A, result; tol=tol, m=m, norm=norm, anorm=anorm) return result end -expmv!{T}( t::Number, +expmv!( t::Number, A, vec::Vector{T}; tol::Real=1e-7, m::Int=min(30,size(A,1)), - norm=Base.norm, anorm=default_anorm(A)) = expmv!(vec, t, A, vec; tol=tol, m=m, norm=norm, anorm=anorm) + norm=Base.norm, anorm=default_anorm(A)) where {T} = expmv!(vec, t, A, vec; tol=tol, m=m, norm=norm, anorm=anorm) -function expmv!{T}(w::Vector{T}, t::Number, A, vec::Vector{T}; - tol::Real=1e-7, m::Int=min(30,size(A,1)), norm=Base.norm, anorm=default_anorm(A)) +function expmv!(w::Vector{T}, t::Number, A, vec::Vector{T}; + tol::Real=1e-7, m::Int=min(30,size(A,1)), norm=Base.norm, anorm=default_anorm(A)) where {T} if size(vec,1) != size(A,2) error("dimension mismatch") @@ -59,8 +60,8 @@ function expmv!{T}(w::Vector{T}, t::Number, A, vec::Vector{T}; # estimate first time-step and round to two significant digits beta = norm(vec) r = 1/m - fact = (((m+1)/exp(1.))^(m+1))*sqrt(2.*pi*(m+1)) - tau = (1./anorm)*((fact*tol)/(4.*beta*anorm))^r + fact = (((m+1)/exp(1.0))^(m+1))*sqrt(2.0*pi*(m+1)) + tau = (1.0/anorm)*((fact*tol)/(4.0*beta*anorm))^r tau = signif(tau, 2) # storage for Krylov subspace vectors diff --git a/src/phimv.jl b/src/phimv.jl index 6b68cf2..091ea6d 100644 --- a/src/phimv.jl +++ b/src/phimv.jl @@ -1,7 +1,7 @@ export phimv, phimv! """ - phimv{T}(t, A, u, vec; [tol], [m], [norm]) + phimv{T}(t, A, u, vec; [tol], [m], [norm], [anorm]) Calculate the solution of a nonhomogeneous linear ODE problem with constant input ``w = e^{tA}v + tφ(tA)u`` using the Krylov subspace approximation. @@ -31,24 +31,26 @@ Calculate the solution of a nonhomogeneous linear ODE problem with constant inpu EXPOKIT: Software Package for Computing Matrix Exponentials. ACM - Transactions On Mathematical Software, 24(1):130-156, 1998 """ -function phimv{T}( t::Number, + +function phimv( t::Number, A, u::Vector{T}, vec::Vector{T}; tol::Real=1e-7, m::Int=min(30, size(A, 1)), - norm=Base.norm, anorm=default_anorm(A)) + norm=Base.norm, anorm=default_anorm(A)) where {T} + result = convert(Vector{promote_type(eltype(A), T, typeof(t))}, copy(vec)) phimv!(t, A, u, result; tol=tol, m=m, norm=norm, anorm=anorm) return result end -phimv!{T}( t::Number, +phimv!( t::Number, A, u::Vector{T}, vec::Vector{T}; tol::Real=1e-7, m::Int=min(30, size(A, 1)), - norm=Base.norm, anorm=default_anorm(A)) = phimv!(vec, t, A, u, vec; tol=tol, m=m, norm=norm, anorm=anorm) + norm=Base.norm, anorm=default_anorm(A)) where {T} = phimv!(vec, t, A, u, vec; tol=tol, m=m, norm=norm, anorm=anorm) -function phimv!{T}( w::Vector{T}, t::Number, A, u::Vector{T}, vec::Vector{T}; - tol::Real=1e-7, m::Int=min(30, size(A, 1)), norm=Base.norm, anorm=default_anorm(A)) +function phimv!( w::Vector{T}, t::Number, A, u::Vector{T}, vec::Vector{T}; + tol::Real=1e-7, m::Int=min(30, size(A, 1)), norm=Base.norm, anorm=default_anorm(A)) where {T} if size(vec, 1) != size(A, 2) error("dimension mismatch") @@ -67,7 +69,7 @@ function phimv!{T}( w::Vector{T}, t::Number, A, u::Vector{T}, vec::Vector{T}; beta = norm(A*vec + u) r = 1/m fact = (((m+1)/exp(1))^(m+1))*sqrt(2*pi*(m+1)) - tau = (1./anorm)*((fact*tol)/(4.*beta*anorm))^r + tau = (1.0/anorm)*((fact*tol)/(4.0*beta*anorm))^r tau = signif(tau, 2) # storage for Krylov subspace vectors diff --git a/test/runtests.jl b/test/runtests.jl index 4478186..489d1de 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Expokit -using Base.Test +using Compat.Test struct LinearOp m