Skip to content

Rework index manipulation API#416

Open
lkdvos wants to merge 23 commits intomainfrom
ld-indexmanipulations
Open

Rework index manipulation API#416
lkdvos wants to merge 23 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.

@github-actions
Copy link
Copy Markdown
Contributor

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

@lkdvos lkdvos force-pushed the ld-indexmanipulations branch from f45ab42 to 2841304 Compare April 26, 2026 12:57
@lkdvos
Copy link
Copy Markdown
Member Author

lkdvos commented Apr 26, 2026

This might also resolve #413, where I tried to compute cond with eigh_vals instead of LinearAlgebra.eigvals.

@lkdvos lkdvos force-pushed the ld-indexmanipulations branch 3 times, most recently from ff15f1e to c4408b3 Compare April 26, 2026 21:33
@lkdvos lkdvos marked this pull request as ready for review April 26, 2026 22:02
@lkdvos lkdvos requested review from Jutho and kshyatt April 26, 2026 22:03
@lkdvos lkdvos linked an issue Apr 26, 2026 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

❌ Patch coverage is 89.83957% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tensors/indexmanipulations.jl 89.44% 17 Missing ⚠️
ext/TensorKitMooncakeExt/indexmanipulations.jl 90.00% 1 Missing ⚠️
src/tensors/tensoroperations.jl 50.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
ext/TensorKitAMDGPUExt/roctensormap.jl 52.11% <100.00%> (+0.68%) ⬆️
ext/TensorKitCUDAExt/cutensormap.jl 74.32% <100.00%> (-0.35%) ⬇️
src/TensorKit.jl 13.79% <ø> (ø)
src/planar/planaroperations.jl 72.79% <100.00%> (ø)
src/tensors/braidingtensor.jl 70.39% <100.00%> (ø)
src/tensors/treetransformers.jl 83.16% <100.00%> (+0.44%) ⬆️
ext/TensorKitMooncakeExt/indexmanipulations.jl 96.11% <90.00%> (ø)
src/tensors/tensoroperations.jl 93.95% <50.00%> (ø)
src/tensors/indexmanipulations.jl 90.04% <89.44%> (+16.10%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos lkdvos force-pushed the ld-indexmanipulations branch 2 times, most recently from 6fcbef9 to b8c6b86 Compare April 27, 2026 13:32
lkdvos and others added 15 commits April 28, 2026 16:41
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>
@lkdvos lkdvos force-pushed the ld-indexmanipulations branch from a0bc84b to 2c44dca Compare April 28, 2026 20:41
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