Skip to content

Commit fe5e80a

Browse files
authored
Fix convert for ConcreteOperatorFunction (#250)
* Fix convert for ConcreteOperatorFunction * compute output eltype from input * Add conversion test
1 parent 30f8910 commit fe5e80a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.7.27"
3+
version = "0.7.28"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Operators/general/OperatorFunction.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ struct ConcreteOperatorFunction{BT<:Operator,FF,T} <: OperatorFunction{BT,FF,T}
88
f::FF
99
end
1010

11-
ConcreteOperatorFunction(op::Operator,f::Function) =
12-
ConcreteOperatorFunction{typeof(op),typeof(f),eltype(op)}(op,f)
11+
function ConcreteOperatorFunction(op::Operator,f::Function)
12+
T = typeof(f(oneunit(eltype(op))))
13+
ConcreteOperatorFunction{typeof(op),typeof(f),T}(op,f)
14+
end
1315
OperatorFunction(op::Operator,f::Function) = ConcreteOperatorFunction(op,f)
1416

1517
for op in (:domainspace,:rangespace,:domain,:bandwidths)
@@ -31,7 +33,8 @@ function convert(::Type{Operator{T}},D::ConcreteOperatorFunction) where T
3133
if T==eltype(D)
3234
D
3335
else
34-
ConcreteOperatorFunction{typeof(D.op),T}(D.op,D.f)
36+
DopT = strictconvert(Operator{T}, D.op)
37+
ConcreteOperatorFunction(DopT, D.f)::Operator{T}
3538
end
3639
end
3740

test/SpacesTest.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ using LinearAlgebra
171171
P = PartialInverseOperator(C)
172172
@test AbstractMatrix(P * C) == I(size(C,1))
173173
end
174+
175+
@testset "ConcreteOperatorFunction" begin
176+
A = 2I : PointSpace(1:4)
177+
Ainv = inv(A)
178+
B = convert(Operator{ComplexF64}, Ainv)
179+
@test B isa Operator{ComplexF64}
180+
@test ComplexF64.(Ainv[1:4, 1:4]) == B[1:4, 1:4]
181+
end
174182
end
175183

176184
@testset "DiracSpace" begin

0 commit comments

Comments
 (0)