Skip to content

numpy arrays scalar #1224

@fbriol

Description

@fbriol

Hello I need different functions taking as arguments a value of « numpy arrays scalar » type.

It is possible to write prototypes like this:

PYBIND11_MODULE(np_scalar, m) {
    m.def("overloaded", [](py::array_t<double>) {
        return "double";
    });
    m.def("overloaded", [](py::array_t<std::int8_t>) {
        return "int8";
    });
    m.def("overloaded", [](py::array_t<std::int16_t>) {
        return "int16";
    });
}

However, this method does not allow to intercept scalars, for example:

>>> import np_scalar
>>> np_scalar.overloaded(numpy.array([1], dtype='int8'))
'int8'
>>> np_scalar.overloaded(numpy.int8(1))
'double'

How do we intercept numpy arrays scalar?

Thank you very much for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions