Skip to content

Rework index manipulation API#416

Draft
lkdvos wants to merge 17 commits intomainfrom
ld-indexmanipulations
Draft

Rework index manipulation API#416
lkdvos wants to merge 17 commits intomainfrom
ld-indexmanipulations

Conversation

@lkdvos
Copy link
Copy Markdown
Member

@lkdvos lkdvos commented Apr 26, 2026

Summary

This PR overhauls the index manipulation API in src/tensors/indexmanipulations.jl to match TensorOperations dispatch conventions, reduces code duplication in the implementation, and adds a dedicated documentation page.
The goal was a bunch of code simplification, (overall number of lines reduced, even though I added some docs 🎉 )

API changes

  • Unified in-place interface: permute!, braid!, transpose!, and repartition! now directly accept α, β, backend, and allocator as optional arguments (with defaults One(), Zero(), DefaultBackend(), DefaultAllocator()), following the TensorOperations dispatch pattern. The old add_permute!, add_braid!, and add_transpose! are deprecated and forward to the new functions.
  • allocator support: previously, the index manipulation functions did not support a custom allocator at all. It is now a positional argument in both the public and internal interfaces, consistent with TensorOperations convention.
  • Out-of-place functions (permute, braid, transpose, repartition) gain backend as a new keyword argument alongside the now-supported allocator keyword.
  • twist! added: new in-place variant of twist.

Implementation changes

  • All permutation operations now route through braid!, eliminating duplicate codepaths.
  • Dedicated braid! method added for AdjointTensorMap.
  • add_transform! kernels for TensorMap refactored to operate on the raw data vector rather than the full TensorMap. Because the data vector has a concrete type, this avoids recompilation for every TensorMap type combination, improving compilation time.
  • Various minor simplifications throughout.

Documentation

  • New dedicated page docs/src/man/indexmanipulations.md with a structured overview categorising operations into: reweighting (flip, twist), space insertion/removal (insertleftunit, insertrightunit, removeunit), and index rearrangements (permute, braid, transpose, repartition).
  • Docstrings updated to use TO-style bracket notation for optional arguments.

lkdvos and others added 15 commits April 24, 2026 20:06
Merge the two-tier `permute!`/`add_permute!` pattern into a single tier: `permute!`, `braid!`, `transpose!`, and `repartition!` now directly accept optional `α`, `β`, `backend`, and `allocator` arguments with sensible defaults (One(), Zero(), DefaultBackend(), DefaultAllocator()), matching TensorOperations convention. The old `add_permute!`, `add_braid!`, and `add_transpose!` are deprecated wrappers that emit `Base.depwarn` and forward to the new functions. The `allocator` kwarg is fully threaded through the internal call chain (`add_transform!`, all kernel functions, and `allocate_buffers`). Mooncake AD rules are updated to use the new function names.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace single-method-with-variadics (`backend::AbstractBackend...`) with the TensorOperations-style dispatch chain: four separate overloads per in-place function inserting One()/Zero(), DefaultBackend(), and DefaultAllocator() successively so that the full 7-arg form is the implementation endpoint. Move `allocator` from keyword to positional argument throughout the internal chain (`add_transform!`, all kernel functions, `allocate_buffers`). Non-inplace functions (`permute`, `braid`, `transpose`, `repartition`) gain `backend` as a new keyword alongside the existing `allocator` keyword, keeping the user-facing API ergonomic. Docstrings updated to use TO-style bracket notation showing optional arguments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

After the build completes, the updated documentation will be available here

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant