@@ -280,6 +280,19 @@ A / A \\ f.(axes(A,1))
280280"""
281281expand (A, f) = A * transform (A, f)
282282
283+ """
284+ expand(v)
285+
286+ finds a natural basis for a quasi-vector and expands
287+ in that basis.
288+ """
289+ function expand (v)
290+ P = basis (v)
291+ ApplyQuasiArray (* , P, P \ v)
292+ end
293+
294+
295+
283296copy (L:: Ldiv{<:AbstractBasisLayout} ) = transform_ldiv (L. A, L. B)
284297# TODO : redesign to use simplifiable(\, A, B)
285298copy (L:: Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector} ) = transform_ldiv (L. A, L. B)
@@ -318,9 +331,19 @@ _factorize(::WeightedBasisLayouts, wS, dims...; kws...) = WeightedFactorization(
318331# #
319332
320333struct ExpansionLayout{Lay} <: AbstractLazyLayout end
321- applylayout (:: Type{typeof(*)} , :: Lay , :: Union{PaddedLayout,AbstractStridedLayout} ) where Lay <: AbstractBasisLayout = ExpansionLayout {Lay} ()
334+ applylayout (:: Type{typeof(*)} , :: Lay , :: Union{PaddedLayout,AbstractStridedLayout,ZerosLayout} ) where Lay <: AbstractBasisLayout = ExpansionLayout {Lay} ()
335+
336+ """
337+ basis(v)
338+
339+ gives a basis for expanding given quasi-vector.
340+ """
341+ basis (v) = basis_layout (MemoryLayout (v), v)
342+
343+ basis_layout (:: ExpansionLayout , v:: ApplyQuasiArray{<:Any,N,typeof(*)} ) where N = v. args[1 ]
344+ basis_layout (lay, v) = basis_axes (axes (v,1 ), v) # allow choosing a basis based on axes
345+ basis_axes (ax, v) = error (" Overload for $ax " )
322346
323- basis (v:: ApplyQuasiArray{<:Any,N,typeof(*)} ) where N = v. args[1 ]
324347coefficients (v:: ApplyQuasiArray{<:Any,N,typeof(*),<:Tuple{Any,Any}} ) where N = v. args[2 ]
325348coefficients (v:: ApplyQuasiArray{<:Any,N,typeof(*),<:Tuple{Any,Any,Vararg{Any}}} ) where N = ApplyArray (* , tail (v. args)... )
326349
333356LazyArrays. _mul_arguments (:: ExpansionLayout , A) = LazyArrays. _mul_arguments (ApplyLayout {typeof(*)} (), A)
334357copy (L:: Ldiv{Bas,<:ExpansionLayout} ) where Bas<: AbstractBasisLayout = copy (Ldiv {Bas,ApplyLayout{typeof(*)}} (L. A, L. B))
335358copy (L:: Mul{<:ExpansionLayout,Lay} ) where Lay = copy (Mul {ApplyLayout{typeof(*)},Lay} (L. A, L. B))
359+ copy (L:: Mul{<:ExpansionLayout,Lay} ) where Lay<: AbstractLazyLayout = copy (Mul {ApplyLayout{typeof(*)},Lay} (L. A, L. B))
336360
337361function _broadcastbasis (:: typeof (+ ), _, _, a, b)
338362 try
@@ -374,8 +398,8 @@ function layout_broadcasted(::Tuple{Vararg{ExpansionLayout}}, ::typeof(+), fs...
374398 P * + (_plus_P_ldiv_Ps_cs (P, Ps, cs)... ) # +((Ref(P) .\ Ps .* cs)...)
375399end
376400
377- function layout_broadcasted (:: NTuple{2 ,ExpansionLayout} , :: typeof (* ), a, f)
378- axes (a, 1 ) == axes (f, 1 ) || throw (DimensionMismatch ())
401+ function layout_broadcasted (:: Tuple{Any ,ExpansionLayout} , :: typeof (* ), a, f)
402+ axes (a)[ 1 ] == axes (f)[ 1 ] || throw (DimensionMismatch ())
379403 P,c = arguments (f)
380404 (a .* P) * c
381405end
@@ -575,24 +599,22 @@ end
575599# ###
576600# sum
577601# ###
578-
579-
580- function __sum (:: SubBasisLayout , Vm, dims)
602+ function sum_layout (:: SubBasisLayout , Vm, dims)
581603 @assert dims == 1
582604 sum (parent (Vm); dims= dims)[:,parentindices (Vm)[2 ]]
583605end
584606
585- __sum (:: AdjointBasisLayout , Vm:: AbstractQuasiMatrix , dims) = permutedims (sum (Vm' ; dims= (isone (dims) ? 2 : 1 )))
607+ sum_layout (:: AdjointBasisLayout , Vm:: AbstractQuasiMatrix , dims) = permutedims (sum (Vm' ; dims= (isone (dims) ? 2 : 1 )))
586608
587609
588- function __sum (:: MappedBasisLayouts , V, dims)
610+ function sum_layout (:: MappedBasisLayouts , V, dims)
589611 kr = basismap (V)
590612 @assert kr isa AbstractAffineQuasiVector
591613 sum (demap (V); dims= dims)/ kr. A
592614end
593615
594- __sum (:: ExpansionLayout , A, dims) = __sum (ApplyLayout {typeof(*)} (), A, dims)
595- __cumsum (:: ExpansionLayout , A, dims) = __cumsum (ApplyLayout {typeof(*)} (), A, dims)
616+ sum_layout (:: ExpansionLayout , A, dims) = sum_layout (ApplyLayout {typeof(*)} (), A, dims)
617+ cumsum_layout (:: ExpansionLayout , A, dims) = cumsum_layout (ApplyLayout {typeof(*)} (), A, dims)
596618
597619include (" basisconcat.jl" )
598620include (" basiskron.jl" )
0 commit comments