From eb3941a617c42b1421bbb4cb591d1e1d5b8d10e9 Mon Sep 17 00:00:00 2001 From: Saurabh7 Date: Wed, 29 Jun 2016 18:31:55 +0530 Subject: [PATCH] shallow subset --- src/shogun/features/DenseFeatures.cpp | 16 ++++++++++++++++ src/shogun/features/DenseFeatures.h | 2 ++ src/shogun/features/Features.h | 6 ++++++ src/shogun/labels/DenseLabels.cpp | 1 + src/shogun/labels/Labels.h | 6 ++++++ src/shogun/labels/MulticlassLabels.cpp | 14 ++++++++++++++ src/shogun/labels/MulticlassLabels.h | 2 ++ 7 files changed, 47 insertions(+) diff --git a/src/shogun/features/DenseFeatures.cpp b/src/shogun/features/DenseFeatures.cpp index b782ec68c13..c4f11d5fa50 100644 --- a/src/shogun/features/DenseFeatures.cpp +++ b/src/shogun/features/DenseFeatures.cpp @@ -636,6 +636,22 @@ CFeatures* CDenseFeatures::copy_dimension_subset(SGVector dims) return result; } +template +CFeatures* CDenseFeatures::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 shallow_copy_matrix = SGMatrix(feature_matrix.matrix, num_features, num_vectors, false); + shallow_copy_features=new CDenseFeatures(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 ST* CDenseFeatures::compute_feature_vector(int32_t num, int32_t& len, ST* target) { diff --git a/src/shogun/features/DenseFeatures.h b/src/shogun/features/DenseFeatures.h index 8580884cea0..463fde27fbe 100644 --- a/src/shogun/features/DenseFeatures.h +++ b/src/shogun/features/DenseFeatures.h @@ -515,6 +515,8 @@ template 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"; } diff --git a/src/shogun/features/Features.h b/src/shogun/features/Features.h index 9425080d2b4..3a2d8338838 100644 --- a/src/shogun/features/Features.h +++ b/src/shogun/features/Features.h @@ -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(); diff --git a/src/shogun/labels/DenseLabels.cpp b/src/shogun/labels/DenseLabels.cpp index 525f43b3d5b..47ae77ada63 100644 --- a/src/shogun/labels/DenseLabels.cpp +++ b/src/shogun/labels/DenseLabels.cpp @@ -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; } + diff --git a/src/shogun/labels/Labels.h b/src/shogun/labels/Labels.h index b77c030dc54..9c1a1bc94bf 100644 --- a/src/shogun/labels/Labels.h +++ b/src/shogun/labels/Labels.h @@ -123,6 +123,12 @@ class CLabels : public CSGObject */ virtual SGVector get_values(); + virtual CLabels* shallow_subset_copy() + { + SG_SNOTIMPLEMENTED; + return NULL; + } + private: void init(); diff --git a/src/shogun/labels/MulticlassLabels.cpp b/src/shogun/labels/MulticlassLabels.cpp index 161c5361ebc..870f89c62fc 100644 --- a/src/shogun/labels/MulticlassLabels.cpp +++ b/src/shogun/labels/MulticlassLabels.cpp @@ -134,3 +134,17 @@ int32_t CMulticlassLabels::get_num_classes() SGVector unique=get_unique_labels(); return unique.vlen; } + +CLabels* CMulticlassLabels::shallow_subset_copy() +{ + CLabels* shallow_copy_labels=nullptr; + SGVector shallow_copy_vector = SGVector(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; +} diff --git a/src/shogun/labels/MulticlassLabels.h b/src/shogun/labels/MulticlassLabels.h index 6d5d75ce1db..86c7d3668c9 100644 --- a/src/shogun/labels/MulticlassLabels.h +++ b/src/shogun/labels/MulticlassLabels.h @@ -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 */