-
Notifications
You must be signed in to change notification settings - Fork 789
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
Fix Unit3 copy assign #334
Conversation
If the basis was already cached we reset it to the cached basis of `u`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, thanks @martinvl. Just requesting one small change.
gtsam/geometry/tests/testUnit3.cpp
Outdated
@@ -484,6 +484,15 @@ TEST(Unit3, ErrorBetweenFactor) { | |||
} | |||
} | |||
|
|||
TEST(Unit3, copy_assign) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name should follow the naming convention.
Thanks! However, The current implementation of the operator makes me think it is deliberate. The reason is that your implementation probably agrees with the default copy operator, right? The current state is almost certainly my doing, but I forgot, and I neglected to comment this :-( I imagine it was to state that the cache is probably only actually populated for a specific instance, e.g., during optimization, and when copied it probably won’t be used again - so it’s wasteful to copy it. Finally, I don’t quite understand your statement about “the previous” Basis or Jacobian. The Unit3 is immutable, so the cache is either not there, or correct. Is there a bug or a problem that you’re trying to fix here? If there is, and copying the cache is desired, then the solution is probably to remove the the assign and copy implementations. But I’m somehow doubtful, given the last comment above. |
@dellaert I see your point about not making wasteful copies.
Unit3 p{1, 0.2, 0.3};
p = Unit3{-1, 2, 8}; The problem here is if Unit3 p{1, 0.2, 0.3};
p.error(p); // this triggers the computation of `B_`
p = Unit3{-1, 2, 8};
const auto err = p.error(p); // no new computation of `B_` is triggered, and `err` gets wrong value Another acceptable solution would be to simply call |
@martinvl you are right. Probably the right thing is to just delete the copy constructor and the assignment operator. I am assuming your test would fail if that does not do the right thing. Could you add a similar test for the copy constructor and then just remove both? |
Sure, will fix it first thing in the morning! |
The copy constructor cannot cause this type of issue, because in this case This is only an issue with the assignment operator, as it is the only mutable method of |
@martinvl so CI is failing because of an assignment in Manifold.h. Can you please take a look at it? |
First of all: Sorry for the delay! For some reason I didn't get a notification about the CI and totally forgot! As you say @varunagrawal, we actually need the assignment operator, so simply removing does not seem a viable option. I did some more digging, and it turns out the Therefore I suggest using my original patch, which simply fixed the issues in the non-default operators. Resetting to a6e9b02. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll merge. Thanks !
Unit3::operator=
doesn't properly handle setting the cached basis and Jacobian. IfB_
and/orH_B_
was calculated prior to callingUnit3::operator=
then they are not reset, which causes subsequent calls tobasis()
to return the previous basis and Jacobian.This PR fixes
Unit3::operator=(const Unit3& u)
so thatB_
andH_B_
are set to the cached values ofu
if they exist, and reset otherwise.This change is