From f8ab175bc2256e8f3de76d56ffb63bc517b2d32d Mon Sep 17 00:00:00 2001 From: jishnub Date: Fri, 7 May 2021 13:18:49 +0400 Subject: [PATCH 1/2] compact show for SArray --- src/SArray.jl | 6 ++++++ test/SArray.jl | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/SArray.jl b/src/SArray.jl index 5e175079..5a03b3e1 100644 --- a/src/SArray.jl +++ b/src/SArray.jl @@ -283,3 +283,9 @@ end function promote_rule(::Type{<:SArray{S,T,N,L}}, ::Type{<:SArray{S,U,N,L}}) where {S,T,U,N,L} SArray{S,promote_type(T,U),N,L} end + +function Base.show(io::IO, S::SArray) + print(io, typeof(S), "(") + show(io, S.data) + print(io, ")") +end diff --git a/test/SArray.jl b/test/SArray.jl index f2d19fc9..f1dd6b2a 100644 --- a/test/SArray.jl +++ b/test/SArray.jl @@ -146,4 +146,17 @@ @test @inferred(promote_type(SVector{2,Int}, SVector{2,Float64})) === SVector{2,Float64} @test @inferred(promote_type(SMatrix{2,3,Float32,6}, SMatrix{2,3,Complex{Float64},6})) === SMatrix{2,3,Complex{Float64},6} end + + @testset "show" begin + io = IOBuffer() + S = SVector{2, Float64}(1.0, 2.0) + show(io, S) + S_str = String(take!(io)) + @test S_str == "SVector{2, Float64}((1.0, 2.0))" + + S = SMatrix{1, 2, Int, 2}(1, 2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "SMatrix{1, 2, $Int, 2}((1, 2))" + end end From 9be73ddcc31fe6088f24a081af71093507d28525 Mon Sep 17 00:00:00 2001 From: jishnub Date: Fri, 7 May 2021 13:34:59 +0400 Subject: [PATCH 2/2] compact show for MArray --- src/MArray.jl | 6 ++++++ src/SArray.jl | 2 +- test/MArray.jl | 14 ++++++++++++++ test/SArray.jl | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/MArray.jl b/src/MArray.jl index 9c928804..d473ab79 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -280,3 +280,9 @@ function Base.view( end Base.elsize(::Type{<:MArray{S,T}}) where {S,T} = sizeof(T) + +function Base.show(io::IO, S::MArray) + print(io, typeof(S), "(") + show(io, Tuple(S)) + print(io, ")") +end diff --git a/src/SArray.jl b/src/SArray.jl index 5a03b3e1..7d82180e 100644 --- a/src/SArray.jl +++ b/src/SArray.jl @@ -286,6 +286,6 @@ end function Base.show(io::IO, S::SArray) print(io, typeof(S), "(") - show(io, S.data) + show(io, Tuple(S)) print(io, ")") end diff --git a/test/MArray.jl b/test/MArray.jl index 3a5cf42d..fb995fe6 100644 --- a/test/MArray.jl +++ b/test/MArray.jl @@ -188,4 +188,18 @@ v[] = 2 @test v[] == 2 end + + @testset "show" begin + io = IOBuffer() + + S = MVector{2,Float64}(1,2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "MVector{2, Float64}((1.0, 2.0))" + + S = MMatrix{1, 2, Int, 2}(1, 2) + show(io, S) + S_str = String(take!(io)) + @test S_str == "MMatrix{1, 2, $Int, 2}((1, 2))" + end end diff --git a/test/SArray.jl b/test/SArray.jl index f1dd6b2a..5c315497 100644 --- a/test/SArray.jl +++ b/test/SArray.jl @@ -149,7 +149,7 @@ @testset "show" begin io = IOBuffer() - S = SVector{2, Float64}(1.0, 2.0) + S = SVector{2, Float64}(1, 2) show(io, S) S_str = String(take!(io)) @test S_str == "SVector{2, Float64}((1.0, 2.0))"