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
Additional IndexSet features (union, intersection, difference, symmetric difference, select, filter, vector) #210
base: v2
Are you sure you want to change the base?
Conversation
Hi Lucas, thanks for this. I agree it's definitely needed - we just usually have an approach of not adding things until we know of a particular use-case for them. Since you have identified one for your own code, we should add this. I'd like to make some changes, though, including the following:
Matt or I can make those changes though. However, you are free to take a swing at them too if you are so inclined! I added your name to the website list of contributors for the other pull & will give you a badge for this one too. Thanks. |
EDIT: I went ahead and decided to give it a go. I think everything should be OK now! Hello, Miles. I totally understand the approach, it's very reasonable. I'm glad you also find this useful. As for the changes you suggested, they are all fine with me. I used (Edit: since There's also (Edit: this is now implemented in the latest commit.) Regarding the use of (Edit: I actually decided to give it a go, and I think it should be fine now.)
Thank you! If you could change it to "Lucas Vieira" at Federal University of Minas Gerais, following the convention of others in the list, and link to my site instead, I'd appreciate it. (Edit: I also took the liberty of making a pull request for these changes.) |
OK, I decided to give it a go and rewrite the functions to have better names and better implementations. Since I also added symmetric difference for completeness (also in the unit test), and created another pull request for the documentation of all these features as per this last commit. I think they should all be OK now, and they're only using internal features of the library. It's very self-contained! :) I hope this is good enough work. Cheers! |
Hi, this pull request is a very good idea, and I think it can help clean up a lot of code! I want to point out that I recently added very similar functionality to ITensor V3 (on the rc3 branch). The functions I added can be found here: https://github.com/ITensor/ITensor/blob/rc3/itensor/indexset.h#L709, and the implementations are in I think it covers all of the functions you added in this pull request. I chose some non-traditional names for these operations, to be consistent with previous definitions of similar functions that have been around in ITensor (for example, I use the name Also, I prefer these to be free functions rather than member functions, since we are trying to stick to a convention that member functions are ones that modify while all other functions are free (and these all return new IndexSets, rather than modify an input IndexSet). Would you mind updating this pull request to reflect the same names and styles as the V3 versions, so that we can have this functionality in V2 as well? Also note that in V3, I have added conversion of various collections like Cheers, |
Excellent, Matt! I'll make the changes you requested and update the request. I haven't looked much into V3 yet, but I think I'll definitely keep an eye on it now. Cheers! |
I've been working on some high-rank tensors with many indices of various types, and I find that ITensor was lacking a way to easily manipulate many indices at once. The functions
commonIndex
andfindtype
only return the first match, which is completely insufficient in such cases where multiple indices are required.These additions to the
IndexSet
class allow us to perform these set-based operations quickly and easily, and immediately use them on any function which acceptsIndexSet
as an input. If they don't (unfortunately, some do not), there's also a.vector()
method which returns the vector of indices which is typically accepted.Example
Given two
IndexSet
instancesA = {i,j,k,l}
andB = {k,l,m}
A+B = {i,j,k,l,m}
: collect all unique indices from two setsA*B = {k,l}
: indices in both sets (this extends commonIndex)A-B = {i,j}
andB-A = {m}
: indices only onA
or only onB
The
.select()
and.filter()
methods allow the user to further manipulate such sets by type.See code comments for more details. Proper unit tests were also included in these commits.