Skip to content

Avoid temporary arrays for independent numeric generators - #2944

Draft
rithikasridharbabu-2007 wants to merge 1 commit into
xtensor-stack:masterfrom
rithikasridharbabu-2007:contribution/independent-generator-assignment
Draft

rithikasridharbabu-2007 wants to merge 1 commit into
xtensor-stack:masterfrom
rithikasridharbabu-2007:contribution/independent-generator-assignment

Conversation

@rithikasridharbabu-2007

Copy link
Copy Markdown

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

Assigning arange or linspace to an existing contiguous container currently creates a full-size temporary because generators conservatively retain overlap protection. This adds an opt-in is_memory_independent trait, forwards it through xgenerator, and opts in arithmetic arange_generator specializations, used by both builders. Same-size assignments can then reuse existing storage.

Container assignment validates the shape before entering a generator’s noexcept assign_to. Unknown generators, including generators that read the destination, retain overlap protection. Forced-temporary mode is respected. Views and dynamically strided containers retain their current assignment paths: direct view assignment was slower than generating into a contiguous temporary in the local diagnostic.

Related to #2943. This is a focused first step for plain arithmetic arange/linspace assignments, rather than a complete solution for all generators or composed expressions.

Validation

  • Nine relevant test executables passed: test_xbuilder, test_xassign, test_xarray, test_xtensor, test_xview, test_xrandom, test_xnoalias, test_xadapt, and test_xfixed. Automatic overlap detection was enabled with XTENSOR_FORCE_TEMPORARY_MEMORY_IN_ASSIGNMENTS=OFF.
  • New regression tests cover zero data-buffer allocations for same-size arange/linspace assignment, resizing and empty output, an unknown generator reading the destination in reverse, self-concatenation, and dimension mismatch. The assignment suite passes 5 cases / 49 assertions.
  • Three diagnostic runs on macOS arm64 with AppleClang 17, C++20 and -O3 -DNDEBUG showed the additional element-buffer allocation falling from 8 MiB to zero for 1,048,576 doubles. All generated values were checked. Allocation instrumentation and default-allocator timings were measured separately. Large container timings were close; no general runtime speedup is claimed.
  • A separate forced-temporary build still allocated the expected temporary for ordinary assignment.

Remaining validation / draft status

  • The complete combined test target does not compile on the unchanged baseline in this environment: masked-view tests trigger reference-binding and deleted-assignment errors in xtl::xmasked_value. Reproduced with xtl 0.8.0 and 0.8.2. Full-suite success is not claimed.
  • A focused ASan/UBSan executable compiled, but its run produced no output and was interrupted. Sanitizer validation remains incomplete.

Opening as a draft for feedback on the trait and the container-only scope while these validation limits remain.

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.

2 participants