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: docs/src/index.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Overview of StructArrays.jl
2
2
3
-
This package introduces the type `StructArray` which is an `AbstractArray` whose elements are `struct` (for example `NamedTuples`, or `ComplexF64`, or a custom user defined `struct`). While a `StructArray` iterates `structs`, the layout uses separate arrays for each field of the `struct`. This is often called [Structure-Of-Arrays (SOA)](https://en.wikipedia.org/wiki/AoS_and_SoA); the concepts will be explained in greater detail below. `struct` entries of a StructArray are constructed on-the-fly. This contrasts with the "Array-Of-Structs" (AOS) layout where individual array elements are explicitly stored as `struct`s.
3
+
This package introduces the type `StructArray` which is an `AbstractArray` whose elements are `struct` (for example `NamedTuple`s, or `ComplexF64`, or a custom user defined `struct`). While a `StructArray` iterates `struct`s, the layout uses separate arrays for each field of the `struct`. This is often called [Structure-Of-Arrays (SOA)](https://en.wikipedia.org/wiki/AoS_and_SoA); the concepts will be explained in greater detail below. `struct` entries of a `StructArray` are constructed on-the-fly. This contrasts with the "Array-Of-Structs" (AOS) layout where individual array elements are explicitly stored as `struct`s.
4
4
5
-
`Base.getproperty` or the dot syntax can be used to access struct fields of element of a `StructArray`, whereas elements can be accessed with `getindex` (`[]`).
5
+
`Base.getproperty` or the dot syntax can be used to access `struct` fields of element of a `StructArray`, whereas elements can be accessed with `getindex` (`[]`).
6
6
7
7
The package was largely inspired by the `Columns` type in [IndexedTables](https://github.com/JuliaComputing/IndexedTables.jl) which it now replaces.
8
8
9
9
## Collection and initialization
10
10
11
-
One can create a `StructArray` by providing the struct type and a tuple or NamedTuple of field arrays:
11
+
One can create a `StructArray` by providing the `struct` type and a `Tuple` or `NamedTuple` of field arrays:
You can also initialze a StructArray by passing in a NamedTuple, in which case the name (rather than the order) specifies how the input arrays are assigned to fields:
22
+
You can also initialize a `StructArray` by passing in a `NamedTuple`, in which case the name (rather than the order) specifies how the input arrays are assigned to fields:
23
23
24
24
```@repl intro
25
-
x = StructArray{Foo}((b = adata, a = bdata)) # initialize a with bdata and vice versa
25
+
x = Array{Foo}((b = adata, a = bdata)) # initialize a with bdata and vice versa
26
26
```
27
27
28
-
If a struct is not specified, a StructArray with Tuple or NamedTuple elements will be created:
28
+
If a `struct` is not specified, a `StructArray` with `Tuple `or `NamedTuple` elements will be created:
29
29
```@repl intro
30
30
x = StructArray((adata, bdata))
31
31
x = StructArray((a = adata, b = bdata))
32
32
```
33
33
34
-
It's also possible to create a `StructArray` by choosing a particular dimension to interpret as the components of a struct:
34
+
It's also possible to create a `StructArray` by choosing a particular dimension to interpret as the components of a `struct`:
35
35
36
36
```@repl intro
37
37
x = StructArray{Complex{Int}}(adata; dims=1) # along dimension 1, the first item `re` and the second is `im`
38
38
x = StructArray{Complex{Int}}(adata; dims=2) # along dimension 2, the first item `re` and the second is `im`
39
39
```
40
40
41
-
One can also create a `StructArray` from an iterable of structs without creating an intermediate `Array`:
41
+
One can also create a `StructArray` from an iterable of `struct`s without creating an intermediate `Array`:
42
42
43
43
```@repl intro
44
44
StructArray(log(j+2.0*im) for j in 1:10)
@@ -58,7 +58,7 @@ julia> rand!(s)
58
58
0.92407+0.929336im0.267358+0.804478im
59
59
```
60
60
61
-
Finally, it is possible to create a StructArray from an array-of-structs:
61
+
Finally, it is possible to create a `StructArray` from an array-of-structs:
62
62
63
63
```jldoctest; setup=:(using StructArrays)
64
64
julia> aos = [1+2im, 3+4im]
@@ -86,7 +86,7 @@ julia> soa.re
86
86
87
87
## Using custom array types
88
88
89
-
StructArrays supports using custom array types. It is always possible to pass field arrays of a custom type. The "custom array of structs to struct of custom arrays" transformation will use the `similar` method of the custom array type. This can be useful when working on the GPU for example:
89
+
`StructArray`s supports using custom array types. It is always possible to pass field arrays of a custom type. The "custom array of `struct`s to `struct` of custom arrays" transformation will use the `similar` method of the custom array type. This can be useful when working on the GPU for example:
StructArrays also provides a `LazyRow` wrapper for lazy row iteration. `LazyRow(t, i)` does not materialize the i-th row but returns a lazy wrapper around it on which `getproperty` does the correct thing. This is useful when the row has many fields only some of which are necessary. It also allows changing columns in place.
143
+
`StructArray`s also provides a `LazyRow` wrapper for lazy row iteration. `LazyRow(t, i)` does not materialize the i-th row but returns a lazy wrapper around it on which `getproperty` does the correct thing. This is useful when the row has many fields only some of which are necessary. It also allows changing columns in place.
144
144
145
145
```julia
146
146
julia> t =StructArray((a = [1, 2], b = ["x", "y"]));
0 commit comments