From 045cbe74d29ffe950adac15233781c8bebcefd90 Mon Sep 17 00:00:00 2001 From: alefcastelli Date: Wed, 23 Aug 2023 13:54:00 -0600 Subject: [PATCH 1/3] try new base.isempty --- src/PowerNetworkMatrix.jl | 2 +- src/virtual_lodf_calculations.jl | 8 ++++++++ src/virtual_ptdf_calculations.jl | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PowerNetworkMatrix.jl b/src/PowerNetworkMatrix.jl index c3e9b7d0..61c63b10 100644 --- a/src/PowerNetworkMatrix.jl +++ b/src/PowerNetworkMatrix.jl @@ -303,7 +303,7 @@ function Base.show_nd( end end -function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::PowerNetworkMatrix) +function Base.show(io::IO, array::PowerNetworkMatrix) summary(io, array) isempty(array) && return println(io, ":") diff --git a/src/virtual_lodf_calculations.jl b/src/virtual_lodf_calculations.jl index 2e29a67c..e4f6e5fd 100644 --- a/src/virtual_lodf_calculations.jl +++ b/src/virtual_lodf_calculations.jl @@ -54,6 +54,14 @@ struct VirtualLODF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64} tol::Base.RefValue{Float64} end +function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualLODF) + summary(io, array) + isempty(array) && return + println(io, ":") + Base.print_array(io, array) + return +end + function _get_PTDF_A_diag( K::KLU.KLUFactorization{Float64, Int}, BA::SparseArrays.SparseMatrixCSC{Float64, Int}, diff --git a/src/virtual_ptdf_calculations.jl b/src/virtual_ptdf_calculations.jl index 2ac60559..bf5e30f1 100644 --- a/src/virtual_ptdf_calculations.jl +++ b/src/virtual_ptdf_calculations.jl @@ -57,6 +57,14 @@ struct VirtualPTDF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64} tol::Base.RefValue{Float64} end +function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualPTDF) + summary(io, array) + isempty(array) && return + println(io, ":") + Base.print_array(io, array) + return +end + """ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF array indexed with the branch numbers. From 7a33ec8bf0240513e75962fef73d2dcf188081e7 Mon Sep 17 00:00:00 2001 From: alefcastelli Date: Thu, 24 Aug 2023 11:21:59 -0600 Subject: [PATCH 2/3] add tests for Base.show --- test/test_BA_ABA_matrix.jl | 22 ++++++++++++++++++++++ test/test_virtual_lodf.jl | 15 +++++++++++++++ test/test_virtual_ptdf.jl | 13 +++++++++++++ 3 files changed, 50 insertions(+) diff --git a/test/test_BA_ABA_matrix.jl b/test/test_BA_ABA_matrix.jl index a4d9a608..a8e7c99c 100644 --- a/test/test_BA_ABA_matrix.jl +++ b/test/test_BA_ABA_matrix.jl @@ -79,3 +79,25 @@ end end @test test_val end + +@testset "Test show for A, BA and ABA matrix" begin + sys = PSB.build_system(PSB.PSITestSystems, "c_sys5") + + a = IncidenceMatrix(sys) + ba = BA_Matrix(sys) + aba = ABA_Matrix(sys) + + for mat in [a, ba, aba] + test_value = false + try + show(@eval a); + test_value = true + catch err + if err isa Exception + test_value = false + end + end + @test test_value + end + +end \ No newline at end of file diff --git a/test/test_virtual_lodf.jl b/test/test_virtual_lodf.jl index c53e5cd8..ca6361bb 100644 --- a/test/test_virtual_lodf.jl +++ b/test/test_virtual_lodf.jl @@ -103,9 +103,11 @@ end @testset "Test Virtual LODF auxiliary functions" begin sys = PSB.build_system(PSB.PSITestSystems, "c_sys5") + # test isempty when VirtualLODF is created (cache must be empty) vlodf = VirtualLODF(sys) @test isempty(vlodf) == true + # test eachindex and axes @test length(eachindex(vlodf)) == length(axes(vlodf)[1]) * length(axes(vlodf)[2]) @@ -119,4 +121,17 @@ end end end @test test_value + + # test show + test_value = false + try + show(vlodf); + test_value = true + catch err + if err isa Exception + test_value = false + end + end + @test test_value + end diff --git a/test/test_virtual_ptdf.jl b/test/test_virtual_ptdf.jl index eb764f47..fdd0dc2c 100644 --- a/test/test_virtual_ptdf.jl +++ b/test/test_virtual_ptdf.jl @@ -177,4 +177,17 @@ end @test setdiff(PNM.get_branch_ax(vptdf), PSY.get_name.(PNM.get_ac_branches(sys))) == String[] @test setdiff(PNM.get_bus_ax(vptdf), PSY.get_number.(PNM.get_buses(sys))) == String[] + + # test show + test_value = false + try + show(vptdf); + test_value = true + catch err + if err isa Exception + test_value = false + end + end + @test test_value + end From bb4904b7cda6df0981c0022b93fad018afa837a2 Mon Sep 17 00:00:00 2001 From: alefcastelli Date: Thu, 24 Aug 2023 11:26:43 -0600 Subject: [PATCH 3/3] formatter --- test/test_BA_ABA_matrix.jl | 5 ++--- test/test_virtual_lodf.jl | 3 +-- test/test_virtual_ptdf.jl | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/test_BA_ABA_matrix.jl b/test/test_BA_ABA_matrix.jl index a8e7c99c..0ebdd801 100644 --- a/test/test_BA_ABA_matrix.jl +++ b/test/test_BA_ABA_matrix.jl @@ -90,7 +90,7 @@ end for mat in [a, ba, aba] test_value = false try - show(@eval a); + show(@eval a) test_value = true catch err if err isa Exception @@ -99,5 +99,4 @@ end end @test test_value end - -end \ No newline at end of file +end diff --git a/test/test_virtual_lodf.jl b/test/test_virtual_lodf.jl index ca6361bb..c5811f7e 100644 --- a/test/test_virtual_lodf.jl +++ b/test/test_virtual_lodf.jl @@ -125,7 +125,7 @@ end # test show test_value = false try - show(vlodf); + show(vlodf) test_value = true catch err if err isa Exception @@ -133,5 +133,4 @@ end end end @test test_value - end diff --git a/test/test_virtual_ptdf.jl b/test/test_virtual_ptdf.jl index fdd0dc2c..3ec4b509 100644 --- a/test/test_virtual_ptdf.jl +++ b/test/test_virtual_ptdf.jl @@ -181,7 +181,7 @@ end # test show test_value = false try - show(vptdf); + show(vptdf) test_value = true catch err if err isa Exception @@ -189,5 +189,4 @@ end end end @test test_value - end