Julia BoundsError Means

Viewed 36
ERROR: BoundsError: attempt to access Tuple{Int64} at index [2]
Stacktrace:
 [1] indexed_iterate
   @ .\tuple.jl:89 [inlined]

When I run my Julia code, it shows this BoundsError. What does this mean and how can I solve it? My code is to find the size of a Vector{Float64}.

(m,n)=size(c)

where c is a Vector{Float64}.

1 Answers

A Tuple{Int64} is a tuple containing a single element. So the error message is saying that you tried to access element 2 of a one-element tuple.

In Julia, vectors are truly one-dimensional, so size returns only one value (for eg. size(1:10) is just (10,)). When you try to assign that to (m, n), you're trying to extract two values from it, hence the error.

Since you know it's a Vector already, you know that its number of columns is going to be just 1. So you can instead just do n = length(c) to obtain the number of elements c contains.

Related