@@ -160,30 +160,13 @@ getindex(Z::Zernike, xy::StaticVector{2}, B::BlockIndex{1}) = Z[RadialCoordinate
160
160
getindex (Z:: Zernike , xy:: StaticVector{2} , B:: Block{1} ) = [Z[xy, B[j]] for j= 1 : Int (B)]
161
161
getindex (Z:: Zernike , xy:: StaticVector{2} , JR:: BlockOneTo ) = mortar ([Z[xy,Block (J)] for J = 1 : Int (JR[end ])])
162
162
163
+
163
164
# ##
164
165
# Jacobi matrices
165
166
# ##
166
-
167
- # Due to excessively long lazy typing, we wrap the bands of the Zernike Jacobi matrix in its own type
168
- # The bands for X and Y are distinct
169
- struct ZernikeJacobimatrixBandsX{T} <: AbstractBlockMatrix{T}
170
- Z:: Zernike{T}
171
- data:: AbstractBlockMatrix{T}
172
- ZernikeJacobimatrixBandsX {T} (Z:: Zernike{T} ) where T = new {T} (Z, zernikejacobibandsX (Z))
173
- end
174
- struct ZernikeJacobimatrixBandsY{T} <: AbstractBlockMatrix{T}
175
- Z:: Zernike{T}
176
- data:: AbstractBlockMatrix{T}
177
- ZernikeJacobimatrixBandsY {T} (Z:: Zernike{T} ) where T = new {T} (Z, zernikejacobibandsY (Z))
178
- end
179
-
180
- size (b:: ZernikeJacobimatrixBandsX ) = size (b. data)
181
- axes (b:: ZernikeJacobimatrixBandsX ) = axes (b. data)
182
- size (b:: ZernikeJacobimatrixBandsY ) = size (b. data)
183
- axes (b:: ZernikeJacobimatrixBandsY ) = axes (b. data)
184
-
185
- function zernikejacobibandsX (Z:: Zernike )
186
- α = Z. b # extract second basis parameter
167
+ function jacobimatrix (:: Val{1} , Z:: Zernike{T} ) where T
168
+ if iszero (Z. a)
169
+ α = Z. b # extract second basis parameter
187
170
188
171
k = mortar (Base. OneTo .(oneto (∞))) # k counts the the angular mode (+1)
189
172
n = mortar (Fill .(oneto (∞),oneto (∞))) # n counts the block number which corresponds to the order (+1)
@@ -224,65 +207,48 @@ function zernikejacobibandsX(Z::Zernike)
224
207
du = sqrt .( (dufirst .+ dueven .+ duodd ) ./ quotient)
225
208
dl = sqrt .( (dleven .+ dlodd .+ dlspecial) ./ quotient)
226
209
227
- return BlockBroadcastArray (hcat, du, Zeros ((axes (n,1 ),)), dl)
228
- end
229
-
230
- function zernikejacobibandsY (Z:: Zernike )
231
- α = Z. b # extract second basis parameter
232
-
233
- k = mortar (Base. OneTo .(oneto (∞))) # k counts the the angular mode (+1)
234
- n = mortar (Fill .(oneto (∞),oneto (∞))) # n counts the block number which corresponds to the order (+1)
235
-
236
- # repeatedly used for sorting
237
- keven = iseven .(k)
238
- kodd = isodd .(k)
239
- neven = iseven .(n)
240
- nodd = isodd .(n)
241
-
242
- # h1-h4 are helpers for our different sorting scheme
243
-
244
- # first entries for all blocks
245
- h1 = (n .- nodd)
246
- l1 = (k .== 1 ) .* (h1 .* (h1 .+ 2 * α) ./ 2 )
247
-
248
- # Even blocks
249
- h0 = (kodd .* ((k .÷ 2 ) .+ 1 ) .- (keven .* ((k .÷ 2 ) .- 1 )))
250
- h2 = (k .>= 2 ) .* ((n .÷ 2 .- 1 ) .+ h0)
251
- l2 = neven .* (h2 .* (h2 .+ α))
252
-
253
- # Odd blocks
254
- h3 = (n .> k .>= 2 ) .* (((n .+ 1 ) .÷ 2 ) .- h0)
255
- l3 = nodd .* (h3 .* (h3 .+ α))
256
- # Combine for diagonal of super diagonal block
257
- d = sqrt .((l1 .+ l2 .+ l3) ./ (4 .* (n .+ (α- 1 )) .* (n .+ α)))
258
-
259
- # The off-diagonals of the super diagonal block are negative, shifted versions of the diagonal with some entries skipped
260
- dl = (- 1 ) .* (nodd .* kodd .+ neven .* keven) .* Vcat (0 , d)
261
- du = (- 1 ) .* (nodd .* keven .+ neven .* kodd) .* d[2 : end ]
262
-
263
- # generate and return bands
264
- return dat = BlockBroadcastArray (hcat, dl, Zeros ((axes (n,1 ),)), d, Zeros ((axes (n,1 ),)), du)
265
- end
266
-
267
- function getindex (b:: ZernikeJacobimatrixBandsX{T} ,i,j) where T
268
- return BlockArrays. getindex (b. data,i,j)
269
- end
270
- function getindex (b:: ZernikeJacobimatrixBandsY{T} ,i,j) where T
271
- return BlockArrays. getindex (b. data,i,j)
272
- end
273
-
274
- function jacobimatrix (:: Val{1} , Z:: Zernike{T} ) where T
275
- if iszero (Z. a)
276
- dat = ZernikeJacobimatrixBandsX {T} (Z)
277
- return Symmetric (BlockBandedMatrices. _BandedBlockBandedMatrix (dat' , axes (dat,1 ), (- 1 ,1 ), (1 ,1 )))
210
+ return Symmetric (BlockBandedMatrices. _BandedBlockBandedMatrix (BlockBroadcastArray (hcat, du, Zeros ((axes (n,1 ),)), dl)' , axes (n,1 ), (- 1 ,1 ), (1 ,1 )))
278
211
else
279
212
error (" Implement for non-zero first basis parameter." )
280
213
end
281
214
end
215
+
282
216
function jacobimatrix (:: Val{2} , Z:: Zernike{T} ) where T
283
217
if iszero (Z. a)
284
- dat = ZernikeJacobimatrixBandsY {T} (Z)
285
- return Symmetric (BlockBandedMatrices. _BandedBlockBandedMatrix (dat' , axes (dat,1 ), (- 1 ,1 ), (2 ,2 )))
218
+ α = Z. b # extract second basis parameter
219
+
220
+ k = mortar (Base. OneTo .(oneto (∞))) # k counts the the angular mode (+1)
221
+ n = mortar (Fill .(oneto (∞),oneto (∞))) # n counts the block number which corresponds to the order (+1)
222
+
223
+ # repeatedly used for sorting
224
+ keven = iseven .(k)
225
+ kodd = isodd .(k)
226
+ neven = iseven .(n)
227
+ nodd = isodd .(n)
228
+
229
+ # h1-h4 are helpers for our different sorting scheme
230
+
231
+ # first entries for all blocks
232
+ h1 = (n .- nodd)
233
+ l1 = (k .== 1 ) .* (h1 .* (h1 .+ 2 * α) ./ 2 )
234
+
235
+ # Even blocks
236
+ h0 = (kodd .* ((k .÷ 2 ) .+ 1 ) .- (keven .* ((k .÷ 2 ) .- 1 )))
237
+ h2 = (k .>= 2 ) .* ((n .÷ 2 .- 1 ) .+ h0)
238
+ l2 = neven .* (h2 .* (h2 .+ α))
239
+
240
+ # Odd blocks
241
+ h3 = (n .> k .>= 2 ) .* (((n .+ 1 ) .÷ 2 ) .- h0)
242
+ l3 = nodd .* (h3 .* (h3 .+ α))
243
+ # Combine for diagonal of super diagonal block
244
+ d = sqrt .((l1 .+ l2 .+ l3) ./ (4 .* (n .+ (α- 1 )) .* (n .+ α)))
245
+
246
+ # The off-diagonals of the super diagonal block are negative, shifted versions of the diagonal with some entries skipped
247
+ dl = (- 1 ) .* (nodd .* kodd .+ neven .* keven) .* Vcat (0 , d)
248
+ du = (- 1 ) .* (nodd .* keven .+ neven .* kodd) .* view (d,2 : ∞)
249
+
250
+ # generate and return bands
251
+ return Symmetric (BlockBandedMatrices. _BandedBlockBandedMatrix (BlockBroadcastArray (hcat, dl, Zeros ((axes (n,1 ),)), d, Zeros ((axes (n,1 ),)), du)' , axes (n,1 ), (- 1 ,1 ), (2 ,2 )))
286
252
else
287
253
error (" Implement for non-zero first basis parameter." )
288
254
end
0 commit comments