MCPcopy Create free account
hub / github.com/numpy/numpy / count_nonzero_u64

Function count_nonzero_u64

numpy/core/src/multiarray/item_selection.c:2554–2578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2552}
2553
2554static inline NPY_GCC_OPT_3 npy_intp
2555count_nonzero_u64(const char *data, npy_intp bstride, npy_uintp len)
2556{
2557 npy_intp count = 0;
2558#if NPY_SIMD
2559 if (bstride == sizeof(npy_uint64)) {
2560 const npy_uintp len_m = len & -npyv_nlanes_u64;
2561 const npyv_u64 vone = npyv_setall_u64(1);
2562 const npyv_u64 vzero = npyv_zero_u64();
2563
2564 npyv_u64 vsum64 = npyv_zero_u64();
2565 for (const char *end = data + len_m*bstride; data < end; data += NPY_SIMD_WIDTH) {
2566 npyv_u64 mask = npyv_cvt_u64_b64(npyv_cmpeq_u64(npyv_load_u64((npy_uint64*)data), vzero));
2567 mask = npyv_and_u64(mask, vone);
2568 vsum64 = npyv_add_u64(vsum64, mask);
2569 }
2570 len -= len_m;
2571 count = len_m - npyv_sum_u64(vsum64);
2572 }
2573#endif
2574 for (; len > 0; --len, data += bstride) {
2575 count += (*(npy_uint64*)data != 0);
2576 }
2577 return count;
2578}
2579/*
2580 * Counts the number of True values in a raw boolean array. This
2581 * is a low-overhead function which does no heap allocations.

Callers

nothing calls this directly

Calls 2

npyv_cmpeq_u64Function · 0.85
npyv_setall_u64Function · 0.50

Tested by

no test coverage detected