Skip to content

Commit

Permalink
implemented copy_subset method
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 22, 2011
1 parent f8239e9 commit 295d6f0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/shogun/features/SimpleFeatures.h
Expand Up @@ -918,6 +918,27 @@ template<class ST> class CSimpleFeatures: public CDotFeatures {
delete[] it;
}

/** Creates a new CFeatures instance containing copies of the elements
* which are specified by the provided indices.
*
* @param indices indices of feature elements to copy
* @return new CFeatures instance with copies of feature data
*/
virtual CFeatures* copy_subset(SGVector<index_t> indices) const
{
SGMatrix<ST> feature_matrix_copy(num_features, indices.vlen);

for (index_t i=0; i<indices.vlen; ++i)
{
index_t real_idx=subset_idx_conversion(indices.vector[i]);
memcpy(&feature_matrix_copy.matrix[i*num_features],
&feature_matrix[real_idx*num_features],
num_features*sizeof(ST));
}

return new CSimpleFeatures(feature_matrix_copy);
}

/** @return object name */
inline virtual const char* get_name() const {
return "SimpleFeatures";
Expand All @@ -937,6 +958,7 @@ template<class ST> class CSimpleFeatures: public CDotFeatures {
*/
virtual ST* compute_feature_vector(int32_t num, int32_t& len, ST* target =
NULL) {
SG_NOTIMPLEMENTED;
len = 0;
return NULL;
}
Expand Down

0 comments on commit 295d6f0

Please sign in to comment.