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

Function _vec_string_with_args

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

Source from the content-addressed store, hash-verified

4038}
4039
4040static PyObject *
4041_vec_string_with_args(PyArrayObject* char_array, PyArray_Descr* type,
4042 PyObject* method, PyObject* args)
4043{
4044 PyObject* broadcast_args[NPY_MAXARGS];
4045 PyArrayMultiIterObject* in_iter = NULL;
4046 PyArrayObject* result = NULL;
4047 PyArrayIterObject* out_iter = NULL;
4048 Py_ssize_t i, n, nargs;
4049
4050 nargs = PySequence_Size(args) + 1;
4051 if (nargs == -1 || nargs > NPY_MAXARGS) {
4052 PyErr_Format(PyExc_ValueError,
4053 "len(args) must be < %d", NPY_MAXARGS - 1);
4054 Py_DECREF(type);
4055 goto err;
4056 }
4057
4058 broadcast_args[0] = (PyObject*)char_array;
4059 for (i = 1; i < nargs; i++) {
4060 PyObject* item = PySequence_GetItem(args, i-1);
4061 if (item == NULL) {
4062 Py_DECREF(type);
4063 goto err;
4064 }
4065 broadcast_args[i] = item;
4066 Py_DECREF(item);
4067 }
4068 in_iter = (PyArrayMultiIterObject*)PyArray_MultiIterFromObjects
4069 (broadcast_args, nargs, 0);
4070 if (in_iter == NULL) {
4071 Py_DECREF(type);
4072 goto err;
4073 }
4074 n = in_iter->numiter;
4075
4076 result = (PyArrayObject*)PyArray_SimpleNewFromDescr(in_iter->nd,
4077 in_iter->dimensions, type);
4078 if (result == NULL) {
4079 goto err;
4080 }
4081
4082 out_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)result);
4083 if (out_iter == NULL) {
4084 goto err;
4085 }
4086
4087 while (PyArray_MultiIter_NOTDONE(in_iter)) {
4088 PyObject* item_result;
4089 PyObject* args_tuple = PyTuple_New(n);
4090 if (args_tuple == NULL) {
4091 goto err;
4092 }
4093
4094 for (i = 0; i < n; i++) {
4095 PyArrayIterObject* it = in_iter->iters[i];
4096 PyObject* arg = PyArray_ToScalar(PyArray_ITER_DATA(it), it->ao);
4097 if (arg == NULL) {

Callers 1

_vec_stringFunction · 0.85

Calls 3

PyArray_IterNewFunction · 0.85
PyArray_SETITEMFunction · 0.85

Tested by

no test coverage detected