Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FastLapackInterface.jl? #300

Open
nathanaelbosch opened this issue Feb 9, 2024 · 0 comments
Open

Use FastLapackInterface.jl? #300

nathanaelbosch opened this issue Feb 9, 2024 · 0 comments

Comments

@nathanaelbosch
Copy link
Owner

https://github.com/DynareJulia/FastLapackInterface.jl
We're already doing something similar in

"""
getupperright!(A)
Get the upper right part of a matrix `A` without allocating.
This function is mostly there to make accessing `R` from a `QR` object more efficient, as
`qr!(A).R` allocates since it does not use views. This function is not exported and is only
ever used internally by `triangularize!`(@ref).
"""
function getupperright!(A)
m, n = size(A)
return UpperTriangular(triu!(A[1:min(m, n), 1:n]))
end
"""
triangularize!(A; [cachemat])
Compute `qr(A).R` in the most efficient and allocation-free way possible.
The fallback implementation essentially computes `qr!(A).R`. But if `A` is of type
`StridedMatrix{<:LinearAlgebra.BlasFloat}`, we can make things more efficient by calling
LAPACK directly and using the preallocated cache `cachemat`.
"""
triangularize!(A; cachemat)
function triangularize!(A; cachemat=nothing)
QR = qr!(A)
return getupperright!(getfield(QR, :factors))
end
function triangularize!(A::StridedMatrix{<:LinearAlgebra.BlasFloat}; cachemat)
D = size(A, 2)
BLOCKSIZE = 36
R, _ = LinearAlgebra.LAPACK.geqrt!(A, @view cachemat[1:min(BLOCKSIZE, D), :])
return getupperright!(R)
end

but not quite. FastLapackInterface.jl might be the cleaner way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant