-
Notifications
You must be signed in to change notification settings - Fork 22
Replace enorm with intrinsic norm2 #45
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
ivan-pi
wants to merge
6
commits into
fortran-lang:main
Choose a base branch
from
ivan-pi:norm2
base: main
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.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4f60b0
Replace enorm with intrinsic norm2
ivan-pi 0e48dd5
Import precision in enorm
ivan-pi 01bad72
Add missing parameters in enorm
ivan-pi b4b72ae
Replace enorm in examples
ivan-pi 008400c
Replace enorm with norm2 in tests
ivan-pi 9abf8be
Remove enorm function
ivan-pi 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
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
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,73 @@ | ||
!***************************************************************************************** | ||
!> | ||
! given an n-vector x, this function calculates the | ||
! euclidean norm of x. | ||
! | ||
! the euclidean norm is computed by accumulating the sum of | ||
! squares in three different sums. the sums of squares for the | ||
! small and large components are scaled so that no overflows | ||
! occur. non-destructive underflows are permitted. underflows | ||
! and overflows do not occur in the computation of the unscaled | ||
! sum of squares for the intermediate components. | ||
! the definitions of small, intermediate and large components | ||
! depend on two constants, rdwarf and rgiant. the main | ||
! restrictions on these constants are that rdwarf**2 not | ||
! underflow and rgiant**2 not overflow. the constants | ||
! given here are suitable for every known computer. | ||
|
||
pure real(wp) function enorm(n, x) | ||
use, intrinsic :: iso_fortran_env, only: wp => real64 | ||
implicit none | ||
|
||
integer, intent(in) :: n !! a positive integer input variable. | ||
real(wp), intent(in) :: x(n) !! an input array of length n. | ||
|
||
integer :: i | ||
real(wp) :: agiant, s1, s2, s3, xabs, x1max, x3max | ||
|
||
real(wp), parameter :: rdwarf = 3.834e-20_wp | ||
real(wp), parameter :: rgiant = 1.304e19_wp | ||
real(wp), parameter :: one = 1.0_wp | ||
real(wp), parameter :: zero = 0.0_wp | ||
|
||
s1 = zero | ||
s2 = zero | ||
s3 = zero | ||
x1max = zero | ||
x3max = zero | ||
agiant = rgiant/real(n, wp) | ||
do i = 1, n | ||
xabs = abs(x(i)) | ||
if (xabs > rdwarf .and. xabs < agiant) then | ||
! sum for intermediate components. | ||
s2 = s2 + xabs**2 | ||
elseif (xabs <= rdwarf) then | ||
! sum for small components. | ||
if (xabs <= x3max) then | ||
if (xabs /= zero) s3 = s3 + (xabs/x3max)**2 | ||
else | ||
s3 = one + s3*(x3max/xabs)**2 | ||
x3max = xabs | ||
end if | ||
! sum for large components. | ||
elseif (xabs <= x1max) then | ||
s1 = s1 + (xabs/x1max)**2 | ||
else | ||
s1 = one + s1*(x1max/xabs)**2 | ||
x1max = xabs | ||
end if | ||
end do | ||
|
||
! calculation of norm. | ||
|
||
if (s1 /= zero) then | ||
enorm = x1max*sqrt(s1 + (s2/x1max)/x1max) | ||
elseif (s2 == zero) then | ||
enorm = x3max*sqrt(s3) | ||
else | ||
if (s2 >= x3max) enorm = sqrt(s2*(one + (x3max/s2)*(x3max*s3))) | ||
if (s2 < x3max) enorm = sqrt(x3max*((s2/x3max) + (x3max*s3))) | ||
end if | ||
|
||
end function enorm | ||
!***************************************************************************************** |
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.