|
GenSVM
|
Header file for gensvm_sparse.c. More...
#include "gensvm_globals.h"

Go to the source code of this file.
Classes | |
| struct | GenSparse |
| A structure to represent a sparse matrix in CSR format. More... | |
Functions | |
| struct GenSparse * | gensvm_init_sparse (void) |
| Initialize a GenSparse structure. More... | |
| void | gensvm_free_sparse (struct GenSparse *sp) |
| Free an allocated GenSparse structure. More... | |
| long | gensvm_count_nnz (double *A, long rows, long cols) |
| Count the number of nonzeros in a matrix. More... | |
| bool | gensvm_nnz_comparison (long nnz, long rows, long cols) |
| Compare the number of nonzeros is such that sparsity if worth it. More... | |
| bool | gensvm_could_sparse (double *A, long rows, long cols) |
| Check if it is worthwile to convert to a sparse matrix. More... | |
| struct GenSparse * | gensvm_dense_to_sparse (double *A, long rows, long cols) |
| Convert a dense matrix to a GenSparse structure if advantageous. More... | |
| double * | gensvm_sparse_to_dense (struct GenSparse *A) |
| Convert a GenSparse structure to a dense matrix. More... | |
Header file for gensvm_sparse.c.
Contains declarations of the GenSparse structure and related functions.
This file is part of GenSVM.
GenSVM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
GenSVM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GenSVM. If not, see http://www.gnu.org/licenses/.
Definition in file gensvm_sparse.h.
| bool gensvm_could_sparse | ( | double * | A, |
| long | rows, | ||
| long | cols | ||
| ) |
Check if it is worthwile to convert to a sparse matrix.
It is only worth to convert to a sparse matrix if the amount of sparsity is sufficient. For this to be the case, the number of nonzeros must be smaller than
. This is tested here. If the amount of nonzero entries is small enough, the function returns the number of nonzeros. If it is too big, it returns -1.
| [in] | A | matrix in dense format (RowMajor order) |
| [in] | rows | number of rows of A |
| [in] | cols | number of columns of A |
Definition at line 129 of file gensvm_sparse.c.

| long gensvm_count_nnz | ( | double * | A, |
| long | rows, | ||
| long | cols | ||
| ) |
Count the number of nonzeros in a matrix.
This is a utility function to count the number of nonzeros in a dense matrix. This is simply done by comparing with 0.0.
| [in] | A | a dense matrix (RowMajor order) |
| [in] | rows | the number of rows of A |
| [in] | cols | the number of columns of A |
Definition at line 84 of file gensvm_sparse.c.
| struct GenSparse* gensvm_dense_to_sparse | ( | double * | A, |
| long | rows, | ||
| long | cols | ||
| ) |
Convert a dense matrix to a GenSparse structure if advantageous.
This utility function can be used to convert a dense matrix to a sparse matrix in the form of a GenSparse struture. Note that the allocated memory must be freed by the caller. The user should first check whether using a sparse matrix is worth it by calling gensvm_could_sparse().
| [in] | A | a dense matrix in RowMajor order |
| [in] | rows | number of rows of the matrix A |
| [in] | cols | number of columns of the matrix A |
Definition at line 150 of file gensvm_sparse.c.

| void gensvm_free_sparse | ( | struct GenSparse * | sp | ) |
Free an allocated GenSparse structure.
Simply free a previously allocated GenSparse structure by freeing all of its components. Finally, the structure itself is freed, and the pointer is set to NULL for safety.
| [in] | sp | GenSparse structure to free |
Definition at line 62 of file gensvm_sparse.c.
| struct GenSparse* gensvm_init_sparse | ( | void | ) |
Initialize a GenSparse structure.
A GenSparse structure is used to hold a sparse data matrix. We work with Compressed Row Storage (CSR) storage, also known as old Yale format.
Definition at line 38 of file gensvm_sparse.c.
| bool gensvm_nnz_comparison | ( | long | nnz, |
| long | rows, | ||
| long | cols | ||
| ) |
Compare the number of nonzeros is such that sparsity if worth it.
This is a utility function, see gensvm_could_sparse() for more info.
| [in] | nnz | number of nonzero elements |
| [in] | rows | number of rows |
| [in] | cols | number of columns |
Definition at line 105 of file gensvm_sparse.c.
| double* gensvm_sparse_to_dense | ( | struct GenSparse * | A | ) |
Convert a GenSparse structure to a dense matrix.
This function converts a GenSparse structure back to a normal dense matrix in RowMajor order. Note that the allocated memory must be freed by the caller.
| [in] | A | a GenSparse structure |
Definition at line 199 of file gensvm_sparse.c.
1.8.13