-
Notifications
You must be signed in to change notification settings - Fork 191
linalg: vector norms #871
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
Merged
linalg: vector norms #871
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1dbf88e
add `norms` module
perazz a9f4c7d
fix norms types
perazz 98b9b55
submodule
perazz c4433cf
add examples
perazz 7d2fb85
add tests
perazz cd53be4
document interfaces
perazz edf4757
documentation
perazz 35fadc3
attempt artifact v4
perazz 5ba7ef0
The name of the module procedure conflicts with a name in the encompa…
perazz fe23d1e
Update doc/specs/stdlib_linalg.md
perazz 7ad3ea8
Update doc/specs/stdlib_linalg.md
perazz 4e772e1
Update doc/specs/stdlib_linalg.md
perazz b405671
Update doc/specs/stdlib_linalg.md
perazz aa734de
improve argument descriptions
perazz 437b96e
use intrinsic `norm2` where possible
perazz de4f8d3
2-norm: use BLAS on contiguous or strided arrays if possible
perazz 37616ad
do not use strides
perazz 93b37ff
interface to, use and test 1-norm `asum` from BLAS
perazz f271688
drop duplicate descr
perazz 9e020a8
move `get_norm` before `norm`
perazz 0dabeac
Update src/stdlib_linalg_norms.fypp
perazz 54caa7f
Update src/stdlib_linalg_norms.fypp
perazz 07f0525
Update src/stdlib_linalg_norms.fypp
perazz a94647c
Update src/stdlib_linalg_norms.fypp
perazz 13636a9
Update example/linalg/example_get_norm.f90
perazz 92ab520
Update src/stdlib_linalg_norms.fypp
perazz 91882fa
Update example/linalg/example_get_norm.f90
perazz 1a79128
Update example/linalg/example_norm.f90
perazz 0e798ff
Merge branch 'norms' of github.com:perazz/stdlib into norms
perazz 5f6b5e8
ND arrays: use LAPACK internals via loops
perazz f6d07f8
streamline ND->1D norm functions
perazz a65e771
streamline `dim`-med norm functions
perazz 39d6daa
test infinity norm vs. `maxval(abs(.))`
perazz 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,51 @@ | ||
! Vector norm: demonstrate usage of the function interface | ||
program example_get_norm | ||
use stdlib_linalg, only: get_norm, linalg_state_type | ||
implicit none | ||
|
||
real :: a(3,3),nrm,nrmd(3) | ||
perazz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
integer :: j | ||
type(linalg_state_type) :: err | ||
|
||
! a = [ -3.00000000 0.00000000 3.00000000 | ||
! -2.00000000 1.00000000 4.00000000 | ||
! -1.00000000 2.00000000 5.00000000 ] | ||
a = reshape([(j-4,j=1,9)], [3,3]) | ||
|
||
print "(' a = [ ',3(g0,3x),2(/9x,3(g0,3x)),']')", transpose(a) | ||
|
||
! Norm with integer input | ||
call get_norm(a, nrm, 2) | ||
print *, 'Euclidean norm = ',nrm ! 8.30662346 | ||
|
||
! Norm with character input | ||
call get_norm(a, nrm, '2') | ||
print *, 'Euclidean norm = ',nrm ! 8.30662346 | ||
|
||
! Euclidean norm of row arrays, a(i,:) | ||
call get_norm(a, nrmd, 2, dim=2) | ||
print *, 'Rows norms = ',nrmd ! 4.24264050 4.58257580 5.47722578 | ||
|
||
! Euclidean norm of columns arrays, a(:,i) | ||
call get_norm(a, nrmd, 2, dim=1) | ||
print *, 'Columns norms = ',nrmd ! 3.74165750 2.23606801 7.07106781 | ||
|
||
! Infinity norms | ||
call get_norm(a, nrm, 'inf') | ||
print *, 'maxval(||a||) = ',nrm ! 5.00000000 | ||
|
||
call get_norm(a, nrmd, 'inf', dim=2) | ||
print *, 'maxval(||a(i,:)||) = ',nrmd ! 3.00000000 4.00000000 5.00000000 | ||
|
||
call get_norm(a, nrm, '-inf') | ||
print *, 'minval(||a||) = ',nrm ! 0.00000000 | ||
|
||
call get_norm(a, nrmd, '-inf', dim=1) | ||
print *, 'minval(||a(:,i)||) = ',nrmd ! 1.00000000 0.00000000 3.00000000 | ||
|
||
! Catch Error: | ||
! [norm] returned Value Error: dimension 4 is out of rank for shape(a)= [3 3] | ||
perazz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
call get_norm(a, nrmd, 'inf', dim=4, err=err) | ||
print *, 'invalid: ',err%print() | ||
|
||
end program example_get_norm |
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,40 @@ | ||
! Vector norm: demonstrate usage of the function interface | ||
program example_norm | ||
use stdlib_linalg, only: norm, linalg_state_type | ||
implicit none | ||
|
||
real :: a(3,3),na | ||
integer :: j | ||
type(linalg_state_type) :: err | ||
|
||
! a = [ -3.00000000 0.00000000 3.00000000 | ||
! -2.00000000 1.00000000 4.00000000 | ||
! -1.00000000 2.00000000 5.00000000 ] | ||
a = reshape([(j-4,j=1,9)], [3,3]) | ||
|
||
print "(' a = [ ',3(g0,3x),2(/9x,3(g0,3x)),']')", transpose(a) | ||
|
||
! Norm with integer input | ||
print *, 'Euclidean norm = ',norm(a, 2) ! 8.30662346 | ||
|
||
! Norm with character input | ||
print *, 'Euclidean norm = ',norm(a, '2') ! 8.30662346 | ||
|
||
! Euclidean norm of row arrays, a(i,:) | ||
print *, 'Rows norms = ',norm(a, 2, dim=2) ! 4.24264050 4.58257580 5.47722578 | ||
|
||
! Euclidean norm of columns arrays, a(:,i) | ||
print *, 'Columns norms = ',norm(a, 2, dim=1) ! 3.74165750 2.23606801 7.07106781 | ||
|
||
! Infinity norms | ||
print *, 'maxval(||a||) = ',norm(a, 'inf') ! 5.00000000 | ||
print *, 'maxval(||a(i,:)||) = ',norm(a, 'inf', dim=2) ! 3.00000000 4.00000000 5.00000000 | ||
print *, 'minval(||a||) = ',norm(a, '-inf') ! 0.00000000 | ||
print *, 'minval(||a(:,i)||) = ',norm(a, '-inf', dim=1) ! 1.00000000 0.00000000 3.00000000 | ||
|
||
! Catch Error: | ||
! [norm] returned Value Error: dimension 4 is out of rank for shape(a)= [3 3] | ||
perazz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print *, 'invalid: ',norm(a,'inf', dim=4, err=err) | ||
print *, 'error = ',err%print() | ||
|
||
end program example_norm |
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.
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.