Skip to content

Commit

Permalink
Merge pull request #19 from JuliaLinearAlgebra/an/svds
Browse files Browse the repository at this point in the history
Loosen AbstractMatrix requirement in svds
  • Loading branch information
andreasnoack committed Jul 10, 2018
2 parents f3c76be + f123bcf commit 7461c3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Arpack.jl
Expand Up @@ -222,10 +222,10 @@ struct AtA_or_AAt{T,S} <: AbstractArray{T, 2}
buffer::Vector{T}
end

function AtA_or_AAt(A::AbstractMatrix{T}) where T
function AtA_or_AAt(A)
T = eltype(A)
Tnew = typeof(zero(T)/sqrt(one(T)))
Anew = convert(AbstractMatrix{Tnew}, A)
AtA_or_AAt{Tnew,typeof(Anew)}(Anew, Vector{Tnew}(undef, max(size(A)...)))
return AtA_or_AAt{Tnew,typeof(A)}(A, Vector{Tnew}(undef, max(size(A)...)))
end

function LinearAlgebra.mul!(y::StridedVector{T}, A::AtA_or_AAt{T}, x::StridedVector{T}) where T
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Expand Up @@ -281,3 +281,17 @@ end
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)), rand(1:10, 10, 10))
@test_throws MethodError svds(big.(rand(1:10, 10, 8)))
end

struct MyOp{S}
mat::S
end
Base.size(A::MyOp) = size(A.mat)
Base.size(A::MyOp, i::Integer) = size(A.mat, i)
Base.eltype(A::MyOp) = Float64
Base.:*(A::MyOp, B::AbstractMatrix) = A.mat*B
LinearAlgebra.mul!(y::AbstractVector, A::MyOp, x::AbstractVector) = mul!(y, A.mat, x)
LinearAlgebra.adjoint(A::MyOp) = MyOp(adjoint(A.mat))
@testset "svds for non-AbstractMatrix" begin
A = MyOp(randn(10, 9))
@test svds(A, v0 = ones(9))[1].S == svds(A.mat, v0 = ones(9))[1].S
end

0 comments on commit 7461c3a

Please sign in to comment.