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

Add blockrange function #633

Closed
mtfishman opened this issue Apr 23, 2021 · 1 comment
Closed

Add blockrange function #633

mtfishman opened this issue Apr 23, 2021 · 1 comment

Comments

@mtfishman
Copy link
Member

Add a function blockrange which returns the range of Index values of a specified block or QN. For example:

# Get the range of values of a block
blockrange(i::Index, b::Block) = _blockrange(i, Int(b))
function _blockrange(i::Index, b)
  start = 1
  for j in 1:b-1
    start += ITensors.blockdim(i, j)
  end
  return start:start+ITensors.blockdim(i, b)-1
end

function blockrange(i::Index, find_qn::QN)
  # The block the QN is in
  b = ITensors.findfirstblock(x -> qn(x) == find_qn, i)
  return blockrange(i, b)
end

The version taking QN may be ambiguous since multiple blocks could have the same QN.

This could also work for an ITensor, where a block or a tuple of QNs in each dimension is specified and it returns a CartesianIndices object for the range of values of the block.

See the discussion here for a motivating example: http://itensor.org/support/2879/extract-project-iqtensor-on-a-qn-subspace

@mtfishman
Copy link
Member Author

I think better names for this could be eachindex to match with Julia's usage of index or eachval to match with the ITensor usage of val as a value an Index gets set to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant