Skip to content

Instantly share code, notes, and snippets.

@jtilly
Created February 19, 2016 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtilly/12ae71c74f7a7718fb9f to your computer and use it in GitHub Desktop.
Save jtilly/12ae71c74f7a7718fb9f to your computer and use it in GitHub Desktop.
Compute OLS with Fortran and Lapack
function ols(y, x, n, k) result (beta)
implicit none
external DGELS
integer, intent(in) :: n, k
real(dp), allocatable, intent(in) :: y(:), x(:, :)
integer :: info, lwork
real(dp) :: beta(k)
real(dp), allocatable :: work(:)
allocate(work(100 * n * k))
lwork = 100 * n * k
call DGELS('No transpose', n, k, 1, x, n, y, n, work, lwork, info)
beta = y(1:k)
deallocate(work)
end function ols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment