-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'activations' of https://github.com/jalvesz/stdlib into …
…activations
- Loading branch information
Showing
17 changed files
with
1,314 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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 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) | ||
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] | ||
call get_norm(a, nrmd, 'inf', dim=4, err=err) | ||
print *, 'invalid: ',err%print() | ||
|
||
end program example_get_norm |
This file contains 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] | ||
print *, 'invalid: ',norm(a,'inf', dim=4, err=err) | ||
print *, 'error = ',err%print() | ||
|
||
end program example_norm |
This file contains 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 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.