Skip to content

Commit 672e44d

Browse files
good show of VectorOfArray
1 parent c55b174 commit 672e44d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/RecursiveArrayTools.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ module RecursiveArrayTools
55
using Compat, Juno, RecipesBase, StaticArrays
66

77
@compat abstract type AbstractVectorOfArray{T, N} <: AbstractArray{T, N} end
8+
@compat abstract type AbstractDiffEqArray{T, N} <: AbstractVectorOfArray{T, N} end
89

910
include("utils.jl")
1011
include("vector_of_array.jl")
1112
include("array_partition.jl")
1213

13-
export VectorOfArray, DiffEqArray, AbstractVectorOfArray, vecarr_to_arr,
14-
vecarr_to_vectors, tuples
14+
export VectorOfArray, DiffEqArray, AbstractVectorOfArray, AbstractDiffEqArray,
15+
vecarr_to_arr, vecarr_to_vectors, tuples
1516

1617
export recursivecopy, recursivecopy!, vecvecapply, copyat_or_push!,
1718
vecvec_to_mat, recursive_one, recursive_mean, recursive_eltype

src/array_partition.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ Juno.@render Juno.Inline x::ArrayPartition begin
9696
Juno.LazyTree(typeof(x), () -> [Juno.SubTree(Juno.Text("$f"), Juno.getfield′(x, f)) for f in fields])
9797
end
9898
Base.summary(A::ArrayPartition) = string(typeof(A), " with arrays:")
99-
Base.show(M::MIME"text/plain",A::ArrayPartition) = (Base.showarray.(A.x); nothing)
10099
Base.show(A::ArrayPartition) = (Base.show.(A.x); nothing)
101100
Base.display(A::ArrayPartition) = (println(summary(A));display.(A.x);nothing)
102101
Base.print(A::ArrayPartition) = show(A)

src/vector_of_array.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N}
33
u::A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
44
end
55
# VectorOfArray with an added series for time
6-
type DiffEqArray{T, N, A, B} <: AbstractVectorOfArray{T, N}
6+
type DiffEqArray{T, N, A, B} <: AbstractDiffEqArray{T, N}
77
u::A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
88
t::B
99
end
@@ -58,6 +58,14 @@ vecarr_to_vectors(VA::AbstractVectorOfArray) = [VA[i,:] for i in eachindex(VA[1]
5858
# make it show just like its data
5959
Base.show(io::IO, x::AbstractVectorOfArray) = show(io, x.u)
6060
Base.show(io::IO, m::MIME"text/plain", x::AbstractVectorOfArray) = show(io, m, x.u)
61+
Base.summary(A::AbstractVectorOfArray) = string("VectorOfArray{",eltype(A),",",ndims(A),"}")
62+
Base.display(A::AbstractVectorOfArray) = (println(summary(A));println("u:");display(A.u);nothing)
63+
Base.print(A::AbstractVectorOfArray) = show(A)
64+
Base.println(A::AbstractVectorOfArray) = show(A)
65+
66+
Base.show(io::IO, x::AbstractDiffEqArray) = (print(io,"t: ");show(io, x.t);println(io);print(io,"u: ");show(io, x.u))
67+
Base.show(io::IO, m::MIME"text/plain", x::AbstractDiffEqArray) = (print(io,"t: ");show(io,m,x.t);println(io);print(io,"u: ");show(io,m,x.u))
68+
Base.display(A::AbstractDiffEqArray) = (println(summary(A));println("t:");display(A.t);println("u:");display(A.u);nothing)
6169

6270
# restore the type rendering in Juno
6371
Juno.@render Juno.Inline x::AbstractVectorOfArray begin
@@ -69,7 +77,7 @@ end
6977
@recipe function f(VA::AbstractVectorOfArray)
7078
vecarr_to_vectors(VA)
7179
end
72-
@recipe function f(VA::DiffEqArray)
80+
@recipe function f(VA::AbstractDiffEqArray)
7381
A = vecarr_to_vectors(VA)
7482
VA.t,A
7583
end

test/basic_indexing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
using RecursiveArrayTools
12

23
# Example Problem
34
recs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
45
testa = cat(2, recs...)
56
testva = VectorOfArray(recs)
7+
t = [1,2,3]
8+
diffeq = DiffEqArray(recs,t)
9+
610
testa[1:2, 1:2] == [1 4; 2 5]
711
testva[1:2, 1:2] == [1 4; 2 5]
812
testa[1:2, 1:2] == [1 4; 2 5]

0 commit comments

Comments
 (0)