Skip to content

Implement reduce_product() - #361

Open
Shnatsel wants to merge 6 commits into
linebender:mainfrom
Shnatsel:reduce-product
Open

Implement reduce_product()#361
Shnatsel wants to merge 6 commits into
linebender:mainfrom
Shnatsel:reduce-product

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Matches std::simd in precision (same number of roundings), but uses a more SIMD-friendly multiplication order. It uses the same order across all backends. The implementation is similar to reduce_sum().

The result is not guaranteed to be equal to v.to_slice().sum(), but that is only achievable with fully scalar multiplication; std::simd scalarizes to uphold this behavior which it doesn't even document.

Unlike #357 we can't reduce precision loss to log2(N) rather than N, at least not without complex algorithms that compute the precise sum in one rounding by separately accounting for the accumulated error. A precise variant which does that could be added later.

This is the final part of #340. Closes #340.

@Shnatsel Shnatsel mentioned this pull request Aug 30, 2026
22 tasks
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.

Feature Request: Add cross-lane horizontal reduction methods (e.g., .reduce_sum(), .reduce_max()) to SimdBase / Simd vector types

1 participant