1 //------------------------------------------------------------------------------
2 // GB_nvals: number of entries in a matrix
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 #include "GB.h"
11
12 #define GB_FREE_ALL ;
13
GB_nvals(GrB_Index * nvals,const GrB_Matrix A,GB_Context Context)14 GrB_Info GB_nvals // get the number of entries in a matrix
15 (
16 GrB_Index *nvals, // matrix has nvals entries
17 const GrB_Matrix A, // matrix to query
18 GB_Context Context
19 )
20 {
21
22 //--------------------------------------------------------------------------
23 // check inputs
24 //--------------------------------------------------------------------------
25
26 GB_RETURN_IF_NULL (nvals) ;
27
28 // leave zombies alone, and leave jumbled, but assemble any pending tuples
29 GB_MATRIX_WAIT_IF_PENDING (A) ;
30
31 //--------------------------------------------------------------------------
32 // return the number of entries in the matrix
33 //--------------------------------------------------------------------------
34
35 // Pending tuples are disjoint from the zombies and the live entries in the
36 // matrix. However, there can be duplicates in the pending tuples, and the
37 // number of duplicates has not yet been determined. Thus, zombies can be
38 // tolerated but pending tuples cannot.
39
40 ASSERT (GB_ZOMBIES_OK (A)) ;
41 ASSERT (GB_JUMBLED_OK (A)) ;
42 ASSERT (!GB_PENDING (A)) ;
43
44 (*nvals) = GB_NNZ (A) - (A->nzombies) ;
45 return (GrB_SUCCESS) ;
46 }
47
48