1 //------------------------------------------------------------------------------
2 // gbdisp: display a GraphBLAS matrix struct
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: GPL-3.0-or-later
7
8 //------------------------------------------------------------------------------
9
10 // Usage:
11
12 // gbdisp (C, cnz, level)
13
14 #include "gb_matlab.h"
15
16 #define USAGE "usage: gbdisp (C, cnz, level)"
17
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])18 void mexFunction
19 (
20 int nargout,
21 mxArray *pargout [ ],
22 int nargin,
23 const mxArray *pargin [ ]
24 )
25 {
26
27 //--------------------------------------------------------------------------
28 // check inputs
29 //--------------------------------------------------------------------------
30
31 gb_usage (nargin == 3 && nargout == 0, USAGE) ;
32
33 //--------------------------------------------------------------------------
34 // get cnz and level
35 //--------------------------------------------------------------------------
36
37 int64_t cnz = (int64_t) mxGetScalar (pargin [1]) ;
38 int level = (int) mxGetScalar (pargin [2]) ;
39
40 #define LEN 256
41 char s [LEN+1] ;
42 if (cnz == 0)
43 {
44 snprintf (s, LEN, "no nonzeros") ;
45 }
46 else if (cnz == 1)
47 {
48 snprintf (s, LEN, "1 nonzero") ;
49 }
50 else
51 {
52 snprintf (s, LEN, GBd " nonzeros", cnz) ;
53 }
54
55 s [LEN] = '\0' ;
56
57 //--------------------------------------------------------------------------
58 // print the GraphBLAS matrix
59 //--------------------------------------------------------------------------
60
61 // print 1-based indices
62 GB_Global_print_one_based_set (true) ;
63
64 GrB_Matrix C = gb_get_shallow (pargin [0]) ;
65 OK (GxB_Matrix_fprint (C, s, level, NULL)) ;
66 OK (GrB_Matrix_free (&C)) ;
67 GB_WRAPUP ;
68 }
69
70