Skip to content

Commit 408d8f3

Browse files
ChrisRackauckas-ClaudeChrisRackauckasgdalle
authored
Fix eltype invalidation for SparsityPatternCSC (#304)
SparsityPatternCSC{Ti} <: AbstractMatrix{Bool} but the custom Base.eltype method was returning Ti (the index type) instead of Bool. This caused 24,906 method invalidations when loading the package, as it invalidated the backedge from Base.eltype(::AbstractArray). Change the custom method to SparseArrays.indtype instead, since that's what the type parameter Ti actually represents. The eltype is now correctly inherited from AbstractMatrix{Bool}. Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com> Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com>
1 parent 1c3c9da commit 408d8f3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323

2424
SparsityPatternCSC(A::SparseMatrixCSC) = SparsityPatternCSC(A.m, A.n, A.colptr, A.rowval)
2525

26-
Base.eltype(::SparsityPatternCSC{T}) where {T} = T
26+
SparseArrays.indtype(::SparsityPatternCSC{T}) where {T} = T
2727
Base.size(S::SparsityPatternCSC) = (S.m, S.n)
2828
Base.size(S::SparsityPatternCSC, d::Integer) = d::Integer <= 2 ? size(S)[d] : 1
2929
Base.axes(S::SparsityPatternCSC, d::Integer) = Base.OneTo(size(S, d))

test/graph.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ using Test
1515
## SparsityPatternCSC
1616

1717
@testset "SparsityPatternCSC" begin
18-
@test eltype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Int
18+
@test eltype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Bool
19+
@test SparseArrays.indtype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Int
1920
@testset "Transpose" begin
2021
for _ in 1:1000
2122
m, n = rand(100:1000), rand(100:1000)

0 commit comments

Comments
 (0)