@@ -30,56 +30,53 @@ combine_mul_styles(::AbstractAdjointBasisLayout) = LazyQuasiArrayApplyStyle()
3030ApplyStyle (:: typeof (pinv), :: Type{<:Basis} ) = LazyQuasiArrayApplyStyle ()
3131pinv (J:: Basis ) = apply (pinv,J)
3232
33- _multup (a:: Tuple ) = Mul (a... )
34- _multup (a) = a
35-
3633
3734function == (A:: Basis , B:: Basis )
3835 axes (A) == axes (B) && throw (ArgumentError (" Override == to compare bases of type $(typeof (A)) and $(typeof (B)) " ))
3936 false
4037end
4138
39+ @inline quasildivapplystyle (:: AbstractBasisLayout , :: AbstractBasisLayout ) = LdivApplyStyle ()
40+ @inline quasildivapplystyle (:: AbstractBasisLayout , _) = LdivApplyStyle ()
41+ @inline quasildivapplystyle (_, :: AbstractBasisLayout ) = LdivApplyStyle ()
4242
43- ApplyStyle (:: typeof (\ ), :: Type{<:Basis} , :: Type{<:AbstractQuasiMatrix} ) = LdivApplyStyle ()
44- ApplyStyle (:: typeof (\ ), :: Type{<:Basis} , :: Type{<:AbstractQuasiVector} ) = LdivApplyStyle ()
45- ApplyStyle (:: typeof (\ ), :: Type{<:SubQuasiArray{<:Any,2,<:Basis}} , :: Type{<:AbstractQuasiMatrix} ) = LdivApplyStyle ()
46- ApplyStyle (:: typeof (\ ), :: Type{<:SubQuasiArray{<:Any,2,<:Basis}} , :: Type{<:AbstractQuasiVector} ) = LdivApplyStyle ()
4743
48- copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)}} ) = + (broadcast (\ ,Ref (L. A),arguments (L. B))... )
49- copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)},<:Any,<:AbstractQuasiVector} ) =
50- + ( broadcast ( \ , Ref ( L. A), arguments ( L. B)) ... )
44+ @inline copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)}} ) = + (broadcast (\ ,Ref (L. A),arguments (L. B))... )
45+ @inline copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)},<:Any,<:AbstractQuasiVector} ) =
46+ transform_ldiv ( L. A, L. B)
5147
52- function copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(-)}} )
48+ @inline function copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(-)}} )
5349 a,b = arguments (L. B)
5450 (L. A\ a)- (L. A\ b)
5551end
5652
57- function copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(-)},<:Any,<:AbstractQuasiVector} )
58- a,b = arguments (L. B)
59- (L. A\ a)- (L. A\ b)
60- end
53+ @inline copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(-)},<:Any,<:AbstractQuasiVector} ) =
54+ transform_ldiv (L. A, L. B)
6155
6256function copy (P:: Ldiv{BasisLayout,BasisLayout} )
6357 A, B = P. A, P. B
64- A == B || throw (ArgumentError (" Override materialize for $(typeof (A)) \\ $(typeof (B)) " ))
65- Eye (size (A,2 ))
58+ A == B || throw (ArgumentError (" Override copy for $(typeof (A)) \\ $(typeof (B)) " ))
59+ SquareEye {eltype(P)} (size (A,2 ))
6660end
6761function copy (P:: Ldiv{SubBasisLayout,SubBasisLayout} )
6862 A, B = P. A, P. B
6963 (parent (A) == parent (B) && parentindices (A) == parentindices (B)) ||
70- throw (ArgumentError (" Override materialize for $(typeof (A)) \\ $(typeof (B)) " ))
71- Eye (size (A,2 ))
64+ throw (ArgumentError (" Override copy for $(typeof (A)) \\ $(typeof (B)) " ))
65+ SquareEye {eltype(P)} (size (A,2 ))
7266end
7367
74- function copy (P:: Ldiv{MappedBasisLayout,MappedBasisLayout} )
68+ @inline function copy (P:: Ldiv{MappedBasisLayout,MappedBasisLayout} )
7569 A, B = P. A, P. B
7670 demap (A)\ demap (B)
7771end
78- # function copy(P::Ldiv{MappedBasisLayout,SubBasisLayout})
79- # A, B = P.A, P.B
80- # # use lazy_getindex to avoid sparse arrays
81- # lazy_getindex(parent(A)\parent(B),:,parentindices(B)[2])
82- # end
72+
73+ @inline copy (L:: Ldiv{BasisLayout,SubBasisLayout} ) = apply (\ , L. A, ApplyQuasiArray (L. B))
74+ @inline function copy (L:: Ldiv{SubBasisLayout,BasisLayout} )
75+ P = parent (L. A)
76+ kr, jr = parentindices (L. A)
77+ lazy_getindex (apply (\ , P, L. B), jr, :) # avoid sparse arrays
78+ end
79+
8380
8481for Bas1 in (:Basis , :WeightedBasis ), Bas2 in (:Basis , :WeightedBasis )
8582 @eval == (A:: SubQuasiArray{<:Any,2,<:$Bas1} , B:: SubQuasiArray{<:Any,2,<:$Bas2} ) =
8885
8986
9087# expansion
91- grid (P) = error (" Overload Grid" )
88+ _grid (_, P) = error (" Overload Grid" )
89+ _grid (:: MappedBasisLayout , P) = igetindex .(Ref (parentindices (P)[1 ]), grid (demap (P)))
90+ _grid (:: SubBasisLayout , P) = grid (parent (P))
91+ grid (P) = _grid (MemoryLayout (typeof (P)), P)
92+
9293function transform (L)
9394 p = grid (L)
9495 p,L[p,:]
9596end
9697
97- function copy (L :: Ldiv{<:AbstractBasisLayout,<:Any,<:Any,<:AbstractQuasiVector} )
98- p,T = transform (L . A)
99- T \ L . B[p]
98+ function transform_ldiv (A, B, _ )
99+ p,T = transform (A)
100+ T \ convert (Array, B[p])
100101end
101102
103+ transform_ldiv (A, B) = transform_ldiv (A, B, axes (A))
104+
105+ copy (L:: Ldiv{<:AbstractBasisLayout,<:Any,<:Any,<:AbstractQuasiVector} ) =
106+ transform_ldiv (L. A, L. B)
107+
102108copy (L:: Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiVector} ) =
103- copy (Ldiv {LazyLayout,ApplyLayout{typeof(*)}} (L. A, L. B))
109+ transform_ldiv (L. A, L. B)
110+
111+ function copy (L:: Ldiv{ApplyLayout{typeof(*)},<:AbstractBasisLayout} )
112+ args = arguments (L. A)
113+ @assert length (args) == 2 # temporary
114+ apply (\ , last (args), apply (\ , first (args), L. B))
115+ end
116+
104117
105118function copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(*)},<:AbstractQuasiMatrix,<:AbstractQuasiVector} )
106119 p,T = transform (L. A)
107- T \ L. B[p]
120+ T \ L. B[p]
108121end
109122
110123# # materialize views
144157sublayout (:: AbstractBasisLayout , :: Type{<:Tuple{<:Inclusion,<:AbstractUnitRange}} ) = SubBasisLayout ()
145158sublayout (:: BasisLayout , :: Type{<:Tuple{<:AffineQuasiVector,<:AbstractUnitRange}} ) = MappedBasisLayout ()
146159
160+ @inline sub_materialize (:: AbstractBasisLayout , V:: AbstractQuasiArray ) = V
161+ @inline sub_materialize (:: AbstractBasisLayout , V:: AbstractArray ) = V
162+
147163demap (x) = x
148164demap (V:: SubQuasiArray{<:Any,2,<:Any,<:Tuple{<:Any,<:Slice}} ) = parent (V)
149165function demap (V:: SubQuasiArray{<:Any,2} )
@@ -172,8 +188,28 @@ function arguments(V::SubQuasiArray{<:Any,2,<:Any,<:Tuple{<:Inclusion,<:Abstract
172188 A,P
173189end
174190
175- copy (L:: Ldiv{BasisLayout,SubBasisLayout} ) = apply (\ , L. A, ApplyQuasiArray (L. B))
191+ # ###
192+ # sum
193+ # ###
176194
195+ _sum (V:: AbstractQuasiArray , dims) = __sum (MemoryLayout (typeof (V)), V, dims)
196+ _sum (V:: AbstractQuasiArray , :: Colon ) = __sum (MemoryLayout (typeof (V)), V, :)
197+ sum (V:: AbstractQuasiArray ; dims= :) = _sum (V, dims)
177198
199+ __sum (L, Vm, _) = error (" Override for $L " )
200+ function __sum (:: SubBasisLayout , Vm, dims)
201+ @assert dims == 1
202+ sum (parent (Vm); dims= dims)[:,parentindices (Vm)[2 ]]
203+ end
204+ function __sum (:: ApplyLayout{typeof(*)} , V:: AbstractQuasiVector , :: Colon )
205+ a = arguments (V)
206+ first (apply (* , sum (a[1 ]; dims= 1 ), tail (a)... ))
207+ end
208+
209+ function __sum (:: MappedBasisLayout , V:: AbstractQuasiArray , dims)
210+ kr, jr = parentindices (V)
211+ @assert kr isa AffineQuasiVector
212+ sum (demap (V); dims= dims)/ kr. A
213+ end
178214
179215include (" splines.jl" )
0 commit comments