SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
174 
180  void display_vector(const char* name="vector",
181  const char* prefix="");
182 
183 protected:
184  virtual void copy_data(const SGReferencedData& orig);
185 
186  virtual void init_data();
187 
188  virtual void free_data();
189 
200 
201 public:
204 
207 
208 };
209 
210 }
211 
212 #endif // __SGSPARSEVECTOR_H__

SHOGUN Machine Learning Toolbox - Documentation