-
Notifications
You must be signed in to change notification settings - Fork 208
feat: Add generalized lagtm routine supporting arbitrary values for alpha and beta #1068
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
Open
Mahmood-Sinan
wants to merge
10
commits into
fortran-lang:master
Choose a base branch
from
Mahmood-Sinan:generalized_lagtm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+218
−15
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
27906b3
extended lagtm implemented, but only for real alpha and beta values
Mahmood-Sinan d2d9aef
alpha and beta now supports complex values also
Mahmood-Sinan c6b1a33
modularized extended lapack, but cmakefile has to be changed
Mahmood-Sinan d18b50c
changed cmakefiles.txt
Mahmood-Sinan d50fd87
added tests for random values of alpha and beta
Mahmood-Sinan 608f8ad
Update src/lapack_extended/stdlib_extended_lapack.fypp
jalvesz a27ebf8
Update src/lapack_extended/stdlib_extended_lapack.fypp
jalvesz 3428d45
changed file names from extended_lapack to lapack_extended, updated d…
Mahmood-Sinan 21a5435
updated the docs
Mahmood-Sinan ffe1a6f
Merge branch 'master' into generalized_lagtm
jvdp1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| ADD_EXAMPLE(specialmatrices_dp_spmv) | ||
| ADD_EXAMPLE(specialmatrices_cdp_spmv) | ||
| ADD_EXAMPLE(tridiagonal_dp_type) |
30 changes: 30 additions & 0 deletions
30
example/specialmatrices/example_specialmatrices_cdp_spmv.f90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| program example_tridiagonal_matrix_cdp | ||
| use stdlib_linalg_constants, only: dp | ||
| use stdlib_specialmatrices, only: tridiagonal_cdp_type, tridiagonal, dense, spmv | ||
| implicit none | ||
|
|
||
| integer, parameter :: n = 5 | ||
| type(tridiagonal_cdp_type) :: A | ||
| complex(dp) :: dl(n-1), dv(n), du(n-1) | ||
| complex(dp) :: x(n), y(n), y_dense(n) | ||
| integer :: i | ||
| complex(dp) :: alpha, beta | ||
|
|
||
| dl = [(cmplx(i,i, dp), i=1, n - 1)] | ||
| dv = [(cmplx(2*i,2*i, dp), i=1, n)] | ||
| du = [(cmplx(3*i,3*i, dp), i=1, n - 1)] | ||
|
|
||
| A = tridiagonal(dl, dv, du) | ||
|
|
||
| x = (1.0_dp, 0.0_dp) | ||
| y = (3.0_dp, -7.0_dp) | ||
| y_dense = (0.0_dp, 0.0_dp) | ||
| alpha = cmplx(2.0_dp, 3.0_dp) | ||
| beta = cmplx(-1.0_dp, 5.0_dp) | ||
|
|
||
| y_dense = alpha * matmul(dense(A), x) + beta * y | ||
| call spmv(A, x, y, alpha, beta) | ||
|
|
||
| print *, 'dense :', y_dense | ||
| print *, 'Tridiagonal :', y | ||
| end program example_tridiagonal_matrix_cdp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| set(lapack_extended_fppFiles | ||
| ../stdlib_kinds.fypp | ||
| stdlib_lapack_extended_base.fypp | ||
| stdlib_lapack_extended.fypp | ||
| ) | ||
| set(lapack_extended_cppFiles | ||
| ../stdlib_linalg_constants.fypp | ||
| ) | ||
|
|
||
| configure_stdlib_target(lapack_extended "" lapack_extended_fppFiles lapack_extended_cppFiles) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #:include "common.fypp" | ||
| #:set R_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_SUFFIX)) | ||
| #:set C_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX)) | ||
| #:set KINDS_TYPES = R_KINDS_TYPES+C_KINDS_TYPES | ||
|
|
||
| submodule(stdlib_lapack_extended_base) stdlib_lapack_extended | ||
| implicit none | ||
| contains | ||
| #:for ik,it,ii in LINALG_INT_KINDS_TYPES | ||
| #:for k1,t1,s1 in KINDS_TYPES | ||
| pure module subroutine stdlib${ii}$_glagtm_${s1}$(trans, n, nrhs, alpha, dl, d, du, x, ldx, beta, b, ldb) | ||
| character, intent(in) :: trans | ||
| integer(${ik}$), intent(in) :: ldb, ldx, n, nrhs | ||
| ${t1}$, intent(in) :: alpha, beta | ||
| ${t1}$, intent(inout) :: b(ldb,*) | ||
| ${t1}$, intent(in) :: d(*), dl(*), du(*), x(ldx,*) | ||
|
|
||
| ! Internal variables. | ||
| integer(${ik}$) :: i, j | ||
| ${t1}$ :: temp | ||
| if(n == 0) then | ||
| return | ||
| endif | ||
| if(beta == 0.0_${k1}$) then | ||
| b(1:n, 1:nrhs) = 0.0_${k1}$ | ||
| else | ||
| b(1:n, 1:nrhs) = beta * b(1:n, 1:nrhs) | ||
| end if | ||
|
|
||
| if(trans == 'N') then | ||
| do j = 1, nrhs | ||
| if(n == 1_${ik}$) then | ||
| temp = d(1_${ik}$) * x(1_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| else | ||
| temp = d(1_${ik}$) * x(1_${ik}$, j) + du(1_${ik}$) * x(2_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| do i = 2, n - 1 | ||
| temp = dl(i - 1) * x(i - 1, j) + d(i) * x(i, j) + du(i) * x(i + 1, j) | ||
| b(i, j) = b(i, j) + alpha * temp | ||
| end do | ||
| temp = dl(n - 1) * x(n - 1, j) + d(n) * x(n, j) | ||
| b(n, j) = b(n, j) + alpha * temp | ||
| end if | ||
| end do | ||
| #:if t1.startswith('complex') | ||
| else if(trans == 'C') then | ||
| do j = 1, nrhs | ||
| if(n == 1_${ik}$) then | ||
| temp = conjg(d(1_${ik}$)) * x(1_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| else | ||
| temp = conjg(d(1_${ik}$)) * x(1_${ik}$, j) + conjg(dl(1_${ik}$)) * x(2_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| do i = 2, n - 1 | ||
| temp = conjg(du(i - 1)) * x(i - 1, j) + conjg(d(i)) * x(i, j) + conjg(dl(i)) * x(i + 1, j) | ||
| b(i, j) = b(i, j) + alpha * temp | ||
| end do | ||
| temp = conjg(du(n - 1)) * x(n - 1, j) + conjg(d(n)) * x(n, j) | ||
| b(n, j) = b(n, j) + alpha * temp | ||
| end if | ||
| end do | ||
| #:endif | ||
| else | ||
| do j = 1, nrhs | ||
| if(n == 1_${ik}$) then | ||
| temp = d(1_${ik}$) * x(1_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| else | ||
| temp = d(1_${ik}$) * x(1_${ik}$, j) + dl(1_${ik}$) * x(2_${ik}$, j) | ||
| b(1_${ik}$, j) = b(1_${ik}$, j) + alpha * temp | ||
| do i = 2, n - 1 | ||
| temp = du(i - 1) * x(i - 1, j) + d(i) * x(i, j) + dl(i) * x(i + 1, j) | ||
| b(i, j) = b(i, j) + alpha * temp | ||
| end do | ||
| temp = du(n - 1) * x(n - 1, j) + d(n) * x(n, j) | ||
| b(n, j) = b(n, j) + alpha * temp | ||
| end if | ||
| end do | ||
| end if | ||
| end subroutine stdlib${ii}$_glagtm_${s1}$ | ||
| #:endfor | ||
| #:endfor | ||
|
|
||
| end submodule | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #:include "common.fypp" | ||
| #:set R_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_SUFFIX)) | ||
| #:set C_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX)) | ||
| #:set KINDS_TYPES = R_KINDS_TYPES+C_KINDS_TYPES | ||
| module stdlib_lapack_extended_base | ||
| use stdlib_linalg_constants | ||
| implicit none | ||
|
|
||
| interface glagtm | ||
| #:for ik,it,ii in LINALG_INT_KINDS_TYPES | ||
| #:for k1,t1,s1 in KINDS_TYPES | ||
| pure module subroutine stdlib${ii}$_glagtm_${s1}$(trans, n, nrhs, alpha, dl, d, du, x, ldx, beta, b, ldb) | ||
| character, intent(in) :: trans | ||
| integer(${ik}$), intent(in) :: ldb, ldx, n, nrhs | ||
| ${t1}$, intent(in) :: alpha, beta | ||
| ${t1}$, intent(inout) :: b(ldb,*) | ||
| ${t1}$, intent(in) :: d(*), dl(*), du(*), x(ldx,*) | ||
| end subroutine stdlib${ii}$_glagtm_${s1}$ | ||
| #:endfor | ||
| #:endfor | ||
| end interface | ||
| end module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we modernize this interface?
What is the reason to keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jvdp1 Thanks for the review. I kept the LAPACK style interface(
*) to stay close tolagtm, but I agree that assumed shape arrays would be more modern. I'm happy to switch to that, if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@perazz @jalvesz what do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such change should not be taken lightly. While assumed-shape is considered more safe than assumed-size for the simple reason that it enforces bound checking and helps with runtime problem detection, it also implies an API behavioral change on what is allowed or not to do with the interface.
With assumed-size declaration, one can have a 1D working array passed to the function which will be reinterpreted as a 2D array internally. with assumed-shape, this is no longer possible as ranks should match between caller and callee.
If this routine is intended to closely match but extending the capabilities of
*lagtm, then I would suggest not changing the array declaration style.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree with you. As I don't have a full overview of all the old and newLAPACK features, a second opinion is needed.
I agree with this justification.
@jalvesz @Mahmood-Sinan I consider this suggestion has being resolved. The PRcan be merged IMHO.