Skip to content

Commit bb345cb

Browse files
authored
type assertion in convert (#87)
1 parent fa98e6b commit bb345cb

17 files changed

+51
-49
lines changed

src/ApproxFunOrthogonalPolynomials.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ points(d::IntervalOrSegmentDomain{T},n::Integer) where {T} =
9797
fromcanonical.(Ref(d), chebyshevpoints(float(real(eltype(T))), n)) # eltype to handle point
9898
bary(v::AbstractVector{Float64},d::IntervalOrSegmentDomain,x::Float64) = bary(v,tocanonical(d,x))
9999

100+
strictconvert(T::Type, x) = convert(T, x)::T
101+
100102
include("bary.jl")
101103

102104

src/Domains/Arc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Arc{T,V<:Real,TT} <: SegmentDomain{TT}
1616
center::T
1717
radius::V
1818
angles::Tuple{V,V}
19-
Arc{T,V,TT}(c,r,a) where {T,V,TT} = new{T,V,TT}(convert(T,c),convert(V,r),Tuple{V,V}(a))
19+
Arc{T,V,TT}(c,r,a) where {T,V,TT} = new{T,V,TT}(strictconvert(T,c),strictconvert(V,r),Tuple{V,V}(a))
2020
end
2121

2222

src/Domains/Ray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function convert(::Type{Ray}, d::AbstractInterval)
4545
Ray(b,angle(a),one(typeof(a)),false)
4646
end
4747
end
48-
Ray(d::AbstractInterval) = convert(Ray, d)
48+
Ray(d::AbstractInterval) = strictconvert(Ray, d)
4949

5050

5151
isambiguous(d::Ray)=isnan(d.center)

src/Spaces/Chebyshev/Chebyshev.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Chebyshev{D<:Domain,R} <: PolynomialSpace{D,R}
1616
isempty(d) && throw(ArgumentError("Domain cannot be empty"))
1717
new(d)
1818
end
19-
Chebyshev{D,R}() where {D,R} = new(convert(D, ChebyshevInterval()))
19+
Chebyshev{D,R}() where {D,R} = new(strictconvert(D, ChebyshevInterval()))
2020
end
2121

2222
Chebyshev(d::Domain) = Chebyshev{typeof(d),real(prectype(d))}(d)

src/Spaces/Chebyshev/ChebyshevOperators.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(leftendpoint)
6565
x = op.x
6666
d = domain(op)
6767
p = op.order
68-
cst = convert(T,(2/complexlength(d))^p)
68+
cst = strictconvert(T,(2/complexlength(d))^p)
6969
n=length(k)
7070

7171
ret = Array{T}(undef, n)
@@ -79,7 +79,7 @@ function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(leftendpoint)
7979
@simd for j=k
8080
@inbounds ret[j+k1] *= (j-1)^2-m^2
8181
end
82-
scal!(convert(T,1/(2m+1)), ret)
82+
scal!(strictconvert(T,1/(2m+1)), ret)
8383
end
8484

8585
scal!(cst,ret)
@@ -91,7 +91,7 @@ function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(rightendpoint
9191
x = op.x
9292
d = domain(op)
9393
p = op.order
94-
cst = convert(T,(2/complexlength(d))^p)
94+
cst = strictconvert(T,(2/complexlength(d))^p)
9595
n=length(k)
9696

9797
ret = fill(one(T),n)
@@ -101,7 +101,7 @@ function getindex(op::ConcreteEvaluation{<:Chebyshev{DD,RR},typeof(rightendpoint
101101
@simd for j=k
102102
@inbounds ret[j+k1] *= (j-1)^2-m^2
103103
end
104-
scal!(convert(T,1/(2m+1)), ret)
104+
scal!(strictconvert(T,1/(2m+1)), ret)
105105
end
106106

107107
scal!(cst,ret)
@@ -110,7 +110,7 @@ end
110110
function getindex(op::ConcreteEvaluation{Chebyshev{DD,RR},M,OT,T},
111111
j::Integer) where {DD<:IntervalOrSegment,RR,M<:Real,OT,T}
112112
if op.order == 0
113-
convert(T,evaluatechebyshev(j,tocanonical(domain(op),op.x))[end])
113+
strictconvert(T,evaluatechebyshev(j,tocanonical(domain(op),op.x))[end])
114114
else
115115
error("Only zero–second order implemented")
116116
end
@@ -223,8 +223,8 @@ function getindex(D::ConcreteDerivative{Chebyshev{DD,RR},K,T},k::Integer,j::Inte
223223
d=domain(D)
224224

225225
if j==k+m
226-
C=convert(T,pochhammer(one(T),m-1)/2*(4/complexlength(d))^m)
227-
convert(T,C*(m+k-one(T)))
226+
C=strictconvert(T,pochhammer(one(T),m-1)/2*(4/complexlength(d))^m)
227+
strictconvert(T,C*(m+k-one(T)))
228228
else
229229
zero(T)
230230
end
@@ -238,14 +238,14 @@ linesum(f::Fun{Chebyshev{DD,RR}}) where {DD<:IntervalOrSegment,RR} =
238238
## Clenshaw-Curtis functional
239239

240240
for (Func,Len) in ((:DefiniteIntegral,:complexlength),(:DefiniteLineIntegral,:arclength))
241-
ConcFunc = Meta.parse("Concrete"*string(Func))
241+
ConcFunc = Symbol(:Concrete, Func)
242242
@eval begin
243243
$Func(S::Chebyshev{D}) where {D<:IntervalOrSegment} = $ConcFunc(S)
244244
function getindex::$ConcFunc{Chebyshev{D,R},T},k::Integer) where {D<:IntervalOrSegment,R,T}
245245
d = domain(Σ)
246246
C = $Len(d)/2
247247

248-
isodd(k) ? convert(T,2C/(k*(2-k))) : zero(T)
248+
isodd(k) ? strictconvert(T,2C/(k*(2-k))) : zero(T)
249249
end
250250
end
251251
end

src/Spaces/CurveSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export Bernstein, Bézier
2424
struct Bernstein{order,D,R} <: Space{D,R}
2525
domain::D
2626
Bernstein{order,D,R}(d) where {order,D,R} = new(d)
27-
Bernstein{order,D,R}() where {order,D,R} = new(convert(D, ChebyshevInterval()))
27+
Bernstein{order,D,R}() where {order,D,R} = new(strictconvert(D, ChebyshevInterval()))
2828
end
2929

3030
const Bézier = Bernstein # option+e e gives é

src/Spaces/Hermite/Hermite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ weight(H::GaussWeight,x) = exp(-H.L * x^2)
103103

104104
function Base.sum(f::Fun{GaussWeight{H,T}}) where {H<:Hermite,T}
105105
@assert space(f).space.L==space(f).L # only implemented with matching weight
106-
f.coefficients[1]*sqrt(convert(T,π))/sqrt(space(f).L)
106+
f.coefficients[1]*sqrt(strictconvert(T,π))/sqrt(space(f).L)
107107
end
108108

109109
include("hermitetransform.jl")

src/Spaces/Jacobi/JacobiOperators.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function getindex(op::ConcreteEvaluation{<:Jacobi,typeof(leftendpoint)},kr::Abst
3535
sp=op.space
3636
T=eltype(op)
3737
RT=real(T)
38-
a=convert(RT,sp.a);b=convert(RT,sp.b)
38+
a=strictconvert(RT,sp.a);b=strictconvert(RT,sp.b)
3939

4040
if op.order == 0
4141
jacobip(T,kr.-1,a,b,-one(T))
@@ -67,7 +67,7 @@ function getindex(op::ConcreteEvaluation{<:Jacobi,typeof(rightendpoint)},kr::Abs
6767
sp=op.space
6868
T=eltype(op)
6969
RT=real(T)
70-
a=convert(RT,sp.a);b=convert(RT,sp.b)
70+
a=strictconvert(RT,sp.a);b=strictconvert(RT,sp.b)
7171

7272

7373
if op.order == 0
@@ -169,7 +169,7 @@ end
169169

170170

171171
for (Func,Len,Sum) in ((:DefiniteIntegral,:complexlength,:sum),(:DefiniteLineIntegral,:arclength,:linesum))
172-
ConcFunc = Meta.parse("Concrete"*string(Func))
172+
ConcFunc = Symbol(:Concrete, Func)
173173

174174
@eval begin
175175
$Func(S::Jacobi{<:IntervalOrSegment}) = $ConcFunc(S)
@@ -179,9 +179,9 @@ for (Func,Len,Sum) in ((:DefiniteIntegral,:complexlength,:sum),(:DefiniteLineInt
179179

180180
if dsp.b == dsp.a == 0
181181
# TODO: copy and paste
182-
k == 1 ? convert(T,$Sum(Fun(dsp,[one(T)]))) : zero(T)
182+
k == 1 ? strictconvert(T,$Sum(Fun(dsp,[one(T)]))) : zero(T)
183183
else
184-
convert(T,$Sum(Fun(dsp,[zeros(T,k-1);1])))
184+
strictconvert(T,$Sum(Fun(dsp,[zeros(T,k-1);1])))
185185
end
186186
end
187187

@@ -239,17 +239,17 @@ function Base.getindex(C::ConcreteConversion{J1,J2,T},k::Integer,j::Integer) whe
239239
L=C.domainspace
240240
if L.b+1==C.rangespace.b
241241
if j==k
242-
k==1 ? convert(T,1) : convert(T,(L.a+L.b+k)/(L.a+L.b+2k-1))
242+
k==1 ? strictconvert(T,1) : strictconvert(T,(L.a+L.b+k)/(L.a+L.b+2k-1))
243243
elseif j==k+1
244-
convert(T,(L.a+k)./(L.a+L.b+2k+1))
244+
strictconvert(T,(L.a+k)./(L.a+L.b+2k+1))
245245
else
246246
zero(T)
247247
end
248248
elseif L.a+1==C.rangespace.a
249249
if j==k
250-
k==1 ? convert(T,1) : convert(T,(L.a+L.b+k)/(L.a+L.b+2k-1))
250+
k==1 ? strictconvert(T,1) : strictconvert(T,(L.a+L.b+k)/(L.a+L.b+2k-1))
251251
elseif j==k+1
252-
convert(T,-(L.b+k)./(L.a+L.b+2k+1))
252+
strictconvert(T,-(L.b+k)./(L.a+L.b+2k+1))
253253
else
254254
zero(T)
255255
end
@@ -416,7 +416,7 @@ function getindex(C::ConcreteConversion{US,J,T},k::Integer,j::Integer) where {US
416416
if j==k
417417
S=rangespace(C)
418418
jp=jacobip(T,k-1,S.a,S.b,one(T))
419-
um=convert(Operator{T}, Evaluation(setcanonicaldomain(domainspace(C)),rightendpoint,0))[k]::T
419+
um=strictconvert(Operator{T}, Evaluation(setcanonicaldomain(domainspace(C)),rightendpoint,0))[k]::T
420420
(um/jp)::T
421421
else
422422
zero(T)

src/Spaces/Jacobi/jacobitransform.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ end
4040

4141
function coefficients(f::AbstractVector{T}, a::Jacobi, b::Chebyshev) where T
4242
if domain(a) == domain(b) && (!isapproxinteger(a.a-0.5) || !isapproxinteger(a.b-0.5))
43-
jac2cheb(f, convert(T,a.a), convert(T,a.b))
43+
jac2cheb(f, strictconvert(T,a.a), strictconvert(T,a.b))
4444
else
4545
defaultcoefficients(f,a,b)
4646
end
4747
end
4848
function coefficients(f::AbstractVector{T}, a::Chebyshev, b::Jacobi) where T
4949
isempty(f) && return f
5050
if domain(a) == domain(b) && (!isapproxinteger(b.a-0.5) || !isapproxinteger(b.b-0.5))
51-
cheb2jac(f, convert(T,b.a), convert(T,b.b))
51+
cheb2jac(f, strictconvert(T,b.a), strictconvert(T,b.b))
5252
else
5353
defaultcoefficients(f,a,b)
5454
end

src/Spaces/Laguerre/Laguerre.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ tocanonical(d::Laguerre,x) = mappoint(domain(d),Ray(),x)
4343
fromcanonical(d::Laguerre,x) = mappoint(Ray(),domain(d),x)
4444

4545

46-
@inline laguerrerecα(::Type{T},α,k) where {T} = convert(T,2k+α-1)
47-
@inline laguerrerecβ(::Type{T},_,k) where {T} = convert(T,-k)
48-
@inline laguerrerecγ(::Type{T},α,k) where {T} = convert(T,-(k-1+α))
46+
@inline laguerrerecα(::Type{T},α,k) where {T} = strictconvert(T,2k+α-1)
47+
@inline laguerrerecβ(::Type{T},_,k) where {T} = strictconvert(T,-k)
48+
@inline laguerrerecγ(::Type{T},α,k) where {T} = strictconvert(T,-(k-1+α))
4949

5050

51-
@inline laguerrerecA(::Type{T},_,k) where {T} = convert(T,-1/(k+1))
52-
@inline laguerrerecB(::Type{T},α,k) where {T} = convert(T,(2k+α+1)/(k+1))
53-
@inline laguerrerecC(::Type{T},α,k) where {T} = convert(T,(k+α)/(k+1))
51+
@inline laguerrerecA(::Type{T},_,k) where {T} = strictconvert(T,-1/(k+1))
52+
@inline laguerrerecB(::Type{T},α,k) where {T} = strictconvert(T,(2k+α+1)/(k+1))
53+
@inline laguerrerecC(::Type{T},α,k) where {T} = strictconvert(T,(k+α)/(k+1))
5454

5555
for (REC,JREC) in ((:recα,:laguerrerecα),(:recβ,:laguerrerecβ),(:recγ,:laguerrerecγ),
5656
(:recA,:laguerrerecA),(:recB,:laguerrerecB),(:recC,:laguerrerecC))

src/Spaces/PolynomialSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct JacobiZ{S<:Space,T} <: TridiagonalOperator{T}
9090
end
9191

9292
JacobiZ(sp::PolynomialSpace,z) =
93-
(T = promote_type(prectype(sp),typeof(z)); JacobiZ{typeof(sp),T}(sp,convert(T,z)))
93+
(T = promote_type(prectype(sp),typeof(z)); JacobiZ{typeof(sp),T}(sp,strictconvert(T,z)))
9494

9595
convert(::Type{Operator{T}},J::JacobiZ{S}) where {T,S} = JacobiZ{S,T}(J.space,J.z)
9696

src/Spaces/Ultraspherical/ContinuousSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ function BlockBandedMatrix(S::SubOperator{T,<:ConcreteDirichlet{<:TensorChebyshe
411411
end
412412

413413

414-
union_rule(A::PiecewiseSpace, B::ContinuousSpace) = union(A, convert(PiecewiseSpace, B))
414+
union_rule(A::PiecewiseSpace, B::ContinuousSpace) = union(A, strictconvert(PiecewiseSpace, B))
415415
union_rule(A::ConstantSpace, B::ContinuousSpace) = B
416416
union_rule(A::ContinuousSpace, B::PolynomialSpace{<:IntervalOrSegment}) =
417417
Space(domain(A) domain(B))

src/Spaces/Ultraspherical/DirichletSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export ChebyshevDirichlet
66
struct ChebyshevDirichlet{left,right,D,R} <: PolynomialSpace{D,R}
77
domain::D
88
ChebyshevDirichlet{left,right,D,R}(d) where {left,right,D,R} = new(d)
9-
ChebyshevDirichlet{left,right,D,R}() where {left,right,D,R} = new(convert(D, ChebyshevInterval()))
9+
ChebyshevDirichlet{left,right,D,R}() where {left,right,D,R} = new(strictconvert(D, ChebyshevInterval()))
1010
end
1111

1212
for TYP in (:Number,:AbstractArray,:Vec,:Fun)

src/Spaces/Ultraspherical/Ultraspherical.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ struct Ultraspherical{T,D<:Domain,R} <: PolynomialSpace{D,R}
1818
order::T
1919
domain::D
2020
Ultraspherical{T,D,R}(m::T,d::D) where {T,D,R} = (@assert m 0; new(m,d))
21-
Ultraspherical{T,D,R}(m::Number,d::Domain) where {T,D,R} = (@assert m 0; new(convert(T,m),convert(D,d)))
22-
Ultraspherical{T,D,R}(d::Domain) where {T,D,R} = new(one(T),convert(D,d))
23-
Ultraspherical{T,D,R}(m::Number) where {T,D,R} = (@assert m 0; new(convert(T,m),D()))
21+
Ultraspherical{T,D,R}(m::Number,d::Domain) where {T,D,R} = (@assert m 0; new(strictconvert(T,m),strictconvert(D,d)))
22+
Ultraspherical{T,D,R}(d::Domain) where {T,D,R} = new(one(T),strictconvert(D,d))
23+
Ultraspherical{T,D,R}(m::Number) where {T,D,R} = (@assert m 0; new(strictconvert(T,m),D()))
2424
end
2525

2626
Ultraspherical(m::Number,d::Domain) = Ultraspherical{typeof(m),typeof(d),real(prectype(d))}(m,d)

src/Spaces/Ultraspherical/UltrasphericalOperators.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function getindex(D::ConcreteDerivative{Ultraspherical{TT,DD,RR},K,T},
7979
λ=order(domainspace(D))
8080

8181
if j==k+m
82-
convert(T,(pochhammer(one(T)*λ,m)*(4/complexlength(d)).^m))
82+
strictconvert(T,(pochhammer(one(T)*λ,m)*(4/complexlength(d)).^m))
8383
else
8484
zero(T)
8585
end
@@ -104,9 +104,9 @@ function getindex(Q::ConcreteIntegral{Ultraspherical{LT,DD,RR}},k::Integer,j::In
104104

105105
if λ == 1 && k==j+1
106106
C = complexlength(d)/2
107-
convert(T,C./(k-1))
107+
strictconvert(T,C./(k-1))
108108
elseif λ > 1 && k==j+m
109-
convert(T,pochhammer(one(T)*λ,-m)*(complexlength(d)/4)^m)
109+
strictconvert(T,pochhammer(one(T)*λ,-m)*(complexlength(d)/4)^m)
110110
else
111111
zero(T)
112112
end
@@ -285,9 +285,9 @@ function getindex(M::ConcreteConversion{C,Ultraspherical{LT,DD,RR},T},
285285
if j==k==1
286286
one(T)
287287
elseif j==k
288-
convert(T,sqrt(π)/(2FastTransforms.Λ(k-1)))
288+
strictconvert(T,sqrt(π)/(2FastTransforms.Λ(k-1)))
289289
elseif k < j && iseven(k-j)
290-
convert(T,-(j-1)*(k-0.5)*(FastTransforms.Λ((j-k-2)/2)/(j-k))*
290+
strictconvert(T,-(j-1)*(k-0.5)*(FastTransforms.Λ((j-k-2)/2)/(j-k))*
291291
(FastTransforms.Λ((j+k-3)/2)/(j+k-1)))
292292
else
293293
zero(T)
@@ -314,9 +314,9 @@ function getindex(M::ConcreteConversion{Ultraspherical{LT,DD,RR},C,T},
314314
end
315315
elseif λ == 0.5
316316
if k==1 && isodd(j)
317-
convert(T,FastTransforms.Λ((j-1)/2)^2/π)
317+
strictconvert(T,FastTransforms.Λ((j-1)/2)^2/π)
318318
elseif k j && iseven(k-j)
319-
convert(T,FastTransforms.Λ((j-k)/2)*FastTransforms.Λ((k+j-2)/2)*2/π)
319+
strictconvert(T,FastTransforms.Λ((j-k)/2)*FastTransforms.Λ((k+j-2)/2)*2/π)
320320
else
321321
zero(T)
322322
end
@@ -334,7 +334,7 @@ function getindex(M::ConcreteConversion{Ultraspherical{LT,DD,RR},
334334
λ2 = order(rangespace(M))
335335
if abs(λ1-λ2) < 1
336336
if j k && iseven(k-j)
337-
convert(T,(λ1 < λ2 && k j ? -1 : 1) * # fix sign for lgamma
337+
strictconvert(T,(λ1 < λ2 && k j ? -1 : 1) * # fix sign for lgamma
338338
exp(lgamma(λ2)+log(k-1+λ2)-lgamma(λ1)-lgamma(λ1-λ2) + lgamma((j-k)/2+λ1-λ2)-
339339
lgamma((j-k)/2+1)+lgamma((k+j-2)/2+λ1)-lgamma((k+j-2)/2+λ2+1)))
340340
else

src/fastops.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function BandedMatrix(S::SubOperator{T,ConcreteDerivative{Chebyshev{DD,RR},K,T},
7777
k = D.order
7878
d = domain(D)
7979

80-
C=convert(T,pochhammer(one(T),k-1)/2*(4/(complexlength(d)))^k)
80+
C=strictconvert(T,pochhammer(one(T),k-1)/2*(4/(complexlength(d)))^k)
8181

8282

8383
# need to drop columns
@@ -103,7 +103,7 @@ function BandedMatrix(S::SubOperator{T,ConcreteDerivative{Ultraspherical{LT,DD,R
103103
λ = order(domainspace(D))
104104
d = domain(D)
105105

106-
C = convert(T,pochhammer(one(T)*λ,k)*(4/(complexlength(d)))^k)
106+
C = strictconvert(T,pochhammer(one(T)*λ,k)*(4/(complexlength(d)))^k)
107107
ret[band(dg+k)] .= C
108108

109109
ret

src/roots.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ for (BF,FF) in ((BigFloat,Float64),(Complex{BigFloat},ComplexF64))
8181
htol = eps(2000.)*max(hscale, 1) # TODO: choose tolerance better
8282

8383
# calculate Flaot64 roots
84-
r = Array{$BF}(rootsunit_coeffs(convert(Vector{$FF},c./vscale), Float64(htol)))
84+
r = Array{$BF}(rootsunit_coeffs(strictconvert(Vector{$FF},c./vscale), Float64(htol)))
8585
# Map roots from [-1,1] to domain of f:
8686
rts = fromcanonical.(Ref(d),r)
8787
fp = differentiate(f)

0 commit comments

Comments
 (0)