24 parser.set_free_vector_after_release(
false);
29 bool is_labelled, int32_t size) :
32 init(file, is_labelled, size);
34 parser.set_free_vector_after_release(
false);
41 REQUIRE(dense_features,
"%s::CStreamingDenseFeatures(): Features needed!\n")
49 init(file, is_labelled, size);
51 parser.set_free_vector_after_release(
false);
52 parser.set_free_vectors_on_destruct(
false);
58 SG_DEBUG(
"entering %s::~CStreamingDenseFeatures()\n", get_name())
60 current_vector.vector=NULL;
61 current_vector.vlen=0;
62 SG_DEBUG(
"leaving %s::~CStreamingDenseFeatures()\n", get_name())
71 parser.init(working_file, has_labels, 1);
72 parser.set_free_vector_after_release(
false);
73 parser.start_parser();
80 ASSERT(vec2_len==current_vector.vlen)
83 for (int32_t i=0; i<current_vector.vlen; i++)
84 result+=current_vector[i]*vec2[i];
92 ASSERT(vec2_len==current_vector.vlen)
95 for (int32_t i=0; i<current_vector.vlen; i++)
96 result+=current_vector[i]*vec2[i];
104 ASSERT(vec2_len==current_vector.vlen)
108 for (int32_t i=0; i<current_vector.vlen; i++)
113 for (int32_t i=0; i<current_vector.vlen; i++)
114 vec2[i]+=alpha*current_vector[i];
121 ASSERT(vec2_len==current_vector.vlen)
125 for (int32_t i=0; i<current_vector.vlen; i++)
130 for (int32_t i=0; i<current_vector.vlen; i++)
131 vec2[i]+=alpha*current_vector[i];
137 return current_vector.vlen;
162 #define GET_FEATURE_TYPE(f_type, sg_type) \
163 template<> EFeatureType CStreamingDenseFeatures<sg_type>::get_feature_type() const \
181 #undef GET_FEATURE_TYPE
184 void CStreamingDenseFeatures<T>::init()
190 current_vector.vector=NULL;
191 current_vector.vlen=-1;
197 void CStreamingDenseFeatures<T>::init(CStreamingFile* file,
bool is_labelled,
201 has_labels=is_labelled;
204 parser.init(file, is_labelled, size);
211 if (!parser.is_running())
212 parser.start_parser();
226 ret_value=(bool)parser.get_next_example(current_vector.vector,
227 current_vector.vlen, current_label);
236 return current_vector;
244 return current_label;
250 parser.finalize_example();
256 return current_vector.vlen;
269 return CMath::dot(current_vector.vector, other_vector.
vector, current_vector.vlen);
278 if (len1!=current_vector.vlen)
280 "Lengths %d and %d not equal while computing dot product!\n", len1, current_vector.vlen);
288 return current_vector.vlen;
302 SG_DEBUG(
"Streaming %d elements\n", num_elements)
304 REQUIRE(num_elements>0,
"Requested number of feature vectors (%d) must be "
305 "positive\n", num_elements);
310 for (
index_t i=0; i<num_elements; ++i)
313 if (!get_next_example())
315 SG_WARNING(
"Ran out of streaming data, reallocating matrix and "
333 SG_DEBUG(
"Allocating %dx%d matrix\n",
334 current_vector.vlen, num_elements);
335 matrix=
SGMatrix<T>(current_vector.vlen, num_elements);
343 "Dimension of streamed vector (%d) does not match "
344 "dimensions of previous vectors (%d)\n",
348 memcpy(&matrix.
matrix[current_vector.vlen*i], vec.
vector,
virtual int32_t get_dim_feature_space() const
virtual CFeatures * get_streamed_features(index_t num_elements)
Class CStreamingFileFromDenseFeatures is a derived class of CStreamingFile which creates an input sou...
This class implements streaming features with dense feature vectors.
SGVector< T > get_vector()
virtual CFeatures * duplicate() const
virtual void add_to_dense_vec(float32_t alpha, float32_t *vec2, int32_t vec2_len, bool abs_val=false)
virtual void get_vector(bool *&vector, int32_t &len)
#define GET_FEATURE_TYPE(f_type, sg_type)
virtual bool get_next_example()
virtual void reset_stream()
virtual float32_t dense_dot(const float32_t *vec2, int32_t vec2_len)
virtual EFeatureClass get_feature_class() const
EFeatureClass
shogun feature class
A Streaming File access class.
virtual void set_vector_and_label_reader()
CInputParser< T > parser
The parser object, which reads from input and returns parsed example objects.
virtual void set_vector_reader()
virtual float32_t dot(SGVector< T > vec)
virtual void release_example()
virtual EFeatureClass get_feature_class() const =0
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
Streaming features that support dot products among other operations.
virtual void end_parser()
virtual void get_vector_and_label(bool *&vector, int32_t &len, float64_t &label)
all of classes and functions are contained in the shogun namespace
~CStreamingDenseFeatures()
void set_read_functions()
bool seekable
Whether the stream is seekable.
The class Features is the base class of all feature objects.
int32_t get_num_features()
CStreamingDenseFeatures()
virtual int32_t get_num_vectors() const
virtual void start_parser()
virtual int32_t get_nnz_features_for_vector()
virtual EFeatureType get_feature_type() const =0
virtual float64_t get_label()