|
| 1 | +function threshold!(A::AbstractArray, ϵ) |
| 2 | + for i in eachindex(A) |
| 3 | + if abs(A[i]) < ϵ A[i] = 0 end |
| 4 | + end |
| 5 | + A |
| 6 | +end |
| 7 | + |
| 8 | +using FastTransforms, LinearAlgebra, Random, Test |
| 9 | + |
| 10 | +# The colatitudinal grid (mod π): |
| 11 | +N = 10 |
| 12 | +θ = (0.5:N-0.5)/N |
| 13 | + |
| 14 | +# The longitudinal grid (mod π): |
| 15 | +M = 2*N-1 |
| 16 | +φ = (0:M-1)*2/M |
| 17 | + |
| 18 | +x = [cospi(φ)*sinpi(θ) for θ in θ, φ in φ] |
| 19 | +y = [sinpi(φ)*sinpi(θ) for θ in θ, φ in φ] |
| 20 | +z = [cospi(θ) for θ in θ, φ in φ] |
| 21 | + |
| 22 | +P = plan_sph2fourier(Float64, N) |
| 23 | +PA = plan_sph_analysis(Float64, N, M) |
| 24 | +J = FastTransforms.plan_sph_isometry(Float64, N) |
| 25 | + |
| 26 | + |
| 27 | +f = (x, y, z) -> x^2+y^4+x^2*y*z^3-x*y*z^2 |
| 28 | + |
| 29 | + |
| 30 | +F = f.(x, y, z) |
| 31 | +V = PA*F |
| 32 | +U = threshold!(P\V, 100eps()) |
| 33 | +FastTransforms.execute_sph_yz_axis_exchange!(J, U) |
| 34 | +FR = f.(x, -z, -y) |
| 35 | +VR = PA*FR |
| 36 | +UR = threshold!(P\VR, 100eps()) |
| 37 | +@test U ≈ UR |
| 38 | +norm(U-UR) |
| 39 | + |
| 40 | + |
| 41 | +α, β, γ = 0.123, 0.456, 0.789 |
| 42 | + |
| 43 | +# Isometry built up from ZYZR |
| 44 | +A = [cos(α) -sin(α) 0; sin(α) cos(α) 0; 0 0 1] |
| 45 | +B = [cos(β) 0 -sin(β); 0 1 0; sin(β) 0 cos(β)] |
| 46 | +C = [cos(γ) -sin(γ) 0; sin(γ) cos(γ) 0; 0 0 1] |
| 47 | +R = diagm([1, 1, 1.0]) |
| 48 | +Q = A*B*C*R |
| 49 | + |
| 50 | +# Transform the sampling grid. Note that `Q` is transposed here. |
| 51 | +u = Q[1,1]*x + Q[2,1]*y + Q[3,1]*z |
| 52 | +v = Q[1,2]*x + Q[2,2]*y + Q[3,2]*z |
| 53 | +w = Q[1,3]*x + Q[2,3]*y + Q[3,3]*z |
| 54 | + |
| 55 | +F = f.(x, y, z) |
| 56 | +V = PA*F |
| 57 | +U = threshold!(P\V, 100eps()) |
| 58 | +FastTransforms.execute_sph_rotation!(J, α, β, γ, U) |
| 59 | +FR = f.(u, v, w) |
| 60 | +VR = PA*FR |
| 61 | +UR = threshold!(P\VR, 100eps()) |
| 62 | +@test U ≈ UR |
| 63 | +norm(U-UR) |
| 64 | + |
| 65 | + |
| 66 | +F = f.(x, y, z) |
| 67 | +V = PA*F |
| 68 | +U = threshold!(P\V, 100eps()) |
| 69 | +FastTransforms.execute_sph_polar_reflection!(U) |
| 70 | +FR = f.(x, y, -z) |
| 71 | +VR = PA*FR |
| 72 | +UR = threshold!(P\VR, 100eps()) |
| 73 | +@test U ≈ UR |
| 74 | +norm(U-UR) |
| 75 | + |
| 76 | + |
| 77 | +# Isometry built up from planar reflection |
| 78 | +W = [0.123, 0.456, 0.789] |
| 79 | +H = w -> I - 2/(w'w)*w*w' |
| 80 | +Q = H(W) |
| 81 | + |
| 82 | +# Transform the sampling grid. Note that `Q` is transposed here. |
| 83 | +u = Q[1,1]*x + Q[2,1]*y + Q[3,1]*z |
| 84 | +v = Q[1,2]*x + Q[2,2]*y + Q[3,2]*z |
| 85 | +w = Q[1,3]*x + Q[2,3]*y + Q[3,3]*z |
| 86 | + |
| 87 | +F = f.(x, y, z) |
| 88 | +V = PA*F |
| 89 | +U = threshold!(P\V, 100eps()) |
| 90 | +FastTransforms.execute_sph_reflection!(J, W, U) |
| 91 | +FR = f.(u, v, w) |
| 92 | +VR = PA*FR |
| 93 | +UR = threshold!(P\VR, 100eps()) |
| 94 | +@test U ≈ UR |
| 95 | +norm(U-UR) |
| 96 | + |
| 97 | +F = f.(x, y, z) |
| 98 | +V = PA*F |
| 99 | +U = threshold!(P\V, 100eps()) |
| 100 | +FastTransforms.execute_sph_reflection!(J, (W[1], W[2], W[3]), U) |
| 101 | +FR = f.(u, v, w) |
| 102 | +VR = PA*FR |
| 103 | +UR = threshold!(P\VR, 100eps()) |
| 104 | +@test U ≈ UR |
| 105 | +norm(U-UR) |
| 106 | + |
| 107 | +# Random orthogonal transformation |
| 108 | +Random.seed!(0) |
| 109 | +Q = qr(rand(3, 3)).Q |
| 110 | + |
| 111 | +# Transform the sampling grid, note that `Q` is transposed here. |
| 112 | +u = Q[1,1]*x + Q[2,1]*y + Q[3,1]*z |
| 113 | +v = Q[1,2]*x + Q[2,2]*y + Q[3,2]*z |
| 114 | +w = Q[1,3]*x + Q[2,3]*y + Q[3,3]*z |
| 115 | + |
| 116 | +F = f.(x, y, z) |
| 117 | +V = PA*F |
| 118 | +U = threshold!(P\V, 100eps()) |
| 119 | +FastTransforms.execute_sph_orthogonal_transformation!(J, Q, U) |
| 120 | +FR = f.(u, v, w) |
| 121 | +VR = PA*FR |
| 122 | +UR = threshold!(P\VR, 100eps()) |
| 123 | +@test U ≈ UR |
| 124 | +norm(U-UR) |
0 commit comments