Skip to content

Commit edf4757

Browse files
committed
documentation
1 parent cd53be4 commit edf4757

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,3 +1382,111 @@ If `err` is not present, exceptions trigger an `error stop`.
13821382
{!example/linalg/example_inverse_function.f90!}
13831383
```
13841384

1385+
## `norm` - Computes the vector norm of a generic-rank array.
1386+
1387+
### Status
1388+
1389+
Experimental
1390+
1391+
### Description
1392+
1393+
This function computes one of several vector norms of `real` or `complex` array \( A \), depending on
1394+
the value of the `order` input argument. \( A \) may be an array of any rank.
1395+
1396+
Result `x` returns a `real`, scalar norm value for the whole array; if `dim` is specified, `x` is a rank-1
1397+
array with the same shape as \(A \) and dimension `dim` collapsed, containing all norms evaluated along `dim`.
1398+
1399+
### Syntax
1400+
1401+
`x = ` [[stdlib_linalg(module):norm(interface)]] `(a, order, [, dim, err])`
1402+
1403+
### Arguments
1404+
1405+
`a`: Shall be a rank-n `real` or `complex` array containing the data. It is an `intent(in)` argument.
1406+
1407+
`order`: Shall be an `integer` value or a `character` flag that specifies the norm type, as follows. It is an `intent(in)` argument.
1408+
1409+
| Integer input | Character Input | Norm type |
1410+
|------------------|------------------|---------------------------------------------------------|
1411+
| `-huge(0)` | `'-inf', '-Inf'` | Minimum absolute value \( \min_i{ \left|a_i\right| } \) |
1412+
| `1` | `'1'` | 1-norm \( \sum_i{ \left|a_i\right| } \) |
1413+
| `2` | `'2'` | Euclidean norm \( \sqrt{\sum_i{ a_i^2 }} \) |
1414+
| `>=3` | `'3','4',...` | p-norm \( \left( \sum_i{ \left|a_i\right|^p }\right) ^{1/p} \) |
1415+
| `huge(0)` | `'inf', 'Inf'` | Maximum absolute value \( \max_i{ \left|a_i\right| } \) |
1416+
1417+
`dim` (optional): Shall be a scalar `integer` value with a value in the range from `1` to `n`, where `n` is the rank of the array. It is an `intent(in)` argument.
1418+
1419+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument. If `err` is not present, the function is `pure`.
1420+
1421+
### Return value
1422+
1423+
By default, the return value `x` is a scalar, and contains the norm as evaluated over all elements of the generic-rank array \( A \).
1424+
If the optional `dim` argument is present, `x` is a rank `n-1` array with the same shape as \( A \) except
1425+
for dimension `dim`, that is collapsed. Each element of `x` contains the 1D norm of the elements of \( A \),
1426+
evaluated along dimension `dim` only.
1427+
1428+
Raises `LINALG_ERROR` if the requested norm type is invalid.
1429+
Raises `LINALG_VALUE_ERROR` if any of the arguments has an invalid size.
1430+
If `err` is not present, exceptions trigger an `error stop`.
1431+
1432+
### Example
1433+
1434+
```fortran
1435+
{!example/linalg/example_norm.f90!}
1436+
```
1437+
1438+
## `get_norm` - Computes the vector norm of a generic-rank array.
1439+
1440+
### Status
1441+
1442+
Experimental
1443+
1444+
### Description
1445+
1446+
This `pure subroutine` interface computes one of several vector norms of `real` or `complex` array \( A \), depending on
1447+
the value of the `order` input argument. \( A \) may be an array of any rank.
1448+
1449+
Result `nrm` returns a `real`, scalar norm value for the whole array; if `dim` is specified, `nrm` is a rank-1
1450+
array with the same shape as \(A \) and dimension `dim` collapsed, containing all norms evaluated along `dim`.
1451+
1452+
### Syntax
1453+
1454+
`call ` [[stdlib_linalg(module):get_norm(interface)]] `(a, nrm, order, [, dim, err])`
1455+
1456+
### Arguments
1457+
1458+
`a`: Shall be a rank-n `real` or `complex` array containing the data. It is an `intent(in)` argument.
1459+
1460+
`nrm`: if `dim` is absent, shall be a scalar with the norm evaluated over all the elements of the array. Otherwise, an array of rank `n-1`, and a shape similar
1461+
to that of `a` with dimension `dim` dropped.
1462+
1463+
`order`: Shall be an `integer` value or a `character` flag that specifies the norm type, as follows. It is an `intent(in)` argument.
1464+
1465+
| Integer input | Character Input | Norm type |
1466+
|------------------|------------------|---------------------------------------------------------|
1467+
| `-huge(0)` | `'-inf', '-Inf'` | Minimum absolute value \( \min_i{ \left|a_i\right| } \) |
1468+
| `1` | `'1'` | 1-norm \( \sum_i{ \left|a_i\right| } \) |
1469+
| `2` | `'2'` | Euclidean norm \( \sqrt{\sum_i{ a_i^2 }} \) |
1470+
| `>=3` | `'3','4',...` | p-norm \( \left( \sum_i{ \left|a_i\right|^p }\right) ^{1/p} \) |
1471+
| `huge(0)` | `'inf', 'Inf'` | Maximum absolute value \( \max_i{ \left|a_i\right| } \) |
1472+
1473+
`dim` (optional): Shall be a scalar `integer` value with a value in the range from `1` to `n`, where `n` is the rank of the array. It is an `intent(in)` argument.
1474+
1475+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument. If `err` is not present, the function is `pure`.
1476+
1477+
### Return value
1478+
1479+
By default, the return value `nrm` is a scalar, and contains the norm as evaluated over all elements of the generic-rank array \( A \).
1480+
If the optional `dim` argument is present, `nrm` is a rank `n-1` array with the same shape as \( A \) except
1481+
for dimension `dim`, that is collapsed. Each element of `nrm` contains the 1D norm of the elements of \( A \),
1482+
evaluated along dimension `dim` only.
1483+
1484+
Raises `LINALG_ERROR` if the requested norm type is invalid.
1485+
Raises `LINALG_VALUE_ERROR` if any of the arguments has an invalid size.
1486+
If `err` is not present, exceptions trigger an `error stop`.
1487+
1488+
### Example
1489+
1490+
```fortran
1491+
{!example/linalg/example_get_norm.f90!}
1492+
```

0 commit comments

Comments
 (0)