@@ -347,25 +347,46 @@ function _gpu_gesvdj!(
347347 )
348348 throw (MethodError (_gpu_gesvdj!, (A, S, U, Vᴴ)))
349349end
350+ function _gpu_gesvd_maybe_transpose! (A:: AbstractMatrix , S:: AbstractVector , U:: AbstractMatrix , Vᴴ:: AbstractMatrix )
351+ m, n = size (A)
352+ m ≥ n && return _gpu_gesvd! (A, S, U, Vᴴ)
353+ # both CUSOLVER and ROCSOLVER require m ≥ n for gesvd (QR_Iteration)
354+ # if this condition is not met, do the SVD via adjoint
355+ minmn = min (m, n)
356+ Aᴴ = min (m, n) > 0 ? adjoint! (similar (A' ), A):: AbstractMatrix : similar (A' )
357+ Uᴴ = similar (U' )
358+ V = similar (Vᴴ' )
359+ if size (U) == (m, m)
360+ _gpu_gesvd! (Aᴴ, view (S, 1 : minmn, 1 ), V, Uᴴ)
361+ else
362+ _gpu_gesvd! (Aᴴ, S, V, Uᴴ)
363+ end
364+ length (U) > 0 && adjoint! (U, Uᴴ)
365+ length (Vᴴ) > 0 && adjoint! (Vᴴ, V)
366+ return U, S, Vᴴ
367+ end
368+
350369# GPU SVD implementation
351- function MatrixAlgebraKit . svd_full! (A:: AbstractMatrix , USVᴴ, alg:: GPU_SVDAlgorithm )
370+ function svd_full! (A:: AbstractMatrix , USVᴴ, alg:: GPU_SVDAlgorithm )
352371 check_input (svd_full!, A, USVᴴ, alg)
353372 U, S, Vᴴ = USVᴴ
354373 fill! (S, zero (eltype (S)))
355374 m, n = size (A)
356375 minmn = min (m, n)
376+ if minmn == 0
377+ one! (U)
378+ zero! (S)
379+ one! (Vᴴ)
380+ return USVᴴ
381+ end
357382 if alg isa GPU_QRIteration
358383 isempty (alg. kwargs) ||
359- throw ( ArgumentError ( " GPU_QRIteration does not accept any keyword arguments" ))
360- _gpu_gesvd ! (A, view (S, 1 : minmn, 1 ), U, Vᴴ)
384+ @warn " GPU_QRIteration does not accept any keyword arguments"
385+ _gpu_gesvd_maybe_transpose ! (A, view (S, 1 : minmn, 1 ), U, Vᴴ)
361386 elseif alg isa GPU_SVDPolar
362387 _gpu_Xgesvdp! (A, view (S, 1 : minmn, 1 ), U, Vᴴ; alg. kwargs... )
363388 elseif alg isa GPU_Jacobi
364389 _gpu_gesvdj! (A, view (S, 1 : minmn, 1 ), U, Vᴴ; alg. kwargs... )
365- # elseif alg isa LAPACK_Bisection
366- # throw(ArgumentError("LAPACK_Bisection is not supported for full SVD"))
367- # elseif alg isa LAPACK_Jacobi
368- # throw(ArgumentError("LAPACK_Bisection is not supported for full SVD"))
369390 else
370391 throw (ArgumentError (" Unsupported SVD algorithm" ))
371392 end
@@ -390,13 +411,13 @@ function svd_trunc!(A::AbstractMatrix, USVᴴ, alg::TruncatedAlgorithm{<:GPU_Ran
390411 return USVᴴtrunc... , ϵ
391412end
392413
393- function MatrixAlgebraKit . svd_compact! (A:: AbstractMatrix , USVᴴ, alg:: GPU_SVDAlgorithm )
414+ function svd_compact! (A:: AbstractMatrix , USVᴴ, alg:: GPU_SVDAlgorithm )
394415 check_input (svd_compact!, A, USVᴴ, alg)
395416 U, S, Vᴴ = USVᴴ
396417 if alg isa GPU_QRIteration
397418 isempty (alg. kwargs) ||
398- throw ( ArgumentError ( " GPU_QRIteration does not accept any keyword arguments" ))
399- _gpu_gesvd ! (A, S. diag, U, Vᴴ)
419+ @warn " GPU_QRIteration does not accept any keyword arguments"
420+ _gpu_gesvd_maybe_transpose ! (A, S. diag, U, Vᴴ)
400421 elseif alg isa GPU_SVDPolar
401422 _gpu_Xgesvdp! (A, S. diag, U, Vᴴ; alg. kwargs... )
402423 elseif alg isa GPU_Jacobi
@@ -416,8 +437,8 @@ function MatrixAlgebraKit.svd_vals!(A::AbstractMatrix, S, alg::GPU_SVDAlgorithm)
416437 U, Vᴴ = similar (A, (0 , 0 )), similar (A, (0 , 0 ))
417438 if alg isa GPU_QRIteration
418439 isempty (alg. kwargs) ||
419- throw ( ArgumentError ( " GPU_QRIteration does not accept any keyword arguments" ))
420- _gpu_gesvd ! (A, S, U, Vᴴ)
440+ @warn " GPU_QRIteration does not accept any keyword arguments"
441+ _gpu_gesvd_maybe_transpose ! (A, S, U, Vᴴ)
421442 elseif alg isa GPU_SVDPolar
422443 _gpu_Xgesvdp! (A, S, U, Vᴴ; alg. kwargs... )
423444 elseif alg isa GPU_Jacobi
0 commit comments