Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LAGraph_Cached_AT: construct G->AT for a graph 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 : #define LG_FREE_ALL GrB_free (&AT) ; 19 : 20 : #include "LG_internal.h" 21 : 22 1279 : int LAGraph_Cached_AT 23 : ( 24 : // input/output: 25 : LAGraph_Graph G, // graph for which to compute G->AT 26 : char *msg 27 : ) 28 : { 29 : 30 : //-------------------------------------------------------------------------- 31 : // clear msg and check G 32 : //-------------------------------------------------------------------------- 33 : 34 1279 : GrB_Matrix AT = NULL ; 35 1279 : LG_CLEAR_MSG_AND_BASIC_ASSERT (G, msg) ; 36 1279 : GrB_Matrix A = G->A ; 37 : 38 1279 : if (G->AT != NULL) 39 : { 40 : // G->AT already computed 41 42 : return (GrB_SUCCESS) ; 42 : } 43 : 44 1237 : if (G->kind == LAGraph_ADJACENCY_UNDIRECTED) 45 : { 46 : // G->AT not needed since A is symmetric (warning only, not an error) 47 72 : return (LAGRAPH_CACHE_NOT_NEEDED) ; 48 : } 49 : 50 : //-------------------------------------------------------------------------- 51 : // G->AT = (G->A)' 52 : //-------------------------------------------------------------------------- 53 : 54 : GrB_Index nrows, ncols ; 55 1165 : GRB_TRY (GrB_Matrix_nrows (&nrows, A)) ; 56 1165 : GRB_TRY (GrB_Matrix_ncols (&ncols, A)) ; 57 : GrB_Type atype ; 58 : char atype_name [LAGRAPH_MAX_NAME_LEN] ; 59 1165 : LG_TRY (LAGraph_Matrix_TypeName (atype_name, A, msg)) ; 60 1165 : LG_TRY (LAGraph_TypeFromName (&atype, atype_name, msg)) ; 61 1165 : GRB_TRY (GrB_Matrix_new (&AT, atype, ncols, nrows)) ; 62 848 : GRB_TRY (GrB_transpose (AT, NULL, NULL, A, NULL)) ; 63 605 : G->AT = AT ; 64 : 65 605 : return (GrB_SUCCESS) ; 66 : }