1 //------------------------------------------------------------------------------ 2 // GrB_Matrix_extractTuples: extract all tuples from a matrix 3 //------------------------------------------------------------------------------ 4 5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 6 // SPDX-License-Identifier: Apache-2.0 7 8 //------------------------------------------------------------------------------ 9 10 // Extracts all tuples from a matrix, like [I,J,X] = find (A) in MATLAB. If 11 // any parameter I, J and/or X is NULL, then that component is not extracted. 12 // The size of the I, J, and X arrays (those that are not NULL) is given by 13 // nvals, which must be at least as large as GrB_nvals (&nvals, A). The values 14 // in the matrix are typecasted to the type of X, as needed. 15 16 // If any parameter I, J, and/or X is NULL, that component is not extracted. 17 // So to extract just the row and col indices, pass I and J as non-NULL, 18 // and X as NULL. This is like [I,J,~] = find (A). 19 20 #include "GB.h" 21 22 #define GB_EXTRACT(prefix,type,T) \ 23 GrB_Info GB_EVAL3 (prefix, _Matrix_extractTuples_, T) /* [I,J,X] = find (A) */\ 24 ( \ 25 GrB_Index *I, /* array for returning row indices of tuples */ \ 26 GrB_Index *J, /* array for returning col indices of tuples */ \ 27 type *X, /* array for returning values of tuples */ \ 28 GrB_Index *p_nvals, /* I,J,X size on input; # tuples on output */ \ 29 const GrB_Matrix A /* matrix to extract tuples from */ \ 30 ) \ 31 { \ 32 GB_WHERE1 ("GrB_Matrix_extractTuples_" GB_STR(T) " (I, J, X, nvals, A)") ;\ 33 GB_BURBLE_START ("GrB_Matrix_extractTuples") ; \ 34 GB_RETURN_IF_NULL_OR_FAULTY (A) ; \ 35 GB_RETURN_IF_NULL (p_nvals) ; \ 36 GrB_Info info = GB_extractTuples (I, J, X, p_nvals, GB_ ## T ## _code, A, \ 37 Context) ; \ 38 GB_BURBLE_END ; \ 39 return (info) ; \ 40 } 41 42 GB_EXTRACT (GrB, bool , BOOL ) 43 GB_EXTRACT (GrB, int8_t , INT8 ) 44 GB_EXTRACT (GrB, uint8_t , UINT8 ) 45 GB_EXTRACT (GrB, int16_t , INT16 ) 46 GB_EXTRACT (GrB, uint16_t , UINT16 ) 47 GB_EXTRACT (GrB, int32_t , INT32 ) 48 GB_EXTRACT (GrB, uint32_t , UINT32 ) 49 GB_EXTRACT (GrB, int64_t , INT64 ) 50 GB_EXTRACT (GrB, uint64_t , UINT64 ) 51 GB_EXTRACT (GrB, float , FP32 ) 52 GB_EXTRACT (GrB, double , FP64 ) 53 GB_EXTRACT (GxB, GxB_FC32_t, FC32 ) 54 GB_EXTRACT (GxB, GxB_FC64_t, FC64 ) 55 GB_EXTRACT (GrB, void , UDT ) 56 57