@@ -20,13 +20,13 @@ MatrixAlgebraKit.default_driver(::Type{TA}) where {TA <: StridedROCArray{<:BlasF
2020MatrixAlgebraKit. default_driver (:: Type{TA} ) where {TA <: AbstractVector{<:StridedROCMatrix{<:BlasFloat}} } = ROCSOLVER ()
2121
2222function MatrixAlgebraKit. default_svd_algorithm (:: Type{T} ; kwargs... ) where {T <: StridedROCMatrix{<:BlasFloat} }
23- return QRIteration (; kwargs... )
23+ return Bisection (; kwargs... )
2424end
2525function MatrixAlgebraKit. default_svd_algorithm (:: Type{T} ; kwargs... ) where {T <: StridedROCArray{<:BlasFloat, 3} }
26- return QRIteration (; kwargs... )
26+ return Bisection (; kwargs... )
2727end
2828function MatrixAlgebraKit. default_svd_algorithm (:: Type{T} ; kwargs... ) where {T <: AbstractVector{<:StridedROCMatrix{<:BlasFloat}} }
29- return QRIteration (; kwargs... )
29+ return Bisection (; kwargs... )
3030end
3131function MatrixAlgebraKit. default_eigh_algorithm (:: Type{T} ; kwargs... ) where {T <: StridedROCVecOrMat{<:BlasFloat} }
3232 return DivideAndConquer (; kwargs... )
@@ -55,8 +55,14 @@ function gesvdj!(::ROCSOLVER, A::StridedROCMatrix, S::StridedROCVector, U::Strid
5555 return MatrixAlgebraKit. svd_via_adjoint! (gesvdj!, ROCSOLVER (), A, S, U, Vᴴ; kwargs... )
5656end
5757
58- gesvdx! (:: ROCSOLVER , A:: StridedROCMatrix , S:: StridedROCVector , U:: StridedROCMatrix , Vᴴ:: StridedROCMatrix ; kwargs... ) =
59- YArocSOLVER. gesvdx! (A, S, U, Vᴴ; kwargs... )
58+ function gesvdx! (:: ROCSOLVER , A:: StridedROCMatrix , S:: StridedROCVector , U:: StridedROCMatrix , Vᴴ:: StridedROCMatrix ; kwargs... )
59+ if min (size (A)... ) == 1
60+ _gesvdx_rank1! (A, S, U, Vᴴ; kwargs... )
61+ else
62+ YArocSOLVER. gesvdx! (A, S, U, Vᴴ; kwargs... )
63+ end
64+ return S, U, Vᴴ
65+ end
6066
6167# rocSOLVER's batched `gesvd` requires m ≥ n, so wide matrices go through the adjoint
6268function gesvd_batched! (:: ROCSOLVER , As:: AbstractVector{<:StridedROCMatrix} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat }
@@ -80,14 +86,64 @@ gesvdj_batched!(::ROCSOLVER, As::AbstractVector{<:StridedROCMatrix}, Ss::Strided
8086gesvdj_batched! (:: ROCSOLVER , As:: StridedROCArray{T, 3} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat } =
8187 YArocSOLVER. gesvdj_strided_batched! (As, Ss, Us, Vᴴs; kwargs... )
8288
83- gesvdx_batched! (:: ROCSOLVER , As:: AbstractVector{<:StridedROCMatrix} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat } =
84- YArocSOLVER. gesvdx_batched! (As, Ss, Us, Vᴴs; kwargs... )
85- gesvdx_batched! (:: ROCSOLVER , As:: StridedROCArray{T, 3} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat } =
86- YArocSOLVER. gesvdx_strided_batched! (As, Ss, Us, Vᴴs; kwargs... )
89+ function gesvdx_batched! (:: ROCSOLVER , As:: AbstractVector{<:StridedROCMatrix} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat }
90+ if min (size (first (As))... ) == 1
91+ _gesvdx_rank1_batched! (As, Ss, Us, Vᴴs; kwargs... )
92+ else
93+ YArocSOLVER. gesvdx_batched! (As, Ss, Us, Vᴴs; kwargs... )
94+ end
95+ return Ss, Us, Vᴴs
96+ end
97+ function gesvdx_batched! (:: ROCSOLVER , As:: StridedROCArray{T, 3} , Ss:: StridedROCMatrix , Us:: StridedROCArray{T, 3} , Vᴴs:: StridedROCArray{T, 3} ; kwargs... ) where {T <: BlasFloat }
98+ if min (size (As, 1 ), size (As, 2 )) == 1
99+ _gesvdx_rank1_batched! (As, Ss, Us, Vᴴs; kwargs... )
100+ else
101+ YArocSOLVER. gesvdx_strided_batched! (As, Ss, Us, Vᴴs; kwargs... )
102+ end
103+ return Ss, Us, Vᴴs
104+ end
87105
88106gesdd! (:: ROCSOLVER , A:: StridedROCMatrix , S:: StridedROCVector , U:: StridedROCMatrix , Vᴴ:: StridedROCMatrix ; kwargs... ) =
89107 YArocSOLVER. gesdd! (A, S, U, Vᴴ; kwargs... )
90108
109+ function _gesvdx_rank1! (A:: StridedROCMatrix , S:: StridedROCVector , U:: StridedROCMatrix , Vᴴ:: StridedROCMatrix ; kwargs... )
110+ select_kwargs = Base. structdiff (NamedTuple (kwargs), (; irange = nothing , vl = nothing , vu = nothing ))
111+ nrmA = norm (A)
112+ fill! (S, nrmA)
113+ if ! isempty (U) && ! isempty (Vᴴ)
114+ u, v = view (U, :, 1 ), view (Vᴴ, 1 , :)
115+ x, e = size (A, 1 ) == 1 ? (v, u) : (u, v)
116+ if iszero (nrmA)
117+ zero! (x)
118+ fill! (view (x, 1 : 1 ), one (eltype (x)))
119+ else
120+ copyto! (x, vec (A))
121+ x ./= nrmA
122+ end
123+ fill! (e, one (eltype (e)))
124+ end
125+ _gesvdx_apply_range! (S, select_kwargs)
126+ return S, U, Vᴴ
127+ end
128+
129+ function _gesvdx_rank1_batched! (As, Ss:: StridedROCMatrix , Us, Vᴴs; kwargs... )
130+ select_kwargs = Base. structdiff (NamedTuple (kwargs), (; irange = nothing , vl = nothing , vu = nothing ))
131+ gesvdj_batched! (ROCSOLVER (), As, Ss, Us, Vᴴs; select_kwargs... )
132+ _gesvdx_apply_range! (Ss, select_kwargs)
133+ return Ss, Us, Vᴴs
134+ end
135+
136+ function _gesvdx_apply_range! (S, select:: NamedTuple )
137+ if haskey (select, :irange )
138+ 1 in convert (UnitRange{Int}, select. irange) || zero! (S)
139+ elseif haskey (select, :vl ) || haskey (select, :vu )
140+ vl = convert (eltype (S), get (select, :vl , - Inf ))
141+ vu = convert (eltype (S), get (select, :vu , Inf ))
142+ S .= ifelse .((vl .<= S) .& (S .< vu), S, zero (eltype (S)))
143+ end
144+ return S
145+ end
146+
91147heevj! (:: ROCSOLVER , A:: StridedROCMatrix , Dd:: StridedROCVector , V:: StridedROCMatrix ; kwargs... ) =
92148 YArocSOLVER. heevj! (A, Dd, V; kwargs... )
93149heevd! (:: ROCSOLVER , A:: StridedROCMatrix , Dd:: StridedROCVector , V:: StridedROCMatrix ; kwargs... ) =
0 commit comments