Skip to content

Commit edeb09a

Browse files
committed
Support sub2ind(A, i, j)
Finishes #10337, and is the complement of #9256
1 parent 811fe45 commit edeb09a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

base/abstractarray.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,8 @@ end
975975
Expr(:block,meta,exprs...,Expr(:tuple,[symbol(:s,i) for i=1:N]...))
976976
end
977977

978-
# TODO in v0.5: either deprecate line 1 or add line 2
979978
ind2sub(a::AbstractArray, ind::Integer) = ind2sub(size(a), ind)
980-
# sub2ind(a::AbstractArray, I::Integer...) = sub2ind(size(a), I...)
979+
sub2ind(a::AbstractArray, I::Integer...) = sub2ind(size(a), I...)
981980

982981
function sub2ind{T<:Integer}(dims::Tuple{Vararg{Integer}}, I::AbstractVector{T}...)
983982
N = length(dims)

base/deprecated.jl

-3
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,6 @@ end
368368
@deprecate flipud(A::AbstractArray) flipdim(A, 1)
369369
@deprecate fliplr(A::AbstractArray) flipdim(A, 2)
370370

371-
@deprecate sub2ind{T<:Integer}(dims::Array{T}, sub::Array{T}) sub2ind(tuple(dims...), sub...)
372-
@deprecate ind2sub!{T<:Integer}(sub::Array{T}, dims::Array{T}, ind::T) ind2sub!(sub, tuple(dims...), ind)
373-
374371
@deprecate strftime Libc.strftime
375372
@deprecate strptime Libc.strptime
376373
@deprecate flush_cstdio Libc.flush_cstdio

test/arrayops.jl

+5
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,11 @@ function i7197()
10441044
ind2sub(size(S), 5)
10451045
end
10461046
@test i7197() == (2,2)
1047+
A = reshape(collect(1:9), (3,3))
1048+
@test ind2sub(size(A), 6) == (3,2)
1049+
@test sub2ind(size(A), 3, 2) == 6
1050+
@test ind2sub(A, 6) == (3,2)
1051+
@test sub2ind(A, 3, 2) == 6
10471052

10481053
# PR #9256
10491054
function pr9256()

0 commit comments

Comments
 (0)