| 27 | } |
| 28 | |
| 29 | GrB_Info GB_extractTuples // extract all tuples from a matrix |
| 30 | ( |
| 31 | GrB_Index *I_out, // array for returning row indices of tuples |
| 32 | GrB_Index *J_out, // array for returning col indices of tuples |
| 33 | void *X, // array for returning values of tuples |
| 34 | GrB_Index *p_nvals, // I,J,X size on input; # tuples on output |
| 35 | const GB_Type_code xcode, // type of array X |
| 36 | const GrB_Matrix A, // matrix to extract tuples from |
| 37 | GB_Context Context |
| 38 | ) |
| 39 | { |
| 40 | |
| 41 | //-------------------------------------------------------------------------- |
| 42 | // check inputs |
| 43 | //-------------------------------------------------------------------------- |
| 44 | |
| 45 | GrB_Info info ; |
| 46 | GB_void *restrict X_bitmap = NULL ; size_t X_bitmap_size = 0 ; |
| 47 | int64_t *restrict Ap = NULL ; size_t Ap_size = 0 ; |
| 48 | |
| 49 | ASSERT_MATRIX_OK (A, "A to extract", GB0) ; |
| 50 | ASSERT (p_nvals != NULL) ; |
| 51 | |
| 52 | // delete any lingering zombies and assemble any pending tuples; |
| 53 | // allow A to remain jumbled |
| 54 | GB_MATRIX_WAIT_IF_PENDING_OR_ZOMBIES (A) ; |
| 55 | |
| 56 | GB_BURBLE_DENSE (A, "(A %s) ") ; |
| 57 | ASSERT (xcode <= GB_UDT_code) ; |
| 58 | const GB_Type_code acode = A->type->code ; |
| 59 | const size_t asize = A->type->size ; |
| 60 | |
| 61 | // xcode and A must be compatible |
| 62 | if (!GB_code_compatible (xcode, acode)) |
| 63 | { |
| 64 | return (GrB_DOMAIN_MISMATCH) ; |
| 65 | } |
| 66 | |
| 67 | const int64_t anz = GB_nnz (A) ; |
| 68 | if (anz == 0) |
| 69 | { |
| 70 | // no work to do |
| 71 | (*p_nvals) = 0 ; |
| 72 | return (GrB_SUCCESS) ; |
| 73 | } |
| 74 | |
| 75 | int64_t nvals = *p_nvals ; // size of I,J,X on input |
| 76 | if (nvals < anz && (I_out != NULL || J_out != NULL || X != NULL)) |
| 77 | { |
| 78 | // output arrays are not big enough |
| 79 | return (GrB_INSUFFICIENT_SPACE) ; |
| 80 | } |
| 81 | |
| 82 | //------------------------------------------------------------------------- |
| 83 | // determine the number of threads to use |
| 84 | //------------------------------------------------------------------------- |
| 85 | |
| 86 | GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ; |
no test coverage detected