Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store the MigrationMatrix using unique_ptr in DiscreteDemography. #781

Closed
molpopgen opened this issue Jun 19, 2021 · 0 comments · Fixed by #785
Closed

Do not store the MigrationMatrix using unique_ptr in DiscreteDemography. #781

molpopgen opened this issue Jun 19, 2021 · 0 comments · Fixed by #785

Comments

@molpopgen
Copy link
Owner

This design decision was convenient when DiscreteDemography was a standalone C++ class. (The unique pointer would store nullptr for "no migration", returning None to Python.) However, it leads to complications implementing deepcopy for the demographic model.

A likely side-effect is that accessing a model's MigrationMatrix may trigger a copy in the not-None case.

Solution: store an object, not a pointer. The object can easily model the concept of "empty migration matrix" without relying on nullptr. Adding an empty() member function would suffice. Then, the Python side would return None if empty, or a reference to the object otherwise.

@molpopgen molpopgen created this issue from a note in Streamline discrete demography code (To do) Jun 19, 2021
@molpopgen molpopgen added this to the 0.16.0 milestone Jun 19, 2021
@molpopgen molpopgen linked a pull request Jun 19, 2021 that will close this issue
Streamline discrete demography code automation moved this from To do to Done Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant