Skip to content

Commit d4d1e85

Browse files
committed
docs: add interface explanation
1 parent e3c85bf commit d4d1e85

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/stdlib_linalg.fypp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,58 @@ module stdlib_linalg
13211321
#:endfor
13221322
end interface get_norm
13231323

1324-
!> Matrix norm: function interface
1324+
!> Matrix norms: function interface
13251325
interface mnorm
1326+
!! version: experimental
1327+
!!
1328+
!! Computes the matrix norm of a generic-rank array \( A \).
1329+
!! ([Specification](../page/specs/stdlib_linalg.html#mnorm-computes-the-matrix-norm-of-a-generic-rank-array))
1330+
!!
1331+
!!### Summary
1332+
!! Return one of several matrix norm metrics of a `real` or `complex` input array \( A \),
1333+
!! that can have rank 2 or higher. For rank-2 arrays, the matrix norm is returned.
1334+
!! If rank>2 and the optional input dimensions `dim` are specified,
1335+
!! a rank `n-2` array is returned with dimensions `dim(1),dim(2)` collapsed, containing all
1336+
!! matrix norms evaluated over the specified dimensions only.
1337+
!!
1338+
!!### Description
1339+
!!
1340+
!! This interface provides methods for computing the matrix norm(s) of an array.
1341+
!! Supported data types include `real` and `complex`.
1342+
!! Input arrays must have rank >= 2.
1343+
!!
1344+
!! Norm type input is mandatory, and it is provided via the `order` argument.
1345+
!! This can be provided as either an `integer` value or a `character` string.
1346+
!! Allowed metrics are:
1347+
!! - 1-norm: `order` = 1 or '1'
1348+
!! - 2-norm/Euclidean: `order` = 2 or '2' or 'Euclidean'
1349+
!! - p-norm: `order` >= 3
1350+
!! - Infinity norm: `order` = huge(0) or 'Inf'
1351+
!! - Minus-infinity norm: `order` = '-Inf'
1352+
!!
1353+
!! If an invalid norm type is provided, the routine defaults to 1-norm and returns an error state.
1354+
!!
1355+
!!### Example
1356+
!!
1357+
!!```fortran
1358+
!! real(sp) :: a(3,3), na
1359+
!! real(sp) :: b(3,3,4), nb(4) ! Array of 4 3x3 matrices
1360+
!! a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
1361+
!!
1362+
!! ! 2-norm/Euclidean norm of single matrix
1363+
!! na = mnorm(a, 'Euclidean')
1364+
!!
1365+
!! ! 1-norm of each 3x3 matrix in b
1366+
!! nb = mnorm(b, 1, dim=[1,2])
1367+
!!
1368+
!! ! p-norm with p=3
1369+
!! na = mnorm(a, 3)
1370+
!!```
1371+
!!
13261372
#:for rk,rt,ri in RC_KINDS_TYPES
13271373
#:for it,ii in NORM_INPUT_OPTIONS
1374+
1375+
!> Matrix norms: ${rt}$ rank-2 arrays
13281376
module function matrix_norm_${ii}$_${ri}$(a, order, err) result(nrm)
13291377
!> Input matrix a(m,n)
13301378
${rt}$, intent(in), target :: a(:,:)
@@ -1336,8 +1384,8 @@ module stdlib_linalg
13361384
type(linalg_state_type), intent(out), optional :: err
13371385
end function matrix_norm_${ii}$_${ri}$
13381386

1387+
!> Matrix norms: ${rt}$ higher rank arrays
13391388
#:for rank in range(3, MAXRANK + 1)
1340-
!> N-D array with optional `dim` specifier
13411389
module function matrix_norm_${rank}$D_to_${rank-2}$D_${ii}$_${ri}$(a, order, dim, err) result(nrm)
13421390
!> Input matrix a(m,n)
13431391
${rt}$, intent(in), contiguous, target :: a${ranksuffix(rank)}$

0 commit comments

Comments
 (0)