SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SGSparseVector.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013,2014 Thoralf Klein
8  * Written (W) 2012 Fernando José Iglesias García
9  * Written (W) 2010,2012 Soeren Sonnenburg
10  * Copyright (C) 2010 Berlin Institute of Technology
11  * Copyright (C) 2012 Soeren Sonnenburg
12  */
13 
14 #ifndef __SGSPARSEVECTOR_H__
15 #define __SGSPARSEVECTOR_H__
16 
17 #include <shogun/lib/config.h>
18 
20 #include <shogun/lib/SGVector.h>
21 
22 namespace shogun
23 {
24  class CFile;
25 
27 template <class T> struct SGSparseVectorEntry
28 {
32  T entry;
33 };
34 
40 template <class T> class SGSparseVector : public SGReferencedData
41 {
42 public:
45 
52  SGSparseVector(SGSparseVectorEntry<T>* feats, index_t num_entries,
53  bool ref_counting=true);
54 
56  SGSparseVector(index_t num_entries, bool ref_counting=true);
57 
59  SGSparseVector(const SGSparseVector& orig);
60 
61  virtual ~SGSparseVector();
62 
74  T dense_dot(T alpha, T* vec, int32_t dim, T b);
75 
82  template<typename ST> T dense_dot(SGVector<ST> vec);
83 
91  T sparse_dot(const SGSparseVector<T>& v);
92 
100  static T sparse_dot(const SGSparseVector<T>& a, const SGSparseVector<T>& b);
101 
107  inline SGSparseVector<T> get()
108  {
109  return *this;
110  }
111 
117  int32_t get_num_dimensions();
118 
127  void sort_features(bool stable_pointer = false);
128 
134  bool is_sorted() const;
135 
142  T get_feature(int32_t index);
143 
150  SGVector<T> get_dense(int32_t dimension);
151 
158 
160  SGSparseVector<T> clone() const;
161 
166  void load(CFile* loader);
167 
172  void save(CFile* saver);
173 
182  void add_to_dense(T alpha, T * vec, int32_t dim, bool abs_val = false);
183 
189  void display_vector(const char* name="vector",
190  const char* prefix="");
191 
192 protected:
193  virtual void copy_data(const SGReferencedData& orig);
194 
195  virtual void init_data();
196 
197  virtual void free_data();
198 
209 
210 public:
213 
216 
217 };
218 
219 }
220 
221 #endif // __SGSPARSEVECTOR_H__
void sort_features(bool stable_pointer=false)
T sparse_dot(const SGSparseVector< T > &v)
int32_t index_t
Definition: common.h:62
virtual void copy_data(const SGReferencedData &orig)
static T dot_prod_expensive_unsorted(const SGSparseVector< T > &a, const SGSparseVector< T > &b)
void display_vector(const char *name="vector", const char *prefix="")
void save(CFile *saver)
shogun vector
void add_to_dense(T alpha, T *vec, int32_t dim, bool abs_val=false)
shogun reference count managed data
A File access base class.
Definition: File.h:34
SGSparseVectorEntry< T > * features
T dense_dot(T alpha, T *vec, int32_t dim, T b)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
template class SGSparseVectorEntry
Definition: File.h:23
T get_feature(int32_t index)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
SGVector< T > get_dense()
SGSparseVector< T > clone() const
void load(CFile *loader)

SHOGUN Machine Learning Toolbox - Documentation