-
Notifications
You must be signed in to change notification settings - Fork 370
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
MultiFab::deepCopy()
#3848
MultiFab::deepCopy()
#3848
Conversation
Create a copy of this MultiFab, using the same Arena.
We should use a different name, because |
I am not sure it does - they have different arguments in their signatures...?
I added the lowercase variant similar to the uppercase ( Should we add this extra |
Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
That's how C++ works. https://isocpp.org/wiki/faq/strange-inheritance#hiding-rule (We could work around it by |
Haha, ah yes I sometimes forget that fun detail :D Python has no overloading at all... unless we are in pybind11 😆
Sounds safe to me, since we do not have default parameters on the existing copies...? |
What makes me uneasy is its implication. We have so far repeatedly resisted the urge of making it too easy to create a deep copied object. The copy ctor is deleted. We have a ctor for creating an alias MultiFab, which takes a parameter
So let's have some time to think about this. Maybe we should make the function name more obvious like |
Yes, I very much sympathize where this comes from. Here, I think there is a reasonable difference: in C++, the copy constructor and copy assignment are syntactically very reasonable to delete for large containers such as MultiFab, because they can be implicitly be called and lead to surprising resource costs. This is essentially the same reason why Python does by-ref for everything by default - no implicit copies of containers ever. Contrary to copy constructors and copy assignment operators, adding a
Maybe I miss a point. Yes, we should definitely expose MultiFab a = b.copy();
a *= -1; MultiFab a = b.make_alike(); // or b.copy(/* deep= */ false)
a = 0; Let's chat about this more. I think that is a reasonable syntax and explicit once a copy is actually needed. It also uses canonical naming for deep copies, so we definitely would want this downstream in pyAMReX.
My feeling is that making it equally explicit and not more verbose/complicated to create deep copies is desirable. |
To avoid confusion with In pyAMReX, because |
Summary
Create a deep copy of this MultiFab, using the same Arena and factory.
Additional background
See AMReX-Codes/pyamrex#282
Checklist
The proposed changes: