Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LAGraph_Matrix_Structure: return the structure of a matrix 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 and Scott Kolodziej, Texas A&M University 15 : 16 : //------------------------------------------------------------------------------ 17 : 18 : // LAGraph_Matrix_Structure: return the structure of a matrix as a boolean 19 : // matrix, where C(i,j)=true if the entry A(i,j) is present in the matrix A. 20 : 21 : #define LG_FREE_ALL GrB_free (C) ; 22 : 23 : #include "LG_internal.h" 24 : 25 563 : int LAGraph_Matrix_Structure 26 : ( 27 : // output: 28 : GrB_Matrix *C, // a boolean matrix with same structure of A, with C(i,j) 29 : // set to true if A(i,j) appears in the sparsity structure 30 : // of A. 31 : // input: 32 : GrB_Matrix A, 33 : char *msg 34 : ) 35 : { 36 : 37 : //-------------------------------------------------------------------------- 38 : // check inputs 39 : //-------------------------------------------------------------------------- 40 : 41 563 : LG_CLEAR_MSG ; 42 : GrB_Index nrows, ncols ; 43 563 : LG_ASSERT_MSG (C != NULL, GrB_NULL_POINTER, "&C != NULL") ; 44 562 : LG_ASSERT (A != NULL, GrB_NULL_POINTER) ; 45 561 : (*C) = NULL ; 46 : 47 : //-------------------------------------------------------------------------- 48 : // get the size of A 49 : //-------------------------------------------------------------------------- 50 : 51 561 : GRB_TRY (GrB_Matrix_nrows (&nrows, A)) ; 52 561 : GRB_TRY (GrB_Matrix_ncols (&ncols, A)) ; 53 : 54 : //-------------------------------------------------------------------------- 55 : // C<s(A)> = true 56 : //-------------------------------------------------------------------------- 57 : 58 561 : GRB_TRY (GrB_Matrix_new (C, GrB_BOOL, nrows, ncols)) ; 59 537 : GRB_TRY (GrB_assign (*C, A, NULL, (bool) true, 60 : GrB_ALL, nrows, GrB_ALL, nrows, GrB_DESC_S)) ; 61 : 62 512 : return (GrB_SUCCESS) ; 63 : }