Skip to content

Commit fc1b2cb

Browse files
authored
implicit type-params in Fun (#156)
1 parent 9a5338e commit fc1b2cb

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Fun.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ Base.promote_op(::typeof(LinearAlgebra.matprod),::Type{NN},::Type{Fun{S,T,VT}})
126126
zero(::Type{Fun}) = Fun(0.)
127127
zero(::Type{Fun{S,T,VT}}) where {T,S<:Space,VT} = zeros(T,S(AnyDomain()))
128128
one(::Type{Fun{S,T,VT}}) where {T,S<:Space,VT} = ones(T,S(AnyDomain()))
129-
zero(f::Fun{S,T}) where {S,T} = zeros(T,f.space)
130-
one(f::Fun{S,T}) where {S,T} = ones(T,f.space)
129+
zero(f::Fun) = zeros(cfstype(f), space(f))
130+
one(f::Fun) = ones(cfstype(f), space(f))
131131

132132
cfstype(::Fun{S,T}) where {S,T} = T
133133
cfstype(::Type{Fun{S,T,VT}}) where {S,T,VT} = T
@@ -218,7 +218,7 @@ evaluate(f::Fun,x,y,z...) = evaluate(f.coefficients,f.space,Vec(x,y,z...))
218218
dynamic(f::Fun) = f # Fun's are already dynamic in that they compile by type
219219

220220
for (op,dop) in ((:first,:leftendpoint),(:last,:rightendpoint))
221-
@eval $op(f::Fun{S,T}) where {S,T} = f($dop(domain(f)))
221+
@eval $op(f::Fun) = f($dop(domain(f)))
222222
end
223223

224224

@@ -406,7 +406,7 @@ for (OP,SUM) in ((:(norm),:(sum)),(:linenorm,:linesum))
406406
@eval begin
407407
$OP(f::Fun) = $OP(f,2)
408408

409-
function $OP(f::Fun{S},p::Real) where S<:Space{D,R} where {D,R<:Number}
409+
function $OP(f::Fun{<:Space{<:Any,<:Number}}, p::Real)
410410
if p < 1
411411
return error("p should be 1 ≤ p ≤ ∞")
412412
elseif 1 p < Inf
@@ -416,7 +416,7 @@ for (OP,SUM) in ((:(norm),:(sum)),(:linenorm,:linesum))
416416
end
417417
end
418418

419-
function $OP(f::Fun{S},p::Int) where S<:Space{D,R} where {D,R<:Number}
419+
function $OP(f::Fun{<:Space{<:Any,<:Number}}, p::Int)
420420
if 1 p < Inf
421421
return iseven(p) ? abs($SUM(abs2(f)^(p÷2)))^(1/p) : abs($SUM(abs2(f)^(p/2)))^(1/p)
422422
else
@@ -432,13 +432,13 @@ end
432432
transpose(f::Fun) = f # default no-op
433433

434434
for op = (:real, :imag, :conj)
435-
@eval Base.$op(f::Fun{S}) where {S<:RealSpace} = Fun(f.space, ($op)(f.coefficients))
435+
@eval Base.$op(f::Fun{<:RealSpace}) = Fun(f.space, ($op)(f.coefficients))
436436
end
437437

438438
conj(f::Fun) = error("Override conj for $(typeof(f))")
439439

440-
abs2(f::Fun{S,T}) where {S<:RealSpace,T<:Real} = f^2
441-
abs2(f::Fun{S,T}) where {S<:RealSpace,T<:Complex} = real(f)^2+imag(f)^2
440+
abs2(f::Fun{<:RealSpace,<:Real}) = f^2
441+
abs2(f::Fun{<:RealSpace,<:Complex}) = real(f)^2+imag(f)^2
442442
abs2(f::Fun)=f*conj(f)
443443

444444
## integration
@@ -478,7 +478,8 @@ Base.rtoldefault(x::Union{T,Type{T}}, y::Union{S,Type{S}}, atol) where {T<:Fun,S
478478
Base.rtoldefault(cfstype(x),cfstype(y), atol)
479479

480480

481-
function isapprox(f::Fun{S1,T},g::Fun{S2,S};rtol::Real=Base.rtoldefault(T,S,0), atol::Real=0, norm::Function=coefficientnorm) where {S1,S2,T,S}
481+
function isapprox(f::Fun,g::Fun;
482+
rtol::Real=Base.rtoldefault(cfstype(f),cfstype(g),0), atol::Real=0, norm::Function=coefficientnorm)
482483
if spacescompatible(f,g)
483484
d = norm(f - g)
484485
if isfinite(d)

0 commit comments

Comments
 (0)