MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / LabelMap

Class LabelMap

paddle/phi/kernels/impl/einsum_kernel_impl.h:76–102  ·  view source on GitHub ↗

map a label('a' - 'z') -> int64_t, O(1) speed.

Source from the content-addressed store, hash-verified

74
75// map a label('a' - 'z') -> int64_t, O(1) speed.
76class LabelMap {
77 constexpr static int N =
78 26 + 1; // 'a' - 'z' + '.', '.' is for broadcast dims
79 int64_t default_value;
80 int64_t map[N];
81
82 public:
83 explicit LabelMap(int64_t default_value = 0) {
84 this->default_value = default_value;
85 for (size_t i = 0; i < N; ++i) map[i] = default_value;
86 }
87 int64_t& operator[](int label) {
88 int i = label - 'a';
89 return map[i];
90 }
91 int64_t operator[](int label) const {
92 int i = label - 'a';
93 return map[i];
94 }
95 bool exist(char label) { return !is_default(label); }
96
97 private:
98 // non-exist is present by is_default
99 bool is_default(char label) {
100 return (*this)[static_cast<int>(label)] == default_value;
101 }
102};
103
104inline std::string label_to_string(const std::vector<char>& all_labels,
105 const LabelMap& label2type) {

Callers 4

EinsumInferMetaFunction · 0.85
EinsumGradKernelFunction · 0.85
PerformContractionFunction · 0.85
EinsumKernelImplFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected