|
1 | 1 | using ApproxFunBase, Test
|
2 | 2 | import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment, dimension, Vec, checkpoints
|
3 |
| -using ApproxFunOrthogonalPolynomials |
4 | 3 | using StaticArrays
|
5 | 4 | using BandedMatrices: rowrange, colrange, BandedMatrix
|
6 | 5 | using LinearAlgebra
|
@@ -254,216 +253,4 @@ using LinearAlgebra
|
254 | 253 | @test (@inferred union(b, b)) == b
|
255 | 254 | end
|
256 | 255 | end
|
257 |
| - |
258 |
| - @testset "ApproxFunOrthogonalPolynomials" begin |
259 |
| - @test (@inferred Fun()) == Fun(x->x, Chebyshev()) |
260 |
| - @test (@inferred norm(Fun())) ≈ norm(Fun(), 2) ≈ √(2/3) # √∫x^2 dx over -1..1 |
261 |
| - |
262 |
| - v = rand(4) |
263 |
| - v2 = transform(NormalizedChebyshev(), v) |
264 |
| - @test itransform(NormalizedChebyshev(), v2) ≈ v |
265 |
| - |
266 |
| - f = @inferred Fun(x->x^2, Chebyshev()) |
267 |
| - v = @inferred coefficients(f, Chebyshev(), Legendre()) |
268 |
| - @test eltype(v) == eltype(coefficients(f)) |
269 |
| - @test v ≈ coefficients(Fun(x->x^2, Legendre())) |
270 |
| - |
271 |
| - # inference check for coefficients |
272 |
| - v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1)) |
273 |
| - @test v ≈ [-0.5, 0, 0.5] |
274 |
| - |
275 |
| - @testset "int coeffs" begin |
276 |
| - f = Fun(Chebyshev(), [0,1]) |
277 |
| - @test f(0.4) ≈ 0.4 |
278 |
| - f = Fun(NormalizedChebyshev(), [0,1]) |
279 |
| - @test f(0.4) ≈ 0.4 * √(2/pi) |
280 |
| - |
281 |
| - f = Fun(Chebyshev(), [1]) |
282 |
| - @test f(0.4) ≈ 1 |
283 |
| - f = Fun(NormalizedChebyshev(), [1]) |
284 |
| - @test f(0.4) ≈ √(1/pi) |
285 |
| - end |
286 |
| - |
287 |
| - @testset "inplace transform" begin |
288 |
| - @testset for sp_c in Any[Legendre(), Chebyshev(), Jacobi(1,2), Jacobi(0.3, 2.3), |
289 |
| - Ultraspherical(1), Ultraspherical(2)] |
290 |
| - @testset for sp in Any[sp_c, NormalizedPolynomialSpace(sp_c)] |
291 |
| - v = rand(10) |
292 |
| - v2 = copy(v) |
293 |
| - @test itransform!(sp, transform!(sp, v)) ≈ v |
294 |
| - @test transform!(sp, v) ≈ transform(sp, v2) |
295 |
| - @test itransform(sp, v) ≈ v2 |
296 |
| - @test itransform!(sp, v) ≈ v2 |
297 |
| - |
298 |
| - # different vector |
299 |
| - p_fwd = ApproxFunBase.plan_transform!(sp, v) |
300 |
| - p_inv = ApproxFunBase.plan_itransform!(sp, v) |
301 |
| - @test p_inv * copy(p_fwd * copy(v)) ≈ v |
302 |
| - end |
303 |
| - end |
304 |
| - end |
305 |
| - |
306 |
| - @testset "conversion" begin |
307 |
| - C12 = Conversion(Chebyshev(), NormalizedLegendre()) |
308 |
| - C21 = Conversion(NormalizedLegendre(), Chebyshev()) |
309 |
| - @test Matrix((C12 * C21)[1:10, 1:10]) ≈ I |
310 |
| - @test Matrix((C21 * C12)[1:10, 1:10]) ≈ I |
311 |
| - |
312 |
| - C12 = Conversion(Chebyshev(), NormalizedPolynomialSpace(Ultraspherical(1))) |
313 |
| - C1C2 = Conversion(Ultraspherical(1), NormalizedPolynomialSpace(Ultraspherical(1))) * |
314 |
| - Conversion(Chebyshev(), Ultraspherical(1)) |
315 |
| - @test Matrix(C12[1:10, 1:10]) ≈ Matrix(C1C2[1:10, 1:10]) |
316 |
| - end |
317 |
| - |
318 |
| - @testset "union" begin |
319 |
| - @test union(Chebyshev(), NormalizedLegendre()) == Jacobi(Chebyshev()) |
320 |
| - @test union(Chebyshev(), Legendre()) == Jacobi(Chebyshev()) |
321 |
| - end |
322 |
| - |
323 |
| - @testset "Fun constructor" begin |
324 |
| - # we make the fun go through somewhat complicated chains of functions |
325 |
| - # that break inference of the space |
326 |
| - # however, the type of coefficients should be inferred correctly. |
327 |
| - f = Fun(Chebyshev(0..1)) |
328 |
| - newfc(f) = coefficients(Fun(Fun(f, Legendre(0..1)), space(f))) |
329 |
| - newvals(f) = values(Fun(Fun(f, Legendre(0..1)), space(f))) |
330 |
| - @test newfc(f) ≈ coefficients(f) |
331 |
| - @test newvals(f) ≈ values(f) |
332 |
| - |
333 |
| - newfc2(f) = coefficients(chop(pad(f, 10))) |
334 |
| - @test newfc2(f) == coefficients(f) |
335 |
| - |
336 |
| - f2 = Fun(space(f), view(Float64[1:4;], :)) |
337 |
| - f3 = Fun(space(f), Float64[1:4;]) |
338 |
| - @test newvals(f2) ≈ values(f3) |
339 |
| - @test values(f2) ≈ values(f3) |
340 |
| - |
341 |
| - # Ensure no trailing zeros |
342 |
| - f = Fun(Ultraspherical(0.5, 0..1)) |
343 |
| - cf = coefficients(f) |
344 |
| - @test findlast(!iszero, cf) == length(cf) |
345 |
| - |
346 |
| - @testset "OneHotVector" begin |
347 |
| - for n in [1, 3, 10_000] |
348 |
| - f = Fun(Chebyshev(), [zeros(n-1); 1]) |
349 |
| - g = ApproxFunBase.basisfunction(Chebyshev(), n) |
350 |
| - @test f == g |
351 |
| - @test f(0.5) == g(0.5) |
352 |
| - end |
353 |
| - end |
354 |
| - end |
355 |
| - |
356 |
| - @testset "multiplication of Funs" begin |
357 |
| - f = Fun(Chebyshev(), Float64[1:101;]) |
358 |
| - g = Fun(Chebyshev(), Float64[1:101;]*im) |
359 |
| - @test f(0.5)*g(0.5) ≈ (f*g)(0.5) |
360 |
| - end |
361 |
| - |
362 |
| - @testset "Multivariate" begin |
363 |
| - @testset for S in Any[Chebyshev(), Legendre()] |
364 |
| - f = Fun(x->ones(2,2), S) |
365 |
| - @test (f+1) * f ≈ (1+f) * f ≈ f^2 + f |
366 |
| - @test (f-1) * f ≈ f^2 - f |
367 |
| - @test (1-f) * f ≈ f - f^2 |
368 |
| - @test f + f ≈ 2f ≈ f*2 |
369 |
| - end |
370 |
| - end |
371 |
| - |
372 |
| - @testset "static coeffs" begin |
373 |
| - f = Fun(Chebyshev(), SA[1,2,3]) |
374 |
| - g = Fun(Chebyshev(), [1,2,3]) |
375 |
| - @test coefficients(f^2) == coefficients(g^2) |
376 |
| - end |
377 |
| - |
378 |
| - @testset "special functions" begin |
379 |
| - for f in Any[Fun(), Fun(-0.5..1), Fun(Segment(1.0+im,2.0+2im))] |
380 |
| - for spfn in Any[sin, cos, exp] |
381 |
| - p = leftendpoint(domain(f)) |
382 |
| - @test spfn(f)(p) ≈ spfn(p) atol=1e-14 |
383 |
| - end |
384 |
| - end |
385 |
| - end |
386 |
| - |
387 |
| - @testset "Derivative" begin |
388 |
| - @test Derivative() == Derivative() |
389 |
| - for d in Any[(), (0..1,)] |
390 |
| - for ST in Any[Chebyshev, Legendre, |
391 |
| - (x...) -> Jacobi(2,2,x...), (x...) -> Jacobi(1.5,2.5,x...)] |
392 |
| - S1 = ST(d...) |
393 |
| - for S in [S1, NormalizedPolynomialSpace(S1)] |
394 |
| - @test Derivative(S) == Derivative(S,1) |
395 |
| - @test Derivative(S)^2 == Derivative(S,2) |
396 |
| - f = Fun(x->x^3, S) |
397 |
| - @test Derivative(S) * f ≈ Fun(x->3x^2, S) |
398 |
| - @test Derivative(S,2) * f ≈ Fun(x->6x, S) |
399 |
| - @test Derivative(S,3) * f ≈ Fun(x->6, S) |
400 |
| - @test Derivative(S,4) * f ≈ zeros(S) |
401 |
| - end |
402 |
| - end |
403 |
| - end |
404 |
| - @test Derivative(Chebyshev()) != Derivative(Chebyshev(), 2) |
405 |
| - @test Derivative(Chebyshev()) != Derivative(Legendre()) |
406 |
| - end |
407 |
| - |
408 |
| - @testset "SubOperator" begin |
409 |
| - D = Derivative(Chebyshev()) |
410 |
| - S = @view D[1:10, 1:10] |
411 |
| - @test rowrange(S, 1) == 2:2 |
412 |
| - @test colrange(S, 2) == 1:1 |
413 |
| - @test (@inferred BandedMatrix(S)) == (@inferred Matrix(S)) |
414 |
| - end |
415 |
| - |
416 |
| - @testset "CachedOperator" begin |
417 |
| - C = cache(Derivative()) |
418 |
| - C = C : Chebyshev() → Ultraspherical(2) |
419 |
| - D = Derivative() : Chebyshev() → Ultraspherical(2) |
420 |
| - @test C[1:2, 1:0] == D[1:2, 1:0] |
421 |
| - @test C[1:10, 1:10] == D[1:10, 1:10] |
422 |
| - for col in 1:5, row in 1:5 |
423 |
| - @test C[row, col] == D[row, col] |
424 |
| - end |
425 |
| - end |
426 |
| - |
427 |
| - @testset "PartialInverseOperator" begin |
428 |
| - @testset "sanity check" begin |
429 |
| - A = UpperTriangular(rand(10, 10)) |
430 |
| - B = inv(A) |
431 |
| - for I in CartesianIndices(B) |
432 |
| - @test B[I] ≈ ApproxFunBase._getindexinv(A, Tuple(I)..., UpperTriangular) |
433 |
| - end |
434 |
| - end |
435 |
| - C = Conversion(Chebyshev(), Ultraspherical(1)) |
436 |
| - P = PartialInverseOperator(C, (0, 6)) |
437 |
| - Iapprox = (P * C)[1:10, 1:10] |
438 |
| - @test all(isone, diag(Iapprox)) |
439 |
| - for k in axes(Iapprox,1), j in k + 1:min(k + bandwidths(P,2), size(Iapprox, 2)) |
440 |
| - @test Iapprox[k,j] ≈ 0 atol=eps(eltype(Iapprox)) |
441 |
| - end |
442 |
| - B = AbstractMatrix(P[1:10, 1:10]) |
443 |
| - @testset for I in CartesianIndices(B) |
444 |
| - @test B[I] ≈ P[Tuple(I)...] rtol=1e-8 atol=eps(eltype(B)) |
445 |
| - end |
446 |
| - end |
447 |
| - |
448 |
| - @testset "istriu/istril" begin |
449 |
| - for D in Any[Derivative(Chebyshev()), |
450 |
| - Conversion(Chebyshev(), Legendre()), |
451 |
| - Multiplication(Fun(Chebyshev()), Chebyshev())] |
452 |
| - D2 = D[1:3, 1:3] |
453 |
| - for f in Any[istriu, istril] |
454 |
| - @test f(D) == f(D2) |
455 |
| - @test f(D') == f(D2') |
456 |
| - end |
457 |
| - end |
458 |
| - end |
459 |
| - |
460 |
| - @testset "inplace ldiv" begin |
461 |
| - @testset for T in [Float32, Float64, ComplexF32, ComplexF64] |
462 |
| - v = rand(T, 4) |
463 |
| - v2 = copy(v) |
464 |
| - ApproxFunBase.ldiv_coefficients!(Conversion(Chebyshev(), Ultraspherical(1)), v) |
465 |
| - @test ApproxFunBase.ldiv_coefficients(Conversion(Chebyshev(), Ultraspherical(1)), v2) ≈ v |
466 |
| - end |
467 |
| - end |
468 |
| - end |
469 | 256 | end
|
0 commit comments