Skip to content

Commit 5ef2961

Browse files
authored
Add Plotting (#91)
* Add Plotting * Add Poisson example with plotting * add tests
1 parent 4e03466 commit 5ef2961

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ContinuumArrays"
22
uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c"
3-
version = "0.7.2"
3+
version = "0.7.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -13,6 +13,7 @@ IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
1313
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
1414
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1515
QuasiArrays = "c4ea9172-b204-11e9-377d-29865faadc5c"
16+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1617
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1718

1819
[compat]
@@ -25,6 +26,7 @@ Infinities = "0.1"
2526
IntervalSets = "0.5"
2627
LazyArrays = "0.21"
2728
QuasiArrays = "0.5.1"
29+
RecipesBase = "1.0"
2830
StaticArrays = "0.12, 1"
2931
julia = "1.5"
3032

examples/poisson.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using ContinuumArrays, Plots
2+
3+
###
4+
# Dirichlet
5+
####
6+
7+
L = LinearSpline(range(0,1; length=10_000))[:,2:end-1]
8+
x = axes(L,1)
9+
D = Derivative(x)
10+
Δ = -((D*L)'D*L)
11+
M = L'L
12+
f = L \ exp.(x)
13+
u = L *\ (M*f))
14+
plot(u)
15+
16+
# we can also use cholesky
17+
= L * (cholesky(Symmetric(-Δ)) \ -(M*f))
18+
plot(ũ)

src/ContinuumArrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ContinuumArrays
2-
using IntervalSets, LinearAlgebra, LazyArrays, FillArrays, BandedMatrices, QuasiArrays, Infinities, InfiniteArrays, StaticArrays, BlockArrays
2+
using IntervalSets, LinearAlgebra, LazyArrays, FillArrays, BandedMatrices, QuasiArrays, Infinities, InfiniteArrays, StaticArrays, BlockArrays, RecipesBase
33
import Base: @_inline_meta, @_propagate_inbounds_meta, axes, getindex, convert, prod, *, /, \, +, -, ==, ^,
44
IndexStyle, IndexLinear, ==, OneTo, _maybetail, tail, similar, copyto!, copy, diff,
55
first, last, show, isempty, findfirst, findlast, findall, Slice, union, minimum, maximum, sum, _sum,
@@ -88,4 +88,6 @@ include("operators.jl")
8888
include("bases/bases.jl")
8989
include("basisconcat.jl")
9090

91+
include("plotting.jl")
92+
9193
end

src/bases/bases.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ copy(L::Ldiv{<:AbstractBasisLayout,BroadcastLayout{typeof(*)},<:Any,<:AbstractQu
122122

123123
# expansion
124124
_grid(_, P) = error("Overload Grid")
125+
_grid(lay::ApplyLayout{typeof(*)}, P) = grid(first(arguments(lay,P)))
125126
_grid(::MappedBasisLayout, P) = invmap(parentindices(P)[1])[grid(demap(P))]
126127
_grid(::SubBasisLayout, P) = grid(parent(P))
127128
_grid(::WeightedBasisLayouts, P) = grid(unweightedbasis(P))

src/plotting.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plotgrid(g) = grid(g)
2+
3+
@recipe function f(g::AbstractQuasiVector)
4+
x = plotgrid(g)
5+
x,g[x]
6+
end
7+
8+
@recipe function f(g::AbstractQuasiMatrix)
9+
x = plotgrid(g)
10+
x,g[x,:]
11+
end

test/runtests.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, FastTransforms, InfiniteArrays, Test, Base64
1+
using ContinuumArrays, QuasiArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, FastTransforms, InfiniteArrays, Test, Base64, RecipesBase
22
import ContinuumArrays: ℵ₁, materialize, AffineQuasiVector, BasisLayout, AdjointBasisLayout, SubBasisLayout, ℵ₁,
33
MappedBasisLayout, AdjointMappedBasisLayout, MappedWeightedBasisLayout, TransformFactorization, Weight, WeightedBasisLayout, SubWeightedBasisLayout, WeightLayout,
44
Expansion, basis, invmap, Map, checkpoints
@@ -596,3 +596,13 @@ ContinuumArrays.invmap(::InvQuadraticMap{T}) where T = QuadraticMap{T}()
596596
end
597597

598598
include("test_basisconcat.jl")
599+
600+
@testset "Plotting" begin
601+
L = LinearSpline(0:5)
602+
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), L)
603+
@test rep[1].args == (L.points,L[L.points,:])
604+
605+
u = L*randn(6)
606+
rep = RecipesBase.apply_recipe(Dict{Symbol, Any}(), u)
607+
@test rep[1].args == (L.points,u[L.points])
608+
end

0 commit comments

Comments
 (0)