From 1827d6a3c634f47b2a6835c29bcf554f7db28386 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Tue, 2 Jul 2024 07:33:28 +0200 Subject: [PATCH] Refactor _interleave --- src/auxiliary/auxiliary.jl | 10 ++++++++++ src/tensors/tensor.jl | 6 ------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/auxiliary/auxiliary.jl b/src/auxiliary/auxiliary.jl index e8c9445b..3cf0da46 100644 --- a/src/auxiliary/auxiliary.jl +++ b/src/auxiliary/auxiliary.jl @@ -49,3 +49,13 @@ end else using Base: @constprop end + +""" + _interleave(a::NTuple{N}, b::NTuple{N}) -> NTuple{2N} + +Interleave two tuples of the same length. +""" +_interleave(::Tuple{}, ::Tuple{}) = () +function _interleave(a::NTuple{N}, b::NTuple{N}) where {N} + return (a[1], b[1], _interleave(tail(a), tail(b))...) +end diff --git a/src/tensors/tensor.jl b/src/tensors/tensor.jl index 64c20e7d..cf4f3d7b 100644 --- a/src/tensors/tensor.jl +++ b/src/tensors/tensor.jl @@ -395,12 +395,6 @@ function TensorMap(data::DenseArray, codom::ProductSpace{S,N₁}, dom::ProductSp return t end -function _interleave(a::Base.Dims{N}, b::Base.Dims{N}) where {N} - return ntuple(2N) do i - halfi, rem = divrem(i, 2) - return getindex(rem == 1 ? a : b, halfi + rem) - end -end # Efficient copy constructors #----------------------------- Base.copy(t::TrivialTensorMap) = typeof(t)(copy(t.data), t.codom, t.dom)