Skip to content

Commit cd53be4

Browse files
committed
document interfaces
1 parent 7d2fb85 commit cd53be4

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

src/stdlib_linalg.fypp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,49 @@ module stdlib_linalg
10741074
#:set NORM_INPUT_OPTIONS = list(zip(NORM_INPUT_TYPE,NORM_INPUT_SHORT))
10751075
! Vector norms: function interface
10761076
interface norm
1077+
!! version: experimental
1078+
!!
1079+
!! Computes the vector norm of a generic-rank array \( A \).
1080+
!! ([Specification](../page/specs/stdlib_linalg.html#norm-computes-the-vector-norm-of-a-generic-rank-array))
1081+
!!
1082+
!!### Summary
1083+
!! Return one of several scalar norm metrics of a `real` or `complex` input array \( A \),
1084+
!! that can have any rank. For generic rank-n arrays, the scalar norm over the whole
1085+
!! array is returned by default. If `n>=2` and the optional input dimension `dim` is specified,
1086+
!! a rank `n-1` array is returned with dimension `dim` collapsed, containing all 1D array norms
1087+
!! evaluated along dimension `dim` only.
1088+
!!
1089+
!!
1090+
!!### Description
1091+
!!
1092+
!! This interface provides methods for computing the vector norm(s) of an array.
1093+
!! Supported data types include `real` and `complex`.
1094+
!! Input arrays may have generic rank from 1 to ${MAXRANK}$.
1095+
!!
1096+
!! Norm type input is mandatory, and it is provided via the `order` argument.
1097+
!! This can be provided as either an `integer` value or a `character` string.
1098+
!! Allowed metrics are:
1099+
!! - 1-norm \( \sum_i{ \left|a_i\right| } \): `order` = 1 or '1'
1100+
!! - Euclidean norm \( \sqrt{\sum_i{ a_i^2 }} \): `order` = 2 or '2'
1101+
!! - p-norm \( \left( \sum_i{ \left|a_i\right|^p }\right) ^{1/p} \): `integer` `order`, order>=3
1102+
!! - Infinity norm \( \max_i{ \left|a_i\right| } \): order = huge(0) or 'inf'
1103+
!! - Minus-infinity norm \( \min_i{ \left|a_i\right| } \): order = -huge(0) or '-inf'
1104+
!!
1105+
!!### Example
1106+
!!
1107+
!!```fortran
1108+
!!
1109+
!! real(sp) :: a(3,3), na, rown(3)
1110+
!! a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
1111+
!!
1112+
!! ! L2 norm: whole matrix
1113+
!! na = norm(a, 2)
1114+
!!
1115+
!! ! Infinity norm of each row
1116+
!! rown = norm(a, 'inf', dim=2)
1117+
!!
1118+
!!```
1119+
!!
10771120
#:for rk,rt,ri in RC_KINDS_TYPES
10781121
#:for it,ii in NORM_INPUT_OPTIONS
10791122
!> Scalar norms: ${rt}$
@@ -1128,6 +1171,50 @@ module stdlib_linalg
11281171

11291172
!> Vector norm: subroutine interface
11301173
interface get_norm
1174+
!! version: experimental
1175+
!!
1176+
!! Computes the vector norm of a generic-rank array \( A \).
1177+
!! ([Specification](../page/specs/stdlib_linalg.html#get-norm-computes-the-vector-norm-of-a-generic-rank-array))
1178+
!!
1179+
!!### Summary
1180+
!! Subroutine interface that returns one of several scalar norm metrics of a `real` or `complex`
1181+
!! input array \( A \), that can have any rank. For generic rank-n arrays, the scalar norm over
1182+
!! the whole array is returned by default. If `n>=2` and the optional input dimension `dim` is
1183+
!! specified, a rank `n-1` array is returned with dimension `dim` collapsed, containing all 1D
1184+
!! array norms evaluated along dimension `dim` only.
1185+
!!
1186+
!!
1187+
!!### Description
1188+
!!
1189+
!! This `pure subroutine `interface provides methods for computing the vector norm(s) of an array.
1190+
!! Supported data types include `real` and `complex`.
1191+
!! Input arrays may have generic rank from 1 to ${MAXRANK}$.
1192+
!!
1193+
!! Norm type input is mandatory, and it is provided via the `order` argument.
1194+
!! This can be provided as either an `integer` value or a `character` string.
1195+
!! Allowed metrics are:
1196+
!! - 1-norm \( \sum_i{ \left|a_i\right| } \): `order` = 1 or '1'
1197+
!! - Euclidean norm \( \sqrt{\sum_i{ a_i^2 }} \): `order` = 2 or '2'
1198+
!! - p-norm \( \left( \sum_i{ \left|a_i\right|^p }\right) ^{1/p} \): `integer` `order`, order>=3
1199+
!! - Infinity norm \( \max_i{ \left|a_i\right| } \): order = huge(0) or 'inf'
1200+
!! - Minus-infinity norm \( \min_i{ \left|a_i\right| } \): order = -huge(0) or '-inf'
1201+
!!
1202+
!!### Example
1203+
!!
1204+
!!```fortran
1205+
!!
1206+
!! real(sp) :: a(3,3), na, rown(3)
1207+
!! type(linalg_state_type) :: err
1208+
!! a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
1209+
!!
1210+
!! ! L2 norm: whole matrix
1211+
!! call get_norm(a, na, 2)
1212+
!!
1213+
!! ! Infinity norms of each row, with error control
1214+
!! call get_norm(a, rown, 'inf', dim=2, err=err)
1215+
!!
1216+
!!```
1217+
!!
11311218
#:for rk,rt,ri in RC_KINDS_TYPES
11321219
#:for it,ii in NORM_INPUT_OPTIONS
11331220
!> Scalar norms: ${rt}$

0 commit comments

Comments
 (0)