Skip to content

Commit

Permalink
Refactor _interleave
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Jul 2, 2024
1 parent d06cca1 commit 1827d6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/auxiliary/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions src/tensors/tensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1827d6a

Please sign in to comment.