From 495ab9a6f4694a35bbdc63cd3ecc1081924e12b9 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Thu, 31 Oct 2024 22:50:48 +0000 Subject: [PATCH 1/3] quasivector plot --- Project.toml | 4 +++- ext/QuasiArraysRecipesBaseExt.jl | 7 +++++++ src/QuasiArrays.jl | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 ext/QuasiArraysRecipesBaseExt.jl diff --git a/Project.toml b/Project.toml index 99b9efe..523c442 100644 --- a/Project.toml +++ b/Project.toml @@ -13,17 +13,19 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" [weakdeps] +RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [extensions] +QuasiArraysRecipesBaseExt = "RecipesBase" QuasiArraysSparseArraysExt = "SparseArrays" - [compat] ArrayLayouts = "1" DomainSets = "0.7.6" FillArrays = "1" LazyArrays = "1.2, 2" +RecipesBase = "1.0" StaticArrays = "1" julia = "1.6" diff --git a/ext/QuasiArraysRecipesBaseExt.jl b/ext/QuasiArraysRecipesBaseExt.jl new file mode 100644 index 0000000..a0640f3 --- /dev/null +++ b/ext/QuasiArraysRecipesBaseExt.jl @@ -0,0 +1,7 @@ +module QuasiArraysRecipesBaseExt + +using RecipesBase, QuasiArrays + +@recipe f(v::QuasiVector) = v.axes[1], v.parent + +end # module \ No newline at end of file diff --git a/src/QuasiArrays.jl b/src/QuasiArrays.jl index 6d89998..c48e380 100644 --- a/src/QuasiArrays.jl +++ b/src/QuasiArrays.jl @@ -130,5 +130,4 @@ if !isdefined(Base, :get_extension) include("../ext/QuasiArraysSparseArraysExt.jl") end - end From 4b22d728e48674179f815cc880a2f983b397de34 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Fri, 15 Nov 2024 16:41:44 +0000 Subject: [PATCH 2/3] add tests --- Project.toml | 4 +++- test/runtests.jl | 3 ++- test/test_plots.jl | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/test_plots.jl diff --git a/Project.toml b/Project.toml index 523c442..fc8f963 100644 --- a/Project.toml +++ b/Project.toml @@ -26,15 +26,17 @@ DomainSets = "0.7.6" FillArrays = "1" LazyArrays = "1.2, 2" RecipesBase = "1.0" +Plots = "1" StaticArrays = "1" julia = "1.6" [extras] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Base64", "IntervalSets", "Random", "SparseArrays", "Test"] +test = ["Base64", "IntervalSets", "Plots", "Random", "SparseArrays", "Test"] diff --git a/test/runtests.jl b/test/runtests.jl index 3ecfe1c..1b5482a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using QuasiArrays, Test +include("test_plots.jl") include("test_abstractquasiarray.jl") include("test_quasibroadcast.jl") @@ -21,4 +22,4 @@ include("test_quasikron.jl") include("test_ldiv.jl") include("test_quasilazy.jl") -include("test_sparsequasi.jl") \ No newline at end of file +include("test_sparsequasi.jl") diff --git a/test/test_plots.jl b/test/test_plots.jl new file mode 100644 index 0000000..a8dacce --- /dev/null +++ b/test/test_plots.jl @@ -0,0 +1,18 @@ +using Plots + +function struct_isequal(a,b) + fa = fieldnames(typeof(a)) + fb = fieldnames(typeof(b)) + fa != fb && return false + for f in fa + !struct_isequal(getfield(a,f),getfield(b,f)) && return false + end + return true +end + +@testset "plots" begin + v = QuasiVector(rand(5), rand(5)) + a = plot(v) + b = plot(axes(v,1),parent(v)) + @test struct_isequal(a,b) +end From f2d3a4e77bfa0e0eecb425ba5874b64da854a812 Mon Sep 17 00:00:00 2001 From: Tianyi Pu <912396513@qq.com> Date: Fri, 15 Nov 2024 17:26:18 +0000 Subject: [PATCH 3/3] fix --- ext/QuasiArraysRecipesBaseExt.jl | 1 + test/test_plots.jl | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/QuasiArraysRecipesBaseExt.jl b/ext/QuasiArraysRecipesBaseExt.jl index a0640f3..b77586c 100644 --- a/ext/QuasiArraysRecipesBaseExt.jl +++ b/ext/QuasiArraysRecipesBaseExt.jl @@ -2,6 +2,7 @@ module QuasiArraysRecipesBaseExt using RecipesBase, QuasiArrays +@recipe f(v::Inclusion{<:Any,<:AbstractVector}) = (v.domain,) @recipe f(v::QuasiVector) = v.axes[1], v.parent end # module \ No newline at end of file diff --git a/test/test_plots.jl b/test/test_plots.jl index a8dacce..7038b00 100644 --- a/test/test_plots.jl +++ b/test/test_plots.jl @@ -11,8 +11,14 @@ function struct_isequal(a,b) end @testset "plots" begin + # QuasiVector v = QuasiVector(rand(5), rand(5)) a = plot(v) - b = plot(axes(v,1),parent(v)) + b = plot(v.axes[1],parent(v)) + @test struct_isequal(a,b) + + # Inclusion + a = plot(axes(v,1)) + b = plot(v.axes[1]) @test struct_isequal(a,b) end