From f0bd8691ff5cc485e7186179284484bf7b228379 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Wed, 1 Jul 2026 14:02:10 -0400 Subject: [PATCH] Drop a per-call closure allocation in the bipermutedimsopadd! axis check ## Summary Removes a per-call heap allocation in `check_input` for `bipermutedimsopadd!`. The axis check built its comparison tuple with `ntuple(d -> op(axes(src, perm[d])), ndims(dest))`, whose index closure captures runtime values (`op`, `src`, `perm`) and so is heap-allocated on every call. Mapping over the permutation tuple directly with `map(p -> op(axes(src, p)), perm)` is unrolled over the concrete tuple and allocates nothing, and is equivalent because `ndims(dest) == length(perm)` is already checked just above. A 2x2 `permutedimsadd!` drops from 2 allocations (64 B) to 1 (16 B). --- Project.toml | 2 +- src/permutedimsadd.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index bc6c8fb..bb49932 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "TensorAlgebra" uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" -version = "0.14.0" +version = "0.14.1" authors = ["ITensor developers and contributors"] [workspace] diff --git a/src/permutedimsadd.jl b/src/permutedimsadd.jl index 70d6352..d791df6 100644 --- a/src/permutedimsadd.jl +++ b/src/permutedimsadd.jl @@ -28,7 +28,7 @@ function check_input( perm = (perm_codomain..., perm_domain...) ndims(dest) == length(perm) || throw(DimensionMismatch("destination ndims does not match permutation length")) - axes(dest) == ntuple(d -> op(axes(src, perm[d])), ndims(dest)) || + axes(dest) == map(p -> op(axes(src, p)), perm) || throw(DimensionMismatch("destination axes do not match permuted source axes")) return nothing end