SHOGUN
6.0.0
src
shogun
lib
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
19
#include <
shogun/lib/SGReferencedData.h
>
20
#include <
shogun/lib/SGVector.h
>
21
22
namespace
shogun
23
{
24
class
CFile;
25
27
template
<
class
T>
struct
SGSparseVectorEntry
28
{
30
index_t
feat_index
;
32
T
entry
;
33
};
34
40
template
<
class
T>
class
SGSparseVector
:
public
SGReferencedData
41
{
42
public
:
44
SGSparseVector
();
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
157
SGVector<T>
get_dense();
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
208
static
T dot_prod_expensive_unsorted(
const
SGSparseVector<T>
& a,
const
SGSparseVector<T>
& b);
209
210
public
:
212
index_t
num_feat_entries
;
213
215
SGSparseVectorEntry<T>
*
features
;
216
217
};
218
219
}
220
221
#endif // __SGSPARSEVECTOR_H__
SGReferencedData.h
index_t
int32_t index_t
Definition:
common.h:72
shogun::SGSparseVectorEntry::feat_index
index_t feat_index
Definition:
SGSparseVector.h:30
shogun::SGSparseVector
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
Definition:
base/Parameter.h:29
shogun::SGReferencedData
shogun reference count managed data
Definition:
SGReferencedData.h:21
shogun::SGSparseVectorEntry::entry
T entry
Definition:
SGSparseVector.h:32
shogun::CFile
A File access base class.
Definition:
File.h:34
shogun::SGVector
shogun vector
Definition:
base/Parameter.h:28
shogun
all of classes and functions are contained in the shogun namespace
Definition:
class_list.h:18
shogun::SGSparseVector::num_feat_entries
index_t num_feat_entries
Definition:
SGSparseVector.h:212
shogun::SGSparseVectorEntry
template class SGSparseVectorEntry
Definition:
File.h:23
SGVector.h
shogun::SGSparseVector::features
SGSparseVectorEntry< T > * features
Definition:
SGSparseVector.h:215
SHOGUN
Machine Learning Toolbox - Documentation