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

Use emplace_back for More Efficient Vector Append #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions rednose/helpers/ekf_sym.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ std::optional<Estimate> EKFSym::predict_and_update_batch(double t, int kind, std
obs.t = t;
obs.kind = kind;
obs.extra_args = extra_args;
for (Map<VectorXd> zi : z_map) {
obs.z.push_back(zi);
for (const auto &zi : z_map) {
obs.z.emplace_back(zi);
}
for (Map<MatrixXdr> Ri : R_map) {
obs.R.push_back(Ri);
for (const auto &Ri : R_map) {
obs.R.emplace_back(Ri);
}

std::optional<Estimate> res = std::make_optional(this->predict_and_update_batch(obs, augment));
Expand Down Expand Up @@ -171,12 +171,13 @@ Estimate EKFSym::predict_and_update_batch(Observation& obs, bool augment) {

// update batch
std::vector<VectorXd> y;
y.reserve(obs.z.size());
for (int i = 0; i < obs.z.size(); i++) {
assert(obs.z[i].rows() == obs.R[i].rows());
assert(obs.z[i].rows() == obs.R[i].cols());

// update state
y.push_back(this->update(obs.kind, obs.z[i], obs.R[i], obs.extra_args[i]));
y.emplace_back(this->update(obs.kind, obs.z[i], obs.R[i], obs.extra_args[i]));
}

res.xk = this->x;
Expand Down