LCOV - code coverage report
Current view: top level - src - gensvm_debug.c (source / functions) Hit Total Coverage
Test: coverage.all Lines: 28 28 100.0 %
Date: 2017-02-21 18:44:20 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file gensvm_debug.c
       3             :  * @author G.J.J. van den Burg
       4             :  * @date 2016-05-01
       5             :  * @brief Functions facilitating debugging
       6             :  *
       7             :  * @details
       8             :  * Defines functions useful for debugging matrices.
       9             :  *
      10             :  * @copyright
      11             :  Copyright 2016, G.J.J. van den Burg.
      12             : 
      13             :  This file is part of GenSVM.
      14             : 
      15             :  GenSVM is free software: you can redistribute it and/or modify
      16             :  it under the terms of the GNU General Public License as published by
      17             :  the Free Software Foundation, either version 3 of the License, or
      18             :  (at your option) any later version.
      19             : 
      20             :  GenSVM is distributed in the hope that it will be useful,
      21             :  but WITHOUT ANY WARRANTY; without even the implied warranty of
      22             :  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      23             :  GNU General Public License for more details.
      24             : 
      25             :  You should have received a copy of the GNU General Public License
      26             :  along with GenSVM. If not, see <http://www.gnu.org/licenses/>.
      27             : 
      28             :  */
      29             : 
      30             : #include "gensvm_debug.h"
      31             : 
      32             : /**
      33             :  * @brief Print a dense matrix
      34             :  *
      35             :  * @details
      36             :  * Debug function to print a matrix
      37             :  *
      38             :  * @param[in]   M       matrix
      39             :  * @param[in]   rows    number of rows of M
      40             :  * @param[in]   cols    number of columns of M
      41             :  */
      42           1 : void gensvm_print_matrix(double *M, long rows, long cols)
      43             : {
      44             :         long i, j;
      45             : 
      46           4 :         for (i=0; i<rows; i++) {
      47           9 :                 for (j=0; j<cols; j++) {
      48           6 :                         if (j > 0)
      49           3 :                                 note(" ");
      50           6 :                         note("%+6.6f", matrix_get(M, cols, i, j));
      51             :                 }
      52           3 :                 note("\n");
      53             :         }
      54           1 :         note("\n");
      55           1 : }
      56             : 
      57             : /**
      58             :  * @brief Print a sparse matrix
      59             :  *
      60             :  * @details
      61             :  * Debug function to print a GenSparse sparse matrix
      62             :  *
      63             :  * @param[in]   A       a GenSparse matrix to print
      64             :  *
      65             :  */
      66           1 : void gensvm_print_sparse(struct GenSparse *A)
      67             : {
      68             :         long i;
      69             : 
      70             :         // print matrix dimensions
      71           1 :         note("Sparse Matrix:\n");
      72           1 :         note("\tnnz = %li, rows = %li, cols = %li\n", A->nnz, A->n_row,
      73             :                         A->n_col);
      74             : 
      75             :         // print nonzero values
      76           1 :         note("\tvalues = [ ");
      77           5 :         for (i=0; i<A->nnz; i++) {
      78           4 :                 if (i != 0) note(", ");
      79           4 :                 note("%f", A->values[i]);
      80             :         }
      81           1 :         note(" ]\n");
      82             : 
      83             :         // print row indices
      84           1 :         note("\tIA = [ ");
      85           6 :         for (i=0; i<A->n_row+1; i++) {
      86           5 :                 if (i != 0) note(", ");
      87           5 :                 note("%i", A->ia[i]);
      88             :         }
      89           1 :         note(" ]\n");
      90             : 
      91             :         // print column indices
      92           1 :         note("\tJA = [ ");
      93           5 :         for (i=0; i<A->nnz; i++) {
      94           4 :                 if (i != 0) note(", ");
      95           4 :                 note("%i", A->ja[i]);
      96             :         }
      97           1 :         note(" ]\n");
      98           1 : }

Generated by: LCOV version 1.12