You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notes on new features (minor releases). For more details on bugfixes and non-feature-adding changes (patch releases), check out the [releases page](https://github.com/jonniedie/ComponentArrays.jl/releases).
5
+
6
+
### v0.7.0
7
+
- Much faster (and lazier) arrays of subcomponents!
ComponentVector{Int64}(a =5, b = [1, 2], c = [00; 00], d = (a =2, b =10))
56
-
```
57
-
58
-
### v0.4.0
59
-
- Zygote rules for DiffEqFlux support! Check out [the docs](https://jonniedie.github.io/ComponentArrays.jl/dev/examples/DiffEqFlux/) for an example!
60
-
61
-
### v0.3.0
62
-
- Matrix and higher-dimensional array components!
63
-
64
-
...and plenty more!
30
+
See the [NEWS page](https://github.com/jonniedie/ComponentArrays.jl/blob/master/NEWS.md) for new features!
65
31
66
32
## General use
67
33
The easiest way to construct 1-dimensional ```ComponentArray```s (aliased as `ComponentVector`) is as if they were ```NamedTuple```s. In fact, a good way to think about them is as arbitrarily nested, mutable ```NamedTuple```s that can be passed through a solver.
@@ -96,11 +62,11 @@ true
96
62
97
63
Higher dimensional ```ComponentArray```s can be created too, but it's a little messy at the moment. The nice thing for modeling is that dimension expansion through broadcasted operations can create higher-dimensional ```ComponentArray```s automatically, so Jacobian cache arrays that are created internally with ```false .* x .* x'``` will be two-dimensional ```ComponentArray```s (aliased as `ComponentMatrix`) with proper axes. Check out the [ODE with Jacobian](https://github.com/jonniedie/ComponentArrays.jl/blob/master/examples/ODE_jac_example.jl) example in the examples folder to see how this looks in practice.
98
64
```julia
99
-
julia> x =ComponentArray(a=1, b=[2, 1, 4], c=c)
65
+
julia> x =ComponentArray(a=1, b=[2, 1, 4.0], c=c)
100
66
ComponentVector{Float64}(a =1.0, b = [2.0, 1.0, 4.0], c = (a =2.0, b = [1.0, 2.0]))
101
67
102
68
julia> x2 = x .* x'
103
-
7×7ComponentArray{Tuple{Axis{(a =1, b =2:4, c = (5:7, (a =1, b =2:3)))},Axis{(a =1, b =2:4, c = (5:7, (a =1, b =2:3)))}},Float64,2,Array{Float64,2}}:
69
+
7×7ComponentMatrix{Float64} with axes Axis(a =1, b =2:4, c =ViewAxis(5:7, Axis(a =1, b =2:3)))×Axis(a =1, b =2:4, c =ViewAxis(5:7, Axis(a =1, b =2:3)))
104
70
1.02.01.04.02.01.02.0
105
71
2.04.02.08.04.02.04.0
106
72
1.02.01.04.02.01.02.0
@@ -110,7 +76,7 @@ julia> x2 = x .* x'
110
76
2.04.02.08.04.02.04.0
111
77
112
78
julia> x2[:c,:c]
113
-
3×3ComponentArray{Tuple{Axis{(a =1, b =2:3)},Axis{(a =1, b =2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
79
+
3×3ComponentMatrix{Float64,SubArray...} with axes Axis(a =1, b =2:3)×Axis(a =1, b =2:3)
114
80
4.02.04.0
115
81
2.01.02.0
116
82
4.02.04.0
@@ -119,10 +85,10 @@ julia> x2[:a,:a]
119
85
1.0
120
86
121
87
julia> x2[:a,:c]
122
-
ComponentVector{Float64}(a =2.0, b = [1.0, 2.0])
88
+
ComponentVector{Float64,SubArray...}(a =2.0, b = [1.0, 2.0])
123
89
124
90
julia> x2[:b,:c]
125
-
3×3ComponentArray{Tuple{Axis{NamedTuple()},Axis{(a =1, b =2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
91
+
3×3ComponentMatrix{Float64,SubArray...} with axes FlatAxis() ×Axis(a =1, b =2:3)
Base.show(io::IO, ::MIME"text/plain", ::Type{ComponentArray{T,N,A,Ax}}) where {T,N,A,Ax} =print(io, "ComponentArray{$T,$N,$A,$Ax}") # make `typeof(u)` show the full type
29
-
Base.show(io::IO, ::Type{<:ComponentArray{T, N}}) where {T, N} =print(io, "ComponentArray{$T, $N}") # do not pollute the stacktrace with verbose type printing
30
-
Base.show(io::IO, ::Type{<:ComponentArray{T, 1}}) where T =print(io, "ComponentVector{$T}")
31
-
Base.show(io::IO, ::Type{<:ComponentArray{T, 2}}) where T =print(io, "ComponentMatrix{$T}")
29
+
Base.show(io::IO, ::Type{<:ComponentArray{T,N,<:Array}}) where {T,N} =print(io, "ComponentArray{$T,$N}") # do not pollute the stacktrace with verbose type printing
30
+
Base.show(io::IO, ::Type{<:ComponentArray{T,1,<:Array}}) where T =print(io, "ComponentVector{$T}")
31
+
Base.show(io::IO, ::Type{<:ComponentArray{T,2,<:Array}}) where T =print(io, "ComponentMatrix{$T}")
32
+
Base.show(io::IO, ::Type{<:ComponentArray{T,N,A}}) where {T,N,A} =print(io, "ComponentArray{$T,$N,$(A.name)...}")
33
+
Base.show(io::IO, ::Type{<:ComponentArray{T,1,A}}) where {T,A} =print(io, "ComponentVector{$T,$(A.name)...}")
34
+
Base.show(io::IO, ::Type{<:ComponentArray{T,2,A}}) where {T,A} =print(io, "ComponentMatrix{$T,$(A.name)...}")
35
+
32
36
function Base.show(io::IO, x::ComponentVector)
33
37
print(io, "(")
34
38
for (i,key) inenumerate(keys(x))
@@ -42,16 +46,13 @@ function Base.show(io::IO, x::ComponentVector)
42
46
print(io, ")")
43
47
returnnothing
44
48
end
45
-
function Base.show(io::IO, ::MIME"text/plain", x::ComponentVector{T,A,Axes}) where {A<:Vector{T},Axes} where T
46
-
print(io, "ComponentVector{" , T, "}")
47
-
show(io, x)
48
-
returnnothing
49
-
end
50
-
function Base.show(io::IO, ::MIME"text/plain", x::ComponentVector{T,A,Axes}) where {T,A,Axes}
51
-
print(io, "ComponentVector{" , A, "}")
49
+
50
+
function Base.show(io::IO, ::MIME"text/plain", x::ComponentVector)
51
+
show(io, typeof(x))
52
52
show(io, x)
53
53
returnnothing
54
54
end
55
+
55
56
function Base.show(io::IO, a::AbstractVector{<:T}) where T<:ComponentVector
56
57
elem = a[1]
57
58
print(io, "[$elem")
@@ -62,22 +63,13 @@ function Base.show(io::IO, a::AbstractVector{<:T}) where T<:ComponentVector
62
63
returnnothing
63
64
end
64
65
65
-
66
-
function Base.show(io::IO, ::MIME"text/plain", x::ComponentMatrix{T,A,Axes}) where {A<:Matrix{T},Axes} where T
67
-
if!haskey(io, :compact) &&length(axes(x, 2)) >1
68
-
io =IOContext(io, :compact=>true)
69
-
end
70
-
axs =indexmap.(getaxes(x))
71
-
println(io, "ComponentMatrix{" , T, "} with axes $(axs[1]) × $(axs[2])")
72
-
Base.print_matrix(io, getdata(x))
73
-
returnnothing
74
-
end
75
66
function Base.show(io::IO, ::MIME"text/plain", x::ComponentMatrix{T,A,Axes}) where {T,A,Axes}
76
67
if!haskey(io, :compact) &&length(axes(x, 2)) >1
77
68
io =IOContext(io, :compact=>true)
78
69
end
79
-
axs =indexmap.(getaxes(x))
80
-
println(io, "ComponentMatrix{" , A, "} with axes $(axs[1]) × $(axs[2])")
70
+
axs =getaxes(x)
71
+
sz =size(x)
72
+
println(io, "$(sz[1])×$(sz[2])$(typeof(x)) with axes $(axs[1]) × $(axs[2])")
0 commit comments