I’m working on monotone spline fitting using an ispline basis. The matrix formed is similar to a banded matrix, but has all ones in the lower triangle portion below the banded portion. Additionally, I’m adding a constant column of all ones. Does anyone know of a package for more efficiently storing and working with this type of matrix, ideally one that will play nice with a non-negative-least-squares solver?

What do you need to do with the matrix? If all you need are matvecs and solves, then you could probably easily write a custom function for the multiplication that is efficient, and then use something like IterativeSolvers.jl to perform your solves with very little extra code. Something like this:

```
using IterativeSolvers
struct MyMatrix
B::(banded matrix object)
end
function lowertri_ones_apply(v)
.... # easy to write in matrix-free form
end
function Base.:*(M::MyMatrix, v)
M.B*v + lowertri_ones_apply(v)
end
function LinearAlgebra.mul!(M::MyMatrix, v)
... # should actually write THIS first, then make have * just make a copy and then call mul!.
end
eltype(M::MyMatrix) = ...
size(M::MyMatrix) = ...
function mysolve(M::MyMatrix, v; kwargs...)
IterativeSolvers.gmres(M, v; kwargs...)
end
```

If you need more operations than that, maybe it isn’t so easy. But if those are the only operations you need, some custom approach like this would probably be pleasant and fast.

1 Like