Skip to content

Commit

Permalink
Cleanup string preprocessors and rename init to fit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored and vigsterkr committed Jun 8, 2018
1 parent 4784e33 commit cb0f95c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 48 deletions.
22 changes: 6 additions & 16 deletions src/shogun/preprocessor/DecompressString.cpp
Expand Up @@ -24,13 +24,6 @@ CDecompressString<ST>::~CDecompressString()
delete compressor;
}

template <class ST>
bool CDecompressString<ST>::init(CFeatures* f)
{
ASSERT(f->get_feature_class()==C_STRING)
return true;
}

template <class ST>
void CDecompressString<ST>::cleanup()
{
Expand All @@ -56,22 +49,19 @@ template <class ST>
bool CDecompressString<ST>::apply_to_string_features(CFeatures* f)
{
int32_t i;
int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors();
auto sf = f->as<CStringFeatures<ST>>();
int32_t num_vec = sf->get_num_vectors();

for (i=0; i<num_vec; i++)
{
int32_t len=0;
bool free_vec;
ST* vec=((CStringFeatures<ST>*)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<ST>*)f)->
free_feature_vector(vec, i, free_vec);
((CStringFeatures<ST>*)f)->
cleanup_feature_vector(i);
((CStringFeatures<ST>*)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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/shogun/preprocessor/DecompressString.h
Expand Up @@ -43,9 +43,6 @@ template <class ST> class CDecompressString : public CStringPreprocessor<ST>
/** destructor */
virtual ~CDecompressString();

/// initialize preprocessor from features
virtual bool init(CFeatures* f);

/// cleanup
virtual void cleanup();

Expand Down
15 changes: 3 additions & 12 deletions src/shogun/preprocessor/SortUlongString.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<uint64_t>*)f)->get_num_vectors();
auto sf = f->as<CStringFeatures<uint64_t>>();
int32_t num_vec = sf->get_num_vectors();

for (i=0; i<num_vec; i++)
{
int32_t len=0;
bool free_vec;
uint64_t* vec=((CStringFeatures<uint64_t>*)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)
Expand Down
2 changes: 0 additions & 2 deletions src/shogun/preprocessor/SortUlongString.h
Expand Up @@ -31,8 +31,6 @@ class CSortUlongString : public CStringPreprocessor<uint64_t>
/** destructor */
virtual ~CSortUlongString();

/// initialize preprocessor from features
virtual bool init(CFeatures* f);
/// cleanup
virtual void cleanup();
/// initialize preprocessor from file
Expand Down
14 changes: 3 additions & 11 deletions src/shogun/preprocessor/SortWordString.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<uint16_t>*)f)->get_num_vectors() ;
auto sf = f->as<CStringFeatures<uint16_t>>();
int32_t num_vec = sf->get_num_vectors();

for (i=0; i<num_vec; i++)
{
int32_t len = 0 ;
bool free_vec;
uint16_t* vec = ((CStringFeatures<uint16_t>*)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);
Expand Down
3 changes: 0 additions & 3 deletions src/shogun/preprocessor/SortWordString.h
Expand Up @@ -32,9 +32,6 @@ class CSortWordString : public CStringPreprocessor<uint16_t>
/** destructor */
virtual ~CSortWordString();

/// initialize preprocessor from features
virtual bool init(CFeatures* f);

/// cleanup
virtual void cleanup();
/// initialize preprocessor from file
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/kernel/CommUlongStringKernel_unittest.cc
Expand Up @@ -37,7 +37,7 @@ TEST(CommUlongStringKernel, kernel_matrix)
CStringFeatures<uint64_t>* l_feats = new CStringFeatures<uint64_t>(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);
Expand Down

0 comments on commit cb0f95c

Please sign in to comment.