@@ -85,6 +85,9 @@ function convert(::Type{<:BandedBlockBandedMatrix}, B::BandedMatrix)
85
85
end
86
86
end
87
87
88
+ convert (:: Type{BandedBlockBandedMatrix{T,BLOCKS,RAXIS}} , A:: BandedBlockBandedMatrix ) where {T,BLOCKS,RAXIS} =
89
+ _BandedBlockBandedMatrix (convert (BLOCKS, A. data), convert (RAXIS, A. raxis), (A. l, A. u), (A. λ, A. μ))
90
+
88
91
function BandedBlockBandedMatrix {T,B,R} (Z:: Zeros , axes:: NTuple{2,AbstractUnitRange{Int}} ,
89
92
lu:: NTuple{2,Int} , λμ:: NTuple{2,Int} ) where {T,B,R<: AbstractUnitRange{Int} }
90
93
if size (Z) ≠ map (length,axes)
@@ -191,10 +194,7 @@ similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::NTuple{2,AbstractUnitRange{
191
194
192
195
193
196
similar (A:: BandedBlockBandedMatrix{T} , axes:: NTuple{2,AbstractUnitRange{Int}} ) where T =
194
- BandedBlockBandedMatrix {T} (undef, axes, blockbandwidths (A), subblockbandwidths (A))
195
-
196
- similar (A:: BandedBlockBandedMatrix{T} , axes:: NTuple{2,OneTo{Int}} ) where T =
197
- Matrix {T} (undef, map (length,axes))
197
+ similar (Matrix{T}, map (length,axes)... )
198
198
199
199
axes (A:: BandedBlockBandedMatrix ) = (A. raxis, axes (A. data,2 ))
200
200
@@ -398,21 +398,91 @@ end
398
398
# with BLASBandedMatrix.
399
399
# #################
400
400
401
+ const SubBandedBlockBandedMatrix{T,R1,R2} =
402
+ SubArray{T,2 ,<: BandedBlockBandedMatrix{T} ,<: Tuple{<:BlockSlice{R1},<:BlockSlice{R2}} }
403
+
404
+
405
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{Block1},BlockSlice{Block1}}} ) = BandedColumnMajor ()
406
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{BlockIndexRange1}}} ) = BandedColumnMajor ()
407
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{Block1}}} ) = BandedColumnMajor ()
408
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{Block1},BlockSlice{BlockIndexRange1}}} ) = BandedColumnMajor ()
409
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{BlockRange1},BlockSlice{BlockRange1}}} ) = BandedBlockBandedColumnMajor ()
410
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{Block1},BlockSlice{BlockRange1}}} ) = BandedBlockBandedColumnMajor ()
411
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{BlockRange1},BlockSlice{Block1}}} ) = BandedBlockBandedColumnMajor ()
412
+ sublayout (:: BandedBlockBandedColumnMajor , :: Type{<:Tuple{BlockSlice{BlockRange1},BlockSlice{BlockIndexRange1}}} ) = BandedBlockBandedColumnMajor ()
413
+
414
+ isbanded (A:: SubArray{<:Any,2,<:BandedBlockBandedMatrix} ) = MemoryLayout (typeof (A)) == BandedColumnMajor ()
415
+ isbandedblockbanded (A:: SubArray{<:Any,2,<:BandedBlockBandedMatrix} ) = MemoryLayout (typeof (A)) == BandedBlockBandedColumnMajor ()
416
+
417
+
418
+ subblockbandwidths (V:: SubBandedBlockBandedMatrix ) = subblockbandwidths (parent (V))
419
+
420
+ function blockbandwidths (V:: SubBandedBlockBandedMatrix{<:Any,BlockRange1,Block1} )
421
+ A = parent (V)
422
+
423
+ KR = parentindices (V)[1 ]. block. indices[1 ]
424
+ J = parentindices (V)[2 ]. block
425
+ shift = Int (KR[1 ])- Int (J)
426
+ blockbandwidth (A,1 ) - shift, blockbandwidth (A,2 ) + shift
427
+ end
428
+
429
+ function blockbandwidths (V:: SubBandedBlockBandedMatrix{<:Any,Block1,BlockRange1} )
430
+ A = parent (V)
431
+
432
+ K = parentindices (V)[1 ]. block
433
+ JR = parentindices (V)[2 ]. block. indices[1 ]
434
+ shift = Int (K)- Int (JR[1 ])
435
+
436
+ blockbandwidth (A,1 ) - shift, blockbandwidth (A,2 ) + shift
437
+ end
438
+
439
+ function blockbandwidths (V:: SubBandedBlockBandedMatrix{<:Any,BlockRange1,BlockRange1} )
440
+ A = parent (V)
441
+
442
+ KR = parentindices (V)[1 ]. block. indices[1 ]
443
+ JR = parentindices (V)[2 ]. block. indices[1 ]
444
+ shift = Int (KR[1 ])- Int (JR[1 ])
445
+
446
+ blockbandwidth (A,1 ) - shift, blockbandwidth (A,2 ) + shift
447
+ end
448
+
449
+
401
450
const BandedBlockBandedBlock{T, BLOCKS, RAXIS} = SubArray{T,2 ,BandedBlockBandedMatrix{T, BLOCKS, RAXIS},<: Tuple{<:BlockSlice1,<:BlockSlice1} ,false }
402
451
403
452
404
- isbanded (:: BandedBlockBandedBlock ) = true
405
- MemoryLayout (:: BandedBlockBandedBlock ) = BandedColumnMajor ()
406
453
BroadcastStyle (:: Type{<: BandedBlockBandedBlock} ) = BandedStyle ()
407
454
408
455
409
- function inblockbands (V:: BandedBlockBandedBlock )
456
+ function inblockbands (V:: SubArray{<:Any,2,<:AbstractMatrix,<:Tuple{<:BlockSlice1,<:BlockSlice1},false} )
410
457
A = parent (V)
411
458
K_sl, J_sl = parentindices (V)
412
459
K, J = K_sl. block, J_sl. block
413
- - A. l ≤ Int (J- K) ≤ A. u
460
+ l,u = blockbandwidths (A)
461
+ - l ≤ Int (J- K) ≤ u
414
462
end
415
463
464
+ function parentblock (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{BlockIndexRange1}}} ) where T
465
+ A = parent (V)
466
+ K_sl, J_sl = parentindices (V)
467
+ view (A, K_sl. block. block, J_sl. block. block)
468
+ end
469
+
470
+ function parentblock (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{Block1},BlockSlice{BlockIndexRange1}}} ) where T
471
+ A = parent (V)
472
+ K_sl, J_sl = parentindices (V)
473
+ view (A, K_sl. block, J_sl. block. block)
474
+ end
475
+
476
+ function parentblock (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{Block1}}} ) where T
477
+ A = parent (V)
478
+ K_sl, J_sl = parentindices (V)
479
+ view (A, K_sl. block. block, J_sl. block)
480
+ end
481
+
482
+ # gives the columns of parent(V).data that encode the block
483
+ parentblocks2Int (V:: BandedBlockBandedBlock ):: Tuple{Int,Int} = Int (first (parentindices (V)). block),
484
+ Int (last (parentindices (V)). block)
485
+
416
486
417
487
# #####################################
418
488
# BandedMatrix interface for Blocks #
@@ -422,11 +492,23 @@ end
422
492
(- 720 ,- 720 )
423
493
end
424
494
495
+ function bandwidths (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{BlockIndexRange1}}} ) where T
496
+ B = parentblock (V)
497
+ K_sl, J_sl = parentindices (V)
498
+ bandwidths (B) .+ (- 1 ,1 ) .* bandshift (K_sl. block. indices[1 ],J_sl. block. indices[1 ])
499
+ end
425
500
501
+ function bandwidths (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{Block1},BlockSlice{BlockIndexRange1}}} ) where T
502
+ B = parentblock (V)
503
+ K_sl, J_sl = parentindices (V)
504
+ bandwidths (B) .+ (- 1 ,1 ) .* bandshift (Base. OneTo (1 ),J_sl. block. indices[1 ])
505
+ end
426
506
427
- # gives the columns of parent(V).data that encode the block
428
- blocks (V:: BandedBlockBandedBlock ):: Tuple{Int,Int} = Int (first (parentindices (V)). block),
429
- Int (last (parentindices (V)). block)
507
+ function bandwidths (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{Block1}}} ) where T
508
+ B = parentblock (V)
509
+ K_sl, J_sl = parentindices (V)
510
+ bandwidths (B) .+ (- 1 ,1 ) .* bandshift (K_sl. block. indices[1 ],Base. OneTo (1 ))
511
+ end
430
512
431
513
432
514
function bandeddata (V:: BandedBlockBandedBlock{T} ) where T
@@ -438,6 +520,27 @@ function bandeddata(V::BandedBlockBandedBlock{T}) where T
438
520
view (A. data, u + K - J + 1 , J)
439
521
end
440
522
523
+ function bandeddata (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{BlockIndexRange1}}} ) where T
524
+ A = parent (V)
525
+ K_sl, J_sl = parentindices (V)
526
+ view (bandeddata (parentblock (V)), :, J_sl. block. indices[1 ])
527
+ end
528
+
529
+ function bandeddata (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{Block1},BlockSlice{BlockIndexRange1}}} ) where T
530
+ A = parent (V)
531
+ K_sl, J_sl = parentindices (V)
532
+ view (bandeddata (parentblock (V)), :, J_sl. block. indices[1 ])
533
+ end
534
+
535
+ function bandeddata (V:: SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{BlockIndexRange1},BlockSlice{Block1}}} ) where T
536
+ A = parent (V)
537
+ K_sl, J_sl = parentindices (V)
538
+ bandeddata (parentblock (V))
539
+ end
540
+
541
+
542
+
543
+
441
544
442
545
@inline function inbands_getindex (V:: BandedBlockBandedBlock , k:: Int , j:: Int )
443
546
A = parent (V)
453
556
@propagate_inbounds function getindex (V:: BandedBlockBandedBlock , k:: Int , j:: Int )
454
557
@boundscheck checkbounds (V, k, j)
455
558
A = parent (V)
456
- K,J = blocks (V)
559
+ K,J = parentblocks2Int (V)
457
560
if - A. l ≤ J- K ≤ A. u && - A. λ ≤ j- k ≤ A. μ
458
561
inbands_getindex (V, k, j)
459
562
else
464
567
@propagate_inbounds function setindex! (V:: BandedBlockBandedBlock , v, k:: Int , j:: Int )
465
568
@boundscheck checkbounds (V, k, j)
466
569
A = parent (V)
467
- K,J = blocks (V)
570
+ K,J = parentblocks2Int (V)
468
571
if - A. l ≤ J- K ≤ A. u && - A. λ ≤ j- k ≤ A. μ
469
572
inbands_setindex! (V, v, k, j)
470
573
elseif iszero (v) # allow setindex for 0 datya
0 commit comments