Skip to content

Commit

Permalink
Support sub2ind(A, i, j)
Browse files Browse the repository at this point in the history
Finishes #10337, and is the complement of #9256
  • Loading branch information
timholy committed Apr 28, 2016
1 parent 811fe45 commit edeb09a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,8 @@ end
Expr(:block,meta,exprs...,Expr(:tuple,[symbol(:s,i) for i=1:N]...))
end

# TODO in v0.5: either deprecate line 1 or add line 2
ind2sub(a::AbstractArray, ind::Integer) = ind2sub(size(a), ind)
# sub2ind(a::AbstractArray, I::Integer...) = sub2ind(size(a), I...)
sub2ind(a::AbstractArray, I::Integer...) = sub2ind(size(a), I...)

function sub2ind{T<:Integer}(dims::Tuple{Vararg{Integer}}, I::AbstractVector{T}...)
N = length(dims)
Expand Down
3 changes: 0 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,6 @@ end
@deprecate flipud(A::AbstractArray) flipdim(A, 1)
@deprecate fliplr(A::AbstractArray) flipdim(A, 2)

@deprecate sub2ind{T<:Integer}(dims::Array{T}, sub::Array{T}) sub2ind(tuple(dims...), sub...)
@deprecate ind2sub!{T<:Integer}(sub::Array{T}, dims::Array{T}, ind::T) ind2sub!(sub, tuple(dims...), ind)

@deprecate strftime Libc.strftime
@deprecate strptime Libc.strptime
@deprecate flush_cstdio Libc.flush_cstdio
Expand Down
5 changes: 5 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,11 @@ function i7197()
ind2sub(size(S), 5)
end
@test i7197() == (2,2)
A = reshape(collect(1:9), (3,3))
@test ind2sub(size(A), 6) == (3,2)
@test sub2ind(size(A), 3, 2) == 6
@test ind2sub(A, 6) == (3,2)
@test sub2ind(A, 3, 2) == 6

# PR #9256
function pr9256()
Expand Down

0 comments on commit edeb09a

Please sign in to comment.