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

Function init_string_ufuncs

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

Source from the content-addressed store, hash-verified

239
240
241NPY_NO_EXPORT int
242init_string_ufuncs(PyObject *umath)
243{
244 int res = -1;
245 /* NOTE: This should receive global symbols? */
246 PyArray_DTypeMeta *String = PyArray_DTypeFromTypeNum(NPY_STRING);
247 PyArray_DTypeMeta *Unicode = PyArray_DTypeFromTypeNum(NPY_UNICODE);
248 PyArray_DTypeMeta *Bool = PyArray_DTypeFromTypeNum(NPY_BOOL);
249
250 /* We start with the string loops: */
251 PyArray_DTypeMeta *dtypes[] = {String, String, Bool};
252 /*
253 * We only have one loop right now, the strided one. The default type
254 * resolver ensures native byte order/canonical representation.
255 */
256 PyType_Slot slots[] = {
257 {NPY_METH_strided_loop, nullptr},
258 {0, nullptr}
259 };
260
261 PyArrayMethod_Spec spec = {};
262 spec.name = "templated_string_comparison";
263 spec.nin = 2;
264 spec.nout = 1;
265 spec.dtypes = dtypes;
266 spec.slots = slots;
267 spec.flags = NPY_METH_NO_FLOATINGPOINT_ERRORS;
268
269 /* All String loops */
270 using string_looper = add_loops<false, npy_byte, COMP::EQ, COMP::NE, COMP::LT, COMP::LE, COMP::GT, COMP::GE>;
271 if (string_looper()(umath, &spec) < 0) {
272 goto finish;
273 }
274
275 /* All Unicode loops */
276 using ucs_looper = add_loops<false, npy_ucs4, COMP::EQ, COMP::NE, COMP::LT, COMP::LE, COMP::GT, COMP::GE>;
277 dtypes[0] = Unicode;
278 dtypes[1] = Unicode;
279 if (ucs_looper()(umath, &spec) < 0) {
280 goto finish;
281 }
282
283 res = 0;
284 finish:
285 Py_DECREF(String);
286 Py_DECREF(Unicode);
287 Py_DECREF(Bool);
288 return res;
289}
290
291
292template <bool rstrip, typename character>

Callers 1

initumathFunction · 0.85

Calls 1

PyArray_DTypeFromTypeNumFunction · 0.85

Tested by

no test coverage detected