Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Aqua and resolve ambiguities in convert #14

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LowRankMatrices"
uuid = "e65ccdef-c354-471a-8090-89bec1c20ec3"
authors = ["Jishnu Bhattacharya <[email protected]> and contributors"]
version = "1.0.0"
version = "1.0.1"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand All @@ -14,12 +14,16 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LowRankMatricesFillArraysExt = "FillArrays"

[compat]
Aqua = "0.8"
FillArrays = "0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 1"
LinearAlgebra = "<0.0.1, 1"
Test = "<0.0.1, 1"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "FillArrays"]
test = ["Aqua", "Test", "FillArrays"]
7 changes: 4 additions & 3 deletions src/lowrankmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ function refactorsvd!(U::AbstractMatrix{S}, Σ::AbstractVector{T}, V::AbstractMa
r
end

for MAT in (:LowRankMatrix, :AbstractMatrix, :AbstractArray)
@eval convert(::Type{$MAT{T}}, L::LowRankMatrix) where {T} =
LowRankMatrix(convert(Matrix{T}, L.U), convert(Matrix{T}, L.V))
function convert(::Type{LowRankMatrix{T}}, L::LowRankMatrix) where {T}
L isa LowRankMatrix{T} && return L
LowRankMatrix(convert(Matrix{T}, L.U), convert(Matrix{T}, L.V))
end

convert(::Type{Matrix{T}}, L::LowRankMatrix) where {T} = convert(Matrix{T}, Matrix(L))
promote_rule(::Type{LowRankMatrix{T}}, ::Type{LowRankMatrix{V}}) where {T,V} = LowRankMatrix{promote_type(T,V)}
promote_rule(::Type{LowRankMatrix{T}}, ::Type{Matrix{V}}) where {T,V} = Matrix{promote_type(T,V)}
Expand Down
7 changes: 7 additions & 0 deletions test/aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Aqua
using LowRankMatrices
using Test

@testset "Project quality" begin
Aqua.test_all(LowRankMatrices)
end
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ using Test
using LinearAlgebra
using FillArrays

if VERSION >= v"1.10"
include("aqua.jl")
end

@testset "Constructors" begin
@test Matrix(LowRankMatrix(Zeros(10,5))) == zeros(10,5)

Expand Down Expand Up @@ -45,6 +49,18 @@ using FillArrays

end

@testset "convert" begin
L = LowRankMatrix([1,2], [1,2])
Lf = convert(LowRankMatrix{Float64}, L)
@test Lf == L
@test Lf isa LowRankMatrix{Float64}
Lf = convert(AbstractMatrix{Float64}, L)
@test Lf == L
@test Lf isa AbstractMatrix{Float64}
Lf = convert(AbstractArray{Float64}, L)
@test Lf == L
@test Lf isa AbstractArray{Float64}
end

@testset "LowRankMatrix algebra" begin
A = LowRankMatrices._LowRankMatrix(randn(20,4), randn(12,4))
Expand Down
Loading