Skip to content

Commit 1754012

Browse files
authored
BandedMatrix for view of ConstantOperator (#476)
* BandedMatrix for view of ConstantOperator * specialize BandedMatrix for UnitRange{Int} tuples
1 parent 2a55e1a commit 1754012

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
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.8.30"
3+
version = "0.8.31"
44

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

src/Operators/banded/ConstantOperator.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ subblockbandwidths(::ConstantOperator) = 0,0
3333
getindex(C::ConstantOperator,k::Integer,j::Integer) =
3434
k==j ? eltype(C)(C.λ) : zero(eltype(C))
3535

36+
function BandedMatrix(S::SubOperator{T, <:ConstantOperator{T}, NTuple{2,UnitRange{Int}}}) where {T}
37+
# only one band will be populated
38+
bw = bandwidth(S,2)
39+
C = parent(S)
40+
n = convert(Number, C)
41+
B = BandedMatrix{T}(undef, size(S), bandwidths(S))
42+
B[band(bw)] .= n
43+
B
44+
end
3645

3746
==(C1::ConstantOperator, C2::ConstantOperator) = C1.λ==C2.λ
3847

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ end
425425
ApproxFunBase.mul_coefficients!(Operator(2I), v)
426426
@test v Float64[2i^2 for i in 1:4]
427427
end
428+
@testset "ConstantOperator" begin
429+
C = ConstantOperator(3.0, PointSpace(1:4))
430+
@test isdiag(C)
431+
@testset "BandedMatrix" begin
432+
B = C[2:4, 1:3]
433+
@test B == ApproxFunBase.default_BandedMatrix(view(C, 2:4, 1:3))
434+
435+
B = C[1:4, 1:4]
436+
@test B == ApproxFunBase.default_BandedMatrix(view(C, 1:4, 1:4))
437+
438+
B = C[4:4, 4:4]
439+
@test B == ApproxFunBase.default_BandedMatrix(view(C, 4:4, 4:4))
440+
end
441+
end
428442
@testset "Matrix types" begin
429443
F = Multiplication(Fun(PointSpace(1:3)), PointSpace(1:3))
430444
function test_matrices(F)

0 commit comments

Comments
 (0)