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

linalg: solve #806

Merged
merged 33 commits into from
May 11, 2024
Merged

linalg: solve #806

merged 33 commits into from
May 11, 2024

Conversation

perazz
Copy link
Member

@perazz perazz commented Apr 25, 2024

Linear system solution $Ax=b$, for both 1-rhs (b(:)) or n-rhs (b(:,:)) cases, based on LAPACK *GESV functions.

  • base implementation
  • tests
  • exclude unsupported xdp
  • documentation
  • submodule
  • examples
  • pure subroutine interface

Prior art:

  • NumPy: solve(a, b)
  • Scipy: solve(a, b, lower=False, overwrite_a=False, overwrite_b=False, check_finite=True, assume_a='gen', transposed=False)
  • IMSL: lu_solve(a, b, transpose=False)
  • Add solve based on OpenBLAS #710 cc @zoziha

Proposed implementation:

  • pure (only intent(in) arguments)
  • "expert" interface (intent(out) error handler, a can be overwritten)

Example calls:

  • x = solve(a,b) -> simplest pure call
  • x = solve(a,b,overwrite_a=.false.,err) -> expert call:
    • logical(lk), optional, intent(in) :: overwrite_a = option to avoid internal allocation, but destroy input matrix a. Default: .false.
    • type(linalg_state_type), intent(out) :: err = return state variable

cc: @jvdp1 @zoziha @jalvesz @fortran-lang/stdlib: I believe this is ready for consideration.

@perazz perazz marked this pull request as ready for review April 26, 2024 08:12
Copy link
Contributor

@zoziha zoziha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @perazz, thanks for your efforts, stdlib gradually has a user-friendly, high-level BLAS API.

perazz and others added 2 commits April 27, 2024 14:39
Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Here are a few suggestions/comments.

@perazz
Copy link
Member Author

perazz commented Apr 30, 2024

@jvdp1 @zoziha I've implemented a pure subroutine interface, that looks like this:

call solve_lu(a,b,x,pivot=ipiv,overwrite_a=.true.,err=err)
  • Is solve_lu a good name? I've chosen this because it follows the same pattern as solve_lstsq in the least-squares interface
  • Both the subroutine and the function interfaces are now pure

Please, let me know what you think of this approach, I will complete the documentation for this after we've defined the final version. Thanks!

@jvdp1
Copy link
Member

jvdp1 commented Apr 30, 2024

@jvdp1 @zoziha I've implemented a pure subroutine interface

Great! Thanks @perazz. LGTM

  • Is solve_lu a good name? I've chosen this because it follows the same pattern as solve_lstsq in the least-squares interface

LGTM. it makes sense and gives some info on how it is solves.

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @perazz . LGTM, and it is almost ready to be merged. Nice addition!

@jvdp1 jvdp1 mentioned this pull request May 8, 2024
7 tasks
@perazz
Copy link
Member Author

perazz commented May 9, 2024

Dear all @jvdp1 @jalvesz @zoziha I've documented the subroutine interface and added a no-allocation example.
I believe this should be ready now. pivot is the only pre-allocated array needed in this case. I suggest we wait until we have the full picture (what pre-allocated arrays do svd, eig, etc. need? ) so we can create a linalg_storage type a posteriori

@jvdp1
Copy link
Member

jvdp1 commented May 11, 2024

Thank you @perazz . I will merge it.
As discussed here, I will prepare a new release today/tomorrow.

@jvdp1 jvdp1 merged commit 3bdcc82 into fortran-lang:master May 11, 2024
17 checks passed
@perazz
Copy link
Member Author

perazz commented May 11, 2024

Thanks a lot @jvdp1

@jvdp1 jvdp1 mentioned this pull request May 11, 2024
7 tasks
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

Successfully merging this pull request may close these issues.

4 participants