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

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LG_check_export: export G->A for testing
       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             : // Export G->A in CSR format, for testing only.
      19             : // See test_export for a brutal memory test of this method.
      20             : 
      21             : #define LG_FREE_ALL                             \
      22             : {                                               \
      23             :     LAGraph_Free ((void **) Ap_handle, NULL) ;  \
      24             :     LAGraph_Free ((void **) Aj_handle, NULL) ;  \
      25             :     LAGraph_Free ((void **) Ax_handle, NULL) ;  \
      26             : }
      27             : 
      28             : #include "LG_internal.h"
      29             : #include "LG_test.h"
      30             : 
      31         443 : int LG_check_export
      32             : (
      33             :     // input
      34             :     LAGraph_Graph G,        // export G->A in CSR format
      35             :     // output
      36             :     GrB_Index **Ap_handle,  // size Ap_len on output
      37             :     GrB_Index **Aj_handle,  // size Aj_len on output
      38             :     void **Ax_handle,       // size Ax_len * typesize on output
      39             :     GrB_Index *Ap_len,
      40             :     GrB_Index *Aj_len,
      41             :     GrB_Index *Ax_len,
      42             :     size_t *typesize,       // size of the type of A
      43             :     char *msg
      44             : )
      45             : {
      46         443 :     LG_CLEAR_MSG ;
      47             : 
      48         443 :     GrB_Index *Ap = NULL, *Aj = NULL ;
      49         443 :     void *Ax = NULL ;
      50         443 :     LG_TRY (LAGraph_CheckGraph (G, msg)) ;
      51             : 
      52         443 :     LG_ASSERT_MSG (Ap_handle != NULL, GrB_NULL_POINTER, "&Ap is NULL") ;
      53         443 :     LG_ASSERT_MSG (Aj_handle != NULL, GrB_NULL_POINTER, "&Aj is NULL") ;
      54         443 :     LG_ASSERT_MSG (Ax_handle != NULL, GrB_NULL_POINTER, "&Ax is NULL") ;
      55         443 :     LG_ASSERT_MSG (Ap_len != NULL, GrB_NULL_POINTER, "&Ap_len is NULL") ;
      56         443 :     LG_ASSERT_MSG (Aj_len != NULL, GrB_NULL_POINTER, "&Aj_len is NULL") ;
      57         443 :     LG_ASSERT_MSG (Ax_len != NULL, GrB_NULL_POINTER, "&Ax_len is NULL") ;
      58         443 :     LG_ASSERT_MSG (typesize != NULL, GrB_NULL_POINTER, "&typesize is NULL") ;
      59             : 
      60             :     // get the type of G->A
      61         443 :     GrB_Type atype = NULL ;
      62             :     char atype_name [LAGRAPH_MAX_NAME_LEN] ;
      63         443 :     LG_TRY (LAGraph_Matrix_TypeName (atype_name, G->A, msg)) ;
      64         443 :     LG_TRY (LAGraph_TypeFromName (&atype, atype_name, msg)) ;
      65             : 
      66         443 :     size_t s = 0 ;
      67         443 :     if      (atype == GrB_BOOL  ) s = sizeof (bool    ) ;
      68         293 :     else if (atype == GrB_INT8  ) s = sizeof (int8_t  ) ;
      69         283 :     else if (atype == GrB_INT16 ) s = sizeof (int16_t ) ;
      70         273 :     else if (atype == GrB_INT32 ) s = sizeof (int32_t ) ;
      71         243 :     else if (atype == GrB_INT64 ) s = sizeof (int64_t ) ;
      72         146 :     else if (atype == GrB_UINT8 ) s = sizeof (uint8_t ) ;
      73         136 :     else if (atype == GrB_UINT16) s = sizeof (uint16_t) ;
      74         126 :     else if (atype == GrB_UINT32) s = sizeof (uint32_t) ;
      75         125 :     else if (atype == GrB_UINT64) s = sizeof (uint64_t) ;
      76         115 :     else if (atype == GrB_FP32  ) s = sizeof (float   ) ;
      77         105 :     else if (atype == GrB_FP64  ) s = sizeof (double  ) ;
      78         443 :     LG_ASSERT_MSG (s != 0, GrB_NOT_IMPLEMENTED, "unsupported type") ;
      79         443 :     (*typesize) = s ;
      80             : 
      81         443 :     GRB_TRY (GrB_Matrix_exportSize (Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT,
      82             :         G->A)) ;
      83         443 :     LG_TRY (LAGraph_Malloc ((void **) Ap_handle, *Ap_len, sizeof (GrB_Index), msg)) ;
      84         394 :     LG_TRY (LAGraph_Malloc ((void **) Aj_handle, *Aj_len, sizeof (GrB_Index), msg)) ;
      85         345 :     LG_TRY (LAGraph_Malloc ((void **) Ax_handle, *Ax_len, s, msg)) ;
      86         296 :     Ap = (*Ap_handle) ;
      87         296 :     Aj = (*Aj_handle) ;
      88         296 :     Ax = (*Ax_handle) ;
      89             : 
      90         296 :     if      (atype == GrB_BOOL  )
      91             :     {
      92          99 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (bool     *) Ax,
      93             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
      94             :     }
      95         197 :     else if (atype == GrB_INT8  )
      96             :     {
      97           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (int8_t   *) Ax,
      98             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
      99             :     }
     100         190 :     else if (atype == GrB_INT16 )
     101             :     {
     102           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (int16_t  *) Ax,
     103             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     104             :     }
     105         183 :     else if (atype == GrB_INT32 )
     106             :     {
     107          21 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (int32_t  *) Ax,
     108             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     109             :     }
     110         162 :     else if (atype == GrB_INT64 )
     111             :     {
     112          67 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (int64_t  *) Ax,
     113             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     114             :     }
     115          95 :     else if (atype == GrB_UINT8 )
     116             :     {
     117           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (uint8_t  *) Ax,
     118             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     119             :     }
     120          88 :     else if (atype == GrB_UINT16)
     121             :     {
     122           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (uint16_t *) Ax,
     123             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     124             :     }
     125          81 :     else if (atype == GrB_UINT32)
     126             :     {
     127           1 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (uint32_t *) Ax,
     128             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     129             :     }
     130          80 :     else if (atype == GrB_UINT64)
     131             :     {
     132           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (uint64_t *) Ax,
     133             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     134             :     }
     135          73 :     else if (atype == GrB_FP32  )
     136             :     {
     137           7 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (float    *) Ax,
     138             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     139             :     }
     140          66 :     else if (atype == GrB_FP64  )
     141             :     {
     142          66 :         GRB_TRY (GrB_Matrix_export (Ap, Aj, (double   *) Ax,
     143             :             Ap_len, Aj_len, Ax_len, GrB_CSR_FORMAT, G->A)) ;
     144             :     }
     145             : 
     146         132 :     return (GrB_SUCCESS) ;
     147             : }

Generated by: LCOV version 1.14