Skip to content

Commit 7ac9a80

Browse files
adienesKristofferC
authored andcommitted
Switch from segfault to zip behavior for mismatched indices in map! (#56673)
(cherry picked from commit 0947114)
1 parent 9c892c6 commit 7ac9a80

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/abstractarray.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,26 @@ generic_map_tests(map, map!)
855855
# @test_throws BoundsError map!(+, ones(3), ones(2, 2), ones(2, 2))
856856
end
857857

858+
@testset "#30624" begin
859+
### unstructured
860+
@test map!(+, ones(3), ones(3), ones(3), [1]) == [3, 1, 1]
861+
@test map!(+, ones(3), [1], ones(3), ones(3)) == [3, 1, 1]
862+
@test map!(+, [1], [1], [], []) == [1]
863+
@test map!(+, [[1]], [1], [], []) == [[1]]
864+
865+
# TODO: decide if input axes & lengths should be validated
866+
# @test_throws BoundsError map!(+, ones(1), ones(2))
867+
# @test_throws BoundsError map!(+, ones(1), ones(2, 2))
868+
869+
@test map!(+, ones(3), view(ones(2, 3), 1:2, 2:3), ones(3)) == [2, 2, 2]
870+
@test map!(+, ones(3), ones(2, 2), ones(3)) == [2, 2, 2]
871+
872+
### structured (all mapped arguments are <:AbstractArray equal ndims > 1)
873+
@test map!(+, ones(4), ones(2, 2), ones(2, 2)) == [2, 2, 2, 2]
874+
@test map!(+, ones(4), ones(2, 2), ones(1, 2)) == [2, 2, 1, 1]
875+
# @test_throws BoundsError map!(+, ones(3), ones(2, 2), ones(2, 2))
876+
end
877+
858878
test_UInt_indexing(TestAbstractArray)
859879
test_13315(TestAbstractArray)
860880
test_checksquare()

0 commit comments

Comments
 (0)