Skip to content

Commit 5d9b27c

Browse files
authored
Test code quality, resolve ambiguities (#355)
1 parent c09f0ac commit 5d9b27c

File tree

10 files changed

+115
-74
lines changed

10 files changed

+115
-74
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
99
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
10-
SuiteSparse_jll = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
10+
11+
[compat]
1112

1213
[extras]
14+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
1315
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1416
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1517
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1618
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1719

1820
[targets]
19-
test = ["Dates", "InteractiveUtils", "Printf", "Test"]
21+
test = ["Aqua", "Dates", "InteractiveUtils", "Printf", "Test"]

src/abstractsparse.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ issparse(A::DenseArray) = false
7676
issparse(S::AbstractSparseArray) = true
7777

7878
indtype(S::AbstractSparseArray{<:Any,Ti}) where {Ti} = Ti
79+
indtype(T::UpperOrLowerTriangular{<:Any,<:AbstractSparseArray}) = indtype(parent(T))
7980

8081
# The following two methods should be overloaded by concrete types to avoid
8182
# allocating the I = findall(...)

src/linalg.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ const SparseOrTri{Tv,Ti} = Union{SparseMatrixCSCUnion{Tv,Ti},SparseTriangular{Tv
169169
# done by a quicksort of the row indices or by a full scan of the dense result vector.
170170
# The last is faster, if more than ≈ 1/32 of the result column is nonzero.
171171
# TODO: extend to SparseMatrixCSCUnion to allow for SubArrays (view(X, :, r)).
172-
function spmatmul(A::SparseOrTri{TvA,TiA}, B::Union{SparseOrTri{TvB,TiB},SparseVectorUnion{TvB,TiB},SubArray{TvB,<:Any,<:AbstractSparseArray{TvB,TiB}}}) where {TvA,TiA,TvB,TiB}
173-
174-
Tv = promote_op(matprod, TvA, TvB)
175-
Ti = promote_type(TiA, TiB)
172+
function spmatmul(A::SparseOrTri, B::Union{SparseOrTri,SparseVectorUnion,SubArray{<:Any,<:Any,<:AbstractSparseArray}})
173+
Tv = promote_op(matprod, eltype(A), eltype(B))
174+
Ti = promote_type(indtype(A), indtype(B))
176175
mA, nA = size(A)
177176
nB = size(B, 2)
178177
nA == size(B, 1) || throw(DimensionMismatch())
@@ -375,8 +374,8 @@ const WrapperMatrixTypes{T,MT} = Union{
375374
Hermitian{T,MT},
376375
}
377376

378-
function dot(A::MA, B::AbstractSparseMatrixCSC{TB}) where {MA<:Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}},TB}
379-
T = promote_type(eltype(A), TB)
377+
function dot(A::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}}, B::AbstractSparseMatrixCSC)
378+
T = promote_type(eltype(A), eltype(B))
380379
(m, n) = size(A)
381380
if (m, n) != size(B)
382381
throw(DimensionMismatch())
@@ -397,7 +396,7 @@ function dot(A::MA, B::AbstractSparseMatrixCSC{TB}) where {MA<:Union{DenseMatrix
397396
return s
398397
end
399398

400-
function dot(A::AbstractSparseMatrixCSC{TA}, B::MB) where {TA,MB<:Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}}}
399+
function dot(A::AbstractSparseMatrixCSC, B::Union{DenseMatrixUnion,WrapperMatrixTypes{<:Any,Union{DenseMatrixUnion,AbstractSparseMatrix}}})
401400
return conj(dot(B, A))
402401
end
403402

@@ -1315,19 +1314,19 @@ function opnormestinv(A::AbstractSparseMatrixCSC{T}, t::Integer = min(2,maximum(
13151314
end
13161315

13171316
## kron
1318-
const _SparseArraysCSC{T} = Union{SparseVector{T}, AbstractSparseMatrixCSC{T}}
1319-
const _SparseKronArrays = Union{_SparseArrays, AdjOrTrans{<:Any,<:_SparseArraysCSC}}
1317+
const _SparseArraysCSC = Union{AbstractCompressedVector, AbstractSparseMatrixCSC}
1318+
const _SparseKronArrays = Union{_SparseArraysCSC, AdjOrTrans{<:Any,<:_SparseArraysCSC}}
13201319

1321-
const _Symmetric_SparseKronArrays{T,A<:_SparseKronArrays} = Symmetric{T,A}
1322-
const _Hermitian_SparseKronArrays{T,A<:_SparseKronArrays} = Hermitian{T,A}
1323-
const _Triangular_SparseKronArrays{T,A<:_SparseKronArrays} = UpperOrLowerTriangular{T,A}
1320+
const _Symmetric_SparseKronArrays = Symmetric{<:Any,<:_SparseKronArrays}
1321+
const _Hermitian_SparseKronArrays = Hermitian{<:Any,<:_SparseKronArrays}
1322+
const _Triangular_SparseKronArrays = UpperOrLowerTriangular{<:Any,<:_SparseKronArrays}
13241323
const _Annotated_SparseKronArrays = Union{_Triangular_SparseKronArrays, _Symmetric_SparseKronArrays, _Hermitian_SparseKronArrays}
13251324
const _SparseKronGroup = Union{_SparseKronArrays, _Annotated_SparseKronArrays}
13261325

13271326
@inline function kron!(C::SparseMatrixCSC, A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC)
13281327
mA, nA = size(A); mB, nB = size(B)
13291328
mC, nC = mA*mB, nA*nB
1330-
@boundscheck size(C) == (mC, nC) || throw(DimensionMismatch("target matrix needs to have size ($mC, $nC)," *
1329+
@boundscheck size(C) == (mC, nC) || throw(DimensionMismatch("target matrix needs to have size ($mC, $nC)," *
13311330
" but has size $(size(C))"))
13321331
rowvalC = rowvals(C)
13331332
nzvalC = nonzeros(C)
@@ -1393,6 +1392,8 @@ kron!(C::SparseMatrixCSC, A::_SparseKronGroup, B::Diagonal) =
13931392
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
13941393
kron!(C::SparseMatrixCSC, A::Diagonal, B::_SparseKronGroup) =
13951394
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1395+
kron!(C::SparseMatrixCSC, A::AbstractCompressedVector, B::AdjOrTrans{<:Any,<:AbstractCompressedVector}) =
1396+
broadcast!(*, C, A, B)
13961397
kron!(c::SparseMatrixCSC, a::Number, b::_SparseKronGroup) = mul!(c, a, b)
13971398
kron!(c::SparseMatrixCSC, a::_SparseKronGroup, b::Number) = mul!(c, a, b)
13981399

@@ -1406,7 +1407,7 @@ function kron(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC)
14061407
sizehint!(C, nnz(A)*nnz(B))
14071408
return @inbounds kron!(C, A, B)
14081409
end
1409-
function kron(x::SparseVector, y::SparseVector)
1410+
function kron(x::AbstractCompressedVector, y::AbstractCompressedVector)
14101411
nnzx, nnzy = nnz(x), nnz(y)
14111412
nnzz = nnzx*nnzy # number of nonzeros in new vector
14121413
nzind = Vector{promote_type(indtype(x), indtype(y))}(undef, nnzz) # the indices of nonzeros
@@ -1421,6 +1422,7 @@ kron(A::_SparseKronGroup, B::_DenseConcatGroup) = kron(A, sparse(B))
14211422
kron(A::_DenseConcatGroup, B::_SparseKronGroup) = kron(sparse(A), B)
14221423
kron(A::SparseVectorUnion, B::AdjOrTransSparseVectorUnion) = A .* B
14231424
# disambiguation
1425+
kron(A::AbstractCompressedVector, B::AdjOrTrans{<:Any,<:AbstractCompressedVector}) = A .* B
14241426
kron(a::Number, b::_SparseKronGroup) = a * b
14251427
kron(a::_SparseKronGroup, b::Number) = a * b
14261428

src/readonly.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ Base.copy(x::ReadOnly) = ReadOnly(copy(parent(x)))
3535
(==)(x::ReadOnly, y::AbstractVector) = parent(x) == y
3636
(==)(x::AbstractVector, y::ReadOnly) = x == parent(y)
3737
(==)(x::ReadOnly, y::ReadOnly) = parent(x) == parent(y)
38+
# disambiguation
39+
(==)(x::ReadOnly{T,1,<:AbstractVector{T}}, y::ReadOnly{S,1,<:AbstractVector{S}}) where {T,S} =
40+
parent(x) == parent(y)
3841

3942
Base.dataids(::ReadOnly) = tuple()

src/solvers/spqr.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module SPQR
55
import Base: \, *
66
using Base: require_one_based_indexing
77
using LinearAlgebra
8-
using LinearAlgebra: AbstractQ, AdjointQ, copy_similar
8+
using LinearAlgebra: AbstractQ, AdjointQ, AdjointAbsVec, copy_similar
99
using ..LibSuiteSparse: SuiteSparseQR_C
1010

1111
# ordering options */
@@ -322,6 +322,7 @@ function (*)(A::AbstractMatrix, adjQ::AdjointQ{<:Any,<:QRSparseQ})
322322
throw(DimensionMismatch("matrix A has dimensions $(size(A)) but Q-matrix has dimensions $(size(adjQ))"))
323323
end
324324
end
325+
(*)(u::AdjointAbsVec, Q::AdjointQ{<:Any,<:QRSparseQ}) = (Q'u')'
325326

326327
(*)(Q::QRSparseQ, B::SparseMatrixCSC) = sparse(Q) * B
327328
(*)(A::SparseMatrixCSC, Q::QRSparseQ) = A * sparse(Q)

src/sparsevector.jl

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ _unsafe_unfix(s::FixedSparseVector) = SparseVector(length(s), parent(nonzeroinds
8585

8686
# Define an alias for a view of a whole column of a SparseMatrixCSC. Many methods can be written for the
8787
# union of such a view and a SparseVector so we define an alias for such a union as well
88-
const SparseColumnView{Tv,Ti} = SubArray{Tv,1,<:AbstractSparseMatrixCSC{Tv,Ti},Tuple{Base.Slice{Base.OneTo{Int}},Int},false}
89-
const SparseVectorView{Tv,Ti} = SubArray{Tv,1,<:AbstractSparseVector{Tv,Ti},Tuple{Base.Slice{Base.OneTo{Int}}},false}
90-
const SparseVectorUnion{Tv,Ti} = Union{AbstractCompressedVector{Tv,Ti}, SparseColumnView{Tv,Ti}, SparseVectorView{Tv,Ti}}
91-
const AdjOrTransSparseVectorUnion{Tv,Ti} = LinearAlgebra.AdjOrTrans{Tv, <:SparseVectorUnion{Tv,Ti}}
92-
const SVorFSV{Tv,Ti} = Union{SparseVector{Tv,Ti},FixedSparseVector{Tv,Ti}}
88+
const SparseColumnView = SubArray{<:Any,1,<:AbstractSparseMatrixCSC,Tuple{Base.Slice{Base.OneTo{Int}},Int},false}
89+
const SparseVectorView = SubArray{<:Any,1,<:AbstractSparseVector,Tuple{Base.Slice{Base.OneTo{Int}}},false}
90+
const SparseVectorUnion = Union{AbstractCompressedVector, SparseColumnView, SparseVectorView}
91+
const AdjOrTransSparseVectorUnion = AdjOrTrans{<:Any,<:SparseVectorUnion}
92+
9393
### Basic properties
9494

95-
length(x::SVorFSV) = getfield(x, :n)
96-
size(x::SVorFSV) = (getfield(x, :n),)
95+
length(x::SparseVector) = getfield(x, :n)
96+
length(x::FixedSparseVector) = getfield(x, :n)
97+
size(x::SparseVector) = (getfield(x, :n),)
98+
size(x::FixedSparseVector) = (getfield(x, :n),)
9799

98100
function Base._simple_count(f, x::AbstractCompressedVector, init::T) where T
99101
init + T(count(f, nonzeros(x)) + f(zero(eltype(x)))*(length(x) - nnz(x)))
@@ -118,7 +120,8 @@ function nzrange(x::SparseVectorUnion, j::Integer)
118120
j == 1 ? (1:nnz(x)) : throw(BoundsError(x, (":", j)))
119121
end
120122

121-
nonzeros(x::SVorFSV) = getfield(x, :nzval)
123+
nonzeros(x::SparseVector) = getfield(x, :nzval)
124+
nonzeros(x::FixedSparseVector) = getfield(x, :nzval)
122125
function nonzeros(x::SparseColumnView)
123126
rowidx, colidx = parentindices(x)
124127
A = parent(x)
@@ -127,7 +130,8 @@ function nonzeros(x::SparseColumnView)
127130
end
128131
nonzeros(x::SparseVectorView) = nonzeros(parent(x))
129132

130-
nonzeroinds(x::SVorFSV) = getfield(x, :nzind)
133+
nonzeroinds(x::SparseVector) = getfield(x, :nzind)
134+
nonzeroinds(x::FixedSparseVector) = getfield(x, :nzind)
131135
function nonzeroinds(x::SparseColumnView)
132136
rowidx, colidx = parentindices(x)
133137
A = parent(x)
@@ -802,12 +806,12 @@ function findall(x::SparseVectorUnion)
802806
return findall(identity, x)
803807
end
804808

805-
function findall(p::F, x::SparseVectorUnion{<:Any,Ti}) where {Ti,F<:Function}
809+
function findall(p::F, x::SparseVectorUnion) where {F<:Function}
806810
if p(zero(eltype(x)))
807811
return invoke(findall, Tuple{Function, Any}, p, x)
808812
end
809813
numnz = nnz(x)
810-
I = Vector{Ti}(undef, numnz)
814+
I = Vector{indtype(x)}(undef, numnz)
811815

812816
nzind = nonzeroinds(x)
813817
nzval = nonzeros(x)
@@ -827,7 +831,7 @@ function findall(p::F, x::SparseVectorUnion{<:Any,Ti}) where {Ti,F<:Function}
827831

828832
return I
829833
end
830-
findall(p::Base.Fix2{typeof(in)}, x::SparseVectorUnion{<:Any,Ti}) where {Ti} =
834+
findall(p::Base.Fix2{typeof(in)}, x::SparseVectorUnion) =
831835
invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x)
832836

833837
"""
@@ -849,11 +853,11 @@ julia> findnz(x)
849853
([1, 4, 6, 8], [1, 2, 4, 3])
850854
```
851855
"""
852-
function findnz(x::SparseVectorUnion{Tv,Ti}) where {Tv,Ti}
856+
function findnz(x::SparseVectorUnion)
853857
numnz = nnz(x)
854858

855-
I = Vector{Ti}(undef, numnz)
856-
V = Vector{Tv}(undef, numnz)
859+
I = Vector{indtype(x)}(undef, numnz)
860+
V = Vector{eltype(x)}(undef, numnz)
857861

858862
nzind = nonzeroinds(x)
859863
nzval = nonzeros(x)
@@ -1095,13 +1099,13 @@ complex(x::AbstractSparseVector) =
10951099

10961100
### Concatenation
10971101

1098-
# Without the first of these methods, horizontal concatenations of SparseVectors fall
1099-
# back to the horizontal concatenation method that ensures that combinations of
1100-
# sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
1101-
# of _absspvec_hcat below. The <:Integer qualifications are necessary for correct dispatch.
1102-
hcat(X::SparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_hcat(X...)
1103-
hcat(X::FixedSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_hcat(X...)
1104-
hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_hcat(X...)
1102+
function hcat(Xin::AbstractSparseVector...)
1103+
X = map(_unsafe_unfix, Xin)
1104+
Tv = promote_type(map(eltype, X)...)
1105+
Ti = promote_type(map(indtype, X)...)
1106+
r = _absspvec_hcat(map(x -> convert(SparseVector{Tv,Ti}, x), X)...)
1107+
return @if_move_fixed Xin... r
1108+
end
11051109
function _absspvec_hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
11061110
# check sizes
11071111
n = length(X)
@@ -1128,24 +1132,15 @@ function _absspvec_hcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
11281132
roff += length(xnzind)
11291133
end
11301134
colptr[n+1] = roff
1131-
r = SparseMatrixCSC{Tv,Ti}(m, n, colptr, nzrow, nzval)
1132-
return @if_move_fixed X... r
1135+
return SparseMatrixCSC{Tv,Ti}(m, n, colptr, nzrow, nzval)
11331136
end
11341137

1135-
# Without the first of these methods, vertical concatenations of SparseVectors fall
1136-
# back to the vertical concatenation method that ensures that combinations of
1137-
# sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs, instead
1138-
# of _absspvec_vcat below. The <:Integer qualifications are necessary for correct dispatch.
1139-
vcat(X::SparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
1140-
vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti<:Integer} = _absspvec_vcat(X...)
1141-
function vcat(X::SparseVector...)
1142-
commeltype = promote_type(map(eltype, X)...)
1143-
commindtype = promote_type(map(indtype, X)...)
1144-
return vcat(map(x -> SparseVector{commeltype,commindtype}(x), X)...)
1145-
end
1146-
function vcat(X::SVorFSV...)
1147-
r = vcat(map(_unsafe_unfix, X)...)
1148-
return @if_move_fixed X r
1138+
function vcat(Xin::AbstractSparseVector...)
1139+
X = map(_unsafe_unfix, Xin)
1140+
Tv = promote_type(map(eltype, X)...)
1141+
Ti = promote_type(map(indtype, X)...)
1142+
r = _absspvec_vcat(map(x -> convert(SparseVector{Tv,Ti}, x), X)...)
1143+
return @if_move_fixed Xin... r
11491144
end
11501145
function _absspvec_vcat(X::AbstractSparseVector{Tv,Ti}...) where {Tv,Ti}
11511146
# check sizes
@@ -1177,22 +1172,18 @@ end
11771172

11781173
hcat(Xin::Union{Vector, AbstractSparseVector}...) = hcat(map(sparse, Xin)...)
11791174
vcat(Xin::Union{Vector, AbstractSparseVector}...) = vcat(map(sparse, Xin)...)
1180-
# Without the following method, vertical concatenations of SparseVectors with Vectors
1181-
# fall back to the vertical concatenation method that ensures that combinations of
1182-
# sparse/special/dense matrix/vector types concatenate to SparseMatrixCSCs (because
1183-
# the vcat method immediately above is less specific, being defined in AbstractSparseVector
1184-
# rather than SparseVector).
1185-
vcat(X::Union{Vector,AbstractCompressedVector}...) = vcat(map(sparse, X)...)
1186-
11871175

11881176
### Concatenation of un/annotated sparse/special/dense vectors/matrices
11891177

1190-
const _SparseArrays = Union{SparseVector, AbstractSparseMatrixCSC, Adjoint{<:Any,<:SparseVector}, Transpose{<:Any,<:SparseVector}}
1178+
const _SparseArrays = Union{AbstractSparseVector,
1179+
AbstractSparseMatrixCSC,
1180+
Adjoint{<:Any,<:AbstractSparseVector},
1181+
Transpose{<:Any,<:AbstractSparseVector}}
11911182
const _SparseConcatArrays = Union{_SpecialArrays, _SparseArrays}
11921183

1193-
const _Symmetric_SparseConcatArrays{T,A<:_SparseConcatArrays} = Symmetric{T,A}
1194-
const _Hermitian_SparseConcatArrays{T,A<:_SparseConcatArrays} = Hermitian{T,A}
1195-
const _Triangular_SparseConcatArrays{T,A<:_SparseConcatArrays} = UpperOrLowerTriangular{T,A}
1184+
const _Symmetric_SparseConcatArrays = Symmetric{<:Any,<:_SparseConcatArrays}
1185+
const _Hermitian_SparseConcatArrays = Hermitian{<:Any,<:_SparseConcatArrays}
1186+
const _Triangular_SparseConcatArrays = UpperOrLowerTriangular{<:Any,<:_SparseConcatArrays}
11961187
const _Annotated_SparseConcatArrays = Union{_Triangular_SparseConcatArrays, _Symmetric_SparseConcatArrays, _Hermitian_SparseConcatArrays}
11971188
# It's important that _SparseConcatGroup is a larger union than _DenseConcatGroup to make
11981189
# sparse cat-methods less specific and to kick in only if there is some sparse array present
@@ -1548,7 +1539,8 @@ end
15481539
Base.reducedim_initarray(A::SparseVectorUnion, region, v0, ::Type{R}) where {R} =
15491540
fill!(Array{R}(undef, Base.to_shape(Base.reduced_indices(A, region))), v0)
15501541

1551-
function Base._mapreduce(f, op, ::IndexCartesian, A::SparseVectorUnion{T}) where {T}
1542+
function Base._mapreduce(f, op, ::IndexCartesian, A::SparseVectorUnion)
1543+
T = eltype(A)
15521544
isempty(A) && return Base.mapreduce_empty(f, op, T)
15531545
z = nnz(A)
15541546
rest, ini = if z == 0
@@ -1671,26 +1663,26 @@ end
16711663
(/)(x::SparseVectorUnion, a::Number) =
16721664
@if_move_fixed x SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) / a)
16731665
# dot
1674-
function dot(x::AbstractVector{Tx}, y::SparseVectorUnion{Ty}) where {Tx<:Number,Ty<:Number}
1666+
function dot(x::AbstractVector, y::SparseVectorUnion)
16751667
require_one_based_indexing(x, y)
16761668
n = length(x)
16771669
length(y) == n || throw(DimensionMismatch())
16781670
nzind = nonzeroinds(y)
16791671
nzval = nonzeros(y)
1680-
s = dot(zero(Tx), zero(Ty))
1672+
s = dot(zero(eltype(x)), zero(eltype(y)))
16811673
@inbounds for i = 1:length(nzind)
16821674
s += dot(x[nzind[i]], nzval[i])
16831675
end
16841676
return s
16851677
end
16861678

1687-
function dot(x::SparseVectorUnion{Tx}, y::AbstractVector{Ty}) where {Tx<:Number,Ty<:Number}
1679+
function dot(x::SparseVectorUnion, y::AbstractVector)
16881680
require_one_based_indexing(x, y)
16891681
n = length(y)
16901682
length(x) == n || throw(DimensionMismatch())
16911683
nzind = nonzeroinds(x)
16921684
nzval = nonzeros(x)
1693-
s = dot(zero(Tx), zero(Ty))
1685+
s = dot(zero(eltype(x)), zero(eltype(y)))
16941686
@inbounds for i = 1:length(nzind)
16951687
s += dot(nzval[i], y[nzind[i]])
16961688
end
@@ -1718,7 +1710,7 @@ function _spdot(f::Function,
17181710
s
17191711
end
17201712

1721-
function dot(x::SparseVectorUnion{<:Number}, y::SparseVectorUnion{<:Number})
1713+
function dot(x::SparseVectorUnion, y::SparseVectorUnion)
17221714
x === y && return sum(abs2, x)
17231715
n = length(x)
17241716
length(y) == n || throw(DimensionMismatch())

test/ambiguous.jl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
2-
using Test, LinearAlgebra, SparseArrays
2+
using Test, LinearAlgebra, SparseArrays, Aqua
3+
4+
@testset "code quality" begin
5+
@testset "Method ambiguity" begin
6+
# Aqua.test_ambiguities([SparseArrays, Base, Core])
7+
end
8+
@testset "Unbound type parameters" begin
9+
@test_broken Aqua.detect_unbound_args_recursively(SparseArrays) == []
10+
end
11+
@testset "Undefined exports" begin
12+
Aqua.test_undefined_exports(SparseArrays) == []
13+
end
14+
@testset "Compare Project.toml and test/Project.toml" begin
15+
Aqua.test_project_extras(SparseArrays)
16+
end
17+
@testset "Stale dependencies" begin
18+
Aqua.test_stale_deps(SparseArrays)
19+
end
20+
@testset "Compat bounds" begin
21+
Aqua.test_deps_compat(SparseArrays)
22+
end
23+
@testset "Project.toml formatting" begin
24+
Aqua.test_project_toml_formatting(SparseArrays)
25+
end
26+
@testset "Piracy" begin
27+
@test_broken Aqua.Piracy.hunt(SparseArrays) == Method[]
28+
end
29+
end
30+
331
@testset "detect_ambiguities" begin
432
@test_nowarn detect_ambiguities(SparseArrays; recursive=true, ambiguous_bottom=false)
533
end

0 commit comments

Comments
 (0)