We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Base.Slice
1 parent d0548b4 commit 5a83c70Copy full SHA for 5a83c70
2 files changed
src/host/base.jl
@@ -278,9 +278,11 @@ struct NonContiguous end
278
GPUIndexStyle() = Contiguous()
279
GPUIndexStyle(I...) = NonContiguous()
280
GPUIndexStyle(::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
281
-GPUIndexStyle(i1::Colon, ::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
282
-GPUIndexStyle(i1::AbstractUnitRange, ::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
283
-GPUIndexStyle(i1::Colon, I...) = GPUIndexStyle(I...)
+GPUIndexStyle(::Colon, ::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
+GPUIndexStyle(::Base.Slice, ::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
+GPUIndexStyle(::AbstractUnitRange, ::Union{Base.ScalarIndex, CartesianIndex}...) = Contiguous()
284
+GPUIndexStyle(::Colon, I...) = GPUIndexStyle(I...)
285
+GPUIndexStyle(::Base.Slice, I...) = GPUIndexStyle(I...)
286
287
viewlength() = ()
288
@inline viewlength(::Real, I...) = viewlength(I...) # skip scalar
test/testsuite/base.jl
@@ -333,11 +333,20 @@ end
333
end
334
335
@test compare(x->view(x, :, 1:4, 3), AT, rand(Float32, 5, 4, 3))
336
+ @test compare(x->view(x, Base.Slice(Base.OneTo(5)), 1:4, 3), AT, rand(Float32, 5, 4, 3))
337
338
let x = AT(rand(Float32, 5, 4, 3))
339
@test_throws BoundsError view(x, :, :, 1:10)
340
341
342
+ @testset "selectdim" begin
343
+ @test compare(x -> selectdim(x, 3, 1), AT, rand(Float32, 2, 2, 2))
344
+ let x = AT(rand(Float32, 5, 4, 3))
345
+ @test typeof(selectdim(x, 3, 1)) == typeof(view(x, :, :, 1))
346
+ @test typeof(selectdim(x, 2, 1)) == typeof(view(x, :, 1, :))
347
+ end
348
349
+
350
# bug in parentindices conversion
351
let x = AT{Int}(undef, 1, 1)
352
x[1,:] .= 42
0 commit comments