Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 8cd1f6b

Browse files
linear combinations of operators tests pass
1 parent aabfced commit 8cd1f6b

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

src/derivative_operators/concretization.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ function BandedMatrices.BandedMatrix(A::DerivativeOperator{T}, N::Int=A.len) whe
5555
end
5656
return L / A.dx^A.derivative_order
5757
end
58+
59+
function Base.convert(::Type{Array},A::DerivativeOperator{T}) where T
60+
Array(A)
61+
end
62+
63+
function Base.convert(::Type{SparseMatrixCSC},A::DerivativeOperator{T}) where T
64+
SparseMatrixCSC(A)
65+
end
66+
67+
function Base.convert(::Type{BandedMatrix},A::DerivativeOperator{T}) where T
68+
BandedMatrix(A)
69+
end
70+
71+
function Base.convert(::Type{AbstractMatrix},A::DerivativeOperator{T}) where T
72+
BandedMatrix(A)
73+
end

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ SafeTestsets
22
OrdinaryDiffEq
33
SpecialFunctions
44
ForwardDiff
5+
FillArrays

test/derivative_operators_interface.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SparseArrays, DiffEqOperators, LinearAlgebra, Random, Test, BandedMatrices
1+
using SparseArrays, DiffEqOperators, LinearAlgebra, Random,
2+
Test, BandedMatrices, FillArrays
23

34
function second_derivative_stencil(N)
45
A = zeros(N,N+2)
@@ -184,23 +185,19 @@ end
184185
@testset "Linear combinations of operators" begin
185186
# Only tests the additional functionality defined in "operator_combination.jl"
186187
N = 10
187-
Random.seed!(0); LA = DiffEqArrayOperator(rand(N,N))
188+
Random.seed!(0); LA = DiffEqArrayOperator(rand(N,N+2))
188189
LD = CenteredDifference(2,2,1.0,N)
189-
@test_broken begin
190-
L = 1.1*LA - 2.2*LD + 3.3*I
191-
# Builds convert(L) the brute-force way
192-
fullL = zeros(N,N)
193-
v = zeros(N)
194-
for i = 1:N
195-
v[i] = 1.0
196-
fullL[:,i] = L*v
197-
v[i] = 0.0
198-
end
199-
@test convert(L) fullL
200-
@test exp(L) exp(fullL)
201-
for p in [1,2,Inf]
202-
@test opnorm(L,p) opnorm(fullL,p)
203-
@test opnormbound(L,p) 1.1*opnorm(LA,p) + 2.2*opnorm(LD,p) + 3.3
204-
end
205-
end
190+
L = 1.1*LA - 2.2*LD + 3.3*Eye(N,N+2)
191+
# Builds convert(L) the brute-force way
192+
fullL = zeros(N,N+2)
193+
v = zeros(N+2)
194+
for i = 1:N+2
195+
v[i] = 1.0
196+
fullL[:,i] = L*v
197+
v[i] = 0.0
198+
end
199+
@test convert(AbstractMatrix,L) fullL
200+
for p in [1,2,Inf]
201+
@test opnorm(L,p) opnorm(fullL,p)
202+
end
206203
end

0 commit comments

Comments
 (0)