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))

0 commit comments

Comments
 (0)