@@ -5,17 +5,16 @@ using Base.Test
5
5
# ####### Utilities ###########
6
6
7
7
# 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` .
10
10
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)
13
12
function Agen_nodrop (A:: AbstractArray , I... )
14
13
irep = replace_colon (A, I)
15
14
_Agen (A, irep... )
16
15
end
17
16
18
- # This does the same thing as slice
17
+ # This drops scalar dimensions
19
18
function Agen_slice (A:: AbstractArray , I... )
20
19
irep = replace_colon (A, I)
21
20
B = _Agen (A, irep... )
@@ -179,9 +178,9 @@ function runsubarraytests(A::Array, I...)
179
178
end
180
179
181
180
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
183
182
# of the "residual" dimensions have size 1. It's possible that we
184
- # need dedicated tests for sub .
183
+ # need dedicated tests for view .
185
184
for d = 1 : length (I)- 1
186
185
if ! isa (I[d], Colon) && any (I[d] .> size (A,d))
187
186
return nothing
@@ -203,7 +202,6 @@ function runsubarraytests(A::ANY, I...)
203
202
Cdim += 1
204
203
end
205
204
end
206
- # sub
207
205
local S
208
206
try
209
207
S = view (A, I... )
@@ -216,18 +214,6 @@ function runsubarraytests(A::ANY, I...)
216
214
test_linear (S, C)
217
215
test_cartesian (S, C)
218
216
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)
231
217
end
232
218
233
219
# 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)
324
310
325
311
# ###### "Classical" tests #######
326
312
327
- # sub
313
+ # Tests where non-trailing dimensions are preserved
328
314
A = copy (reshape (1 : 120 , 3 , 5 , 8 ))
329
315
sA = view (A, 2 : 2 , 1 : 5 , :)
330
316
@test strides (sA) == (1 , 3 , 15 )
@@ -372,7 +358,7 @@ sA = view(A, 1:2, 3, [1 3; 4 2])
372
358
@test ndims (sA) == 3
373
359
@test indices (sA) === (Base. OneTo (2 ), Base. OneTo (2 ), Base. OneTo (2 ))
374
360
375
- # sub logical indexing #4763
361
+ # logical indexing #4763
376
362
A = view ([1 : 10 ;], 5 : 8 )
377
363
@test A[A.< 7 ] == [5 , 6 ]
378
364
@test Base. unsafe_getindex (A, A.< 7 ) == [5 , 6 ]
@@ -381,7 +367,7 @@ sB = view(B, 2:3, 2:3)
381
367
@test sB[sB.> 8 ] == [10 , 11 ]
382
368
@test Base. unsafe_getindex (sB, sB.> 8 ) == [10 , 11 ]
383
369
384
- # slice
370
+ # Tests where dimensions are dropped
385
371
A = copy (reshape (1 : 120 , 3 , 5 , 8 ))
386
372
sA = view (A, 2 , :, 1 : 8 )
387
373
@test parent (sA) == A
0 commit comments