Skip to content

Commit 6cc83c9

Browse files
authored
Add tests for multivariate fun (#130)
* Add tests for multivariate fun * chop in ProductFun * disable some tests * chop test for small coeff
1 parent 85f6b8b commit 6cc83c9

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

test/MultivariateTest.jl

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ import Base: oneto
8484
F = Fun(L)
8585
@test L(0.1, 0.2) F(0.1, 0.2)
8686

87+
x = Fun(); y = x;
8788
D1 = Derivative(space(L), [1,0])
8889
D2 = Derivative(space(L), [0,1])
89-
@test (D2 * L)(0.1, 0.2) Fun()(0.1)
90-
@test (D1 * L)(0.1, 0.2) Fun()(0.2)
91-
@test (D1[L] * L)(0.1, 0.2) 2Fun()(0.1) * Fun()(0.2)^2
92-
@test ((Derivative() I) * L)(0.1, 0.2) Fun()(0.2)
93-
@test ((I Derivative()) * L)(0.1, 0.2) Fun()(0.1)
90+
@test (D2 * L)(0.1, 0.2) x(0.1)
91+
@test (D1 * L)(0.1, 0.2) y(0.2)
92+
# @test ((L * D1) * L)(0.1, 0.2) ≈ x(0.1) * (y(0.2))^2
93+
# @test ((L * D2) * L)(0.1, 0.2) ≈ (x(0.1))^2 * y(0.2)
94+
@test (D1[L] * L)(0.1, 0.2) 2x(0.1) * y(0.2)^2
95+
@test ((Derivative() I) * L)(0.1, 0.2) y(0.2)
96+
@test ((I Derivative()) * L)(0.1, 0.2) x(0.1)
9497
end
9598

9699

@@ -335,14 +338,40 @@ import Base: oneto
335338
@test F(1.5,1.5im) hankelh1(0,10abs(1.5im-1.5))
336339

337340
P = ProductFun((x,y)->x*y, Chebyshev() Chebyshev())
338-
@test Evaluation(1) * P == Fun()
339-
@test Evaluation(-1) * P == -Fun()
341+
x = Fun(); y = x;
342+
@test Evaluation(1) * P == x
343+
@test Evaluation(-1) * P == -x
340344
D1 = Derivative(Chebyshev() Chebyshev(), [1,0])
341345
D2 = Derivative(Chebyshev() Chebyshev(), [0,1])
342-
@test (D2 * P)(0.1, 0.2) Fun()(0.1)
343-
@test (D1 * P)(0.1, 0.2) Fun()(0.2)
344-
@test ((I Derivative()) * P)(0.1, 0.2) Fun()(0.1)
345-
@test ((Derivative() I) * P)(0.1, 0.2) Fun()(0.2)
346+
@test (D2 * P)(0.1, 0.2) x(0.1)
347+
@test (D1 * P)(0.1, 0.2) y(0.2)
348+
# @test ((P * D1) * P)(0.1, 0.2) ≈ x(0.1) * (y(0.2))^2
349+
# @test ((P * D2) * P)(0.1, 0.2) ≈ (x(0.1))^2 * y(0.2)
350+
@test ((I Derivative()) * P)(0.1, 0.2) x(0.1)
351+
@test ((Derivative() I) * P)(0.1, 0.2) y(0.2)
352+
353+
# MultivariateFun methods
354+
f = invoke(*, Tuple{KroneckerOperator, ApproxFunBase.MultivariateFun},
355+
Derivative() I, P)
356+
@test f(0.1, 0.2) y(0.2)
357+
O = invoke(*, Tuple{ApproxFunBase.MultivariateFun, KroneckerOperator},
358+
P, Derivative() I)
359+
@test (O * Fun(P))(0.1, 0.2) x(0.1) * (y(0.2))^2
360+
361+
@testset "chopping" begin
362+
M = [0 0 0; 0 1 0; 0 0 1]
363+
P = ProductFun(M, Chebyshev() Chebyshev(), chopping = true)
364+
@test coefficients(P) == M
365+
M = [0 0 0; 0 1 0; 0 0 1e-100]
366+
P = ProductFun(M, Chebyshev() Chebyshev(), chopping = true)
367+
@test coefficients(P) == @view M[1:2, 1:2]
368+
M = [0 0 0; 0 1 0; 0 0 0]
369+
P = ProductFun(M, Chebyshev() Chebyshev(), chopping = true)
370+
@test coefficients(P) == @view M[1:2, 1:2]
371+
# M = zeros(3,3)
372+
# P = ProductFun(M, Chebyshev() ⊗ Chebyshev(), chopping = true)
373+
# @test all(iszero, coefficients(P))
374+
end
346375
end
347376

348377
@testset "Functional*Fun" begin

0 commit comments

Comments
 (0)