80 REQUIRE(vec,
"vec must not be NULL\n");
93 vec[
features[i].feat_index] += alpha*features[i].entry;
99 template <
typename ST>
110 result +=
static_cast<T
>(vec[
features[i].feat_index])
174 int32_t dimensions = -1;
178 if (
features[i].feat_index > dimensions)
180 dimensions =
features[i].feat_index;
184 return dimensions + 1;
202 feat_idx[j] =
features[j].feat_index;
211 "sort_features(): failed sanity check %d <= %d after sorting (comparing indices features[%d] <= features[%d], features=%d)\n",
212 features[j - 1].feat_index,
features[j].feat_index, j - 1, j, num_feat_entries);
216 int32_t last_index = 0;
222 "sort_features(): target index %d must not exceed source index j=%d",
225 "sort_features(): failed sanity check %d = features[%d].feat_index <= features[%d].feat_index = %d\n",
236 if (
features[last_index].entry != 0.0)
245 if (
features[last_index].entry == 0.0)
250 int32_t new_feat_count = last_index + 1;
251 ASSERT(new_feat_count <= num_feat_entries);
256 SG_SINFO(
"shrinking vector from %d to %d\n", num_feat_entries, new_feat_count);
260 num_feat_entries = new_feat_count;
265 "sort_features(): failed sanity check %d < %d after sorting (comparing indices features[%d] < features[%d], features=%d)\n",
266 features[j - 1].feat_index,
features[j].feat_index, j - 1, j, num_feat_entries);
305 if (
features[i].feat_index == index)
383 SG_SERROR(
"SGSparseVector::load():: Not supported for complex128_t\n");
389 SG_SERROR(
"SGSparseVector::save():: Not supported for complex128_t\n");
416 SG_SWARNING(
"Computing sparse_dot(a,b) on unsorted vectors is very expensive: O(n^2)\n");
417 SG_SWARNING(
"Using fallback to give correct results because upstream code does not sort.\n");
423 const T tmp = b.
features[b_idx].entry;
429 dot_prod += tmp * a.
features[a_idx].entry;
612 SG_SPRINT(
"%s%s%d:(%.18lg+i%.18lg)", prefix, i == 0 ?
"" :
" ",
features[i].feat_index,
T get_feature(int32_t index)
void sort_features(bool stable_pointer=false)
std::complex< float64_t > complex128_t
virtual void copy_data(const SGReferencedData &orig)
int32_t get_num_dimensions()
static void qsort_index(T1 *output, T2 *index, uint32_t size)
virtual void set_sparse_vector(const SGSparseVectorEntry< bool > *entries, int32_t num_feat)
void add_to_dense(T alpha, T *vec, int32_t dim, bool abs_val=false)
T sparse_dot(const SGSparseVector< T > &v)
SGVector< T > get_dense()
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
shogun reference count managed data
SGSparseVector< T > clone() const
A File access base class.
virtual void get_sparse_vector(SGSparseVectorEntry< bool > *&entries, int32_t &num_feat)
void display_vector(const char *name="vector", const char *prefix="")
static T dot_prod_expensive_unsorted(const SGSparseVector< T > &a, const SGSparseVector< T > &b)
all of classes and functions are contained in the shogun namespace
T dense_dot(T alpha, T *vec, int32_t dim, T b)
template class SGSparseVectorEntry
virtual ~SGSparseVector()
void resize_vector(int32_t n)
SGSparseVectorEntry< T > * features