-
Notifications
You must be signed in to change notification settings - Fork 192
Provide state/error handling for linear algebra #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+701
−6
Merged
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7ccdb49
add `linalg` state handler
perazz 6d6fb55
cleanup, `fypp`ize numeric types
perazz e7398a0
more cleanup
perazz 31cb5eb
`complex` format: add brackets i.e. `(0.0,1.0)` instead of `0.0 1.0`
perazz 4ef4fb0
add `linalg_state` tests
perazz c5c568b
remove multiple `public` statement
perazz 88317d9
Update src/stdlib_linalg_constants.fypp
perazz 9eb9775
Update src/stdlib_linalg_constants.fypp
perazz 9f74fd7
address style changes
perazz 3762517
documentation + example
perazz cb9a7fc
generalize interface (`rank`-agnostic)
perazz 0782e43
add `xdp` formats
perazz b9e7e67
intel compiler issue: remove buffer write
perazz affd5d0
add `xdp` symbol
perazz 322b37e
move kinds to `stdlib_kinds`
perazz 526e816
Merge branch 'master' into linalg_state
perazz 41bf3a3
remove duplicate `stdlib_linalg_constants.fypp`
perazz a90f25a
more explanation
perazz fb008b4
Update example_state1.f90
perazz 00db324
add another state example
perazz 9b52091
Update example/linalg/example_state1.f90
perazz 4b3c20a
Update example/linalg/example_state2.f90
perazz 422a3d0
Update example/linalg/example_state2.f90
perazz c6ab922
Update src/stdlib_linalg_state.fypp
perazz 36b3f93
Update src/stdlib_linalg_state.fypp
perazz dbc843a
Update src/stdlib_linalg_state.fypp
perazz 33c2de6
example_state1: import `operator(/=)`
perazz dfd03fc
import `linalg_error_handling`
perazz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: linalg_state_type | ||
--- | ||
|
||
# Linear Algebra -- State and Error Handling Module | ||
|
||
[TOC] | ||
|
||
## Introduction | ||
|
||
The `stdlib_linalg_state` module provides a derived type holding information on the | ||
state of linear algebra operations, and procedures for expert control of linear algebra workflows. | ||
All linear algebra procedures are engineered to support returning an optional `linalg_state_type` | ||
variable to holds such information, as a form of expert API. If the user does not require state | ||
information, but fatal errors are encountered during the execution of linear algebra routines, the | ||
program will undergo a hard stop. | ||
Instead, if the state argument is present, the program will never stop, but will return detailed error | ||
information into the state handler. | ||
|
||
## Derived types provided | ||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### The `linalg_state_type` derived type | ||
|
||
The `linalg_state_type` is defined as a derived type containing an integer error flag, and | ||
fixed-size character strings to store an error message and the location of the error state change. | ||
Fixed-size string storage was chosen to facilitate the compiler's memory allocation and ultimately | ||
ensure maximum computational performance. | ||
|
||
A similarly named generic interface, `linalg_state_type`, is provided to allow the developer to | ||
create diagnostic messages and raise error flags easily. The call starts with an error flag or | ||
the location of the event, and is followed by an arbitrary list of `integer`, `real`, `complex` or | ||
`character` variables. Numeric variables may be provided as either scalars or rank-1 (array) inputs. | ||
|
||
#### Type-bound procedures | ||
|
||
The following convenience type-bound procedures are provided: | ||
- `print()` returns an allocatable character string containing state location, message, and error flag; | ||
- `print_message()` returns an allocatable character string containing the state message; | ||
- `ok()` returns a `logical` flag that is `.true.` in case of successful state (`flag==LINALG_SUCCESS`); | ||
- `error()` returns a `logical` flag that is `.true.` in case of error state (`flag/=LINALG_SUCCESS`). | ||
|
||
#### Status | ||
|
||
Experimental | ||
|
||
#### Example | ||
|
||
```fortran | ||
{!example/linalg/example_state1.f90!} | ||
``` | ||
|
||
## Error flags provided | ||
|
||
The module provides the following state flags: | ||
- `LINALG_SUCCESS`: Successful execution | ||
- `LINALG_VALUE_ERROR`: Numerical errors (such as infinity, not-a-number, range bounds) are encountered. | ||
- `LINALG_ERROR`: Linear Algebra errors are encountered, such as: non-converging iterations, impossible operations, etc. | ||
- `LINALG_INTERNAL_ERROR`: Provided as a developer safeguard for internal errors that should never occur. | ||
|
||
## Comparison operators provided | ||
|
||
The module provides overloaded comparison operators for all comparisons of a `linalg_state_type` variable | ||
with an integer error flag: `<`, `<=`, `==`, `>=`, `>`, `/=`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
program example_state1 | ||
use stdlib_linalg_state | ||
implicit none | ||
type(linalg_state_type) :: err | ||
|
||
! Create a state flag | ||
err = linalg_state_type(LINALG_VALUE_ERROR,'just an example with scalar ',& | ||
'integer=',1,'real=',2.0,'complex=',(3.0,1.0),'and array ',[1,2,3],'inputs') | ||
|
||
! Print flag | ||
print *, err%print() | ||
|
||
! Check success | ||
print *, 'Check error: ',err%error() | ||
print *, 'Check flag : ',err /= LINALG_SUCCESS | ||
|
||
|
||
end program example_state1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.