#include <iostream>

#include "SparseVectorFeature.h"
#include "vislearning/cbaselib/FeaturePool.h"

using namespace OBJREC;

using namespace std;
// refactor-nice.pl: check this substitution
// old: using namespace ice;
using namespace NICE;

/** simple destructor */
SparseVectorFeature::~SparseVectorFeature()
{
}

double SparseVectorFeature::val( const Example *example ) const
{
	return example->svec->get(feature_index);
}

void SparseVectorFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
{
	for ( int i = 0 ; i < dimension ; i++ )
	{
		SparseVectorFeature *f = new SparseVectorFeature ( dimension );
		f->feature_index = i;
		featurePool.addFeature(f, 1.0 / dimension);
	}
}

Feature *SparseVectorFeature::clone() const
{
	SparseVectorFeature *f = new SparseVectorFeature( dimension );
	f->feature_index = feature_index;
	return f;
}

Feature *SparseVectorFeature::generateFirstParameter () const
{
	return clone();
}

void SparseVectorFeature::restore (istream & is, int format)
{
	is >> feature_index;
}

void SparseVectorFeature::store (ostream & os, int format) const
{
	os << "SVECTORFEATURE "
			<< feature_index;
}

void SparseVectorFeature::clear ()
{
}

void SparseVectorFeature::getStump ( int & _feature_index, int & _dimension ) const
{
	_feature_index = feature_index;
	_dimension = dimension;
}
