124 int32_t tmp_len = len;
125 ST* tmp_feat_before = feat;
126 ST* tmp_feat_after = NULL;
135 tmp_feat_after = applied.
vector;
139 SG_FREE(tmp_feat_before);
140 tmp_feat_before = tmp_feat_after;
146 sg_memcpy(feat, tmp_feat_after,
sizeof(ST) * tmp_len);
147 SG_FREE(tmp_feat_after);
162 SG_ERROR(
"Index out of bounds (number of vectors %d, you " 167 SG_ERROR(
"Requires a in-memory feature matrix\n")
184 SG_ERROR(
"Index out of bounds (number of vectors %d, you " 212 SG_ERROR(
"A subset is set, cannot call vector_subset\n")
222 for (int32_t i = 0; i < idx_len; i++)
227 if (ii < 0 || ii >= num_vec)
228 SG_ERROR(
"Index out of range: should be 0<%d<%d\n", ii, num_vec)
243 SG_ERROR(
"A subset is set, cannot call feature_subset\n")
256 for (int32_t j = 0; j < idx_len; j++)
260 if (jj < 0 || jj >= num_feat)
262 "Index out of range: should be 0<%d<%d\n", jj, num_feat);
284 REQUIRE(column_offset>=0,
"Column offset (%d) cannot be negative!\n", column_offset);
288 index_t num_cols=num_vecs+column_offset;
290 REQUIRE(target.
matrix!=
nullptr,
"Provided matrix is not allocated!\n");
292 "Number of rows of given matrix (%d) should be equal to the number of features (%d)!\n",
295 "Number of cols of given matrix (%d) should be at least %d!\n",
306 for (int32_t i=0; i<num_vecs; ++i)
323 return st_feature_matrix;
358 ST* fm = SG_MALLOC(ST, int64_t(num_feat) * num_vec);
360 for (int32_t i=0; i<old_num_vec; i++)
364 for (int32_t j=0; j<vec.
vlen; j++)
365 fm[j*int64_t(old_num_vec)+i]=vec.
vector[j];
380 ASSERT(num_feat>0 && num_vec>0)
385 for (int32_t i = 0; i < num_vec; i++)
390 for (int32_t j = 0; j < num_feat; j++)
400 SG_ERROR(
"A subset is set, cannot call apply_preproc\n")
402 SG_DEBUG(
"force: %d\n", force_preprocessing)
433 SG_ERROR(
"no preprocessors available\n")
455 SG_ERROR(
"A subset is set, cannot call set_num_vectors\n")
464 SG_ERROR(
"A subset is set, cannot call initialize_cache\n")
480 SG_ERROR(
"A subset is set, cannot call reshape\n")
482 if (p_num_features * p_num_vectors
486 num_vectors = p_num_vectors;
506 ST* vec2 = sf->get_feature_vector(vec_idx2, len2, free2);
511 sf->free_feature_vector(vec2, vec_idx2, free2);
517 float64_t* vec2, int32_t vec2_len,
bool abs_val)
535 vec2[i] += alpha * vec1[i];
543 float64_t* vec2, int32_t vec2_len,
bool abs_val)
575 SG_ERROR(
"Index out of bounds (number of vectors %d, you " 579 dense_feature_iterator* iterator = SG_MALLOC(dense_feature_iterator, 1);
582 iterator->vidx = vector_index;
590 dense_feature_iterator* it = (dense_feature_iterator*) iterator;
591 if (!it || it->index >= it->vlen)
605 dense_feature_iterator* it = (dense_feature_iterator*) iterator;
619 num_features*
sizeof(ST));
635 REQUIRE(max<num_features && min>=0,
636 "Provided dimensions is in the range [%d, %d] but they " 637 "have to be within [0, %d]! But it \n", min, max,
num_features);
665 SG_REF(shallow_copy_features);
669 return shallow_copy_features;
697 #define GET_FEATURE_TYPE(f_type, sg_type) \ 698 template<> EFeatureType CDenseFeatures<sg_type>::get_feature_type() const \ 716 #undef GET_FEATURE_TYPE 731 result += vec1[i] ? vec2[i] : 0;
751 result += vec1[i] * vec2[i];
771 result += vec1[i] * vec2[i];
779 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
791 result += vec1[i] * vec2[i];
799 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
811 result += vec1[i] * vec2[i];
819 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
831 result += vec1[i] * vec2[i];
839 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
851 result += vec1[i] * vec2[i];
859 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
871 result += vec1[i] * vec2[i];
879 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
891 result += vec1[i] * vec2[i];
899 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
911 result += vec1[i] * vec2[i];
919 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
931 result += vec1[i] * vec2[i];
939 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
956 int32_t vec_idx1,
const float64_t* vec2, int32_t vec2_len)
968 result += vec1[i] * vec2[i];
982 int32_t v1len, v2len;
983 bool v1free, v2free, stop =
false;
993 for (int32_t j=0; j<v1len; j++)
995 if (vec1[j]!=vec2[j])
1014 REQUIRE(others!=
nullptr,
"The list of other feature instances is not initialized!\n");
1020 while (current!=
nullptr)
1024 REQUIRE(casted!=
nullptr,
"Provided object's type (%s) must match own type (%s)!\n",
1027 "Provided feature object has different dimension (%d) than this one (%d)!\n",
1030 total_num_vectors+=casted->get_num_vectors();
1045 while (current!=
nullptr)
1049 num_copied+=casted->get_num_vectors();
1066 auto list=some<CList>();
1067 list->append_element(other);
1075 matrix.
load(loader);
1088 "base_features must be of dynamic type CDenseFeatures\n")
SGVector< index_t > get_subset_idx() const
CSubsetStack * m_subset_stack
virtual int32_t get_dim_feature_space() const
SGMatrix< ST > get_feature_matrix()
virtual EFeatureType get_feature_type() const =0
void set_feature_matrix(SGMatrix< ST > matrix)
CSGObject * get_next_element()
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
virtual CFeatures * copy_subset(SGVector< index_t > indices)
void set_num_vectors(int32_t num)
int32_t num_features
number of features in cache
void set_preprocessed(int32_t num)
CDenseFeatures(int32_t size=0)
void set_feature_vector(SGVector< ST > vector, int32_t num)
void feature_subset(int32_t *idx, int32_t idx_len)
void obtain_from_dot(CDotFeatures *df)
virtual void * get_feature_iterator(int32_t vector_index)
virtual bool reshape(int32_t p_num_features, int32_t p_num_vectors)
#define SG_NOTIMPLEMENTED
void free_feature_matrix()
CPreprocessor * get_preprocessor(int32_t num) const
virtual EFeatureType get_feature_type() const
virtual bool is_equal(CDenseFeatures *rhs)
int32_t get_num_features() const
Features that support dot products among other operations.
void unlock_entry(int64_t number)
EFeatureClass
shogun feature class
ST * get_feature_vector(int32_t num, int32_t &len, bool &dofree)
class to add subset support to another class. A CSubsetStackStack instance should be added and wrappe...
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
int32_t get_num_preprocessors() const
T * set_entry(int64_t number)
CSubset * get_last_subset() const
virtual const char * get_name() const =0
CSGObject * get_first_element()
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
int32_t num_vectors
number of vectors in cache
virtual void remove_all_subsets()
Template class DensePreprocessor, base class for preprocessors (cf. CPreprocessor) that apply to CDen...
SGMatrix< ST > feature_matrix
bool is_preprocessed(int32_t num) const
virtual const char * get_name() const
void free_feature_vector(ST *feat_vec, int32_t num, bool dofree)
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
A File access base class.
virtual bool apply_preprocessor(bool force_preprocessing=false)
index_t subset_idx_conversion(index_t idx) const
virtual int32_t get_dim_feature_space() const =0
T * lock_entry(int64_t number)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
virtual CFeatures * shallow_subset_copy()
CCache< ST > * feature_cache
virtual EFeatureClass get_feature_class() const =0
CDenseFeatures< ST > * get_transposed()
SGMatrix< ST > steal_feature_matrix()
virtual CFeatures * duplicate() const
void set_num_features(int32_t num)
The class DenseFeatures implements dense feature matrices.
bool equals(const SGMatrix< T > &other) const
virtual EFeatureClass get_feature_class() const
all of classes and functions are contained in the shogun namespace
static CDenseFeatures * obtain_from_generic(CFeatures *const base_features)
int32_t get_cache_size() const
void vector_subset(int32_t *idx, int32_t idx_len)
The class Features is the base class of all feature objects.
virtual SGMatrix< ST > apply_to_feature_matrix(CFeatures *features)=0
virtual CFeatures * copy_dimension_subset(SGVector< index_t > dims)
void copy_feature_matrix(SGMatrix< ST > target, index_t column_offset=0) const
SGVector< float64_t > get_computed_dot_feature_vector(int32_t num)
virtual bool has_subsets() const
virtual void save(CFile *saver)
virtual void load(CFile *loader)
virtual ~CDenseFeatures()
void clean_preprocessors()
virtual ST * compute_feature_vector(int32_t num, int32_t &len, ST *target=NULL)
virtual int32_t get_nnz_features_for_vector(int32_t num)
T max(const Container< T > &a)
virtual SGVector< ST > apply_to_feature_vector(SGVector< ST > vector)=0
virtual int32_t get_num_vectors() const
CFeatures * create_merged_copy(CList *other)
virtual int32_t get_num_vectors() const =0
virtual void add_subset(SGVector< index_t > subset)
Class List implements a doubly connected list for low-level-objects.
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
#define GET_FEATURE_TYPE(f_type, sg_type)
virtual void free_feature_iterator(void *iterator)