From cbaad4102d8ddf8cac80dd0331033a498343e72a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 6 Oct 2023 14:54:24 +0530 Subject: [PATCH 1/2] show for BandedMatrix may print the constructor --- Project.toml | 2 +- src/banded/BandedMatrix.jl | 12 ++++++++++++ test/test_miscs.jl | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 17249f8b..39fbe117 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BandedMatrices" uuid = "aae01518-5342-5314-be14-df237901396f" -version = "1.0.1" +version = "1.1.0" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/banded/BandedMatrix.jl b/src/banded/BandedMatrix.jl index 8a5f942b..d88178d9 100644 --- a/src/banded/BandedMatrix.jl +++ b/src/banded/BandedMatrix.jl @@ -956,3 +956,15 @@ function banded_axpy!(a::Number, X::BandedMatrix, Y::BandedMatrix) end return Y end + +# show +function show(io::IO, B::BandedMatrix) + print(io, "BandedMatrix(") + l, u = bandwidths(B) + for (ind, b) in enumerate(-l:u) + r = @view B[band(b)] + show(io, b => r) + b == u || print(io, ", ") + end + print(io, ")") +end diff --git a/test/test_miscs.jl b/test/test_miscs.jl index 32a596c9..101e4822 100644 --- a/test/test_miscs.jl +++ b/test/test_miscs.jl @@ -89,6 +89,9 @@ import BandedMatrices: _BandedMatrix, DefaultBandedMatrix @test occursin(needle, sprint() do io show(io, MIME"text/plain"(), BandedMatrix(Eye(3),(1,1))) end) + B = BandedMatrix(-1=>[1:10;], 0=>[1:11;], 1=>[1:10;]) + Bshowstr = sprint(show, B) + @test Bshowstr == "BandedMatrix($(-1=>[1:10;]), $(0=>[1:11;]), $(1=>[1:10;]))" end @time @testset "Issue #27" begin A=brand(1,10,0,9) From ab18601d32948e6bd366d10a697e33810e24a9d1 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 6 Oct 2023 14:58:12 +0530 Subject: [PATCH 2/2] fewer allocations in tests --- test/test_miscs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_miscs.jl b/test/test_miscs.jl index 101e4822..f52a0552 100644 --- a/test/test_miscs.jl +++ b/test/test_miscs.jl @@ -89,9 +89,9 @@ import BandedMatrices: _BandedMatrix, DefaultBandedMatrix @test occursin(needle, sprint() do io show(io, MIME"text/plain"(), BandedMatrix(Eye(3),(1,1))) end) - B = BandedMatrix(-1=>[1:10;], 0=>[1:11;], 1=>[1:10;]) + B = BandedMatrix(-1=>1:4, 0=>1:5, 1=>1:4) Bshowstr = sprint(show, B) - @test Bshowstr == "BandedMatrix($(-1=>[1:10;]), $(0=>[1:11;]), $(1=>[1:10;]))" + @test Bshowstr == "BandedMatrix($(-1=>[1:4;]), $(0=>[1:5;]), $(1=>[1:4;]))" end @time @testset "Issue #27" begin A=brand(1,10,0,9)