Commit 9f56e9e9f4f32d6e1c7bdbefb96c4bd90e9fbb08

Authored by Josh Klontz
1 parent 17ed6bf8

micro optimizations

openbr/plugins/classification/boostedforest.cpp
@@ -151,16 +151,18 @@ private: @@ -151,16 +151,18 @@ private:
151 151
152 float classifyPreprocessed(const Template &t, float *confidence) const 152 float classifyPreprocessed(const Template &t, float *confidence) const
153 { 153 {
  154 + const bool categorical = representation->maxCatCount() > 0;
  155 +
154 float sum = 0; 156 float sum = 0;
155 for (int i = 0; i < classifiers.size(); i++) { 157 for (int i = 0; i < classifiers.size(); i++) {
156 - Node *node = classifiers[i]; 158 + const Node *node = classifiers[i];
157 159
158 while (node->left) { 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 node = (node->subset[c >> 5] & (1 << (c & 31))) ? node->left : node->right; 164 node = (node->subset[c >> 5] & (1 << (c & 31))) ? node->left : node->right;
162 } else { 165 } else {
163 - double val = representation->evaluate(t, node->featureIdx);  
164 node = val <= node->threshold ? node->left : node->right; 166 node = val <= node->threshold ? node->left : node->right;
165 } 167 }
166 } 168 }