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

New functionality in linear #1095

Merged
merged 6 commits into from
Feb 12, 2022
Merged

New functionality in linear #1095

merged 6 commits into from
Feb 12, 2022

Conversation

dellaert
Copy link
Member

@dellaert dellaert commented Feb 9, 2022

  • Added a likelihood method in GaussianConditional
  • Added an html method in VectorValues:

image

@dellaert dellaert added the quick-review Quick and easy PR to review label Feb 9, 2022
@dellaert dellaert requested a review from gchenfc February 9, 2022 23:11
@dellaert dellaert self-assigned this Feb 9, 2022
Copy link
Member

@gchenfc gchenfc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Minor comment about extra copies, but probably not that significant anyway.

newKeys.reserve(nrParents());
for (auto&& key : parents()) newKeys.push_back(key);

// Hopefully second newAb copy below is optimized out...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this comment, do you mean hopefully the compiler optimizes it out?

Because indeed I think the lines:
auto newAb = Ab_
and
return boost::make_shared<JacobianFactor>(newKeys, newAb, model_);
are both making copies.

Although I guess since the JacobianFactor constructor is copying anyway, I can't think of a functional-style way to avoid the extra copy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one is for sure, but maybe the second one is optimized out? A la RVO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't think RVO can optimize-out a copy into a function call argument, only for a return value out (i.e. shared_ptr won't have extra copy), but ofc I'm not very knowledgable here.

Though I tried making a quick mock-up:
https://godbolt.org/z/Wze8EW5x3

I think the place the copy is actually happening is the JacobianFactor constructor:

  JacobianFactor::JacobianFactor(
    const KEYS& keys, const VerticalBlockMatrix& augmentedMatrix, const SharedDiagonal& model) :
  Base(keys), Ab_(augmentedMatrix)

attention: Ab_(matrix)
The const VerticalBlockMatrix & ensures there's not a copy there, and I don't know if the standard allows introspecting that far to check to optimize-out a copy

Well in any case, I don't know the copy can be easily avoided regardless, since newAb has to get modified at some point without changing Ab_.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I think if you do Obj(m): m(std::move(m)) {} the move is guaranteed.

@dellaert dellaert merged commit 3e65779 into develop Feb 12, 2022
@dellaert dellaert deleted the feature/linear_improvements branch February 12, 2022 19:18
@dellaert
Copy link
Member Author

Thanks @ProfFan . But how do we say that we want to move this copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quick-review Quick and easy PR to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants