# C++ API changes in ip\_diffim

**URL:** <https://www.rubin.community/t/c-api-changes-in-ip-diffim/1582>\
**Category:** Data Management\
**Tags:** dm-dev\
**Created:** [January 24, 2017, 7:33pm UTC](https://www.rubin.community/t/c-api-changes-in-ip-diffim/1582 "2017-01-24T19:33:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rowen](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/rowen/32/52_2.png) [@rowen](https://www.rubin.community/u/rowen)\
**Post date:** [January 24, 2017, 7:33pm UTC](https://www.rubin.community/t/c-api-changes-in-ip-diffim/1582/1 "2017-01-24T19:33:36Z")

</div>

As part of wrapping `ip_diffim` with pybind11 on [DM-8460](https://jira.lsstcorp.org/browse/DM-8460) I changed the C++ API to longer use shared pointers to Eigen matrices and vectors, but instead pass such objects directly (e.g. by copy or reference).

Note that there is no visible difference in Python; only the C++ API is affected. Furthermore, this should only affect people editing the `ip_diffim` package because no code outside of this package calls C++ from `ip_diffim`.

The reason for this change is that the shared pointers were unnecessary and were causing problems with pybind11. Eigen is designed such that its objects can be passed directly without need of smart pointers. However, what precipitated the change was that pybind11 could not figure out how to return a Python object from a function that returned a shared pointer to an Eigen matrix. After some failed attempts to work around the problem we decided to clean up the C++ code.

At the same time I took the opportunity to make the code const safe. The existing code used `shared_ptr<Eigen::...>` in situations where shared\_ptr` should have been used. Thus it was easy to modify the internals of various objects in ways that were not intended.
