Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
PtrArrays = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"

[extensions]
StridedViewsAMDGPUExt = "AMDGPU"
StridedViewsCUDAExt = "CUDA"
StridedViewsJLArraysExt = "JLArrays"
StridedViewsPtrArraysExt = "PtrArrays"

[compat]
AMDGPU = "2"
Aqua = "0.8"
CUDA = "4,5"
JET = "0.9, 0.10, 0.11"
JLArrays = "0.3.1"
LinearAlgebra = "1.6"
PackageExtensionCompat = "1"
PtrArrays = "1.2.0"
Expand All @@ -34,9 +37,10 @@ AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
PtrArrays = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random", "Aqua", "JET", "PtrArrays", "CUDA", "AMDGPU"]
test = ["Test", "Random", "Aqua", "JET", "PtrArrays", "CUDA", "AMDGPU", "JLArrays"]
27 changes: 27 additions & 0 deletions ext/StridedViewsJLArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module StridedViewsJLArraysExt

using StridedViews
using JLArrays
using JLArrays: Adapt

const JLArrayStridedView{T, N, A <: JLArray{T}} = StridedView{T, N, A}

function Adapt.adapt_structure(to, A::JLArrayStridedView)
return StridedView(
Adapt.adapt_structure(to, parent(A)),
A.size, A.strides, A.offset, A.op
)
end

function Base.pointer(x::JLArrayStridedView{T}) where {T}
return Base.unsafe_convert(Ptr{T}, pointer(x.parent, x.offset + 1))
end
function Base.unsafe_convert(::Type{Ptr{T}}, a::JLArrayStridedView{T}) where {T}
return convert(Ptr{T}, pointer(a))
end

function Base.print_array(io::IO, X::JLArrayStridedView)
return Base.print_array(io, Adapt.adapt_structure(Array, X))
end

end # module
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Test
using LinearAlgebra
using Random
using StridedViews
using JLArrays

Random.seed!(1234)

Expand Down Expand Up @@ -290,6 +291,21 @@ if !is_buildkite
end
end

@testset "JLArrays with StridedView" begin
@testset for T in (Float64, ComplexF64)
Araw = randn(T, 10, 10, 10, 10)
A = JLArray(Araw)
@test isstrided(A)
B = StridedView(A)
@test B isa StridedView
JLArrays.@allowscalar begin
@test B == A
end
Bvec = JLArrays.Adapt.adapt(Vector{T}, B)
@test Bvec == StridedView(Araw)
end
end

using Aqua
Aqua.test_all(StridedViews)

Expand Down
Loading