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();
225 ret_value=(bool)parser.get_next_example(current_vector.vector,
226 current_vector.vlen, current_label);
234 return current_vector;
242 return current_label;
248 parser.finalize_example();
254 return current_vector.vlen;
276 if (len1!=current_vector.vlen)
278 "Lengths %d and %d not equal while computing dot product!\n", len1, current_vector.vlen);
286 return current_vector.vlen;
299 SG_DEBUG(
"entering %s(%p)::get_streamed_features(%d)\n", get_name(),
this,
305 for (
index_t i=0; i<num_elements; ++i)
308 if (!get_next_example())
310 SG_WARNING(
"%s::get_streamed_features(): ran out of streaming "
311 "data, reallocating matrix and returning!\n", get_name());
328 SG_DEBUG(
"%s::get_streamed_features(): allocating %dx%d matrix\n",
329 get_name(), current_vector.vlen, num_elements);
330 matrix=
SGMatrix<T>(current_vector.vlen, num_elements);
339 SG_ERROR(
"%s::get_streamed_features(): streamed vectors have "
340 "different dimensions. This is not allowed!\n",
345 memcpy(&matrix.
matrix[current_vector.vlen*i], vec.
vector,
364 SG_DEBUG(
"leaving %s(%p)::get_streamed_features(%d) and returning %dx%d "
365 "matrix\n", get_name(),
this, num_elements, matrix.
num_rows,
virtual int32_t get_dim_feature_space() const
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
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
EMessageType get_loglevel() const
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
void display_vector(const char *name="vector", const char *prefix="") 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()
static T abs(T a)
return the absolute value of a number