@@ -4,14 +4,14 @@ abstract type Weight{T} <: LazyQuasiVector{T} end
44
55const WeightedBasis{T, A<: AbstractQuasiVector , B<: Basis } = BroadcastQuasiMatrix{T,typeof (* ),<: Tuple{A,B} }
66
7- struct WeightLayout <: MemoryLayout end
8- abstract type AbstractBasisLayout <: MemoryLayout end
7+ struct WeightLayout <: AbstractQuasiLazyLayout end
8+ abstract type AbstractBasisLayout <: AbstractQuasiLazyLayout end
99struct BasisLayout <: AbstractBasisLayout end
1010struct SubBasisLayout <: AbstractBasisLayout end
1111struct MappedBasisLayout <: AbstractBasisLayout end
1212struct WeightedBasisLayout <: AbstractBasisLayout end
1313
14- abstract type AbstractAdjointBasisLayout <: MemoryLayout end
14+ abstract type AbstractAdjointBasisLayout <: AbstractQuasiLazyLayout end
1515struct AdjointBasisLayout <: AbstractAdjointBasisLayout end
1616struct AdjointSubBasisLayout <: AbstractAdjointBasisLayout end
1717struct AdjointMappedBasisLayout <: AbstractAdjointBasisLayout end
@@ -25,9 +25,7 @@ adjointlayout(::Type, ::MappedBasisLayout) = AdjointMappedBasisLayout()
2525broadcastlayout (:: Type{typeof(*)} , :: WeightLayout , :: BasisLayout ) = WeightedBasisLayout ()
2626broadcastlayout (:: Type{typeof(*)} , :: WeightLayout , :: SubBasisLayout ) = WeightedBasisLayout ()
2727
28- combine_mul_styles (:: AbstractBasisLayout ) = LazyQuasiArrayApplyStyle ()
29- combine_mul_styles (:: AbstractAdjointBasisLayout ) = LazyQuasiArrayApplyStyle ()
30-
28+ # Default is lazy
3129ApplyStyle (:: typeof (pinv), :: Type{<:Basis} ) = LazyQuasiArrayApplyStyle ()
3230pinv (J:: Basis ) = apply (pinv,J)
3331
@@ -37,10 +35,6 @@ function ==(A::Basis, B::Basis)
3735 false
3836end
3937
40- @inline quasildivapplystyle (:: AbstractBasisLayout , :: AbstractBasisLayout ) = LdivApplyStyle ()
41- @inline quasildivapplystyle (:: AbstractBasisLayout , _) = LdivApplyStyle ()
42- @inline quasildivapplystyle (_, :: AbstractBasisLayout ) = LdivApplyStyle ()
43-
4438
4539@inline copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)}} ) = + (broadcast (\ ,Ref (L. A),arguments (L. B))... )
4640@inline copy (L:: Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(+)},<:Any,<:AbstractQuasiVector} ) =
@@ -138,7 +132,7 @@ copy(L::Ldiv{<:AbstractBasisLayout,ApplyLayout{typeof(*)},<:Any,<:AbstractQuasiV
138132 transform_ldiv (L. A, L. B)
139133
140134function copy (L:: Ldiv{ApplyLayout{typeof(*)},<:AbstractBasisLayout} )
141- args = arguments (L. A)
135+ args = arguments (ApplyLayout {typeof(*)} (), L. A)
142136 @assert length (args) == 2 # temporary
143137 apply (\ , last (args), apply (\ , first (args), L. B))
144138end
@@ -149,6 +143,55 @@ function copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(*)},<:Abstrac
149143 T \ L. B[p]
150144end
151145
146+
147+ # #
148+ # Algebra
149+ # #
150+
151+ # struct ExpansionLayout <: MemoryLayout end
152+ # applylayout(::Type{typeof(*)}, ::BasisLayout, _) = ExpansionLayout()
153+
154+ const Expansion{T,Space<: Basis ,Coeffs<: AbstractVector } = ApplyQuasiVector{T,typeof (* ),<: Tuple{Space,Coeffs} }
155+
156+ basis (v:: AbstractQuasiVector ) = v. args[1 ]
157+
158+ for op in (:* , :\ )
159+ @eval function broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof ($ op), x:: Number , f:: Expansion )
160+ S,c = arguments (f)
161+ S * broadcast ($ op, x, c)
162+ end
163+ end
164+ for op in (:* , :/ )
165+ @eval function broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof ($ op), f:: Expansion , x:: Number )
166+ S,c = arguments (f)
167+ S * broadcast ($ op, c, x)
168+ end
169+ end
170+
171+
172+ function broadcastbasis (:: typeof (+ ), a, b)
173+ a ≠ b && error (" Overload broadcastbasis(::typeof(+), ::$(typeof (a)) , ::$(typeof (b)) )" )
174+ a
175+ end
176+
177+ broadcastbasis (:: typeof (- ), a, b) = broadcastbasis (+ , a, b)
178+
179+ for op in (:+ , :- )
180+ @eval function broadcasted (:: LazyQuasiArrayStyle{1} , :: typeof ($ op), f:: Expansion , g:: Expansion )
181+ S,c = arguments (f)
182+ T,d = arguments (g)
183+ ST = broadcastbasis ($ op, S, T)
184+ ST * $ op ((ST \ S) * c , (ST \ T) * d)
185+ end
186+ end
187+
188+ @eval function == (f:: Expansion , g:: Expansion )
189+ S,c = arguments (f)
190+ T,d = arguments (g)
191+ ST = broadcastbasis (+ , S, T)
192+ (ST \ S) * c == (ST \ T) * d
193+ end
194+
152195# # materialize views
153196
154197# materialize(S::SubQuasiArray{<:Any,2,<:ApplyQuasiArray{<:Any,2,typeof(*),<:Tuple{<:Basis,<:Any}}}) =
164207_sub_getindex (A, kr, jr) = A[kr, jr]
165208_sub_getindex (A, :: Slice , :: Slice ) = A
166209
167- function copy (M:: QMul2 {<: QuasiAdjoint{<:Any,<:SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}}} ,
168- <: SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}} })
169- Ac, B = M. args
210+ @simplify function * (Ac:: QuasiAdjoint{<:Any,<:SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}}} ,
211+ B:: SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}} )
170212 A = Ac'
171213 PA,PB = parent (A),parent (B)
172214 kr,jr = parentindices (B)
@@ -175,14 +217,12 @@ end
175217
176218
177219# Differentiation of sub-arrays
178- function copy (M:: QMul2{<:Derivative,<:SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:Inclusion,<:Any}}} )
179- A, B = M. args
220+ @simplify function * (A:: Derivative , B:: SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:Inclusion,<:Any}} )
180221 P = parent (B)
181222 (Derivative (axes (P,1 ))* P)[parentindices (B)... ]
182223end
183224
184- function copy (M:: QMul2{<:Derivative,<:SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}}} )
185- A, B = M. args
225+ @simplify function * (A:: Derivative , B:: SubQuasiArray{<:Any,2,<:AbstractQuasiMatrix,<:Tuple{<:AbstractAffineQuasiVector,<:Any}} )
186226 P = parent (B)
187227 kr,jr = parentindices (B)
188228 (Derivative (axes (P,1 ))* P* kr. A)[kr,jr]
@@ -220,15 +260,18 @@ end
220260# SubLayout behaves like ApplyLayout{typeof(*)}
221261
222262combine_mul_styles (:: SubBasisLayout ) = combine_mul_styles (ApplyLayout {typeof(*)} ())
223- _arguments (:: SubBasisLayout , A) = _arguments (ApplyLayout {typeof(*)} (), A)
263+ _mul_arguments (:: SubBasisLayout , A) = _mul_arguments (ApplyLayout {typeof(*)} (), A)
264+ arguments (:: SubBasisLayout , A) = arguments (ApplyLayout {typeof(*)} (), A)
224265call (:: SubBasisLayout , :: SubQuasiArray ) = *
225266
226267combine_mul_styles (:: AdjointSubBasisLayout ) = combine_mul_styles (ApplyLayout {typeof(*)} ())
227- _arguments (:: AdjointSubBasisLayout , A) = _arguments (ApplyLayout {typeof(*)} (), A)
268+ _mul_arguments (:: AdjointSubBasisLayout , A) = _mul_arguments (ApplyLayout {typeof(*)} (), A)
228269arguments (:: AdjointSubBasisLayout , A) = arguments (ApplyLayout {typeof(*)} (), A)
229270call (:: AdjointSubBasisLayout , :: SubQuasiArray ) = *
230271
231- function arguments (V:: SubQuasiArray{<:Any,2,<:Any,<:Tuple{<:Inclusion,<:AbstractUnitRange}} )
272+ copy (M:: Mul{AdjointSubBasisLayout,SubBasisLayout} ) = apply (* , arguments (M. A)... , arguments (M. B)... )
273+
274+ function arguments (:: ApplyLayout{typeof(*)} , V:: SubQuasiArray{<:Any,2,<:Any,<:Tuple{<:Inclusion,<:AbstractUnitRange}} )
232275 A = parent (V)
233276 _,jr = parentindices (V)
234277 first (jr) ≥ 1 || throw (BoundsError ())
@@ -249,8 +292,8 @@ function __sum(::SubBasisLayout, Vm, dims)
249292 @assert dims == 1
250293 sum (parent (Vm); dims= dims)[:,parentindices (Vm)[2 ]]
251294end
252- function __sum (:: ApplyLayout{typeof(*)} , V:: AbstractQuasiVector , :: Colon )
253- a = arguments (V)
295+ function __sum (LAY :: ApplyLayout{typeof(*)} , V:: AbstractQuasiVector , :: Colon )
296+ a = arguments (LAY, V)
254297 first (apply (* , sum (a[1 ]; dims= 1 ), tail (a)... ))
255298end
256299
0 commit comments