Class Index¶
Defined in File index.hpp
Nested Relationships¶
Nested Types¶
Inheritance Relationships¶
Base Type¶
public sequant::Taggable
(Class Taggable)
Class Documentation¶
-
class Index : public sequant::Taggable¶
Index = label + IndexSpace.
Note
Unlike SeQuant1’s ParticleIndex, this Index supports dependencies between indices to be able to express e.g. hierarchical partitioning of index spaces or hierarchical nesting of spaces
Note
Index label can be plain (
label
) or composite (label_ordinal
) wherelabel
is a string of characters excluding ‘_’, andordinal
is an integer less than the value returned by min_tmp_label() .Note
Index and other SeQuant classes currently use wide characters to represent labels and other strings; this goes against some popular recommendations to use narrow strings (bytestrings) everywhere. The rationale for such choice makes “character”-centric operations easy without the need to grok Unicode and to introduce extra dependencies such as [https://github.com/unicode-org/icu](ICU). Many functions accept bytestrings as input, but they are recoded to wide (but UTF-8 encoded) strings. For optimal efficiency and simplicity users are recommended to use wide strings until further notice.
Public Types
-
using index_vector = container::vector<Index>¶
protoindices cannot be represented by small_vector because it does not accept incomplete types, see https://www.boost.org/doc/libs/master/doc/html/container/main_features.html#container.main_features.containers_of_incomplete_types N.B. hard-coding alignment should lift this restriction but it seems that alignof is still invoked (for no good reason)
Public Functions
-
Index() = default¶
-
template<typename String, typename = std::enable_if_t<meta::is_basic_string_convertible_v<std::remove_reference_t<String>>>>
inline Index(String &&label, const IndexSpace &space, IndexList proto_indices, bool symmetric_proto_indices = true)¶ - Parameters:
label – the label, does not need to be unique
space – (a const ref to) the IndexSpace object that specifies to this space this object belongs
proto_indices – labels of proto indices (all must be unique, i.e. duplicates are not allowed)
symmetric_proto_indices – if true, proto_indices can be permuted at will and will always be sorted
-
template<typename String, typename = std::enable_if_t<meta::is_basic_string_convertible_v<std::remove_reference_t<String>>>>
inline Index(String &&label, const IndexSpace &space, container::vector<Index> proto_indices, bool symmetric_proto_indices = true)¶ - Parameters:
label – the label, does not need to be unique
space – (a const ref to) the IndexSpace object that specifies to this space this object belongs
proto_indices – labels of proto indices (all must be unique, i.e. duplicates are not allowed)
symmetric_proto_indices – if true, proto_indices can be permuted at will and will always be sorted
-
template<typename String, typename = std::enable_if_t<meta::is_basic_string_convertible_v<std::remove_reference_t<String>>>>
inline Index(String &&label)¶ See also
IndexSpace::instance )
- Parameters:
label – the index label, does not need to be unique, but must be convertible into an IndexSpace (
-
template<typename IndexOrIndexLabel, typename I, typename = std::enable_if_t<(std::is_same_v<std::decay_t<IndexOrIndexLabel>, Index> || meta::is_basic_string_convertible_v<std::decay_t<IndexOrIndexLabel>>)>>
inline Index(IndexOrIndexLabel &&index_or_index_label, std::initializer_list<I> proto_indices, bool symmetric_proto_indices = true)¶ constructs an Index using an existing Index’s label and space and a list of proto indices
- Template Parameters:
IndexOrIndexLabel – either Index or a type that can be viewed/converted to a string (i.e.,
meta::is_basic_string_convertible_v<std::decay_t<IndexOrIndexLabel>>==true
)
- Parameters:
index_or_index_label – an Index or a label, does not need to be unique
proto_indices – list of proto indices, or their labels (all must be unique, i.e. duplicates are not allowed)
symmetric_proto_indices – if true, proto_indices can be permuted at will and will always be sorted
-
template<typename IndexOrIndexLabel, typename IndexContainer, typename = std::enable_if_t<std::is_convertible_v<std::remove_reference_t<IndexContainer>, container::vector<Index>> && (std::is_same_v<std::decay_t<IndexOrIndexLabel>, Index> || meta::is_wstring_convertible_v<std::decay_t<IndexOrIndexLabel>>)>>
inline Index(IndexOrIndexLabel &&index_or_index_label, IndexContainer &&proto_indices, bool symmetric_proto_indices = true)¶ constructs an Index using an existing Index’s label and space and a list of proto indices
- Template Parameters:
IndexOrIndexLabel – either Index or a type that can be viewed/converted to a string (i.e.,
meta::is_basic_string_convertible_v<std::decay_t<IndexOrIndexLabel>>==true
)- Parameters:
index_or_index_label – an Index or a label, does not need to be unique
proto_indices – list of proto indices (all must be unique, i.e. duplicates are not allowed)
symmetric_proto_indices – if true, proto_indices can be permuted at will and will always be sorted
-
template<typename IndexOrIndexLabel>
inline Index(IndexOrIndexLabel &&index_or_index_label, IndexSpace space)¶ constructs an Index using an existing Index’s label and proto indices (if any) and an IndexSpace
- Template Parameters:
IndexOrIndexLabel – either Index or a type that can be viewed/converted to a string (i.e.,
meta::is_basic_string_convertible_v<std::decay_t<IndexOrIndexLabel>>==true
)- Parameters:
index_or_index_label – [in] an Index object or a label
space – (a const ref to) the IndexSpace object that specifies the space to which ths object refers to
-
inline Index replace_space(IndexSpace space) const¶
constructs an Index using this object’s label and proto indices (if any) and a new IndexSpace
- Parameters:
space – (a const ref to) the IndexSpace object that specifies the space to which ths object refers to
-
inline Index replace_qns(QuantumNumbersAttr qns) const¶
constructs an Index using this object’s label and proto indices (if any), its IndexSpaceType, and a new set of QuantumNumbers
-
inline void reset_tag() const¶
resets tag of this and its protoindices (if any)
-
inline std::wstring_view label() const¶
Note
label format is
base
orbase_ordinal
Warning
this does not include the proto index labels, use Index::full_label() instead
- Returns:
the label as a UTF-8 encoded wide-character string
-
inline std::pair<std::wstring_view, std::wstring_view> split_label() const¶
Warning
this does not include the proto index labels
- Returns:
the label split into base and ordinal parts; the ordinal part is empty, if missing
-
std::string ascii_label() const¶
Replaces non-ascii wstring characters with human-readable analogs, each such UTF-8 character will be encoded by one or more chars.
Note
Maps:
↑
->a
,↓
->b
, and all greek characters to their english language equivalents (e.g.α
->alpha
,Ξ
->XI
, etc.)Warning
not to be used with proto indices
- Returns:
A string label representable in ASCII encoding
-
std::string to_string() const¶
Note
equivalent to
sequant::to_string(this->label())
Warning
not to be used with proto indices
- Returns:
A UTF-8 encoded narrow-character string label
-
inline std::wstring_view full_label() const¶
Warning
this includes the proto index labels (if any), use Index::label() instead if only want the label
- Returns:
the full label as a UTF-8 encoded wide-character string
-
template<typename WS, typename = std::enable_if_t<(meta::is_wstring_convertible_v<std::decay_t<WS>>)>>
inline std::wstring make_label_plus_suffix(WS &&suffix) const¶ makes a new label by appending a suffix to the label
Appends
suffix
to the label itself (if plain) or to its core (if composite)- Parameters:
suffix – a string to append to the label
- Returns:
this->label()
withsuffix
appended
-
template<typename WS, typename = std::enable_if_t<(meta::is_wstring_convertible_v<std::decay_t<WS>>)>>
inline std::wstring make_label_minus_substring(WS &&substr) const¶ makes a new label by removing a substring from the label
Removes
substr
from the label itself (if plain) or from its core (if composite)- Parameters:
substr – a string to remove from the label
- Returns:
this->label()
withsubstr
removed
-
inline const IndexSpace &space() const¶
- Returns:
the IndexSpace object
-
inline bool has_proto_indices() const¶
- Returns:
true if this index has proto indices
-
inline const index_vector &proto_indices() const¶
- Returns:
the list of proto indices of this index
-
inline bool symmetric_proto_indices() const¶
- Returns:
true if the index is symmetric with respect to the permutation of protoindices
-
inline Index drop_proto_indices() const¶
drops the proto indices from this Index
- Returns:
a copy of this Index without proto indices
-
std::wstring to_latex() const¶
-
inline auto proto_indices_color() const¶
See also
- Returns:
the color of the protoindices
-
inline auto color() const¶
Color of an Index = hashed IndexSpace + IndexSpace objects of the protoindices
- Returns:
the color of this object
Public Static Functions
-
static inline Index make_tmp_index(const IndexSpace &space)¶
creates a globally-unique temporary index in space
space
. The label of the resulting index =IndexSpace::base_key(space)
+ ‘_’ + temporary counter. Each call increments the current tmp counter (see next_tmp_index() ) . To make neater temporary indices unique in a given scope (e.g. a single term in an expression) use IndexFactory.- Parameters:
space – an IndexSpace object
- Returns:
a unique temporary index in space
space
-
template<typename IndexRange, typename = std::enable_if_t<meta::is_range_v<std::remove_reference_t<IndexRange>>>>
static inline Index make_tmp_index(const IndexSpace &space, IndexRange &&proto_indices, bool symmetric_proto_indices = true)¶ creates a globaly-unique temporary index in space
space
. The label of the resulting index =IndexSpace::base_key(space)
+ ‘_’ + temporary counter. Each call increments the current tmp counter (see next_tmp_index() ) . To make neater temporary indices unique in a given scope (e.g. a single term in an expression) use IndexFactory.- Parameters:
space – an IndexSpace object
proto_indices – list of proto indices (all must be unique, i.e. duplicates are not allowed)
symmetric_proto_indices – if true, proto_indices can be permuted at will and will always be sorted
- Returns:
a unique temporary index in space
space
-
static inline std::pair<std::wstring_view, std::wstring_view> make_split_label(std::wstring_view label)¶
- Parameters:
label – an Index label (e.g., returned by Index::label())
- Returns:
label
split into base and ordinal parts; the ordinal part is empty, if missing
-
static inline std::wstring make_merged_label(std::wstring_view base_label, std::wstring_view ordinal_label)¶
-
template<typename WS1, typename WS2, typename = std::enable_if_t<(meta::is_wstring_or_view_v<std::decay_t<WS1>> && meta::is_wstring_convertible_v<std::decay_t<WS2>>)>>
static inline std::wstring make_label_plus_suffix(WS1 &&label, WS2 &&suffix)¶ makes a new label by appending a suffix to the label
Appends
suffix
tolabel
itself (if plain) or to its core (if composite)- Parameters:
label – the label to append the suffix to
suffix – a string to append to the label
- Returns:
this->label()
withsuffix
appended
-
template<typename WS1, typename WS2, typename = std::enable_if_t<(meta::is_wstring_or_view_v<std::decay_t<WS1>> && meta::is_wstring_convertible_v<std::decay_t<WS2>>)>>
static inline std::wstring make_label_minus_substring(WS1 &&label, WS2 &&substr)¶ makes a new label by removing a substring from the label
Removes
substr
fromlabel
itself (if plain) or from its core (if composite)- Parameters:
label – the label to remove the substring from
substr – a string to remove from the label
- Returns:
this->label()
withsubstr
removed
-
template<typename Range>
static inline auto proto_indices_color(const Range &protoindex_range)¶ See also
- Parameters:
protoindex_range – a range of Index objects
- Returns:
the color of the protoindices
-
static const std::size_t min_tmp_index()¶
- Returns:
the smallest index of a generated index
-
static inline std::size_t next_tmp_index()¶
- Returns:
a unique temporary index, its value is equal to or greater than that returned by min_tmp_index()
-
static void reset_tmp_index()¶
resets the temporary index counter so that the next call to next_tmp_index() will return the value returned by min_tmp_index()
Warning
should only to be used when reproducibility matters (e.g. unit testing)
-
struct LabelCompare¶
compares Index objects using labels only
Public Types
-
using is_transparent = void¶
-
using is_transparent = void¶
-
using index_vector = container::vector<Index>¶