Skip to content

Commit 12b91d4

Browse files
committed
Fix unary minus for nested ArrayPartition
1 parent ba03cdd commit 12b91d4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/array_partition.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ for op in (:+, :-)
106106
end
107107
end
108108

109+
function Base.:-(A::ArrayPartition)
110+
return ArrayPartition(map(-, A.x))
111+
end
112+
109113
for op in (:*, :/)
110114
@eval function Base.$op(A::ArrayPartition, B::Number)
111115
ArrayPartition(map(y->Base.broadcast($op, y, B), A.x))

test/partitions_test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ up = 2 .* ap .+ 1
191191
@testset "ArrayInterface.ismutable(ArrayPartition($a, $b)) == $r" for (a, b, r) in ((1,2, false), ([1], 2, false), ([1], [2], true))
192192
@test ArrayInterface.ismutable(ArrayPartition(a, b)) == r
193193
end
194+
195+
# Test unary minus
196+
197+
x = ArrayPartition(ArrayPartition([1, 2]), [3, 4])
198+
@test -x == 0-x
199+
@test typeof(x) === typeof(-x)

0 commit comments

Comments
 (0)