Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit d4deef8

Browse files
Jeremy E Kozdonlcw
authored andcommitted
Add better function to check if valid fieldarray
1 parent ad3d0d6 commit d4deef8

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/arrays.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,17 @@ function fieldarray(a::StructArray{S}, dims::Dims=size(a)) where {S}
107107
@assert isfieldarray(a)
108108
fieldarray(undef, _namedtuple(S), arraytype(a), dims)
109109
end
110+
111+
isfieldarray(a) = Tullio.storage_type(a) == typeof(a)
112+
function isfieldarray(a::StructArray)
113+
data = components(a)[1]
114+
while data isa StructArray
115+
data = components(data)[1]
116+
end
117+
isfieldarray(a, data)
118+
end
119+
isfieldarray(a::StructArray, data) =
120+
all(isfieldarray.(values(components(a)), Ref(data)))
121+
isfieldarray(a::Union{Base.ReshapedArray, SubArray}, data) =
122+
isfieldarray(parent(a), data)
123+
isfieldarray(a, data) = pointer(a) == pointer(data)

src/banded.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function get_batched_array(x::StructArray, Nqh, Neh)
6363
Nqv = div(prod(size(x)[1:end-1]), Nqh)
6464
n = Nev * Nqv * Nfields
6565
xa = parent(components(x)[1])
66-
@assert all(map(y -> pointer(y) === pointer(xa), parent.(components(x))))
66+
@assert isfieldarray(x)
6767

6868
# Reshape so that fields come before vertical dofs (smaller bandwidth)
6969
xa = PermutedDimsArray(reshape(xa, Nqh, Nqv, Nfields, Nev, Neh),

test/arrays.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
a = fieldarray(undef, T, A, ())
1414
@test size(a) == ()
1515
@test typeof(a) == typeof(fieldarray(a))
16+
@test Bennu.isfieldarray(a)
1617

1718
b = fieldarray(a, (1,2,1,3))
1819
@test size(b) == (1,2,1,3)
@@ -23,6 +24,7 @@
2324
@test eltype(a) == T
2425
@test Tullio.storage_type(a) <: A
2526
@test typeof(a) == typeof(fieldarray(a))
27+
@test Bennu.isfieldarray(a)
2628

2729
b = fieldarray(a, (1,2,1,3))
2830
@test size(b) == (1,2,1,3)
@@ -35,6 +37,7 @@
3537
@test eltype(a) == T
3638
@test Tullio.storage_type(a) <: A
3739
@test typeof(a) == typeof(fieldarray(a))
40+
@test Bennu.isfieldarray(a)
3841

3942
b = fieldarray(a, (1,2,1,3))
4043
@test size(b) == (1,2,1,3)
@@ -47,6 +50,8 @@
4750
@test eltype(a) == NamedTuple{(:a, :b), Tuple{SVector{2, T}, T}}
4851
@test Tullio.storage_type(a) <: A
4952
@test typeof(a) == typeof(fieldarray(a))
53+
@test Bennu.isfieldarray(a)
54+
@test !Bennu.isfieldarray(similar(a))
5055

5156
b = fieldarray(a, (1,2,1,3))
5257
@test size(b) == (1,2,1,3)

0 commit comments

Comments
 (0)