Skip to content

Conversation

@ssam18
Copy link

@ssam18 ssam18 commented Dec 18, 2025

This PR addresses GitHub issue #2871 where using auto with xtensor reducer functions (like amax, sum with keep_dims) causes crashes or incorrect results in optimized builds, particularly on Android ARM64.

Root Cause: Lazy expressions hold references to local variables. When intermediate results are stored with auto, these references become dangling when the function returns, leading to undefined behavior.

Changes:

  • docs/source/pitfall.rst: Added detailed warning section explaining the issue and providing three solutions:
    1. Use explicit container types (xt::xtensor<T, N>)
    2. Use xt::eval() to force immediate evaluation
    3. Use evaluation_strategy::immediate with reducers
  • test/test_xmath.cpp: Added test demonstrating correct patterns

Testing:

  • All 83 xmath tests pass
  • All 64 xreducer tests pass

Fixes #2871

…tensor-stack#2871)

This commit addresses GitHub issue xtensor-stack#2871 where using 'auto' with xtensor
reducer functions (like amax, sum with keep_dims) in functions causes
crashes or incorrect results in optimized builds.

The issue is that lazy expressions hold references to local variables.
When intermediate results are stored with 'auto', these references
become dangling when the function returns, leading to undefined behavior.

Fixes xtensor-stack#2871
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.

Android ARM64: xtensor auto Deduction Fails in Release Build - Expression Template Optimization Bug

1 participant