@@ -108,13 +108,15 @@ show(io::IO, ::MIME"text/plain", δ::DiracDelta) = show(io, δ)
108
108
# Differentiation
109
109
# ########
110
110
111
+ abstract type AbstractDifferentialQuasiMatrix{T} <: LazyQuasiMatrix{T} end
112
+
111
113
"""
112
114
Derivative(axis)
113
115
114
116
represents the differentiation (or finite-differences) operator on the
115
117
specified axis.
116
118
"""
117
- struct Derivative{T,D<: Inclusion ,Order} <: LazyQuasiMatrix {T}
119
+ struct Derivative{T,D<: Inclusion ,Order} <: AbstractDifferentialQuasiMatrix {T}
118
120
axis:: D
119
121
order:: Order
120
122
end
@@ -125,7 +127,7 @@ Laplacian(axis)
125
127
represents the laplacian operator `Δ` on the
126
128
specified axis.
127
129
"""
128
- struct Laplacian{T,D<: Inclusion ,Order} <: LazyQuasiMatrix {T}
130
+ struct Laplacian{T,D<: Inclusion ,Order} <: AbstractDifferentialQuasiMatrix {T}
129
131
axis:: D
130
132
order:: Order
131
133
end
@@ -136,14 +138,42 @@ AbsLaplacian(axis)
136
138
represents the positive-definite/negative/absolute-value laplacian operator `|Δ| ≡ -Δ` on the
137
139
specified axis.
138
140
"""
139
- struct AbsLaplacian{T,D<: Inclusion ,Order} <: LazyQuasiMatrix {T}
141
+ struct AbsLaplacian{T,D<: Inclusion ,Order} <: AbstractDifferentialQuasiMatrix {T}
140
142
axis:: D
141
143
order:: Order
142
144
end
143
145
144
- _operatororder (D) = something (D. order, 1 )
146
+ operatororder (D) = something (D. order, 1 )
147
+
148
+ show (io:: IO , a:: AbstractDifferentialQuasiMatrix ) = summary (io, a)
149
+ axes (D:: AbstractDifferentialQuasiMatrix ) = (D. axis, D. axis)
150
+ == (a:: AbstractDifferentialQuasiMatrix , b:: AbstractDifferentialQuasiMatrix ) = a. axis == b. axis && operatororder (a) == operatororder (b)
151
+ copy (D:: AbstractDifferentialQuasiMatrix ) = D
152
+
153
+
154
+
155
+ @simplify function * (D:: AbstractDifferentialQuasiMatrix , B:: AbstractQuasiVecOrMat )
156
+ T = typeof (zero (eltype (D)) * zero (eltype (B)))
157
+ operatorcall (D, convert (AbstractQuasiArray{T}, B), D. order)
158
+ end
159
+
160
+ ^ (D:: AbstractDifferentialQuasiMatrix{T} , k:: Integer ) where T = similaroperator (D, D. axis, operatororder (D) .* k)
161
+
162
+ function view (D:: AbstractDifferentialQuasiMatrix , kr:: Inclusion , jr:: Inclusion )
163
+ @boundscheck axes (D,1 ) == kr == jr || throw (BoundsError (D,(kr,jr)))
164
+ D
165
+ end
166
+
167
+ operatorcall (D:: AbstractDifferentialQuasiMatrix , B, order) = operatorcall (D)(B, order)
168
+ operatorcall (D:: AbstractDifferentialQuasiMatrix , B, :: Nothing ) = operatorcall (D)(B)
169
+
170
+
171
+ operatorcall (:: Derivative ) = diff
172
+ operatorcall (:: Laplacian ) = laplacian
173
+ operatorcall (:: AbsLaplacian ) = abslaplacian
145
174
146
- for (Op, op) in ((:Derivative , :diff ), (:Laplacian , :laplacian ), (:AbsLaplacian , :abslaplacian ))
175
+
176
+ for Op in (:Derivative , :Laplacian , :AbsLaplacian )
147
177
@eval begin
148
178
$ Op {T, D} (axis:: D , order) where {T,D<: Inclusion } = $ Op {T,D,typeof(order)} (axis, order)
149
179
$ Op {T, D} (axis:: D ) where {T,D<: Inclusion } = $ Op {T,D,Nothing} (axis, nothing )
@@ -153,42 +183,20 @@ for (Op, op) in ((:Derivative, :diff), (:Laplacian, :laplacian), (:AbsLaplacian,
153
183
$ Op (ax:: AbstractQuasiVector{T} , order... ) where T = $ Op {eltype(eltype(ax))} (ax, order... )
154
184
$ Op (L:: AbstractQuasiMatrix , order... ) = $ Op (axes (L,1 ), order... )
155
185
156
- show (io:: IO , a:: $Op ) = summary (io, a)
157
- function summary (io:: IO , D:: $Op{<:Any,<:Inclusion,Nothing} )
158
- print (io, " $($ Op) (" )
159
- summary (io, D. axis)
160
- print (io," )" )
161
- end
186
+ similaroperator (D:: $Op , ax, ord) = $ Op {eltype(D)} (ax, ord)
187
+
188
+ simplifiable (:: typeof (* ), A:: $Op , B:: $Op ) = Val (true )
189
+ * (D1:: $Op , D2:: $Op ) = similaroperator (convert (AbstractQuasiMatrix{promote_type (eltype (D1),eltype (D2))}, D1), D1. axis, operatororder (D1)+ operatororder (D2))
190
+
162
191
163
192
function summary (io:: IO , D:: $Op )
164
193
print (io, " $($ Op) (" )
165
194
summary (io, D. axis)
166
- print (io, " , " )
167
- print (io, D. order)
168
- print (io," )" )
169
- end
170
-
171
- axes (D:: $Op ) = (D. axis, D. axis)
172
- == (a:: $Op , b:: $Op ) = a. axis == b. axis && _operatororder (a) == _operatororder (b)
173
- copy (D:: $Op ) = D
174
-
175
-
176
- @simplify function * (D:: $Op , B:: AbstractQuasiVecOrMat )
177
- T = typeof (zero (eltype (D)) * zero (eltype (B)))
178
- if D. order isa Nothing
179
- $ op (convert (AbstractQuasiArray{T}, B))
180
- else
181
- $ op (convert (AbstractQuasiArray{T}, B), D. order)
195
+ if ! isnothing (D. order)
196
+ print (io, " , " )
197
+ print (io, D. order)
182
198
end
183
- end
184
-
185
- ^ (D:: $Op{T} , k:: Integer ) where T = $ Op {T} (D. axis, _operatororder (D) .* k)
186
-
187
- @simplify * (D1:: $Op , D2:: $Op ) = $ Op {promote_type(eltype(D1),eltype(D2))} (D1. axis, _operatororder (D1)+ _operatororder (D2))
188
-
189
- function view (D:: $Op , kr:: Inclusion , jr:: Inclusion )
190
- @boundscheck axes (D,1 ) == kr == jr || throw (BoundsError (D,(kr,jr)))
191
- D
199
+ print (io," )" )
192
200
end
193
201
end
194
202
end
199
207
# end
200
208
201
209
202
- const Identity{T,D} = QuasiDiagonal{T,Inclusion{T,D}}
203
-
204
- Identity (d:: Inclusion ) = QuasiDiagonal (d)
205
-
206
210
struct OperatorLayout <: AbstractLazyLayout end
207
- MemoryLayout (:: Type{<:Derivative } ) = OperatorLayout ()
211
+ MemoryLayout (:: Type{<:AbstractDifferentialQuasiMatrix } ) = OperatorLayout ()
208
212
# copy(M::Mul{OperatorLayout, <:ExpansionLayout}) = simplify(M)
209
213
# copy(M::Mul{OperatorLayout, <:AbstractLazyLayout}) = M.A * expand(M.B)
210
214
@@ -215,4 +219,4 @@ abs(Δ::Laplacian{T}) where T = AbsLaplacian{T}(axes(Δ,1), Δ.order)
215
219
- (Δ:: Laplacian{<:Any,<:Any,Nothing} ) = abs (Δ)
216
220
- (Δ:: AbsLaplacian{T,<:Any,Nothing} ) where T = Laplacian {T} (Δ. axis)
217
221
218
- ^ (Δ:: AbsLaplacian{T} , k:: Real ) where T = AbsLaplacian {T} (Δ. axis, _operatororder (Δ)* k)
222
+ ^ (Δ:: AbsLaplacian{T} , k:: Real ) where T = AbsLaplacian {T} (Δ. axis, operatororder (Δ)* k)
0 commit comments