@@ -7,7 +7,7 @@ This package introduces the type `StructArray` which is an `AbstractArray` whose
7
7
8
8
` Base.getproperty ` or the dot syntax can be used to access columns, whereas rows can be accessed with ` getindex ` .
9
9
10
- The package is largely inspired from the ` Columns ` type in [ IndexedTables] ( https://github.com/JuliaComputing/IndexedTables.jl )
10
+ The package was largely inspired by the ` Columns ` type in [ IndexedTables] ( https://github.com/JuliaComputing/IndexedTables.jl ) which it now replaces.
11
11
12
12
## Example usage to store complex numbers
13
13
@@ -39,6 +39,39 @@ julia> StructArray([1+im, 3-2im])
39
39
3 - 2im
40
40
```
41
41
42
+ ### Collection and initialization
43
+
44
+ One can also create a ` StructArrray ` from an iterable of structs without creating an intermediate ` Array ` :
45
+
46
+ ``` julia
47
+ julia> StructArray (log (j+ 2.0 * im) for j in 1 : 10 )
48
+ 10 - element StructArray{Complex{Float64},1 ,NamedTuple{(:re , :im ),Tuple{Array{Float64,1 },Array{Float64,1 }}}}:
49
+ 0.8047189562170501 + 1.1071487177940904im
50
+ 1.0397207708399179 + 0.7853981633974483im
51
+ 1.2824746787307684 + 0.5880026035475675im
52
+ 1.4978661367769954 + 0.4636476090008061im
53
+ 1.683647914993237 + 0.3805063771123649im
54
+ 1.8444397270569681 + 0.3217505543966422im
55
+ 1.985145956776061 + 0.27829965900511133im
56
+ 2.1097538525880535 + 0.24497866312686414im
57
+ 2.2213256282451583 + 0.21866894587394195im
58
+ 2.3221954495706862 + 0.19739555984988078im
59
+ ```
60
+
61
+ Another option is to create an uninitialized ` StructArray ` and then fill it with data. Just like in normal arrays, this is done with the ` undef ` syntax:
62
+
63
+ ``` julia
64
+ julia> s = StructArray {ComplexF64} (undef, 2 , 2 )
65
+ 2 × 2 StructArray{Complex{Float64},2 ,NamedTuple{(:re , :im ),Tuple{Array{Float64,2 },Array{Float64,2 }}}}:
66
+ 6.91646e-310 + 6.91646e-310im 6.91646e-310 + 6.91646e-310im
67
+ 6.91646e-310 + 6.91646e-310im 6.91646e-310 + 6.91646e-310im
68
+
69
+ julia> rand! (s)
70
+ 2 × 2 StructArray{Complex{Float64},2 ,NamedTuple{(:re , :im ),Tuple{Array{Float64,2 },Array{Float64,2 }}}}:
71
+ 0.446415 + 0.671453im 0.0797964 + 0.675723im
72
+ 0.0340059 + 0.420472im 0.907252 + 0.808263im
73
+ ```
74
+
42
75
## Example usage to store a data table
43
76
44
77
``` julia
0 commit comments