Skip to content

Commit bc799b5

Browse files
authored
fix undef var in matrix conversion error message (#132)
1 parent f8bcd75 commit bc799b5

File tree

2 files changed

+95
-89
lines changed

2 files changed

+95
-89
lines changed

src/Operators/Operator.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,10 @@ end
731731

732732
# TODO: Unify with SubOperator
733733
for TYP in (:RaggedMatrix, :Matrix)
734-
def_TYP = Meta.parse("default_" * string(TYP))
734+
def_TYP = Symbol(string("default_", TYP))
735735
@eval function $TYP(S::Operator)
736736
if isinf(size(S,1)) || isinf(size(S,2))
737-
error("Cannot convert $S to a $TYP")
737+
error("Cannot convert $S to a ", $TYP)
738738
end
739739

740740
if isbanded(S)

test/runtests.jl

+93-87
Original file line numberDiff line numberDiff line change
@@ -95,102 +95,108 @@ end
9595
@test ApproxFunBase.coefficients(f) === v
9696
end
9797

98-
@testset "operator algebra" begin
99-
@testset "Multiplication" begin
100-
sp = PointSpace(1:3)
101-
coeff = [1:3;]
102-
f = Fun(sp, coeff)
103-
for sp2 in Any[(), (sp,)]
104-
a = Multiplication(f, sp2...)
105-
b = Multiplication(f, sp2...)
106-
@test a == b
107-
@test bandwidths(a) == bandwidths(b)
98+
@testset "operator" begin
99+
@testset "operator algebra" begin
100+
@testset "Multiplication" begin
101+
sp = PointSpace(1:3)
102+
coeff = [1:3;]
103+
f = Fun(sp, coeff)
104+
for sp2 in Any[(), (sp,)]
105+
a = Multiplication(f, sp2...)
106+
b = Multiplication(f, sp2...)
107+
@test a == b
108+
@test bandwidths(a) == bandwidths(b)
109+
end
108110
end
109-
end
110-
@testset "TimesOperator" begin
111-
sp = PointSpace(1:3)
112-
coeff = [1:3;]
113-
f = Fun(sp, coeff)
114-
for sp2 in Any[(), (sp,)]
115-
M = Multiplication(f, sp2...)
116-
a = (M * M) * M
117-
b = M * (M * M)
118-
@test a == b
119-
@test bandwidths(a) == bandwidths(b)
111+
@testset "TimesOperator" begin
112+
sp = PointSpace(1:3)
113+
coeff = [1:3;]
114+
f = Fun(sp, coeff)
115+
for sp2 in Any[(), (sp,)]
116+
M = Multiplication(f, sp2...)
117+
a = (M * M) * M
118+
b = M * (M * M)
119+
@test a == b
120+
@test bandwidths(a) == bandwidths(b)
121+
end
122+
@testset "unwrap TimesOperator" begin
123+
M = Multiplication(f)
124+
for ops in Any[Operator{Float64}[M, M * M], Operator{Float64}[M*M, M]]
125+
@test TimesOperator(ops).ops == [M, M, M]
126+
end
127+
end
128+
M = Multiplication(f)
129+
@test coefficients(((M * M) * M) * f) == coefficients((M * M * M) * f)
130+
T = @inferred TimesOperator(M, M)
131+
TM = @inferred TimesOperator(T, M)
132+
MT = @inferred TimesOperator(M, T)
133+
TT = @inferred TimesOperator(T, T)
134+
@test T == M * M
135+
@test TM == T * M
136+
@test MT == M * T
137+
@test T * M == M * T == M * M * M
138+
@test TT == T * T == M * M * M * M
120139
end
121-
@testset "unwrap TimesOperator" begin
140+
@testset "plus operator" begin
141+
c = [1,2,3]
142+
f = Fun(PointSpace(1:3), c)
122143
M = Multiplication(f)
123-
for ops in Any[Operator{Float64}[M, M * M], Operator{Float64}[M*M, M]]
124-
@test TimesOperator(ops).ops == [M, M, M]
144+
@testset for t in [1, 3]
145+
op = M + t * M
146+
@test bandwidths(op) == bandwidths(M)
147+
@test coefficients(op * f) == @. (1+t)*c^2
148+
for op2 in Any[M + M + t * M, op + M]
149+
@test bandwidths(op2) == bandwidths(M)
150+
@test coefficients(op2 * f) == @. (2+t)*c^2
151+
end
152+
op3 = op + op
153+
@test bandwidths(op3) == bandwidths(M)
154+
@test coefficients(op3 * f) == @. 2(1+t)*c^2
155+
156+
f1 = (op + op - op)*f
157+
f2 = ((op + op) - op)*f
158+
f3 = op * f
159+
@test coefficients(f1) == coefficients(f2) == coefficients(f3)
125160
end
161+
Z = ApproxFunBase.ZeroOperator()
162+
@test Z + Z == Z
163+
@test Z + Z + Z == Z
164+
@test Z + Z + Z + Z == Z
126165
end
127-
M = Multiplication(f)
128-
@test coefficients(((M * M) * M) * f) == coefficients((M * M * M) * f)
129-
T = @inferred TimesOperator(M, M)
130-
TM = @inferred TimesOperator(T, M)
131-
MT = @inferred TimesOperator(M, T)
132-
TT = @inferred TimesOperator(T, T)
133-
@test T == M * M
134-
@test TM == T * M
135-
@test MT == M * T
136-
@test T * M == M * T == M * M * M
137-
@test TT == T * T == M * M * M * M
138166
end
139-
@testset "plus operator" begin
140-
c = [1,2,3]
141-
f = Fun(PointSpace(1:3), c)
142-
M = Multiplication(f)
143-
@testset for t in [1, 3]
144-
op = M + t * M
145-
@test bandwidths(op) == bandwidths(M)
146-
@test coefficients(op * f) == @. (1+t)*c^2
147-
for op2 in Any[M + M + t * M, op + M]
148-
@test bandwidths(op2) == bandwidths(M)
149-
@test coefficients(op2 * f) == @. (2+t)*c^2
167+
168+
@testset "operator indexing" begin
169+
@testset "SubOperator" begin
170+
D = Dirichlet(ConstantSpace(0..1))
171+
S = D[:, :]
172+
@test S[1,1] == 1
173+
ax1 = axes(S, 1)
174+
ax2 = axes(S, 2)
175+
inds1 = Any[ax1, StepRange(ax1), :]
176+
inds2 = Any[ax2, StepRange(ax2), :]
177+
@testset for r2 in inds2, r1 in inds1
178+
M = S[r1, r2]
179+
@test M isa AbstractMatrix
180+
@test size(M) == (2,1)
181+
@test all(==(1), M)
182+
end
183+
@testset for r1 in inds1
184+
V = S[r1, 1]
185+
@test V isa AbstractVector
186+
@test size(V) == (2,)
187+
@test all(==(1), V)
188+
end
189+
@testset for r2 in inds2
190+
V = S[1, r2]
191+
@test V isa AbstractVector
192+
@test size(V) == (1,)
193+
@test all(==(1), V)
150194
end
151-
op3 = op + op
152-
@test bandwidths(op3) == bandwidths(M)
153-
@test coefficients(op3 * f) == @. 2(1+t)*c^2
154-
155-
f1 = (op + op - op)*f
156-
f2 = ((op + op) - op)*f
157-
f3 = op * f
158-
@test coefficients(f1) == coefficients(f2) == coefficients(f3)
159195
end
160-
Z = ApproxFunBase.ZeroOperator()
161-
@test Z + Z == Z
162-
@test Z + Z + Z == Z
163-
@test Z + Z + Z + Z == Z
164196
end
165-
end
166-
167-
@testset "operator indexing" begin
168-
@testset "SubOperator" begin
169-
D = Dirichlet(ConstantSpace(0..1))
170-
S = D[:, :]
171-
@test S[1,1] == 1
172-
ax1 = axes(S, 1)
173-
ax2 = axes(S, 2)
174-
inds1 = Any[ax1, StepRange(ax1), :]
175-
inds2 = Any[ax2, StepRange(ax2), :]
176-
@testset for r2 in inds2, r1 in inds1
177-
M = S[r1, r2]
178-
@test M isa AbstractMatrix
179-
@test size(M) == (2,1)
180-
@test all(==(1), M)
181-
end
182-
@testset for r1 in inds1
183-
V = S[r1, 1]
184-
@test V isa AbstractVector
185-
@test size(V) == (2,)
186-
@test all(==(1), V)
187-
end
188-
@testset for r2 in inds2
189-
V = S[1, r2]
190-
@test V isa AbstractVector
191-
@test size(V) == (1,)
192-
@test all(==(1), V)
193-
end
197+
@testset "conversion to a matrix" begin
198+
M = Multiplication(Fun(identity, PointSpace(1:3)))
199+
@test_throws ErrorException Matrix(M)
194200
end
195201
end
196202

0 commit comments

Comments
 (0)