diff --git src/machine/cxx/SVM.cc src/machine/cxx/SVM.cc
index 142b4e7..70fcff7 100644
|
|
blitz::Array<uint8_t,1> mach::svm_pickle |
178 | 178 | return buffer; |
179 | 179 | } |
180 | 180 | |
| 181 | static boost::shared_ptr<svm_model> make_model(const char* filename) { |
| 182 | boost::shared_ptr<svm_model> retval(svm_load_model(filename), |
| 183 | std::ptr_fun(svm_model_free)); |
| 184 | #if LIBSVM_VERSION > 315 |
| 185 | if (retval) retval->sv_indices = 0; ///< force initialization: see ticket #109 |
| 186 | #endif |
| 187 | return retval; |
| 188 | } |
| 189 | |
181 | 190 | /** |
182 | 191 | * Reverts the pickling process, returns the model |
183 | 192 | */ |
… |
… |
boost::shared_ptr<svm_model> mach::svm_unpickle |
193 | 202 | binfile.close(); |
194 | 203 | |
195 | 204 | //reload the file using the appropriate libsvm loading method |
196 | | boost::shared_ptr<svm_model> retval(svm_load_model(tmp_filename), |
197 | | std::ptr_fun(svm_model_free)); |
| 205 | boost::shared_ptr<svm_model> retval = make_model(tmp_filename); |
| 206 | |
| 207 | if (!retval) { |
| 208 | boost::format s("cannot open model file '%s'"); |
| 209 | s % tmp_filename; |
| 210 | throw std::runtime_error(s.str()); |
| 211 | } |
198 | 212 | |
199 | 213 | //unlinks the temporary file |
200 | 214 | boost::filesystem::remove(tmp_filename); |
… |
… |
void mach::SupportVector::reset() { |
224 | 238 | } |
225 | 239 | |
226 | 240 | mach::SupportVector::SupportVector(const std::string& model_file): |
227 | | m_model(svm_load_model(model_file.c_str()), std::ptr_fun(svm_model_free)) |
| 241 | m_model(make_model(model_file.c_str())) |
228 | 242 | { |
229 | 243 | if (!m_model) { |
230 | 244 | boost::format s("cannot open model file '%s'"); |