@@ -308,35 +308,47 @@ check_input(::typeof(svd_trunc!), A::AbstractMatrix, USVᴴ, alg::SketchedAlgori
308308
309309function svd_trunc_no_error! (A:: AbstractMatrix , (U, S, Vᴴ), alg:: SketchedAlgorithm )
310310 check_input (svd_trunc_no_error!, A, (U, S, Vᴴ), alg)
311+ return gesvdr! (alg. driver, A, S, U, Vᴴ; alg. sketch, alg. alg, alg. trunc)
312+ end
313+
314+ function svd_trunc! (A:: AbstractMatrix , USVᴴ, alg:: SketchedAlgorithm )
315+ U, S, Vᴴ = svd_trunc_no_error! (A, USVᴴ, alg)
316+ Na = norm (A)
317+ Ns = norm (S)
318+ return U, S, Vᴴ, sqrt (max (zero (Na), (Na + Ns) * (Na - Ns)))
319+ end
320+
321+ # gesvdr! drivers
322+ # ---------------
323+ default_driver (:: Type{<:SketchedAlgorithm} , :: Type{<:AbstractArray} ) = Native ()
324+
325+ gesvdr! (:: DefaultDriver , A, S, U, Vᴴ; kwargs... ) =
326+ gesvdr! (default_driver (SketchedAlgorithm, A), A, S, U, Vᴴ; kwargs... )
327+
328+ function gesvdr! (
329+ :: Native , A:: AbstractMatrix , S, U, Vᴴ;
330+ sketch:: SketchingStrategy , alg:: AbstractAlgorithm ,
331+ trunc:: TruncationStrategy
332+ )
311333 m, n = size (A)
312334 if m ≥ n
313- Q, B = left_sketch! (A, (U, Vᴴ), alg . sketch)
335+ Q, B = left_sketch! (A, (U, Vᴴ), sketch)
314336 k = size (B, 1 )
315337 U′ = similar (B, (k, k))
316338 Vᴴ′ = similar (B)
317- USVᴴ_inner = svd_compact! (B, (U′, S, Vᴴ′), alg. alg)
318- (Uout′, Sout, Vᴴout), _ = truncate (svd_trunc!, USVᴴ_inner, alg. trunc)
339+ Uout′, Sout, Vᴴout, _ = svd_trunc! (B, (U′, S, Vᴴ′), TruncatedAlgorithm (alg, trunc))
319340 Uout = Q * Uout′
320341 else
321- B, Pᴴ = right_sketch! (A, (U, Vᴴ), alg . sketch)
342+ B, Pᴴ = right_sketch! (A, (U, Vᴴ), sketch)
322343 k = size (B, 2 )
323344 U′ = similar (B)
324345 Vᴴ′ = similar (B, (k, k))
325- USVᴴ_inner = svd_compact! (B, (U′, S, Vᴴ′), alg. alg)
326- (Uout, Sout, Vᴴout′), _ = truncate (svd_trunc!, USVᴴ_inner, alg. trunc)
346+ Uout, Sout, Vᴴout′, _ = svd_trunc! (B, (U′, S, Vᴴ′), TruncatedAlgorithm (alg, trunc))
327347 Vᴴout = Vᴴout′ * Pᴴ
328348 end
329- get (alg. alg. kwargs, :fixgauge , true ) && gaugefix! (svd_trunc!, Uout, Vᴴout)
330349 return Uout, Sout, Vᴴout
331350end
332351
333- function svd_trunc! (A:: AbstractMatrix , USVᴴ, alg:: SketchedAlgorithm )
334- U, S, Vᴴ = svd_trunc_no_error! (A, USVᴴ, alg)
335- Na = norm (A)
336- Ns = norm (S)
337- return U, S, Vᴴ, sqrt (max (zero (Na), (Na + Ns) * (Na - Ns)))
338- end
339-
340352# Deprecations
341353# ------------
342354for algtype in (:SafeDivideAndConquer , :DivideAndConquer , :QRIteration , :Jacobi , :Bisection )
@@ -380,6 +392,40 @@ for (algtype, newtype, drivertype) in (
380392 end
381393end
382394
395+ # CUSOLVER_Randomized → SketchedAlgorithm with driver = CUSOLVER()
396+ function _cusolver_randomized_to_sketched (alg:: CUSOLVER_Randomized )
397+ k = alg. kwargs. k
398+ p = alg. kwargs. p
399+ niters = alg. kwargs. niters
400+ return SketchedAlgorithm (
401+ QRIteration (),
402+ GaussianSketching (k + p; numiter = niters + 1 ),
403+ truncrank (k);
404+ driver = CUSOLVER (),
405+ )
406+ end
407+
408+ for f! in (:svd_trunc! , :svd_trunc_no_error! )
409+ @eval Base. @deprecate (
410+ $ f! (A:: AbstractMatrix , USVᴴ, alg:: CUSOLVER_Randomized ),
411+ $ f! (A, USVᴴ, _cusolver_randomized_to_sketched (alg))
412+ )
413+ end
414+
415+ @inline function select_algorithm (:: typeof (svd_trunc!), A, alg:: CUSOLVER_Randomized ; kwargs... )
416+ Base. depwarn (
417+ " `CUSOLVER_Randomized` is deprecated; use \
418+ `SketchedAlgorithm(QRIteration(), GaussianSketching(k+p; numiter=niters+1), truncrank(k); driver=CUSOLVER())` instead." ,
419+ :select_algorithm ,
420+ )
421+ isempty (kwargs) ||
422+ throw (ArgumentError (" Additional keyword arguments are not allowed when algorithm parameters are specified." ))
423+ return _cusolver_randomized_to_sketched (alg)
424+ end
425+ @inline function select_algorithm (:: typeof (svd_trunc_no_error!), A, alg:: CUSOLVER_Randomized ; kwargs... )
426+ return select_algorithm (svd_trunc!, A, alg; kwargs... )
427+ end
428+
383429# GLA_QRIteration SVD deprecations (eigh methods remain in the GLA extension)
384430Base. @deprecate (
385431 svd_compact! (A:: AbstractMatrix , USVᴴ, alg:: GLA_QRIteration ),
0 commit comments