Skip to content

Commit aa23a3e

Browse files
committed
experimented with power-2 aligned data capacity
1 parent c1d5af4 commit aa23a3e

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

doc/articles/nonzero_1d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __call__(self):
4848

4949

5050
#-------------------------------------------------------------------------------
51-
NUMBER = 10
51+
NUMBER = 200
5252

5353
def seconds_to_display(seconds: float) -> str:
5454
seconds /= NUMBER

src/_arraykit.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,17 +3535,17 @@ resolve_dtype_iter(PyObject *Py_UNUSED(m), PyObject *arg) {
35353535
//------------------------------------------------------------------------------
35363536
// general utility
35373537

3538-
static npy_uint32
3539-
AK_next_power(npy_uint32 v) {
3540-
v--;
3541-
v |= v >> 1;
3542-
v |= v >> 2;
3543-
v |= v >> 4;
3544-
v |= v >> 8;
3545-
v |= v >> 16;
3546-
v++;
3547-
return v;
3548-
}
3538+
// static npy_uint32
3539+
// AK_next_power(npy_uint32 v) {
3540+
// v--;
3541+
// v |= v >> 1;
3542+
// v |= v >> 2;
3543+
// v |= v >> 4;
3544+
// v |= v >> 8;
3545+
// v |= v >> 16;
3546+
// v++;
3547+
// return v;
3548+
// }
35493549

35503550

35513551
#define NONZERO_APPEND_INDEX_RELATIVE { \
@@ -3641,6 +3641,7 @@ AK_nonzero_1d(PyArrayObject* array) {
36413641

36423642
Py_ssize_t count = 0;
36433643
// the maximum number of collected integers is equal to or less than count_max; for small count_max, we can just set that value; for large size, we set it to half the size
3644+
// Py_ssize_t capacity = count_max < 1024 ? count_max : (Py_ssize_t)AK_next_power((npy_uint32)(count_max / 8));
36443645
Py_ssize_t capacity = count_max < 1024 ? count_max : count_max / 8;
36453646
npy_int64* indices = (npy_int64*)malloc(sizeof(npy_int64) * capacity);
36463647

0 commit comments

Comments
 (0)