LCOV - code coverage report
Current view: top level - src/utility - LAGraph_TypeFromName.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: cc56ed4. Current time (UTC): 2024-08-30T17:14:30Z Lines: 5 5 100.0 %
Date: 2024-08-30 17:16:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph_TypeFromName: return the GrB_Type corresponding to its given name
       3             : //------------------------------------------------------------------------------
       4             : 
       5             : // LAGraph, (c) 2019-2022 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             : // This method works for any GraphBLAS library.  On input, name is a char array
      19             : // of length at least LAGRAPH_MAX_NAME_LEN.
      20             : 
      21             : // Only built-in types are supported.  User-defined types are not supported.
      22             : 
      23             : #include "LG_internal.h"
      24             : 
      25       13620 : int LAGraph_TypeFromName
      26             : (
      27             :     // output:
      28             :     GrB_Type *type, // GraphBLAS type
      29             :     // input:
      30             :     char *name,     // name of the type: a null-terminated string
      31             :     char *msg
      32             : )
      33             : {
      34             : 
      35             :     //--------------------------------------------------------------------------
      36             :     // check inputs
      37             :     //--------------------------------------------------------------------------
      38             : 
      39       13620 :     LG_CLEAR_MSG ;
      40       13620 :     LG_ASSERT (type != NULL, GrB_NULL_POINTER) ;
      41       13620 :     LG_ASSERT (name != NULL, GrB_NULL_POINTER) ;
      42             : 
      43             :     //--------------------------------------------------------------------------
      44             :     // determine the GrB_Type from its name
      45             :     //--------------------------------------------------------------------------
      46             : 
      47             :     #if LAGRAPH_SUITESPARSE
      48             : 
      49       13620 :         return (GxB_Type_from_name (type, name)) ;
      50             : 
      51             :     #else
      52             : 
      53             :         if      (MATCHNAME (name, "bool"          )) (*type) = GrB_BOOL   ;
      54             :         else if (MATCHNAME (name, "int8_t"        )) (*type) = GrB_INT8   ;
      55             :         else if (MATCHNAME (name, "int16_t"       )) (*type) = GrB_INT16  ;
      56             :         else if (MATCHNAME (name, "int32_t"       )) (*type) = GrB_INT32  ;
      57             :         else if (MATCHNAME (name, "int64_t"       )) (*type) = GrB_INT64  ;
      58             :         else if (MATCHNAME (name, "uint8_t"       )) (*type) = GrB_UINT8  ;
      59             :         else if (MATCHNAME (name, "uint16_t"      )) (*type) = GrB_UINT16 ;
      60             :         else if (MATCHNAME (name, "uint32_t"      )) (*type) = GrB_UINT32 ;
      61             :         else if (MATCHNAME (name, "uint64_t"      )) (*type) = GrB_UINT64 ;
      62             :         else if (MATCHNAME (name, "float"         )) (*type) = GrB_FP32   ;
      63             :         else if (MATCHNAME (name, "double"        )) (*type) = GrB_FP64   ;
      64             :         #if 0
      65             :         // if complex types from SuiteSparse:GraphBLAS are added to LAGraph:
      66             :         else if (MATCHNAME (name, "float complex" )) (*type) = GxB_FC32   ;
      67             :         else if (MATCHNAME (name, "double complex")) (*type) = GxB_FC64   ;
      68             :         #endif
      69             :         else
      70             :         {
      71             :             (*type) = NULL ;
      72             :             LG_ASSERT_MSGF (false, GrB_NOT_IMPLEMENTED,
      73             :                 "type \"%s\" not supported", name) ;
      74             :         }
      75             :         return (GrB_SUCCESS) ;
      76             : 
      77             :     #endif
      78             : }

Generated by: LCOV version 1.14