From 09b3ac238adfc9cd37822168d63af691d2513b99 Mon Sep 17 00:00:00 2001 From: 1ucasvb Date: Wed, 13 Mar 2019 06:17:51 -0300 Subject: [PATCH 1/3] Adding set operations, .filter() and .select(). --- docs/cppv2/classes/indexset.md | 45 ++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/cppv2/classes/indexset.md b/docs/cppv2/classes/indexset.md index 8365d5da..c76fbf90 100644 --- a/docs/cppv2/classes/indexset.md +++ b/docs/cppv2/classes/indexset.md @@ -2,16 +2,16 @@ Container for storing indices. -The following documentation refers to IndexSet, but also applies to -IQIndexSet, which is implemented using the same template class. -For IQIndexSet, just replace all usage of the `Index` type with +The following documentation refers to `IndexSet`, but also applies to +`IQIndexSet`, which is implemented using the same template class. +For `IQIndexSet`, just replace all usage of the `Index` type with the type `IQIndex`. * `IndexSet` is an alias for `IndexSetT` * `IQIndexSet` is an alias for `IndexSetT` -IndexSet and IQIndexSet are defined in "itensor/indexset.h". Also see "itensor/indexset_impl.h". -An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". +IndexSet and `IQIndexSet` are defined in "itensor/indexset.h"`. Also see "itensor/indexset_impl.h". +An `IndexSet` is a subclass of `Range` which is defined in "itensor/tensor/range.h". ## Synopsis ## @@ -140,6 +140,40 @@ An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". Reference to this IndexSet as its parent type, namely `RangeT` where `index_type` is Index for IndexSet or IQIndex for IQIndexSet. +* `.select(index_type type) -> IndexSet` + + Returns a new `IndexSet` containing only the indices of the selected type. + +* `.filter(index_type type) -> IndexSet` + + Returns a new `IndexSet` containing all indices which are *not* of the specified type. + +## Binary set operations + +Given two `IndexSet` instances A and B, we can do binary set operations between them and obtain +a new `IndexSet` instance. The available operations are: + +* `.setUnion(IndexSet & other) -> IndexSet` + + `A.setUnion(B)` returns a new `IndexSet` which contains the collected indices from both sets. + +* `.setIntersection(IndexSet & other) -> IndexSet` + + `A.setIntersection(B)` returns a new `IndexSet` which contains all the common indices of both + sets. In a tensor contraction, these are the indices which are being summed over. + +* `.setDifference(IndexSet & other) -> IndexSet` + + `A.setDifference(B)` returns a new `IndexSet` which contains the indices of A which are not also + in B. Note that, in contrast with the previous two, this operation is not symmetric: + `B.setDifference(A)` will return a different set. + +* `.setSymmetricDifference(IndexSet & other) -> IndexSet` + + `A.setSymmetricDifference(B)` returns a new `IndexSet` which contains the indices which are unique + to either A or B not present in both. This is the complement of the intersection of the two + sets. In a tensor contraction, this is the set of indices of the resulting tensor. + ## Other Class Methods and Features * `.dag()` @@ -296,6 +330,7 @@ An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". Change prime level of all indices having prime level `plevold` to `plevnew`. (Optionally only if their IndexType matches `t`.) + ## Other IndexSet Functions From 1773fd820f9450ecc61076701a7d49aae89b3105 Mon Sep 17 00:00:00 2001 From: 1ucasvb Date: Wed, 13 Mar 2019 06:17:51 -0300 Subject: [PATCH 2/3] Adding set operations, .filter() and .select(). --- docs/cppv2/classes/indexset.md | 48 ++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/docs/cppv2/classes/indexset.md b/docs/cppv2/classes/indexset.md index 8365d5da..6e199489 100644 --- a/docs/cppv2/classes/indexset.md +++ b/docs/cppv2/classes/indexset.md @@ -2,16 +2,16 @@ Container for storing indices. -The following documentation refers to IndexSet, but also applies to -IQIndexSet, which is implemented using the same template class. -For IQIndexSet, just replace all usage of the `Index` type with +The following documentation refers to `IndexSet`, but also applies to +`IQIndexSet`, which is implemented using the same template class. +For `IQIndexSet`, just replace all usage of the `Index` type with the type `IQIndex`. * `IndexSet` is an alias for `IndexSetT` * `IQIndexSet` is an alias for `IndexSetT` -IndexSet and IQIndexSet are defined in "itensor/indexset.h". Also see "itensor/indexset_impl.h". -An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". +IndexSet and `IQIndexSet` are defined in "itensor/indexset.h"`. Also see "itensor/indexset_impl.h". +An `IndexSet` is a subclass of `Range` which is defined in "itensor/tensor/range.h". ## Synopsis ## @@ -140,6 +140,40 @@ An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". Reference to this IndexSet as its parent type, namely `RangeT` where `index_type` is Index for IndexSet or IQIndex for IQIndexSet. +* `.select(index_type type) -> IndexSet` + + Returns a new `IndexSet` containing only the indices of the selected type. + +* `.filter(index_type type) -> IndexSet` + + Returns a new `IndexSet` containing all indices which are *not* of the specified type. + +## Binary set operations + +Given two `IndexSet` instances A and B, we can do binary set operations between them and obtain +a new `IndexSet` instance. The available operations are: + +* `.setUnion(IndexSet & other) -> IndexSet` + + `A.setUnion(B)` returns a new `IndexSet` which contains the collected indices from both sets. + +* `.setIntersection(IndexSet & other) -> IndexSet` + + `A.setIntersection(B)` returns a new `IndexSet` which contains all the common indices of both + sets. In a tensor contraction, these are the indices which are being summed over. + +* `.setDifference(IndexSet & other) -> IndexSet` + + `A.setDifference(B)` returns a new `IndexSet` which contains the indices of A which are not also + in B. Note that, in contrast with the previous two, this operation is not symmetric: + `B.setDifference(A)` will return a different set. + +* `.setSymmetricDifference(IndexSet & other) -> IndexSet` + + `A.setSymmetricDifference(B)` returns a new `IndexSet` which contains the indices which are unique + to either A or B not present in both. This is the complement of the intersection of the two + sets. In a tensor contraction, this is the set of indices of the resulting tensor. + ## Other Class Methods and Features * `.dag()` @@ -296,6 +330,7 @@ An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". Change prime level of all indices having prime level `plevold` to `plevnew`. (Optionally only if their IndexType matches `t`.) + ## Other IndexSet Functions @@ -335,6 +370,9 @@ An IndexSet is a subclass of Range which is defined in "itensor/tensor/range.h". Return the size of the largest Index in the set. +* `.vector() -> std::vector` + + Returns the set of indices as a vector of `Index` elements.
_This page current as of version 2.0.7_ From 832ddf2104a8b96974585408f5efc7d78fd5981c Mon Sep 17 00:00:00 2001 From: 1ucasvb Date: Wed, 13 Mar 2019 07:22:27 -0300 Subject: [PATCH 3/3] Fixing filter\select -> filterType\selectType --- docs/cppv2/classes/indexset.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cppv2/classes/indexset.md b/docs/cppv2/classes/indexset.md index 6e199489..d6b41dec 100644 --- a/docs/cppv2/classes/indexset.md +++ b/docs/cppv2/classes/indexset.md @@ -140,11 +140,11 @@ An `IndexSet` is a subclass of `Range` which is defined in "itensor/tensor/range Reference to this IndexSet as its parent type, namely `RangeT` where `index_type` is Index for IndexSet or IQIndex for IQIndexSet. -* `.select(index_type type) -> IndexSet` +* `.selectType(index_type type) -> IndexSet` Returns a new `IndexSet` containing only the indices of the selected type. -* `.filter(index_type type) -> IndexSet` +* `.filterType(index_type type) -> IndexSet` Returns a new `IndexSet` containing all indices which are *not* of the specified type.