Skip to content

Commit

Permalink
Fix string preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored and vigsterkr committed Jun 4, 2018
1 parent 9d875ed commit ba362a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/shogun/preprocessor/StringPreprocessor.cpp
Expand Up @@ -96,6 +96,8 @@ namespace shogun
"has to be of C_STRING (%d) class!\n",
features->get_feature_class(), C_STRING);

SG_REF(features);

auto string_features = features->as<CStringFeatures<ST>>();
auto string_list = string_features->get_features();

Expand All @@ -106,7 +108,12 @@ namespace shogun

auto processed = new CStringFeatures<ST>(
string_list, string_features->get_alphabet());
SG_UNREF(features);

// FIXME: we should prevent freeing input features here because SGString
// doesn't have ref counting, which will be freed after unref.
// fix this after #4248
if (features->ref_count() > 1)
SG_UNREF(features);
SG_REF(processed);

return processed;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/kernel/CommUlongStringKernel_unittest.cc
Expand Up @@ -38,8 +38,8 @@ TEST(CommUlongStringKernel, kernel_matrix)
l_feats->obtain_from_char(s_feats, 5-1, 5, 0, false);
CSortUlongString* preproc = new CSortUlongString();
preproc->fit(l_feats);
l_feats->add_preprocessor(preproc);
l_feats->apply_preprocessor();
l_feats = preproc->apply(l_feats)->as<CStringFeatures<uint64_t>>();

CCommUlongStringKernel* kernel = new CCommUlongStringKernel(l_feats, l_feats);
CIdentityKernelNormalizer* normalizer = new CIdentityKernelNormalizer();
kernel->set_normalizer(normalizer);
Expand Down

0 comments on commit ba362a0

Please sign in to comment.