Skip to content

Commit 38c803d

Browse files
authored
Merge pull request #17336 from JuliaLang/teh/subarray_redundancies
Remove redundant SubArray tests
2 parents a18b18c + 874cc5d commit 38c803d

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

test/subarray.jl

+9-23
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ using Base.Test
55
######## Utilities ###########
66

77
# Generate an array similar to A[indx1, indx2, ...], but only call
8-
# getindex with scalar-valued indexes. This will be safe even after
9-
# getindex starts calling sub/slice.
8+
# getindex with scalar-valued indexes. This will be safe even if
9+
# `getindex` someday calls `view`.
1010

11-
# The "nodrop" variant is similar to current getindex/sub, except it
12-
# doesn't drop any dimensions (not even trailing ones)
11+
# The "nodrop" variant does not drop any dimensions (not even trailing ones)
1312
function Agen_nodrop(A::AbstractArray, I...)
1413
irep = replace_colon(A, I)
1514
_Agen(A, irep...)
1615
end
1716

18-
# This does the same thing as slice
17+
# This drops scalar dimensions
1918
function Agen_slice(A::AbstractArray, I...)
2019
irep = replace_colon(A, I)
2120
B = _Agen(A, irep...)
@@ -179,9 +178,9 @@ function runsubarraytests(A::Array, I...)
179178
end
180179

181180
function runsubarraytests(A::ANY, I...)
182-
# When A was created with sub, we have to check bounds, since some
181+
# When A was created with view, we have to check bounds, since some
183182
# of the "residual" dimensions have size 1. It's possible that we
184-
# need dedicated tests for sub.
183+
# need dedicated tests for view.
185184
for d = 1:length(I)-1
186185
if !isa(I[d], Colon) && any(I[d] .> size(A,d))
187186
return nothing
@@ -203,7 +202,6 @@ function runsubarraytests(A::ANY, I...)
203202
Cdim += 1
204203
end
205204
end
206-
# sub
207205
local S
208206
try
209207
S = view(A, I...)
@@ -216,18 +214,6 @@ function runsubarraytests(A::ANY, I...)
216214
test_linear(S, C)
217215
test_cartesian(S, C)
218216
test_mixed(S, C)
219-
# slice
220-
try
221-
S = view(A, I...)
222-
catch err
223-
@show typeof(A)
224-
@show A.indexes
225-
@show I
226-
rethrow(err)
227-
end
228-
test_linear(S, C)
229-
test_cartesian(S, C)
230-
test_mixed(S, C)
231217
end
232218

233219
# indexN is a cartesian index, indexNN is a linear index for 2 dimensions, and indexNNN is a linear index for 3 dimensions
@@ -324,7 +310,7 @@ x11289 = randn(5,5)
324310

325311
####### "Classical" tests #######
326312

327-
# sub
313+
# Tests where non-trailing dimensions are preserved
328314
A = copy(reshape(1:120, 3, 5, 8))
329315
sA = view(A, 2:2, 1:5, :)
330316
@test strides(sA) == (1, 3, 15)
@@ -372,7 +358,7 @@ sA = view(A, 1:2, 3, [1 3; 4 2])
372358
@test ndims(sA) == 3
373359
@test indices(sA) === (Base.OneTo(2), Base.OneTo(2), Base.OneTo(2))
374360

375-
# sub logical indexing #4763
361+
# logical indexing #4763
376362
A = view([1:10;], 5:8)
377363
@test A[A.<7] == [5, 6]
378364
@test Base.unsafe_getindex(A, A.<7) == [5, 6]
@@ -381,7 +367,7 @@ sB = view(B, 2:3, 2:3)
381367
@test sB[sB.>8] == [10, 11]
382368
@test Base.unsafe_getindex(sB, sB.>8) == [10, 11]
383369

384-
# slice
370+
# Tests where dimensions are dropped
385371
A = copy(reshape(1:120, 3, 5, 8))
386372
sA = view(A, 2, :, 1:8)
387373
@test parent(sA) == A

0 commit comments

Comments
 (0)