Contiguous views also for Base.Slice#666
Merged
maleadt merged 2 commits intoJuliaGPU:masterfrom Dec 11, 2025
Merged
Conversation
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/test/testsuite/base.jl b/test/testsuite/base.jl
index 8a5ca85..f6bfd33 100644
--- a/test/testsuite/base.jl
+++ b/test/testsuite/base.jl
@@ -333,19 +333,19 @@ end
end
@test compare(x->view(x, :, 1:4, 3), AT, rand(Float32, 5, 4, 3))
- @test compare(x->view(x, Base.Slice(Base.OneTo(5)), 1:4, 3), AT, rand(Float32, 5, 4, 3))
+ @test compare(x -> view(x, Base.Slice(Base.OneTo(5)), 1:4, 3), AT, rand(Float32, 5, 4, 3))
let x = AT(rand(Float32, 5, 4, 3))
@test_throws BoundsError view(x, :, :, 1:10)
end
- @testset "selectdim" begin
- @test compare(x -> selectdim(x, 3, 1), AT, rand(Float32, 2, 2, 2))
- let x = AT(rand(Float32, 5, 4, 3))
- @test typeof(selectdim(x, 3, 1)) == typeof(view(x, :, :, 1))
- @test typeof(selectdim(x, 2, 1)) == typeof(view(x, :, 1, :))
+ @testset "selectdim" begin
+ @test compare(x -> selectdim(x, 3, 1), AT, rand(Float32, 2, 2, 2))
+ let x = AT(rand(Float32, 5, 4, 3))
+ @test typeof(selectdim(x, 3, 1)) == typeof(view(x, :, :, 1))
+ @test typeof(selectdim(x, 2, 1)) == typeof(view(x, :, 1, :))
+ end
end
- end
# bug in parentindices conversion
let x = AT{Int}(undef, 1, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Besides
Base.Colonbase also usesBase.Sliceto indicate complete slices of a dimension (https://github.com/JuliaLang/julia/blob/8fd607a7df9e65ed060c88f32d801c95aa8a573f/base/indices.jl#L382).For views of GPUArrays, we can treat Slice the same way as Colon and create contiguous arrays (CuArray/.. etc) instead of
SubArrays.Closes JuliaGPU/CUDA.jl#2986