How to get more information about julia array bounds error?

I would encode the Julia function with an array bound error:

function wrong()

   alphas = [ 0.5, 1, 1.25, 2.0 ] ;
   theta = 0:0.02:1 * pi ;
   U = zeros( length(theta), 4 ) ;

   i = 1 ;
   j = 1 ;
   for a = alphas
      kd = pi * a ;

      for t = theta
         v = (cos( kd * cos( t ) ) - cos( kd ))/sin( t ) ;

         U[i, j] = v ;

         i = i + 1 ;
      end

      j = j + 1 ;
   end
end

Here i = 1 should be in the loop. I get:

julia> wrong()
ERROR: BoundsError()
 in setindex! at array.jl:308 (repeats 2 times)

Is there a way to get the julia translator to provide more detailed information about the exceptions when they hit, or ways to debug in the error statement and see what happens? For example, knowing what index values ​​that were caused by a boundary error when this happened would be useful for debugging this.

+4
source share
1 answer

julia v0.4 https://github.com/JuliaLang/julia/pull/9534. julia 0.4 , , , :

julia> wrong()
ERROR: BoundsError: attempt to access 158x4 Array{Float64,2}:
 NaN           0.0  0.0  0.0
   0.0157085   0.0  0.0  0.0
   0.0314201   0.0  0.0  0.0
   0.047138    0.0  0.0  0.0
   0.0628651   0.0  0.0  0.0
   0.0786045   0.0  0.0  0.0
   0.094359    0.0  0.0  0.0
   0.110131    0.0  0.0  0.0
   0.125924    0.0  0.0  0.0
   0.141739    0.0  0.0  0.0
   
   0.127183    0.0  0.0  0.0
   0.111388    0.0  0.0  0.0
   0.0956143   0.0  0.0  0.0
   0.0798585   0.0  0.0  0.0
   0.064118   0.0  0.0  0.0
   0.04839     0.0  0.0  0.0
   0.0326715   0.0  0.0  0.0
   0.0169595   0.0  0.0  0.0
   0.00125087  0.0  0.0  0.0
  at index [159,2]
 in wrong at none:15

, julia, 0.4 .

+4

Source: https://habr.com/ru/post/1585017/


All Articles