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
|
//------------------------------------------------------------------------------
// gb_get_format: determine the format of a matrix result
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// gb_get_format determines the format of a result matrix C, which may be
// computed from one or two input matrices A and B. The following rules are
// used, in order:
// (1) GraphBLAS operations of the form C = GrB.method (Cin, ...) use the
// format of Cin for the new matrix C.
// (1) If the format is determined by the descriptor to the method, then that
// determines the format of C.
// (2) If C is a column vector (cncols == 1) then C is stored by column.
// (3) If C is a row vector (cnrows == 1) then C is stored by row.
// (4) If A is present, and not a row or column vector or scalar, then its
// format is used for C.
// (5) If B is present, and not a row or column vector or scalar, then its
// format is used for C.
// (6) Otherwise, the global default format is used for C.
#include "gb_interface.h"
GxB_Format_Value gb_get_format // GxB_BY_ROW or GxB_BY_COL
(
GrB_Index cnrows, // C is cnrows-by-cncols
GrB_Index cncols,
GrB_Matrix A, // may be NULL
GrB_Matrix B, // may be NULL
GxB_Format_Value fmt_descriptor // may be GxB_NO_FORMAT
)
{
GxB_Format_Value fmt ;
if (fmt_descriptor != GxB_NO_FORMAT)
{
// (1) the format is defined by the descriptor to the method
fmt = fmt_descriptor ;
}
else if (cncols == 1)
{
// (2) column vectors are stored by column, by default
fmt = GxB_BY_COL ;
}
else if (cnrows == 1)
{
// (3) row vectors are stored by row, by default
fmt = GxB_BY_ROW ;
}
else if (A != NULL && !gb_is_vector (A))
{
// (4) get the format of A
OK (GxB_Matrix_Option_get (A, GxB_FORMAT, &fmt)) ;
}
else if (B != NULL && !gb_is_vector (B))
{
// (5) get the format of B
OK (GxB_Matrix_Option_get (B, GxB_FORMAT, &fmt)) ;
}
else
{
// (6) get the global default format
OK (GxB_Global_Option_get (GxB_FORMAT, &fmt)) ;
}
return (fmt) ;
}
|