SHOGUN  6.1.3
List of all members | Public Member Functions | Public Attributes | Protected Member Functions
SGSparseMatrix< T > Class Template Reference

Detailed Description

template<class T>
class shogun::SGSparseMatrix< T >

template class SGSparseMatrix

Definition at line 27 of file base/Parameter.h.

Inheritance diagram for SGSparseMatrix< T >:
[legend]

Public Member Functions

 SGSparseMatrix ()
 
 SGSparseMatrix (SGSparseVector< T > *vecs, index_t num_feat, index_t num_vec, bool ref_counting=true)
 
 SGSparseMatrix (index_t num_feat, index_t num_vec, bool ref_counting=true)
 
 SGSparseMatrix (SGMatrix< T > dense)
 
 SGSparseMatrix (const SGSparseMatrix &orig)
 
virtual ~SGSparseMatrix ()
 
const SGSparseVector< T > & operator[] (index_t index) const
 
SGSparseVector< T > & operator[] (index_t index)
 
SGSparseMatrix< T > get ()
 
const SGVector< T > operator* (SGVector< T > v) const
 
template<class ST >
const SGVector< T > operator* (SGVector< ST > v) const
 
const T operator() (index_t i_row, index_t i_col) const
 
T & operator() (index_t i_row, index_t i_col)
 
void load (CFile *loader)
 
SGVector< float64_tload_with_labels (CLibSVMFile *libsvm_file, bool do_sort_features=true)
 
void save (CFile *saver)
 
void save_with_labels (CLibSVMFile *saver, SGVector< float64_t > labels)
 
SGSparseMatrix< T > get_transposed ()
 
void from_dense (SGMatrix< T > full)
 
void sort_features ()
 
template<>
const SGVector< complex128_toperator* (SGVector< float64_t > v) const
 
template<>
const SGVector< complex128_toperator* (SGVector< int32_t > v) const
 
template<>
const SGVector< float64_toperator* (SGVector< int32_t > v) const
 
template<>
void load (CFile *loader)
 
template<>
SGVector< float64_tload_with_labels (CLibSVMFile *file, bool do_sort_features)
 
template<>
void save (CFile *saver)
 
template<>
void save_with_labels (CLibSVMFile *saver, SGVector< float64_t > labels)
 
int32_t ref_count ()
 

Public Attributes

index_t num_vectors
 total number of vectors More...
 
index_t num_features
 total number of features More...
 
SGSparseVector< T > * sparse_matrix
 array of sparse vectors of size num_vectors More...
 

Protected Member Functions

virtual void copy_data (const SGReferencedData &orig)
 
virtual void init_data ()
 
virtual void free_data ()
 
void copy_refcount (const SGReferencedData &orig)
 
int32_t ref ()
 
int32_t unref ()
 

Constructor & Destructor Documentation

◆ SGSparseMatrix() [1/5]

default constructor

Definition at line 11 of file SGSparseMatrix.cpp.

◆ SGSparseMatrix() [2/5]

SGSparseMatrix ( SGSparseVector< T > *  vecs,
index_t  num_feat,
index_t  num_vec,
bool  ref_counting = true 
)

constructor for setting params

Definition at line 17 of file SGSparseMatrix.cpp.

◆ SGSparseMatrix() [3/5]

SGSparseMatrix ( index_t  num_feat,
index_t  num_vec,
bool  ref_counting = true 
)

constructor to create new matrix in memory

Definition at line 26 of file SGSparseMatrix.cpp.

◆ SGSparseMatrix() [4/5]

SGSparseMatrix ( SGMatrix< T >  dense)

constructor to create new sparse matrix from a dense one

Parameters
densedense matrix to be converted

Definition at line 34 of file SGSparseMatrix.cpp.

◆ SGSparseMatrix() [5/5]

SGSparseMatrix ( const SGSparseMatrix< T > &  orig)

copy constructor

Definition at line 40 of file SGSparseMatrix.cpp.

◆ ~SGSparseMatrix()

~SGSparseMatrix ( )
virtual

destructor

Definition at line 46 of file SGSparseMatrix.cpp.

Member Function Documentation

◆ copy_data()

void copy_data ( const SGReferencedData orig)
protectedvirtual

copy data

Implements SGReferencedData.

Definition at line 159 of file SGSparseMatrix.cpp.

◆ copy_refcount()

void copy_refcount ( const SGReferencedData orig)
protectedinherited

copy refcount

Definition at line 55 of file SGReferencedData.cpp.

◆ free_data()

void free_data ( )
protectedvirtual

free data

Implements SGReferencedData.

Definition at line 175 of file SGSparseMatrix.cpp.

◆ from_dense()

void from_dense ( SGMatrix< T >  full)

create a sparse matrix from a dense one

Parameters
fullthe dense matrix to create the sparse one from

Definition at line 232 of file SGSparseMatrix.cpp.

◆ get()

SGSparseMatrix<T> get ( )

get the sparse matrix (no copying is done here)

Returns
the refcount increased matrix

Definition at line 75 of file SGSparseMatrix.h.

◆ get_transposed()

SGSparseMatrix< T > get_transposed ( )

return the transposed of the sparse matrix

Definition at line 182 of file SGSparseMatrix.cpp.

◆ init_data()

void init_data ( )
protectedvirtual

init data

Implements SGReferencedData.

Definition at line 167 of file SGSparseMatrix.cpp.

◆ load() [1/2]

void load ( CFile loader)

Definition at line 102 of file SGSparseMatrix.cpp.

◆ load() [2/2]

void load ( CFile loader)

load sparse matrix from file

Parameters
loaderFile object via which to load data

Definition at line 91 of file SGSparseMatrix.cpp.

◆ load_with_labels() [1/2]

SGVector< float64_t > load_with_labels ( CLibSVMFile file,
bool  do_sort_features 
)

Definition at line 123 of file SGSparseMatrix.cpp.

◆ load_with_labels() [2/2]

SGVector< float64_t > load_with_labels ( CLibSVMFile libsvm_file,
bool  do_sort_features = true 
)

load sparse matrix from libsvm file together with labels

Parameters
libsvm_filethe libsvm file
do_sort_featureswhether to sort the vector indices (such that they are in ascending order) after loading
Returns
label vector

Definition at line 107 of file SGSparseMatrix.cpp.

◆ operator()() [1/2]

const T operator() ( index_t  i_row,
index_t  i_col 
) const

operator overload for sparse-matrix read only access

Parameters
i_row
i_col

Definition at line 106 of file SGSparseMatrix.h.

◆ operator()() [2/2]

T& operator() ( index_t  i_row,
index_t  i_col 
)

operator overload for sparse-matrix r/w access

Parameters
i_row
i_col

Definition at line 127 of file SGSparseMatrix.h.

◆ operator*() [1/5]

const SGVector< complex128_t > operator* ( SGVector< float64_t v) const

Definition at line 52 of file SGSparseMatrix.cpp.

◆ operator*() [2/5]

const SGVector< complex128_t > operator* ( SGVector< int32_t >  v) const

Definition at line 65 of file SGSparseMatrix.cpp.

◆ operator*() [3/5]

const SGVector< float64_t > operator* ( SGVector< int32_t >  v) const

Definition at line 78 of file SGSparseMatrix.cpp.

◆ operator*() [4/5]

const SGVector<T> operator* ( SGVector< T >  v) const

compute sparse-matrix dense-vector multiplication

Parameters
vthe dense-vector to be multiplied with
Returns
the result vector \(Q*v\), Q being this sparse matrix

Definition at line 84 of file SGSparseMatrix.h.

◆ operator*() [5/5]

const SGVector<T> operator* ( SGVector< ST >  v) const

compute sparse-matrix dense-vector multiplication

Parameters
vthe dense-vector to be multiplied with
Returns
the result vector \(Q*v\), Q being this sparse matrix

◆ operator[]() [1/2]

const SGSparseVector<T>& operator[] ( index_t  index) const

index access operator

Definition at line 59 of file SGSparseMatrix.h.

◆ operator[]() [2/2]

SGSparseVector<T>& operator[] ( index_t  index)

index access operator

Definition at line 65 of file SGSparseMatrix.h.

◆ ref()

int32_t ref ( )
protectedinherited

increase reference counter

Returns
reference count

Definition at line 64 of file SGReferencedData.cpp.

◆ ref_count()

int32_t ref_count ( )
inherited

display reference counter

Returns
reference count

Definition at line 41 of file SGReferencedData.cpp.

◆ save() [1/2]

void save ( CFile saver)

Definition at line 137 of file SGSparseMatrix.cpp.

◆ save() [2/2]

void save ( CFile saver)

save sparse matrix to file

Parameters
saverFile object via which to save data

Definition at line 127 of file SGSparseMatrix.cpp.

◆ save_with_labels() [1/2]

void save_with_labels ( CLibSVMFile saver,
SGVector< float64_t labels 
)

Definition at line 155 of file SGSparseMatrix.cpp.

◆ save_with_labels() [2/2]

void save_with_labels ( CLibSVMFile saver,
SGVector< float64_t labels 
)

save sparse matrix together with labels to file

Parameters
saverFile object via which to save data
labelslabel vector

Definition at line 142 of file SGSparseMatrix.cpp.

◆ sort_features()

void sort_features ( )

sort the indices of the sparse matrix such that they are in ascending order

Definition at line 224 of file SGSparseMatrix.cpp.

◆ unref()

int32_t unref ( )
protectedinherited

decrement reference counter and deallocate object if refcount is zero before or after decrementing it

Returns
reference count

Definition at line 84 of file SGReferencedData.cpp.

Member Data Documentation

◆ num_features

index_t num_features

total number of features

Definition at line 207 of file SGSparseMatrix.h.

◆ num_vectors

index_t num_vectors

total number of vectors

Definition at line 204 of file SGSparseMatrix.h.

◆ sparse_matrix

SGSparseVector<T>* sparse_matrix

array of sparse vectors of size num_vectors

Definition at line 210 of file SGSparseMatrix.h.


The documentation for this class was generated from the following files:

SHOGUN Machine Learning Toolbox - Documentation