Tenncor
prop.hpp
Go to the documentation of this file.
1 
8 #include "tag/tag.hpp"
9 
10 #ifndef TAG_PROP_HPP
11 #define TAG_PROP_HPP
12 
13 namespace tag
14 {
15 
17 const std::string commutative_tag = "commutative";
18 
20 const std::string immutable_tag = "immutable";
21 
23 struct PropTag final : public iTag
24 {
25  PropTag (std::string init_label) : labels_({init_label}) {}
26 
28  size_t tag_id (void) const override
29  {
30  return tag_id_;
31  }
32 
34  void absorb (TagptrT&& other) override
35  {
36  std::unordered_set<std::string>& olabels =
37  static_cast<PropTag*>(other.get())->labels_;
38  labels_.insert(olabels.begin(), olabels.end());
39  }
40 
42  TagRepsT get_tags (void) const override;
43 
44 private:
45  std::unordered_set<std::string> labels_;
46 
47  static size_t tag_id_;
48 };
49 
51 struct PropertyRegistry final
52 {
54  tag_reg_(registry) {}
55 
57  void property_tag (teq::TensrefT tens, std::string property)
58  {
59  tag_reg_.add_tag(tens, TagptrT(new PropTag(property)));
60  }
61 
63  bool has_property (const teq::iTensor* tens, std::string property) const;
64 
67 };
68 
71 
73 const std::string props_key = get_reg().register_tagr("properties",
74 [](teq::TensrefT ref, std::string property)
75 {
76  get_property_reg().property_tag(ref, property);
77 });
78 
79 }
80 
81 #endif // TAG_PROP_HPP
PropTag(std::string init_label)
Definition: prop.hpp:25
bool has_property(const teq::iTensor *tens, std::string property) const
Return true if tensor has specified property.
Definition: tag.hpp:25
Registry for associating tensors to tag collectives.
Definition: tag.hpp:165
size_t tag_id(void) const override
Implementation of iTag.
Definition: prop.hpp:28
const std::string props_key
Identifier of property tag.
Definition: prop.hpp:73
PropTag (properties tag) define node properties.
Definition: prop.hpp:23
Definition: group.hpp:17
std::unique_ptr< iTag > TagptrT
Unique pointer of tag.
Definition: tag.hpp:40
std::map< std::string, std::vector< std::string > > TagRepsT
Map tag key to a series of labels.
Definition: tag.hpp:21
static size_t tag_id_
Definition: prop.hpp:47
std::string register_tagr(std::string tag_key, TagrF tagr)
Definition: tag.hpp:232
const std::string commutative_tag
Identifier for commutative property.
Definition: prop.hpp:17
void property_tag(teq::TensrefT tens, std::string property)
Associate property with tensor.
Definition: prop.hpp:57
void absorb(TagptrT &&other) override
Implementation of iTag.
Definition: prop.hpp:34
TagRegistry & tag_reg_
Internal tag registry used to retrieve tensor-property association.
Definition: prop.hpp:66
PropertyRegistry(TagRegistry &registry=get_reg())
Definition: prop.hpp:53
TagRegistry wrapper to tag and check properties on tensors.
Definition: prop.hpp:51
std::unordered_set< std::string > labels_
Definition: prop.hpp:45
TagRegistry & get_reg(void)
Return reference to global tag registry.
Interface of traversible and differentiable nodes with shape information.
Definition: itensor.hpp:36
PropertyRegistry & get_property_reg(void)
Return reference to global property registry.
const std::string immutable_tag
Identifier for immutable property.
Definition: prop.hpp:20
void add_tag(teq::TensrefT tens, TagptrT tag)
Add tag to collective referenced by tens.
Definition: tag.hpp:168
TagRepsT get_tags(void) const override
Implementation of iTag.
std::weak_ptr< iTensor > TensrefT
Tensor weak pointers.
Definition: itensor.hpp:54