-
Notifications
You must be signed in to change notification settings - Fork 480
Adds new icamax with exception handling #1116
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
Merged
langou
merged 5 commits into
Reference-LAPACK:master
from
weslleyspereira:try-new-icamax
Jun 16, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
File renamed without changes.
File renamed without changes.
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,188 @@ | ||
| !> \brief \b ICAMAX | ||
| ! | ||
| ! =========== DOCUMENTATION =========== | ||
| ! | ||
| ! Online html documentation available at | ||
| ! http://www.netlib.org/lapack/explore-html/ | ||
| ! | ||
| ! Definition: | ||
| ! =========== | ||
| ! | ||
| ! INTEGER FUNCTION ICAMAX(N,X,INCX) | ||
| ! | ||
| ! .. Scalar Arguments .. | ||
| ! INTEGER INCX,N | ||
| ! .. | ||
| ! .. Array Arguments .. | ||
| ! COMPLEX X(*) | ||
| ! .. | ||
| ! | ||
| ! | ||
| !> \par Purpose: | ||
| ! ============= | ||
| !> | ||
| !> \verbatim | ||
| !> | ||
| !> ICAMAX finds the index of the first element having maximum |Re(.)| + |Im(.)| | ||
| !> \endverbatim | ||
| ! | ||
| ! Arguments: | ||
| ! ========== | ||
| ! | ||
| !> \param[in] N | ||
| !> \verbatim | ||
| !> N is INTEGER | ||
| !> number of elements in input vector(s) | ||
| !> \endverbatim | ||
| !> | ||
| !> \param[in] X | ||
| !> \verbatim | ||
| !> X is COMPLEX array, dimension ( 1 + ( N - 1 )*abs( INCX ) ) | ||
| !> \endverbatim | ||
| !> | ||
| !> \param[in] INCX | ||
| !> \verbatim | ||
| !> INCX is INTEGER | ||
| !> storage spacing between elements of X | ||
| !> \endverbatim | ||
| ! | ||
| ! Authors: | ||
| ! ======== | ||
| ! | ||
| !> James Demmel, University of California Berkeley, USA | ||
| !> Weslley Pereira, National Renewable Energy Laboratory, USA | ||
| ! | ||
| !> \ingroup iamax | ||
| ! | ||
| !> \par Further Details: | ||
| ! ===================== | ||
| !> | ||
| !> \verbatim | ||
| !> | ||
| !> James Demmel et al. Proposed Consistent Exception Handling for the BLAS and | ||
| !> LAPACK, 2022 (https://arxiv.org/abs/2207.09281). | ||
| !> | ||
| !> \endverbatim | ||
| !> | ||
| ! ===================================================================== | ||
| integer function icamax(n, x, incx) | ||
| integer, parameter :: wp = kind(1.e0) | ||
| ! | ||
| ! -- Reference BLAS level1 routine -- | ||
| ! -- Reference BLAS is a software package provided by Univ. of Tennessee, -- | ||
| ! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- | ||
| ! | ||
| ! .. Constants .. | ||
| real(wp), parameter :: hugeval = huge(0.0_wp) | ||
| ! | ||
| ! .. Scalar Arguments .. | ||
| integer :: n, incx | ||
| ! | ||
| ! .. Array Arguments .. | ||
| complex(wp) :: x(*) | ||
| ! .. | ||
| ! .. Local Scalars .. | ||
| integer :: i, j, ix, jx | ||
| real(wp) :: val, smax, scaledsmax | ||
| ! | ||
| ! Quick return if possible | ||
| ! | ||
| icamax = 0 | ||
| if (n < 1 .or. incx < 1) return | ||
| ! | ||
| icamax = 1 | ||
| if (n == 1) return | ||
| ! | ||
| icamax = 0 | ||
| scaledsmax = 0 | ||
| smax = -1 | ||
| ! | ||
| ! scaledsmax = 1 indicates that x(i) finite but | ||
| ! abs(real(x(i))) + abs(imag(x(i))) is not finite | ||
| ! | ||
| if (incx == 1) then | ||
| ! code for increment equal to 1 | ||
| do i = 1, n | ||
| if (x(i) /= x(i)) then | ||
| ! return when first NaN found | ||
| icamax = i | ||
| return | ||
| elseif (abs(real(x(i))) > hugeval .or. abs(imag(x(i))) > hugeval) then | ||
| ! keep looking for first NaN | ||
| do j = i+1, n | ||
| if (x(j) /= x(j)) then | ||
| ! return when first NaN found | ||
| icamax = j | ||
| return | ||
| endif | ||
| enddo | ||
| ! record location of first Inf | ||
| icamax = i | ||
| return | ||
| else ! still no Inf found yet | ||
| if (scaledsmax == 0) then | ||
| ! no abs(real(x(i))) + abs(imag(x(i))) = Inf yet | ||
| val = abs(real(x(i))) + abs(imag(x(i))) | ||
| if (abs(val) > hugeval) then | ||
weslleyspereira marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| scaledsmax = 1 | ||
| smax = 0.25*abs(real(x(i))) + 0.25*abs(imag(x(i))) | ||
| icamax = i | ||
| elseif (val > smax) then ! everything finite so far | ||
| smax = val | ||
| icamax = i | ||
| endif | ||
| else ! scaledsmax = 1 | ||
| val = 0.25*abs(real(x(i))) + 0.25*abs(imag(x(i))) | ||
| if (val > smax) then | ||
| smax = val | ||
| icamax = i | ||
| endif | ||
| endif | ||
| endif | ||
| end do | ||
| else | ||
| ! code for increment not equal to 1 | ||
| ix = 1 | ||
| do i = 1, n | ||
| if (x(ix) /= x(ix)) then | ||
| ! return when first NaN found | ||
| icamax = i | ||
| return | ||
| elseif (abs(real(x(ix))) > hugeval .or. abs(imag(x(ix))) > hugeval) then | ||
| ! keep looking for first NaN | ||
| jx = ix + incx | ||
| do j = i+1, n | ||
| if (x(jx) /= x(jx)) then | ||
| ! return when first NaN found | ||
| icamax = j | ||
| return | ||
| endif | ||
| jx = jx + incx | ||
| enddo | ||
| ! record location of first Inf | ||
| icamax = i | ||
| return | ||
| else ! still no Inf found yet | ||
| if (scaledsmax == 0) then | ||
| ! no abs(real(x(ix))) + abs(imag(x(ix))) = Inf yet | ||
| val = abs(real(x(ix))) + abs(imag(x(ix))) | ||
| if (abs(val) > hugeval) then | ||
| scaledsmax = 1 | ||
| smax = 0.25*abs(real(x(ix))) + 0.25*abs(imag(x(ix))) | ||
| icamax = i | ||
| elseif (val > smax) then ! everything finite so far | ||
| smax = val | ||
| icamax = i | ||
| endif | ||
| else ! scaledsmax = 1 | ||
| val = 0.25*abs(real(x(ix))) + 0.25*abs(imag(x(ix))) | ||
| if (val > smax) then | ||
| smax = val | ||
| icamax = i | ||
| endif | ||
| endif | ||
| endif | ||
| ix = ix + incx | ||
| end do | ||
| endif | ||
| end | ||
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.
Uh oh!
There was an error while loading. Please reload this page.