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

String tools #745

Merged
merged 6 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
type ${{github.workspace}}/build/g2o/config.h

- name: Build
run: cmake --build ${{github.workspace}}/build -j 2
run: cmake --build ${{github.workspace}}/build -j 2 --config ${{matrix.config.build_type}}

- name: Test
run: |
Expand Down
2 changes: 0 additions & 2 deletions g2o/core/base_vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include <cassert>
#include <stack>

#include "creators.h"
#include "g2o/stuff/macros.h"
#include "optimizable_graph.h"

namespace g2o {
Expand Down
2 changes: 1 addition & 1 deletion g2o/core/base_vertex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
G2O_VERTEX_DIM, G2O_VERTEX_DIM) *
lambda;
double det = tempA.determinant();
if (g2o_isnan(det) || det < std::numeric_limits<double>::epsilon())
if (std::isnan(det) || det < std::numeric_limits<double>::epsilon())

Check warning on line 40 in g2o/core/base_vertex.hpp

View check run for this annotation

Codecov / codecov/patch

g2o/core/base_vertex.hpp#L40

Added line #L40 was not covered by tests
return det;
Eigen::Matrix<double, D, 1, Eigen::ColMajor> dx = tempA.llt().solve(_b);
oplus(&dx[0]);
Expand Down
9 changes: 7 additions & 2 deletions g2o/core/block_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <fstream>
#include <iomanip>

#include "g2o/core/eigen_types.h"
#include "g2o/stuff/logger.h"
#include "g2o/stuff/macros.h"
#include "g2o/stuff/misc.h"
Expand Down Expand Up @@ -530,8 +531,12 @@ bool BlockSolver<Traits>::buildSystem() {
const OptimizableGraph::Vertex* v =
static_cast<const OptimizableGraph::Vertex*>(e->vertex(i));
if (!v->fixed()) {
bool hasANan = arrayHasNaN(jacobianWorkspace.workspaceForVertex(i),
e->dimension() * v->dimension());
bool hasANan =
g2o::VectorX::MapType(jacobianWorkspace.workspaceForVertex(i),
e->dimension() * v->dimension())
.array()
.isNaN()
.any();
if (hasANan) {
G2O_WARN(
"buildSystem(): NaN within Jacobian for edge {} for vertex {}",
Expand Down
7 changes: 4 additions & 3 deletions g2o/core/optimization_algorithm_levenberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "optimization_algorithm_levenberg.h"

#include <cassert>
#include <cmath>
#include <iostream>

#include "batch_stats.h"
Expand Down Expand Up @@ -126,7 +127,7 @@ OptimizationAlgorithm::SolverResult OptimizationAlgorithmLevenberg::solve(
ok2 ? computeScale() + cst(1e-3) : 1; // make sure it's non-zero :)
rho /= scale;

if (rho > 0 && g2o_isfinite(tempChi) && ok2) { // last step was good
if (rho > 0 && std::isfinite(tempChi) && ok2) { // last step was good
double alpha = 1. - pow((2 * rho - 1), 3);
// crop lambda between minimum and maximum factors
alpha = (std::min)(alpha, _goodStepUpperScale);
Expand All @@ -139,14 +140,14 @@ OptimizationAlgorithm::SolverResult OptimizationAlgorithmLevenberg::solve(
_currentLambda *= _ni;
_ni *= 2;
_optimizer->pop(); // restore the last state before trying to optimize
if (!g2o_isfinite(_currentLambda)) break;
if (!std::isfinite(_currentLambda)) break;
}
qmax++;
} while (rho < 0 && qmax < _maxTrialsAfterFailure->value() &&
!_optimizer->terminate());

if (qmax == _maxTrialsAfterFailure->value() || rho == 0 ||
!g2o_isfinite(_currentLambda))
!std::isfinite(_currentLambda))
return Terminate;
return OK;
}
Expand Down
1 change: 0 additions & 1 deletion g2o/core/sparse_block_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <vector>

#include "g2o/config.h"
#include "g2o/stuff/misc.h"
#include "g2o/stuff/sparse_helper.h"
#include "matrix_operations.h"
#include "matrix_structure.h"
Expand Down
5 changes: 3 additions & 2 deletions g2o/core/sparse_block_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,9 @@
for (typename HashSparseColumn::const_iterator it = column.begin();
it != column.end(); ++it)
sparseRowSorted.push_back(*it);
std::sort(sparseRowSorted.begin(), sparseRowSorted.end(),
CmpPairFirst<int, MatrixType*>());
std::sort(

Check warning on line 703 in g2o/core/sparse_block_matrix.hpp

View check run for this annotation

Codecov / codecov/patch

g2o/core/sparse_block_matrix.hpp#L703

Added line #L703 was not covered by tests
sparseRowSorted.begin(), sparseRowSorted.end(),
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });

Check warning on line 705 in g2o/core/sparse_block_matrix.hpp

View check run for this annotation

Codecov / codecov/patch

g2o/core/sparse_block_matrix.hpp#L705

Added line #L705 was not covered by tests
// try to free some memory early
HashSparseColumn aux;
std::swap(aux, column);
Expand Down
19 changes: 15 additions & 4 deletions g2o/core/sparse_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,35 @@

#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <utility>

#include "batch_stats.h"
#include "estimate_propagator.h"
#include "g2o/config.h"
#include "g2o/config.h" // IWYU pragma: keep
#include "g2o/core/optimizable_graph.h"
#include "g2o/core/ownership.h"
#include "g2o/stuff/logger.h"
#include "g2o/stuff/macros.h"
#include "g2o/stuff/misc.h"
#include "g2o/stuff/timeutil.h"
#include "hyper_graph_action.h"
#include "optimization_algorithm.h"
#include "robust_kernel.h"

namespace {
/**
* tests whether there is a NaN in the array
*/
bool arrayHasNaN(const double* array, int size, int* nanIndex = 0) {
for (int i = 0; i < size; ++i)
if (std::isnan(array[i])) {
if (nanIndex) *nanIndex = i;
return true;

Check warning on line 54 in g2o/core/sparse_optimizer.cpp

View check run for this annotation

Codecov / codecov/patch

g2o/core/sparse_optimizer.cpp#L53-L54

Added lines #L53 - L54 were not covered by tests
}
return false;
}
} // namespace

namespace g2o {
using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion g2o/core/sparse_optimizer_terminate_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace g2o {

SparseOptimizerTerminateAction::SparseOptimizerTerminateAction()
: HyperGraphAction(),
_gainThreshold(cst(1e-6)),
_gainThreshold(1e-6),
_lastChi(0),
_auxTerminateFlag(false),
_maxIterations(std::numeric_limits<int>::max()) {}
Expand Down
Loading