Skip to content

Commit

Permalink
updated next samples data structure with blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lambday authored and karlnapf committed Jul 4, 2016
1 parent c738b3b commit 5662bcf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
35 changes: 25 additions & 10 deletions src/shogun/statistical_testing/internals/NextSamples.cpp
Expand Up @@ -16,9 +16,8 @@
* along with this program. If not, see <http:/www.gnu.org/licenses/>.
*/

#include <iostream>
#include <shogun/statistical_testing/internals/NextSamples.h>
#include <shogun/features/Features.h>
#include <shogun/statistical_testing/internals/NextSamples.h>

using namespace shogun;
using namespace internal;
Expand All @@ -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<std::shared_ptr<CFeatures>>& NextSamples::operator[](index_t i)
std::vector<Block>& NextSamples::operator[](size_t i)
{
REQUIRE(i >= 0 && i < next_samples.size(),
REQUIRE(i>=0 && i<next_samples.size(),
"index (%d) must be between [0,%d]!\n",
i, next_samples.size() - 1);
i, next_samples.size()-1);
return next_samples[i];
}

const std::vector<std::shared_ptr<CFeatures>>& NextSamples::operator[](index_t i) const
const std::vector<Block>& NextSamples::operator[](size_t i) const
{
REQUIRE(i >= 0 && i < next_samples.size(),
REQUIRE(i>=0 && i<next_samples.size(),
"index (%d) must be between [0,%d]!\n",
i, next_samples.size() - 1);
i, next_samples.size()-1);
return next_samples[i];
}

Expand All @@ -55,6 +63,13 @@ const index_t NextSamples::num_blocks() const

const bool NextSamples::empty() const
{
using type = const std::vector<std::shared_ptr<CFeatures>>;
return std::any_of(next_samples.cbegin(), next_samples.cend(), [](type& f) { return f.size() == 0; });
using type=const std::vector<Block>;
return std::any_of(next_samples.cbegin(), next_samples.cend(), [](type& f) { return f.size()==0; });
}

void NextSamples::clear()
{
using type=std::vector<Block>;
std::for_each(next_samples.begin(), next_samples.end(), [](type& f) { f.clear(); });
next_samples.clear();
}
23 changes: 19 additions & 4 deletions src/shogun/statistical_testing/internals/NextSamples.h
Expand Up @@ -19,9 +19,10 @@
#ifndef NEXT_SAMPLES_H__
#define NEXT_SAMPLES_H__

#include <vector>
#include <memory>
#include <vector>
#include <shogun/lib/common.h>
#include <shogun/statistical_testing/internals/Block.h>

namespace shogun
{
Expand Down Expand Up @@ -59,21 +60,30 @@ 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.
*
* @param i determines samples from which distribution
* @return a vector of fetched blocks of features from the specified distribution
*/
std::vector<std::shared_ptr<CFeatures>>& operator[](index_t i);
std::vector<Block>& operator[](size_t i);

/**
* Const version of the above. This is called when a const instance of NextSamples
* is returned.
*/
const std::vector<std::shared_ptr<CFeatures>>& operator[](index_t i) const;
const std::vector<Block>& operator[](size_t i) const;

/**
* @return number of blocks fetched from each of the distribution. It is assumed
Expand All @@ -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<std::vector<std::shared_ptr<CFeatures>>> next_samples;
std::vector<std::vector<Block>> next_samples;
};

}
Expand Down

0 comments on commit 5662bcf

Please sign in to comment.