|
| 1 | +--- |
| 2 | +title: linalg_state_type |
| 3 | +--- |
| 4 | + |
| 5 | +# Linear Algebra -- State and Error Handling Module |
| 6 | + |
| 7 | +[TOC] |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +The `stdlib_linalg_state` module provides a derived type holding information on the |
| 12 | +state of linear algebra operations, and procedures for expert control of linear algebra workflows. |
| 13 | +All linear algebra procedures are engineered to support returning an optional `linalg_state_type` |
| 14 | +variable to holds such information, as a form of expert API. If the user does not require state |
| 15 | +information, but fatal errors are encountered during the execution of linear algebra routines, the |
| 16 | +program will undergo a hard stop. |
| 17 | +Instead, if the state argument is present, the program will never stop, but will return detailed error |
| 18 | +information into the state handler. |
| 19 | + |
| 20 | +## Derived types provided |
| 21 | + |
| 22 | +<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> |
| 23 | +### The `linalg_state_type` derived type |
| 24 | + |
| 25 | +The `linalg_state_type` is defined as a derived type containing an integer error flag, and |
| 26 | +fixed-size character strings to store an error message and the location of the error state change. |
| 27 | +Fixed-size string storage was chosen to facilitate the compiler's memory allocation and ultimately |
| 28 | +ensure maximum computational performance. |
| 29 | + |
| 30 | +A similarly named generic interface, `linalg_state_type`, is provided to allow the developer to |
| 31 | +create diagnostic messages and raise error flags easily. The call starts with an error flag or |
| 32 | +the location of the event, and is followed by an arbitrary list of `integer`, `real`, `complex` or |
| 33 | +`character` variables. Numeric variables may be provided as either scalars or rank-1 (array) inputs. |
| 34 | + |
| 35 | +#### Type-bound procedures |
| 36 | + |
| 37 | +The following convenience type-bound procedures are provided: |
| 38 | +- `print()` returns an allocatable character string containing state location, message, and error flag; |
| 39 | +- `print_message()` returns an allocatable character string containing the state message; |
| 40 | +- `ok()` returns a `logical` flag that is `.true.` in case of successful state (`flag==LINALG_SUCCESS`); |
| 41 | +- `error()` returns a `logical` flag that is `.true.` in case of error state (`flag/=LINALG_SUCCESS`). |
| 42 | + |
| 43 | +#### Status |
| 44 | + |
| 45 | +Experimental |
| 46 | + |
| 47 | +#### Example |
| 48 | + |
| 49 | +```fortran |
| 50 | +{!example/linalg/example_state1.f90!} |
| 51 | +``` |
| 52 | + |
| 53 | +## Error flags provided |
| 54 | + |
| 55 | +The module provides the following state flags: |
| 56 | +- `LINALG_SUCCESS`: Successful execution |
| 57 | +- `LINALG_VALUE_ERROR`: Numerical errors (such as infinity, not-a-number, range bounds) are encountered. |
| 58 | +- `LINALG_ERROR`: Linear Algebra errors are encountered, such as: non-converging iterations, impossible operations, etc. |
| 59 | +- `LINALG_INTERNAL_ERROR`: Provided as a developer safeguard for internal errors that should never occur. |
| 60 | + |
| 61 | +## Comparison operators provided |
| 62 | + |
| 63 | +The module provides overloaded comparison operators for all comparisons of a `linalg_state_type` variable |
| 64 | +with an integer error flag: `<`, `<=`, `==`, `>=`, `>`, `/=`. |
0 commit comments