Skip to content

Commit bb47ba5

Browse files
committed
specs: svd, svdvals
1 parent 32784cd commit bb47ba5

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,92 @@ Exceptions trigger an `error stop`.
797797
```fortran
798798
{!example/linalg/example_determinant2.f90!}
799799
```
800+
801+
## `svd` - Compute the singular value decomposition of a 2d matrix.
802+
803+
### Status
804+
805+
Experimental
806+
807+
### Description
808+
809+
This subroutine computes the singular value decomposition of a `real` or `complex` 2d matrix \( A = U \cdot S \cdot \V^T \).
810+
The solver is based on LAPACK's `*GESDD` backends.
811+
812+
Result vector `s` returns the array of singular values on the diagonal of \( S \).
813+
If requested, `u` contains the left singular vectors, as columns of \( U \).
814+
If requested, `vt` contains the right singular vectors, as rows of \( V^T \).
815+
816+
### Syntax
817+
818+
`call ` [[stdlib_linalg(module):svd(interface)]] `(a, s, [, u, vt, overwrite_a, full_matrices, err])`
819+
820+
### Arguments
821+
822+
`a`: Shall be a rank-2 `real` or `complex` array containing the coefficient matrix of size `[m,n]`. It is an `intent(inout)` argument, but returns unchanged unless `overwrite_a=.true.`.
823+
824+
`s`: Shall be a rank-1 `real` array, returning the list of `k = min(m,n)` singular values. It is an `intent(inout)` argument.
825+
826+
`u` (optional): Shall be a rank-2 array of same kind as `a`, returning the left singular vectors of `a` as columns. Its size should be `[m,m]` unless `full_matrices=.false.`, in which case, it can be `[m,min(m,n)]`. It is an `intent(inout)` argument.
827+
828+
`vt` (optional): Shall be a rank-2 array of same kind as `a`, returning the right singular vectors of `a` as rows. Its size should be `[n,n]` unless `full_matrices=.false.`, in which case, it can be `[min(m,n),n]`. It is an `intent(inout)` argument.
829+
830+
`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. By default, `overwrite_a=.false.`. This is an `intent(in)` argument.
831+
832+
`full_matrices` (optional): Shall be an input `logical` flag. If `.true.` (default), matrices `u` and `vt` shall be full-sized. Otherwise, their secondary dimension can be resized to `min(m,n)`. See `u`, `v` for details.
833+
834+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
835+
836+
### Return values
837+
838+
Returns an array `s` that contains the list of singular values of matrix `a`.
839+
If requested, returns a rank-2 array `u` that contains the left singular values of `a` along its columns.
840+
If requested, returns a rank-2 array `vt` that contains the right singular values of `a` along its rows.
841+
842+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
843+
Raises `LINALG_VALUE_ERROR` if the matrix or any of the output arrays invalid/incompatible sizes.
844+
Exceptions trigger an `error stop`, unless argument `err` is present.
845+
846+
### Example
847+
848+
```fortran
849+
{!example/linalg/example_svd1.f90!}
850+
```
851+
852+
## `svdvals` - Compute the singular values of a 2d matrix.
853+
854+
### Status
855+
856+
Experimental
857+
858+
### Description
859+
860+
This subroutine computes the singular values of a `real` or `complex` 2d matrix from its singular
861+
value decomposition \( A = U \cdot S \cdot \V^T \). The solver is based on LAPACK's `*GESDD` backends.
862+
863+
Result vector `s` returns the array of singular values on the diagonal of \( S \).
864+
865+
### Syntax
866+
867+
`s = ` [[stdlib_linalg(module):svdvals(interface)]] `(a [, err])`
868+
869+
### Arguments
870+
871+
`a`: Shall be a rank-2 `real` or `complex` array containing the coefficient matrix of size `[m,n]`. It is an `intent(in)` argument.
872+
873+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
874+
875+
### Return values
876+
877+
Returns an array `s` that contains the list of singular values of matrix `a`.
878+
879+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
880+
Raises `LINALG_VALUE_ERROR` if the matrix or any of the output arrays invalid/incompatible sizes.
881+
Exceptions trigger an `error stop`, unless argument `err` is present.
882+
883+
### Example
884+
885+
```fortran
886+
{!example/linalg/example_svd2.f90!}
887+
```
888+

src/stdlib_linalg.fypp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ module stdlib_linalg
463463
!! version: experimental
464464
!!
465465
!! Computes the singular value decomposition of a `real` or `complex` 2d matrix.
466+
!! ([Specification](../page/specs/stdlib_linalg.html#svd-compute-the-singular-value-decomposition-of-a-2d-matrix))
466467
!!
467468
!!### Summary
468469
!! Interface for computing the singular value decomposition of a `real` or `complex` 2d matrix.
@@ -534,6 +535,7 @@ module stdlib_linalg
534535
!! version: experimental
535536
!!
536537
!! Computes the singular values of a `real` or `complex` 2d matrix.
538+
!! ([Specification](../page/specs/stdlib_linalg.html#svdvals-compute-the-singular-values-of-a-2d-matrix))
537539
!!
538540
!!### Summary
539541
!!

0 commit comments

Comments
 (0)