Skip to content

Commit a94ae8d

Browse files
committed
Formatting and fixes a cast.
1 parent 7b5d38d commit a94ae8d

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/_arraykit.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -615,26 +615,23 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
615615
&PyArray_Type, &indexers,
616616
&PyArray_Type, &positions
617617
))
618-
{
618+
{
619619
return NULL;
620620
}
621621

622-
if (PyArray_NDIM(indexers) != 1)
623-
{
622+
if (PyArray_NDIM(indexers) != 1) {
624623
PyErr_SetString(PyExc_ValueError, "indexers must be 1-dimensional");
625624
return NULL;
626625
}
627626

628-
if (PyArray_TYPE(indexers) != NPY_INT64)
629-
{
627+
if (PyArray_TYPE(indexers) != NPY_INT64) {
630628
PyErr_SetString(PyExc_ValueError, "Array must be of type np.int64");
631629
return NULL;
632630
}
633631

634632
npy_intp num_unique = PyArray_SIZE(positions);
635633

636-
if (num_unique > PyArray_SIZE(indexers))
637-
{
634+
if (num_unique > PyArray_SIZE(indexers)) {
638635
// This algorithm is only optimal if the number of unique elements is
639636
// less than the number of elements in the indexers.
640637
// Otherwise, the most optimal code is ``np.unique(indexers, return_index=True)[1]``
@@ -648,10 +645,10 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
648645

649646
npy_intp dims = {num_unique};
650647
PyArrayObject *element_locations = (PyArrayObject*)PyArray_Empty(
651-
1, // ndim
652-
&dims, // shape
653-
PyArray_DescrFromType(NPY_INT64), // dtype
654-
0 // fortran
648+
1, // ndim
649+
&dims, // shape
650+
PyArray_DescrFromType(NPY_INT64), // dtype
651+
0 // fortran
655652
);
656653
if (element_locations == NULL) {
657654
return NULL;
@@ -688,15 +685,11 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
688685
// over using numpy's iteration APIs.
689686
npy_int64 *element_location_values = (npy_int64*)PyArray_DATA(element_locations);
690687
npy_int64 *new_indexers_values = (npy_int64*)PyArray_DATA(new_indexers);
691-
npy_int64 *array_values = (npy_int64*)PyArray_DATA(indexers);
692-
693-
npy_int64 num_found = 0;
694688

695689
// Now, implement the core algorithm by looping over the ``indexers``.
696690
// We need to use numpy's iteration API, as the ``indexers`` could be
697691
// C-contiguous, F-contiguous, both, or neither.
698692
// See https://numpy.org/doc/stable/reference/c-api/iterator.html#simple-iteration-example
699-
700693
NpyIter *indexer_iter = NpyIter_New(
701694
indexers,
702695
NPY_ITER_READONLY| NPY_ITER_EXTERNAL_LOOP,
@@ -725,6 +718,7 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
725718
npy_intp *innersizeptr = NpyIter_GetInnerLoopSizePtr(indexer_iter);
726719

727720
size_t i = 0;
721+
npy_int64 num_found = 0;
728722
do {
729723
// Get the inner loop data/stride/inner_size values
730724
char* data = *dataptr;
@@ -733,15 +727,13 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
733727
npy_int64 element;
734728

735729
while (inner_size--) {
736-
memcpy (&element, data, sizeof (long));
730+
memcpy (&element, data, sizeof (npy_int64));
737731

738-
if (element_location_values[element] == num_unique)
739-
{
732+
if (element_location_values[element] == num_unique) {
740733
element_location_values[element] = num_found;
741734
++num_found;
742735

743-
if (num_found == num_unique)
744-
{
736+
if (num_found == num_unique) {
745737
// This insight is core to the performance of the algorithm.
746738
// If we have found every possible indexer, we can simply return
747739
// back the inputs! Essentially, we can observe on <= single pass
@@ -770,7 +762,6 @@ get_new_indexers_and_screen(PyObject *Py_UNUSED(m), PyObject *args, PyObject *kw
770762
return result;
771763
}
772764

773-
774765
//------------------------------------------------------------------------------
775766
// ArrayGO
776767
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)