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

Add asEigenArray/Matrix returning Eigen::Map

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: ndarray

      Description

      Add ndarray::asEigenArray(array) and asEigenMatrix(array) which return Eigen::Map.

      Also make it possible (or automatic) to eliminate ndarray::Array::asEigen and ndarray::EigenView when building against a more modern version of Eigen.

      This is to help LSST upgrade Eigen, which will probably require eliminating our use of ndarray::EigenView.

        Attachments

          Issue Links

            Activity

            No builds found.
            rowen Russell Owen created issue -
            rowen Russell Owen made changes -
            Field Original Value New Value
            Epic Link DM-10068 [ 31628 ]
            rowen Russell Owen made changes -
            Link This issue relates to DM-14725 [ DM-14725 ]
            rowen Russell Owen made changes -
            Risk Score 0
            rowen Russell Owen made changes -
            Link This issue relates to RFC-479 [ RFC-479 ]
            rowen Russell Owen made changes -
            Link This issue blocks DM-14305 [ DM-14305 ]
            rowen Russell Owen made changes -
            Story Points 20 10
            rowen Russell Owen made changes -
            Component/s afw [ 10714 ]
            Component/s meas_astrom [ 10745 ]
            Component/s ndarray [ 10761 ]
            rowen Russell Owen made changes -
            Summary Change ndarray asEigen to return Eigen::Map instead of ndarray::EigenView Add asEigenArray/Matrix returning Eigen::Map
            rowen Russell Owen made changes -
            Component/s afw [ 10714 ]
            Component/s meas_astrom [ 10745 ]
            rowen Russell Owen made changes -
            Description Change {{ndarray::Array::asEigen}} to return {{Eigen::Map}} instead of {{ndarray::EigenView}} and update the DM stack accordingly.

            The primary concern is that {{EigenView}} manages its memory and {{Eigen::Map}} does not so we have to be careful not to introduce memory leaks.
            Add {{ndarray::Array::asEigenArray}} and {{asEigenMatrix}} which return {{Eigen::Map}}.

            Also make it possible (or automatic) to eliminate {{ndarray::Array::asEigen}} and {{ndarray::EigenView}} when building against a more modern version of Eigen.

            This is to help LSST upgrade Eigen, which will probably require eliminating our use of {{ndarray::EigenView}}.
            rowen Russell Owen made changes -
            Assignee Russell Owen [ rowen ] Jim Bosch [ jbosch ]
            rowen Russell Owen made changes -
            Link This issue blocks DM-14740 [ DM-14740 ]
            rowen Russell Owen made changes -
            Description Add {{ndarray::Array::asEigenArray}} and {{asEigenMatrix}} which return {{Eigen::Map}}.

            Also make it possible (or automatic) to eliminate {{ndarray::Array::asEigen}} and {{ndarray::EigenView}} when building against a more modern version of Eigen.

            This is to help LSST upgrade Eigen, which will probably require eliminating our use of {{ndarray::EigenView}}.
            Add {{ndarray::asEigenArray(array)}} and {{asEigenMatrix(array)}} which return {{Eigen::Map}}.

            Also make it possible (or automatic) to eliminate {{ndarray::Array::asEigen}} and {{ndarray::EigenView}} when building against a more modern version of Eigen.

            This is to help LSST upgrade Eigen, which will probably require eliminating our use of {{ndarray::EigenView}}.
            Hide
            rowen Russell Owen added a comment -

            Thank you for implementing this. Can you please say more about why you emulated ndarray::Array::asEigen such that asEigen(array) returns a Matrix map and ndarray::asEigen<Eigen::ArrayXpr>(array) returns an Array map.

            I had been hoping for asEigenArray and asEigenMatrix for two reasons:

            • It makes the code easier to read and more obvious (it's not clear to me why asEigen would return a Matrix instead of an Array)
            • It makes it a bit easier to spot old LSST code that needs conversion

            On the other hand if one can request more than just Matrix and Array then the flexibility may be helpful and we do have a few other asEigen functions that will confuse conversion regardless of what we call this.

            Show
            rowen Russell Owen added a comment - Thank you for implementing this. Can you please say more about why you emulated ndarray::Array::asEigen such that asEigen(array) returns a Matrix map and ndarray::asEigen<Eigen::ArrayXpr>(array) returns an Array map. I had been hoping for asEigenArray and asEigenMatrix for two reasons: It makes the code easier to read and more obvious (it's not clear to me why asEigen would return a Matrix instead of an Array) It makes it a bit easier to spot old LSST code that needs conversion On the other hand if one can request more than just Matrix and Array then the flexibility may be helpful and we do have a few other asEigen functions that will confuse conversion regardless of what we call this.
            Hide
            jbosch Jim Bosch added a comment -

            There have a been a few occasions where I've wanted to write code that works with either Array or Matrix objects, and I hate having to duplicate that code rather than just templating it.  I wouldn't object to also having asEigenMatrix and asEigenArray (or just the latter), but I'd like to keep the current new signatures, too.

            Show
            jbosch Jim Bosch added a comment - There have a been a few occasions where I've wanted to write code that works with either Array or Matrix objects, and I hate having to duplicate that code rather than just templating it.  I wouldn't object to  also having asEigenMatrix and asEigenArray (or just the latter), but I'd like to keep the current new signatures, too.
            Hide
            rowen Russell Owen added a comment -

            Fair enough. How about offering asEigenMatrix and asEigenVector specializations and removing the default for that template parameter for bare asEigen?

            I realize it's a subtle difference from the old Array::asEigen, but based on reading old code using that API I think it would improve readability and discoverability. (Also the old API is going away, at least for LSST when using newer Eigen).

            Show
            rowen Russell Owen added a comment - Fair enough. How about offering asEigenMatrix and asEigenVector specializations and removing the default for that template parameter for bare asEigen ? I realize it's a subtle difference from the old Array::asEigen, but based on reading old code using that API I think it would improve readability and discoverability. (Also the old API is going away, at least for LSST when using newer Eigen).
            Hide
            jbosch Jim Bosch added a comment -

            Russell Owen, as you're doing most of the work on this, you might as well take it back. You may also want to take a look at whether the Epic is right - either it isn't, or the Epic's description has the wrong cycle.

            Show
            jbosch Jim Bosch added a comment - Russell Owen , as you're doing most of the work on this, you might as well take it back. You may also want to take a look at whether the Epic is right - either it isn't, or the Epic's description has the wrong cycle.
            rowen Russell Owen made changes -
            Assignee Jim Bosch [ jbosch ] Russell Owen [ rowen ]
            Hide
            rowen Russell Owen added a comment - - edited

            Jim Bosch did the heavy lifting adding the free functions asEigen but suggested I take it back due to doing some of the work, so I did so.

            As to the epic: it is the one John Swinbank suggests we use. Perhaps the epic needs updating.

            Show
            rowen Russell Owen added a comment - - edited Jim Bosch did the heavy lifting adding the free functions asEigen but suggested I take it back due to doing some of the work, so I did so. As to the epic: it is the one John Swinbank suggests we use. Perhaps the epic needs updating.
            rowen Russell Owen made changes -
            Status To Do [ 10001 ] In Progress [ 3 ]
            Hide
            swinbank John Swinbank added a comment -

            (Just to be clear, I think that was a miscommunication — the correct epic for this work is DM-14447).

            Show
            swinbank John Swinbank added a comment - (Just to be clear, I think that was a miscommunication — the correct epic for this work is DM-14447 ).
            swinbank John Swinbank made changes -
            Epic Link DM-10068 [ 31628 ] DM-14447 [ 80385 ]
            rowen Russell Owen made changes -
            Link This issue mitigates DM-9677 [ DM-9677 ]
            Hide
            rowen Russell Owen added a comment -

            I updated the tarball, tweaked the build to build EigenView (since it will take a bit of work on our wrappers to switch to pybind11's Eigen header) and removed an outdated patch.

            Show
            rowen Russell Owen added a comment - I updated the tarball, tweaked the build to build EigenView (since it will take a bit of work on our wrappers to switch to pybind11's Eigen header) and removed an outdated patch.
            rowen Russell Owen made changes -
            Reviewers Jim Bosch [ jbosch ]
            Status In Progress [ 3 ] In Review [ 10004 ]
            rowen Russell Owen made changes -
            Resolution Done [ 10000 ]
            Status In Review [ 10004 ] Done [ 10002 ]

              People

              Assignee:
              rowen Russell Owen
              Reporter:
              rowen Russell Owen
              Reviewers:
              Jim Bosch
              Watchers:
              Jim Bosch, John Parejko, John Swinbank, Russell Owen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.