@@ -36,7 +36,8 @@ import InfiniteLinearAlgebra: chop!, chop, choplength, compatible_resize!
3636import ContinuumArrays: Basis, Weight, basis, @simplify , Identity, AbstractAffineQuasiVector, ProjectionFactorization,
3737 inbounds_getindex, grid, plotgrid, transform_ldiv, TransformFactorization, QInfAxes, broadcastbasis, ExpansionLayout, basismap,
3838 AffineQuasiVector, AffineMap, WeightLayout, AbstractWeightedBasisLayout, WeightedBasisLayout, WeightedBasisLayouts, demap, AbstractBasisLayout, BasisLayout,
39- checkpoints, weight, unweighted, MappedBasisLayouts, __sum, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, _broadcastbasis
39+ checkpoints, weight, unweighted, MappedBasisLayouts, __sum, invmap, plan_ldiv, layout_broadcasted, MappedBasisLayout, SubBasisLayout, _broadcastbasis,
40+ plan_transform, plan_grid_transform
4041import FastTransforms: Λ, forwardrecurrence, forwardrecurrence!, _forwardrecurrence!, clenshaw, clenshaw!,
4142 _forwardrecurrence_next, _clenshaw_next, check_clenshaw_recurrences, ChebyshevGrid, chebyshevpoints, Plan
4243
@@ -52,20 +53,13 @@ export OrthogonalPolynomial, Normalized, orthonormalpolynomial, LanczosPolynomia
5253 ∞, Derivative, .. , Inclusion,
5354 chebyshevt, chebyshevu, legendre, jacobi, ultraspherical,
5455 legendrep, jacobip, ultrasphericalc, laguerrel,hermiteh, normalizedjacobip,
55- jacobimatrix, jacobiweight, legendreweight, chebyshevtweight, chebyshevuweight, Weighted, PiecewiseInterlace
56+ jacobimatrix, jacobiweight, legendreweight, chebyshevtweight, chebyshevuweight, Weighted, PiecewiseInterlace, plan_transform
5657
5758
5859import Base: oneto
5960
6061
6162include (" interlace.jl" )
62-
63-
64- cardinality (:: FullSpace{<:AbstractFloat} ) = ℵ₁
65- cardinality (:: EuclideanDomain ) = ℵ₁
66- cardinality (:: Union{DomainSets.RealNumbers,DomainSets.ComplexNumbers} ) = ℵ₁
67- cardinality (:: Union{DomainSets.Integers,DomainSets.Rationals,DomainSets.NaturalNumbers} ) = ℵ₀
68-
6963include (" standardchop.jl" )
7064include (" adaptivetransform.jl" )
7165
@@ -95,9 +89,9 @@ _equals(::MappedOPLayout, ::MappedOPLayout, P, Q) = demap(P) == demap(Q) && basi
9589_equals (:: MappedOPLayout , :: MappedBasisLayouts , P, Q) = demap (P) == demap (Q) && basismap (P) == basismap (Q)
9690_equals (:: MappedBasisLayouts , :: MappedOPLayout , P, Q) = demap (P) == demap (Q) && basismap (P) == basismap (Q)
9791
98- _broadcastbasis (:: typeof (+ ), :: MappedOPLayout , :: MappedOPLayout , P, Q) where {L,M} = _broadcastbasis (+ , MappedBasisLayout (), MappedBasisLayout (), P, Q)
99- _broadcastbasis (:: typeof (+ ), :: MappedOPLayout , M:: MappedBasisLayout , P, Q) where L = _broadcastbasis (+ , MappedBasisLayout (), M, P, Q)
100- _broadcastbasis (:: typeof (+ ), L:: MappedBasisLayout , :: MappedOPLayout , P, Q) where M = _broadcastbasis (+ , L, MappedBasisLayout (), P, Q)
92+ _broadcastbasis (:: typeof (+ ), :: MappedOPLayout , :: MappedOPLayout , P, Q) = _broadcastbasis (+ , MappedBasisLayout (), MappedBasisLayout (), P, Q)
93+ _broadcastbasis (:: typeof (+ ), :: MappedOPLayout , M:: MappedBasisLayout , P, Q) = _broadcastbasis (+ , MappedBasisLayout (), M, P, Q)
94+ _broadcastbasis (:: typeof (+ ), L:: MappedBasisLayout , :: MappedOPLayout , P, Q) = _broadcastbasis (+ , L, MappedBasisLayout (), P, Q)
10195__sum (:: MappedOPLayout , A, dims) = __sum (MappedBasisLayout (), A, dims)
10296
10397# demap to avoid Golub-Welsch fallback
@@ -231,11 +225,6 @@ function recurrencecoefficients(C::SubQuasiArray{T,2,<:Any,<:Tuple{AbstractAffin
231225 A * kr. A, A* kr. b + B, C
232226end
233227
234-
235- _vec (a) = vec (a)
236- _vec (a:: InfiniteArrays.ReshapedArray ) = _vec (parent (a))
237- _vec (a:: Adjoint{<:Any,<:AbstractVector} ) = a'
238-
239228include (" clenshaw.jl" )
240229include (" ratios.jl" )
241230include (" normalized.jl" )
@@ -270,24 +259,76 @@ function golubwelsch(V::SubQuasiArray)
270259 x,w
271260end
272261
273- function factorize (L:: SubQuasiArray{T,2,<:Normalized,<:Tuple{Inclusion,OneTo}} , dims... ; kws... ) where T
274- x,w = golubwelsch (L)
275- TransformFactorization (x, L[x,:]' * Diagonal (w))
262+ """
263+ MulPlan(matrix, dims)
264+
265+ Takes a matrix and supports it applied to different dimensions.
266+ """
267+ struct MulPlan{T, Fact, Dims} # <: Plan{T} We don't depend on AbstractFFTs
268+ matrix:: Fact
269+ dims:: Dims
276270end
277271
272+ MulPlan (fact, dims) = MulPlan {eltype(fact), typeof(fact), typeof(dims)} (fact, dims)
273+
274+ function * (P:: MulPlan{<:Any,<:Any,Int} , x:: AbstractVector )
275+ @assert P. dims == 1
276+ P. matrix * x
277+ end
278278
279- function factorize (L:: SubQuasiArray{T,2,<:OrthogonalPolynomial,<:Tuple{Inclusion,OneTo}} , dims... ; kws... ) where T
280- Q = Normalized (parent (L))[parentindices (L)... ]
281- D = L \ Q
282- F = factorize (Q, dims... ; kws... )
283- TransformFactorization (F. grid, D* F. plan)
279+ function * (P:: MulPlan{<:Any,<:Any,Int} , X:: AbstractMatrix )
280+ if P. dims == 1
281+ P. matrix * X
282+ else
283+ @assert P. dims == 2
284+ permutedims (P. matrix * permutedims (X))
285+ end
284286end
285287
286- function factorize (L:: SubQuasiArray{T,2,<:OrthogonalPolynomial,<:Tuple{<:Inclusion,<:AbstractUnitRange}} , dims... ; kws... ) where T
287- _,jr = parentindices (L)
288- ProjectionFactorization (factorize (parent (L)[:,oneto (maximum (jr))], dims... ; kws... ), jr)
288+ function * (P:: MulPlan{<:Any,<:Any,Int} , X:: AbstractArray{<:Any,3} )
289+ Y = similar (X)
290+ if P. dims == 1
291+ for j in axes (X,3 )
292+ Y[:,:,j] = P. matrix * X[:,:,j]
293+ end
294+ elseif P. dims == 2
295+ for k in axes (X,1 )
296+ Y[k,:,:] = P. matrix * X[k,:,:]
297+ end
298+ else
299+ @assert P. dims == 3
300+ for k in axes (X,1 ), j in axes (X,2 )
301+ Y[k,j,:] = P. matrix * X[k,j,:]
302+ end
303+ end
304+ Y
289305end
290306
307+ function * (P:: MulPlan , X:: AbstractArray )
308+ for d in P. dims
309+ X = MulPlan (P. matrix, d) * X
310+ end
311+ X
312+ end
313+
314+ * (A:: AbstractMatrix , P:: MulPlan ) = MulPlan (A* P. matrix, P. dims)
315+
316+
317+ function plan_grid_transform (Q:: Normalized , arr, dims= 1 : ndims (arr))
318+ L = Q[:,OneTo (size (arr,1 ))]
319+ x,w = golubwelsch (L)
320+ x, MulPlan (L[x,:]' * Diagonal (w), dims)
321+ end
322+
323+ function plan_grid_transform (P:: OrthogonalPolynomial , arr, dims... )
324+ Q = Normalized (P)
325+ x, A = plan_grid_transform (Q, arr, dims... )
326+ n = size (arr,1 )
327+ D = (P \ Q)[1 : n, 1 : n]
328+ x, D * A
329+ end
330+
331+
291332function \ (A:: SubQuasiArray{<:Any,2,<:OrthogonalPolynomial} , B:: SubQuasiArray{<:Any,2,<:OrthogonalPolynomial} )
292333 axes (A,1 ) == axes (B,1 ) || throw (DimensionMismatch ())
293334 _,jA = parentindices (A)
0 commit comments