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

Function _vec_string

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

Source from the content-addressed store, hash-verified

4203}
4204
4205static PyObject *
4206_vec_string(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUSED(kwds))
4207{
4208 PyArrayObject* char_array = NULL;
4209 PyArray_Descr *type;
4210 PyObject* method_name;
4211 PyObject* args_seq = NULL;
4212
4213 PyObject* method = NULL;
4214 PyObject* result = NULL;
4215
4216 if (!PyArg_ParseTuple(args, "O&O&O|O",
4217 PyArray_Converter, &char_array,
4218 PyArray_DescrConverter, &type,
4219 &method_name, &args_seq)) {
4220 goto err;
4221 }
4222
4223 if (PyArray_TYPE(char_array) == NPY_STRING) {
4224 method = PyObject_GetAttr((PyObject *)&PyBytes_Type, method_name);
4225 }
4226 else if (PyArray_TYPE(char_array) == NPY_UNICODE) {
4227 method = PyObject_GetAttr((PyObject *)&PyUnicode_Type, method_name);
4228 }
4229 else {
4230 if (_is_user_defined_string_array(char_array)) {
4231 PyTypeObject* scalar_type =
4232 NPY_DTYPE(PyArray_DESCR(char_array))->scalar_type;
4233 method = PyObject_GetAttr((PyObject*)scalar_type, method_name);
4234 }
4235 else {
4236 Py_DECREF(type);
4237 goto err;
4238 }
4239 }
4240 if (method == NULL) {
4241 Py_DECREF(type);
4242 goto err;
4243 }
4244
4245 if (args_seq == NULL
4246 || (PySequence_Check(args_seq) && PySequence_Size(args_seq) == 0)) {
4247 result = _vec_string_no_args(char_array, type, method);
4248 }
4249 else if (PySequence_Check(args_seq)) {
4250 result = _vec_string_with_args(char_array, type, method, args_seq);
4251 }
4252 else {
4253 Py_DECREF(type);
4254 PyErr_SetString(PyExc_TypeError,
4255 "'args' must be a sequence of arguments");
4256 goto err;
4257 }
4258 if (result == NULL) {
4259 goto err;
4260 }
4261
4262 Py_DECREF(char_array);

Callers 15

str_lenFunction · 0.90
addFunction · 0.90
multiplyFunction · 0.90
modFunction · 0.90
capitalizeFunction · 0.90
centerFunction · 0.90
countFunction · 0.90
decodeFunction · 0.90
encodeFunction · 0.90
endswithFunction · 0.90
expandtabsFunction · 0.90
findFunction · 0.90

Calls 5

PyArray_TYPEFunction · 0.85
PyArray_DESCRFunction · 0.85
_vec_string_no_argsFunction · 0.85
_vec_string_with_argsFunction · 0.85

Tested by 1

failMethod · 0.72