Skip to content

Commit

Permalink
Deprecate densepreproc old api add apply_to_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored and vigsterkr committed Jun 8, 2018
1 parent 2e29dd7 commit 8958305
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/shogun/preprocessor/DensePreprocessor.cpp
Expand Up @@ -92,12 +92,26 @@ CFeatures* CDensePreprocessor<ST>::apply(CFeatures* features, bool inplace)
"has to be of C_DENSE (%d) class!\n",
features->get_feature_class(), C_DENSE);

SGMatrix<ST> feat_matrix=apply_to_feature_matrix(features);
CDenseFeatures<ST>* preprocessed=new CDenseFeatures<ST>(feat_matrix);
auto matrix = features->as<CDenseFeatures<ST>>()->get_feature_matrix();
if (!inplace)
matrix = matrix.clone();
auto feat_matrix = apply_to_matrix(matrix);
auto preprocessed = new CDenseFeatures<ST>(feat_matrix);
SG_REF(preprocessed);
return preprocessed;
}

template <class ST>
SGMatrix<ST>
CDensePreprocessor<ST>::apply_to_feature_matrix(CFeatures* features)
{
auto simple_features = features->as<CDenseFeatures<ST>>();
auto feature_matrix =
apply_to_matrix(simple_features->get_feature_matrix());
simple_features->set_feature_matrix(feature_matrix);
return feature_matrix;
}

template class CDensePreprocessor<bool>;
template class CDensePreprocessor<char>;
template class CDensePreprocessor<int8_t>;
Expand Down
14 changes: 12 additions & 2 deletions src/shogun/preprocessor/DensePreprocessor.h
Expand Up @@ -44,11 +44,14 @@ template <class ST> class CDensePreprocessor : public CPreprocessor
/// apply preproc on feature matrix
/// result in feature matrix
/// return pointer to feature_matrix, i.e. f->get_feature_matrix();
virtual SGMatrix<ST> apply_to_feature_matrix(CFeatures* features)=0;
// remove after cleaning up codebase
[[deprecated]] virtual SGMatrix<ST>
apply_to_feature_matrix(CFeatures* features);

/// apply preproc on single feature vector
/// result in feature matrix
virtual SGVector<ST> apply_to_feature_vector(SGVector<ST> vector)=0;
[[deprecated]] virtual SGVector<ST>
apply_to_feature_vector(SGVector<ST> vector) = 0;

/// return that we are dense features (just fixed size matrices)
virtual EFeatureClass get_feature_class();
Expand All @@ -58,6 +61,13 @@ template <class ST> class CDensePreprocessor : public CPreprocessor
/// return a type of preprocessor
virtual EPreprocessorType get_type() const;

protected:
/** Apply preprocessor on matrix. Subclasses should try to apply in
* place to avoid copying.
* @param matrix the input feature matrix
* @return the matrix after applying the preprocessor
*/
virtual SGMatrix<ST> apply_to_matrix(SGMatrix<ST> matrix) = 0;
};

}
Expand Down

0 comments on commit 8958305

Please sign in to comment.