Julia: ind2sub doc example is broken

Created on 6 Sep 2017  ·  2Comments  ·  Source: JuliaLang/julia

The help text:

help?> ind2sub
search: ind2sub

  ind2sub(a, index) -> subscripts

  Returns a tuple of subscripts into array a corresponding to the linear index index.

     Examples
    ≡≡≡≡≡≡≡≡≡≡

  julia> A = ones(5,6,7);

  julia> ind2sub(A,35)
  (5, 1, 2)

  julia> ind2sub(A,70)
  (5, 2, 3)

  ind2sub(dims, index) -> subscripts

  Returns a tuple of subscripts into an array with dimensions dims, corresponding to the linear index index.

     Examples
    ≡≡≡≡≡≡≡≡≡≡

  i, j, ... = ind2sub(size(A), indmax(A))
...

What happens when you run the last line in the above example:

julia> A = ones(5, 6, 7);

julia> ind2sub(size(A), indmax(A))
ERROR: MethodError: no method matching ind2sub(::Tuple{Int64,Int64,Int64}, ::CartesianIndex{3})
Closest candidates are:
  ind2sub(::AbstractArray, ::Any) at abstractarray.jl:1617
  ind2sub(::Tuple{Vararg{Integer,N}} where N, ::Integer) at abstractarray.jl:1694
  ind2sub(::Union{Tuple{Vararg{Integer,N}}, Tuple{Vararg{AbstractUnitRange,N}}}, ::AbstractArray{#s51,1} where #s51<:Integer) where N at abstractarray.jl:1750

The change happened in #22907, which changed the output of indmax from a linear index to a Cartesian index if the input is multidimensional.

arrays doc

Most helpful comment

This is great --- we can remove the example, since you no longer need ind2sub in that case. Once all the examples are removed, we can remove the function :)

All 2 comments

This is great --- we can remove the example, since you no longer need ind2sub in that case. Once all the examples are removed, we can remove the function :)

This also now fails more gracefully after #23708.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Keno picture Keno  ·  3Comments

musm picture musm  ·  3Comments

iamed2 picture iamed2  ·  3Comments

TotalVerb picture TotalVerb  ·  3Comments

StefanKarpinski picture StefanKarpinski  ·  3Comments