Line data Source code
1 : //------------------------------------------------------------------------------ 2 : // LAGraph_Vector_Structure: return the structure of a vector 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 : // LAGraph_Vector_Structure: return the structure of a vector as a boolean 19 : // vector, where w(i)=true if the entry u(i) is present in the vector u. 20 : 21 : #define LG_FREE_ALL GrB_free (w) ; 22 : 23 : #include "LG_internal.h" 24 : 25 4 : int LAGraph_Vector_Structure 26 : ( 27 : // output: 28 : GrB_Vector *w, // a boolean matrix with same structure of u, with w(i) 29 : // set to true if u(i) appears in the sparsity structure 30 : // of u. 31 : // input: 32 : GrB_Vector u, 33 : char *msg 34 : ) 35 : { 36 : 37 : //-------------------------------------------------------------------------- 38 : // check inputs 39 : //-------------------------------------------------------------------------- 40 : 41 4 : LG_CLEAR_MSG ; 42 : GrB_Index n ; 43 4 : LG_ASSERT_MSG (w != NULL, GrB_NULL_POINTER, "&w != NULL") ; 44 3 : LG_ASSERT (u != NULL, GrB_NULL_POINTER) ; 45 2 : (*w) = NULL ; 46 : 47 : //-------------------------------------------------------------------------- 48 : // get the size of u 49 : //-------------------------------------------------------------------------- 50 : 51 2 : GRB_TRY (GrB_Vector_size (&n, u)) ; 52 : 53 : //-------------------------------------------------------------------------- 54 : // w<s(u)> = true 55 : //-------------------------------------------------------------------------- 56 : 57 2 : GRB_TRY (GrB_Vector_new (w, GrB_BOOL, n)) ; 58 2 : GRB_TRY (GrB_assign (*w, u, NULL, (bool) true, GrB_ALL, n, GrB_DESC_S)) ; 59 : 60 2 : return (GrB_SUCCESS) ; 61 : }