You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_linalg.md
+92
Original file line number
Diff line number
Diff line change
@@ -898,3 +898,95 @@ Exceptions trigger an `error stop`.
898
898
```fortran
899
899
{!example/linalg/example_determinant2.f90!}
900
900
```
901
+
902
+
## `svd` - Compute the singular value decomposition of a rank-2 array (matrix).
903
+
904
+
### Status
905
+
906
+
Experimental
907
+
908
+
### Description
909
+
910
+
This subroutine computes the singular value decomposition of a `real` or `complex` rank-2 array (matrix) \( A = U \cdot S \cdot \V^T \).
911
+
The solver is based on LAPACK's `*GESDD` backends.
912
+
913
+
Result vector `s` returns the array of singular values on the diagonal of \( S \).
914
+
If requested, `u` contains the left singular vectors, as columns of \( U \).
915
+
If requested, `vt` contains the right singular vectors, as rows of \( V^T \).
916
+
917
+
### Syntax
918
+
919
+
`call `[[stdlib_linalg(module):svd(interface)]]`(a, s, [, u, vt, overwrite_a, full_matrices, err])`
920
+
921
+
### Class
922
+
Subroutine
923
+
924
+
### Arguments
925
+
926
+
`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.`.
927
+
928
+
`s`: Shall be a rank-1 `real` array, returning the list of `k = min(m,n)` singular values. It is an `intent(out)` argument.
929
+
930
+
`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(out)` argument.
931
+
932
+
`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(out)` argument.
933
+
934
+
`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.`. It is an `intent(in)` argument.
935
+
936
+
`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.
937
+
938
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
939
+
940
+
### Return values
941
+
942
+
Returns an array `s` that contains the list of singular values of matrix `a`.
943
+
If requested, returns a rank-2 array `u` that contains the left singular vectors of `a` along its columns.
944
+
If requested, returns a rank-2 array `vt` that contains the right singular vectors of `a` along its rows.
945
+
946
+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
947
+
Raises `LINALG_VALUE_ERROR` if the matrix or any of the output arrays invalid/incompatible sizes.
948
+
Exceptions trigger an `error stop`, unless argument `err` is present.
949
+
950
+
### Example
951
+
952
+
```fortran
953
+
{!example/linalg/example_svd.f90!}
954
+
```
955
+
956
+
## `svdvals` - Compute the singular values of a rank-2 array (matrix).
957
+
958
+
### Status
959
+
960
+
Experimental
961
+
962
+
### Description
963
+
964
+
This subroutine computes the singular values of a `real` or `complex` rank-2 array (matrix) from its singular
965
+
value decomposition \( A = U \cdot S \cdot \V^T \). The solver is based on LAPACK's `*GESDD` backends.
966
+
967
+
Result vector `s` returns the array of singular values on the diagonal of \( S \).
!! Compute singular value decomposition of a matrix \( A = U \cdot S \cdot \V^T \)
593
+
!!
594
+
!!### Description
595
+
!!
596
+
!! This function computes the singular value decomposition of a `real` or `complex` matrix \( A \),
597
+
!! and returns the array of singular values, and optionally the left matrix \( U \) containing the
598
+
!! left unitary singular vectors, and the right matrix \( V^T \), containing the right unitary
599
+
!! singular vectors.
600
+
!!
601
+
!! param: a Input matrix of size [m,n].
602
+
!! param: s Output `real` array of size [min(m,n)] returning a list of singular values.
603
+
!! param: u [optional] Output left singular matrix of size [m,m] or [m,min(m,n)] (.not.full_matrices). Contains singular vectors as columns.
604
+
!! param: vt [optional] Output right singular matrix of size [n,n] or [min(m,n),n] (.not.full_matrices). Contains singular vectors as rows.
605
+
!! param: overwrite_a [optional] Flag indicating if the input matrix can be overwritten.
606
+
!! param: full_matrices [optional] If `.true.` (default), matrices \( U \) and \( V^T \) have size [m,m], [n,n]. Otherwise, they are [m,k], [k,n] with `k=min(m,n)`.
607
+
!! param: err [optional] State return flag.
608
+
!!
609
+
!> Input matrix A[m,n]
610
+
${rt}$, intent(inout), target :: a(:,:)
611
+
!> Array of singular values
612
+
real(${rk}$), intent(out) :: s(:)
613
+
!> The columns of U contain the left singular vectors
614
+
${rt}$, optional, intent(out), target :: u(:,:)
615
+
!> The rows of V^T contain the right singular vectors
616
+
${rt}$, optional, intent(out), target :: vt(:,:)
617
+
!> [optional] Can A data be overwritten and destroyed?
618
+
logical(lk), optional, intent(in) :: overwrite_a
619
+
!> [optional] full matrices have shape(u)==[m,m], shape(vh)==[n,n] (default); otherwise
620
+
!> they are shape(u)==[m,k] and shape(vh)==[k,n] with k=min(m,n)
0 commit comments