Skip to content

Commit c82d7c8

Browse files
lkdvosJutho
andauthored
PtrArrays extension (#16)
* Add package extension for `PtrArrays.jl` * Add minimal tests * Bump version * Restrict `_normalizeparent` * add one more test --------- Co-authored-by: Jutho <Jutho@users.noreply.github.com>
1 parent f4d8121 commit c82d7c8

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StridedViews"
22
uuid = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
33
authors = ["Lukas Devos <lukas.devos@ugent.be>", "Jutho Haegeman <jutho.haegeman@ugent.be>"]
4-
version = "0.4.0"
4+
version = "0.4.1"
55

66
[deps]
77
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
@@ -10,23 +10,27 @@ PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
1010

1111
[weakdeps]
1212
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
13+
PtrArrays = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
1314

1415
[extensions]
1516
StridedViewsCUDAExt = "CUDA"
17+
StridedViewsPtrArraysExt = "PtrArrays"
1618

1719
[compat]
1820
Aqua = "0.8"
1921
CUDA = "4,5"
2022
LinearAlgebra = "1.6"
2123
PackageExtensionCompat = "1"
24+
PtrArrays = "1.2.0"
2225
Random = "1.6"
2326
Test = "1.6"
2427
julia = "1.6"
2528

2629
[extras]
2730
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
31+
PtrArrays = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
2832
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2933
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3034

3135
[targets]
32-
test = ["Test", "Random", "Aqua"]
36+
test = ["Test", "Random", "Aqua", "PtrArrays"]

ext/StridedViewsPtrArraysExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module StridedViewsPtrArraysExt
2+
3+
using StridedViews
4+
using PtrArrays
5+
6+
StridedViews._normalizeparent(A::PtrArray) = PtrArray(A.ptr, length(A))
7+
8+
end

src/auxiliary.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ end
4747

4848
# 'Normalize' the layout of a DenseArray, in order to reduce the number of required
4949
# specializations in functions.
50+
@inline _normalizeparent(A) = A
5051
@static if isdefined(Core, :Memory)
5152
@inline _normalizeparent(A::Array) = A.ref.mem
53+
else
54+
@inline _normalizeparent(A::Array) = reshape(A, length(A))
5255
end
53-
@inline _normalizeparent(A::DenseArray) = reshape(A, length(A))
5456

5557
# Auxiliary methods for `sview`
5658
#------------------------------

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,17 @@ end
250250
end
251251
end
252252

253+
using PtrArrays
254+
@testset "PtrArrays with StridedView" begin
255+
@testset for T in (Float64, ComplexF64)
256+
A = randn!(malloc(T, 10, 10, 10, 10))
257+
@test isstrided(A)
258+
B = StridedView(A)
259+
@test B isa StridedView
260+
@test B == A
261+
free(A)
262+
end
263+
end
264+
253265
using Aqua
254266
Aqua.test_all(StridedViews)

0 commit comments

Comments
 (0)