Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-10011

ndarray sometimes returns an array with axes missing in Python

    Details

      Description

      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.

        Attachments

          Activity

          Hide
          jbosch Jim Bosch added a comment -

          This behavior was due to a call to PyArray_Squeeze, which was added because it mimics the behavior of NumPy itself in at least some contexts.  That explicit call has gone away with the switch to pybind11's NumPy APIs, so if it's still present (I didn't notice any test failures due to changes in behavior), it's now an upstream pybind11 problem, and probably something they consider a feature, not a bug (as ndarray once did).

          Show
          jbosch Jim Bosch added a comment - This behavior was due to a call to PyArray_Squeeze , which was added because it mimics the behavior of NumPy itself in at least some contexts.  That explicit call has gone away with the switch to pybind11's NumPy APIs, so if it's still present (I didn't notice any test failures due to changes in behavior), it's now an upstream pybind11 problem, and probably something they consider a feature, not a bug (as ndarray once did).
          Hide
          rowen Russell Owen added a comment -

          For the record: I tried removing the special wrapper for getJacobian in ...afw/geom/python/transform.py and I still see the issue.

          Show
          rowen Russell Owen added a comment - For the record: I tried removing the special wrapper for getJacobian in ...afw/geom/python/transform.py and I still see the issue.

            People

            • Assignee:
              Unassigned
              Reporter:
              rowen Russell Owen
              Watchers:
              Jim Bosch, Krzysztof Findeisen, Russell Owen
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel