Skip to content

Commit af71939

Browse files
Merge pull request #128 from KlausC/krc/ismutableArrayPartitions
fix ArrayInterface.ismutable(::ArrayPartition)
2 parents 5023a5f + 3402cb5 commit af71939

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.jl.*.cov
33
*.jl.mem
44
Manifest.toml
5+
.vscode

src/array_partition.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ end
7070
# ignore dims since array partitions are vectors
7171
Base.ones(A::ArrayPartition, dims::NTuple{N,Int}) where {N} = ones(A)
7272

73+
# mutable iff all components of ArrayPartition are mutable
74+
@generated function ArrayInterface.ismutable(::Type{<:ArrayPartition{T,S}}) where {T,S}
75+
res = all(ArrayInterface.ismutable, S.parameters)
76+
return :( $res )
77+
end
78+
7379
## vector space operations
7480

7581
for op in (:+, :-)

test/partitions_test.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using RecursiveArrayTools, Test, Statistics
1+
using RecursiveArrayTools, Test, Statistics, ArrayInterface
22
A = (rand(5),rand(5))
33
p = ArrayPartition(A)
44
@test (p.x[1][1],p.x[2][1]) == (p[1],p[6])
@@ -135,3 +135,7 @@ function foo(y, x)
135135
end
136136
foo(xcde0, xce0)
137137
#@test 0 == @allocated foo(xcde0, xce0)
138+
139+
@testset "ArrayInterface.ismutable(ArrayPartition($a, $b)) == $r" for (a, b, r) in ((1,2, false), ([1], 2, false), ([1], [2], true))
140+
@test ArrayInterface.ismutable(ArrayPartition(a, b)) == r
141+
end

0 commit comments

Comments
 (0)