| 26 | //------------------------------------------------------------------------------ |
| 27 | |
| 28 | static GrB_Info GB_import_worker // import a matrix of any type |
| 29 | ( |
| 30 | GrB_Matrix *A, // handle of matrix to create |
| 31 | GrB_Type type, // type of matrix to create |
| 32 | GrB_Index nrows, // number of rows of the matrix |
| 33 | GrB_Index ncols, // number of columns of the matrix |
| 34 | const GrB_Index *Ap, // pointers for CSR, CSC, row indices for COO |
| 35 | const GrB_Index *Ai, // row indices for CSR, CSC, col indices for COO |
| 36 | const void *Ax, // values (must match the GrB_Type type parameter) |
| 37 | GrB_Index Ap_len, // number of entries in Ap (not # of bytes) |
| 38 | GrB_Index Ai_len, // number of entries in Ai (not # of bytes) |
| 39 | GrB_Index Ax_len, // number of entries in Ax (not # of bytes) |
| 40 | GrB_Format format, // import format |
| 41 | GB_Context Context |
| 42 | ) |
| 43 | { |
| 44 | |
| 45 | //-------------------------------------------------------------------------- |
| 46 | // check inputs |
| 47 | //-------------------------------------------------------------------------- |
| 48 | |
| 49 | GB_RETURN_IF_NULL (A) ; |
| 50 | (*A) = NULL ; |
| 51 | GB_RETURN_IF_NULL (Ax) ; |
| 52 | ASSERT_TYPE_OK (type, "type for GrB_Matrix_import", GB0) ; |
| 53 | GrB_Info info ; |
| 54 | |
| 55 | // GrB_Matrix_import has no descritptor so it only supports a secure import |
| 56 | bool fast_import = false ; |
| 57 | |
| 58 | if (nrows > GB_NMAX || ncols > GB_NMAX || Ap_len > GB_NMAX |
| 59 | || Ai_len > GB_NMAX || Ax_len > GB_NMAX) |
| 60 | { |
| 61 | // problem is too large |
| 62 | return (GrB_INVALID_VALUE) ; |
| 63 | } |
| 64 | |
| 65 | GrB_Index nvals = 0 ; |
| 66 | bool ok = true ; |
| 67 | int64_t plen = (format == GrB_CSR_FORMAT) ? (nrows+1) : (ncols+1) ; |
| 68 | |
| 69 | switch (format) |
| 70 | { |
| 71 | |
| 72 | case GrB_CSR_FORMAT : |
| 73 | case GrB_CSC_FORMAT : |
| 74 | |
| 75 | GB_RETURN_IF_NULL (Ap) ; |
| 76 | GB_RETURN_IF_NULL (Ai) ; |
| 77 | if (Ap_len < plen) |
| 78 | { |
| 79 | // Ap is too small |
| 80 | return (GrB_INVALID_VALUE) ; |
| 81 | } |
| 82 | nvals = Ap [plen-1] ; |
| 83 | if (Ai_len < nvals || Ax_len < nvals || nvals > GB_NMAX) |
| 84 | { |
| 85 | // Ai and/or Ax are too small or problem is too large |
no test coverage detected