1 //------------------------------------------------------------------------------
2 // GB_convert_hyper_to_sparse_test: test conversion of hypersparse to sparse
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 // Returns true if a hypersparse matrix should be converted to sparse.
11 // Returns false if the matrix should stay hypersparse.
12 
13 // A matrix with vdim <= 1 must always be sparse, not hypersparse;
14 // that is, a GrB_Vector is never hypersparse.
15 
16 #include "GB.h"
17 
GB_convert_hyper_to_sparse_test(float hyper_switch,int64_t k,int64_t vdim)18 bool GB_convert_hyper_to_sparse_test    // test for hypersparse to sparse
19 (
20     float hyper_switch,     // A->hyper_switch
21     int64_t k,              // # of non-empty vectors of A (estimate is OK)
22     int64_t vdim            // A->vdim
23 )
24 {
25 
26     // get the vector dimension of this matrix
27     float n = (float) vdim ;
28 
29     // ensure k is in the range 0 to n, inclusive
30     k = GB_IMAX (k, 0) ;
31     k = GB_IMIN (k, n) ;
32 
33     return (n <= 1 || (((float) k) > n * hyper_switch * 2)) ;
34 }
35 
36