Skip to content

Commit

Permalink
Merge branch 'main' into dk/lusparse
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Sep 5, 2023
2 parents 08efc2e + 2fae1a1 commit 33e8b6f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ function LinearAlgebra.generic_trimatmul!(C::StridedVecOrMat, uploc, isunitc, tf
end
return C
end
function LinearAlgebra.generic_trimatmul!(C::StridedVecOrMat, uploc, isunitc, _, xA::AdjOrTrans{<:Any,<:SparseMatrixCSCUnion}, B::AbstractVecOrMat)
function LinearAlgebra.generic_trimatmul!(C::StridedVecOrMat, uploc, isunitc, ::Function, xA::AdjOrTrans{<:Any,<:SparseMatrixCSCUnion}, B::AbstractVecOrMat)
A = parent(xA)
nrowC = size(C, 1)
ncol = checksquare(A)
Expand Down
5 changes: 3 additions & 2 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,8 @@ function Base.fill!(V::SubArray{Tv, <:Any, <:AbstractSparseMatrixCSC{Tv}, <:Tupl
else
_spsetnz_setindex!(A, convert(Tv, x), I, J)
end
return _checkbuffers(A)
_checkbuffers(A)
V
end
"""
Helper method for immediately preceding fill! method. For all (i,j) such that i in I and
Expand Down Expand Up @@ -3207,7 +3208,7 @@ function _spsetz_setindex!(A::AbstractSparseMatrixCSC,
kI > lengthI && break
entrykIrow = I[kI]
else # entrykArow == entrykIrow
nonzeros(A)[kA] = 0
nonzeros(A)[kA] = zero(eltype(A))
kA += 1
kI += 1
(kA > coljAlastk || kI > lengthI) && break
Expand Down
10 changes: 3 additions & 7 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ using Test, LinearAlgebra, SparseArrays, Aqua

@testset "code quality" begin
@testset "Method ambiguity" begin
# Aqua.test_ambiguities([SparseArrays, Base, Core])
Aqua.test_ambiguities([SparseArrays, Base, Core])
end
@testset "Unbound type parameters" begin
@test_broken Aqua.detect_unbound_args_recursively(SparseArrays) == []
end
@testset "Undefined exports" begin
Aqua.test_undefined_exports(SparseArrays) == []
Aqua.test_undefined_exports(SparseArrays)
end
@testset "Compare Project.toml and test/Project.toml" begin
Aqua.test_project_extras(SparseArrays)
Expand All @@ -53,13 +53,9 @@ using Test, LinearAlgebra, SparseArrays, Aqua
end

let ambig = detect_ambiguities(SparseArrays; recursive=true)
@test_broken isempty(ambig)
@test isempty(ambig)
ambig = Set{Any}(((m1.sig, m2.sig) for (m1, m2) in ambig))
expect = []
push!(expect, (Tuple{typeof(LinearAlgebra.generic_trimatmul!), AbstractVecOrMat, Any, Any, Function, AbstractMatrix, AbstractVecOrMat},
Tuple{typeof(LinearAlgebra.generic_trimatmul!), StridedVecOrMat, Any, Any, Any, Union{Adjoint{var"#s388", var"#s387"}, Transpose{var"#s388", var"#s387"}} where {var"#s388", var"#s387"<:(Union{SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, SubArray{Tv, 2, <:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int}}, I}} where I<:AbstractUnitRange} where {Tv, Ti})}, AbstractVecOrMat}))
push!(expect, (Tuple{typeof(LinearAlgebra.generic_trimatmul!), AbstractVecOrMat, Any, Any, Function, Union{Adjoint{T, S}, Transpose{T, S}} where {T, S}, AbstractVecOrMat},
Tuple{typeof(LinearAlgebra.generic_trimatmul!), StridedVecOrMat, Any, Any, Any, Union{Adjoint{var"#s388", var"#s387"}, Transpose{var"#s388", var"#s387"}} where {var"#s388", var"#s387"<:(Union{SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, SubArray{Tv, 2, <:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int}}, I}} where I<:AbstractUnitRange} where {Tv, Ti})}, AbstractVecOrMat}))
good = true
while !isempty(ambig)
sigs = pop!(ambig)
Expand Down
12 changes: 12 additions & 0 deletions test/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ begin
vMAW = tr(wr(view(MA, :, 1:n)))
@test vAW * B vMAW * B
end
a = sprand(rng, ComplexF64, n, n, 0.01)
ma = Matrix(a)
@testset "triangular multiply with conjugate matrices" for tr in (x -> adjoint(transpose(x)), x -> transpose(adjoint(x))),
wr in (UpperTriangular, LowerTriangular, UnitUpperTriangular, UnitLowerTriangular)
AW = tr(wr(a))
MAW = tr(wr(ma))
@test AW * B MAW * B
# and for SparseMatrixCSCView - a view of all rows and unit range of cols
vAW = tr(wr(view(a, :, 1:n)))
vMAW = tr(wr(view(ma, :, 1:n)))
@test vAW * B vMAW * B
end
A = A - Diagonal(diag(A)) + 2I # avoid rounding errors by division
MA = Matrix(A)
@testset "triangular solver for $tr($wr)" for tr in (identity, adjoint, transpose),
Expand Down
17 changes: 15 additions & 2 deletions test/sparsematrix_constructors_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ end
A = rand(5,5)
= similar(A)
Ac = copyto!(A, B)
@test Ac === A
@test Ac === A
@test A == copyto!(A´, Matrix(B))
# Test copyto!(dense, Rdest, sparse, Rsrc)
A = rand(5,5)
Expand Down Expand Up @@ -1363,7 +1363,9 @@ end
a = sprand(10, 10, 0.2)
b = copy(a)
sa = view(a, 1:10, 2:3)
fill!(sa, 0.0)
sa_filled = fill!(sa, 0.0)
# `fill!` should return the sub array instead of its parent.
@test sa_filled === sa
b[1:10, 2:3] .= 0.0
@test a == b
A = sparse([1], [1], [Vector{Float64}(undef, 3)], 3, 3)
Expand All @@ -1375,6 +1377,17 @@ end
B[1, jj] = [4.0, 5.0, 6.0]
end
@test A == B

# https://github.com/JuliaSparse/SparseArrays.jl/pull/433
struct Foo
x::Int
end
Base.zero(::Type{Foo}) = Foo(0)
Base.zero(::Foo) = zero(Foo)
C = sparse([1], [1], [Foo(3)], 3, 3)
sC = view(C, 1:1, 1:2)
fill!(sC, zero(Foo))
@test C[1:1, 1:2] == zeros(Foo, 1, 2)
end

using Base: swaprows!, swapcols!
Expand Down

0 comments on commit 33e8b6f

Please sign in to comment.