For hello.ilen
implementations see:
For map1.map1
:
But implemented for 1 iterable with slightly more efficient PyObject_CallOneArg
. Its __next__
is simply:
static PyObject *
map1_next(map1object *lz)
{
PyObject *it = lz->it;
PyObject *item = Py_TYPE(it)->tp_iternext(it);
if (item == NULL) {
return NULL;
}
PyObject *result = PyObject_CallOneArg(lz->func, item);
Py_DECREF(item);
return result;
}
custom.Custom
is a simple class with __call__
:
static PyObject *
Custom_callvector(CustomObject *self, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
if (PyVectorcall_NARGS(nargsf) == 2){
return PyObject_VectorcallDict(self->first, args, nargsf, NULL);
} else {
return PyObject_VectorcallDict(self->last, args, nargsf, NULL);
}
}
I just picked template for it from 2. Defining Extension Types: Tutorial — Python 3.12.3 documentation.
nda
is just an array object with same API as numpy
. nda.ary
== numpy.asarray