Skip to content

Commit

Permalink
add some helper functions like clear vector, fill vector etc to SGVector
Browse files Browse the repository at this point in the history
This unfortunately causes conflicts w/ modelselection that using
SGVector<void>. Until ms is resolved to use sth else it will remain broken.
  • Loading branch information
Soeren Sonnenburg committed Sep 22, 2011
1 parent b879040 commit b73b2c1
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 202 deletions.
16 changes: 8 additions & 8 deletions src/shogun/base/Parameter.cpp
Expand Up @@ -1622,10 +1622,10 @@ TParameter::delete_cont()
switch(m_datatype.m_ctype)
{
case CT_SGVECTOR:
data_start=&(((SGVector<void>*)m_parameter)->vector);
//FIXME void data_start=&(((SGVector<void>*)m_parameter)->vector);
break;
case CT_SGMATRIX:
data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
//FIXME void data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
break;
default:
break;
Expand Down Expand Up @@ -1783,10 +1783,10 @@ TParameter::new_cont(index_t new_len_y, index_t new_len_x)
switch(m_datatype.m_ctype)
{
case CT_SGVECTOR:
data_start=&(((SGVector<void>*)m_parameter)->vector);
//FIXME void data_start=&(((SGVector<void>*)m_parameter)->vector);
break;
case CT_SGMATRIX:
data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
//FIXME void data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
break;
default:
break;
Expand Down Expand Up @@ -2247,10 +2247,10 @@ TParameter::save(CSerializableFile* file, const char* prefix)
switch(m_datatype.m_ctype)
{
case CT_SGVECTOR:
data_start=&(((SGVector<void>*)m_parameter)->vector);
//FIXME void data_start=&(((SGVector<void>*)m_parameter)->vector);
break;
case CT_SGMATRIX:
data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
//FIXME void data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
break;
default:
break;
Expand Down Expand Up @@ -2338,10 +2338,10 @@ TParameter::load(CSerializableFile* file, const char* prefix)
switch(m_datatype.m_ctype)
{
case CT_SGVECTOR:
data_start=&(((SGVector<void>*)m_parameter)->vector);
//FIXME void data_start=&(((SGVector<void>*)m_parameter)->vector);
break;
case CT_SGMATRIX:
data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
//FIXME void data_start=&(((SGMatrix<void>*)m_parameter)->matrix);
break;
default:
break;
Expand Down
74 changes: 74 additions & 0 deletions src/shogun/features/Features.cpp
Expand Up @@ -186,6 +186,32 @@ CPreprocessor* CFeatures::del_preprocessor(int32_t num)
return removed_preproc;
}

void CFeatures::set_preprocessed(int32_t num)
{
preprocessed[num]=true;
}

bool CFeatures::is_preprocessed(int32_t num)
{
return preprocessed[num];
}

int32_t CFeatures::get_num_preprocessors() const
{
return num_preproc;
}

int32_t CFeatures::get_cache_size()
{
return cache_size;
}

bool CFeatures::reshape(int32_t num_features, int32_t num_vectors)
{
SG_NOTIMPLEMENTED;
return false;
}

void CFeatures::list_feature_obj()
{
SG_INFO( "%p - ", this);
Expand Down Expand Up @@ -283,6 +309,21 @@ void CFeatures::list_feature_obj()
}
}


void CFeatures::load(CFile* loader)
{
SG_SET_LOCALE_C;
SG_NOTIMPLEMENTED;
SG_RESET_LOCALE;
}

void CFeatures::save(CFile* writer)
{
SG_SET_LOCALE_C;
SG_NOTIMPLEMENTED;
SG_RESET_LOCALE;
}

bool CFeatures::check_feature_compatibility(CFeatures* f)
{
bool result=false;
Expand All @@ -293,6 +334,21 @@ bool CFeatures::check_feature_compatibility(CFeatures* f)
return result;
}

bool CFeatures::has_property(EFeatureProperty p)
{
return (properties & p) != 0;
}

void CFeatures::set_property(EFeatureProperty p)
{
properties |= p;
}

void CFeatures::unset_property(EFeatureProperty p)
{
properties &= (properties | p) ^ p;
}

void CFeatures::set_subset(CSubset* subset)
{
SG_UNREF(m_subset);
Expand All @@ -301,7 +357,25 @@ void CFeatures::set_subset(CSubset* subset)
subset_changed_post();
}

index_t CFeatures::subset_idx_conversion(index_t idx) const
{
return m_subset ? m_subset->subset_idx_conversion(idx) : idx;
}

bool CFeatures::has_subset() const
{
return m_subset!=NULL;
}

void CFeatures::remove_subset()
{
set_subset(NULL);
}

CFeatures* CFeatures::copy_subset(SGVector<index_t> indices)
{
SG_ERROR("copy_subset and therefore model storage of CMachine "
"(required for cross-validation and model-selection is ",
"not yet implemented for feature type %s\n", get_name());
return NULL;
}
55 changes: 13 additions & 42 deletions src/shogun/features/Features.h
Expand Up @@ -126,13 +126,13 @@ class CFeatures : public CSGObject
*
* @param num index of preprocessor in list
*/
inline void set_preprocessed(int32_t num) { preprocessed[num]=true; }
void set_preprocessed(int32_t num);

/** get whether specified preprocessor was already applied
*
* @param num index of preprocessor in list
*/
inline bool is_preprocessed(int32_t num) { return preprocessed[num]; }
bool is_preprocessed(int32_t num);

/** get the number of applied preprocs
*
Expand All @@ -144,7 +144,7 @@ class CFeatures : public CSGObject
*
* @return number of preprocessors
*/
inline int32_t get_num_preprocessors() const { return num_preproc; }
int32_t get_num_preprocessors() const;

/** clears all preprocs */
void clean_preprocessors();
Expand All @@ -153,7 +153,7 @@ class CFeatures : public CSGObject
*
* @return cache size
*/
inline int32_t get_cache_size() { return cache_size; };
int32_t get_cache_size();

/** get number of examples/vectors, possibly corresponding to the current subset
*
Expand All @@ -171,11 +171,7 @@ class CFeatures : public CSGObject
* @param num_vectors new number of vectors
* @return if reshaping was successful
*/
virtual bool reshape(int32_t num_features, int32_t num_vectors)
{
SG_NOTIMPLEMENTED;
return false;
}
virtual bool reshape(int32_t num_features, int32_t num_vectors);

/** get memory footprint of one feature
*
Expand All @@ -192,23 +188,13 @@ class CFeatures : public CSGObject
*
* @param loader File object via which data shall be loaded
*/
virtual void load(CFile* loader)
{
SG_SET_LOCALE_C;
SG_NOTIMPLEMENTED;
SG_RESET_LOCALE;
}
virtual void load(CFile* loader);

/** save features to file
*
* @param writer File object via which data shall be saved
*/
virtual void save(CFile* writer)
{
SG_SET_LOCALE_C;
SG_NOTIMPLEMENTED;
SG_RESET_LOCALE;
}
virtual void save(CFile* writer);

/** check feature compatibility
*
Expand All @@ -222,25 +208,19 @@ class CFeatures : public CSGObject
* @param p feature property
* @return if features have given property
*/
inline bool has_property(EFeatureProperty p) { return (properties & p) != 0; }
bool has_property(EFeatureProperty p);

/** set property
*
* @param p kernel property to set
*/
inline void set_property(EFeatureProperty p)
{
properties |= p;
}
void set_property(EFeatureProperty p);

/** unset property
*
* @param p kernel property to unset
*/
inline void unset_property(EFeatureProperty p)
{
properties &= (properties | p) ^ p;
}
void unset_property(EFeatureProperty p);

/** setter for subset variable, deletes old one
* subset_changed_post() is called afterwards
Expand All @@ -261,15 +241,12 @@ class CFeatures : public CSGObject
* @param idx index to convert
* @return converted index
*/
inline index_t subset_idx_conversion(index_t idx) const
{
return m_subset ? m_subset->subset_idx_conversion(idx) : idx;
}
index_t subset_idx_conversion(index_t idx) const;

/** check if has subsets
* @return true if has subsets
*/
inline bool has_subset() const { return m_subset!=NULL; }
bool has_subset() const;

/** Creates a new CFeatures instance containing copies of the elements
* which are specified by the provided indices.
Expand All @@ -280,13 +257,7 @@ class CFeatures : public CSGObject
* @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)
{
SG_ERROR("copy_subset and therefore model storage of CMachine "
"(required for cross-validation and model-selection is ",
"not yet implemented for feature type %s\n", get_name());
return NULL;
}
CFeatures* copy_subset(SGVector<index_t> indices);

private:
/** feature properties */
Expand Down

0 comments on commit b73b2c1

Please sign in to comment.