1 //------------------------------------------------------------------------------
2 // gbnvals: number of entries in 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 // The input may be either a GraphBLAS matrix struct or a standard MATLAB
11 // sparse matrix.
12 
13 // Usage
14 
15 // nvals = gbnvals (X)
16 
17 #include "gb_matlab.h"
18 
19 #define USAGE "usage: nvals = gbnvals (X)"
20 
mexFunction(int nargout,mxArray * pargout[],int nargin,const mxArray * pargin[])21 void mexFunction
22 (
23     int nargout,
24     mxArray *pargout [ ],
25     int nargin,
26     const mxArray *pargin [ ]
27 )
28 {
29 
30     //--------------------------------------------------------------------------
31     // check inputs
32     //--------------------------------------------------------------------------
33 
34     gb_usage (nargin == 1 && nargout <= 1, USAGE) ;
35 
36     //--------------------------------------------------------------------------
37     // get a shallow copy of the matrix
38     //--------------------------------------------------------------------------
39 
40     GrB_Matrix X = gb_get_shallow (pargin [0]) ;
41 
42     //--------------------------------------------------------------------------
43     // get the # of entries in the matrix
44     //--------------------------------------------------------------------------
45 
46     GrB_Index nvals ;
47     OK (GrB_Matrix_nvals (&nvals, X)) ;
48 
49     //--------------------------------------------------------------------------
50     // free the shallow copy and return the result
51     //--------------------------------------------------------------------------
52 
53     pargout [0] = mxCreateDoubleScalar ((double) nvals) ;
54     OK (GrB_Matrix_free (&X)) ;
55     GB_WRAPUP ;
56 }
57 
58