| 35 | //------------------------------------------------------------------------------ |
| 36 | |
| 37 | static GrB_Info GB_export_worker // export a matrix |
| 38 | ( |
| 39 | GrB_Index *Ap, // pointers for CSR, CSC, row indices for COO |
| 40 | GrB_Index *Ai, // row indices for CSR, CSC, col indices for COO |
| 41 | void *Ax, // values (must match the type of A_input) |
| 42 | GrB_Index *Ap_len, // number of entries in Ap (not # of bytes) |
| 43 | GrB_Index *Ai_len, // number of entries in Ai (not # of bytes) |
| 44 | GrB_Index *Ax_len, // number of entries in Ax (not # of bytes) |
| 45 | GrB_Format format, // export format |
| 46 | GrB_Matrix A_input, // matrix to export |
| 47 | GB_Context Context |
| 48 | ) |
| 49 | { |
| 50 | |
| 51 | //-------------------------------------------------------------------------- |
| 52 | // check inputs |
| 53 | //-------------------------------------------------------------------------- |
| 54 | |
| 55 | GrB_Info info ; |
| 56 | |
| 57 | GrB_Matrix A = A_input ; |
| 58 | struct GB_Matrix_opaque T_header ; |
| 59 | GrB_Matrix T = NULL ; |
| 60 | |
| 61 | switch (format) |
| 62 | { |
| 63 | case GrB_CSR_FORMAT : |
| 64 | case GrB_CSC_FORMAT : |
| 65 | case GrB_COO_FORMAT : |
| 66 | GB_RETURN_IF_NULL (Ap) ; GB_RETURN_IF_NULL (Ap_len) ; |
| 67 | GB_RETURN_IF_NULL (Ai) ; GB_RETURN_IF_NULL (Ai_len) ; |
| 68 | default: |
| 69 | GB_RETURN_IF_NULL (Ax) ; GB_RETURN_IF_NULL (Ax_len) ; |
| 70 | } |
| 71 | |
| 72 | // finish any pending work |
| 73 | GB_MATRIX_WAIT (A) ; |
| 74 | |
| 75 | //-------------------------------------------------------------------------- |
| 76 | // determine current format of A and if a copy is needed |
| 77 | //-------------------------------------------------------------------------- |
| 78 | |
| 79 | int sparsity = GB_sparsity (A) ; |
| 80 | bool is_csc = A->is_csc ; |
| 81 | bool make_copy ; |
| 82 | bool csc_requested ; |
| 83 | |
| 84 | switch (format) |
| 85 | { |
| 86 | case GrB_CSR_FORMAT : |
| 87 | make_copy = !(sparsity == GxB_SPARSE && !is_csc) ; |
| 88 | csc_requested = false ; |
| 89 | break ; |
| 90 | |
| 91 | case GrB_CSC_FORMAT : |
| 92 | make_copy = !(sparsity == GxB_SPARSE && is_csc) ; |
| 93 | csc_requested = true ; |
| 94 | break ; |
no test coverage detected