Triangular Arrays in julia?

In BandedMatrices.jl, we do something similar using a band keyword:

A = bzeros(Float64,10,10,1,1)  # 10 x 10 tridiagonal matrix
A[band(1)] = 1:9                        # set upper diagonal

Something similar could be done for triangular matrices to accomplish what you are trying to do without overloading : in a confusing way:

a = UpperTriangular(ones(4,4))
a[UpperTriangle] = 1:10      # set upper triangle entries
3 Likes

Cool. In fact my deleted post was a suggestion to allow arrays to do exactly that (a[:UpperTriangular]), but then I thought I hadn’t thought it all the way through. That is a nice and elegant solution IMO.

In my example, UpperTriangle is meant to be a singleton type, so you can override getindex(A,::Type{UpperTriangle})

1 Like

Would that functionality belong in BandedMatrices then?

I think it’d make more sense in a TriangularMatrices.jl package

1 Like

Four years late, but here’s an answer anyway. Yes, it must be possible to manipulate triangular matrices using BLAS, because that is what LINPACK does in Fortran.

1 Like