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
**Description**: Singular values $S$ from $A = U S V^t$.
332
-
**Usage**: `s = svdvals(A)` where `s` is a real array with the same precision as `A`.
322
+
### Description
323
+
324
+
This subroutine computes the Singular Value Decomposition (SVD) of a matrix \f$ A \f$:
325
+
326
+
\f[
327
+
A = U \cdot S \cdot V^T
328
+
\f]
329
+
330
+
where:
331
+
- \f$ A \f$ is the input matrix of size \f$ [m,n] \f$.
332
+
- \f$ U \f$ is an orthogonal matrix of size \f$ [m,m] \f$ (or \f$ [m,k] \f$ for the reduced problem), containing the left singular vectors of \f$ A \f$.
333
+
- \f$ S \f$ is a diagonal matrix containing the singular values of size \f$ [k,k] \f$ with \f$ k = \min(m,n) \f$.
334
+
- \f$ V^T \f$ is an orthogonal matrix of size \f$ [n,n] \f$ (or \f$ [k,n] \f$ for the reduced problem), containing the right singular vectors of \f$ A^T \f$.
335
+
336
+
The singular values are returned in the array \f$ S \f$, and optionally, the matrices \f$ U \f$ and \f$ V^T \f$ are computed and returned.
337
+
338
+
### Arguments
339
+
340
+
-`a`: A `real` matrix of size \f$ [m,n] \f$ representing the input matrix \f$ A \f$. If `overwrite_a = .true.`, this matrix may be modified during computation. This is an `inout` argument.
341
+
-`s`: A `real` array of size \f$ k = \min(m,n) \f$, containing the singular values of \f$ A \f$. This is an output argument.
342
+
-`u`: An optional `real` matrix of the same type and kind as `a`, representing the left singular vectors of \f$ A \f$. This has shape \f$ [m,m] \f$ for the full problem or \f$ [m,k] \f$ for the reduced problem. This is an output argument.
343
+
-`vt`: An optional `real` matrix of the same type and kind as `a`, representing the right singular vectors of \f$ A^T \f$. This has shape \f$ [n,n] \f$ for the full problem or \f$ [k,n] \f$ for the reduced problem. This is an output argument.
344
+
-`overwrite_a`: (Optional, default = `.false.`) A logical flag indicating whether the input matrix `a` may be overwritten during computation. If `.true.`, `a` is overwritten to avoid additional memory allocation.
345
+
-`full_matrices`: (Optional, default = `.true.`) A logical flag that determines whether to compute full-sized matrices \f$ U \f$ and \f$ V^T \f$ (shape \f$ [m,m] \f$ and \f$ [n,n] \f$). If `.false.`, computes reduced matrices of shape \f$ [m,k] \f$ and \f$ [k,n] \f$.
346
+
-`err`: (Optional) A [type(la_state)](@ref la_state_type::la_state) variable to capture the error state. If not provided, the function will stop execution on error.
347
+
348
+
### Return value
349
+
350
+
The SVD of matrix \f$ A \f$ is returned in the corresponding output arguments, with the singular values in `s`, and optionally, the matrices \f$ U \f$ and \f$ V^T \f$.
351
+
352
+
### Errors
353
+
354
+
- Raises [LINALG_VALUE_ERROR](@ref la_state_type::linalg_value_error) if the sizes of the matrices are incompatible with the full/reduced problem.
355
+
- Raises [LINALG_ERROR](@ref la_state_type::linalg_error) if there is insufficient storage space.
356
+
- If `err` is not provided, exceptions will trigger an `error stop`.
357
+
358
+
### Notes
359
+
360
+
- This subroutine computes the Singular Value Decomposition using LAPACK's [GESDD](@ref la_lapack::gesdd) algorithm.
361
+
- If `overwrite_a` is enabled, the input matrix `a` may be overwritten during computation.
This function computes the singular values of a `real` or `complex` matrix \f$ A \f$ and returns them in a vector \f$ s \f$, where \f$ s \f$ is an array of size \f$ k = \min(m, n) \f$.
372
+
Singular values are non-negative values that provide important insights into the properties of the matrix, such as its rank and conditioning.
373
+
374
+
This function does not compute the full Singular Value Decomposition ([SVD](@ref la_svd::svd)); instead, it directly calculates and returns only the singular values of matrix \f$ A \f$.
375
+
376
+
The Singular Value Decomposition of a matrix \f$ A \f$ is expressed as:
377
+
378
+
\f[
379
+
A = U \cdot S \cdot V^T
380
+
\f]
381
+
382
+
where:
383
+
- \f$ A \f$ is the input matrix of size \f$ [m,n] \f$,
384
+
- \f$ U \f$ and \f$ V \f$ are orthogonal matrices,
385
+
- \f$ S \f$ is a diagonal matrix with the singular values of \f$ A \f$.
386
+
387
+
### Arguments
388
+
389
+
-`a`: A `real` or `complex` matrix of size \f$ [m,n] \f$, representing the input matrix whose singular values are to be computed.
390
+
-`err` (optional): A [type(la_state)](@ref la_state_type::la_state) variable that returns the error state. If not provided, the function will stop execution on error.
391
+
392
+
### Return value
393
+
394
+
-`s`: A `real` array containing the singular values of the matrix \f$ A \f$, with the same type and kind as the input matrix. The size of the array is \f$ k = \min(m, n) \f$.
395
+
396
+
### Errors
397
+
398
+
- Raises [LINALG_VALUE_ERROR](@ref la_state_type::linalg_value_error) if the input matrix has invalid dimensions or if the SVD computation fails.
399
+
- If `err` is not provided, exceptions will trigger an `error stop`.
400
+
401
+
### Notes
402
+
403
+
- This function only computes the singular values and does not compute the full SVD (i.e., matrices \f$ U \f$ and \f$ V \f$ are not computed).
404
+
- The singular values are returned as a vector, sorted in decreasing order.
405
+
- The function uses LAPACK's [GESDD](@ref la_lapack::gesdd) routine for singular value computation.
333
406
334
407
## [diag](@ref la_eye::diag) - Diagonal matrix.
335
408
@@ -548,7 +621,7 @@ The Schur decomposition matrices \f$ T \f$ and optionally \f$ Z \f$ are returned
548
621
549
622
### Notes
550
623
551
-
- This subroutine computes the Schur decomposition using LAPACK's Schur decomposition routines ([GEES](@ref la_lapack:gees)).
624
+
- This subroutine computes the Schur decomposition using LAPACK's Schur decomposition routines ([GEES](@ref la_lapack::gees)).
552
625
- Sorting options for eigenvalues can be requested, utilizing LAPACK's eigenvalue sorting mechanism.
553
626
- If `overwrite_a` is enabled, the input matrix `a` will be modified during computation.
Copy file name to clipboardExpand all lines: fypp/src/la_svd.fypp
+35-4Lines changed: 35 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
#:include "common.fypp"
2
+
!> Singular Value Decomposition
2
3
module la_svd
3
4
use la_constants
4
5
use la_blas
@@ -8,13 +9,43 @@ module la_svd
8
9
implicit none(type,external)
9
10
private
10
11
11
-
!> Singular value decomposition
12
+
!> @brief Compute the Singular Value Decomposition (SVD) of a matrix.
13
+
!!
14
+
!! This subroutine computes the Singular Value Decomposition (SVD) of a matrix \f$ A \f$:
15
+
!!
16
+
!! \f$ A = U \cdot S \cdot V^T \f$
17
+
!!
18
+
!! where \f$ A \f$ is a matrix of size \f$ [m,n] \f$, \f$ U \f$ is an orthogonal matrix of size \f$ [m,m] \f$, \f$ S \f$ is a diagonal matrix containing the singular values, and \f$ V^T \f$ is an orthogonal matrix of size \f$ [n,n] \f$.
19
+
!! The subroutine computes the singular values and optionally the matrices \f$ U \f$ and \f$ V^T \f$.
20
+
!!
21
+
!! @param[in,out] a The input matrix \f$ A \f$ of size \f$ [m,n] \f$. If `overwrite_a` is true, the contents of `a` may be modified during computation.
22
+
!! @param[out] s The array of singular values of size \f$ k = min(m,n) \f$.
23
+
!! @param[out] u (Optional) The left singular vectors of matrix \f$ A \f$, with shape \f$ [m,m] \f$ for the full problem or \f$ [m,k] \f$ for the reduced problem.
24
+
!! @param[out] vt (Optional) The right singular vectors of matrix \f$ A^T \f$, with shape \f$ [k,n] \f$ for the reduced problem or \f$ [n,n] \f$ for the full problem.
25
+
!! @param[in] overwrite_a (Optional) A logical flag that determines whether matrix `a` may be overwritten. Default is false.
26
+
!! @param[in] full_matrices (Optional) If true, computes the full-sized matrices \f$ U \f$ and \f$ V^T \f$. If false, computes the reduced matrices.
27
+
!! @param[out] err (Optional) A state return flag. If an error occurs and `err` is not provided, the function will stop execution.
28
+
!!
29
+
!! @note This subroutine performs the SVD computation using the LAPACK [gesdd](@ref la_lapack::gesdd) backend and can be used for both full and reduced decompositions.
30
+
!!
31
+
!! @warning If `overwrite_a` is enabled, the original contents of `a` may be lost during computation.
32
+
!!
12
33
public :: svd
13
-
!> Singular values
34
+
35
+
36
+
!> @brief Compute the singular values of a matrix.
37
+
!!
38
+
!! This function returns the singular values of the input matrix \f$ A \f$.
39
+
!! The singular values are stored in a vector \f$ s \f$, which is an array of size \f$ k = min(m,n) \f$.
40
+
!!
41
+
!! @param[in] a The input matrix \f$ A \f$ of size \f$ [m,n] \f$.
42
+
!! @param[out] err (Optional) A state return flag. If an error occurs and `err` is not provided, the function will stop execution.
43
+
!! @return The singular values of matrix \f$ A \f$ are returned in the `real` array \f$ s \f$, with the same kind as the input matrix.
44
+
!!
45
+
!! @note This function returns only the singular values and does not compute the full SVD.
Copy file name to clipboardExpand all lines: src/la_svd.f90
+35-4Lines changed: 35 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
!> Singular Value Decomposition
1
2
module la_svd
2
3
use la_constants
3
4
use la_blas
@@ -7,13 +8,43 @@ module la_svd
7
8
implicit none(type,external)
8
9
private
9
10
10
-
!> Singular value decomposition
11
+
!> @brief Compute the Singular Value Decomposition (SVD) of a matrix.
12
+
!!
13
+
!! This subroutine computes the Singular Value Decomposition (SVD) of a matrix \f$ A \f$:
14
+
!!
15
+
!! \f$ A = U \cdot S \cdot V^T \f$
16
+
!!
17
+
!! where \f$ A \f$ is a matrix of size \f$ [m,n] \f$, \f$ U \f$ is an orthogonal matrix of size \f$ [m,m] \f$, \f$ S \f$ is a diagonal matrix containing the singular values, and \f$ V^T \f$ is an orthogonal matrix of size \f$ [n,n] \f$.
18
+
!! The subroutine computes the singular values and optionally the matrices \f$ U \f$ and \f$ V^T \f$.
19
+
!!
20
+
!! @param[in,out] a The input matrix \f$ A \f$ of size \f$ [m,n] \f$. If `overwrite_a` is true, the contents of `a` may be modified during computation.
21
+
!! @param[out] s The array of singular values of size \f$ k = min(m,n) \f$.
22
+
!! @param[out] u (Optional) The left singular vectors of matrix \f$ A \f$, with shape \f$ [m,m] \f$ for the full problem or \f$ [m,k] \f$ for the reduced problem.
23
+
!! @param[out] vt (Optional) The right singular vectors of matrix \f$ A^T \f$, with shape \f$ [k,n] \f$ for the reduced problem or \f$ [n,n] \f$ for the full problem.
24
+
!! @param[in] overwrite_a (Optional) A logical flag that determines whether matrix `a` may be overwritten. Default is false.
25
+
!! @param[in] full_matrices (Optional) If true, computes the full-sized matrices \f$ U \f$ and \f$ V^T \f$. If false, computes the reduced matrices.
26
+
!! @param[out] err (Optional) A state return flag. If an error occurs and `err` is not provided, the function will stop execution.
27
+
!!
28
+
!! @note This subroutine performs the SVD computation using the LAPACK [gesdd](@ref la_lapack::gesdd) backend and can be used for both full and reduced decompositions.
29
+
!!
30
+
!! @warning If `overwrite_a` is enabled, the original contents of `a` may be lost during computation.
31
+
!!
11
32
public:: svd
12
-
!> Singular values
33
+
34
+
35
+
!> @brief Compute the singular values of a matrix.
36
+
!!
37
+
!! This function returns the singular values of the input matrix \f$ A \f$.
38
+
!! The singular values are stored in a vector \f$ s \f$, which is an array of size \f$ k = min(m,n) \f$.
39
+
!!
40
+
!! @param[in] a The input matrix \f$ A \f$ of size \f$ [m,n] \f$.
41
+
!! @param[out] err (Optional) A state return flag. If an error occurs and `err` is not provided, the function will stop execution.
42
+
!! @return The singular values of matrix \f$ A \f$ are returned in the `real` array \f$ s \f$, with the same kind as the input matrix.
43
+
!!
44
+
!! @note This function returns only the singular values and does not compute the full SVD.
0 commit comments