@@ -245,6 +245,26 @@ _gpu_gesvd!(A::AbstractMatrix, S::AbstractVector, U::AbstractMatrix, Vᴴ::Abstr
245245_gpu_Xgesvdp! (A:: AbstractMatrix , S:: AbstractVector , U:: AbstractMatrix , Vᴴ:: AbstractMatrix ; kwargs... ) = throw (MethodError (_gpu_Xgesvdp!, (A, S, U, Vᴴ)))
246246_gpu_Xgesvdr! (A:: AbstractMatrix , S:: AbstractVector , U:: AbstractMatrix , Vᴴ:: AbstractMatrix ; kwargs... ) = throw (MethodError (_gpu_Xgesvdr!, (A, S, U, Vᴴ)))
247247_gpu_gesvdj! (A:: AbstractMatrix , S:: AbstractVector , U:: AbstractMatrix , Vᴴ:: AbstractMatrix ; kwargs... ) = throw (MethodError (_gpu_gesvdj!, (A, S, U, Vᴴ)))
248+ function _gpu_gesvd_maybe_transpose! (A:: AbstractMatrix , S:: AbstractVector , U:: AbstractMatrix , Vᴴ:: AbstractMatrix )
249+ m, n = size (A)
250+ m ≥ n && return _gpu_gesvd! (A, S, U, Vᴴ)
251+ # both CUSOLVER and ROCSOLVER require m ≥ n for gesvd (QR_Iteration)
252+ # if this condition is not met, do the SVD via adjoint
253+ minmn = min (m, n)
254+ At = min (m, n) > 0 ? adjoint! (similar (A' ), A):: AbstractMatrix : similar (A' )
255+ Ut = similar (U' )
256+ Vᴴt = similar (Vᴴ' )
257+ if size (U) == (m, m)
258+ _gpu_gesvd! (At, view (S, 1 : minmn, 1 ), Vᴴt, Ut)
259+ else
260+ _gpu_gesvd! (At, S, Vᴴt, Ut)
261+ end
262+ length (U) > 0 ? adjoint! (U, Ut) : one! (U)
263+ length (Vᴴ) > 0 ? adjoint! (Vᴴ, Vᴴt) : one! (Vᴴ)
264+ conj! (S)
265+ return U, S, Vᴴ
266+ end
267+
248268# GPU SVD implementation
249269function svd_full! (A:: AbstractMatrix , USVᴴ, alg:: GPU_SVDAlgorithm )
250270 check_input (svd_full!, A, USVᴴ, alg)
@@ -260,8 +280,8 @@ function svd_full!(A::AbstractMatrix, USVᴴ, alg::GPU_SVDAlgorithm)
260280 end
261281 if alg isa GPU_QRIteration
262282 isempty (alg. kwargs) ||
263- throw ( ArgumentError ( " GPU_QRIteration does not accept any keyword arguments" ))
264- _gpu_gesvd ! (A, view (S, 1 : minmn, 1 ), U, Vᴴ)
283+ @warn " GPU_QRIteration does not accept any keyword arguments"
284+ _gpu_gesvd_maybe_transpose ! (A, view (S, 1 : minmn, 1 ), U, Vᴴ)
265285 elseif alg isa GPU_SVDPolar
266286 _gpu_Xgesvdp! (A, view (S, 1 : minmn, 1 ), U, Vᴴ; alg. kwargs... )
267287 elseif alg isa GPU_Jacobi
@@ -295,7 +315,7 @@ function svd_compact!(A::AbstractMatrix, USVᴴ, alg::GPU_SVDAlgorithm)
295315 if alg isa GPU_QRIteration
296316 isempty (alg. kwargs) ||
297317 @warn " GPU_QRIteration does not accept any keyword arguments"
298- _gpu_gesvd ! (A, S. diag, U, Vᴴ)
318+ _gpu_gesvd_maybe_transpose ! (A, S. diag, U, Vᴴ)
299319 elseif alg isa GPU_SVDPolar
300320 _gpu_Xgesvdp! (A, S. diag, U, Vᴴ; alg. kwargs... )
301321 elseif alg isa GPU_Jacobi
@@ -315,8 +335,8 @@ function svd_vals!(A::AbstractMatrix, S, alg::GPU_SVDAlgorithm)
315335 U, Vᴴ = similar (A, (0 , 0 )), similar (A, (0 , 0 ))
316336 if alg isa GPU_QRIteration
317337 isempty (alg. kwargs) ||
318- throw ( ArgumentError ( " GPU_QRIteration does not accept any keyword arguments" ))
319- _gpu_gesvd ! (A, S, U, Vᴴ)
338+ @warn " GPU_QRIteration does not accept any keyword arguments"
339+ _gpu_gesvd_maybe_transpose ! (A, S, U, Vᴴ)
320340 elseif alg isa GPU_SVDPolar
321341 _gpu_Xgesvdp! (A, S, U, Vᴴ; alg. kwargs... )
322342 elseif alg isa GPU_Jacobi
0 commit comments