* This function is used for `compare_chararrays` and currently also void * comparisons (unstructured voids). The first could probably be deprecated * and removed but is used by `np.char.chararray` the latter should also be * moved to the ufunc probably (removing the need for manual looping). * * The `rstrip` mechanism is presumably for some fortran compat, but the * question is whether it w
| 327 | * `npy_byte` is correct. |
| 328 | */ |
| 329 | NPY_NO_EXPORT PyObject * |
| 330 | _umath_strings_richcompare( |
| 331 | PyArrayObject *self, PyArrayObject *other, int cmp_op, int rstrip) |
| 332 | { |
| 333 | NpyIter *iter = nullptr; |
| 334 | PyObject *result = nullptr; |
| 335 | |
| 336 | char **dataptr = nullptr; |
| 337 | npy_intp *strides = nullptr; |
| 338 | npy_intp *countptr = nullptr; |
| 339 | npy_intp size = 0; |
| 340 | |
| 341 | PyArrayMethod_Context context = {}; |
| 342 | NpyIter_IterNextFunc *iternext = nullptr; |
| 343 | |
| 344 | npy_uint32 it_flags = ( |
| 345 | NPY_ITER_EXTERNAL_LOOP | NPY_ITER_ZEROSIZE_OK | |
| 346 | NPY_ITER_BUFFERED | NPY_ITER_GROWINNER); |
| 347 | npy_uint32 op_flags[3] = { |
| 348 | NPY_ITER_READONLY | NPY_ITER_ALIGNED, |
| 349 | NPY_ITER_READONLY | NPY_ITER_ALIGNED, |
| 350 | NPY_ITER_WRITEONLY | NPY_ITER_ALLOCATE | NPY_ITER_ALIGNED}; |
| 351 | |
| 352 | PyArrayMethod_StridedLoop *strided_loop = nullptr; |
| 353 | NPY_BEGIN_THREADS_DEF; |
| 354 | |
| 355 | if (PyArray_TYPE(self) != PyArray_TYPE(other)) { |
| 356 | /* |
| 357 | * Comparison between Bytes and Unicode is not defined in Py3K; |
| 358 | * we follow. |
| 359 | * TODO: This makes no sense at all for `compare_chararrays`, kept |
| 360 | * only under the assumption that we are more likely to deprecate |
| 361 | * than fix it to begin with. |
| 362 | */ |
| 363 | Py_INCREF(Py_NotImplemented); |
| 364 | return Py_NotImplemented; |
| 365 | } |
| 366 | |
| 367 | PyArrayObject *ops[3] = {self, other, nullptr}; |
| 368 | PyArray_Descr *descrs[3] = {nullptr, nullptr, PyArray_DescrFromType(NPY_BOOL)}; |
| 369 | /* TODO: ensuring native byte order is not really necessary for == and != */ |
| 370 | descrs[0] = NPY_DT_CALL_ensure_canonical(PyArray_DESCR(self)); |
| 371 | if (descrs[0] == nullptr) { |
| 372 | goto finish; |
| 373 | } |
| 374 | descrs[1] = NPY_DT_CALL_ensure_canonical(PyArray_DESCR(other)); |
| 375 | if (descrs[1] == nullptr) { |
| 376 | goto finish; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Create the iterator: |
| 381 | */ |
| 382 | iter = NpyIter_AdvancedNew( |
| 383 | 3, ops, it_flags, NPY_KEEPORDER, NPY_SAFE_CASTING, op_flags, descrs, |
| 384 | -1, nullptr, nullptr, 0); |
| 385 | if (iter == nullptr) { |
| 386 | goto finish; |
no test coverage detected