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

Function _umath_strings_richcompare

numpy/core/src/umath/string_ufuncs.cpp:329–449  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

327 * `npy_byte` is correct.
328 */
329NPY_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;

Callers 2

compare_chararraysFunction · 0.85
_void_compareFunction · 0.85

Calls 9

PyArray_TYPEFunction · 0.85
PyArray_DESCRFunction · 0.85
NpyIter_AdvancedNewFunction · 0.85
NpyIter_GetIterSizeFunction · 0.85
NpyIter_GetOperandArrayFunction · 0.85
NpyIter_GetDataPtrArrayFunction · 0.85
NpyIter_DeallocateFunction · 0.85

Tested by

no test coverage detected