Skip to content

Commit 7fe7111

Browse files
authored
Use Aqua and resolve ambiguities in convert (#14)
* Use Aqua and resolve ambiguities in convert * Add lower compat bounds for old Julia versions * Add tests * Bump version to v1.0.1
1 parent 51ac1f7 commit 7fe7111

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

Project.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LowRankMatrices"
22
uuid = "e65ccdef-c354-471a-8090-89bec1c20ec3"
33
authors = ["Jishnu Bhattacharya <[email protected]> and contributors"]
4-
version = "1.0.0"
4+
version = "1.0.1"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
@@ -14,12 +14,16 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1414
LowRankMatricesFillArraysExt = "FillArrays"
1515

1616
[compat]
17+
Aqua = "0.8"
1718
FillArrays = "0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 1"
19+
LinearAlgebra = "<0.0.1, 1"
20+
Test = "<0.0.1, 1"
1821
julia = "1"
1922

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

2428
[targets]
25-
test = ["Test", "FillArrays"]
29+
test = ["Aqua", "Test", "FillArrays"]

src/lowrankmatrix.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ function refactorsvd!(U::AbstractMatrix{S}, Σ::AbstractVector{T}, V::AbstractMa
6868
r
6969
end
7070

71-
for MAT in (:LowRankMatrix, :AbstractMatrix, :AbstractArray)
72-
@eval convert(::Type{$MAT{T}}, L::LowRankMatrix) where {T} =
73-
LowRankMatrix(convert(Matrix{T}, L.U), convert(Matrix{T}, L.V))
71+
function convert(::Type{LowRankMatrix{T}}, L::LowRankMatrix) where {T}
72+
L isa LowRankMatrix{T} && return L
73+
LowRankMatrix(convert(Matrix{T}, L.U), convert(Matrix{T}, L.V))
7474
end
75+
7576
convert(::Type{Matrix{T}}, L::LowRankMatrix) where {T} = convert(Matrix{T}, Matrix(L))
7677
promote_rule(::Type{LowRankMatrix{T}}, ::Type{LowRankMatrix{V}}) where {T,V} = LowRankMatrix{promote_type(T,V)}
7778
promote_rule(::Type{LowRankMatrix{T}}, ::Type{Matrix{V}}) where {T,V} = Matrix{promote_type(T,V)}

test/aqua.jl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Aqua
2+
using LowRankMatrices
3+
using Test
4+
5+
@testset "Project quality" begin
6+
Aqua.test_all(LowRankMatrices)
7+
end

test/runtests.jl

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ using Test
33
using LinearAlgebra
44
using FillArrays
55

6+
if VERSION >= v"1.10"
7+
include("aqua.jl")
8+
end
9+
610
@testset "Constructors" begin
711
@test Matrix(LowRankMatrix(Zeros(10,5))) == zeros(10,5)
812

@@ -45,6 +49,18 @@ using FillArrays
4549

4650
end
4751

52+
@testset "convert" begin
53+
L = LowRankMatrix([1,2], [1,2])
54+
Lf = convert(LowRankMatrix{Float64}, L)
55+
@test Lf == L
56+
@test Lf isa LowRankMatrix{Float64}
57+
Lf = convert(AbstractMatrix{Float64}, L)
58+
@test Lf == L
59+
@test Lf isa AbstractMatrix{Float64}
60+
Lf = convert(AbstractArray{Float64}, L)
61+
@test Lf == L
62+
@test Lf isa AbstractArray{Float64}
63+
end
4864

4965
@testset "LowRankMatrix algebra" begin
5066
A = LowRankMatrices._LowRankMatrix(randn(20,4), randn(12,4))

0 commit comments

Comments
 (0)