Search code examples
pythonscipycpython

Location or name of function in SciPy C source


I am trying to find some C source code for min_or_max_filter function from SciPy ndimage. The closest functions I found are in this file (NI_MinOrMaxFilter for instance), but none of them are called min_or_max_filter. How does the name mapping between .pyi and .c files work?


Solution

  • generally there is a wrapper function that is responsible for mapping C types to python types to allow the development of C code independently from python.

    this wrapper function is called Py_MinOrMaxFilter , which is registered as "min_or_max_filter",so it is called in python as _nd_image.min_or_max_filter, this function calls NI_MinOrMaxFilter internally after doing the necessary conversions from python types to C types.

    note the underscore in _nd_image means it is a private module and can change between versions without notice.

    using such wrappers is useful as this filter function is a pure C function, whose sole responsibility is to do the filtering while the wrapper's responsibility is to convert the types from python to C, therefore there's a good separation of responsibilities.