@@ -1321,10 +1321,58 @@ module stdlib_linalg
1321
1321
#:endfor
1322
1322
end interface get_norm
1323
1323
1324
- !> Matrix norm : function interface
1324
+ !> Matrix norms : function interface
1325
1325
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
+ !!
1326
1372
#:for rk,rt,ri in RC_KINDS_TYPES
1327
1373
#:for it,ii in NORM_INPUT_OPTIONS
1374
+
1375
+ !> Matrix norms: ${rt}$ rank-2 arrays
1328
1376
module function matrix_norm_${ii}$_${ri}$(a, order, err) result(nrm)
1329
1377
!> Input matrix a(m,n)
1330
1378
${rt}$, intent(in), target :: a(:,:)
@@ -1336,8 +1384,8 @@ module stdlib_linalg
1336
1384
type(linalg_state_type), intent(out), optional :: err
1337
1385
end function matrix_norm_${ii}$_${ri}$
1338
1386
1387
+ !> Matrix norms: ${rt}$ higher rank arrays
1339
1388
#:for rank in range(3, MAXRANK + 1)
1340
- !> N-D array with optional `dim` specifier
1341
1389
module function matrix_norm_${rank}$D_to_${rank-2}$D_${ii}$_${ri}$(a, order, dim, err) result(nrm)
1342
1390
!> Input matrix a(m,n)
1343
1391
${rt}$, intent(in), contiguous, target :: a${ranksuffix(rank)}$
0 commit comments