| 13 | #include "GB.h" |
| 14 | |
| 15 | GB_PUBLIC |
| 16 | int64_t GB_nvec_nonempty // return # of non-empty vectors |
| 17 | ( |
| 18 | const GrB_Matrix A, // input matrix to examine |
| 19 | GB_Context Context |
| 20 | ) |
| 21 | { |
| 22 | |
| 23 | //-------------------------------------------------------------------------- |
| 24 | // check inputs |
| 25 | //-------------------------------------------------------------------------- |
| 26 | |
| 27 | ASSERT (A != NULL) ; |
| 28 | ASSERT (GB_ZOMBIES_OK (A)) ; |
| 29 | ASSERT (GB_JUMBLED_OK (A)) ; |
| 30 | ASSERT (GB_PENDING_OK (A)) ; |
| 31 | |
| 32 | //-------------------------------------------------------------------------- |
| 33 | // trivial cases |
| 34 | //-------------------------------------------------------------------------- |
| 35 | |
| 36 | if (GB_IS_FULL (A) || GB_IS_BITMAP (A)) |
| 37 | { |
| 38 | // A is full or bitmap; nvec_nonempty depends only on the dimensions |
| 39 | return ((A->vlen == 0) ? 0 : A->vdim) ; |
| 40 | } |
| 41 | |
| 42 | if (GB_nnz (A) == 0) |
| 43 | { |
| 44 | // A is sparse or hypersparse, with no entries |
| 45 | return (0) ; |
| 46 | } |
| 47 | |
| 48 | //-------------------------------------------------------------------------- |
| 49 | // determine the number of threads to use |
| 50 | //-------------------------------------------------------------------------- |
| 51 | |
| 52 | int64_t anvec = A->nvec ; |
| 53 | GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ; |
| 54 | int nthreads = GB_nthreads (anvec, chunk, nthreads_max) ; |
| 55 | |
| 56 | //-------------------------------------------------------------------------- |
| 57 | // count the non-empty columns |
| 58 | //-------------------------------------------------------------------------- |
| 59 | |
| 60 | int64_t nvec_nonempty = 0 ; |
| 61 | const int64_t *restrict Ap = A->p ; |
| 62 | |
| 63 | int64_t k ; |
| 64 | #pragma omp parallel for num_threads(nthreads) schedule(static) \ |
| 65 | reduction(+:nvec_nonempty) |
| 66 | for (k = 0 ; k < anvec ; k++) |
| 67 | { |
| 68 | if (Ap [k] < Ap [k+1]) nvec_nonempty++ ; |
| 69 | } |
| 70 | |
| 71 | ASSERT (nvec_nonempty >= 0 && nvec_nonempty <= A->vdim) ; |
| 72 |
no test coverage detected