1 //------------------------------------------------------------------------------
2 // GrB_Vector_extractTuples: extract all tuples from a vector
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 column, like [I,~,X] = find (v) in MATLAB.  If
11 // any parameter I and/or X is NULL, then that component is not extracted.  The
12 // size of the I and X arrays (those that are not NULL) is given by nvals,
13 // which must be at least as large as GrB_nvals (&nvals, v).  The values in the
14 // typecasted to the type of X, as needed.
15 
16 // If any parameter I and/or X is NULL, that component is not extracted.  So to
17 // extract just the row indices, pass I as non-NULL, and X as NULL.  This is
18 // like [I,~,~] = find (v) in MATLAB.
19 
20 #include "GB.h"
21 
22 #define GB_EXTRACT(prefix,type,T)                                             \
23 GrB_Info GB_EVAL3 (prefix, _Vector_extractTuples_, T) /* [I,~,X] = find (A) */\
24 (                                                                             \
25     GrB_Index *I,           /* array for returning row indices of tuples */   \
26     type *X,                /* array for returning values of tuples      */   \
27     GrB_Index *p_nvals,     /* I, X size on input; # tuples on output    */   \
28     const GrB_Vector v      /* vector to extract tuples from             */   \
29 )                                                                             \
30 {                                                                             \
31     GB_WHERE1 ("GrB_Vector_extractTuples_" GB_STR(T) " (I, X, nvals, v)") ;   \
32     GB_BURBLE_START ("GrB_Vector_extractTuples") ;                            \
33     GB_RETURN_IF_NULL_OR_FAULTY (v) ;                                         \
34     GB_RETURN_IF_NULL (p_nvals) ;                                             \
35     ASSERT (GB_VECTOR_OK (v)) ;                                               \
36     GrB_Info info = GB_extractTuples (I, NULL, X, p_nvals, GB_ ## T ## _code, \
37         (GrB_Matrix) v, 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