1 //------------------------------------------------------------------------------
2 // GB_convert_bitmap_to_sparse_test: test conversion of bitmap 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 bitmap matrix should be converted to sparse.
11 // Returns false if the matrix should stay bitmap.
12
13 // If A is m-by-n and A->sparsity is GxB_ANY_SPARSITY with b =
14 // A->bitmap_switch, the matrix switches to bitmap if nnz(A)/(m*n) > b. A
15 // bitmap matrix switches to sparse if nnz(A)/(m*n) <= b/2. A matrix whose
16 // density is between b/2 and b remains in its current state.
17
18 // A->bitmap_switch is normally a fraction in range 0 to 1. A value of 1
19 // ensures that A is never converted to bitmap.
20
21 // These default rules may change in future releases of SuiteSparse:GraphBLAS.
22
23 // If this test returns true and the matrix changes to sparse, then the rule
24 // for A->hyper_switch may then convert it from sparse to hypersparse.
25
26 #include "GB.h"
27
GB_convert_bitmap_to_sparse_test(float bitmap_switch,int64_t anz,int64_t vlen,int64_t vdim)28 bool GB_convert_bitmap_to_sparse_test // test for hyper/sparse to bitmap
29 (
30 float bitmap_switch, // A->bitmap_switch
31 int64_t anz, // # of entries in A = GB_NNZ (A)
32 int64_t vlen, // A->vlen
33 int64_t vdim // A->vdim
34 )
35 {
36
37 // current number of entries in the matrix or vector
38 float nnz = (float) anz ;
39
40 // maximum number of entries in the matrix or vector
41 float nnz_dense = ((float) vlen) * ((float) vdim) ;
42
43 // A should switch to sparse if the following condition is true:
44 return (nnz <= (bitmap_switch/2) * nnz_dense) ;
45 }
46
47