LCOV - code coverage report
Current view: top level - src/utility - LG_internal.h (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: 7b9d2ee. Current time (UTC): 2025-06-03T21:57:17Z Lines: 16 16 100.0 %
Date: 2025-06-03 22:02:40 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LG_internal.h: include file for use within LAGraph itself
       3             : //------------------------------------------------------------------------------
       4             : 
       5             : // LAGraph, (c) 2019-2025 by The LAGraph Contributors, All Rights Reserved.
       6             : // SPDX-License-Identifier: BSD-2-Clause
       7             : //
       8             : // For additional details (including references to third party source code and
       9             : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
      10             : // Contributors.txt for a full list of contributors. Created, in part, with
      11             : // funding and support from the U.S. Government (see Acknowledgments.txt file).
      12             : // DM22-0790
      13             : 
      14             : // Contributed by Timothy A. Davis, Texas A&M University
      15             : 
      16             : //------------------------------------------------------------------------------
      17             : 
      18             : // These definitions are not meant for the user application that relies on
      19             : // LAGraph and/or GraphBLAS.  LG_* methods are for internal use in LAGraph.
      20             : 
      21             : #ifndef LG_INTERNAL_H
      22             : #define LG_INTERNAL_H
      23             : 
      24             : //------------------------------------------------------------------------------
      25             : // include files
      26             : //------------------------------------------------------------------------------
      27             : 
      28             : #include <ctype.h>
      29             : #include "LAGraph.h"
      30             : #undef I
      31             : 
      32             : #if defined ( __linux__ )
      33             : #include <malloc.h>
      34             : #endif
      35             : 
      36             : #define LG_RESTRICT LAGRAPH_RESTRICT
      37             : 
      38             : //------------------------------------------------------------------------------
      39             : // string macros
      40             : //------------------------------------------------------------------------------
      41             : 
      42             : #define LG_XSTR(x) LG_STR(x)
      43             : #define LG_STR(x) #x
      44             : 
      45             : //------------------------------------------------------------------------------
      46             : // string matching
      47             : //------------------------------------------------------------------------------
      48             : 
      49             : #define MATCH(s1,s2,n) (strncmp (s1, s2, n) == 0)
      50             : #define MATCHNAME(s1,s2) MATCH (s1, s2, LAGRAPH_MAX_NAME_LEN)
      51             : 
      52             : //------------------------------------------------------------------------------
      53             : // typedefs
      54             : //------------------------------------------------------------------------------
      55             : 
      56             : // LG_void: used in place of (void *), but valid for pointer arithmetic
      57             : typedef unsigned char LG_void ;
      58             : 
      59             : //------------------------------------------------------------------------------
      60             : // LG_CLEAR_MSG: clear the error msg string
      61             : //------------------------------------------------------------------------------
      62             : 
      63             : // When an LAGraph method starts, it first clears the caller's msg string.
      64             : #define LG_CLEAR_MSG                    \
      65             : {                                       \
      66             :     if (msg != NULL) msg [0] = '\0' ;   \
      67             : }
      68             : 
      69             : //------------------------------------------------------------------------------
      70             : // LG_ERROR_MSG: set the error msg string
      71             : //------------------------------------------------------------------------------
      72             : 
      73             : // When an LAGraph method encounters an error, it can report details in the
      74             : // msg.  This is normally done via LG_ASSERT_MSG.  For example:
      75             : 
      76             : /*
      77             :     if (src < 0 || src >= n)
      78             :     {
      79             :         LG_ERROR_MSG ("Source node %ld must be in range 0 to n-1, "
      80             :             "where n = %ld is the number of nodes in the graph.", src, n) ;
      81             :         return (GrB_INVALID_INDEX) ;
      82             :     }
      83             :     // or, with a simpler message:
      84             :     LG_ASSERT_MSG (src >= 0 && src < n, GrB_INVALID_INDEX, "invalid src node") ;
      85             : */
      86             : 
      87             : #define LG_ERROR_MSG(...)                                           \
      88             : {                                                                   \
      89             :     if (msg != NULL && msg [0] == '\0')                             \
      90             :     {                                                               \
      91             :         snprintf (msg, LAGRAPH_MSG_LEN, __VA_ARGS__) ;              \
      92             :     }                                                               \
      93             : }
      94             : 
      95             : //------------------------------------------------------------------------------
      96             : // LG_FREE_WORK: free all workspace
      97             : //------------------------------------------------------------------------------
      98             : 
      99             : #ifndef LG_FREE_WORK
     100             : #define LG_FREE_WORK ;
     101             : #endif
     102             : 
     103             : //------------------------------------------------------------------------------
     104             : // LG_FREE_ALL: free all workspace and all output arguments, on error
     105             : //------------------------------------------------------------------------------
     106             : 
     107             : #ifndef LG_FREE_ALL
     108             : #define LG_FREE_ALL             \
     109             : {                               \
     110             :     LG_FREE_WORK ;              \
     111             : }
     112             : #endif
     113             : 
     114             : //------------------------------------------------------------------------------
     115             : // GRB_CATCH: catch an error from GraphBLAS
     116             : //------------------------------------------------------------------------------
     117             : 
     118             : // A simple GRB_CATCH macro to be used by GRB_TRY.  If an LAGraph function
     119             : // wants something else, then #define a GRB_CATCH macro before the #include
     120             : // "LG_internal.h" statement.
     121             : 
     122             : #ifndef GRB_CATCH
     123             : #define GRB_CATCH(info)                                                 \
     124             : {                                                                       \
     125             :     LG_ERROR_MSG ("GraphBLAS failure (file %s, line %d): info: %d",     \
     126             :         __FILE__, __LINE__, info) ;                                     \
     127             :     LG_FREE_ALL ;                                                       \
     128             :     return (info) ;                                                     \
     129             : }
     130             : #endif
     131             : 
     132             : //------------------------------------------------------------------------------
     133             : // LAGRAPH_CATCH: catch an error from LAGraph
     134             : //------------------------------------------------------------------------------
     135             : 
     136             : // A simple LAGRAPH_CATCH macro to be used by LAGRAPH_TRY.  If an LAGraph
     137             : // function wants something else, then #define a LAGRAPH_CATCH macro before the
     138             : // #include "LG_internal.h" statement.
     139             : 
     140             : #ifndef LAGRAPH_CATCH
     141             : #define LAGRAPH_CATCH(status)                                           \
     142             : {                                                                       \
     143             :     LG_ERROR_MSG ("LAGraph failure (file %s, line %d): status: %d",     \
     144             :         __FILE__, __LINE__, status) ;                                   \
     145             :     LG_FREE_ALL ;                                                       \
     146             :     return (status) ;                                                   \
     147             : }
     148             : #endif
     149             : 
     150             : //------------------------------------------------------------------------------
     151             : // LG_ASSERT_MSGF: assert an expression is true, and return if it is false
     152             : //------------------------------------------------------------------------------
     153             : 
     154             : // Identical to LG_ASSERT_MSG, except this allows a printf-style formatted
     155             : // message.
     156             : 
     157             : #define LG_ASSERT_MSGF(expression,error_status,expression_format,...)   \
     158             : {                                                                       \
     159             :     if (!(expression))                                                  \
     160             :     {                                                                   \
     161             :         LG_ERROR_MSG ("LAGraph failure (file %s, line %d): "            \
     162             :             expression_format, __FILE__, __LINE__, __VA_ARGS__) ;       \
     163             :         LG_FREE_ALL ;                                                   \
     164             :         return (error_status) ;                                         \
     165             :     }                                                                   \
     166             : }
     167             : 
     168             : //------------------------------------------------------------------------------
     169             : // LG_ASSERT_MSG: assert an expression is true, and return if it is false
     170             : //------------------------------------------------------------------------------
     171             : 
     172             : // Identical to LG_ASSERT, except this allows a different string to be
     173             : // included in the message.
     174             : 
     175             : #define LG_ASSERT_MSG(expression,error_status,expression_message)       \
     176             :     LG_ASSERT_MSGF (expression,error_status,"%s",expression_message)
     177             : 
     178             : //------------------------------------------------------------------------------
     179             : // LG_ASSERT: assert an expression is true, and return if it is false
     180             : //------------------------------------------------------------------------------
     181             : 
     182             : // LAGraph methods can use this assertion macro for simple errors.
     183             : 
     184             : #define LG_ASSERT(expression, error_status)                                 \
     185             : {                                                                           \
     186             :     if (!(expression))                                                      \
     187             :     {                                                                       \
     188             :         LG_ERROR_MSG ("LAGraph assertion \"%s\" failed (file %s, line %d):" \
     189             :             " status: %d", LG_XSTR(expression), __FILE__, __LINE__,         \
     190             :             error_status) ;                                                 \
     191             :         LG_FREE_ALL ;                                                       \
     192             :         return (error_status) ;                                             \
     193             :     }                                                                       \
     194             : }
     195             : 
     196             : //------------------------------------------------------------------------------
     197             : // LG_TRY: check a condition and return on error
     198             : //------------------------------------------------------------------------------
     199             : 
     200             : // The msg is not modified.  This should be used when an LAGraph method calls
     201             : // another one.
     202             : 
     203             : #define LG_TRY(LAGraph_method)                  \
     204             : {                                               \
     205             :     int LAGraph_status = LAGraph_method ;       \
     206             :     if (LAGraph_status < 0)                     \
     207             :     {                                           \
     208             :         LG_FREE_ALL ;                           \
     209             :         return (LAGraph_status) ;               \
     210             :     }                                           \
     211             : }
     212             : 
     213             : //------------------------------------------------------------------------------
     214             : // LG_CLEAR_MSG_AND_BASIC_ASSERT: clear msg and do basic tests of a graph
     215             : //------------------------------------------------------------------------------
     216             : 
     217             : #define LG_CLEAR_MSG_AND_BASIC_ASSERT(G,msg)                                \
     218             : {                                                                           \
     219             :     LG_CLEAR_MSG ;                                                          \
     220             :     LG_ASSERT (G != NULL, GrB_NULL_POINTER) ;                               \
     221             :     LG_ASSERT_MSG (G->A != NULL, LAGRAPH_INVALID_GRAPH,                     \
     222             :         "graph adjacency matrix is NULL") ;                                 \
     223             :     LG_ASSERT_MSG (G->kind >= LAGraph_ADJACENCY_UNDIRECTED &&               \
     224             :         G->kind <= LAGraph_ADJACENCY_DIRECTED,                              \
     225             :         LAGRAPH_INVALID_GRAPH, "graph kind invalid") ;                      \
     226             : }
     227             : 
     228             : //------------------------------------------------------------------------------
     229             : // FPRINTF: fprintf and check result
     230             : //------------------------------------------------------------------------------
     231             : 
     232             : #define FPRINTF(f,...)                                                      \
     233             : {                                                                           \
     234             :     LG_ASSERT_MSG (fprintf (f, __VA_ARGS__) >= 0,                           \
     235             :         LAGRAPH_IO_ERROR, "Unable to write to file") ;                      \
     236             : }
     237             : 
     238             : //------------------------------------------------------------------------------
     239             : // code development settings
     240             : //------------------------------------------------------------------------------
     241             : 
     242             : // turn off debugging; do not edit these three lines
     243             : #ifndef NDEBUG
     244             : #define NDEBUG
     245             : #endif
     246             : 
     247             : // These flags are used for code development.  Uncomment them as needed.
     248             : 
     249             : // to turn on debugging, uncomment this line:
     250             : // #undef NDEBUG
     251             : 
     252             : #undef ASSERT
     253             : 
     254             : #ifndef NDEBUG
     255             : 
     256             :     // debugging enabled
     257             :     #ifdef MATLAB_MEX_FILE
     258             :         // debugging when LAGraph is part of a mexFunction
     259             :         #define ASSERT(x)                                               \
     260             :         {                                                               \
     261             :             if (!(x)) mexErrMsgTxt ("failure: " __FILE__ " line: ") ;   \
     262             :         }
     263             :     #else
     264             :         #include <assert.h>
     265             :         #define ASSERT(x) assert (x) ;
     266             :     #endif
     267             : 
     268             : #else
     269             : 
     270             :     // debugging disabled
     271             :     #define ASSERT(x)
     272             : 
     273             : #endif
     274             : 
     275             : // GraphBLAS version 10 flag
     276             : #if LAGRAPH_SUITESPARSE 
     277             :     #if GxB_IMPLEMENTATION >= GxB_VERSION (10,0,0)
     278             :         #define LG_SUITESPARSE_GRAPHBLAS_V10 1
     279             :     #else
     280             :         #define LG_SUITESPARSE_GRAPHBLAS_V10 0
     281             :     #endif
     282             : #else
     283             :     #define LG_SUITESPARSE_GRAPHBLAS_V10 0
     284             : #endif
     285             : 
     286             : //------------------------------------------------------------------------------
     287             : // LG_Multiply_size_t:  c = a*b but check for overflow
     288             : //------------------------------------------------------------------------------
     289             : 
     290       36196 : static bool LG_Multiply_size_t  // true if ok, false if overflow
     291             : (
     292             :     size_t *c,                  // c = a*b, or zero if overflow occurs
     293             :     const size_t a,
     294             :     const size_t b
     295             : )
     296             : {
     297             : 
     298             :     ASSERT (c != NULL) ;
     299             : 
     300       36196 :     (*c) = 0 ;
     301       36196 :     if (a == 0 || b == 0)
     302             :     {
     303           1 :         return (true) ;
     304             :     }
     305             : 
     306       36195 :     if (a > SIZE_MAX / 2 || b > SIZE_MAX / 2)
     307             :     {
     308             :         // a or b are out of range
     309           4 :         return (false) ;
     310             :     }
     311             : 
     312             :     // a + b is now safe to compute
     313       36191 :     if ((a + b) > (SIZE_MAX / LAGRAPH_MIN (a,b)))
     314             :     {
     315             :         // a * b may overflow
     316           1 :         return (false) ;
     317             :     }
     318             : 
     319             :     // a * b will not overflow
     320       36190 :     (*c) = a * b ;
     321       36190 :     return (true) ;
     322             : }
     323             : 
     324             : //------------------------------------------------------------------------------
     325             : // Matrix Market format
     326             : //------------------------------------------------------------------------------
     327             : 
     328             : // %%MatrixMarket matrix <fmt> <type> <storage> uses the following enums:
     329             : 
     330             : typedef enum
     331             : {
     332             :     MM_coordinate,
     333             :     MM_array,
     334             : }
     335             : MM_fmt_enum ;
     336             : 
     337             : typedef enum
     338             : {
     339             :     MM_real,
     340             :     MM_integer,
     341             :     MM_complex,
     342             :     MM_pattern
     343             : }
     344             : MM_type_enum ;
     345             : 
     346             : typedef enum
     347             : {
     348             :     MM_general,
     349             :     MM_symmetric,
     350             :     MM_skew_symmetric,
     351             :     MM_hermitian
     352             : }
     353             : MM_storage_enum ;
     354             : 
     355             : // maximum length of each line in the Matrix Market file format
     356             : 
     357             : // The MatrixMarket format specificies a maximum line length of 1024.
     358             : // This is currently sufficient for GraphBLAS but will need to be relaxed
     359             : // if this function is extended to handle arbitrary user-defined types.
     360             : #define MMLEN 1024
     361             : #define MAXLINE MMLEN+6
     362             : 
     363             : //------------------------------------------------------------------------------
     364             : // LG_PART and LG_PARTITION: definitions for partitioning an index range
     365             : //------------------------------------------------------------------------------
     366             : 
     367             : LAGRAPH_PUBLIC extern
     368             : int LG_nthreads_outer ; // # of threads to use at the higher level of a nested
     369             :                         // parallel region in LAGraph.  Default: 1.
     370             : 
     371             : LAGRAPH_PUBLIC extern
     372             : int LG_nthreads_inner ; // # of threads to use at the lower level of a nested
     373             :                         // parallel region, or to use inside GraphBLAS.
     374             :                         // Default: the value obtained by omp_get_max_threads
     375             :                         // if OpenMP is in use, or 1 otherwise.
     376             : 
     377             : // LG_PART and LG_PARTITION:  divide the index range 0:n-1 uniformly
     378             : // for nthreads.  LG_PART(tid,n,nthreads) is the first index for thread tid.
     379             : #define LG_PART(tid,n,nthreads)  \
     380             :     (((tid) * ((double) (n))) / ((double) (nthreads)))
     381             : 
     382             : // thread tid will operate on the range k1:(k2-1)
     383             : #define LG_PARTITION(k1,k2,n,tid,nthreads)                                  \
     384             :     k1 = ((tid) ==  0          ) ?  0  : LG_PART ((tid),  n, nthreads) ;    \
     385             :     k2 = ((tid) == (nthreads)-1) ? (n) : LG_PART ((tid)+1,n, nthreads)
     386             : 
     387             : //------------------------------------------------------------------------------
     388             : // LG_eslice: uniform partition of e items to each task
     389             : //------------------------------------------------------------------------------
     390             : 
     391          19 : static inline void LG_eslice
     392             : (
     393             :     int64_t *Slice,         // array of size ntasks+1
     394             :     int64_t e,              // number items to partition amongst the tasks
     395             :     const int ntasks        // # of tasks
     396             : )
     397             : {
     398          19 :     Slice [0] = 0 ;
     399         218 :     for (int tid = 0 ; tid < ntasks ; tid++)
     400             :     {
     401         199 :         Slice [tid] = LG_PART (tid, e, ntasks) ;
     402             :     }
     403          19 :     Slice [ntasks] = e ;
     404          19 : }
     405             : 
     406             : //------------------------------------------------------------------------------
     407             : // definitions for sorting functions
     408             : //------------------------------------------------------------------------------
     409             : 
     410             : // All of the LG_qsort_* functions are single-threaded, by design.  The
     411             : // LG_msort* functions are parallel.  None of these sorting methods are
     412             : // guaranteed to be stable.  These functions are contributed by Tim Davis, and
     413             : // are derived from SuiteSparse:GraphBLAS.  Functions named LG_* are not
     414             : // meant to be accessible by end users of LAGraph.
     415             : 
     416             : #define LG_BASECASE (64 * 1024)
     417             : 
     418             : //------------------------------------------------------------------------------
     419             : // LG_msort1: sort array of size n
     420             : //------------------------------------------------------------------------------
     421             : 
     422             : // LG_msort1 sorts an int64_t array of size n in ascending order.
     423             : 
     424             : int LG_msort1
     425             : (
     426             :     // input/output:
     427             :     int64_t *A_0,       // size n array
     428             :     // input:
     429             :     const int64_t n,
     430             :     char *msg
     431             : ) ;
     432             : 
     433             : //------------------------------------------------------------------------------
     434             : // LG_msort2: sort two arrays of size n
     435             : //------------------------------------------------------------------------------
     436             : 
     437             : // LG_msort2 sorts two int64_t arrays A of size n in ascending order.
     438             : // The arrays are kept in the same order, where the pair (A_0 [k], A_1 [k]) is
     439             : // treated as a single pair.  The pairs are sorted by the first value A_0,
     440             : // with ties broken by A_1.
     441             : 
     442             : int LG_msort2
     443             : (
     444             :     // input/output:
     445             :     int64_t *A_0,       // size n array
     446             :     int64_t *A_1,       // size n array
     447             :     // input:
     448             :     const int64_t n,
     449             :     char *msg
     450             : ) ;
     451             : 
     452             : //------------------------------------------------------------------------------
     453             : // LG_msort3: sort three arrays of size n
     454             : //------------------------------------------------------------------------------
     455             : 
     456             : // LG_msort3 sorts three int64_t arrays A of size n in ascending order.
     457             : // The arrays are kept in the same order, where the triplet (A_0 [k], A_1 [k],
     458             : // A_2 [k]) is treated as a single triplet.  The triplets are sorted by the
     459             : // first value A_0, with ties broken by A_1, and then by A_2 if the values of
     460             : // A_0 and A_1 are identical.
     461             : 
     462             : int LG_msort3
     463             : (
     464             :     // input/output:
     465             :     int64_t *A_0,       // size n array
     466             :     int64_t *A_1,       // size n array
     467             :     int64_t *A_2,       // size n array
     468             :     // input:
     469             :     const int64_t n,
     470             :     char *msg
     471             : ) ;
     472             : 
     473             : void LG_qsort_1a    // sort array A of size 1-by-n
     474             : (
     475             :     int64_t *LG_RESTRICT A_0,       // size n array
     476             :     const int64_t n
     477             : ) ;
     478             : 
     479             : void LG_qsort_2     // sort array A of size 2-by-n, using 2 keys (A [0:1][])
     480             : (
     481             :     int64_t *LG_RESTRICT A_0,       // size n array
     482             :     int64_t *LG_RESTRICT A_1,       // size n array
     483             :     const int64_t n
     484             : ) ;
     485             : 
     486             : void LG_qsort_3     // sort array A of size 3-by-n, using 3 keys (A [0:2][])
     487             : (
     488             :     int64_t *LG_RESTRICT A_0,       // size n array
     489             :     int64_t *LG_RESTRICT A_1,       // size n array
     490             :     int64_t *LG_RESTRICT A_2,       // size n array
     491             :     const int64_t n
     492             : ) ;
     493             : 
     494             : //------------------------------------------------------------------------------
     495             : // LG_lt_1: sorting comparator function, one key
     496             : //------------------------------------------------------------------------------
     497             : 
     498             : // A [a] and B [b] are keys of one integer.
     499             : 
     500             : // LG_lt_1 returns true if A [a] < B [b], for LG_qsort_1b
     501             : 
     502             : #define LG_lt_1(A_0, a, B_0, b) (A_0 [a] < B_0 [b])
     503             : 
     504             : //------------------------------------------------------------------------------
     505             : // LG_lt_2: sorting comparator function, two keys
     506             : //------------------------------------------------------------------------------
     507             : 
     508             : // A [a] and B [b] are keys of two integers.
     509             : 
     510             : // LG_lt_2 returns true if A [a] < B [b], for LG_qsort_2 and LG_msort_2b
     511             : 
     512             : #define LG_lt_2(A_0, A_1, a, B_0, B_1, b)                                   \
     513             : (                                                                           \
     514             :     (A_0 [a] < B_0 [b]) ?                                                   \
     515             :     (                                                                       \
     516             :         true                                                                \
     517             :     )                                                                       \
     518             :     :                                                                       \
     519             :     (                                                                       \
     520             :         (A_0 [a] == B_0 [b]) ?                                              \
     521             :         (                                                                   \
     522             :             /* primary key is the same; tie-break on the 2nd key */         \
     523             :             (A_1 [a] < B_1 [b])                                             \
     524             :         )                                                                   \
     525             :         :                                                                   \
     526             :         (                                                                   \
     527             :             false                                                           \
     528             :         )                                                                   \
     529             :     )                                                                       \
     530             : )
     531             : 
     532             : //------------------------------------------------------------------------------
     533             : // LG_lt_3: sorting comparator function, three keys
     534             : //------------------------------------------------------------------------------
     535             : 
     536             : // A [a] and B [b] are keys of three integers.
     537             : 
     538             : // LG_lt_3 returns true if A [a] < B [b], for LG_qsort_3 and LG_msort_3b
     539             : 
     540             : #define LG_lt_3(A_0, A_1, A_2, a, B_0, B_1, B_2, b)                         \
     541             : (                                                                           \
     542             :     (A_0 [a] < B_0 [b]) ?                                                   \
     543             :     (                                                                       \
     544             :         true                                                                \
     545             :     )                                                                       \
     546             :     :                                                                       \
     547             :     (                                                                       \
     548             :         (A_0 [a] == B_0 [b]) ?                                              \
     549             :         (                                                                   \
     550             :             /* primary key is the same; tie-break on the 2nd and 3rd key */ \
     551             :             LG_lt_2 (A_1, A_2, a, B_1, B_2, b)                              \
     552             :         )                                                                   \
     553             :         :                                                                   \
     554             :         (                                                                   \
     555             :             false                                                           \
     556             :         )                                                                   \
     557             :     )                                                                       \
     558             : )
     559             : 
     560             : //------------------------------------------------------------------------------
     561             : // LG_eq_*: sorting comparator function, three keys
     562             : //------------------------------------------------------------------------------
     563             : 
     564             : // A [a] and B [b] are keys of two or three integers.
     565             : // LG_eq_* returns true if A [a] == B [b]
     566             : 
     567             : #define LG_eq_3(A_0, A_1, A_2, a, B_0, B_1, B_2, b)                         \
     568             : (                                                                           \
     569             :     (A_0 [a] == B_0 [b]) &&                                                 \
     570             :     (A_1 [a] == B_1 [b]) &&                                                 \
     571             :     (A_2 [a] == B_2 [b])                                                    \
     572             : )
     573             : 
     574             : #define LG_eq_2(A_0, A_1, a, B_0, B_1, b)                                   \
     575             : (                                                                           \
     576             :     (A_0 [a] == B_0 [b]) &&                                                 \
     577             :     (A_1 [a] == B_1 [b])                                                    \
     578             : )
     579             : 
     580             : #define LG_eq_1(A_0, a, B_0, b)                                             \
     581             : (                                                                           \
     582             :     (A_0 [a] == B_0 [b])                                                    \
     583             : )
     584             : 
     585             : //------------------------------------------------------------------------------
     586             : // count entries on the diagonal of a matrix
     587             : //------------------------------------------------------------------------------
     588             : 
     589             : int LG_nself_edges
     590             : (
     591             :     // output
     592             :     int64_t *nself_edges,   // # of entries
     593             :     // input
     594             :     GrB_Matrix A,           // matrix to count
     595             :     char *msg               // error message
     596             : ) ;
     597             : 
     598             : //------------------------------------------------------------------------------
     599             : // simple and portable random number generator
     600             : //------------------------------------------------------------------------------
     601             : 
     602             : // return a random uint64_t
     603             : uint64_t LG_Random64 (uint64_t *seed) ;
     604             : 
     605             : // create operators for LAGraph_Random_* methods
     606             : int LG_Random_Init (char *msg) ;
     607             : int LG_Random_Finalize (char *msg) ;
     608             : 
     609             : //------------------------------------------------------------------------------
     610             : // LG_KindName: return the name of a kind
     611             : //------------------------------------------------------------------------------
     612             : 
     613             : // LG_KindName: return the name of a graph kind.  For example, if given
     614             : // LAGraph_ADJACENCY_UNDIRECTED, the string "undirected" is returned.
     615             : 
     616             : int LG_KindName
     617             : (
     618             :     // output:
     619             :     char *name,     // name of the kind (user provided array of size at least
     620             :                     // LAGRAPH_MAX_NAME_LEN)
     621             :     // input:
     622             :     LAGraph_Kind kind,  // graph kind
     623             :     char *msg
     624             : ) ;
     625             : 
     626             : //------------------------------------------------------------------------------
     627             : 
     628             : // # of entries to print for LAGraph_Matrix_Print and LAGraph_Vector_Print
     629             : #define LG_SHORT_LEN 30
     630             : 
     631             : //------------------------------------------------------------------------------
     632             : // GrB_get/set for SuiteSparse extensions
     633             : //------------------------------------------------------------------------------
     634             : 
     635             : #if LAGRAPH_SUITESPARSE
     636             : 
     637             :     // SuiteSparse:GraphBLAS v8.1 or later
     638             :     #define LG_HYPERSPARSE GxB_HYPERSPARSE
     639             :     #define LG_SPARSE      GxB_SPARSE
     640             :     #define LG_BITMAP      GxB_BITMAP
     641             :     #define LG_FULL        GxB_FULL
     642             :     #define LG_SET_FORMAT_HINT(object,sparsity) \
     643             :         GrB_set (object, (int32_t) (sparsity), GxB_SPARSITY_CONTROL)
     644             :     #define LG_GET_FORMAT_HINT(object,status) \
     645             :         GrB_get (object, (int32_t *) status, GxB_SPARSITY_STATUS)
     646             :     #define LG_SET_NTHREADS(nthreads) \
     647             :         GrB_set (GrB_GLOBAL, (int32_t) (nthreads), GxB_NTHREADS)
     648             :     #define LG_SET_HYPER_SWITCH(object,hyper) \
     649             :         GrB_set (object, hyper, GxB_HYPER_SWITCH)
     650             :     #define LG_GET_HYPER_SWITCH(object,hyper) \
     651             :         GrB_get (object, hyper, GxB_HYPER_SWITCH)
     652             :     #define LG_SET_BURBLE(burble) \
     653             :         GrB_set (GrB_GLOBAL, (int32_t) (burble), GxB_BURBLE)
     654             :     #define LG_GET_LIBRARY_DATE(date) \
     655             :         GrB_get (GrB_GLOBAL, (char *) date, GxB_LIBRARY_DATE)
     656             : 
     657             :     #define LG_JIT_OFF   GxB_JIT_OFF
     658             :     #define LG_JIT_PAUSE GxB_JIT_PAUSE
     659             :     #define LG_JIT_RUN   GxB_JIT_RUN
     660             :     #define LG_JIT_LOAD  GxB_JIT_LOAD
     661             :     #define LG_JIT_ON    GxB_JIT_ON
     662             :     #define LG_SET_JIT(jit) \
     663             :         GrB_set (GrB_GLOBAL, (int32_t) (jit), GxB_JIT_C_CONTROL)
     664             : 
     665             :     #if defined ( GRAPHBLAS_HAS_CUDA )
     666             :     // the LG_brutal_malloc family of methods.
     667             :     #define LG_BRUTAL_TESTS 0
     668             :     #else
     669             :     #define LG_BRUTAL_TESTS 1
     670             :     #endif
     671             : 
     672             : #else
     673             : 
     674             :     // vanilla GraphBLAS
     675             :     #define LG_HYPERSPARSE 1
     676             :     #define LG_SPARSE      2
     677             :     #define LG_BITMAP      4
     678             :     #define LG_FULL        8
     679             :     #define LG_SET_FORMAT_HINT(object,sparsity) GrB_SUCCESS
     680             :     #define LG_SET_NTHREADS(nthreads) GrB_SUCCESS
     681             :     #define LG_SET_HYPER_SWITCH(object,hyper) GrB_SUCCESS
     682             :     #define LG_GET_HYPER_SWITCH(object,hyper) GrB_SUCCESS
     683             :     #define LG_GET_FORMAT_HINT(object,status) GrB_SUCCESS
     684             :     #define LG_SET_BURBLE(burble) GrB_SUCCESS
     685             :     #define LG_GET_LIBRARY_DATE(date) GrB_SUCCESS
     686             : 
     687             :     #define LG_JIT_OFF   0
     688             :     #define LG_JIT_PAUSE 1
     689             :     #define LG_JIT_RUN   2
     690             :     #define LG_JIT_LOAD  3
     691             :     #define LG_JIT_ON    4
     692             :     #define LG_SET_JIT(jit) GrB_SUCCESS
     693             : 
     694             :     #define LG_BRUTAL_TESTS 0
     695             : 
     696             : #endif
     697             : 
     698             : #endif

Generated by: LCOV version 1.14