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: NEWS.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,23 @@
1
1
# ComponentArrays.jl NEWS
2
2
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).
3
3
4
+
### v0.12.0
5
+
- Multiple symbol indexing!
6
+
- Use either an `Array` or `Tuple` of `Symbol`s to extract multiple named components into a new `ComponentArray
7
+
- It's fast!
8
+
```julia
9
+
julia> ca =ComponentArray(a=5, b=[4, 1], c=(a=2, b=[6, 30.0]))
10
+
ComponentVector{Float64}(a =5.0, b = [4.0, 1.0], c = (a =2.0, b = [6.0, 30.0]))
11
+
12
+
julia> ca[(:c, :a)]
13
+
ComponentVector{Float64}(c = (a =2.0, b = [6.0, 30.0]), a =5.0)
4
14
15
+
julia> ca[[:c, :a]] == ca[(:c, :a)]
16
+
true
17
+
18
+
julia>@view ca[(:c, :a)]
19
+
ComponentVector{Float64,SubArray...}(c = (a =2.0, b = [6.0, 30.0]), a =5.0)
20
+
```
5
21
### v0.11.0
6
22
- Calling `axes` on a `ComponentArray` returns a new `CombinedAxis` type!
Copy file name to clipboardExpand all lines: docs/src/indexing_behavior.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,26 @@ julia> ca
37
37
ComponentVector{Int64}(a =0, b = [0, 1])
38
38
```
39
39
40
+
## Indexing with multiple symbols
41
+
It is often useful to create a new `ComponentArray` with only select fields of an old one. For this reason, `ComponentArray`s can be indexed with multiple symbolic names:
42
+
```julia
43
+
julia> ca =ComponentArray(a=5, b=[4, 1], c=(a=2, b=[6, 30.0]))
44
+
ComponentVector{Float64}(a =5.0, b = [4.0, 1.0], c = (a =2.0, b = [6.0, 30.0]))
45
+
46
+
julia> ca[(:c, :a)]
47
+
ComponentVector{Float64}(c = (a =2.0, b = [6.0, 30.0]), a =5.0)
48
+
49
+
julia>@view ca[(:c, :a)]
50
+
ComponentVector{Float64,SubArray...}(c = (a =2.0, b = [6.0, 30.0]), a =5.0)
51
+
```
52
+
We see here that the new `ComponentArray` has the order of the `a` and `c` fields switched according to the order they were indexed by.
53
+
54
+
Multi-symbol indexing can be performed by passing either a `Tuple` or an `Array` of `Symbol`s.
55
+
```julia
56
+
julia> ca[[:c, :a]] == ca[(:c, :a)]
57
+
true
58
+
```
59
+
40
60
## Retaining component labels through index operations
41
61
Sometimes you might want to index into a `ComponentArray` without dropping the component name. Let's look at a new example with a more deeply nested structure:
0 commit comments