From b170988534fb1cd12d298b310376a0bb027497d1 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Thu, 26 Feb 2026 15:52:56 -0500 Subject: [PATCH] Fix eltype invalidation for SparsityPatternCSC 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: Chris Rackauckas --- src/graph.jl | 2 +- test/graph.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/graph.jl b/src/graph.jl index 39df611c..94954602 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -23,7 +23,7 @@ end SparsityPatternCSC(A::SparseMatrixCSC) = SparsityPatternCSC(A.m, A.n, A.colptr, A.rowval) -Base.eltype(::SparsityPatternCSC{T}) where {T} = T +SparseArrays.indtype(::SparsityPatternCSC{T}) where {T} = T Base.size(S::SparsityPatternCSC) = (S.m, S.n) Base.size(S::SparsityPatternCSC, d::Integer) = d::Integer <= 2 ? size(S)[d] : 1 Base.axes(S::SparsityPatternCSC, d::Integer) = Base.OneTo(size(S, d)) diff --git a/test/graph.jl b/test/graph.jl index e9784e56..773a0206 100644 --- a/test/graph.jl +++ b/test/graph.jl @@ -15,7 +15,8 @@ using Test ## SparsityPatternCSC @testset "SparsityPatternCSC" begin - @test eltype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Int + @test eltype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Bool + @test SparseArrays.indtype(SparsityPatternCSC(sprand(10, 10, 0.1))) == Int @testset "Transpose" begin for _ in 1:1000 m, n = rand(100:1000), rand(100:1000)