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
|
//------------------------------------------------------------------------------
// GrB_Descriptor_set: set a field in a descriptor
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
GrB_Info GrB_Descriptor_set // set a parameter in a descriptor
(
GrB_Descriptor desc, // descriptor to modify
GrB_Desc_Field field, // parameter to change
GrB_Desc_Value value // value to change it to
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
if (desc != NULL && desc->header_size == 0)
{
// built-in descriptors may not be modified
return (GrB_INVALID_VALUE) ;
}
GB_WHERE (desc, "GrB_Descriptor_set (desc, field, value)") ;
GB_RETURN_IF_NULL_OR_FAULTY (desc) ;
ASSERT_DESCRIPTOR_OK (desc, "desc to set", GB0) ;
//--------------------------------------------------------------------------
// set the parameter
//--------------------------------------------------------------------------
switch (field)
{
case GrB_OUTP :
if (! (value == GxB_DEFAULT || value == GrB_REPLACE))
{
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor value [%d] for GrB_OUTP field;\n"
"must be GxB_DEFAULT [%d] or GrB_REPLACE [%d]",
(int) value, (int) GxB_DEFAULT, (int) GrB_REPLACE) ;
}
desc->out = value ;
break ;
case GrB_MASK :
{
if (! (value == GxB_DEFAULT ||
value == GrB_COMP ||
value == GrB_STRUCTURE ||
value == (GrB_COMP + GrB_STRUCTURE)))
{
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor value [%d] for GrB_MASK field;\n"
"must be GxB_DEFAULT [%d], GrB_COMP [%d],\n"
"GrB_STRUCTURE [%d], or GrB_COMP+GrB_STRUCTURE [%d]",
(int) value, (int) GxB_DEFAULT, (int) GrB_COMP,
(int) GrB_STRUCTURE,
(int) (GrB_COMP + GrB_STRUCTURE)) ;
}
int mask = (int) desc->mask ;
switch (value)
{
case GrB_COMP : mask |= GrB_COMP ; break ;
case GrB_STRUCTURE : mask |= GrB_STRUCTURE ; break ;
default : mask = (int) value ; break ;
}
desc->mask = (GrB_Desc_Value) mask ;
}
break ;
case GrB_INP0 :
if (! (value == GxB_DEFAULT || value == GrB_TRAN))
{
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor value [%d] for GrB_INP0 field;\n"
"must be GxB_DEFAULT [%d] or GrB_TRAN [%d]",
(int) value, (int) GxB_DEFAULT, (int) GrB_TRAN) ;
}
desc->in0 = value ;
break ;
case GrB_INP1 :
if (! (value == GxB_DEFAULT || value == GrB_TRAN))
{
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor value [%d] for GrB_INP1 field;\n"
"must be GxB_DEFAULT [%d] or GrB_TRAN [%d]",
(int) value, (int) GxB_DEFAULT, (int) GrB_TRAN) ;
}
desc->in1 = value ;
break ;
case GxB_AxB_METHOD :
if (! (value == GxB_DEFAULT || value == GxB_AxB_GUSTAVSON
|| value == GxB_AxB_DOT
|| value == GxB_AxB_HASH || value == GxB_AxB_SAXPY))
{
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor value [%d] for GrB_AxB_METHOD field;\n"
"must be GxB_DEFAULT [%d], GxB_AxB_GUSTAVSON [%d]\n"
"GxB_AxB_DOT [%d], GxB_AxB_HASH [%d] or GxB_AxB_SAXPY [%d]",
(int) value, (int) GxB_DEFAULT, (int) GxB_AxB_GUSTAVSON,
(int) GxB_AxB_DOT,
(int) GxB_AxB_HASH, (int) GxB_AxB_SAXPY) ;
}
desc->axb = value ;
break ;
case GxB_IMPORT :
// The user application might not check the error return value of
// this method, so do not return an error if the value is something
// other that GxB_FAST_IMPORT (equal to GxB_DEFAULT) or
// GxB_SERCURE_IMPORT. Instead, default to slower but secure
// import/deserialization, if the GxB_IMPORT setting is made.
// Only use the fast import/deserialize if the value is GxB_DEFAULT
// or GxB_FAST_IMPORT; otherwise use the slower secure method.
desc->import =
(value == GxB_DEFAULT) ? GxB_FAST_IMPORT : GxB_SECURE_IMPORT ;
break ;
default :
GB_ERROR (GrB_INVALID_VALUE,
"invalid descriptor field [%d], must be one of:\n"
"GrB_OUTP [%d], GrB_MASK [%d], GrB_INP0 [%d], GrB_INP1 [%d], "
"GxB_AxB_METHOD [%d] or GxB_IMPORT [%d] (use GxB_Desc_set "
"for other descriptor settings)", (int) field, (int) GrB_OUTP,
(int) GrB_MASK, (int) GrB_INP0, (int) GrB_INP1,
(int) GxB_AxB_METHOD, (int) GxB_IMPORT) ;
}
return (GrB_SUCCESS) ;
}
|