1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
//------------------------------------------------------------------------------
// GB_masker_sparsity: determine the sparsity structure for C<M or !M>=Z
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// Determines the sparsity structure for R for computing R = masker (C,M,Z).
// If R should be hypersparse or sparse, on output, this function simply
// returns GxB_SPARSE. The final determination is made by GB_add_phase0,
// as called by GB_masker.
// C is sparse or hypersparse on input. It is never bitmap or full; that
// case is handled by GB_subassign instead. R can be constructed as sparse,
// hypersparse, or bitmap (not full). M and Z can have any sparsity pattern.
#include "GB_mask.h"
int GB_masker_sparsity // return the sparsity structure for R
(
// input:
const GrB_Matrix C, // input C matrix
const GrB_Matrix M, // mask for C, always present
const bool Mask_comp, // if true, use !M
const GrB_Matrix Z // input Z matrix
)
{
//--------------------------------------------------------------------------
// determine the sparsity of R
//--------------------------------------------------------------------------
// In the tables below "sparse" means either sparse or hypersparse.
ASSERT (GB_IS_SPARSE (C) || GB_IS_HYPERSPARSE (C)) ;
bool M_is_sparse = GB_IS_SPARSE (M) || GB_IS_HYPERSPARSE (M) ;
bool Z_is_sparse = GB_IS_SPARSE (Z) || GB_IS_HYPERSPARSE (Z) ;
int R_sparsity ;
if (Mask_comp)
{
// ------------------------------------------
// C <!M> = Z R
// ------------------------------------------
// sparse sparse sparse sparse
// sparse sparse bitmap bitmap
// sparse sparse full bitmap
// sparse bitmap sparse sparse
// sparse bitmap bitmap bitmap
// sparse bitmap full bitmap
// sparse full sparse sparse
// sparse full bitmap bitmap
// sparse full full bitmap
if (Z_is_sparse)
{
R_sparsity = GxB_SPARSE ;
}
else
{
R_sparsity = GxB_BITMAP ;
}
}
else
{
// ------------------------------------------
// C <M> = Z R
// ------------------------------------------
// sparse sparse sparse sparse
// sparse sparse bitmap sparse
// sparse sparse full sparse
// sparse bitmap sparse sparse
// sparse bitmap bitmap bitmap
// sparse bitmap full bitmap
// sparse full sparse sparse
// sparse full bitmap bitmap
// sparse full full bitmap
if (M_is_sparse || Z_is_sparse)
{
R_sparsity = GxB_SPARSE ;
}
else
{
R_sparsity = GxB_BITMAP ;
}
}
return (R_sparsity) ;
}
|