From 43da4f609329443c471540f53cdc7b097fc3de6e Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 4 May 2021 23:00:51 -0400 Subject: [PATCH 1/9] short form printing --- src/FillArrays.jl | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index d2d678ad..96eb657a 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -618,9 +618,26 @@ Base.print_matrix_row(io::IO, # Display concise description of a Fill. +function Base.show(io::IO, ::MIME"text/plain", x::AbstractFill) + if get(IOContext(io), :compact, false) # for example [Fill(i==j,2,2) for i in 1:3, j in 1:4] + return show(io, x) + end + summary(io, x) + if x isa Union{Zeros,Ones} + elseif length(x) > 1 + print(io, ", with entries equal to ", getindex_value(x)) + else + print(io, ", with entry equal to ", getindex_value(x)) + end +end -Base.show(io::IO, x::AbstractFill) = print(io, "$(summary(x)): entries equal to $(getindex_value(x))") -Base.show(io::IO, x::Union{Zeros,Ones,Eye}) = print(io, "$(summary(x))") +function Base.show(io::IO, x::AbstractFill) # for example (Fill(π,3),) + print(io, nameof(typeof(x)), "(") + x isa Union{Zeros,Ones} || print(io, getindex_value(x), ", ") + join(io, size(x), ", ") + print(io, ")") +end +Base.show(io::IO, x::Eye) = print(io, "Eye(", size(x,1), ")") if VERSION ≥ v"1.5" Base.array_summary(io::IO, ::Zeros{T}, inds::Tuple{Vararg{Base.OneTo}}) where T = @@ -633,13 +650,12 @@ if VERSION ≥ v"1.5" print(io, Base.dims2string(length.(inds)), " Eye{$T}") end -Base.show(io::IO, ::MIME"text/plain", x::Union{Eye,AbstractFill}) = show(io, x) ## # interface ## -getindex_value(a::LinearAlgebra.AdjOrTrans) = getindex_value(parent(a)) +getindex_value(a::LinearAlgebra.AdjOrTrans) = getindex_value(parent(a)) # FillArrays.getindex_value(Adjoint(Fill(1+im,2,2))) getindex_value(a::SubArray) = getindex_value(parent(a)) From dd48f477cfd74cb29b427384857f5ba235faaf30 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 4 May 2021 23:44:28 -0400 Subject: [PATCH 2/9] tests --- src/FillArrays.jl | 7 ++++--- test/runtests.jl | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 96eb657a..4082084c 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -618,12 +618,13 @@ Base.print_matrix_row(io::IO, # Display concise description of a Fill. -function Base.show(io::IO, ::MIME"text/plain", x::AbstractFill) +function Base.show(io::IO, ::MIME"text/plain", x::Union{Eye, AbstractFill}) if get(IOContext(io), :compact, false) # for example [Fill(i==j,2,2) for i in 1:3, j in 1:4] return show(io, x) end summary(io, x) - if x isa Union{Zeros,Ones} + if x isa Union{Zeros, Ones, Eye} + # then no need to print entries elseif length(x) > 1 print(io, ", with entries equal to ", getindex_value(x)) else @@ -633,7 +634,7 @@ end function Base.show(io::IO, x::AbstractFill) # for example (Fill(π,3),) print(io, nameof(typeof(x)), "(") - x isa Union{Zeros,Ones} || print(io, getindex_value(x), ", ") + x isa Union{Zeros, Ones} || print(io, getindex_value(x), ", ") join(io, size(x), ", ") print(io, ")") end diff --git a/test/runtests.jl b/test/runtests.jl index e3c69d24..cd1e309c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1132,16 +1132,21 @@ end @test_throws DimensionMismatch dot(u, Z, v[1:end-1]) end -if VERSION ≥ v"1.5" - @testset "print" begin +@testset "print" begin + if VERSION ≥ v"1.5" @test stringmime("text/plain", Zeros(3)) == "3-element Zeros{Float64}" @test stringmime("text/plain", Ones(3)) == "3-element Ones{Float64}" - @test stringmime("text/plain", Fill(7,2)) == "2-element Fill{$Int}: entries equal to 7" + @test stringmime("text/plain", Fill(7,2)) == "2-element Fill{$Int}, with entries equal to 7" @test stringmime("text/plain", Zeros(3,2)) == "3×2 Zeros{Float64}" @test stringmime("text/plain", Ones(3,2)) == "3×2 Ones{Float64}" - @test stringmime("text/plain", Fill(7,2,3)) == "2×3 Fill{$Int}: entries equal to 7" + @test stringmime("text/plain", Fill(7,2,3)) == "2×3 Fill{$Int}, with entries equal to 7" + @test stringmime("text/plain", Fill(8.0,1)) == "1-element Fill{Float64}, with entry equal to 8.0" @test stringmime("text/plain", Eye(5)) == "5×5 Eye{Float64}" end + @test repr(Zeros(3)) == "Zeros(3)" + @test repr(Ones(3,2)) == "Ones(3, 2)" + @test repr(Fill(7,3,2)) == "Fill(7, 3, 2)" + @test repr(Eye(9)) == "Eye(9)" end @testset "reshape" begin From a04e7d91130c6f2343ec1955f12b4cc2322ee1a0 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 5 May 2021 00:11:15 -0400 Subject: [PATCH 3/9] print Float32 visibly --- src/FillArrays.jl | 6 +++++- test/runtests.jl | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 4082084c..e3e11bce 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -634,7 +634,11 @@ end function Base.show(io::IO, x::AbstractFill) # for example (Fill(π,3),) print(io, nameof(typeof(x)), "(") - x isa Union{Zeros, Ones} || print(io, getindex_value(x), ", ") + if x isa Union{Zeros, Ones} + else + show(io, getindex_value(x)) # show not print to handle (Fill(1f0,2),) + print(io, ", ") + end join(io, size(x), ", ") print(io, ")") end diff --git a/test/runtests.jl b/test/runtests.jl index cd1e309c..7011032e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1146,6 +1146,7 @@ end @test repr(Zeros(3)) == "Zeros(3)" @test repr(Ones(3,2)) == "Ones(3, 2)" @test repr(Fill(7,3,2)) == "Fill(7, 3, 2)" + @test repr(Fill(1f0,10)) == "Fill(1.0f0, 10)" # Float32! @test repr(Eye(9)) == "Eye(9)" end From 639d4dfe7ec147c64598103d0250253c999fe148 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 5 May 2021 08:44:56 -0400 Subject: [PATCH 4/9] test array of arrays printing --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 7011032e..63c77bdc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1134,6 +1134,7 @@ end @testset "print" begin if VERSION ≥ v"1.5" + # 3-arg show, full printing @test stringmime("text/plain", Zeros(3)) == "3-element Zeros{Float64}" @test stringmime("text/plain", Ones(3)) == "3-element Ones{Float64}" @test stringmime("text/plain", Fill(7,2)) == "2-element Fill{$Int}, with entries equal to 7" @@ -1143,11 +1144,14 @@ end @test stringmime("text/plain", Fill(8.0,1)) == "1-element Fill{Float64}, with entry equal to 8.0" @test stringmime("text/plain", Eye(5)) == "5×5 Eye{Float64}" end + # 2-arg show, compact printing @test repr(Zeros(3)) == "Zeros(3)" @test repr(Ones(3,2)) == "Ones(3, 2)" @test repr(Fill(7,3,2)) == "Fill(7, 3, 2)" @test repr(Fill(1f0,10)) == "Fill(1.0f0, 10)" # Float32! @test repr(Eye(9)) == "Eye(9)" + # also used for arrays of arrays: + @test contains(stringmime("text/plain", [Eye(2) for i in 1:2, j in 1:2]), "Eye(2) ") end @testset "reshape" begin From d170312db9684d738b0d1116e017537e390f52ac Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 5 May 2021 12:07:18 -0400 Subject: [PATCH 5/9] aside, fix getindex_value(::Adjoint) --- src/FillArrays.jl | 3 ++- test/runtests.jl | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index e3e11bce..a54de9c8 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -660,7 +660,8 @@ end # interface ## -getindex_value(a::LinearAlgebra.AdjOrTrans) = getindex_value(parent(a)) # FillArrays.getindex_value(Adjoint(Fill(1+im,2,2))) +getindex_value(a::LinearAlgebra.Adjoint) = adjoint(getindex_value(parent(a))) +getindex_value(a::LinearAlgebra.Transpose) = transpose(getindex_value(parent(a))) getindex_value(a::SubArray) = getindex_value(parent(a)) diff --git a/test/runtests.jl b/test/runtests.jl index 63c77bdc..95598397 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1241,10 +1241,10 @@ end end @testset "adjtrans" begin - a = Fill(2.0,5) - @test FillArrays.getindex_value(a') == FillArrays.unique_value(a') == 2.0 - @test convert(Fill, a') ≡ Fill(2.0,1,5) - @test FillArrays.getindex_value(transpose(a)) == FillArrays.unique_value(transpose(a)) == 2.0 - @test convert(Fill, transpose(a)) ≡ Fill(2.0,1,5) + a = Fill(2.0+im, 5) + @test FillArrays.getindex_value(a') == FillArrays.unique_value(a') == 2.0 - im + @test convert(Fill, a') ≡ Fill(2.0-im,1,5) + @test FillArrays.getindex_value(transpose(a)) == FillArrays.unique_value(transpose(a)) == 2.0 + im + @test convert(Fill, transpose(a)) ≡ Fill(2.0+im,1,5) end end From e866494cecf134d63081ed70e3c018e1501dac9c Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 5 May 2021 14:07:06 -0400 Subject: [PATCH 6/9] avoid contains for Julia 1.0 --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 95598397..bf8e76c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1151,7 +1151,7 @@ end @test repr(Fill(1f0,10)) == "Fill(1.0f0, 10)" # Float32! @test repr(Eye(9)) == "Eye(9)" # also used for arrays of arrays: - @test contains(stringmime("text/plain", [Eye(2) for i in 1:2, j in 1:2]), "Eye(2) ") + @test occursin("Eye(2) ", stringmime("text/plain", [Eye(2) for i in 1:2, j in 1:2])) end @testset "reshape" begin From 257a94a371d3b0b968dc8f554ac2e70abce6e72a Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 5 May 2021 16:43:32 -0400 Subject: [PATCH 7/9] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 40adb5a8..7cb512c3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.11.7" +version = "0.11.8" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 602f640cd0ed38a8ca6df45e9b117fb5d638ebc3 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sat, 8 May 2021 16:40:28 -0400 Subject: [PATCH 8/9] tweak for zero-dim case --- src/FillArrays.jl | 2 +- test/runtests.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index a54de9c8..52cc86fa 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -637,7 +637,7 @@ function Base.show(io::IO, x::AbstractFill) # for example (Fill(π,3),) if x isa Union{Zeros, Ones} else show(io, getindex_value(x)) # show not print to handle (Fill(1f0,2),) - print(io, ", ") + ndims(x) > 0 && print(io, ", ") end join(io, size(x), ", ") print(io, ")") diff --git a/test/runtests.jl b/test/runtests.jl index bf8e76c8..836d1ddf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1149,6 +1149,7 @@ end @test repr(Ones(3,2)) == "Ones(3, 2)" @test repr(Fill(7,3,2)) == "Fill(7, 3, 2)" @test repr(Fill(1f0,10)) == "Fill(1.0f0, 10)" # Float32! + @test repr(Fill(0)) == "Fill(0)" @test repr(Eye(9)) == "Eye(9)" # also used for arrays of arrays: @test occursin("Eye(2) ", stringmime("text/plain", [Eye(2) for i in 1:2, j in 1:2])) From 3b3ecbdf216cd877e7ca5f0f0d885cde6791f11a Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 4 Jul 2021 09:50:12 -0400 Subject: [PATCH 9/9] v0.12 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 581bb28a..ca0e54f0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.11.10" +version = "0.12.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"