diff --git a/src/shogun/statistical_testing/internals/NextSamples.cpp b/src/shogun/statistical_testing/internals/NextSamples.cpp index 07df99d9b52..2fd9a08d25f 100644 --- a/src/shogun/statistical_testing/internals/NextSamples.cpp +++ b/src/shogun/statistical_testing/internals/NextSamples.cpp @@ -16,9 +16,8 @@ * along with this program. If not, see . */ -#include -#include #include +#include using namespace shogun; using namespace internal; @@ -28,23 +27,32 @@ NextSamples::NextSamples(index_t num_distributions) : m_num_blocks(0) next_samples.resize(num_distributions); } +NextSamples& NextSamples::operator=(const NextSamples& other) +{ + clear(); + m_num_blocks=other.m_num_blocks; + next_samples=other.next_samples; + return *this; +} + NextSamples::~NextSamples() { + clear(); } -std::vector>& NextSamples::operator[](index_t i) +std::vector& NextSamples::operator[](size_t i) { - REQUIRE(i >= 0 && i < next_samples.size(), + REQUIRE(i>=0 && i>& NextSamples::operator[](index_t i) const +const std::vector& NextSamples::operator[](size_t i) const { - REQUIRE(i >= 0 && i < next_samples.size(), + REQUIRE(i>=0 && i>; - return std::any_of(next_samples.cbegin(), next_samples.cend(), [](type& f) { return f.size() == 0; }); + using type=const std::vector; + return std::any_of(next_samples.cbegin(), next_samples.cend(), [](type& f) { return f.size()==0; }); +} + +void NextSamples::clear() +{ + using type=std::vector; + std::for_each(next_samples.begin(), next_samples.end(), [](type& f) { f.clear(); }); + next_samples.clear(); } diff --git a/src/shogun/statistical_testing/internals/NextSamples.h b/src/shogun/statistical_testing/internals/NextSamples.h index bce175b970b..2993edbff4c 100644 --- a/src/shogun/statistical_testing/internals/NextSamples.h +++ b/src/shogun/statistical_testing/internals/NextSamples.h @@ -19,9 +19,10 @@ #ifndef NEXT_SAMPLES_H__ #define NEXT_SAMPLES_H__ -#include #include +#include #include +#include namespace shogun { @@ -59,7 +60,16 @@ class NextSamples private: NextSamples(index_t num_distributions); public: + /** + * Assignment operator. Clears the current blocks. + */ + NextSamples& operator=(const NextSamples& other); + + /** + * Destructor + */ ~NextSamples(); + /** * Contains a number of blocks (of samples) fetched in the current burst from a * specified distribution. @@ -67,13 +77,13 @@ class NextSamples * @param i determines samples from which distribution * @return a vector of fetched blocks of features from the specified distribution */ - std::vector>& operator[](index_t i); + std::vector& operator[](size_t i); /** * Const version of the above. This is called when a const instance of NextSamples * is returned. */ - const std::vector>& operator[](index_t i) const; + const std::vector& operator[](size_t i) const; /** * @return number of blocks fetched from each of the distribution. It is assumed @@ -89,9 +99,14 @@ class NextSamples * of the distribution */ const bool empty() const; + + /** + * Method that clears the memory occupied by the feature objects inside. + */ + void clear(); private: index_t m_num_blocks; - std::vector>> next_samples; + std::vector> next_samples; }; }