I am wrapping some C++ code to use it from Python. I want to call a C++ function with an argument that can take a None
value or a numpy.array
of the same size of another input variable. This is the example:
import example
# Let I a numpy array containing a 2D or 3D image
M = I > 0
# Calling the C++ function with no mask
example.fit(I, k, mask=None)
# Calling the C++ function with mask as a Numpy array of the same size of I
example.fit(I, k, mask=M)
How can I code it in C++ with pybind11? I have the following function signatures and code:
void fit(const py::array_t<float, py::array::c_style | py::array::forcecast> &input,
int k,
const py::array_t<bool, py::array::c_style | py::array::forcecast> &mask)
{
...
}
PYBIND11_MODULE(example, m)
{
m.def("fit", &fit,
py::arg("input"),
py::arg("k"),
py::arg("mask") = nullptr // Don't know what to put here?
);
Thank you very much!