Incidentally, this errors in 0.5 (but works fine in 0.4)

julia> s=0.0;

julia> m=rand(10000,1000);

julia> @time for el in m
              s = s + el
              end
ERROR: UndefVarError: s not defined
 [inlined code] from .\none:2
 in anonymous at .\no file:4294967295
 in eval at <invalid>:0



quinta-feira, 25 de Fevereiro de 2016 às 13:35:56 UTC, abc escreveu:
>
> For the following matrix
> my_matrix = randn(10000, 1000)
> using eachindex to access all elements is much slower than using ranges 
> or even for el in my_matrix, even though it says in the documentation (
> http://docs.julialang.org/en/release-0.4/stdlib/arrays/#Base.eachindex) 
> that eachindex uses ranges for Arrays.
>
> Some code and numbers:
> julia> sum = 0.0
> julia> @time for iter in eachindex(my_matrix)
>              sum += my_matrix[iter]
>          end
>    1.288944 seconds (50.00 M allocations: 915.519 MB, 3.36% gc time)
> julia> sum = 0.0
> julia> @time for i in 1:10000, j in 1:1000
>              sum += my_matrix[i,j]
>          end
>    0.681678 seconds (34.38 M allocations: 524.582 MB, 2.45% gc time)
> julia> sum = 0.0
> julia> @time for el in my_matrix
>              sum += el
>          end
>    1.063564 seconds (40.00 M allocations: 762.993 MB, 3.41% gc time)
>
> Am I reading the documentation wrong, or is there something strange with 
> the matrix indexing? Because as it is, I don't see any benefit of using 
> anything different than simple ranges for manipulating matrices.
>

Reply via email to