Commit a4a0b93
Nested slicing operations for merging blocks (#466)
Fixes #359.
This introduces syntax for merging blocks by indexing with nested
vectors of `Block{1}`, `BlockRange{1}`, `BlockIndexRange{1}`, etc. The
implementation is very similar to #445.
As an example:
```julia
julia> using BlockArrays
julia> A = BlockArray(randn(8, 8), [2, 2, 2, 2], [2, 2, 2, 2])
4×4-blocked 8×8 BlockMatrix{Float64}:
0.163738 -0.859246 │ -0.399256 -0.143974 │ -0.812783 0.469877 │ 0.0631785 1.56266
-0.209473 1.23701 │ 0.479233 0.219572 │ -0.548844 1.363 │ 0.795119 -0.169581
───────────────────────┼─────────────────────────┼────────────────────────┼────────────────────────
1.34493 -0.846004 │ 1.32566 0.470043 │ 0.650647 0.617614 │ -0.0926643 0.550304
1.20779 -0.528143 │ 1.09621 -0.0868135 │ -0.178719 -0.105456 │ 0.243687 -1.31676
───────────────────────┼─────────────────────────┼────────────────────────┼────────────────────────
1.201 1.48691 │ 0.264342 0.696739 │ -0.86067 -0.608839 │ -0.082433 -0.0931981
0.674171 -1.23494 │ 0.124443 1.94983 │ 0.929236 -1.62257 │ -0.693029 -0.0212493
───────────────────────┼─────────────────────────┼────────────────────────┼────────────────────────
0.0174839 1.65394 │ -0.851706 -1.23722 │ 1.63834 0.158663 │ 1.27422 -2.37923
1.28377 0.364039 │ 0.564611 -1.346 │ -0.619627 0.240933 │ 0.270664 -0.593572
julia> A[[[Block(1), Block(2)], [Block(3), Block(4)]], [[Block(1), Block(2)], [Block(3), Block(4)]]]
2×2-blocked 8×8 BlockedMatrix{Float64}:
0.163738 -0.859246 -0.399256 -0.143974 │ -0.812783 0.469877 0.0631785 1.56266
-0.209473 1.23701 0.479233 0.219572 │ -0.548844 1.363 0.795119 -0.169581
1.34493 -0.846004 1.32566 0.470043 │ 0.650647 0.617614 -0.0926643 0.550304
1.20779 -0.528143 1.09621 -0.0868135 │ -0.178719 -0.105456 0.243687 -1.31676
──────────────────────────────────────────────┼──────────────────────────────────────────────
1.201 1.48691 0.264342 0.696739 │ -0.86067 -0.608839 -0.082433 -0.0931981
0.674171 -1.23494 0.124443 1.94983 │ 0.929236 -1.62257 -0.693029 -0.0212493
0.0174839 1.65394 -0.851706 -1.23722 │ 1.63834 0.158663 1.27422 -2.37923
1.28377 0.364039 0.564611 -1.346 │ -0.619627 0.240933 0.270664 -0.593572
julia> A[[[Block(1)[2:2], Block(2)[2:2]], [Block(3)[2:2], Block(4)[2:2]]], [[Block(1)[2:2], Block(2)[2:2]], [Block(3)[2:2], Block(4)[2:2]]]]
2×2-blocked 4×4 BlockedMatrix{Float64}:
1.23701 0.219572 │ 1.363 -0.169581
-0.528143 -0.0868135 │ -0.105456 -1.31676
───────────────────────┼───────────────────────
-1.23494 1.94983 │ -1.62257 -0.0212493
0.364039 -1.346 │ 0.240933 -0.593572
```
It feels unfortunate that the implementation has to be done in this way
by catching the various cases manually with dispatch, but I can't think
a better way (besides introducing a custom slicing operation).
Co-authored-by: Sheehan Olver <[email protected]>1 parent ecb8f8f commit a4a0b93
3 files changed
+42
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
430 | | - | |
| 429 | + | |
431 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
432 | 436 | | |
433 | 437 | | |
434 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| 57 | + | |
| 58 | + | |
47 | 59 | | |
48 | 60 | | |
49 | 61 | | |
50 | 62 | | |
51 | | - | |
52 | | - | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
| 70 | + | |
| 71 | + | |
60 | 72 | | |
61 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1098 | 1113 | | |
1099 | 1114 | | |
1100 | 1115 | | |
0 commit comments