Skip to content

Commit 416b8cf

Browse files
authored
vector indexing for transpose op (#173)
1 parent ceb351e commit 416b8cf

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

src/Operators/functionals/Evaluation.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ end
5757

5858

5959
## default getindex
60-
getindex(D::ConcreteEvaluation,k::Integer) =
61-
eltype(D)(differentiate(Fun(D.space,[zeros(eltype(D),k-1);one(eltype(D))]),D.order)(D.x))
60+
function getindex(D::ConcreteEvaluation,k::Integer)
61+
f = Fun(D.space, [zeros(eltype(D),k-1); one(eltype(D))])
62+
df = differentiate(f,D.order)
63+
v = df(D.x)
64+
strictconvert(eltype(D), v)
65+
end
6266

6367
#special leftendpoint/rightendpoint overrides
6468
for (dop, fop) in ((:leftendpoint,:first), (:rightendpoint,:last))

src/Operators/general/OperatorLayout.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ domain(P::TransposeOperator)=domain(P.op)
105105
bandwidths(P::TransposeOperator) = reverse(bandwidths(P.op))
106106

107107
getindex(P::TransposeOperator,k::Integer,j::Integer) = P.op[j,k]
108+
getindex(P::TransposeOperator,inds...) = transpose(P.op[reverse(inds)...])
108109

109110
function BandedMatrix(S::SubOperator{T,TO}) where {T,TO<:TransposeOperator}
110111
kr,jr=parentindices(S)

src/Spaces/DiracSpace.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ values(f::Fun{S}) where S<:PointSpace = coefficient(f,:)
8181

8282
function evaluate(f::AbstractVector,PS::PointSpace,x::Number)
8383
p = findfirst(y->isapprox(x,y),PS.points)
84-
if p == 0 || p > length(f)
84+
if p === nothing
8585
zero(eltype(f))
8686
else
8787
f[p]
@@ -92,7 +92,7 @@ function evaluate(f::AbstractVector, PS::DiracSpace, x::Number)
9292
x domain(PS) && return zero(eltype(f))
9393

9494
p = findfirst(y->isapprox(x,y), PS.points)
95-
if p == 0 || p > length(f)
95+
if p === nothing
9696
zero(eltype(f))
9797
else
9898
f[p]*Inf

test/SpacesTest.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ using BandedMatrices: rowrange, colrange
118118
f = Fun(PointSpace(1:3), SA[1,2,3])
119119
@test coefficients(f^2) == coefficients(f).^2
120120
end
121+
122+
@testset "indexing outside bounds" begin
123+
f = Fun(PointSpace(1:3), Float64[1:3;])
124+
@test f(0) == 0
125+
@test f(1) == 1
126+
@test f(4) == 0
127+
end
128+
end
129+
130+
@testset "DiracSpace" begin
131+
f = Fun(ApproxFunBase.DiracSpace(Float64[-1,0,1]), Float64[1,2,3])
132+
@test f(-5) == 0
133+
@test f(0.5) == 0
134+
@test f(5) == 0
135+
@test isinf(f(0))
121136
end
122137

123138
@testset "Derivative operator for HeavisideSpace" begin

test/show.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
summarystr = ApproxFunBase.summarystr(EA)
6060
show(io, MIME"text/plain"(), EA)
6161
@test contains(String(take!(io)), summarystr)
62+
63+
EA = transpose(Evaluation(Chebyshev(), 0))
64+
summarystr = ApproxFunBase.summarystr(EA)
65+
show(io, MIME"text/plain"(), EA)
66+
@test contains(String(take!(io)), summarystr)
6267
end
6368
@testset "QuotientSpace" begin
6469
Q = QuotientSpace(Dirichlet(ConstantSpace(0..1)))

0 commit comments

Comments
 (0)