Skip to content

Commit

Permalink
bugfixes in InterlaceOperator and KroneckerOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 16, 2023
1 parent 36e0868 commit 272c3ab
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/Operators/banded/ToeplitzOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ ToeplitzOperator(V::Vector{T},W::Vector{Q}) where {T<:Number,Q<:Number} =
ToeplitzOperator(V::AbstractVector,W::AbstractVector) =
ToeplitzOperator(collect(V),collect(W))

function ToeplitzOperator{T}(x::ToeplitzOperator) where {T}
function ToeplitzOperator{T}(x::ToeplitzOperator) where {T<:Number}
ToeplitzOperator{T}(strictconvert(Vector{T}, x.negative), strictconvert(Vector{T}, x.nonnegative))
end
Operator{TT}(T::ToeplitzOperator) where {TT} =
Operator{TT}(T::ToeplitzOperator) where {TT<:Number} =
ToeplitzOperator(strictconvert(Vector{TT},T.negative),strictconvert(Vector{TT},T.nonnegative))

for op in (:(Base.real), :(Base.imag))
Expand Down Expand Up @@ -109,8 +109,8 @@ HankelOperator(V::AbstractVector)=HankelOperator(collect(V))
HankelOperator(f::Fun)=HankelOperator(f.coefficients)


HankelOperator{T}(H::HankelOperator) where {T} = HankelOperator{T}(strictconvert(Vector{T}, H.coefficients))
Operator{TT}(H::HankelOperator) where {TT} = HankelOperator(strictconvert(Vector{TT},H.coefficients))
HankelOperator{T}(H::HankelOperator) where {T<:Number} = HankelOperator{T}(strictconvert(Vector{T}, H.coefficients))
Operator{TT}(H::HankelOperator) where {TT<:Number} = HankelOperator(strictconvert(Vector{TT},H.coefficients))

function hankel_getindex(v::AbstractVector,k::Integer,j::Integer)
if k+j-1 length(v)
Expand Down
12 changes: 6 additions & 6 deletions src/Operators/general/InterlaceOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ InterlaceOperator(ops::AbstractArray) =

function InterlaceOperator{T,p,DS,RS,DI,RI,BI}(S::InterlaceOperator) where {T,p,DS<:Space,RS<:Space,DI,RI,BI}
InterlaceOperator{T,p,DS,RS,DI,RI,BI}(
strictconvert(Array{Operator{T},p}, ops),
strictconvert(DS, domainspace),
strictconvert(RS, rangespace),
strictconvert(DI, domaininterlacer),
strictconvert(RI, rangeinterlacer),
strictconvert(BI, bandwidths),
strictconvert(Array{Operator{T},p}, S.ops),
strictconvert(DS, S.domainspace),
strictconvert(RS, S.rangespace),
strictconvert(DI, S.domaininterlacer),
strictconvert(RI, S.rangeinterlacer),
strictconvert(BI, S.bandwidths),
)
end
function Operator{T}(S::InterlaceOperator) where T
Expand Down
4 changes: 2 additions & 2 deletions src/Operators/general/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ end

function ConstantTimesOperator{T,B}(C::ConstantTimesOperator) where {T<:Number,B<:Operator{T}}
ConstantTimesOperator{T,B}(
strictconvert(T, λ),
strictconvert(B, op),
strictconvert(T, C.λ),
strictconvert(B, C.op),
)
end
function Operator{T}(C::ConstantTimesOperator) where {T}
Expand Down
10 changes: 5 additions & 5 deletions src/PDE/KroneckerOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ end

function KroneckerOperator{S,V,DS,RS,DI,RI,T}(K::KroneckerOperator) where {S,V,DS,RS,DI,RI,T}
KroneckerOperator{S,V,DS,RS,DI,RI,T}(
strictconvert(Tuple{S,V}, ops),
strictconvert(DS, domainspace),
strictconvert(RS, rangespace),
strictconvert(DI, domaintensorizer),
strictconvert(RI, rangetensorizer),
strictconvert(Tuple{S,V}, K.ops),
strictconvert(DS, K.domainspace),
strictconvert(RS, K.rangespace),
strictconvert(DI, K.domaintensorizer),
strictconvert(RI, K.rangetensorizer),
)
end
function Operator{T}(K::KroneckerOperator) where T<:Number
Expand Down
56 changes: 56 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,62 @@ end

R = real(M)
@test typeof(M)(M) == M

P = PlusOperator([M,M])
@test typeof(P)(P) == P

T = TimesOperator([M,M])
@test typeof(T)(T) == T

cT = 2M
@test typeof(cT)(cT) == cT

Q = qr(M)
Q2 = typeof(Q)(Q)
# For some reason (perhaps owing to mutability), this does't satisfy Q == Q2,
# so we check the fields
@test typeof(Q) == typeof(Q2)
@test all(x -> getfield(Q, x) === getfield(Q2, x), fieldnames(typeof(Q)))

Sp = ApproxFunBase.SpaceOperator(M, PointSpace(2:4), PointSpace(2:4))
@test typeof(Sp)(Sp) == Sp

K = Sp Sp
@test typeof(K)(K) == K

Sb = view(M, 1:3, 1:3)
@test typeof(Sb)(Sb) == Sb

Intrlc = [M; M]
@test typeof(Intrlc)(Intrlc) == Intrlc

Hrm = ApproxFunBase.HermitianOperator(M)
@test typeof(Hrm)(Hrm) == Hrm

Sym = ApproxFunBase.SymmetricOperator(M)
@test typeof(Sym)(Sym) == Sym

Cch = cache(M)
Cch2 = typeof(Cch)(Cch)
# For some reason (perhaps owing to mutability), this does't satisfy Cch == Cch2,
# so we check the fields
@test typeof(Cch) == typeof(Cch2)
@test all(x -> getfield(Cch, x) === getfield(Cch2, x), fieldnames(typeof(Cch)))

Madj = M'
@test typeof(Madj)(Madj) == Madj

Mtr = transpose(M)
@test typeof(Mtr)(Mtr) == Mtr

CnstO = Operator(2I, PointSpace(1:3))
@test typeof(CnstO)(CnstO) == CnstO

Tplz = ApproxFunBase.ToeplitzOperator([1,2], [2,3])
@test typeof(Tplz)(Tplz) == Tplz

Hnkl = ApproxFunBase.HankelOperator([1,2, 3])
@test typeof(Hnkl)(Hnkl) == Hnkl
end
end

Expand Down

0 comments on commit 272c3ab

Please sign in to comment.