Skip to content

Commit 06d32b0

Browse files
authored
Fix show for empty tensors (#329)
* avoid divide by zero for showing empty tensors * add test
1 parent d82de02 commit 06d32b0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/tensors/blockiterator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function show_blocks(io, mime::MIME"text/plain", iter; maytruncate::Bool = true)
5050
numlinesleft, numcols = get(io, :displaysize, displaysize(io))::Tuple{Int, Int}
5151
numlinesleft -= 2 # lines of headers have already been subtracted, but not the 2 spare lines for old and new prompts
5252
minlinesperblock = 7 # aim to have at least this many lines per printed block (= 5 lines for the actual matrix)
53-
minnumberofblocks = min(3, length(iter)) # aim to show at least this many blocks
53+
minnumberofblocks = clamp(length(iter), 1, 3) # aim to show at least this many blocks
5454
truncateblocks = sum(cb -> min(size(cb[2], 1) + 2, minlinesperblock), iter; init = 0) > numlinesleft
5555
maxnumlinesperblock = max(div(numlinesleft - 2 * truncateblocks, minnumberofblocks), minlinesperblock)
5656
# aim to show at least minnumberofblocks, but not if this means that there would be less than minlinesperblock

test/tensors/tensors.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ end
629629
for V in (ℂ^2, Z2Space(0 => 2, 1 => 2), SU2Space(0 => 2, 1 => 2))
630630
t1 = ones(Float32, V V, V)
631631
t2 = randn(ComplexF64, V V V)
632+
t3 = randn(Float64, zero(V), zero(V))
632633
# test unlimited output
633-
for t in (t1, t2, t1', t2')
634+
for t in (t1, t2, t1', t2', t3)
634635
output = IOBuffer()
635636
summary(output, t)
636637
print(output, ":\n codomain: ")

0 commit comments

Comments
 (0)