I get the following error when I try to reduce the tuple array. Honestly I have no idea why this happen.
julia> a = [(x, rand()*10) for x in 1:20]
20-element Array{Tuple{Int64,Float64},1}:
(1, 8.090189006962254)
(2, 2.117390143738971)
(3, 3.720862674831744)
(4, 3.3448022839992686)
(5, 8.663485519459988)
(6, 2.8559985846713887)
(7, 8.90791074876892)
(8, 1.8252199991786422)
(9, 8.850720581613224)
(10, 2.3484428215704645)
(11, 7.05697492936725)
(12, 5.204279968934786)
(13, 9.661816648445496)
(14, 8.822892862843808)
(15, 9.937308741925413)
(16, 4.386983103895896)
(17, 6.657011304452505)
(18, 3.1464881449135285)
(19, 5.202863099252719)
(20, 5.450333298946468)
Correctly reduce on first tuple argument:
julia> reduce((x, y) → x[1] + y[1], a)
210
Error when reducing on second tuple argument:
julia> reduce((x, y) → x[2] + y[2], a)
ERROR: BoundsError
Stacktrace:
[1] getindex at .\number.jl:78 [inlined]
[2] #21 at .\REPL[10]:1 [inlined]
[3] macro expansion at .\reduce.jl:158 [inlined]
[4] macro expansion at .\simdloop.jl:77 [inlined]
[5] mapreduce_impl(::typeof(identity), ::var"#21#22", ::Array{Tuple{Int64,Float64},1}, ::Int64, ::Int64, ::Int64) at .\reduce.jl:156
[6] mapreduce_impl at .\reduce.jl:170 [inlined]
[7] _mapreduce(::typeof(identity), ::var"#21#22", ::IndexLinear, ::Array{Tuple{Int64,Float64},1}) at .\reduce.jl:316
[8] _mapreduce_dim(::Function, ::Function, ::NamedTuple{(),Tuple{}}, ::Array{Tuple{Int64,Float64},1}, ::Colon) at .\reducedim.jl:312
[9] #mapreduce#584 at .\reducedim.jl:307 [inlined]
[10] mapreduce at .\reducedim.jl:307 [inlined]
[11] #reduce#586 at .\reducedim.jl:352 [inlined]
[12] reduce(::Function, ::Array{Tuple{Int64,Float64},1}) at .\reducedim.jl:352
[13] top-level scope at REPL[10]:1