| 21 | //------------------------------------------------------------------------------ |
| 22 | |
| 23 | GrB_Info GB_resize // change the size of a matrix |
| 24 | ( |
| 25 | GrB_Matrix A, // matrix to modify |
| 26 | const GrB_Index nrows_new, // new number of rows in matrix |
| 27 | const GrB_Index ncols_new, // new number of columns in matrix |
| 28 | GB_Context Context |
| 29 | ) |
| 30 | { |
| 31 | |
| 32 | //-------------------------------------------------------------------------- |
| 33 | // check inputs |
| 34 | //-------------------------------------------------------------------------- |
| 35 | |
| 36 | GrB_Info info ; |
| 37 | GB_void *restrict Ax_new = NULL ; size_t Ax_new_size = 0 ; |
| 38 | int8_t *restrict Ab_new = NULL ; size_t Ab_new_size = 0 ; |
| 39 | ASSERT_MATRIX_OK (A, "A to resize", GB0) ; |
| 40 | |
| 41 | //-------------------------------------------------------------------------- |
| 42 | // handle the CSR/CSC format |
| 43 | //-------------------------------------------------------------------------- |
| 44 | |
| 45 | int64_t vdim_old = A->vdim ; |
| 46 | int64_t vlen_old = A->vlen ; |
| 47 | int64_t vlen_new, vdim_new ; |
| 48 | if (A->is_csc) |
| 49 | { |
| 50 | vlen_new = nrows_new ; |
| 51 | vdim_new = ncols_new ; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | vlen_new = ncols_new ; |
| 56 | vdim_new = nrows_new ; |
| 57 | } |
| 58 | |
| 59 | if (vdim_new == vdim_old && vlen_new == vlen_old) |
| 60 | { |
| 61 | // nothing to do |
| 62 | return (GrB_SUCCESS) ; |
| 63 | } |
| 64 | |
| 65 | //-------------------------------------------------------------------------- |
| 66 | // delete any lingering zombies and assemble any pending tuples |
| 67 | //-------------------------------------------------------------------------- |
| 68 | |
| 69 | // only do so if either dimension is shrinking, or if pending tuples exist |
| 70 | // and vdim_old <= 1 and vdim_new > 1, since in that case, Pending->j has |
| 71 | // not been allocated yet, but would be required in the resized matrix. |
| 72 | // If A is jumbled, it must be sorted. |
| 73 | |
| 74 | if (vdim_new < vdim_old || vlen_new < vlen_old || A->jumbled || |
| 75 | (GB_PENDING (A) && vdim_old <= 1 && vdim_new > 1)) |
| 76 | { |
| 77 | GB_MATRIX_WAIT (A) ; |
| 78 | ASSERT_MATRIX_OK (A, "A to resize, wait", GB0) ; |
| 79 | } |
| 80 |
no test coverage detected