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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
//------------------------------------------------------------------------------
// GB_assign_describe: construct a string that describes GrB_assign / subassign
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
void GB_assign_describe
(
// output
char *str, // string of size slen
int slen,
// input
const bool C_replace, // descriptor for C
const int Ikind,
const int Jkind,
const bool M_is_null,
const int M_sparsity,
const bool Mask_comp, // true for !M, false for M
const bool Mask_struct, // true if M is structural, false if valued
const GrB_BinaryOp accum, // present here
const bool A_is_null,
const int assign_kind // row assign, col assign, assign, or subassign
)
{
//--------------------------------------------------------------------------
// construct the accum operator string
//--------------------------------------------------------------------------
str [0] = '\0' ;
char *op_str ;
if (accum == NULL)
{
// no accum operator is present
op_str = "" ;
}
else
{
// use a simpler version of accum->name
if (accum->opcode == GB_USER_binop_code) op_str = "op" ;
else if (GB_STRING_MATCH (accum->name, "plus")) op_str = "+" ;
else if (GB_STRING_MATCH (accum->name, "minus")) op_str = "-" ;
else if (GB_STRING_MATCH (accum->name, "times")) op_str = "*" ;
else if (GB_STRING_MATCH (accum->name, "div")) op_str = "/" ;
else if (GB_STRING_MATCH (accum->name, "or")) op_str = "|" ;
else if (GB_STRING_MATCH (accum->name, "and")) op_str = "&" ;
else if (GB_STRING_MATCH (accum->name, "xor")) op_str = "^" ;
else op_str = accum->name ;
}
//--------------------------------------------------------------------------
// construct the Mask string
//--------------------------------------------------------------------------
#define GB_MASK_STRING_LEN 128
const char *Mask ;
char Mask_string [GB_MASK_STRING_LEN+1] ;
if (M_is_null)
{
// M is not present
if (Mask_comp)
{
Mask = C_replace ? "<!,replace>" : "<!>" ;
}
else
{
Mask = C_replace ? "<replace>" : "" ;
}
}
else
{
// M is present
snprintf (Mask_string, GB_MASK_STRING_LEN, "<%sM%s%s%s>",
(Mask_comp) ? "!" : "",
(M_sparsity == GxB_BITMAP) ? ",bitmap"
: ((M_sparsity == GxB_FULL) ? ",full" : ""),
Mask_struct ? ",struct" : "",
C_replace ? ",replace" : "") ;
Mask = Mask_string ;
}
//--------------------------------------------------------------------------
// construct the string for A or the scalar
//--------------------------------------------------------------------------
const char *S = (A_is_null) ? "scalar" : "A" ;
//--------------------------------------------------------------------------
// construct the string for (I,J)
//--------------------------------------------------------------------------
const char *Istr = (Ikind == GB_ALL) ? ":" : "I" ;
const char *Jstr = (Jkind == GB_ALL) ? ":" : "J" ;
//--------------------------------------------------------------------------
// burble the final result
//--------------------------------------------------------------------------
switch (assign_kind)
{
case GB_ROW_ASSIGN :
// C(i,J) = A
snprintf (str, slen, "C%s(i,%s) %s= A ", Mask, Jstr, op_str) ;
break ;
case GB_COL_ASSIGN :
// C(I,j) = A
snprintf (str, slen, "C%s(%s,j) %s= A ", Mask, Istr, op_str) ;
break ;
case GB_ASSIGN :
// C<M>(I,J) = A
if (Ikind == GB_ALL && Jkind == GB_ALL)
{
// C<M> += A
snprintf (str, slen, "C%s %s= %s ", Mask, op_str, S) ;
}
else
{
// C<M>(I,J) = A
snprintf (str, slen, "C%s(%s,%s) %s= %s ", Mask, Istr, Jstr,
op_str, S) ;
}
break ;
case GB_SUBASSIGN :
// C(I,J)<M> = A
if (Ikind == GB_ALL && Jkind == GB_ALL)
{
// C<M> += A
snprintf (str, slen, "C%s %s= %s ", Mask, op_str, S) ;
}
else
{
// C(I,J)<M> = A
snprintf (str, slen, "C(%s,%s)%s %s= %s ", Istr, Jstr, Mask,
op_str, S) ;
}
break ;
default: ;
}
}
|