Is it possible to rdiv! by an SVD factorization? As in
using LinearAlgebra
A = ones(3)
B = randn(3, 3)
Blu = lu!(copy(B))
rdiv!(A', Blu) # works
Bsvd = svd!(copy(B))
rdiv!(A', Bsvd) # fails, no such method
In other words, I am asking if there is a technical reason preventing this, or it simply wasn’t added (yet, as of 1.13.3).
So basically you want: X \leftarrow X F^{+} , where F = U \Sigma V^\* . Then you can make use of:
\left( X F^{+} \right)^{\top} = \left( F^{+} \right)^{\top} X^{\top} = \left( F^{\top} \right)^{+} X^{\top}
So this should work:
LinearAlgebra.rdiv!(X::AbstractMatrix, F::SVD) = (ldiv!(F', X'); X)
With your example I get
julia> rdiv!(A', Bsvd)
1×3 adjoint(::Vector{Float64}) with eltype Float64:
1.2252 -2.33595 0.699014
p.s. this works because ldiv!(F::SVD, B::AbstractVecOrMat) does exist:
This is equivalent to a least-squares solution (for ``m \\ge n``) or a minimum-norm solution (for ``m \\le n``).
Similar to the [`pinv`](@ref) function, the solution can be regularized by truncating the SVD,
dropping any singular values less than `max(atol, rtol*σ₁)` where `σ₁` is the largest singular value.
The default relative tolerance is `n*ϵ`, where `n` is the size of the smallest dimension of `M`, and
`ϵ` is the [`eps`](@ref) of the element type of `M`.
!!! compat "Julia 1.13"
The `atol` and `rtol` arguments require Julia 1.13 or later.
"""
function ldiv!(F::SVD{T}, B::AbstractVecOrMat; atol::Number=zero(eltype(F.S)), rtol::Real = (eps(real(float(one(T))))*min(size(F)...))*iszero(atol)) where T
m, n = size(F)
k = _count_svdvals(F.S, atol, rtol)
if k == 0
B[1:n, :] .= 0
else
temp = view(F.U, :, 1:k)' * _cut_B(B, 1:m)
ldiv!(Diagonal(view(F.S, 1:k)), temp)
mul!(view(B, 1:n, :), view(F.Vt, 1:k, :)', temp)
end
return B
The problem is that you can only solve and multiply in-place when one of the matrix has appropriate structure and this structure is preserved by the Julia representation. Triangular matrices allow for multiplication and solving in-place which is why the LU example works. You can also multiply orthogonal matrices in-place if they are stored as e.g. reflectors or rotations, but the U and V matrices in the SVD struct are stored as regular dense matrices. Hence, you’d need extra workspace for the multiplications. A single temporary would suffice, though.