| 17 | #include "GB.h" |
| 18 | |
| 19 | GB_PUBLIC |
| 20 | GrB_Info GB_bix_alloc // allocate A->b, A->i, and A->x space in a matrix |
| 21 | ( |
| 22 | GrB_Matrix A, // matrix to allocate space for |
| 23 | const GrB_Index nzmax, // number of entries the matrix can hold; |
| 24 | // ignored if A is iso and full |
| 25 | const int sparsity, // sparse (=hyper/auto) / bitmap / full |
| 26 | const bool bitmap_calloc, // if true, calloc A->b, otherwise use malloc |
| 27 | const bool numeric, // if true, allocate A->x, otherwise A->x is NULL |
| 28 | const bool A_iso, // if true, allocate A as iso |
| 29 | GB_Context Context |
| 30 | ) |
| 31 | { |
| 32 | |
| 33 | //-------------------------------------------------------------------------- |
| 34 | // check inputs |
| 35 | //-------------------------------------------------------------------------- |
| 36 | |
| 37 | ASSERT (A != NULL) ; |
| 38 | |
| 39 | //-------------------------------------------------------------------------- |
| 40 | // allocate the A->b, A->x, and A->i content of the matrix |
| 41 | //-------------------------------------------------------------------------- |
| 42 | |
| 43 | // Free the existing A->b, A->x, and A->i content, if any. |
| 44 | // Leave A->p and A->h unchanged. |
| 45 | GB_bix_free (A) ; |
| 46 | A->iso = A_iso ; // OK: see caller for iso burble |
| 47 | |
| 48 | bool ok = true ; |
| 49 | if (sparsity == GxB_BITMAP) |
| 50 | { |
| 51 | if (bitmap_calloc) |
| 52 | { |
| 53 | // content is fully defined |
| 54 | A->b = GB_CALLOC (nzmax, int8_t, &(A->b_size)) ; |
| 55 | A->magic = GB_MAGIC ; |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | // bitmap is not defined and will be computed by the caller |
| 60 | A->b = GB_MALLOC (nzmax, int8_t, &(A->b_size)) ; |
| 61 | } |
| 62 | ok = (A->b != NULL) ; |
| 63 | } |
| 64 | else if (sparsity != GxB_FULL) |
| 65 | { |
| 66 | // sparsity: sparse / hyper / auto |
| 67 | A->i = GB_MALLOC (nzmax, int64_t, &(A->i_size)) ; |
| 68 | ok = (A->i != NULL) ; |
| 69 | if (ok) A->i [0] = 0 ; |
| 70 | } |
| 71 | |
| 72 | if (numeric) |
| 73 | { |
| 74 | // calloc the space if A is bitmap |
| 75 | A->x = GB_XALLOC (sparsity == GxB_BITMAP, A_iso, // x:OK |
| 76 | nzmax, A->type->size, &(A->x_size)) ; |
no test coverage detected