Commit 9f56e9e9f4f32d6e1c7bdbefb96c4bd90e9fbb08
1 parent
17ed6bf8
micro optimizations
Showing
1 changed file
with
6 additions
and
4 deletions
openbr/plugins/classification/boostedforest.cpp
| ... | ... | @@ -151,16 +151,18 @@ private: |
| 151 | 151 | |
| 152 | 152 | float classifyPreprocessed(const Template &t, float *confidence) const |
| 153 | 153 | { |
| 154 | + const bool categorical = representation->maxCatCount() > 0; | |
| 155 | + | |
| 154 | 156 | float sum = 0; |
| 155 | 157 | for (int i = 0; i < classifiers.size(); i++) { |
| 156 | - Node *node = classifiers[i]; | |
| 158 | + const Node *node = classifiers[i]; | |
| 157 | 159 | |
| 158 | 160 | while (node->left) { |
| 159 | - if (representation->maxCatCount() > 0) { | |
| 160 | - int c = (int)representation->evaluate(t, node->featureIdx); | |
| 161 | + const float val = representation->evaluate(t, node->featureIdx); | |
| 162 | + if (categorical) { | |
| 163 | + const int c = (int)val; | |
| 161 | 164 | node = (node->subset[c >> 5] & (1 << (c & 31))) ? node->left : node->right; |
| 162 | 165 | } else { |
| 163 | - double val = representation->evaluate(t, node->featureIdx); | |
| 164 | 166 | node = val <= node->threshold ? node->left : node->right; |
| 165 | 167 | } |
| 166 | 168 | } | ... | ... |