From 8504ed0065d7591c58cfa6ed4399bcb3c5bee462 Mon Sep 17 00:00:00 2001 From: "Viral B. Shah" Date: Tue, 27 Oct 2026 17:15:43 +0000 Subject: [PATCH] Show non-default fill value in GBArray show (#104) When the fill value differs from `defaultfill(storedeltype(A))`, print a `fill value:` line after the GraphBLAS header. The default case is unchanged. Doctests whose arrays have a non-default fill are updated. Co-Authored-By: Claude Opus 5.5 --- docs/src/arrays.md | 1 + docs/src/examples.md | 1 + docs/src/index.md | 1 + src/abstractgbarray.jl | 15 ++++++++++++--- test/gbarray.jl | 3 +++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/src/arrays.md b/docs/src/arrays.md index 614f54ac..200d1ea8 100644 --- a/docs/src/arrays.md +++ b/docs/src/arrays.md @@ -90,6 +90,7 @@ julia> v = GBVector{ComplexF32}(100) julia> v = GBMatrix(ComplexF64[1, 2im, 3 + 4im]; fill = nothing) 3x1 GraphBLAS double complex matrix, full by col 3 entries, memory: 288 bytes + fill value: nothing (1,1) 1 + 0i (2,1) 0 + 2i diff --git a/docs/src/examples.md b/docs/src/examples.md index 9158b771..b9c2286d 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -46,6 +46,7 @@ julia> cohen(A), sandia(A) julia> bfs_parents(A, 1, 5) 5x1 GraphBLAS int64_t matrix, bitmap by col 5 entries, memory: 288 bytes + fill value: nothing (1,1) 0 (2,1) 1 diff --git a/docs/src/index.md b/docs/src/index.md index ca3425e4..40130e02 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -90,6 +90,7 @@ true julia> B = setfill(A, missing) # no-copy alias 1000x1000 GraphBLAS double complex matrix, hypersparse by row, ints: 32/32/32 no entries, memory: 256 bytes + fill value: missing julia> B[1, 1] missing diff --git a/src/abstractgbarray.jl b/src/abstractgbarray.jl index 776133c5..d5cf5468 100644 --- a/src/abstractgbarray.jl +++ b/src/abstractgbarray.jl @@ -1019,14 +1019,23 @@ function Base.setindex!( end function Base.show(io::IO, ::MIME"text/plain", A::AbstractGBArray) #fallback printing - gxbprint(io, A) + str = gxbstring(A) + fill = getfill(A) + if !isequal(fill, defaultfill(storedeltype(A))) + # insert the fill value after the two GraphBLAS header lines, or append it + line = " fill value: $fill\n" + i = findfirst('\n', str) + i = i === nothing ? nothing : findnext('\n', str, i + 1) + str = i === nothing ? string(chomp(str), '\n', line) : str[1:i] * line * str[i+1:end] + end + print(io, str) end function Base.show(io::IO, A::AbstractGBArray) - gxbprint(io, A) + show(io, MIME"text/plain"(), A) end function Base.show(io::IOContext, A::AbstractGBArray) - gxbprint(io, A) + show(io, MIME"text/plain"(), A) end diff --git a/test/gbarray.jl b/test/gbarray.jl index 5e158158..f1aeb369 100644 --- a/test/gbarray.jl +++ b/test/gbarray.jl @@ -35,6 +35,9 @@ @test A'[1, 2] == 2 deleteat!(A, 1, 1) @test A[1, 1] == getfill(A) + # #104: non-default fill shows up in show + @test !occursin("fill value", sprint(show, MIME"text/plain"(), A)) + @test occursin("fill value: 17", sprint(show, MIME"text/plain"(), setfill(A, 17))) end @testset "sparse" begin #Construction and indexing correct for sparse matrices