From 9b6e067223f8754b6e4468a5b818e4fb6ecddf0c Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Sat, 13 Dec 2025 22:20:34 -0500 Subject: [PATCH 1/2] avoid divide by zero for showing empty tensors --- src/tensors/blockiterator.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tensors/blockiterator.jl b/src/tensors/blockiterator.jl index 40a0e1edb..2519bd63e 100644 --- a/src/tensors/blockiterator.jl +++ b/src/tensors/blockiterator.jl @@ -50,7 +50,7 @@ function show_blocks(io, mime::MIME"text/plain", iter; maytruncate::Bool = true) numlinesleft, numcols = get(io, :displaysize, displaysize(io))::Tuple{Int, Int} numlinesleft -= 2 # lines of headers have already been subtracted, but not the 2 spare lines for old and new prompts minlinesperblock = 7 # aim to have at least this many lines per printed block (= 5 lines for the actual matrix) - minnumberofblocks = min(3, length(iter)) # aim to show at least this many blocks + minnumberofblocks = clamp(length(iter), 1, 3) # aim to show at least this many blocks truncateblocks = sum(cb -> min(size(cb[2], 1) + 2, minlinesperblock), iter; init = 0) > numlinesleft maxnumlinesperblock = max(div(numlinesleft - 2 * truncateblocks, minnumberofblocks), minlinesperblock) # aim to show at least minnumberofblocks, but not if this means that there would be less than minlinesperblock From 5dd0cc9db2e8af5c23159c0ef35098fd7539f337 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Sat, 13 Dec 2025 22:26:24 -0500 Subject: [PATCH 2/2] add test --- test/tensors/tensors.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/tensors/tensors.jl b/test/tensors/tensors.jl index 0d932cdc7..74cb9cfa0 100644 --- a/test/tensors/tensors.jl +++ b/test/tensors/tensors.jl @@ -629,8 +629,9 @@ end for V in (ℂ^2, Z2Space(0 => 2, 1 => 2), SU2Space(0 => 2, 1 => 2)) t1 = ones(Float32, V ⊗ V, V) t2 = randn(ComplexF64, V ⊗ V ⊗ V) + t3 = randn(Float64, zero(V), zero(V)) # test unlimited output - for t in (t1, t2, t1', t2') + for t in (t1, t2, t1', t2', t3) output = IOBuffer() summary(output, t) print(output, ":\n codomain: ")