Skip to content

Commit

Permalink
shallow subset
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh7 committed Jun 29, 2016
1 parent 29c8a96 commit eb3941a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/shogun/features/DenseFeatures.cpp
Expand Up @@ -636,6 +636,22 @@ CFeatures* CDenseFeatures<ST>::copy_dimension_subset(SGVector<index_t> dims)
return result;
}

template<class ST>
CFeatures* CDenseFeatures<ST>::shallow_subset_copy()
{
SG_SDEBUG("Entering!\n");
CFeatures* shallow_copy_features=nullptr;

SG_SDEBUG("Using underlying feature matrix with %d dimensions and %d feature vectors!\n", num_features, num_vectors);
SGMatrix<ST> shallow_copy_matrix = SGMatrix<ST>(feature_matrix.matrix, num_features, num_vectors, false);
shallow_copy_features=new CDenseFeatures<ST>(shallow_copy_matrix);
if (m_subset_stack->has_subsets())
shallow_copy_features->add_subset(m_subset_stack->get_last_subset()->get_subset_idx());

SG_SDEBUG("Leaving!\n");
return shallow_copy_features;
}

template<class ST> ST* CDenseFeatures<ST>::compute_feature_vector(int32_t num, int32_t& len,
ST* target)
{
Expand Down
2 changes: 2 additions & 0 deletions src/shogun/features/DenseFeatures.h
Expand Up @@ -515,6 +515,8 @@ template<class ST> class CDenseFeatures: public CDotFeatures
*/
static CDenseFeatures* obtain_from_generic(CFeatures* const base_features);

virtual CFeatures* shallow_subset_copy();

/** @return object name */
virtual const char* get_name() const { return "DenseFeatures"; }

Expand Down
6 changes: 6 additions & 0 deletions src/shogun/features/Features.h
Expand Up @@ -331,6 +331,12 @@ class CFeatures : public CSGObject
* @return whether this class supports compatible computation
*/
virtual bool get_feature_class_compatibility (EFeatureClass rhs) const;

virtual CFeatures* shallow_subset_copy()
{
SG_SNOTIMPLEMENTED;
return NULL;
}
private:
void init();

Expand Down
1 change: 1 addition & 0 deletions src/shogun/labels/DenseLabels.cpp
Expand Up @@ -203,3 +203,4 @@ int32_t CDenseLabels::get_num_labels() const
return m_subset_stack->has_subsets()
? m_subset_stack->get_size() : m_labels.vlen;
}

6 changes: 6 additions & 0 deletions src/shogun/labels/Labels.h
Expand Up @@ -123,6 +123,12 @@ class CLabels : public CSGObject
*/
virtual SGVector<float64_t> get_values();

virtual CLabels* shallow_subset_copy()
{
SG_SNOTIMPLEMENTED;
return NULL;
}

private:
void init();

Expand Down
14 changes: 14 additions & 0 deletions src/shogun/labels/MulticlassLabels.cpp
Expand Up @@ -134,3 +134,17 @@ int32_t CMulticlassLabels::get_num_classes()
SGVector<float64_t> unique=get_unique_labels();
return unique.vlen;
}

CLabels* CMulticlassLabels::shallow_subset_copy()
{
CLabels* shallow_copy_labels=nullptr;
SGVector<float64_t> shallow_copy_vector = SGVector<float64_t>(m_labels.vector, m_labels.size(), false);
shallow_copy_labels=new CMulticlassLabels(m_labels.size());

((CDenseLabels*) shallow_copy_labels)->set_labels(shallow_copy_vector);
if (m_subset_stack->has_subsets())
shallow_copy_labels->add_subset(m_subset_stack->get_last_subset()->get_subset_idx());

SG_SDEBUG("Leaving!\n");
return shallow_copy_labels;
}
2 changes: 2 additions & 0 deletions src/shogun/labels/MulticlassLabels.h
Expand Up @@ -123,6 +123,8 @@ class CMulticlassLabels : public CDenseLabels

/** @return object name */
virtual const char* get_name() const { return "MulticlassLabels"; }

virtual CLabels* shallow_subset_copy();

private:
/** initialises and register parameters */
Expand Down

0 comments on commit eb3941a

Please sign in to comment.