Skip to content

Commit 3762517

Browse files
committed
documentation + example
1 parent 9f74fd7 commit 3762517

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This is an index/directory of the specifications (specs) for each new module/fea
2222
- [io](./stdlib_io.html) - Input/output helper & convenience
2323
- [kinds](./stdlib_kinds.html) - Kind parameters
2424
- [linalg](./stdlib_linalg.html) - Linear Algebra
25+
- [linalg_state_type](./stdlib_linalg_state_type.html) - Linear Algebra state and error handling
2526
- [logger](./stdlib_logger.html) - Runtime logging system
2627
- [math](./stdlib_math.html) - General purpose mathematical functions
2728
- [optval](./stdlib_optval.html) - Fallback value for optional arguments

doc/specs/stdlib_linalg_state_type.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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: `<`, `<=`, `==`, `>=`, `>`, `/=`.

example/linalg/example_state1.f90

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
program example_state1
2+
use stdlib_linalg_state
3+
implicit none
4+
type(linalg_state_type) :: err
5+
6+
! Create a state flag
7+
err = linalg_state_type(LINALG_VALUE_ERROR,'just an example with scalar ',&
8+
'integer=',1,'real=',2.0,'complex=',(3.0,1.0),'and array ',[1,2,3],'inputs')
9+
10+
! Print flag
11+
print *, err%print()
12+
13+
! Check success
14+
print *, 'Check error: ',err%error()
15+
print *, 'Check flag : ',err /= LINALG_SUCCESS
16+
17+
18+
end program example_state1

0 commit comments

Comments
 (0)