Thanks, @Tamas_Papp I have no previous experience with StructArrays. I expected something like this to work:
julia> using StructArrays
julia> a = 1:10
1:10
julia> b = 11:20
11:20
julia> transform(a, b) = a+b, a*b, a-b
transform (generic function with 1 method)
x, y, z = StructArray(transform.(a, b))
10-element StructArray(::Vector{Int64}, ::Vector{Int64}, ::Vector{Int64}) with eltype Tuple{Int64, Int64, Int64}:
(12, 11, -10)
(14, 24, -10)
(16, 39, -10)
(18, 56, -10)
(20, 75, -10)
(22, 96, -10)
(24, 119, -10)
(26, 144, -10)
(28, 171, -10)
(30, 200, -10)
julia> x # Get the first row here instead of first column (which I want)
(12, 11, -10)
The only option I can find now is:
julia> w = StructArray(transform.(a, b))
10-element StructArray(::Vector{Int64}, ::Vector{Int64}, ::Vector{Int64}) with eltype Tuple{Int64, Int64, Int64}:
(12, 11, -10)
(14, 24, -10)
(16, 39, -10)
(18, 56, -10)
(20, 75, -10)
(22, 96, -10)
(24, 119, -10)
(26, 144, -10)
(28, 171, -10)
(30, 200, -10)
julia> x = getproperty(w, 1)
10-element Vector{Int64}:
12
14
16
18
20
22
24
26
28
30
Which is not so different from this approach without StructArrays:
julia> w = transform.(a, b)
10-element Vector{Tuple{Int64, Int64, Int64}}:
(12, 11, -10)
(14, 24, -10)
(16, 39, -10)
(18, 56, -10)
(20, 75, -10)
(22, 96, -10)
(24, 119, -10)
(26, 144, -10)
(28, 171, -10)
(30, 200, -10)
julia> x = getindex.(w, 1)
10-element Vector{Int64}:
12
14
16
18
20
22
24
26
28
30
Am I missing something? What I am looking for is a “direct way” to unpack the columns of a broadcasted function. Something like @. x, y, z = transform(a, b)
which you mentioned at the beginning of the this post.