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

Function dispatcher_vectorcall

numpy/core/src/multiarray/arrayfunction_override.c:500–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498
499
500static PyObject *
501dispatcher_vectorcall(PyArray_ArrayFunctionDispatcherObject *self,
502 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
503{
504 PyObject *result = NULL;
505 PyObject *types = NULL;
506 PyObject *relevant_args = NULL;
507
508 PyObject *public_api;
509
510 /* __array_function__ passes args, kwargs. These may be filled: */
511 PyObject *packed_args = NULL;
512 PyObject *packed_kwargs = NULL;
513
514 PyObject *implementing_args[NPY_MAXARGS];
515 PyObject *array_function_methods[NPY_MAXARGS];
516
517 int num_implementing_args;
518
519 if (self->relevant_arg_func != NULL) {
520 public_api = (PyObject *)self;
521
522 /* Typical path, need to call the relevant_arg_func and unpack them */
523 relevant_args = PyObject_Vectorcall(
524 self->relevant_arg_func, args, len_args, kwnames);
525 if (relevant_args == NULL) {
526 fix_name_if_typeerror(self);
527 return NULL;
528 }
529 Py_SETREF(relevant_args, PySequence_Fast(relevant_args,
530 "dispatcher for __array_function__ did not return an iterable"));
531 if (relevant_args == NULL) {
532 return NULL;
533 }
534
535 num_implementing_args = get_implementing_args_and_methods(
536 relevant_args, implementing_args, array_function_methods);
537 if (num_implementing_args < 0) {
538 Py_DECREF(relevant_args);
539 return NULL;
540 }
541 }
542 else {
543 /* For like= dispatching from Python, the public_symbol is the impl */
544 public_api = self->default_impl;
545
546 /*
547 * We are dealing with `like=` from Python. For simplicity, the
548 * Python code passes it on as the first argument.
549 */
550 if (PyVectorcall_NARGS(len_args) == 0) {
551 PyErr_Format(PyExc_TypeError,
552 "`like` argument dispatching, but first argument is not "
553 "positional in call to %S.", self->default_impl);
554 return NULL;
555 }
556
557 array_function_methods[0] = get_array_function(args[0]);

Callers

nothing calls this directly

Calls 7

fix_name_if_typeerrorFunction · 0.85
get_array_functionFunction · 0.85
get_args_and_kwargsFunction · 0.85
call_array_functionFunction · 0.85

Tested by

no test coverage detected