Skip to content

Commit 9a7214e

Browse files
authored
show eltype for Zeros/Ones (#283)
* show eltype for Zeros/Ones * Bump version to v1.5.0
1 parent 1efbdbb commit 9a7214e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/FillArrays.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,19 @@ function Base.show(io::IO, ::MIME"text/plain", x::Union{Eye, AbstractFill})
781781
end
782782

783783
function Base.show(io::IO, x::AbstractFill) # for example (Fill(π,3),)
784-
print(io, nameof(typeof(x)), "(")
785-
if x isa Union{Zeros, Ones}
784+
print(io, nameof(typeof(x)))
785+
sz = size(x)
786+
args = if x isa Union{Zeros, Ones}
787+
T = eltype(x)
788+
if T != Float64
789+
print(io,"{", T, "}")
790+
end
791+
print(io, "(")
786792
else
787-
show(io, getindex_value(x)) # show not print to handle (Fill(1f0,2),)
788-
ndims(x) > 0 && print(io, ", ")
793+
# show, not print, to handle (Fill(1f0,2),)
794+
print(io, "(")
795+
show(io, getindex_value(x))
796+
ndims(x) == 0 || print(io, ", ")
789797
end
790798
join(io, size(x), ", ")
791799
print(io, ")")

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,11 @@ end
17251725
@test Base.replace_in_print_matrix(Zeros(5,3), 1, 2, "0.0") == ""
17261726

17271727
# 2-arg show, compact printing
1728+
@test repr(Zeros{Int}()) == "Zeros{$Int}()"
1729+
@test repr(Zeros{Int}(3)) == "Zeros{$Int}(3)"
17281730
@test repr(Zeros(3)) == "Zeros(3)"
1731+
@test repr(Ones{Int}(3)) == "Ones{$Int}(3)"
1732+
@test repr(Ones{Int}(3,2)) == "Ones{$Int}(3, 2)"
17291733
@test repr(Ones(3,2)) == "Ones(3, 2)"
17301734
@test repr(Fill(7,3,2)) == "Fill(7, 3, 2)"
17311735
@test repr(Fill(1f0,10)) == "Fill(1.0f0, 10)" # Float32!

0 commit comments

Comments
 (0)