Skip to content

Commit

Permalink
[add] decode context class to solve multi-threaded error
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Nov 13, 2014
1 parent 9bc1a9c commit 46ab067
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/segmentor/decode_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef __LTP_SEGMENTOR_DECODE_CONTEXT_H__
#define __LTP_SEGMENTOR_DECODE_CONTEXT_H__

namespace ltp {
namespace segmentor {

class DecodeContext {
public:
//! the gold features.
math::SparseVec correct_features;
//! the predicted features.
math::SparseVec predicted_features;
//!
math::SparseVec updated_features;

//! The feature cache.
math::Mat< math::FeatureVector *> uni_features;

DecodeContext() {}
~DecodeContext() {}

void clear() {
if (uni_features.total_size() > 0) {
int d1 = uni_features.nrows();
int d2 = uni_features.ncols();
for (int i = 0; i < d1; ++ i) {
if (uni_features[i][0]) {
uni_features[i][0]->clear();
}
for (int j = 0; j < d2; ++ j) {
if (uni_features[i][j]) {
delete uni_features[i][j];
}
}
}
}

uni_features.dealloc();
correct_features.zero();
predicted_features.zero();
}
};

} // end for namespace segmentor
} // end for namespace ltp

#endif // end for __LTP_SEGMENTOR_DECODE_CONTEXT_H__

0 comments on commit 46ab067

Please sign in to comment.