Skip to content

Commit 140fc7f

Browse files
committed
Merge branch 'cholesky' of github.com:perazz/stdlib into cholesky
2 parents 2549839 + 8955bf0 commit 140fc7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+26420
-23827
lines changed

API-doc-FORD-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ project_website: https://stdlib.fortran-lang.org
4343
favicon: doc/media/favicon.ico
4444
license: by-sa
4545
author: fortran-lang/stdlib contributors
46-
author_pic: https://fortran-lang.org/assets/img/fortran_logo_512x512.png
46+
author_pic: https://fortran-lang.org/en/_static/fortran-logo-256x256.png
4747
4848
github: https://github.com/fortran-lang
4949
twitter: https://twitter.com/fortranlang

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# Version 0.7.0
2+
3+
Full release notes available at [v0.7.0] tag.
4+
5+
[v0.7.0]: https://github.com/fortran-lang/stdlib/releases/tag/v0.7.0
6+
7+
- new module `stdlib_constants`
8+
[#800](https://github.com/fortran-lang/stdlib/pull/800)
9+
- Many mathematical constants and most common physical ([codata](https://codata.org)) constants
10+
11+
Changes to existing scripts and modules
12+
- changes in CI
13+
- Use of `fortran-setup` for GCC, Intel LLVM and Intel Classic
14+
[#834](https://github.com/fortran-lang/stdlib/pull/834)
15+
- change in module `stdlib_hashmaps`
16+
- Support of hash map key generic interfaces
17+
[#827](https://github.com/fortran-lang/stdlib/pull/827)
18+
- changes in module `stdlib_io`
19+
- Addition of a Fortran format specifier in `loadtxt`
20+
[#805](https://github.com/fortran-lang/stdlib/pull/805)
21+
- changes in module `stdlib_linalg`
22+
- Support of extended and quad precision checking
23+
[#821](https://github.com/fortran-lang/stdlib/pull/821)
24+
- Several fixes
25+
[#815](https://github.com/fortran-lang/stdlib/pull/815)
26+
[#818](https://github.com/fortran-lang/stdlib/pull/818)
27+
[#826](https://github.com/fortran-lang/stdlib/pull/826)
28+
[#830](https://github.com/fortran-lang/stdlib/pull/830)
29+
[#836](https://github.com/fortran-lang/stdlib/pull/836)
30+
- New procedures for Eigenvalues and Eigenvectors computation: `eig`, `eigh`, `eigvals`, `eigvalsh`
31+
[#816](https://github.com/fortran-lang/stdlib/pull/816)
32+
- New procedures for Singular Value Decomposition: `svd`, `svdvals`
33+
[#808](https://github.com/fortran-lang/stdlib/pull/808)
34+
- changes in module `stdlib_sorting`
35+
- Renamed variable from `int_size` to `int_index`
36+
[#824](https://github.com/fortran-lang/stdlib/pull/824)
37+
- Support of `int32` `index` array in `sort_index`
38+
[#829](https://github.com/fortran-lang/stdlib/pull/829)
39+
40+
141
# Version 0.6.1
242

343
Full release notes available at [v0.6.1] tag.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.6.1
1+
0.7.0

doc/specs/stdlib_linalg.md

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ end interface axpy
104104
Note that the 128-bit functions are only provided by `stdlib` and always point to the internal implementation.
105105
Because 128-bit precision is identified as [stdlib_kinds(module):qp], initials for 128-bit procedures were
106106
labelled as `q` (quadruple-precision reals) and `w` ("wide" or quadruple-precision complex numbers).
107-
Extended precision ([stdlib_kinds(module):xdp]) calculations are currently not supported.
107+
Extended precision ([stdlib_kinds(module):xdp]) calculations are labelled as `x` (extended-precision reals).
108+
and `y` (extended-precision complex numbers).
108109

109110
### Example
110111

@@ -779,7 +780,7 @@ Result vector `x` returns the approximate solution that minimizes the 2-norm \(
779780

780781
`cond` (optional): Shall be a scalar `real` value cut-off threshold for rank evaluation: `s_i >= cond*maxval(s), i=1:rank`. Shall be a scalar, `intent(in)` argument.
781782

782-
`singvals` (optional): Shall be a `real` rank-1 array of the same kind `a` and size at least `minval(shape(a))`, returning the list of singular values `s(i)>=cond*maxval(s)`, in descending order of magnitude. It is an `intent(out)` argument.
783+
`singvals` (optional): Shall be a `real` rank-1 array of the same kind `a` and size at least `min(m,n)`, returning the list of singular values `s(i)>=cond*maxval(s)` from the internal SVD, in descending order of magnitude. It is an `intent(out)` argument.
783784

784785
`overwrite_a` (optional): Shall be an input `logical` flag. If `.true.`, input matrix `A` will be used as temporary storage and overwritten. This avoids internal data allocation. This is an `intent(in)` argument.
785786

@@ -881,15 +882,15 @@ This interface is equivalent to the `pure` version of determinant [[stdlib_linal
881882

882883
### Syntax
883884

884-
`c = ` [[stdlib_linalg(module):operator(.det.)(interface)]] `(a)`
885+
`c = ` [[stdlib_linalg(module):operator(.det.)(interface)]] `a`
885886

886887
### Arguments
887888

888889
`a`: Shall be a rank-2 square array of any `real` or `complex` kinds. It is an `intent(in)` argument.
889890

890891
### Return value
891892

892-
Returns a real scalar value that represents the determinnt of the matrix.
893+
Returns a real scalar value that represents the determinant of the matrix.
893894

894895
Raises `LINALG_ERROR` if the matrix is singular.
895896
Raises `LINALG_VALUE_ERROR` if the matrix is non-square.
@@ -1260,3 +1261,124 @@ Exceptions trigger an `error stop`, unless argument `err` is present.
12601261
{!example/linalg/example_chol.f90!}
12611262
```
12621263

1264+
1265+
## `.inv.` - Inverse operator of a square matrix
1266+
1267+
### Status
1268+
1269+
Experimental
1270+
1271+
### Description
1272+
1273+
This operator returns the inverse of a `real` or `complex` square matrix \( A \).
1274+
The inverse \( A^{-1} \) is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
1275+
1276+
This interface is equivalent to the function [[stdlib_linalg(module):inv(interface)]].
1277+
1278+
### Syntax
1279+
1280+
`b = ` [[stdlib_linalg(module):operator(.inv.)(interface)]] `a`
1281+
1282+
### Arguments
1283+
1284+
`a`: Shall be a rank-2 square array of any `real` or `complex` kinds. It is an `intent(in)` argument.
1285+
1286+
### Return value
1287+
1288+
Returns a rank-2 square array with the same type, kind and rank as `a`, that contains the inverse of `a`.
1289+
1290+
If an exception occurred on input errors, or singular matrix, `NaN`s will be returned.
1291+
For fine-grained error control in case of singular matrices prefer the `subroutine` and the `function`
1292+
interfaces.
1293+
1294+
### Example
1295+
1296+
```fortran
1297+
{!example/linalg/example_inverse_operator.f90!}
1298+
```
1299+
1300+
## `invert` - Inversion of a square matrix
1301+
1302+
### Status
1303+
1304+
Experimental
1305+
1306+
### Description
1307+
1308+
This subroutine inverts a square `real` or `complex` matrix in-place.
1309+
The inverse \( A^{-1} \) is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
1310+
1311+
On return, the input matrix `a` is replaced by its inverse.
1312+
The solver is based on LAPACK's `*GETRF` and `*GETRI` backends.
1313+
1314+
### Syntax
1315+
1316+
`call ` [[stdlib_linalg(module):invert(interface)]] `(a, [,inva] [, pivot] [, err])`
1317+
1318+
### Arguments
1319+
1320+
`a`: Shall be a rank-2, square, `real` or `complex` array containing the coefficient matrix.
1321+
If `inva` is provided, it is an `intent(in)` argument.
1322+
If `inva` is not provided, it is an `intent(inout)` argument: on output, it is replaced by the inverse of `a`.
1323+
1324+
`inva` (optional): Shall be a rank-2, square, `real` or `complex` array with the same size, and kind as `a`.
1325+
On output, it contains the inverse of `a`.
1326+
1327+
`pivot` (optional): Shall be a rank-1 array of the same kind and matrix dimension as `a`, that contains the diagonal pivot indices on return. It is an `intent(inout)` argument.
1328+
1329+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
1330+
1331+
### Return value
1332+
1333+
Computes the inverse of the matrix \( A \), \(A^{-1}\, and returns it either in \( A \) or in another matrix.
1334+
1335+
Raises `LINALG_ERROR` if the matrix is singular or has invalid size.
1336+
Raises `LINALG_VALUE_ERROR` if `inva` and `a` do not have the same size.
1337+
If `err` is not present, exceptions trigger an `error stop`.
1338+
1339+
### Example
1340+
1341+
```fortran
1342+
{!example/linalg/example_inverse_inplace.f90!}
1343+
```
1344+
1345+
```fortran
1346+
{!example/linalg/example_inverse_subroutine.f90!}
1347+
```
1348+
1349+
## `inv` - Inverse of a square matrix.
1350+
1351+
### Status
1352+
1353+
Experimental
1354+
1355+
### Description
1356+
1357+
This function returns the inverse of a square `real` or `complex` matrix in-place.
1358+
The inverse, \( A^{-1} \), is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
1359+
1360+
The solver is based on LAPACK's `*GETRF` and `*GETRI` backends.
1361+
1362+
### Syntax
1363+
1364+
`b ` [[stdlib_linalg(module):inv(interface)]] `(a, [, err])`
1365+
1366+
### Arguments
1367+
1368+
`a`: Shall be a rank-2, square, `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
1369+
1370+
`err` (optional): Shall be a `type(linalg_state_type)` value. It is an `intent(out)` argument.
1371+
1372+
### Return value
1373+
1374+
Returns an array value of the same type, kind and rank as `a`, that contains the inverse matrix \(A^{-1}\).
1375+
1376+
Raises `LINALG_ERROR` if the matrix is singular or has invalid size.
1377+
If `err` is not present, exceptions trigger an `error stop`.
1378+
1379+
### Example
1380+
1381+
```fortran
1382+
{!example/linalg/example_inverse_function.f90!}
1383+
```
1384+

doc/specs/stdlib_math.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,70 @@ Notes: Although the angle of the complex number `0` is undefined, `argpi((0,0))`
382382
{!example/math/example_math_argpi.f90!}
383383
```
384384

385+
### `deg2rad`
386+
387+
#### Status
388+
389+
Experimental
390+
391+
#### Class
392+
393+
Elemenal function.
394+
395+
### Description
396+
397+
`deg2rad` converts phase angles from degrees to radians.
398+
399+
#### Syntax
400+
401+
`result = ` [[stdlib_math(module):deg2rad(interface)]] `(theta)`
402+
403+
#### Arguments
404+
405+
`theta`: Shall be a `real` scalar/array.
406+
407+
#### Return value
408+
409+
Returns the `real` phase angle in radians.
410+
411+
#### Example
412+
413+
```fortran
414+
{!example/math/example_math_deg2rad.f90!}
415+
```
416+
417+
### `rad2deg`
418+
419+
#### Status
420+
421+
Experimental
422+
423+
#### Class
424+
425+
Elemenal function.
426+
427+
### Description
428+
429+
`rad2deg` converts phase angles from radians to degrees.
430+
431+
#### Syntax
432+
433+
`result = ` [[stdlib_math(module):rad2deg(interface)]] `(theta)`
434+
435+
#### Arguments
436+
437+
`theta`: Shall be a `real` scalar/array.
438+
439+
#### Return value
440+
441+
Returns the `real` phase angle in degrees.
442+
443+
#### Example
444+
445+
```fortran
446+
{!example/math/example_math_rad2deg.f90!}
447+
```
448+
385449
### `is_close` function
386450

387451
#### Description

example/linalg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ADD_EXAMPLE(is_skew_symmetric)
1212
ADD_EXAMPLE(is_square)
1313
ADD_EXAMPLE(is_symmetric)
1414
ADD_EXAMPLE(is_triangular)
15+
ADD_EXAMPLE(inverse_operator)
16+
ADD_EXAMPLE(inverse_function)
17+
ADD_EXAMPLE(inverse_inplace)
18+
ADD_EXAMPLE(inverse_subroutine)
1519
ADD_EXAMPLE(outer_product)
1620
ADD_EXAMPLE(eig)
1721
ADD_EXAMPLE(eigh)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! Matrix inversion example: function interface
2+
program example_inverse_function
3+
use stdlib_linalg_constants, only: dp
4+
use stdlib_linalg, only: inv,eye
5+
implicit none
6+
7+
real(dp) :: A(2,2), Am1(2,2)
8+
9+
! Input matrix (NB Fortran is column major! input columns then transpose)
10+
A = transpose(reshape( [4, 3, &
11+
3, 2], [2,2] ))
12+
13+
! Invert matrix
14+
Am1 = inv(A)
15+
16+
print *, ' |',Am1(1,:),'|' ! | -2 3 |
17+
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 |
18+
19+
! Final check
20+
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2)
21+
22+
end program example_inverse_function
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! Matrix inversion example: in-place inversion
2+
program example_inverse_inplace
3+
use stdlib_linalg_constants, only: dp
4+
use stdlib_linalg, only: invert,eye
5+
implicit none
6+
7+
real(dp) :: A(2,2), Am1(2,2)
8+
9+
! Input matrix (NB Fortran is column major! input columns then transpose)
10+
A = transpose(reshape( [4, 3, &
11+
3, 2], [2,2] ))
12+
Am1 = A
13+
14+
! Invert matrix
15+
call invert(Am1)
16+
17+
print *, ' |',Am1(1,:),'|' ! | -2 3 |
18+
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 |
19+
20+
! Final check
21+
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2)
22+
23+
end program example_inverse_inplace
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! Matrix inversion example: operator interface
2+
program example_inverse_operator
3+
use stdlib_linalg_constants, only: dp
4+
use stdlib_linalg, only: operator(.inv.),eye
5+
implicit none
6+
7+
real(dp) :: A(2,2), Am1(2,2)
8+
9+
! Input matrix (NB Fortran is column major! input columns then transpose)
10+
A = transpose(reshape( [4, 3, &
11+
3, 2], [2,2] ))
12+
13+
! Invert matrix
14+
Am1 = .inv.A
15+
16+
print *, ' |',Am1(1,:),'|' ! | -2 3 |
17+
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 |
18+
19+
! Final check
20+
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2)
21+
22+
end program example_inverse_operator
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! Matrix inversion example: subroutine interface
2+
program example_inverse_subroutine
3+
use stdlib_linalg_constants, only: dp
4+
use stdlib_linalg, only: invert,eye
5+
implicit none
6+
7+
real(dp) :: A(2,2), Am1(2,2)
8+
9+
! Input matrix (NB Fortran is column major! input columns then transpose)
10+
A = transpose(reshape( [4, 3, &
11+
3, 2], [2,2] ))
12+
13+
! Invert matrix
14+
call invert(A,Am1)
15+
16+
print *, ' |',Am1(1,:),'|' ! | -2 3 |
17+
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 |
18+
19+
! Final check
20+
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2)
21+
22+
end program example_inverse_subroutine

0 commit comments

Comments
 (0)