Skip to content

Change in AbstractArray promotion #45511

@nalimilan

Description

@nalimilan

#44096 changed promotion rules for AbstractArray objects. In current Julia releases and 1.8, [A, B] preserves the type of arrays A and B. In current master, arrays are promoted to a common type if their types differ. This can give surprising results, as it seems relatively common (#44096 (comment)) to test different array types using loops such as:

for A in [[true, true], trues(2), [1, 1]]
    @test f(A) == ...
end

which now only tests Vector{Int} on three identical arrays.

Maybe this will mainly affect tests, as this kind of pattern is unlikely to be used in implementations. But it's somewhat pernicious as it doesn't make tests fail, but instead silently reduces test coverage. If it happens in real code, promotion can lead to allocating a copy of the inputs, which could dramatically increase memory usage (at the benefit of type stability), in particular if some of the inputs are sparse but one of them is dense.

This change doesn't seem to have been discussed, but it was raised recently on Slack so I figured it would be worth going through triage to ensure this is what we want before releasing 1.8.

Cc: @vtjnash, @KristofferC, @fredrikekre, @mbauman

Metadata

Metadata

Assignees

Labels

arrays[a, r, r, a, y, s]priorityThis should be addressed urgentlyregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions