Skip to content

Commit 1ba7d0e

Browse files
committed
Move over tests
1 parent 1134062 commit 1ba7d0e

File tree

2 files changed

+210
-11
lines changed

2 files changed

+210
-11
lines changed

src/ApproxFunFourier.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,15 @@ end
608608
Space(d::PeriodicCurve{S}) where {S<:Fourier} = Fourier(d)
609609
Space(d::PeriodicCurve{S}) where {S<:Laurent} = Laurent(d)
610610

611+
function Fun(T::ToeplitzOperator)
612+
if length(T.nonnegative)==1
613+
Fun(Taylor(),[T.nonnegative;T.negative])
614+
elseif length(T.negative)==0
615+
Fun(Hardy{false}(),T.nonnegative)
616+
else
617+
Fun(Laurent(Circle()),interlace(T.nonnegative,T.negative))
618+
end
619+
end
620+
621+
611622
end #module

test/runtests.jl

Lines changed: 199 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ApproxFunFourier, ApproxFunBase, Test, BlockArrays, BlockBandedMatrices, SpecialFunctions, LinearAlgebra
22
import ApproxFunBase: testspace, testtransforms, testmultiplication,
3-
testbandedoperator, testcalculus, Block, Vec, testfunctional
3+
testbandedoperator, testblockbandedoperator, testbandedblockbandedoperator, testcalculus, Block, Vec, testfunctional
44
import SpecialFunctions: factorial
55

66
@testset "Periodic Domains" begin
@@ -313,16 +313,6 @@ end
313313
@test f(cos(0.1),sin(0.1)) exp(-cos(0.1)-2cos(sin(0.1)))
314314
end
315315

316-
@testset "Fourier Vector" begin
317-
a = [1 2; 3 4]
318-
f = Fun->[sin(θ),sin(2θ)],Fourier())
319-
@test (a*f)(0.1) a*f(0.1)
320-
@test Fun(a)*f a*f
321-
@test Fun(a*Array(f)) a*f
322-
@test norm(f) sqrt(2π)
323-
@test norm(f,2) sqrt(2π)
324-
end
325-
326316
@testset "Operators" begin
327317
d=PeriodicSegment(0.,2π)
328318
a=Fun(t-> 1+sin(cos(10t)),d)
@@ -361,6 +351,14 @@ end
361351
u=L\f
362352

363353
@test norm(L*u-f) < 1000eps()
354+
355+
@time for M in (Multiplication(Fun(CosSpace(),[1.]),CosSpace()),
356+
Multiplication(Fun(CosSpace(),[1.]),SinSpace()),
357+
Multiplication(Fun(SinSpace(),[1.]),SinSpace()),
358+
Multiplication(Fun(SinSpace(),[1.]),CosSpace()),
359+
Derivative(SinSpace()),Derivative(CosSpace()))
360+
testbandedoperator(M)
361+
end
364362
end
365363

366364
@testset "Integral equations" begin
@@ -385,3 +383,193 @@ end
385383
@test L[1,1] == 0
386384
end
387385

386+
@testset "Piecewise + Constant" begin
387+
Γ=Circle() Circle(0.0,0.4)
388+
o=ones(Γ)
389+
@test o(1.) 1.0
390+
@test o(0.4) 1.0
391+
392+
@time G=Fun(z->in(z,component(Γ,2)) ? [1 0; -1/z 1] : [z 0; 0 1/z],Γ)
393+
@test (G-I)(exp(0.1im)) (G(exp(0.1im))-I)
394+
end
395+
396+
@testset "Array" begin
397+
@testset "Fourier Vector" begin
398+
a = [1 2; 3 4]
399+
f = Fun->[sin(θ),sin(2θ)],Fourier())
400+
@test (a*f)(0.1) a*f(0.1)
401+
@test Fun(a)*f a*f
402+
@test Fun(a*Array(f)) a*f
403+
@test norm(f) sqrt(2π)
404+
@test norm(f,2) sqrt(2π)
405+
end
406+
407+
@testset "CosSpace Vector" begin
408+
a = [1 2; 3 4]
409+
f = Fun->[1,cos(θ)],CosSpace())
410+
@test (a*f)(0.1) [1+2cos(0.1); 3+4cos(0.1)]
411+
@test (a*f)(0.1) a*f(0.1)
412+
@test Fun(a)*f a*f
413+
@test Fun(a*Array(f)) a*f
414+
end
415+
416+
@testset "CosSpace Matrix" begin
417+
a = [1 2; 3 4]
418+
m = Fun->[1 cos(θ); cos(2θ) cos(cos(θ))],CosSpace())
419+
@test (a*m)(0.1) a*m(0.1)
420+
@test (m*a)(0.1) m(0.1)*a
421+
@test Fun(a)*m a*m
422+
@test Fun(a*Array(m)) a*m
423+
424+
@test (a+m)(0.1) a+m(0.1)
425+
@test (m+a)(0.1) m(0.1)+a
426+
427+
@test (m+I)(0.1) m(0.1)+I
428+
end
429+
430+
@testset "SinSpace Vector" begin
431+
a = [1 2; 3 4]
432+
f = Fun->[sin(θ),sin(2θ)],SinSpace())
433+
@test (a*f)(0.1) a*f(0.1)
434+
@test Fun(a)*f a*f
435+
@test Fun(a*Array(f)) a*f
436+
437+
@test all(sp -> sp isa SinSpace, space(a*f).spaces)
438+
end
439+
440+
@testset "CosSpace Matrix" begin
441+
a = [1 2; 3 4]
442+
m = Fun->[sin(3θ) sin(θ); sin(2θ) sin(sin(θ))],SinSpace())
443+
@test (a*m)(0.1) a*m(0.1)
444+
@test (m*a)(0.1) m(0.1)*a
445+
@test Fun(a)*m a*m
446+
@test Fun(a*Array(m)) a*m
447+
448+
@test all(sp -> sp isa SinSpace, space(a*m).spaces)
449+
450+
@test (a+m)(0.1) a+m(0.1)
451+
@test (m+a)(0.1) m(0.1)+a
452+
453+
@test (m+I)(0.1) m(0.1)+I
454+
end
455+
456+
@testset "Two circles" begin
457+
Γ = Circle() Circle(0.5)
458+
459+
f = Fun(z -> in(z,component(Γ,2)) ? 1 : z,Γ)
460+
@test f(exp(0.1im)) exp(0.1im)
461+
@test f(0.5exp(0.1im)) 1
462+
463+
G = Fun(z -> in(z,component(Γ,2)) ? [1 -z^(-1); 0 1] :
464+
[z 0; 0 z^(-1)], Γ);
465+
466+
@test G(exp(0.1im)) [exp(0.1im) 0 ; 0 exp(-0.1im)]
467+
@test G(0.5exp(0.1im)) [1 -2exp(-0.1im) ; 0 1]
468+
469+
G1=Fun(Array(G)[:,1])
470+
471+
@test G1(exp(0.1im)) [exp(0.1im),0.]
472+
@test G1(0.5exp(0.1im)) [1,0.]
473+
474+
M = Multiplication(G, space(G1))
475+
testblockbandedoperator(M)
476+
477+
for z in (0.5exp(0.1im),exp(0.2im))
478+
@test G[1,1](z) G[1](z)
479+
@test (M.op.ops[1,1]*G1[1])(z) M.f[1,1](z)*G1[1](z)
480+
@test (M.op.ops[2,1]*G1[1])(z) M.f[2,1](z)*G1[1](z)
481+
@test (M.op.ops[1,2]*G1[2])(z) M.f[1,2](z)*G1[2](z)
482+
@test (M.op.ops[2,2]*G1[2])(z) M.f[2,2](z)*G1[2](z)
483+
end
484+
485+
u = M*G1
486+
@test norm(u(exp(.1im))-[exp(.2im),0])<100eps()
487+
@test norm(u(.5exp(.1im))-[1,0])<100eps()
488+
end
489+
490+
@testset "Circle" begin
491+
G = Fun(z->[-1 -3; -3 -1]/z +
492+
[ 2 2; 1 -3] +
493+
[ 2 -1; 1 2]*z, Circle())
494+
495+
@test G[1,1](exp(0.1im)) == G(exp(0.1im))[1,1]
496+
497+
= Array((G-I)[:,1])
498+
F = (G-I)[:,1]
499+
500+
@test Fun(F) F
501+
502+
@test F(exp(0.1im)) [-exp(-0.1im)+1+2exp(0.1im);-3exp(-0.1im)+1+1exp(0.1im)]
503+
@test Fun(F̃,space(F))(exp(0.1im)) [-exp(-0.1im)+1+2exp(0.1im);-3exp(-0.1im)+1+1exp(0.1im)]
504+
505+
@test coefficients(F̃,space(F)) == F.coefficients
506+
@test Fun(F̃,space(F)) == F
507+
508+
@test F == Fun(vec(F),space(F))
509+
510+
@test inv(G(exp(0.1im))) inv(G)(exp(0.1im))
511+
512+
@test Fun(Matrix(I,2,2),space(G))(exp(0.1im)) Matrix(I,2,2)
513+
@test Fun(I,space(G))(exp(0.1im)) Matrix(I,2,2)
514+
end
515+
end
516+
517+
@testset "Taylor()^2, checks bug in type of plan_transform" begin
518+
f = Fun((x,y)->exp((x-0.1)*cos(y-0.2)),Taylor()^2)
519+
@test f(0.2,0.3) exp(0.1*cos(0.1))
520+
end
521+
522+
@testset "Periodic Poisson" begin
523+
d=PeriodicSegment()^2
524+
S=Space(d)
525+
526+
f=Fun((x,y)->exp(-10(sin(x/2)^2+sin(y/2)^2)),d)
527+
A=Laplacian(d)+0.1I
528+
testbandedblockbandedoperator(A)
529+
@time u=A\f
530+
@test u(.1,.2) u(.2,.1)
531+
@test (lap(u)+.1u-f)|>coefficients|>norm < 1000000eps()
532+
end
533+
534+
@testset "Low Rank" begin
535+
## Periodic
536+
f=LowRankFun((x,y)->cos(x)*sin(y),PeriodicSegment(),PeriodicSegment())
537+
@test f(.1,.2) cos(.1)*sin(.2)
538+
539+
f=LowRankFun((x,y)->cos(cos(x)+sin(y)),PeriodicSegment(),PeriodicSegment())
540+
@test f(.1,.2) cos(cos(.1)+sin(.2))
541+
@test norm(Float64[cos(cos(x)+sin(y)) for x=ApproxFunBase.vecpoints(f,1),y=ApproxFunBase.vecpoints(f,2)]-values(f))<10000eps()
542+
543+
f=ProductFun((x,y)->cos(cos(x)+sin(y)),PeriodicSegment()^2)
544+
@test f(.1,.2) cos(cos(.1)+sin(.2))
545+
x,y=points(f)
546+
@test norm(Float64[cos(cos(x[k,j])+sin(y[k,j])) for k=1:size(f,1),j=1:size(f,2)]-values(f))<10000eps()
547+
548+
d=PeriodicSegment()^2
549+
f=ProductFun((x,y)->exp(-10(sin(x/2)^2+sin(y/2)^2)),d)
550+
@test (transpose(f)-f|>coefficients|>norm)< 1000eps()
551+
end
552+
553+
@testset "off domain evaluate" begin
554+
g = Fun(1, PeriodicSegment(Vec(0,-1) , Vec(π,-1)))
555+
@test g(0.1,-1) 1
556+
@test g(0.1,1) 0
557+
end
558+
559+
560+
@testset "PeriodicLine" begin
561+
d=PeriodicLine()
562+
D=Derivative(d)
563+
564+
f = Fun(x->sech(x-0.1),d,200)
565+
@test f(1.) sech(1-0.1)
566+
567+
f=Fun(x->sech(x-0.1),d)
568+
@test f(1.) sech(1-0.1)
569+
570+
@test ((D*f)(.2),-0.0991717226583897;atol=100000eps())
571+
@test ((D^2*f)(.2),-0.9752522555114987;atol=1000000eps())
572+
573+
f=Fun(z->2exp(z^2),PeriodicLine(0./2))
574+
@test f(1.1im) 2exp(-1.1^2)
575+
end

0 commit comments

Comments
 (0)