diff --git a/src/shogun/preprocessor/DecompressString.cpp b/src/shogun/preprocessor/DecompressString.cpp index 951d75e9a5d..9292de9fd1a 100644 --- a/src/shogun/preprocessor/DecompressString.cpp +++ b/src/shogun/preprocessor/DecompressString.cpp @@ -24,13 +24,6 @@ CDecompressString::~CDecompressString() delete compressor; } -template -bool CDecompressString::init(CFeatures* f) -{ - ASSERT(f->get_feature_class()==C_STRING) - return true; -} - template void CDecompressString::cleanup() { @@ -56,22 +49,19 @@ template bool CDecompressString::apply_to_string_features(CFeatures* f) { int32_t i; - int32_t num_vec=((CStringFeatures*)f)->get_num_vectors(); + auto sf = f->as>(); + int32_t num_vec = sf->get_num_vectors(); for (i=0; i*)f)-> - get_feature_vector(i, len, free_vec); + ST* vec = sf->get_feature_vector(i, len, free_vec); ST* decompressed=apply_to_string(vec, len); - ((CStringFeatures*)f)-> - free_feature_vector(vec, i, free_vec); - ((CStringFeatures*)f)-> - cleanup_feature_vector(i); - ((CStringFeatures*)f)-> - set_feature_vector(i, decompressed, len); + sf->free_feature_vector(vec, i, free_vec); + sf->cleanup_feature_vector(i); + sf->set_feature_vector(i, decompressed, len); } return true; } diff --git a/src/shogun/preprocessor/DecompressString.h b/src/shogun/preprocessor/DecompressString.h index 702d371cd1d..3c7673128ec 100644 --- a/src/shogun/preprocessor/DecompressString.h +++ b/src/shogun/preprocessor/DecompressString.h @@ -43,9 +43,6 @@ template class CDecompressString : public CStringPreprocessor /** destructor */ virtual ~CDecompressString(); - /// initialize preprocessor from features - virtual bool init(CFeatures* f); - /// cleanup virtual void cleanup(); diff --git a/src/shogun/preprocessor/SortUlongString.cpp b/src/shogun/preprocessor/SortUlongString.cpp index f73fffc7a62..2e261dc623a 100644 --- a/src/shogun/preprocessor/SortUlongString.cpp +++ b/src/shogun/preprocessor/SortUlongString.cpp @@ -20,15 +20,6 @@ CSortUlongString::~CSortUlongString() { } -/// initialize preprocessor from features -bool CSortUlongString::init(CFeatures* f) -{ - ASSERT(f->get_feature_class()==C_STRING) - ASSERT(f->get_feature_type()==F_ULONG) - - return true; -} - /// clean up allocated memory void CSortUlongString::cleanup() { @@ -56,14 +47,14 @@ bool CSortUlongString::save(FILE* f) bool CSortUlongString::apply_to_string_features(CFeatures* f) { int32_t i; - int32_t num_vec=((CStringFeatures*)f)->get_num_vectors(); + auto sf = f->as>(); + int32_t num_vec = sf->get_num_vectors(); for (i=0; i*)f)-> - get_feature_vector(i, len, free_vec); + uint64_t* vec = sf->get_feature_vector(i, len, free_vec); ASSERT(!free_vec) // won't work with non-in-memory string features SG_DEBUG("sorting string of length %i\n", len) diff --git a/src/shogun/preprocessor/SortUlongString.h b/src/shogun/preprocessor/SortUlongString.h index 0084398fe17..553d5f7fa0e 100644 --- a/src/shogun/preprocessor/SortUlongString.h +++ b/src/shogun/preprocessor/SortUlongString.h @@ -31,8 +31,6 @@ class CSortUlongString : public CStringPreprocessor /** destructor */ virtual ~CSortUlongString(); - /// initialize preprocessor from features - virtual bool init(CFeatures* f); /// cleanup virtual void cleanup(); /// initialize preprocessor from file diff --git a/src/shogun/preprocessor/SortWordString.cpp b/src/shogun/preprocessor/SortWordString.cpp index 38f02c1469b..bf83b444fa5 100644 --- a/src/shogun/preprocessor/SortWordString.cpp +++ b/src/shogun/preprocessor/SortWordString.cpp @@ -20,15 +20,6 @@ CSortWordString::~CSortWordString() { } -/// initialize preprocessor from features -bool CSortWordString::init(CFeatures* f) -{ - ASSERT(f->get_feature_class()==C_STRING) - ASSERT(f->get_feature_type()==F_WORD) - - return true; -} - /// clean up allocated memory void CSortWordString::cleanup() { @@ -56,13 +47,14 @@ bool CSortWordString::save(FILE* f) bool CSortWordString::apply_to_string_features(CFeatures* f) { int32_t i; - int32_t num_vec=((CStringFeatures*)f)->get_num_vectors() ; + auto sf = f->as>(); + int32_t num_vec = sf->get_num_vectors(); for (i=0; i*)f)->get_feature_vector(i, len, free_vec); + uint16_t* vec = sf->get_feature_vector(i, len, free_vec); ASSERT(!free_vec) // won't work with non-in-memory string features //CMath::qsort(vec, len); diff --git a/src/shogun/preprocessor/SortWordString.h b/src/shogun/preprocessor/SortWordString.h index ae73110b1a5..34df377a01c 100644 --- a/src/shogun/preprocessor/SortWordString.h +++ b/src/shogun/preprocessor/SortWordString.h @@ -32,9 +32,6 @@ class CSortWordString : public CStringPreprocessor /** destructor */ virtual ~CSortWordString(); - /// initialize preprocessor from features - virtual bool init(CFeatures* f); - /// cleanup virtual void cleanup(); /// initialize preprocessor from file diff --git a/tests/unit/kernel/CommUlongStringKernel_unittest.cc b/tests/unit/kernel/CommUlongStringKernel_unittest.cc index e1305610c5f..73ba8fb0f06 100644 --- a/tests/unit/kernel/CommUlongStringKernel_unittest.cc +++ b/tests/unit/kernel/CommUlongStringKernel_unittest.cc @@ -37,7 +37,7 @@ TEST(CommUlongStringKernel, kernel_matrix) CStringFeatures* l_feats = new CStringFeatures(alphabet); l_feats->obtain_from_char(s_feats, 5-1, 5, 0, false); CSortUlongString* preproc = new CSortUlongString(); - preproc->init(l_feats); + preproc->fit(l_feats); l_feats->add_preprocessor(preproc); l_feats->apply_preprocessor(); CCommUlongStringKernel* kernel = new CCommUlongStringKernel(l_feats, l_feats);