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
Copy file name to clipboardExpand all lines: README.md
+22-14Lines changed: 22 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,16 +34,16 @@ flat vectors is fair game.
34
34
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.
35
35
```julia
36
36
julia> c = (a=2, b=[1, 2]);
37
-
37
+
38
38
julia> x =ComponentArray(a=5, b=[(a=20., b=0), (a=33., b=0), (a=44., b=3)], c=c)
39
39
ComponentVector{Float64}(a =5.0, b = [(a =20.0, b =0.0), (a =33.0, b =0.0), (a =44.0, b =3.0)], c = (a =2.0, b = [1.0, 2.0]))
40
-
40
+
41
41
julia> x.c.a =400; x
42
42
ComponentVector{Float64}(a =5.0, b = [(a =20.0, b =0.0), (a =33.0, b =0.0), (a =44.0, b =3.0)], c = (a =400.0, b = [1.0, 2.0]))
`ComponentArray`s can be constructed from existing
64
+
`ComponentArray`s (currently nested fields cannot be changed this way):
65
+
```julia
66
+
julia> x =ComponentVector(a=1, b=2, c=3);
67
+
68
+
julia>ComponentVector(x; a=11, new=42)
69
+
ComponentVector{Int64}(a =11, b =2, c =3, new =42)
70
+
```
63
71
64
72
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.
65
73
```julia
@@ -75,16 +83,16 @@ julia> x2 = x .* x'
75
83
2.04.02.08.04.02.04.0
76
84
1.02.01.04.02.01.02.0
77
85
2.04.02.08.04.02.04.0
78
-
86
+
79
87
julia> x2[:c,:c]
80
88
3×3 ComponentMatrix{Float64,SubArray...} with axes Axis(a =1, b =2:3) ×Axis(a =1, b =2:3)
81
89
4.02.04.0
82
90
2.01.02.0
83
91
4.02.04.0
84
-
92
+
85
93
julia> x2[:a,:a]
86
94
1.0
87
-
95
+
88
96
julia> x2[:a,:c]
89
97
ComponentVector{Float64,SubArray...}(a =2.0, b = [1.0, 2.0])
Copy file name to clipboardExpand all lines: docs/src/quickstart.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,16 +4,16 @@
4
4
The easiest way to construct 1-dimensional ```ComponentArray```s 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.
5
5
```julia
6
6
julia> c = (a=2, b=[1, 2]);
7
-
7
+
8
8
julia> x =ComponentArray(a=1.0, b=[2, 1, 4], c=c)
9
9
ComponentVector{Float64}(a =1.0, b = [2.0, 1.0, 4.0], c = (a =2.0, b = [1.0, 2.0]))
10
-
10
+
11
11
julia> x.c.a =400; x
12
12
ComponentVector{Float64}(a =1.0, b = [2.0, 1.0, 4.0], c = (a =400.0, b = [1.0, 2.0]))
`ComponentArray`s can be constructed from existing
31
+
`ComponentArray`s (currently nested fields cannot be changed this way):
32
+
```julia
33
+
julia> x =ComponentVector(a=1, b=2, c=3);
34
+
35
+
julia>ComponentVector(x; a=11, new=42)
36
+
ComponentVector{Int64}(a =11, b =2, c =3, new =42)
37
+
```
30
38
31
39
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 ```ComponentArray```s 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.
32
40
```julia
@@ -39,16 +47,16 @@ julia> x2 = x .* x'
39
47
400.0800.0400.01600.0160000.0400.0800.0
40
48
1.02.01.04.0400.01.02.0
41
49
2.04.02.08.0800.02.04.0
42
-
50
+
43
51
julia> x2[:c,:c]
44
52
3×3 ComponentMatrix{Float64,SubArray...} with axes Axis(a =1, b =2:3) ×Axis(a =1, b =2:3)
45
53
160000.0400.0800.0
46
54
400.01.02.0
47
55
800.02.04.0
48
-
56
+
49
57
julia> x2[:a,:a]
50
58
1.0
51
-
59
+
52
60
julia> x2[:a,:c]
53
61
ComponentVector{Float64,SubArray...}(a =400.0, b = [1.0, 2.0])
0 commit comments