Skip to content

Fix integer widening in sum and prod - #1363

Open
vera-rubin wants to merge 1 commit into
JuliaArrays:masterfrom
vera-rubin:fix/widen-sum-prod
Open

vera-rubin wants to merge 1 commit into
JuliaArrays:masterfrom
vera-rubin:fix/widen-sum-prod

Conversation

@vera-rubin

Copy link
Copy Markdown

sum and prod on narrow integer static arrays can wrap instead of widening:

# Julia 1.10.10, StaticArrays 1.9.23
using StaticArrays
sum(SVector{2,Int8}(100,28))  # Int8(-128)
prod(SVector{2,Int8}(16,16))  # Int8(0)

Base documents Int results of 128 and 256 for these inputs, with unsigned integers widening to UInt.

We use Base.add_sum and Base.mul_prod in the static overloads so these reductions widen consistently with Base. We've added regression coverage for signed and unsigned integers, mapped calls, empty and singleton vectors, and dimension reductions, and ran the mapreduce and accumulate tests before and after the fix.

— ChipLab

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant