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: src/svd.jl
+40-2Lines changed: 40 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -425,7 +425,31 @@ function rmul!(A::AbstractMatrix, Q::LinearAlgebra.LQPackedQ)
425
425
end
426
426
427
427
# Overload LinearAlgebra methods
428
+
428
429
LinearAlgebra.svdvals!(B::Bidiagonal{T}; tol =eps(T), debug =false) where T<:Real=_svdvals!(B, tol = tol, debug = debug)
430
+
431
+
"""
432
+
svdvals!(A [, tol, debug])
433
+
434
+
Generic computation of singular values.
435
+
```jldoctest
436
+
julia> using LinearAlgebra, GenericLinearAlgebra, Quaternions
437
+
438
+
julia> n = 20;
439
+
440
+
julia> H = [big(1)/(i + j - 1) for i in 1:n, j in 1:n]; # The Hilbert matrix
441
+
442
+
julia> Float64(svdvals(H)[end]/svdvals(Float64.(H))[end] - 1) # The relative error of the LAPACK based solution in 64 bit floating point.
443
+
-0.9999999999447275
444
+
445
+
julia> A = qr([Quaternion(randn(4)...) for i in 1:3, j in 1:3]).Q *
446
+
Diagonal([3, 2, 1]) *
447
+
qr([Quaternion(randn(4)...) for i in 1:3, j in 1:3]).Q'; # A quaternion matrix with the singular value 1, 2, and 3.
448
+
449
+
julia> svdvals(A) ≈ [3, 2, 1]
450
+
true
451
+
```
452
+
"""
429
453
function LinearAlgebra.svdvals!(A::StridedMatrix; tol =eps(real(eltype(A))), debug =false)
430
454
B =bidiagonalize!(A).bidiagonal
431
455
# It doesn't matter that we transpose the bidiagonal matrix when we are only interested in the values
@@ -436,9 +460,23 @@ end
436
460
LinearAlgebra.svd!(B::Bidiagonal{T}; tol =eps(T), full =false, debug =false) where T<:Real=_svd!(B, tol = tol, debug = debug)
437
461
438
462
"""
439
-
svd!
463
+
svd!(A[, tol, full, debug])::SVD
464
+
465
+
A generic singular value decomposition (SVD). The implementation only uses Julia functions so the SVD can be computed for any element type provided that the necessary arithmetic operations are supported by the element type.
466
+
467
+
- `tol`: The relative tolerance for determining convergence. The default value is `eltype(T)` where `T` is the element type of the input matrix bidiagonal (i.e. after converting the matrix to bidiagonal form).
468
+
469
+
- `full`: Sepcifies if all the left and right singular vectors be returned or if only the vectors us to the number of rows and columns of the input matrix `A` should be returned (the default).
470
+
471
+
- `debug`: A Boolean flag to activate debug information during the executions of the algorithm. The default is false.
472
+
473
+
# Algorithm
474
+
...tomorrow
475
+
476
+
# Example
440
477
441
-
A generic SVD implementation.
478
+
```jldoctest
479
+
```
442
480
"""
443
481
function LinearAlgebra.svd!(A::StridedMatrix{T}; tol =eps(real(eltype(A))), full =false, debug =false) where T
0 commit comments