# Accessing matrix (2x2) at \[3\] throws an error on master

**URL:** https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889
**Category:** General Usage
**Created:** [December 12, 2016, 2:20pm UTC](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889 "2016-12-12T14:20:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [December 12, 2016, 2:20pm UTC](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889/1 "2016-12-12T14:20:43Z")

</div>

Sooo, more Optim getting ready for v0.6 material. I fixed the macro problems in [Optim fails on v0.6 - #6 by pkofod](https://discourse.julialang.org/t/optim-fails-on-v0-6/872/6) but the tests still do not pass, as I get the following error

```julia
ERROR: LoadError: LoadError: BoundsError: attempt to access 2×2 Array{Float64,2} at index [3]
 in macro expansion at /home/pkm/.julia/v0.6/Optim/src/cg.jl:200 [inlined]
 in macro expansion at ./simdloop.jl:72 [inlined]
 in update_state!(::Optim.DifferentiableFunction, ::Optim.ConjugateGradientState{Float64}, ::Optim.ConjugateGradient{Void}) at /home/pkm/.julia/v0.6/Optim/src/cg.jl:198
 in optimize(::Optim.DifferentiableFunction, ::Array{Float64,2}, ::Optim.ConjugateGradient{Void}, ::Optim.OptimizationOptions{Void}) at /home/pkm/.julia/v0.6/Optim/src/optimize.jl:245

```

from the lines

```julia
@simd for i in 1:state.n
    @inbounds state.y[i] = state.g[i] - state.g_previous[i]
end

```

I tried adding `shows` in there, and indeed, when I try to index into the third element of any of the three (y, g, g\_previous) 2x2 matrices, it says I’m out of bounds. However, the following examples runs fine

```julia
type State
    y
    g
    g_previous
    n
end

the_state = State(rand(2,2), rand(2,2), rand(2,2), 4)

function update!(state)
    @simd for i in 1:state.n
        @inbounds state.y[i] = state.g[i] - state.g_previous[i]
    end
end

update!(the_state)

```

If I print the types, they are all 2x2 Matrix{Float64,2}'s.

I’m not expecting anyone to go through the code to understand what’s going on, I’m just looking for any good ideas for how to debug this. Thanks

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [December 12, 2016, 2:28pm UTC](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889/2 "2016-12-12T14:28:18Z")

</div>

[https://github.com/JuliaLang/julia/issues/19554](https://github.com/JuliaLang/julia/issues/19554)

[https://github.com/JuliaLang/julia/pull/19555](https://github.com/JuliaLang/julia/pull/19555)

---

<div class="post-metadata">

### Author: ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)
#### Post date: [December 12, 2016, 2:29pm UTC](https://discourse.julialang.org/t/accessing-matrix-2x2-at-3-throws-an-error-on-master/889/3 "2016-12-12T14:29:48Z")

</div>

Thanks… I’m totally behind the stream of issues these days/weeks/…
