A C++ routine that returns a 2-dimensional ndarray, when wrapped with pybind11, may always?) returns a 1-dimensional array if one of the two dimensions has length 1. We first saw this in lsst::afw::geom::Transform::getJacobian and added a pure python wrapper to work around it. But it would be much nicer if the shape was properly preserved when the array was returned.
I have three questions:
- Is this something that ndarray could prevent? If so, that would be great.
- Is there a workaround that works in C++?
- Can this problem happen when passing a numpy array as an argument to a wrapped function that takes an ndarray? (I have not seen it yet, and would have expected to in astshim unit tests). If not, it is surprising that it only happens when returning data.