| 14 | #include "GB.h" |
| 15 | |
| 16 | GrB_Info GB_hypermatrix_prune |
| 17 | ( |
| 18 | GrB_Matrix A, // matrix to prune |
| 19 | GB_Context Context |
| 20 | ) |
| 21 | { |
| 22 | |
| 23 | //-------------------------------------------------------------------------- |
| 24 | // check inputs |
| 25 | //-------------------------------------------------------------------------- |
| 26 | |
| 27 | ASSERT (A != NULL) ; |
| 28 | ASSERT (GB_ZOMBIES_OK (A)) ; // pattern not accessed |
| 29 | ASSERT (GB_JUMBLED_OK (A)) ; |
| 30 | ASSERT_MATRIX_OK (A, "A before hypermatrix_prune", GB0) ; |
| 31 | |
| 32 | if (!GB_IS_HYPERSPARSE (A)) |
| 33 | { |
| 34 | // nothing to do |
| 35 | return (GrB_SUCCESS) ; |
| 36 | } |
| 37 | |
| 38 | //-------------------------------------------------------------------------- |
| 39 | // count # of empty vectors |
| 40 | //-------------------------------------------------------------------------- |
| 41 | |
| 42 | if (A->nvec_nonempty < 0) |
| 43 | { |
| 44 | // A->nvec_nonempty is needed to prune the hyperlist |
| 45 | A->nvec_nonempty = GB_nvec_nonempty (A, Context) ; |
| 46 | } |
| 47 | |
| 48 | //-------------------------------------------------------------------------- |
| 49 | // prune empty vectors |
| 50 | //-------------------------------------------------------------------------- |
| 51 | |
| 52 | if (A->nvec_nonempty < A->nvec) // A->nvec_nonempty used here |
| 53 | { |
| 54 | // create new Ap_new and Ah_new arrays, with no empty vectors |
| 55 | int64_t *restrict Ap_new = NULL ; size_t Ap_new_size = 0 ; |
| 56 | int64_t *restrict Ah_new = NULL ; size_t Ah_new_size = 0 ; |
| 57 | int64_t nvec_new, plen_new ; |
| 58 | int64_t anz = A->nvals ; |
| 59 | ASSERT (anz == A->p [A->nvec]) ; |
| 60 | GrB_Info info = GB_hyper_prune (&Ap_new, &Ap_new_size, |
| 61 | &Ah_new, &Ah_new_size, &nvec_new, &plen_new, |
| 62 | A->p, A->h, A->nvec, Context) ; |
| 63 | if (info != GrB_SUCCESS) |
| 64 | { |
| 65 | // out of memory |
| 66 | return (info) ; |
| 67 | } |
| 68 | // free the old A->p, A->h, and A->Y |
| 69 | GB_phy_free (A) ; |
| 70 | // A->p, A->h, A->Y are now NULL and thus not shallow |
| 71 | ASSERT (!A->p_shallow) ; |
| 72 | ASSERT (!A->h_shallow) ; |
| 73 | ASSERT (!A->Y_shallow) ; |
no test coverage detected