Skip to content

Commit

Permalink
RF - have searchsorted copy haystack when the needle is bigger than t…
Browse files Browse the repository at this point in the history
…he haystack
  • Loading branch information
MrBago committed Aug 17, 2013
1 parent a06b800 commit bb925ed
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,7 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2,
PyArrayObject *sorter = NULL;
PyArrayObject *ret = NULL;
PyArray_Descr *dtype;
int ap1_flags = NPY_ARRAY_NOTSWAPPED | NPY_ARRAY_ALIGNED;
NPY_BEGIN_THREADS_DEF;

/* Find common type */
Expand All @@ -2103,23 +2104,24 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2,
return NULL;
}

/* need ap1 as contiguous array and of right type */
Py_INCREF(dtype);
ap1 = (PyArrayObject *)PyArray_CheckFromAny((PyObject *)op1, dtype,
1, 1,
NPY_ARRAY_ALIGNED | NPY_ARRAY_NOTSWAPPED,
NULL);
if (ap1 == NULL) {
Py_DECREF(dtype);
return NULL;
}

/* need ap2 as contiguous array and of right type */
Py_INCREF(dtype);
ap2 = (PyArrayObject *)PyArray_CheckFromAny(op2, dtype,
0, 0,
NPY_ARRAY_CARRAY_RO | NPY_ARRAY_NOTSWAPPED,
NULL);
if (ap2 == NULL) {
Py_DECREF(dtype);
return NULL;
}

if (PyArray_SIZE(ap2) > PyArray_SIZE(op1)) {
ap1_flags |= NPY_ARRAY_CARRAY_RO;
}

ap1 = (PyArrayObject *)PyArray_CheckFromAny((PyObject *)op1, dtype,
1, 1, ap1_flags, NULL);
if (ap1 == NULL) {
goto fail;
}
/* check that comparison function exists */
Expand Down Expand Up @@ -2148,7 +2150,7 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2,
/* convert to known integer size */
sorter = (PyArrayObject *)PyArray_FromArray(ap3,
PyArray_DescrFromType(NPY_INTP),
NPY_ARRAY_DEFAULT | NPY_ARRAY_NOTSWAPPED);
NPY_ARRAY_ALIGNED | NPY_ARRAY_NOTSWAPPED);
if (sorter == NULL) {
PyErr_SetString(PyExc_ValueError,
"could not parse sorter argument");
Expand Down

0 comments on commit bb925ed

Please sign in to comment.