[SciPy-Dev] sparsetools C++ code size

Robert Kern robert.kern at gmail.com
Wed Mar 5 11:39:49 EST 2014


On Wed, Mar 5, 2014 at 4:33 PM, Jaime Fernández del Río
<jaime.frio at gmail.com> wrote:

> I am asking out of ignorance here: if you have a templated C++ function, how
> do you go about wrapping it to be accessible from Python?

You write an `extern "C"` function that calls an explicitly
instantiated version of the templated function.

extern "C" {

PyObject* my_python_function(PyObject* self, PyObject* args)
{
    double *input_array;
    double *output_array;
    PyObject *py_output_array;

    input_array = ...
    output_array = ...

    my_templated_function<double>(input_array, output_array);

    py_output_array = PyArray_...(output_array);
    return py_output_array
}

}

-- 
Robert Kern



More information about the SciPy-Dev mailing list