Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] Add option to ignore space error in replaceind #1455

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/indexset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ function replaceinds_space_error(is, inds1, inds2, i1, i2)
""")
end

function replaceinds(is::Indices, inds1, inds2)
function replaceinds(is::Indices, inds1, inds2; ignoreSpaceError::Bool=false)
is1 = inds1
poss = indexin(is1, is)
is_tuple = Tuple(is)
Expand All @@ -606,15 +606,17 @@ function replaceinds(is::Indices, inds1, inds2)
i1 = is_tuple[pos]
i2 = inds2[j]
i2 = setdir(i2, dir(i1))
if space(i1) ≠ space(i2)
if !ignoreSpaceError && space(i1) ≠ space(i2)
replaceinds_space_error(is, inds1, inds2, i1, i2)
end
is_tuple = setindex(is_tuple, i2, pos)
end
return (is_tuple)
end

replaceind(is::Indices, i1::Index, i2::Index) = replaceinds(is, (i1,), (i2,))
function replaceind(is::Indices, i1::Index, i2::Index; ignoreSpaceError::Bool=false)
return replaceinds(is, (i1,), (i2,); ignoreSpaceError)
end

function replaceind(is::Indices, i1::Index, i2::Indices)
length(i2) != 1 &&
Expand Down
Loading