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

Function _vec_string_no_args

numpy/core/src/multiarray/multiarraymodule.c:4136–4203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4134}
4135
4136static PyObject *
4137_vec_string_no_args(PyArrayObject* char_array,
4138 PyArray_Descr* type, PyObject* method)
4139{
4140 /*
4141 * This is a faster version of _vec_string_args to use when there
4142 * are no additional arguments to the string method. This doesn't
4143 * require a broadcast iterator (and broadcast iterators don't work
4144 * with 1 argument anyway).
4145 */
4146 PyArrayIterObject* in_iter = NULL;
4147 PyArrayObject* result = NULL;
4148 PyArrayIterObject* out_iter = NULL;
4149
4150 in_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)char_array);
4151 if (in_iter == NULL) {
4152 Py_DECREF(type);
4153 goto err;
4154 }
4155
4156 result = (PyArrayObject*)PyArray_SimpleNewFromDescr(
4157 PyArray_NDIM(char_array), PyArray_DIMS(char_array), type);
4158 if (result == NULL) {
4159 goto err;
4160 }
4161
4162 out_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)result);
4163 if (out_iter == NULL) {
4164 goto err;
4165 }
4166
4167 while (PyArray_ITER_NOTDONE(in_iter)) {
4168 PyObject* item_result;
4169 PyObject* item = PyArray_ToScalar(in_iter->dataptr, in_iter->ao);
4170 if (item == NULL) {
4171 goto err;
4172 }
4173
4174 item_result = PyObject_CallFunctionObjArgs(method, item, NULL);
4175 Py_DECREF(item);
4176 if (item_result == NULL) {
4177 goto err;
4178 }
4179
4180 if (PyArray_SETITEM(result, PyArray_ITER_DATA(out_iter), item_result)) {
4181 Py_DECREF(item_result);
4182 PyErr_SetString( PyExc_TypeError,
4183 "result array type does not match underlying function");
4184 goto err;
4185 }
4186 Py_DECREF(item_result);
4187
4188 PyArray_ITER_NEXT(in_iter);
4189 PyArray_ITER_NEXT(out_iter);
4190 }
4191
4192 Py_DECREF(in_iter);
4193 Py_DECREF(out_iter);

Callers 1

_vec_stringFunction · 0.85

Calls 4

PyArray_IterNewFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_SETITEMFunction · 0.85

Tested by

no test coverage detected