From ab119782aca1a2eb9216cd721bca3ab9a0235911 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Wed, 7 Dec 2016 21:05:57 +0100 Subject: allow datasets to be stored in libsvm/svmlight format --- src/gensvm_sparse.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/gensvm_sparse.c') diff --git a/src/gensvm_sparse.c b/src/gensvm_sparse.c index ce99b3b..1a9317e 100644 --- a/src/gensvm_sparse.c +++ b/src/gensvm_sparse.c @@ -90,6 +90,23 @@ long gensvm_count_nnz(double *A, long rows, long cols) return nnz; } +/** + * @brief Compare the number of nonzeros is such that sparsity if worth it + * + * @details + * This is a utility function, see gensvm_could_sparse() for more info. + * + * @param[in] nnz number of nonzero elements + * @param[in] rows number of rows + * @param[in] cols number of columns + * + * @return whether or not sparsity is worth it + */ +bool gensvm_nnz_comparison(long nnz, long rows, long cols) +{ + return (nnz < (rows*(cols-1.0)-1.0)/2.0); +} + /** * @brief Check if it is worthwile to convert to a sparse matrix * @@ -100,20 +117,19 @@ long gensvm_count_nnz(double *A, long rows, long cols) * the amount of nonzero entries is small enough, the function returns the * number of nonzeros. If it is too big, it returns -1. * + * @sa + * gensvm_nnz_comparison() + * * @param[in] A matrix in dense format (RowMajor order) * @param[in] rows number of rows of A * @param[in] cols number of columns of A * - * @return + * @return whether or not sparsity is worth it */ bool gensvm_could_sparse(double *A, long rows, long cols) { long nnz = gensvm_count_nnz(A, rows, cols); - - if (nnz < (rows*(cols-1.0)-1.0)/2.0) { - return true; - } - return false; + return gensvm_nnz_comparison(nnz, rows, cols); } -- cgit v1.2.3