As a fix to that backsolve_hess!
works on rows instread of columns, the following, quite ugly, but a bit faster code seems to improve it by another 10-20%:
function backsolve_hess!(H::AbstractMatrix{T}, rhs::AbstractArray{T}) where {T}
# Make H UpperTriangular and apply givens to rhs
n = size(H,1)
Ht = H'
rotations = LinearAlgebra.Givens{T}[]
for i = n:-1:2
Gi, r = givens(Ht, i, i-1, i)
push!(rotations, Gi')
rmul!(H, Gi')
end
# H is now upper triangular
ldiv!(UpperTriangular(H), rhs)
for i in n-1:-1:1
lmul!(rotations[i], rhs)
end
return rhs
end
@btime testfast(H, λs, b) #48.689 ms (2017 allocations: 654.73 KiB)
@btime testfast2(H, λs, b) # 40.799 ms (9017 allocations: 8.65 MiB)
some work can probably be done on the allocations, and proper testing of this new code is probably needed.