I have a lower triangular matrix which gets reused. In one of the steps, I have all of the elements (below the diagonal) set to the same value. How do I make Julia understand that I’m not trying to set values above the diagonal?
MWE:
julia> using LinearAlgebra
julia> JB = LowerTriangular(zeros(Float64, 3, 3))
3×3 LowerTriangular{Float64, Matrix{Float64}}:
0.0 ⋅ ⋅
0.0 0.0 ⋅
0.0 0.0 0.0
julia> JB .= -5
ERROR: ArgumentError: cannot set indices in the upper triangular part of an LowerTriangular matrix to a nonzero value (-5)
[...]
function setall2!(A::LowerTriangular, value)
A.data .= value
A
end
This works faster than setall! (see previous post), but at the cost of going into the internal details of LowerTriangular. Note that LowerTriangular doesn’t store the matrix in a compressed form, but instead stores (and ignores) the other half of the matrix.
Doing the index calculations is slower than setting the invisible part of the matrix.