Commit bfab205
authored
Band indexing for adj/trans (#1299)
The advantage of this is that we may forward the indexing to the parent,
and if the parent is a structured matrix and the band is a compile-time
constant, the value may be evaluated as a constant.
E.g.:
```julia
julia> A = UnitUpperTriangular(reshape(1:9, 3, 3))
3×3 UnitUpperTriangular{Int64, Base.ReshapedArray{Int64, 2, UnitRange{Int64}, Tuple{}}}:
1 4 7
⋅ 1 8
⋅ ⋅ 1
julia> function f(A, i, ::Val{band}) where {band}
x = Adjoint(A)[LinearAlgebra.BandIndex(band,i)]
Val(x)
end
f (generic function with 1 method)
julia> @inferred f(A, 1, Val(0))
Val{1}()
julia> @inferred f(A, 1, Val(1))
Val{0}()
```
In this case, the band index `0` is forwarded to the parent
(`UnitUpperTriangular`), and the `getindex` is evaluated at compile-time
to return `1` (if within bounds). Similarly, the band index `1`
corresponds to the zeros of the triangular matrix, so the value is
evaluated at compile-time. This may help with removing branches in
indexing.1 parent e7a8a15 commit bfab205
2 files changed
+53
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
355 | 366 | | |
356 | 367 | | |
357 | 368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
749 | 749 | | |
750 | 750 | | |
751 | 751 | | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
752 | 794 | | |
0 commit comments