Skip to content

Commit

Permalink
introduce more efficient cleanup_feature_vectors function
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Oct 13, 2011
1 parent a6e49bb commit 12a5173
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/shogun/features/StringFeatures.cpp
Expand Up @@ -140,10 +140,7 @@ template<class ST> void CStringFeatures<ST>::cleanup()
single_string=NULL;
}
else
{
for (int32_t i=0; i<num_vectors; i++)
cleanup_feature_vector(i);
}
cleanup_feature_vectors(0, num_vectors-1);

num_vectors=0;
SG_FREE(features);
Expand Down Expand Up @@ -176,6 +173,24 @@ template<class ST> void CStringFeatures<ST>::cleanup_feature_vector(int32_t num)
}
}

template<class ST> void CStringFeatures<ST>::cleanup_feature_vectors(int32_t start, int32_t stop)
{
if (features && get_num_vectors())
{
ASSERT(start<get_num_vectors());
ASSERT(stop<get_num_vectors());

for (int32_t i=start; i<=stop; i++)
{
int32_t real_num=subset_idx_conversion(i);
SG_FREE(features[real_num].string);
features[real_num].string=NULL;
features[real_num].slen=0;
}
determine_maximum_string_length();
}
}

template<class ST> EFeatureClass CStringFeatures<ST>::get_feature_class() { return C_STRING; }

template<class ST> EFeatureType CStringFeatures<ST>::get_feature_type() { return F_UNKNOWN; }
Expand Down Expand Up @@ -1398,6 +1413,7 @@ template<class ST> void CStringFeatures<ST>::determine_maximum_string_length()
{
max_string_length=0;
index_t num_str=get_num_vectors();

for (int32_t i=0; i<num_str; i++)
{
max_string_length=CMath::max(max_string_length,
Expand Down
9 changes: 9 additions & 0 deletions src/shogun/features/StringFeatures.h
Expand Up @@ -128,6 +128,15 @@ template <class ST> class CStringFeatures : public CFeatures
* */
virtual void cleanup_feature_vector(int32_t num);

/** cleanup multiple feature vectors
*
* possible with subset
*
* @param start index of first vector to be cleaned
* @param end last number of the vector to be cleaned
* */
virtual void cleanup_feature_vectors(int32_t start, int32_t stop);

/** get feature class
*
* @return feature class STRING
Expand Down

0 comments on commit 12a5173

Please sign in to comment.