diff --git a/examples/nist.cc b/examples/nist.cc index 8c91a2994..244a7f874 100644 --- a/examples/nist.cc +++ b/examples/nist.cc @@ -124,10 +124,17 @@ using Eigen::RowMajor; typedef Eigen::Matrix Vector; typedef Eigen::Matrix Matrix; +using std::ifstream; +using std::vector; +using std::string; +using std::atoi; +using std::atof; +using std::cout; + void SplitStringUsingChar(const string& full, const char delim, vector* result) { - back_insert_iterator< vector > it(*result); + std::back_insert_iterator< vector > it(*result); const char* p = full.data(); const char* end = p + full.size(); @@ -144,15 +151,15 @@ void SplitStringUsingChar(const string& full, } } -bool GetAndSplitLine(std::ifstream& ifs, std::vector* pieces) { +bool GetAndSplitLine(ifstream& ifs, vector* pieces) { pieces->clear(); char buf[256]; ifs.getline(buf, 256); - SplitStringUsingChar(std::string(buf), ' ', pieces); + SplitStringUsingChar(string(buf), ' ', pieces); return true; } -void SkipLines(std::ifstream& ifs, int num_lines) { +void SkipLines(ifstream& ifs, int num_lines) { char buf[256]; for (int i = 0; i < num_lines; ++i) { ifs.getline(buf, 256); @@ -161,23 +168,23 @@ void SkipLines(std::ifstream& ifs, int num_lines) { class NISTProblem { public: - explicit NISTProblem(const std::string& filename) { - std::ifstream ifs(filename.c_str(), std::ifstream::in); + explicit NISTProblem(const string& filename) { + ifstream ifs(filename.c_str(), ifstream::in); - std::vector pieces; + vector pieces; SkipLines(ifs, 24); GetAndSplitLine(ifs, &pieces); - const int kNumResponses = std::atoi(pieces[1].c_str()); + const int kNumResponses = atoi(pieces[1].c_str()); GetAndSplitLine(ifs, &pieces); - const int kNumPredictors = std::atoi(pieces[0].c_str()); + const int kNumPredictors = atoi(pieces[0].c_str()); GetAndSplitLine(ifs, &pieces); - const int kNumObservations = std::atoi(pieces[0].c_str()); + const int kNumObservations = atoi(pieces[0].c_str()); SkipLines(ifs, 4); GetAndSplitLine(ifs, &pieces); - const int kNumParameters = std::atoi(pieces[0].c_str()); + const int kNumParameters = atoi(pieces[0].c_str()); SkipLines(ifs, 8); // Get the first line of initial and final parameter values to @@ -193,24 +200,24 @@ class NISTProblem { // Parse the line for parameter b1. int parameter_id = 0; for (int i = 0; i < kNumTries; ++i) { - initial_parameters_(i, parameter_id) = std::atof(pieces[i + 2].c_str()); + initial_parameters_(i, parameter_id) = atof(pieces[i + 2].c_str()); } - final_parameters_(0, parameter_id) = std::atof(pieces[2 + kNumTries].c_str()); + final_parameters_(0, parameter_id) = atof(pieces[2 + kNumTries].c_str()); // Parse the remaining parameter lines. for (int parameter_id = 1; parameter_id < kNumParameters; ++parameter_id) { GetAndSplitLine(ifs, &pieces); // b2, b3, .... for (int i = 0; i < kNumTries; ++i) { - initial_parameters_(i, parameter_id) = std::atof(pieces[i + 2].c_str()); + initial_parameters_(i, parameter_id) = atof(pieces[i + 2].c_str()); } - final_parameters_(0, parameter_id) = std::atof(pieces[2 + kNumTries].c_str()); + final_parameters_(0, parameter_id) = atof(pieces[2 + kNumTries].c_str()); } // Certfied cost SkipLines(ifs, 1); GetAndSplitLine(ifs, &pieces); - certified_cost_ = std::atof(pieces[4].c_str()) / 2.0; + certified_cost_ = atof(pieces[4].c_str()) / 2.0; // Read the observations. SkipLines(ifs, 18 - kNumParameters); @@ -218,12 +225,12 @@ class NISTProblem { GetAndSplitLine(ifs, &pieces); // Response. for (int j = 0; j < kNumResponses; ++j) { - response_(i, j) = std::atof(pieces[j].c_str()); + response_(i, j) = atof(pieces[j].c_str()); } // Predictor variables. for (int j = 0; j < kNumPredictors; ++j) { - predictor_(i, j) = std::atof(pieces[j + kNumResponses].c_str()); + predictor_(i, j) = atof(pieces[j + kNumResponses].c_str()); } } } @@ -404,7 +411,7 @@ struct Nelson { }; template -int RegressionDriver(const std::string& filename, +int RegressionDriver(const string& filename, const ceres::Solver::Options& options) { NISTProblem nist_problem(FLAGS_nist_data_dir + filename); CHECK_EQ(num_residuals, nist_problem.response_size()); @@ -518,7 +525,7 @@ void SolveNISTProblems() { ceres::Solver::Options options; SetMinimizerOptions(&options); - std::cout << "Lower Difficulty\n"; + cout << "Lower Difficulty\n"; int easy_success = 0; easy_success += RegressionDriver("Misra1a.dat", options); easy_success += RegressionDriver("Chwirut1.dat", options); @@ -529,7 +536,7 @@ void SolveNISTProblems() { easy_success += RegressionDriver("DanWood.dat", options); easy_success += RegressionDriver("Misra1b.dat", options); - std::cout << "\nMedium Difficulty\n"; + cout << "\nMedium Difficulty\n"; int medium_success = 0; medium_success += RegressionDriver("Kirby2.dat", options); medium_success += RegressionDriver("Hahn1.dat", options); @@ -543,7 +550,7 @@ void SolveNISTProblems() { medium_success += RegressionDriver("Roszman1.dat", options); medium_success += RegressionDriver("ENSO.dat", options); - std::cout << "\nHigher Difficulty\n"; + cout << "\nHigher Difficulty\n"; int hard_success = 0; hard_success += RegressionDriver("MGH09.dat", options); hard_success += RegressionDriver("Thurber.dat", options); @@ -555,11 +562,11 @@ void SolveNISTProblems() { hard_success += RegressionDriver("Rat43.dat", options); hard_success += RegressionDriver("Bennett5.dat", options); - std::cout << "\n"; - std::cout << "Easy : " << easy_success << "/16\n"; - std::cout << "Medium : " << medium_success << "/22\n"; - std::cout << "Hard : " << hard_success << "/16\n"; - std::cout << "Total : " << easy_success + medium_success + hard_success << "/54\n"; + cout << "\n"; + cout << "Easy : " << easy_success << "/16\n"; + cout << "Medium : " << medium_success << "/22\n"; + cout << "Hard : " << hard_success << "/16\n"; + cout << "Total : " << easy_success + medium_success + hard_success << "/54\n"; } } // namespace examples diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h index 3f0087c78..eee7116e5 100644 --- a/include/ceres/conditioned_cost_function.h +++ b/include/ceres/conditioned_cost_function.h @@ -78,7 +78,7 @@ class CERES_EXPORT ConditionedCostFunction : public CostFunction { // functions, or not, depending on the ownership parameter. Conditioners // may be NULL, in which case the corresponding residual is not modified. ConditionedCostFunction(CostFunction* wrapped_cost_function, - const vector& conditioners, + const std::vector& conditioners, Ownership ownership); virtual ~ConditionedCostFunction(); @@ -88,7 +88,7 @@ class CERES_EXPORT ConditionedCostFunction : public CostFunction { private: internal::scoped_ptr wrapped_cost_function_; - vector conditioners_; + std::vector conditioners_; Ownership ownership_; }; diff --git a/include/ceres/cost_function.h b/include/ceres/cost_function.h index fe8fc07d2..069e57236 100644 --- a/include/ceres/cost_function.h +++ b/include/ceres/cost_function.h @@ -115,7 +115,7 @@ class CERES_EXPORT CostFunction { double* residuals, double** jacobians) const = 0; - const vector& parameter_block_sizes() const { + const std::vector& parameter_block_sizes() const { return parameter_block_sizes_; } @@ -124,7 +124,7 @@ class CERES_EXPORT CostFunction { } protected: - vector* mutable_parameter_block_sizes() { + std::vector* mutable_parameter_block_sizes() { return ¶meter_block_sizes_; } @@ -135,7 +135,7 @@ class CERES_EXPORT CostFunction { private: // Cost function signature metadata: number of inputs & their sizes, // number of outputs (residuals). - vector parameter_block_sizes_; + std::vector parameter_block_sizes_; int num_residuals_; CERES_DISALLOW_COPY_AND_ASSIGN(CostFunction); }; diff --git a/include/ceres/cost_function_to_functor.h b/include/ceres/cost_function_to_functor.h index b4a516e0a..65bc93194 100644 --- a/include/ceres/cost_function_to_functor.h +++ b/include/ceres/cost_function_to_functor.h @@ -112,20 +112,20 @@ class CostFunctionToFunctor { // This block breaks the 80 column rule to keep it somewhat readable. CHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " << N8 << ", " << N9; - const vector& parameter_block_sizes = + const std::vector& parameter_block_sizes = cost_function->parameter_block_sizes(); const int num_parameter_blocks = (N0 > 0) + (N1 > 0) + (N2 > 0) + (N3 > 0) + (N4 > 0) + @@ -677,7 +677,7 @@ class CostFunctionToFunctor { template bool EvaluateWithJets(const JetT** inputs, JetT* output) const { const int kNumParameters = N0 + N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9; - const vector& parameter_block_sizes = + const std::vector& parameter_block_sizes = cost_function_->parameter_block_sizes(); const int num_parameter_blocks = parameter_block_sizes.size(); const int num_residuals = cost_function_->num_residuals(); diff --git a/include/ceres/covariance.h b/include/ceres/covariance.h index 35fde4de0..19663409a 100644 --- a/include/ceres/covariance.h +++ b/include/ceres/covariance.h @@ -183,7 +183,7 @@ class CovarianceImpl; // Covariance::Options options; // Covariance covariance(options); // -// vector > covariance_blocks; +// std::vector > covariance_blocks; // covariance_blocks.push_back(make_pair(x, x)); // covariance_blocks.push_back(make_pair(y, y)); // covariance_blocks.push_back(make_pair(x, y)); @@ -353,7 +353,8 @@ class CERES_EXPORT Covariance { // Covariance::Options for more on the conditions under which this // function returns false. bool Compute( - const vector >& covariance_blocks, + const std::vector >& covariance_blocks, Problem* problem); // Return the block of the covariance matrix corresponding to diff --git a/include/ceres/crs_matrix.h b/include/ceres/crs_matrix.h index d2d628941..757cac377 100644 --- a/include/ceres/crs_matrix.h +++ b/include/ceres/crs_matrix.h @@ -74,9 +74,9 @@ struct CERES_EXPORT CRSMatrix { // cols = [ 1, 3, 1, 2, 3, 0, 1] // values = [10, 4, 2, -3, 2, 1, 2] - vector cols; - vector rows; - vector values; + std::vector cols; + std::vector rows; + std::vector values; }; } // namespace ceres diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index f9342cdba..810adedd5 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h @@ -120,18 +120,18 @@ class DynamicAutoDiffCostFunction : public CostFunction { 0); // Allocate scratch space for the strided evaluation. - vector > input_jets(num_parameters); - vector > output_jets(num_residuals()); + std::vector > input_jets(num_parameters); + std::vector > output_jets(num_residuals()); // Make the parameter pack that is sent to the functor (reused). - vector* > jet_parameters(num_parameter_blocks, + std::vector* > jet_parameters(num_parameter_blocks, static_cast* >(NULL)); int num_active_parameters = 0; // To handle constant parameters between non-constant parameter blocks, the // start position --- a raw parameter index --- of each contiguous block of // non-constant parameters is recorded in start_derivative_section. - vector start_derivative_section; + std::vector start_derivative_section; bool in_derivative_section = false; int parameter_cursor = 0; diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index 2b6e82602..37a1eb6d6 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h @@ -104,7 +104,7 @@ class DynamicNumericDiffCostFunction : public CostFunction { << "You must call DynamicNumericDiffCostFunction::SetNumResiduals() " << "before DynamicNumericDiffCostFunction::Evaluate()."; - const vector& block_sizes = parameter_block_sizes(); + const std::vector& block_sizes = parameter_block_sizes(); CHECK(!block_sizes.empty()) << "You must call DynamicNumericDiffCostFunction::AddParameterBlock() " << "before DynamicNumericDiffCostFunction::Evaluate()."; @@ -116,8 +116,8 @@ class DynamicNumericDiffCostFunction : public CostFunction { // Create local space for a copy of the parameters which will get mutated. int parameters_size = accumulate(block_sizes.begin(), block_sizes.end(), 0); - vector parameters_copy(parameters_size); - vector parameters_references_copy(block_sizes.size()); + std::vector parameters_copy(parameters_size); + std::vector parameters_references_copy(block_sizes.size()); parameters_references_copy[0] = ¶meters_copy[0]; for (int block = 1; block < block_sizes.size(); ++block) { parameters_references_copy[block] = parameters_references_copy[block - 1] diff --git a/include/ceres/fpclassify.h b/include/ceres/fpclassify.h index da8a4d086..c2afeabb6 100644 --- a/include/ceres/fpclassify.h +++ b/include/ceres/fpclassify.h @@ -50,7 +50,7 @@ namespace ceres { inline bool IsFinite (double x) { return _finite(x) != 0; } inline bool IsInfinite(double x) { return _finite(x) == 0 && _isnan(x) == 0; } inline bool IsNaN (double x) { return _isnan(x) != 0; } -inline bool IsNormal (double x) { +inline bool IsNormal (double x) { // NOLINT int classification = _fpclass(x); return classification == _FPCLASS_NN || classification == _FPCLASS_PN; diff --git a/include/ceres/gradient_checker.h b/include/ceres/gradient_checker.h index 79ebae5f1..72b05b678 100644 --- a/include/ceres/gradient_checker.h +++ b/include/ceres/gradient_checker.h @@ -78,10 +78,10 @@ class GradientChecker { // block. // Derivatives as computed by the cost function. - vector term_jacobians; + std::vector term_jacobians; // Derivatives as computed by finite differencing. - vector finite_difference_jacobians; + std::vector finite_difference_jacobians; // Infinity-norm of term_jacobians - finite_difference_jacobians. double error_jacobians; @@ -119,7 +119,7 @@ class GradientChecker { // Do a consistency check between the term and the template parameters. CHECK_EQ(M, term->num_residuals()); const int num_residuals = M; - const vector& block_sizes = term->parameter_block_sizes(); + const std::vector& block_sizes = term->parameter_block_sizes(); const int num_blocks = block_sizes.size(); CHECK_LE(num_blocks, 5) << "Unable to test functions that take more " diff --git a/include/ceres/gradient_problem_solver.h b/include/ceres/gradient_problem_solver.h index 6e16dd74e..0676d925f 100644 --- a/include/ceres/gradient_problem_solver.h +++ b/include/ceres/gradient_problem_solver.h @@ -261,7 +261,7 @@ class CERES_EXPORT GradientProblemSolver { // executed, then set update_state_every_iteration to true. // // The solver does NOT take ownership of these pointers. - vector callbacks; + std::vector callbacks; }; struct CERES_EXPORT Summary { @@ -292,7 +292,7 @@ class CERES_EXPORT GradientProblemSolver { double final_cost; // IterationSummary for each minimizer iteration in order. - vector iterations; + std::vector iterations; // Sum total of all time spent inside Ceres when Solve is called. double total_time_in_seconds; diff --git a/include/ceres/internal/autodiff.h b/include/ceres/internal/autodiff.h index 3a96625e3..ef05d550d 100644 --- a/include/ceres/internal/autodiff.h +++ b/include/ceres/internal/autodiff.h @@ -214,15 +214,15 @@ struct AutoDiff { // This block breaks the 80 column rule to keep it somewhat readable. DCHECK_GT(num_outputs, 0); DCHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " diff --git a/include/ceres/internal/port.h b/include/ceres/internal/port.h index e38eb713a..24eca056c 100644 --- a/include/ceres/internal/port.h +++ b/include/ceres/internal/port.h @@ -46,12 +46,6 @@ namespace ceres { -// It is unfortunate that this import of the entire standard namespace is -// necessary. The reasons are historical and won't be explained here, but -// suffice to say it is not a mistake and can't be removed without breaking -// things outside of the Ceres optimization package. -using namespace std; - // This is necessary to properly handle the case that there is a different // "string" implementation in the global namespace. using std::string; diff --git a/include/ceres/local_parameterization.h b/include/ceres/local_parameterization.h index 656c4d466..6a5a68924 100644 --- a/include/ceres/local_parameterization.h +++ b/include/ceres/local_parameterization.h @@ -173,7 +173,7 @@ class CERES_EXPORT IdentityParameterization : public LocalParameterization { class CERES_EXPORT SubsetParameterization : public LocalParameterization { public: explicit SubsetParameterization(int size, - const vector& constant_parameters); + const std::vector& constant_parameters); virtual ~SubsetParameterization() {} virtual bool Plus(const double* x, const double* delta, @@ -191,7 +191,7 @@ class CERES_EXPORT SubsetParameterization : public LocalParameterization { private: const int local_size_; - vector constancy_mask_; + std::vector constancy_mask_; }; // Plus(x, delta) = [cos(|delta|), sin(|delta|) delta / |delta|] * x diff --git a/include/ceres/ordered_groups.h b/include/ceres/ordered_groups.h index c316d712e..d42e285d8 100644 --- a/include/ceres/ordered_groups.h +++ b/include/ceres/ordered_groups.h @@ -63,7 +63,8 @@ class OrderedGroups { return false; } - typename map::const_iterator it = element_to_group_.find(element); + typename std::map::const_iterator it = + element_to_group_.find(element); if (it != element_to_group_.end()) { if (it->second == group) { // Element is already in the right group, nothing to do. @@ -107,7 +108,7 @@ class OrderedGroups { // Bulk remove elements. The return value indicates the number of // elements successfully removed. - int Remove(const vector& elements) { + int Remove(const std::vector& elements) { if (NumElements() == 0 || elements.size() == 0) { return 0; } @@ -121,14 +122,14 @@ class OrderedGroups { // Reverse the order of the groups in place. void Reverse() { - typename map >::reverse_iterator it = + typename std::map >::reverse_iterator it = group_to_elements_.rbegin(); - map > new_group_to_elements; + std::map > new_group_to_elements; new_group_to_elements[it->first] = it->second; int new_group_id = it->first + 1; for (++it; it != group_to_elements_.rend(); ++it) { - for (typename set::const_iterator element_it = it->second.begin(); + for (typename std::set::const_iterator element_it = it->second.begin(); element_it != it->second.end(); ++element_it) { element_to_group_[*element_it] = new_group_id; @@ -143,7 +144,8 @@ class OrderedGroups { // Return the group id for the element. If the element is not a // member of any group, return -1. int GroupId(const T element) const { - typename map::const_iterator it = element_to_group_.find(element); + typename std::map::const_iterator it = + element_to_group_.find(element); if (it == element_to_group_.end()) { return -1; } @@ -151,14 +153,15 @@ class OrderedGroups { } bool IsMember(const T element) const { - typename map::const_iterator it = element_to_group_.find(element); + typename std::map::const_iterator it = + element_to_group_.find(element); return (it != element_to_group_.end()); } // This function always succeeds, i.e., implicitly there exists a // group for every integer. int GroupSize(const int group) const { - typename map >::const_iterator it = + typename std::map >::const_iterator it = group_to_elements_.find(group); return (it == group_to_elements_.end()) ? 0 : it->second.size(); } @@ -180,17 +183,17 @@ class OrderedGroups { return group_to_elements_.begin()->first; } - const map >& group_to_elements() const { + const std::map >& group_to_elements() const { return group_to_elements_; } - const map& element_to_group() const { + const std::map& element_to_group() const { return element_to_group_; } private: - map > group_to_elements_; - map element_to_group_; + std::map > group_to_elements_; + std::map element_to_group_; }; // Typedef for the most commonly used version of OrderedGroups. diff --git a/include/ceres/problem.h b/include/ceres/problem.h index be2ac6c2f..fba120b0b 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h @@ -211,9 +211,10 @@ class CERES_EXPORT Problem { // problem.AddResidualBlock(new MyUnaryCostFunction(...), NULL, x1); // problem.AddResidualBlock(new MyBinaryCostFunction(...), NULL, x2, x1); // - ResidualBlockId AddResidualBlock(CostFunction* cost_function, - LossFunction* loss_function, - const vector& parameter_blocks); + ResidualBlockId AddResidualBlock( + CostFunction* cost_function, + LossFunction* loss_function, + const std::vector& parameter_blocks); // Convenience methods for adding residuals with a small number of // parameters. This is the common case. Instead of specifying the @@ -356,17 +357,17 @@ class CERES_EXPORT Problem { // Fills the passed parameter_blocks vector with pointers to the // parameter blocks currently in the problem. After this call, // parameter_block.size() == NumParameterBlocks. - void GetParameterBlocks(vector* parameter_blocks) const; + void GetParameterBlocks(std::vector* parameter_blocks) const; // Fills the passed residual_blocks vector with pointers to the // residual blocks currently in the problem. After this call, // residual_blocks.size() == NumResidualBlocks. - void GetResidualBlocks(vector* residual_blocks) const; + void GetResidualBlocks(std::vector* residual_blocks) const; // Get all the parameter blocks that depend on the given residual block. void GetParameterBlocksForResidualBlock( const ResidualBlockId residual_block, - vector* parameter_blocks) const; + std::vector* parameter_blocks) const; // Get the CostFunction for the given residual block. const CostFunction* GetCostFunctionForResidualBlock( @@ -385,7 +386,7 @@ class CERES_EXPORT Problem { // block will incur a scan of the entire Problem object. void GetResidualBlocksForParameterBlock( const double* values, - vector* residual_blocks) const; + std::vector* residual_blocks) const; // Options struct to control Problem::Evaluate. struct EvaluateOptions { @@ -408,7 +409,7 @@ class CERES_EXPORT Problem { // used to add parameter blocks to the Problem. These parameter // block should NOT point to new memory locations. Bad things will // happen otherwise. - vector parameter_blocks; + std::vector parameter_blocks; // The set of residual blocks to evaluate. This vector determines // the order in which the residuals occur, and how the rows of the @@ -418,7 +419,7 @@ class CERES_EXPORT Problem { // the order in which they were added to the problem. But, this // may change if the user removes any residual blocks from the // problem. - vector residual_blocks; + std::vector residual_blocks; // Even though the residual blocks in the problem may contain loss // functions, setting apply_loss_function to false will turn off @@ -462,8 +463,8 @@ class CERES_EXPORT Problem { // columns in the jacobian). bool Evaluate(const EvaluateOptions& options, double* cost, - vector* residuals, - vector* gradient, + std::vector* residuals, + std::vector* gradient, CRSMatrix* jacobian); private: diff --git a/include/ceres/rotation.h b/include/ceres/rotation.h index d77ce218e..b7cb32e38 100644 --- a/include/ceres/rotation.h +++ b/include/ceres/rotation.h @@ -47,6 +47,7 @@ #include #include +#include #include "glog/logging.h" namespace ceres { diff --git a/include/ceres/sized_cost_function.h b/include/ceres/sized_cost_function.h index 4f98d4eb9..0a4325bb0 100644 --- a/include/ceres/sized_cost_function.h +++ b/include/ceres/sized_cost_function.h @@ -55,15 +55,15 @@ class SizedCostFunction : public CostFunction { // This block breaks the 80 column rule to keep it somewhat readable. CHECK((!N1 && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || - ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) + ((N1 > 0) && !N2 && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || + ((N1 > 0) && (N2 > 0) && !N3 && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && !N4 && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && !N5 && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && !N6 && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && !N7 && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && !N8 && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && !N9) || // NOLINT + ((N1 > 0) && (N2 > 0) && (N3 > 0) && (N4 > 0) && (N5 > 0) && (N6 > 0) && (N7 > 0) && (N8 > 0) && (N9 > 0))) // NOLINT << "Zero block cannot precede a non-zero block. Block sizes are " << "(ignore trailing 0s): " << N0 << ", " << N1 << ", " << N2 << ", " << N3 << ", " << N4 << ", " << N5 << ", " << N6 << ", " << N7 << ", " diff --git a/include/ceres/solver.h b/include/ceres/solver.h index b2fa3aedd..dc06151a5 100644 --- a/include/ceres/solver.h +++ b/include/ceres/solver.h @@ -92,7 +92,7 @@ class CERES_EXPORT Solver { gradient_tolerance = 1e-10; parameter_tolerance = 1e-8; -#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE) && !defined(CERES_ENABLE_LGPL_CODE) +#if defined(CERES_NO_SUITESPARSE) && defined(CERES_NO_CXSPARSE) && !defined(CERES_ENABLE_LGPL_CODE) // NOLINT linear_solver_type = DENSE_QR; #else linear_solver_type = SPARSE_NORMAL_CHOLESKY; @@ -677,7 +677,7 @@ class CERES_EXPORT Solver { // List of iterations at which the minimizer should dump the trust // region problem. Useful for testing and benchmarking. If empty // (default), no problems are dumped. - vector trust_region_minimizer_iterations_to_dump; + std::vector trust_region_minimizer_iterations_to_dump; // Directory to which the problems should be written to. Should be // non-empty if trust_region_minimizer_iterations_to_dump is @@ -747,7 +747,7 @@ class CERES_EXPORT Solver { // executed, then set update_state_every_iteration to true. // // The solver does NOT take ownership of these pointers. - vector callbacks; + std::vector callbacks; }; struct CERES_EXPORT Summary { @@ -785,7 +785,7 @@ class CERES_EXPORT Solver { double fixed_cost; // IterationSummary for each minimizer iteration in order. - vector iterations; + std::vector iterations; // Number of minimizer iterations in which the step was // accepted. Unless use_non_monotonic_steps is true this is also @@ -926,7 +926,7 @@ class CERES_EXPORT Solver { // Size of the elimination groups given by the user as hints to // the linear solver. - vector linear_solver_ordering_given; + std::vector linear_solver_ordering_given; // Size of the parameter groups used by the solver when ordering // the columns of the Jacobian. This maybe different from @@ -934,7 +934,7 @@ class CERES_EXPORT Solver { // linear_solver_ordering_given blank and asked for an automatic // ordering, or if the problem contains some constant or inactive // parameter blocks. - vector linear_solver_ordering_used; + std::vector linear_solver_ordering_used; // True if the user asked for inner iterations to be used as part // of the optimization. @@ -948,7 +948,7 @@ class CERES_EXPORT Solver { // Size of the parameter groups given by the user for performing // inner iterations. - vector inner_iteration_ordering_given; + std::vector inner_iteration_ordering_given; // Size of the parameter groups given used by the solver for // performing inner iterations. This maybe different from @@ -956,7 +956,7 @@ class CERES_EXPORT Solver { // inner_iteration_ordering_given blank and asked for an automatic // ordering, or if the problem contains some constant or inactive // parameter blocks. - vector inner_iteration_ordering_used; + std::vector inner_iteration_ordering_used; // Type of the preconditioner requested by the user. PreconditionerType preconditioner_type_given; diff --git a/internal/ceres/array_utils.cc b/internal/ceres/array_utils.cc index 205ddaf27..a22eb619d 100644 --- a/internal/ceres/array_utils.cc +++ b/internal/ceres/array_utils.cc @@ -71,7 +71,7 @@ int FindInvalidValue(const int size, const double* x) { } return size; -}; +} void InvalidateArray(const int size, double* x) { if (x != NULL) { diff --git a/internal/ceres/array_utils.h b/internal/ceres/array_utils.h index 7f5694706..c11129e37 100644 --- a/internal/ceres/array_utils.h +++ b/internal/ceres/array_utils.h @@ -43,6 +43,7 @@ #ifndef CERES_INTERNAL_ARRAY_UTILS_H_ #define CERES_INTERNAL_ARRAY_UTILS_H_ +#include #include "ceres/internal/port.h" namespace ceres { diff --git a/internal/ceres/array_utils_test.cc b/internal/ceres/array_utils_test.cc index 203a301d3..fd6a4991c 100644 --- a/internal/ceres/array_utils_test.cc +++ b/internal/ceres/array_utils_test.cc @@ -38,6 +38,8 @@ namespace ceres { namespace internal { +using std::vector; + TEST(ArrayUtils, IsArrayValid) { double x[3]; x[0] = 0.0; diff --git a/internal/ceres/autodiff_local_parameterization_test.cc b/internal/ceres/autodiff_local_parameterization_test.cc index a73c6a65f..5401d8f60 100644 --- a/internal/ceres/autodiff_local_parameterization_test.cc +++ b/internal/ceres/autodiff_local_parameterization_test.cc @@ -72,7 +72,7 @@ TEST(AutoDiffLocalParameterizationTest, IdentityParameterization) { } struct ScaledPlus { - ScaledPlus(const double &scale_factor) + explicit ScaledPlus(const double &scale_factor) : scale_factor_(scale_factor) {} diff --git a/internal/ceres/block_jacobi_preconditioner.cc b/internal/ceres/block_jacobi_preconditioner.cc index 7f79a4f99..d8a728003 100644 --- a/internal/ceres/block_jacobi_preconditioner.cc +++ b/internal/ceres/block_jacobi_preconditioner.cc @@ -43,7 +43,7 @@ namespace internal { BlockJacobiPreconditioner::BlockJacobiPreconditioner( const BlockSparseMatrix& A) { const CompressedRowBlockStructure* bs = A.block_structure(); - vector blocks(bs->cols.size()); + std::vector blocks(bs->cols.size()); for (int i = 0; i < blocks.size(); ++i) { blocks[i] = bs->cols[i].size; } @@ -60,7 +60,7 @@ bool BlockJacobiPreconditioner::UpdateImpl(const BlockSparseMatrix& A, m_->SetZero(); for (int i = 0; i < bs->rows.size(); ++i) { const int row_block_size = bs->rows[i].block.size; - const vector& cells = bs->rows[i].cells; + const std::vector& cells = bs->rows[i].cells; for (int j = 0; j < cells.size(); ++j) { const int block_id = cells[j].block_id; const int col_block_size = bs->cols[block_id].size; diff --git a/internal/ceres/block_jacobian_writer.cc b/internal/ceres/block_jacobian_writer.cc index f90c350cc..085b01143 100644 --- a/internal/ceres/block_jacobian_writer.cc +++ b/internal/ceres/block_jacobian_writer.cc @@ -41,6 +41,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // Given the residual block ordering, build a lookup table to determine which @@ -163,8 +166,7 @@ SparseMatrix* BlockJacobianWriter::CreateJacobian() const { } // Construct the cells in each row. - const vector& residual_blocks = - program_->residual_blocks(); + const vector& residual_blocks = program_->residual_blocks(); int row_block_position = 0; bs->rows.resize(residual_blocks.size()); for (int i = 0; i < residual_blocks.size(); ++i) { diff --git a/internal/ceres/block_jacobian_writer.h b/internal/ceres/block_jacobian_writer.h index 140c72111..1fb52a5d8 100644 --- a/internal/ceres/block_jacobian_writer.h +++ b/internal/ceres/block_jacobian_writer.h @@ -115,10 +115,10 @@ class BlockJacobianWriter { // // which indicates that dr/dx is located at values_[0], and dr/dz is at // values_[12]. See BlockEvaluatePreparer::Prepare()'s comments about 'j'. - vector jacobian_layout_; + std::vector jacobian_layout_; // The pointers in jacobian_layout_ point directly into this vector. - vector jacobian_layout_storage_; + std::vector jacobian_layout_storage_; }; } // namespace internal diff --git a/internal/ceres/block_random_access_dense_matrix.cc b/internal/ceres/block_random_access_dense_matrix.cc index e5822792f..d8a6b331c 100644 --- a/internal/ceres/block_random_access_dense_matrix.cc +++ b/internal/ceres/block_random_access_dense_matrix.cc @@ -39,7 +39,7 @@ namespace ceres { namespace internal { BlockRandomAccessDenseMatrix::BlockRandomAccessDenseMatrix( - const vector& blocks) { + const std::vector& blocks) { const int num_blocks = blocks.size(); block_layout_.resize(num_blocks, 0); num_rows_ = 0; diff --git a/internal/ceres/block_random_access_dense_matrix.h b/internal/ceres/block_random_access_dense_matrix.h index d160fd960..7de3303a4 100644 --- a/internal/ceres/block_random_access_dense_matrix.h +++ b/internal/ceres/block_random_access_dense_matrix.h @@ -56,7 +56,7 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { public: // blocks is a vector of block sizes. The resulting matrix has // blocks.size() * blocks.size() cells. - explicit BlockRandomAccessDenseMatrix(const vector& blocks); + explicit BlockRandomAccessDenseMatrix(const std::vector& blocks); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -85,7 +85,7 @@ class BlockRandomAccessDenseMatrix : public BlockRandomAccessMatrix { private: int num_rows_; - vector block_layout_; + std::vector block_layout_; scoped_array values_; scoped_array cell_infos_; diff --git a/internal/ceres/block_random_access_dense_matrix_test.cc b/internal/ceres/block_random_access_dense_matrix_test.cc index 359eb93e1..fde0a9c58 100644 --- a/internal/ceres/block_random_access_dense_matrix_test.cc +++ b/internal/ceres/block_random_access_dense_matrix_test.cc @@ -37,7 +37,7 @@ namespace ceres { namespace internal { TEST(BlockRandomAccessDenseMatrix, GetCell) { - vector blocks; + std::vector blocks; blocks.push_back(3); blocks.push_back(4); blocks.push_back(5); @@ -69,7 +69,7 @@ TEST(BlockRandomAccessDenseMatrix, GetCell) { } TEST(BlockRandomAccessDenseMatrix, WriteCell) { - vector blocks; + std::vector blocks; blocks.push_back(3); blocks.push_back(4); blocks.push_back(5); diff --git a/internal/ceres/block_random_access_diagonal_matrix.cc b/internal/ceres/block_random_access_diagonal_matrix.cc index b7ff33184..d4ce4ad41 100644 --- a/internal/ceres/block_random_access_diagonal_matrix.cc +++ b/internal/ceres/block_random_access_diagonal_matrix.cc @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + // TODO(sameeragarwal): Drop the dependence on TripletSparseMatrix. BlockRandomAccessDiagonalMatrix::BlockRandomAccessDiagonalMatrix( diff --git a/internal/ceres/block_random_access_diagonal_matrix.h b/internal/ceres/block_random_access_diagonal_matrix.h index ea9967817..e57ed5e9c 100644 --- a/internal/ceres/block_random_access_diagonal_matrix.h +++ b/internal/ceres/block_random_access_diagonal_matrix.h @@ -52,7 +52,7 @@ namespace internal { class BlockRandomAccessDiagonalMatrix : public BlockRandomAccessMatrix { public: // blocks is an array of block sizes. - explicit BlockRandomAccessDiagonalMatrix(const vector& blocks); + explicit BlockRandomAccessDiagonalMatrix(const std::vector& blocks); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -85,8 +85,8 @@ class BlockRandomAccessDiagonalMatrix : public BlockRandomAccessMatrix { private: // row/column block sizes. - const vector blocks_; - vector layout_; + const std::vector blocks_; + std::vector layout_; // The underlying matrix object which actually stores the cells. scoped_ptr tsm_; diff --git a/internal/ceres/block_random_access_diagonal_matrix_test.cc b/internal/ceres/block_random_access_diagonal_matrix_test.cc index aa2d664e6..9308861eb 100644 --- a/internal/ceres/block_random_access_diagonal_matrix_test.cc +++ b/internal/ceres/block_random_access_diagonal_matrix_test.cc @@ -43,7 +43,7 @@ namespace internal { class BlockRandomAccessDiagonalMatrixTest : public ::testing::Test { public: void SetUp() { - vector blocks; + std::vector blocks; blocks.push_back(3); blocks.push_back(4); blocks.push_back(5); diff --git a/internal/ceres/block_random_access_sparse_matrix.cc b/internal/ceres/block_random_access_sparse_matrix.cc index c43a9b78f..f146403f9 100644 --- a/internal/ceres/block_random_access_sparse_matrix.cc +++ b/internal/ceres/block_random_access_sparse_matrix.cc @@ -44,6 +44,11 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::set; +using std::vector; + BlockRandomAccessSparseMatrix::BlockRandomAccessSparseMatrix( const vector& blocks, const set >& block_pairs) diff --git a/internal/ceres/block_random_access_sparse_matrix.h b/internal/ceres/block_random_access_sparse_matrix.h index 51b5d20cf..1b7d9c173 100644 --- a/internal/ceres/block_random_access_sparse_matrix.h +++ b/internal/ceres/block_random_access_sparse_matrix.h @@ -57,8 +57,9 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { // blocks is an array of block sizes. block_pairs is a set of // pairs to identify the non-zero cells // of this matrix. - BlockRandomAccessSparseMatrix(const vector& blocks, - const set >& block_pairs); + BlockRandomAccessSparseMatrix( + const std::vector& blocks, + const std::set >& block_pairs); // The destructor is not thread safe. It assumes that no one is // modifying any cells when the matrix is being destroyed. @@ -103,8 +104,8 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { const int64 kMaxRowBlocks; // row/column block sizes. - const vector blocks_; - vector block_positions_; + const std::vector blocks_; + std::vector block_positions_; // A mapping from to the position in // the values array of tsm_ where the block is stored. @@ -114,7 +115,7 @@ class BlockRandomAccessSparseMatrix : public BlockRandomAccessMatrix { // In order traversal of contents of the matrix. This allows us to // implement a matrix-vector which is 20% faster than using the // iterator in the Layout object instead. - vector, double*> > cell_values_; + std::vector, double*> > cell_values_; // The underlying matrix object which actually stores the cells. scoped_ptr tsm_; diff --git a/internal/ceres/block_random_access_sparse_matrix_test.cc b/internal/ceres/block_random_access_sparse_matrix_test.cc index 10a41909b..e6147dd41 100644 --- a/internal/ceres/block_random_access_sparse_matrix_test.cc +++ b/internal/ceres/block_random_access_sparse_matrix_test.cc @@ -38,6 +38,11 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::set; +using std::vector; + TEST(BlockRandomAccessSparseMatrix, GetCell) { vector blocks; blocks.push_back(3); @@ -169,7 +174,8 @@ class BlockRandomAccessSparseMatrixTest : public ::testing::Test { }; TEST_F(BlockRandomAccessSparseMatrixTest, IntPairToLongOverflow) { - CheckIntPairToLong(numeric_limits::max(), numeric_limits::max()); + CheckIntPairToLong(std::numeric_limits::max(), + std::numeric_limits::max()); } TEST_F(BlockRandomAccessSparseMatrixTest, LongToIntPair) { diff --git a/internal/ceres/block_sparse_matrix.cc b/internal/ceres/block_sparse_matrix.cc index a48726261..6aa3c0039 100644 --- a/internal/ceres/block_sparse_matrix.cc +++ b/internal/ceres/block_sparse_matrix.cc @@ -42,6 +42,8 @@ namespace ceres { namespace internal { +using std::vector; + BlockSparseMatrix::~BlockSparseMatrix() {} BlockSparseMatrix::BlockSparseMatrix( @@ -82,7 +84,7 @@ BlockSparseMatrix::BlockSparseMatrix( } void BlockSparseMatrix::SetZero() { - fill(values_.get(), values_.get() + num_nonzeros_, 0.0); + std::fill(values_.get(), values_.get() + num_nonzeros_, 0.0); } void BlockSparseMatrix::RightMultiply(const double* x, double* y) const { diff --git a/internal/ceres/block_structure.h b/internal/ceres/block_structure.h index 656716ef0..dde8f67f9 100644 --- a/internal/ceres/block_structure.h +++ b/internal/ceres/block_structure.h @@ -71,20 +71,20 @@ bool CellLessThan(const Cell& lhs, const Cell& rhs); struct CompressedList { Block block; - vector cells; + std::vector cells; }; typedef CompressedList CompressedRow; typedef CompressedList CompressedColumn; struct CompressedRowBlockStructure { - vector cols; - vector rows; + std::vector cols; + std::vector rows; }; struct CompressedColumnBlockStructure { - vector rows; - vector cols; + std::vector rows; + std::vector cols; }; } // namespace internal diff --git a/internal/ceres/callbacks.cc b/internal/ceres/callbacks.cc index 7d5ce2548..38583091e 100644 --- a/internal/ceres/callbacks.cc +++ b/internal/ceres/callbacks.cc @@ -78,27 +78,27 @@ CallbackReturnType LoggingCallback::operator()( summary.cumulative_time_in_seconds); } else if (minimizer_type == TRUST_REGION) { if (summary.iteration == 0) { - output = "iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time\n"; + output = "iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time\n"; // NOLINT } const char* kReportRowFormat = - "% 4d % 8e % 3.2e % 3.2e % 3.2e % 3.2e % 3.2e % 4d % 3.2e % 3.2e"; + "% 4d % 8e % 3.2e % 3.2e % 3.2e % 3.2e % 3.2e % 4d % 3.2e % 3.2e"; // NOLINT output += StringPrintf(kReportRowFormat, - summary.iteration, - summary.cost, - summary.cost_change, - summary.gradient_max_norm, - summary.step_norm, - summary.relative_decrease, - summary.trust_region_radius, - summary.linear_solver_iterations, - summary.iteration_time_in_seconds, - summary.cumulative_time_in_seconds); + summary.iteration, + summary.cost, + summary.cost_change, + summary.gradient_max_norm, + summary.step_norm, + summary.relative_decrease, + summary.trust_region_radius, + summary.linear_solver_iterations, + summary.iteration_time_in_seconds, + summary.cumulative_time_in_seconds); } else { LOG(FATAL) << "Unknown minimizer type."; } if (log_to_stdout_) { - cout << output << endl; + std::cout << output << std::endl; } else { VLOG(1) << output; } diff --git a/internal/ceres/canonical_views_clustering.cc b/internal/ceres/canonical_views_clustering.cc index 9bbab4b23..c629a4438 100644 --- a/internal/ceres/canonical_views_clustering.cc +++ b/internal/ceres/canonical_views_clustering.cc @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + typedef HashMap IntMap; typedef HashSet IntSet; diff --git a/internal/ceres/canonical_views_clustering.h b/internal/ceres/canonical_views_clustering.h index d3fa57258..1518ac9a2 100644 --- a/internal/ceres/canonical_views_clustering.h +++ b/internal/ceres/canonical_views_clustering.h @@ -102,7 +102,7 @@ struct CanonicalViewsClusteringOptions; void ComputeCanonicalViewsClustering( const CanonicalViewsClusteringOptions& options, const WeightedGraph& graph, - vector* centers, + std::vector* centers, HashMap* membership); struct CanonicalViewsClusteringOptions { diff --git a/internal/ceres/canonical_views_clustering_test.cc b/internal/ceres/canonical_views_clustering_test.cc index 006b2dd66..0a0e3c5a3 100644 --- a/internal/ceres/canonical_views_clustering_test.cc +++ b/internal/ceres/canonical_views_clustering_test.cc @@ -78,7 +78,7 @@ class CanonicalViewsTest : public ::testing::Test { WeightedGraph graph_; CanonicalViewsClusteringOptions options_; - vector centers_; + std::vector centers_; HashMap membership_; }; diff --git a/internal/ceres/collections_port.h b/internal/ceres/collections_port.h index 3f976b9fb..3c2385633 100644 --- a/internal/ceres/collections_port.h +++ b/internal/ceres/collections_port.h @@ -69,7 +69,6 @@ #include #include "ceres/integral_types.h" -#include "ceres/internal/port.h" // Some systems don't have access to unordered_map/unordered_set. In // that case, substitute the hash map/set with normal map/set. The diff --git a/internal/ceres/compressed_col_sparse_matrix_utils.cc b/internal/ceres/compressed_col_sparse_matrix_utils.cc index b62a6ed38..f4af098df 100644 --- a/internal/ceres/compressed_col_sparse_matrix_utils.cc +++ b/internal/ceres/compressed_col_sparse_matrix_utils.cc @@ -38,12 +38,15 @@ namespace ceres { namespace internal { -void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, - const int* scalar_cols, - const vector& row_blocks, - const vector& col_blocks, - vector* block_rows, - vector* block_cols) { +using std::vector; + +void CompressedColumnScalarMatrixToBlockMatrix( + const int* scalar_rows, + const int* scalar_cols, + const vector& row_blocks, + const vector& col_blocks, + vector* block_rows, + vector* block_cols) { CHECK_NOTNULL(block_rows)->clear(); CHECK_NOTNULL(block_cols)->clear(); const int num_row_blocks = row_blocks.size(); @@ -66,9 +69,10 @@ void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, for (int col_block = 0; col_block < num_col_blocks; ++col_block) { int column_size = 0; for (int idx = scalar_cols[c]; idx < scalar_cols[c + 1]; ++idx) { - vector::const_iterator it = lower_bound(row_block_starts.begin(), - row_block_starts.end(), - scalar_rows[idx]); + vector::const_iterator it = + std::lower_bound(row_block_starts.begin(), + row_block_starts.end(), + scalar_rows[idx]); // Since we are using lower_bound, it will return the row id // where the row block starts. For everything but the first row // of the block, where these values will be the same, we can diff --git a/internal/ceres/compressed_col_sparse_matrix_utils.h b/internal/ceres/compressed_col_sparse_matrix_utils.h index c8de2a159..e27eaa364 100644 --- a/internal/ceres/compressed_col_sparse_matrix_utils.h +++ b/internal/ceres/compressed_col_sparse_matrix_utils.h @@ -47,19 +47,21 @@ namespace internal { // and column block j, then it is expected that A contains at least // one non-zero entry corresponding to the top left entry of c_ij, // as that entry is used to detect the presence of a non-zero c_ij. -void CompressedColumnScalarMatrixToBlockMatrix(const int* scalar_rows, - const int* scalar_cols, - const vector& row_blocks, - const vector& col_blocks, - vector* block_rows, - vector* block_cols); +void CompressedColumnScalarMatrixToBlockMatrix( + const int* scalar_rows, + const int* scalar_cols, + const std::vector& row_blocks, + const std::vector& col_blocks, + std::vector* block_rows, + std::vector* block_cols); // Given a set of blocks and a permutation of these blocks, compute // the corresponding "scalar" ordering, where the scalar ordering of // size sum(blocks). -void BlockOrderingToScalarOrdering(const vector& blocks, - const vector& block_ordering, - vector* scalar_ordering); +void BlockOrderingToScalarOrdering( + const std::vector& blocks, + const std::vector& block_ordering, + std::vector* scalar_ordering); // Solve the linear system // @@ -120,7 +122,7 @@ void SolveRTRWithSparseRHS(IntegerType num_cols, const double* values, const int rhs_nonzero_index, double* solution) { - fill(solution, solution + num_cols, 0.0); + std::fill(solution, solution + num_cols, 0.0); solution[rhs_nonzero_index] = 1.0 / values[cols[rhs_nonzero_index + 1] - 1]; for (IntegerType c = rhs_nonzero_index + 1; c < num_cols; ++c) { diff --git a/internal/ceres/compressed_col_sparse_matrix_utils_test.cc b/internal/ceres/compressed_col_sparse_matrix_utils_test.cc index 3faf06ca5..5f1fd8fea 100644 --- a/internal/ceres/compressed_col_sparse_matrix_utils_test.cc +++ b/internal/ceres/compressed_col_sparse_matrix_utils_test.cc @@ -39,6 +39,8 @@ namespace ceres { namespace internal { +using std::vector; + TEST(_, BlockPermutationToScalarPermutation) { vector blocks; // Block structure @@ -133,7 +135,7 @@ TEST(_, ScalarMatrixToBlockMatrix) { TripletSparseMatrix tsm(5, 8, 18); int* rows = tsm.mutable_rows(); int* cols = tsm.mutable_cols(); - fill(tsm.mutable_values(), tsm.mutable_values() + 18, 1.0); + std::fill(tsm.mutable_values(), tsm.mutable_values() + 18, 1.0); int offset = 0; #define CERES_TEST_FILL_BLOCK(row_block_id, col_block_id) \ diff --git a/internal/ceres/compressed_row_jacobian_writer.cc b/internal/ceres/compressed_row_jacobian_writer.cc index ed8db14c9..9860b827e 100644 --- a/internal/ceres/compressed_row_jacobian_writer.cc +++ b/internal/ceres/compressed_row_jacobian_writer.cc @@ -30,6 +30,9 @@ #include "ceres/compressed_row_jacobian_writer.h" +#include +#include + #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" #include "ceres/parameter_block.h" @@ -40,6 +43,10 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::vector; + void CompressedRowJacobianWriter::PopulateJacobianRowAndColumnBlockVectors( const Program* program, CompressedRowSparseMatrix* jacobian) { const vector& parameter_blocks = @@ -214,9 +221,9 @@ void CompressedRowJacobianWriter::Write(int residual_id, double* column_block_begin = jacobian_values + jacobian_rows[residual_offset + r] + col_pos; - copy(block_row_begin, - block_row_begin + parameter_block_size, - column_block_begin); + std::copy(block_row_begin, + block_row_begin + parameter_block_size, + column_block_begin); } col_pos += parameter_block_size; } diff --git a/internal/ceres/compressed_row_jacobian_writer.h b/internal/ceres/compressed_row_jacobian_writer.h index a722a7c28..517d691b6 100644 --- a/internal/ceres/compressed_row_jacobian_writer.h +++ b/internal/ceres/compressed_row_jacobian_writer.h @@ -33,6 +33,9 @@ #ifndef CERES_INTERNAL_COMPRESSED_ROW_JACOBIAN_WRITER_H_ #define CERES_INTERNAL_COMPRESSED_ROW_JACOBIAN_WRITER_H_ +#include +#include + #include "ceres/evaluator.h" #include "ceres/scratch_evaluate_preparer.h" @@ -80,7 +83,7 @@ class CompressedRowJacobianWriter { static void GetOrderedParameterBlocks( const Program* program, int residual_id, - vector >* evaluated_jacobian_blocks); + std::vector >* evaluated_jacobian_blocks); // JacobianWriter interface. diff --git a/internal/ceres/compressed_row_sparse_matrix.cc b/internal/ceres/compressed_row_sparse_matrix.cc index 7993ed691..b036bb5a2 100644 --- a/internal/ceres/compressed_row_sparse_matrix.cc +++ b/internal/ceres/compressed_row_sparse_matrix.cc @@ -40,6 +40,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // Helper functor used by the constructor for reordering the contents @@ -155,7 +158,7 @@ CompressedRowSparseMatrix::~CompressedRowSparseMatrix() { } void CompressedRowSparseMatrix::SetZero() { - fill(values_.begin(), values_.end(), 0); + std::fill(values_.begin(), values_.end(), 0); } void CompressedRowSparseMatrix::RightMultiply(const double* x, @@ -184,7 +187,7 @@ void CompressedRowSparseMatrix::LeftMultiply(const double* x, double* y) const { void CompressedRowSparseMatrix::SquaredColumnNorm(double* x) const { CHECK_NOTNULL(x); - fill(x, x + num_cols_, 0.0); + std::fill(x, x + num_cols_, 0.0); for (int idx = 0; idx < rows_[num_rows_]; ++idx) { x[cols_[idx]] += values_[idx] * values_[idx]; } @@ -244,20 +247,24 @@ void CompressedRowSparseMatrix::AppendRows(const CompressedRowSparseMatrix& m) { } // Copy the contents of m into this matrix. - copy(m.cols(), m.cols() + m.num_nonzeros(), &cols_[num_nonzeros()]); - copy(m.values(), m.values() + m.num_nonzeros(), &values_[num_nonzeros()]); + std::copy(m.cols(), m.cols() + m.num_nonzeros(), &cols_[num_nonzeros()]); + std::copy(m.values(), + m.values() + m.num_nonzeros(), + &values_[num_nonzeros()]); rows_.resize(num_rows_ + m.num_rows() + 1); // new_rows = [rows_, m.row() + rows_[num_rows_]] - fill(rows_.begin() + num_rows_, - rows_.begin() + num_rows_ + m.num_rows() + 1, - rows_[num_rows_]); + std::fill(rows_.begin() + num_rows_, + rows_.begin() + num_rows_ + m.num_rows() + 1, + rows_[num_rows_]); for (int r = 0; r < m.num_rows() + 1; ++r) { rows_[num_rows_ + r] += m.rows()[r]; } num_rows_ += m.num_rows(); - row_blocks_.insert(row_blocks_.end(), m.row_blocks().begin(), m.row_blocks().end()); + row_blocks_.insert(row_blocks_.end(), + m.row_blocks().begin(), + m.row_blocks().end()); } void CompressedRowSparseMatrix::ToTextFile(FILE* file) const { @@ -329,7 +336,7 @@ CompressedRowSparseMatrix* CompressedRowSparseMatrix::CreateBlockDiagonalMatrix( int* rows = matrix->mutable_rows(); int* cols = matrix->mutable_cols(); double* values = matrix->mutable_values(); - fill(values, values + num_nonzeros, 0.0); + std::fill(values, values + num_nonzeros, 0.0); int idx_cursor = 0; int col_cursor = 0; @@ -481,8 +488,9 @@ CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( const CompressedRowSparseMatrix& m, vector* program) { CHECK_NOTNULL(program)->clear(); - CHECK_GT(m.num_nonzeros(), 0) << "Congratulations, " - << "you found a bug in Ceres. Please report it."; + CHECK_GT(m.num_nonzeros(), 0) + << "Congratulations, " + << "you found a bug in Ceres. Please report it."; vector product; const vector& row_blocks = m.row_blocks(); @@ -495,7 +503,9 @@ CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram( // Compute the lower triangular part of the product. for (int idx1 = m.rows()[r]; idx1 < m.rows()[r + 1]; ++idx1) { for (int idx2 = m.rows()[r]; idx2 <= idx1; ++idx2) { - product.push_back(ProductTerm(m.cols()[idx1], m.cols()[idx2], product.size())); + product.push_back(ProductTerm(m.cols()[idx1], + m.cols()[idx2], + product.size())); } } row_block_begin = row_block_end; diff --git a/internal/ceres/compressed_row_sparse_matrix.h b/internal/ceres/compressed_row_sparse_matrix.h index a0ba7eeb6..13470ce20 100644 --- a/internal/ceres/compressed_row_sparse_matrix.h +++ b/internal/ceres/compressed_row_sparse_matrix.h @@ -109,11 +109,11 @@ class CompressedRowSparseMatrix : public SparseMatrix { const int* rows() const { return &rows_[0]; } int* mutable_rows() { return &rows_[0]; } - const vector& row_blocks() const { return row_blocks_; } - vector* mutable_row_blocks() { return &row_blocks_; } + const std::vector& row_blocks() const { return row_blocks_; } + std::vector* mutable_row_blocks() { return &row_blocks_; } - const vector& col_blocks() const { return col_blocks_; } - vector* mutable_col_blocks() { return &col_blocks_; } + const std::vector& col_blocks() const { return col_blocks_; } + std::vector* mutable_col_blocks() { return &col_blocks_; } // Destructive array resizing method. void SetMaxNumNonZeros(int num_nonzeros); @@ -129,7 +129,7 @@ class CompressedRowSparseMatrix : public SparseMatrix { static CompressedRowSparseMatrix* CreateBlockDiagonalMatrix( const double* diagonal, - const vector& blocks); + const std::vector& blocks); // Compute the sparsity structure of the product m.transpose() * m // and create a CompressedRowSparseMatrix corresponding to it. @@ -147,30 +147,30 @@ class CompressedRowSparseMatrix : public SparseMatrix { // this information for each row in the row block. static CompressedRowSparseMatrix* CreateOuterProductMatrixAndProgram( const CompressedRowSparseMatrix& m, - vector* program); + std::vector* program); // Compute the values array for the expression m.transpose() * m, // where the matrix used to store the result and a program have been // created using the CreateOuterProductMatrixAndProgram function // above. static void ComputeOuterProduct(const CompressedRowSparseMatrix& m, - const vector& program, + const std::vector& program, CompressedRowSparseMatrix* result); private: int num_rows_; int num_cols_; - vector rows_; - vector cols_; - vector values_; + std::vector rows_; + std::vector cols_; + std::vector values_; // If the matrix has an underlying block structure, then it can also // carry with it row and column block sizes. This is auxilliary and // optional information for use by algorithms operating on the // matrix. The class itself does not make use of this information in // any way. - vector row_blocks_; - vector col_blocks_; + std::vector row_blocks_; + std::vector col_blocks_; CERES_DISALLOW_COPY_AND_ASSIGN(CompressedRowSparseMatrix); }; diff --git a/internal/ceres/compressed_row_sparse_matrix_test.cc b/internal/ceres/compressed_row_sparse_matrix_test.cc index 999a661a4..5a210aea5 100644 --- a/internal/ceres/compressed_row_sparse_matrix_test.cc +++ b/internal/ceres/compressed_row_sparse_matrix_test.cc @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + void CompareMatrices(const SparseMatrix* a, const SparseMatrix* b) { EXPECT_EQ(a->num_rows(), b->num_rows()); EXPECT_EQ(a->num_cols(), b->num_cols()); @@ -169,7 +171,7 @@ TEST_F(CompressedRowSparseMatrixTest, AppendAndDeleteBlockDiagonalMatrix) { scoped_array diagonal(new double[num_diagonal_rows]); for (int i = 0; i < num_diagonal_rows; ++i) { - diagonal[i] =i; + diagonal[i] = i; } vector row_and_column_blocks; @@ -384,7 +386,7 @@ TEST(CompressedRowSparseMatrix, Transpose) { cols[16] = 2; rows[5] = 17; - copy(values, values + 17, cols); + std::copy(values, values + 17, cols); scoped_ptr transpose(matrix.Transpose()); @@ -478,11 +480,11 @@ void ToDenseMatrix(const cs_di* matrix, Matrix* dense_matrix) { dense_matrix->setZero(); for (int c = 0; c < matrix->n; ++c) { - for (int idx = matrix->p[c]; idx < matrix->p[c + 1]; ++idx) { - const int r = matrix->i[idx]; - (*dense_matrix)(r, c) = matrix->x[idx]; - } - } + for (int idx = matrix->p[c]; idx < matrix->p[c + 1]; ++idx) { + const int r = matrix->i[idx]; + (*dense_matrix)(r, c) = matrix->x[idx]; + } + } } TEST(CompressedRowSparseMatrix, ComputeOuterProduct) { @@ -506,8 +508,6 @@ TEST(CompressedRowSparseMatrix, ComputeOuterProduct) { num_col_blocks < kMaxNumColBlocks; ++num_col_blocks) { for (int trial = 0; trial < kNumTrials; ++trial) { - - RandomMatrixOptions options; options.num_row_blocks = num_row_blocks; options.num_col_blocks = num_col_blocks; @@ -528,7 +528,8 @@ TEST(CompressedRowSparseMatrix, ComputeOuterProduct) { scoped_ptr matrix( CreateRandomCompressedRowSparseMatrix(options)); - cs_di cs_matrix_transpose = cxsparse.CreateSparseMatrixTransposeView(matrix.get()); + cs_di cs_matrix_transpose = + cxsparse.CreateSparseMatrixTransposeView(matrix.get()); cs_di* cs_matrix = cxsparse.TransposeMatrix(&cs_matrix_transpose); cs_di* expected_outer_product = cxsparse.MatrixMatrixMultiply(&cs_matrix_transpose, cs_matrix); @@ -555,7 +556,8 @@ TEST(CompressedRowSparseMatrix, ComputeOuterProduct) { expected_matrix.triangularView().setZero(); ToDenseMatrix(&actual_outer_product, &actual_matrix); - const double diff_norm = (actual_matrix - expected_matrix).norm() / expected_matrix.norm(); + const double diff_norm = + (actual_matrix - expected_matrix).norm() / expected_matrix.norm(); ASSERT_NEAR(diff_norm, 0.0, kTolerance) << "expected: \n" << expected_matrix diff --git a/internal/ceres/conditioned_cost_function.cc b/internal/ceres/conditioned_cost_function.cc index 7322790f7..029dd5c24 100644 --- a/internal/ceres/conditioned_cost_function.cc +++ b/internal/ceres/conditioned_cost_function.cc @@ -45,7 +45,7 @@ namespace ceres { // the one it's wrapping. ConditionedCostFunction::ConditionedCostFunction( CostFunction* wrapped_cost_function, - const vector& conditioners, + const std::vector& conditioners, Ownership ownership) : wrapped_cost_function_(wrapped_cost_function), conditioners_(conditioners), diff --git a/internal/ceres/conditioned_cost_function_test.cc b/internal/ceres/conditioned_cost_function_test.cc index 03c553f31..ad4465399 100644 --- a/internal/ceres/conditioned_cost_function_test.cc +++ b/internal/ceres/conditioned_cost_function_test.cc @@ -87,7 +87,7 @@ TEST(CostFunctionTest, ConditionedCostFunction) { identity.setIdentity(); NormalPrior* difference_cost_function = new NormalPrior(identity, v2_vector); - vector conditioners; + std::vector conditioners; for (int i = 0; i < kTestCostFunctionSize; i++) { conditioners.push_back(new LinearCostFunction(i + 2, i * 7)); } diff --git a/internal/ceres/conjugate_gradients_solver.cc b/internal/ceres/conjugate_gradients_solver.cc index 3071a0918..92e829c18 100644 --- a/internal/ceres/conjugate_gradients_solver.cc +++ b/internal/ceres/conjugate_gradients_solver.cc @@ -114,7 +114,6 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( double Q0 = -1.0 * xref.dot(bref + r); for (summary.num_iterations = 1;; ++summary.num_iterations) { - // Apply preconditioner if (per_solve_options.preconditioner != NULL) { z.setZero(); @@ -129,7 +128,7 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( summary.termination_type = LINEAR_SOLVER_FAILURE; summary.message = StringPrintf("Numerical failure. rho = r'z = %e.", rho); break; - }; + } if (summary.num_iterations == 1) { p = z; @@ -233,7 +232,7 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( } return summary; -}; +} } // namespace internal } // namespace ceres diff --git a/internal/ceres/coordinate_descent_minimizer.cc b/internal/ceres/coordinate_descent_minimizer.cc index 0d8adee7c..9f14840b0 100644 --- a/internal/ceres/coordinate_descent_minimizer.cc +++ b/internal/ceres/coordinate_descent_minimizer.cc @@ -48,11 +48,14 @@ #include "ceres/solver.h" #include "ceres/trust_region_minimizer.h" #include "ceres/trust_region_strategy.h" -#include "ceres/parameter_block_ordering.h" namespace ceres { namespace internal { +using std::map; +using std::set; +using std::vector; + CoordinateDescentMinimizer::~CoordinateDescentMinimizer() { } @@ -103,8 +106,7 @@ bool CoordinateDescentMinimizer::Init( const int num_parameter_blocks = residual_block->NumParameterBlocks(); for (int j = 0; j < num_parameter_blocks; ++j) { ParameterBlock* parameter_block = residual_block->parameter_blocks()[j]; - const map::const_iterator it = - parameter_block_index.find(parameter_block); + const map::const_iterator it = parameter_block_index.find(parameter_block); if (it != parameter_block_index.end()) { residual_blocks_[it->second].push_back(residual_block); } @@ -244,7 +246,7 @@ bool CoordinateDescentMinimizer::IsOrderingValid( // Verify that each group is an independent set map >::const_iterator it = group_to_elements.begin(); - for ( ; it != group_to_elements.end(); ++it) { + for (; it != group_to_elements.end(); ++it) { if (!program.IsParameterBlockSetIndependent(it->second)) { *message = StringPrintf("The user-provided " diff --git a/internal/ceres/coordinate_descent_minimizer.h b/internal/ceres/coordinate_descent_minimizer.h index c1f8ffcd0..7aed5d326 100644 --- a/internal/ceres/coordinate_descent_minimizer.h +++ b/internal/ceres/coordinate_descent_minimizer.h @@ -85,13 +85,13 @@ class CoordinateDescentMinimizer : public Minimizer { double* parameters, Solver::Summary* summary); - vector parameter_blocks_; - vector > residual_blocks_; + std::vector parameter_blocks_; + std::vector > residual_blocks_; // The optimization is performed in rounds. In each round all the // parameter blocks that form one independent set are optimized in // parallel. This array, marks the boundaries of the independent // sets in parameter_blocks_. - vector independent_set_offsets_; + std::vector independent_set_offsets_; Evaluator::Options evaluator_options_; }; diff --git a/internal/ceres/cost_function_to_functor_test.cc b/internal/ceres/cost_function_to_functor_test.cc index f758efe85..db29fe4de 100644 --- a/internal/ceres/cost_function_to_functor_test.cc +++ b/internal/ceres/cost_function_to_functor_test.cc @@ -35,6 +35,7 @@ namespace ceres { namespace internal { +using std::vector; const double kTolerance = 1e-18; void ExpectCostFunctionsAreEqual(const CostFunction& cost_function, @@ -109,7 +110,7 @@ void ExpectCostFunctionsAreEqual(const CostFunction& cost_function, << "jacobian : " << i << " " << jacobians[i] << " " << actual_jacobians[i]; } -}; +} struct OneParameterBlockFunctor { public: diff --git a/internal/ceres/covariance.cc b/internal/ceres/covariance.cc index 35146c582..4955f4a30 100644 --- a/internal/ceres/covariance.cc +++ b/internal/ceres/covariance.cc @@ -38,6 +38,9 @@ namespace ceres { +using std::pair; +using std::vector; + Covariance::Covariance(const Covariance::Options& options) { impl_.reset(new internal::CovarianceImpl(options)); } diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc index cbbf139b2..e5d0c445c 100644 --- a/internal/ceres/covariance_impl.cc +++ b/internal/ceres/covariance_impl.cc @@ -58,6 +58,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::map; +using std::pair; +using std::swap; +using std::vector; + typedef vector > CovarianceBlocks; CovarianceImpl::CovarianceImpl(const Covariance::Options& options) @@ -122,7 +128,7 @@ bool CovarianceImpl::GetCovarianceBlock(const double* original_parameter_block1, const double* parameter_block2 = original_parameter_block2; const bool transpose = parameter_block1 > parameter_block2; if (transpose) { - std::swap(parameter_block1, parameter_block2); + swap(parameter_block1, parameter_block2); } // Find where in the covariance matrix the block is located. @@ -242,7 +248,8 @@ bool CovarianceImpl::ComputeCovarianceSparsity( problem->GetParameterBlocks(&all_parameter_blocks); const ProblemImpl::ParameterMap& parameter_map = problem->parameter_map(); constant_parameter_blocks_.clear(); - vector& active_parameter_blocks = evaluate_options_.parameter_blocks; + vector& active_parameter_blocks = + evaluate_options_.parameter_blocks; active_parameter_blocks.clear(); for (int i = 0; i < all_parameter_blocks.size(); ++i) { double* parameter_block = all_parameter_blocks[i]; @@ -255,7 +262,7 @@ bool CovarianceImpl::ComputeCovarianceSparsity( } } - sort(active_parameter_blocks.begin(), active_parameter_blocks.end()); + std::sort(active_parameter_blocks.begin(), active_parameter_blocks.end()); // Compute the number of rows. Map each parameter block to the // first row corresponding to it in the covariance matrix using the @@ -594,8 +601,8 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingDenseSVD() { sqrt(options_.min_reciprocal_condition_number); const bool automatic_truncation = (options_.null_space_rank < 0); - const int max_rank = min(num_singular_values, - num_singular_values - options_.null_space_rank); + const int max_rank = std::min(num_singular_values, + num_singular_values - options_.null_space_rank); // Compute the squared inverse of the singular values. Truncate the // computation based on min_singular_value_ratio and @@ -672,7 +679,7 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingEigenSparseQR() { qr_solver(sparse_jacobian); event_logger.AddEvent("QRDecomposition"); - if(qr_solver.info() != Eigen::Success) { + if (qr_solver.info() != Eigen::Success) { LOG(ERROR) << "Eigen::SparseQR decomposition failed."; return false; } diff --git a/internal/ceres/covariance_impl.h b/internal/ceres/covariance_impl.h index 135f4a1d6..f2defe8c7 100644 --- a/internal/ceres/covariance_impl.h +++ b/internal/ceres/covariance_impl.h @@ -52,7 +52,8 @@ class CovarianceImpl { ~CovarianceImpl(); bool Compute( - const vector >& covariance_blocks, + const std::vector >& covariance_blocks, ProblemImpl* problem); bool GetCovarianceBlock(const double* parameter_block1, @@ -60,7 +61,8 @@ class CovarianceImpl { double* covariance_block) const; bool ComputeCovarianceSparsity( - const vector >& covariance_blocks, + const std::vector >& covariance_blocks, ProblemImpl* problem); bool ComputeCovarianceValues(); @@ -78,8 +80,8 @@ class CovarianceImpl { Problem::EvaluateOptions evaluate_options_; bool is_computed_; bool is_valid_; - map parameter_block_to_row_index_; - set constant_parameter_blocks_; + std::map parameter_block_to_row_index_; + std::set constant_parameter_blocks_; scoped_ptr covariance_matrix_; }; diff --git a/internal/ceres/covariance_test.cc b/internal/ceres/covariance_test.cc index 6c506b72d..f4fae0e30 100644 --- a/internal/ceres/covariance_test.cc +++ b/internal/ceres/covariance_test.cc @@ -43,6 +43,11 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::map; +using std::pair; +using std::vector; + TEST(CovarianceImpl, ComputeCovarianceSparsity) { double parameters[10]; @@ -247,7 +252,9 @@ class CovarianceTest : public ::testing::Test { { double jacobian = 5.0; - problem_.AddResidualBlock(new UnaryCostFunction(1, 1, &jacobian), NULL, z); + problem_.AddResidualBlock(new UnaryCostFunction(1, 1, &jacobian), + NULL, + z); } { @@ -319,9 +326,15 @@ class CovarianceTest : public ::testing::Test { const double* block1 = covariance_blocks[i].first; const double* block2 = covariance_blocks[i].second; // block1, block2 - GetCovarianceBlockAndCompare(block1, block2, covariance, expected_covariance); + GetCovarianceBlockAndCompare(block1, + block2, + covariance, + expected_covariance); // block2, block1 - GetCovarianceBlockAndCompare(block2, block1, covariance, expected_covariance); + GetCovarianceBlockAndCompare(block2, + block1, + covariance, + expected_covariance); } } } @@ -590,12 +603,12 @@ TEST_F(CovarianceTest, TruncatedRank) { // was obtained by dropping the eigenvector corresponding to this // eigenvalue. double expected_covariance[] = { - 5.4135e-02, -3.5121e-02, 1.7257e-04, 3.4514e-04, 5.1771e-04, -1.6076e-02, - -3.5121e-02, 3.8667e-02, -1.9288e-03, -3.8576e-03, -5.7864e-03, 1.2549e-02, - 1.7257e-04, -1.9288e-03, 2.3235e-01, -3.5297e-02, -5.2946e-02, -3.3329e-04, - 3.4514e-04, -3.8576e-03, -3.5297e-02, 1.7941e-01, -1.0589e-01, -6.6659e-04, - 5.1771e-04, -5.7864e-03, -5.2946e-02, -1.0589e-01, 9.1162e-02, -9.9988e-04, - -1.6076e-02, 1.2549e-02, -3.3329e-04, -6.6659e-04, -9.9988e-04, 3.9539e-02 + 5.4135e-02, -3.5121e-02, 1.7257e-04, 3.4514e-04, 5.1771e-04, -1.6076e-02, // NOLINT + -3.5121e-02, 3.8667e-02, -1.9288e-03, -3.8576e-03, -5.7864e-03, 1.2549e-02, // NOLINT + 1.7257e-04, -1.9288e-03, 2.3235e-01, -3.5297e-02, -5.2946e-02, -3.3329e-04, // NOLINT + 3.4514e-04, -3.8576e-03, -3.5297e-02, 1.7941e-01, -1.0589e-01, -6.6659e-04, // NOLINT + 5.1771e-04, -5.7864e-03, -5.2946e-02, -1.0589e-01, 9.1162e-02, -9.9988e-04, // NOLINT + -1.6076e-02, 1.2549e-02, -3.3329e-04, -6.6659e-04, -9.9988e-04, 3.9539e-02 // NOLINT }; @@ -637,7 +650,9 @@ class RankDeficientCovarianceTest : public CovarianceTest { { double jacobian = 5.0; - problem_.AddResidualBlock(new UnaryCostFunction(1, 1, &jacobian), NULL, z); + problem_.AddResidualBlock(new UnaryCostFunction(1, 1, &jacobian), + NULL, + z); } { @@ -715,7 +730,8 @@ class LargeScaleCovarianceTest : public ::testing::Test { virtual void SetUp() { num_parameter_blocks_ = 2000; parameter_block_size_ = 5; - parameters_.reset(new double[parameter_block_size_ * num_parameter_blocks_]); + parameters_.reset( + new double[parameter_block_size_ * num_parameter_blocks_]); Matrix jacobian(parameter_block_size_, parameter_block_size_); for (int i = 0; i < num_parameter_blocks_; ++i) { diff --git a/internal/ceres/cxsparse.cc b/internal/ceres/cxsparse.cc index 87503d06c..cf395187b 100644 --- a/internal/ceres/cxsparse.cc +++ b/internal/ceres/cxsparse.cc @@ -38,13 +38,14 @@ #include #include "ceres/compressed_col_sparse_matrix_utils.h" #include "ceres/compressed_row_sparse_matrix.h" -#include "ceres/internal/port.h" #include "ceres/triplet_sparse_matrix.h" #include "glog/logging.h" namespace ceres { namespace internal { +using std::vector; + CXSparse::CXSparse() : scratch_(NULL), scratch_size_(0) { } @@ -128,7 +129,7 @@ cs_dis* CXSparse::BlockAnalyzeCholesky(cs_di* A, int* ordering = cs_amd(1, &block_matrix); vector block_ordering(num_row_blocks, -1); - copy(ordering, ordering + num_row_blocks, &block_ordering[0]); + std::copy(ordering, ordering + num_row_blocks, &block_ordering[0]); cs_free(ordering); vector scalar_ordering; @@ -191,7 +192,7 @@ cs_di* CXSparse::CreateSparseMatrix(TripletSparseMatrix* tsm) { void CXSparse::ApproximateMinimumDegreeOrdering(cs_di* A, int* ordering) { int* cs_ordering = cs_amd(1, A); - copy(cs_ordering, cs_ordering + A->m, ordering); + std::copy(cs_ordering, cs_ordering + A->m, ordering); cs_free(cs_ordering); } diff --git a/internal/ceres/cxsparse.h b/internal/ceres/cxsparse.h index 5868401b9..907bc5187 100644 --- a/internal/ceres/cxsparse.h +++ b/internal/ceres/cxsparse.h @@ -107,8 +107,8 @@ class CXSparse { // The returned matrix should be deallocated with Free when not used // anymore. cs_dis* BlockAnalyzeCholesky(cs_di* A, - const vector& row_blocks, - const vector& col_blocks); + const std::vector& row_blocks, + const std::vector& col_blocks); // Compute an fill-reducing approximate minimum degree ordering of // the matrix A. ordering should be non-NULL and should point to @@ -133,8 +133,7 @@ typedef void cs_dis; class CXSparse { public: - void Free(void*) {}; - + void Free(void* arg) {} }; #endif // CERES_NO_CXSPARSE diff --git a/internal/ceres/dogleg_strategy.cc b/internal/ceres/dogleg_strategy.cc index f29376db7..a88c7e95c 100644 --- a/internal/ceres/dogleg_strategy.cc +++ b/internal/ceres/dogleg_strategy.cc @@ -120,7 +120,8 @@ TrustRegionStrategy::Summary DoglegStrategy::ComputeStep( // jacobian->SquaredColumnNorm(diagonal_.data()); for (int i = 0; i < n; ++i) { - diagonal_[i] = min(max(diagonal_[i], min_diagonal_), max_diagonal_); + diagonal_[i] = std::min(std::max(diagonal_[i], min_diagonal_), + max_diagonal_); } diagonal_ = diagonal_.array().sqrt(); @@ -618,13 +619,13 @@ void DoglegStrategy::StepAccepted(double step_quality) { } if (step_quality > increase_threshold_) { - radius_ = max(radius_, 3.0 * dogleg_step_norm_); + radius_ = std::max(radius_, 3.0 * dogleg_step_norm_); } // Reduce the regularization multiplier, in the hope that whatever // was causing the rank deficiency has gone away and we can return // to doing a pure Gauss-Newton solve. - mu_ = max(min_mu_, 2.0 * mu_ / mu_increase_factor_); + mu_ = std::max(min_mu_, 2.0 * mu_ / mu_increase_factor_); reuse_ = false; } diff --git a/internal/ceres/dogleg_strategy_test.cc b/internal/ceres/dogleg_strategy_test.cc index 795719daa..45128a531 100644 --- a/internal/ceres/dogleg_strategy_test.cc +++ b/internal/ceres/dogleg_strategy_test.cc @@ -63,12 +63,12 @@ class DoglegStrategyFixtureEllipse : public Fixture { virtual void SetUp() { Matrix basis(6, 6); // The following lines exceed 80 characters for better readability. - basis << -0.1046920933796121, -0.7449367449921986, -0.4190744502875876, -0.4480450716142566, 0.2375351607929440, -0.0363053418882862, - 0.4064975684355914, 0.2681113508511354, -0.7463625494601520, -0.0803264850508117, -0.4463149623021321, 0.0130224954867195, - -0.5514387729089798, 0.1026621026168657, -0.5008316122125011, 0.5738122212666414, 0.2974664724007106, 0.1296020877535158, - 0.5037835370947156, 0.2668479925183712, -0.1051754618492798, -0.0272739396578799, 0.7947481647088278, -0.1776623363955670, - -0.4005458426625444, 0.2939330589634109, -0.0682629380550051, -0.2895448882503687, -0.0457239396341685, -0.8139899477847840, - -0.3247764582762654, 0.4528151365941945, -0.0276683863102816, -0.6155994592510784, 0.1489240599972848, 0.5362574892189350; + basis << -0.1046920933796121, -0.7449367449921986, -0.4190744502875876, -0.4480450716142566, 0.2375351607929440, -0.0363053418882862, // NOLINT + 0.4064975684355914, 0.2681113508511354, -0.7463625494601520, -0.0803264850508117, -0.4463149623021321, 0.0130224954867195, // NOLINT + -0.5514387729089798, 0.1026621026168657, -0.5008316122125011, 0.5738122212666414, 0.2974664724007106, 0.1296020877535158, // NOLINT + 0.5037835370947156, 0.2668479925183712, -0.1051754618492798, -0.0272739396578799, 0.7947481647088278, -0.1776623363955670, // NOLINT + -0.4005458426625444, 0.2939330589634109, -0.0682629380550051, -0.2895448882503687, -0.0457239396341685, -0.8139899477847840, // NOLINT + -0.3247764582762654, 0.4528151365941945, -0.0276683863102816, -0.6155994592510784, 0.1489240599972848, 0.5362574892189350; // NOLINT Vector Ddiag(6); Ddiag << 1.0, 2.0, 4.0, 8.0, 16.0, 32.0; diff --git a/internal/ceres/dynamic_autodiff_cost_function_test.cc b/internal/ceres/dynamic_autodiff_cost_function_test.cc index 42d6ab706..4e4faf9e6 100644 --- a/internal/ceres/dynamic_autodiff_cost_function_test.cc +++ b/internal/ceres/dynamic_autodiff_cost_function_test.cc @@ -39,6 +39,8 @@ namespace ceres { namespace internal { +using std::vector; + // Takes 2 parameter blocks: // parameters[0] is size 10. // parameters[1] is size 5. @@ -212,7 +214,7 @@ TEST(DynamicAutodiffCostFunctionTest, JacobianWithFirstParameterBlockConstant) { } } -TEST(DynamicAutodiffCostFunctionTest, JacobianWithSecondParameterBlockConstant) { +TEST(DynamicAutodiffCostFunctionTest, JacobianWithSecondParameterBlockConstant) { // NOLINT // Test the residual counting. vector param_block_0(10, 0.0); for (int i = 0; i < 10; ++i) { diff --git a/internal/ceres/dynamic_compressed_row_finalizer.h b/internal/ceres/dynamic_compressed_row_finalizer.h index 5e6b0d845..70c7d63cf 100644 --- a/internal/ceres/dynamic_compressed_row_finalizer.h +++ b/internal/ceres/dynamic_compressed_row_finalizer.h @@ -48,4 +48,4 @@ struct DynamicCompressedRowJacobianFinalizer { } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESED_ROW_FINALISER_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESED_ROW_FINALISER_H_ diff --git a/internal/ceres/dynamic_compressed_row_jacobian_writer.cc b/internal/ceres/dynamic_compressed_row_jacobian_writer.cc index b46cb797f..24dfdaba0 100644 --- a/internal/ceres/dynamic_compressed_row_jacobian_writer.cc +++ b/internal/ceres/dynamic_compressed_row_jacobian_writer.cc @@ -39,6 +39,9 @@ namespace ceres { namespace internal { +using std::pair; +using std::vector; + ScratchEvaluatePreparer* DynamicCompressedRowJacobianWriter::CreateEvaluatePreparers(int num_threads) { return ScratchEvaluatePreparer::Create(*program_, num_threads); diff --git a/internal/ceres/dynamic_compressed_row_jacobian_writer.h b/internal/ceres/dynamic_compressed_row_jacobian_writer.h index df9581b14..3d7d5e6b7 100644 --- a/internal/ceres/dynamic_compressed_row_jacobian_writer.h +++ b/internal/ceres/dynamic_compressed_row_jacobian_writer.h @@ -80,4 +80,4 @@ class DynamicCompressedRowJacobianWriter { } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_JACOBIAN_WRITER_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_JACOBIAN_WRITER_H_ diff --git a/internal/ceres/dynamic_compressed_row_sparse_matrix.h b/internal/ceres/dynamic_compressed_row_sparse_matrix.h index 7a89a7086..4a2ddd665 100644 --- a/internal/ceres/dynamic_compressed_row_sparse_matrix.h +++ b/internal/ceres/dynamic_compressed_row_sparse_matrix.h @@ -41,6 +41,8 @@ #ifndef CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ #define CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ +#include + #include "ceres/compressed_row_sparse_matrix.h" namespace ceres { @@ -89,11 +91,11 @@ class DynamicCompressedRowSparseMatrix : public CompressedRowSparseMatrix { void Finalize(int num_additional_elements); private: - vector > dynamic_cols_; - vector > dynamic_values_; + std::vector > dynamic_cols_; + std::vector > dynamic_values_; }; } // namespace internal } // namespace ceres -#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ +#endif // CERES_INTERNAL_DYNAMIC_COMPRESSED_ROW_SPARSE_MATRIX_H_ diff --git a/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc b/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc index 03bfcb609..bc1de724f 100644 --- a/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc +++ b/internal/ceres/dynamic_compressed_row_sparse_matrix_test.cc @@ -32,7 +32,6 @@ #include "ceres/casts.h" #include "ceres/compressed_row_sparse_matrix.h" -#include "ceres/casts.h" #include "ceres/internal/eigen.h" #include "ceres/internal/scoped_ptr.h" #include "ceres/linear_least_squares_problems.h" @@ -42,6 +41,9 @@ namespace ceres { namespace internal { +using std::vector; +using std::copy; + class DynamicCompressedRowSparseMatrixTest : public ::testing::Test { protected: virtual void SetUp() { @@ -53,7 +55,7 @@ class DynamicCompressedRowSparseMatrixTest : public ::testing::Test { // Set this to some nonzero value to be sure. num_additional_elements = 13; - expected_num_nonzeros = num_rows * num_cols - min(num_rows, num_cols); + expected_num_nonzeros = num_rows * num_cols - std::min(num_rows, num_cols); InitialiseDenseReference(); InitialiseSparseMatrixReferences(); @@ -82,8 +84,8 @@ class DynamicCompressedRowSparseMatrixTest : public ::testing::Test { } void InitialiseSparseMatrixReferences() { - std::vector rows, cols; - std::vector values; + vector rows, cols; + vector values; for (int i = 0; i < (num_rows * num_cols); ++i) { const int r = i / num_cols, c = i % num_cols; if (r != c) { @@ -97,9 +99,9 @@ class DynamicCompressedRowSparseMatrixTest : public ::testing::Test { tsm.reset(new TripletSparseMatrix(num_rows, num_cols, expected_num_nonzeros)); - std::copy(rows.begin(), rows.end(), tsm->mutable_rows()); - std::copy(cols.begin(), cols.end(), tsm->mutable_cols()); - std::copy(values.begin(), values.end(), tsm->mutable_values()); + copy(rows.begin(), rows.end(), tsm->mutable_rows()); + copy(cols.begin(), cols.end(), tsm->mutable_cols()); + copy(values.begin(), values.end(), tsm->mutable_values()); tsm->set_num_nonzeros(values.size()); Matrix dense_from_tsm; diff --git a/internal/ceres/dynamic_numeric_diff_cost_function_test.cc b/internal/ceres/dynamic_numeric_diff_cost_function_test.cc index 19f4d8846..6d1f36272 100644 --- a/internal/ceres/dynamic_numeric_diff_cost_function_test.cc +++ b/internal/ceres/dynamic_numeric_diff_cost_function_test.cc @@ -38,6 +38,8 @@ namespace ceres { namespace internal { +using std::vector; + const double kTolerance = 1e-6; // Takes 2 parameter blocks: diff --git a/internal/ceres/evaluator.h b/internal/ceres/evaluator.h index 8fc60b878..7fec1ee82 100644 --- a/internal/ceres/evaluator.h +++ b/internal/ceres/evaluator.h @@ -95,8 +95,8 @@ class Evaluator { static bool Evaluate(Program* program, int num_threads, double* cost, - vector* residuals, - vector* gradient, + std::vector* residuals, + std::vector* gradient, CRSMatrix* jacobian); // Build and return a sparse matrix for storing and working with the Jacobian @@ -190,12 +190,12 @@ class Evaluator { // that the base class implementation does not have to worry about // life time issues. Further, these calls are not expected to be // frequent or performance sensitive. - virtual map CallStatistics() const { - return map(); + virtual std::map CallStatistics() const { + return std::map(); } - virtual map TimeStatistics() const { - return map(); + virtual std::map TimeStatistics() const { + return std::map(); } }; diff --git a/internal/ceres/evaluator_test.cc b/internal/ceres/evaluator_test.cc index c0de3fc81..ddfafd945 100644 --- a/internal/ceres/evaluator_test.cc +++ b/internal/ceres/evaluator_test.cc @@ -51,6 +51,8 @@ namespace ceres { namespace internal { +using std::vector; + // TODO(keir): Consider pushing this into a common test utils file. template diff --git a/internal/ceres/execution_summary.h b/internal/ceres/execution_summary.h index 29bdc69ec..3f684f988 100644 --- a/internal/ceres/execution_summary.h +++ b/internal/ceres/execution_summary.h @@ -56,15 +56,15 @@ class ExecutionSummary { calls_[name] += 1; } - const map& times() const { return times_; } - const map& calls() const { return calls_; } + const std::map& times() const { return times_; } + const std::map& calls() const { return calls_; } private: Mutex times_mutex_; - map times_; + std::map times_; Mutex calls_mutex_; - map calls_; + std::map calls_; }; class ScopedExecutionTimer { diff --git a/internal/ceres/gradient_checker_test.cc b/internal/ceres/gradient_checker_test.cc index fa0d841a8..aa60fdc92 100644 --- a/internal/ceres/gradient_checker_test.cc +++ b/internal/ceres/gradient_checker_test.cc @@ -44,6 +44,8 @@ namespace ceres { namespace internal { +using std::vector; + // We pick a (non-quadratic) function whose derivative are easy: // // f = exp(- a' x). diff --git a/internal/ceres/gradient_checking_cost_function.cc b/internal/ceres/gradient_checking_cost_function.cc index 3272848a4..52b649b21 100644 --- a/internal/ceres/gradient_checking_cost_function.cc +++ b/internal/ceres/gradient_checking_cost_function.cc @@ -51,6 +51,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // True if x and y have an absolute relative difference less than @@ -68,7 +71,7 @@ bool IsClose(double x, double y, double relative_precision, relative_error = &local_relative_error; } *absolute_error = fabs(x - y); - *relative_error = *absolute_error / max(fabs(x), fabs(y)); + *relative_error = *absolute_error / std::max(fabs(x), fabs(y)); if (x == 0 || y == 0) { // If x or y is exactly zero, then relative difference doesn't have any // meaning. Take the absolute difference instead. @@ -121,7 +124,8 @@ class GradientCheckingCostFunction : public CostFunction { vector term_jacobians(block_sizes.size()); vector finite_difference_jacobians(block_sizes.size()); vector term_jacobian_pointers(block_sizes.size()); - vector finite_difference_jacobian_pointers(block_sizes.size()); + vector finite_difference_jacobian_pointers( + block_sizes.size()); for (int i = 0; i < block_sizes.size(); i++) { term_jacobians[i].resize(num_residuals, block_sizes[i]); term_jacobian_pointers[i] = term_jacobians[i].data(); @@ -259,7 +263,8 @@ ProblemImpl* CreateGradientCheckingProblemImpl(ProblemImpl* problem_impl, // For every ParameterBlock in problem_impl, create a new parameter // block with the same local parameterization and constancy. - const vector& parameter_blocks = program->parameter_blocks(); + const vector& parameter_blocks = + program->parameter_blocks(); for (int i = 0; i < parameter_blocks.size(); ++i) { ParameterBlock* parameter_block = parameter_blocks[i]; gradient_checking_problem_impl->AddParameterBlock( @@ -276,7 +281,8 @@ ProblemImpl* CreateGradientCheckingProblemImpl(ProblemImpl* problem_impl, // For every ResidualBlock in problem_impl, create a new // ResidualBlock by wrapping its CostFunction inside a // GradientCheckingCostFunction. - const vector& residual_blocks = program->residual_blocks(); + const vector& residual_blocks = + program->residual_blocks(); for (int i = 0; i < residual_blocks.size(); ++i) { ResidualBlock* residual_block = residual_blocks[i]; diff --git a/internal/ceres/gradient_checking_cost_function_test.cc b/internal/ceres/gradient_checking_cost_function_test.cc index caba2f6d9..7bdc4da0e 100644 --- a/internal/ceres/gradient_checking_cost_function_test.cc +++ b/internal/ceres/gradient_checking_cost_function_test.cc @@ -48,6 +48,7 @@ #include "gmock/mock-log.h" #include "gtest/gtest.h" +using std::vector; using testing::AllOf; using testing::AnyNumber; using testing::HasSubstr; diff --git a/internal/ceres/gradient_problem_evaluator.h b/internal/ceres/gradient_problem_evaluator.h index 20053de2a..7d144e397 100644 --- a/internal/ceres/gradient_problem_evaluator.h +++ b/internal/ceres/gradient_problem_evaluator.h @@ -79,11 +79,11 @@ class GradientProblemEvaluator : public Evaluator { virtual int NumResiduals() const { return 1; } - virtual map CallStatistics() const { + virtual std::map CallStatistics() const { return execution_summary_.calls(); } - virtual map TimeStatistics() const { + virtual std::map TimeStatistics() const { return execution_summary_.times(); } diff --git a/internal/ceres/gradient_problem_solver.cc b/internal/ceres/gradient_problem_solver.cc index 4fda929f5..aea0804fd 100644 --- a/internal/ceres/gradient_problem_solver.cc +++ b/internal/ceres/gradient_problem_solver.cc @@ -155,7 +155,7 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, SetSummaryFinalCost(summary); } - const map& evaluator_time_statistics = + const std::map& evaluator_time_statistics = minimizer_options.evaluator->TimeStatistics(); summary->cost_evaluation_time_in_seconds = FindWithDefault(evaluator_time_statistics, "Evaluator::Residual", 0.0); @@ -199,7 +199,7 @@ string GradientProblemSolver::Summary::BriefReport() const { initial_cost, final_cost, TerminationTypeToString(termination_type)); -}; +} string GradientProblemSolver::Summary::FullReport() const { using internal::VersionString; @@ -263,7 +263,7 @@ string GradientProblemSolver::Summary::FullReport() const { StringAppendF(&report, "Termination: %25s (%s)\n", TerminationTypeToString(termination_type), message.c_str()); return report; -}; +} void Solve(const GradientProblemSolver::Options& options, const GradientProblem& problem, diff --git a/internal/ceres/graph.h b/internal/ceres/graph.h index f639d1532..c9d851448 100644 --- a/internal/ceres/graph.h +++ b/internal/ceres/graph.h @@ -139,9 +139,9 @@ class WeightedGraph { for (typename HashSet::const_iterator it = sinks.begin(); it != sinks.end(); ++it) { if (vertex < *it) { - edge_weights_.erase(make_pair(vertex, *it)); + edge_weights_.erase(std::make_pair(vertex, *it)); } else { - edge_weights_.erase(make_pair(*it, vertex)); + edge_weights_.erase(std::make_pair(*it, vertex)); } edges_[*it].erase(vertex); } @@ -165,9 +165,9 @@ class WeightedGraph { } if (vertex1 < vertex2) { - edge_weights_[make_pair(vertex1, vertex2)] = weight; + edge_weights_[std::make_pair(vertex1, vertex2)] = weight; } else { - edge_weights_[make_pair(vertex2, vertex1)] = weight; + edge_weights_[std::make_pair(vertex2, vertex1)] = weight; } } @@ -188,9 +188,11 @@ class WeightedGraph { // the edge weight is zero. double EdgeWeight(const Vertex& vertex1, const Vertex& vertex2) const { if (vertex1 < vertex2) { - return FindWithDefault(edge_weights_, make_pair(vertex1, vertex2), 0.0); + return FindWithDefault(edge_weights_, + std::make_pair(vertex1, vertex2), 0.0); } else { - return FindWithDefault(edge_weights_, make_pair(vertex2, vertex1), 0.0); + return FindWithDefault(edge_weights_, + std::make_pair(vertex2, vertex1), 0.0); } } @@ -206,13 +208,13 @@ class WeightedGraph { static double InvalidWeight() { return std::numeric_limits::quiet_NaN(); - }; + } private: HashSet vertices_; HashMap vertex_weights_; HashMap > edges_; - HashMap, double> edge_weights_; + HashMap, double> edge_weights_; CERES_DISALLOW_COPY_AND_ASSIGN(WeightedGraph); }; diff --git a/internal/ceres/graph_algorithms.h b/internal/ceres/graph_algorithms.h index fb75e2f45..7724f8db9 100644 --- a/internal/ceres/graph_algorithms.h +++ b/internal/ceres/graph_algorithms.h @@ -95,7 +95,7 @@ class VertexDegreeLessThan { // cardinality of S. template int IndependentSetOrdering(const Graph& graph, - vector* ordering) { + std::vector* ordering) { const HashSet& vertices = graph.vertices(); const int num_vertices = vertices.size(); @@ -110,7 +110,7 @@ int IndependentSetOrdering(const Graph& graph, // Mark all vertices white. HashMap vertex_color; - vector vertex_queue; + std::vector vertex_queue; for (typename HashSet::const_iterator it = vertices.begin(); it != vertices.end(); ++it) { @@ -119,8 +119,8 @@ int IndependentSetOrdering(const Graph& graph, } - sort(vertex_queue.begin(), vertex_queue.end(), - VertexTotalOrdering(graph)); + std::sort(vertex_queue.begin(), vertex_queue.end(), + VertexTotalOrdering(graph)); // Iterate over vertex_queue. Pick the first white vertex, add it // to the independent set. Mark it black and its neighbors grey. @@ -145,7 +145,7 @@ int IndependentSetOrdering(const Graph& graph, // Iterate over the vertices and add all the grey vertices to the // ordering. At this stage there should only be black or grey // vertices in the graph. - for (typename vector::const_iterator it = vertex_queue.begin(); + for (typename std::vector::const_iterator it = vertex_queue.begin(); it != vertex_queue.end(); ++it) { const Vertex vertex = *it; @@ -171,7 +171,7 @@ int IndependentSetOrdering(const Graph& graph, // ordering algorithm over all. template int StableIndependentSetOrdering(const Graph& graph, - vector* ordering) { + std::vector* ordering) { CHECK_NOTNULL(ordering); const HashSet& vertices = graph.vertices(); const int num_vertices = vertices.size(); @@ -182,10 +182,10 @@ int StableIndependentSetOrdering(const Graph& graph, const char kGrey = 1; const char kBlack = 2; - vector vertex_queue(*ordering); + std::vector vertex_queue(*ordering); - stable_sort(vertex_queue.begin(), vertex_queue.end(), - VertexDegreeLessThan(graph)); + std::stable_sort(vertex_queue.begin(), vertex_queue.end(), + VertexDegreeLessThan(graph)); // Mark all vertices white. HashMap vertex_color; @@ -220,7 +220,7 @@ int StableIndependentSetOrdering(const Graph& graph, // Iterate over the vertices and add all the grey vertices to the // ordering. At this stage there should only be black or grey // vertices in the graph. - for (typename vector::const_iterator it = vertex_queue.begin(); + for (typename std::vector::const_iterator it = vertex_queue.begin(); it != vertex_queue.end(); ++it) { const Vertex vertex = *it; @@ -274,7 +274,7 @@ template WeightedGraph* Degree2MaximumSpanningForest(const WeightedGraph& graph) { // Array of edges sorted in decreasing order of their weights. - vector > > weighted_edges; + std::vector > > weighted_edges; WeightedGraph* forest = new WeightedGraph(); // Disjoint-set to keep track of the connected components in the @@ -302,19 +302,20 @@ Degree2MaximumSpanningForest(const WeightedGraph& graph) { continue; } const double weight = graph.EdgeWeight(vertex1, vertex2); - weighted_edges.push_back(make_pair(weight, make_pair(vertex1, vertex2))); + weighted_edges.push_back( + std::make_pair(weight, std::make_pair(vertex1, vertex2))); } } // The elements of this vector, are pairs. Sorting it using the reverse iterators gives us the edges // in decreasing order of edges. - sort(weighted_edges.rbegin(), weighted_edges.rend()); + std::sort(weighted_edges.rbegin(), weighted_edges.rend()); // Greedily add edges to the spanning tree/forest as long as they do // not violate the degree/cycle constraint. for (int i =0; i < weighted_edges.size(); ++i) { - const pair& edge = weighted_edges[i].second; + const std::pair& edge = weighted_edges[i].second; const Vertex vertex1 = edge.first; const Vertex vertex2 = edge.second; @@ -350,7 +351,7 @@ Degree2MaximumSpanningForest(const WeightedGraph& graph) { // lookup. if (root2 < root1) { std::swap(root1, root2); - }; + } disjoint_set[root2] = root1; } diff --git a/internal/ceres/graph_algorithms_test.cc b/internal/ceres/graph_algorithms_test.cc index bbb1e0d7b..61b9646c7 100644 --- a/internal/ceres/graph_algorithms_test.cc +++ b/internal/ceres/graph_algorithms_test.cc @@ -40,6 +40,8 @@ namespace ceres { namespace internal { +using std::vector; + TEST(IndependentSetOrdering, Chain) { Graph graph; graph.AddVertex(0); @@ -238,7 +240,7 @@ TEST(StableIndependentSet, BreakTies) { EXPECT_EQ(independent_set_size, 1); EXPECT_EQ(ordering[0], 1); } - } + } // namespace internal } // namespace ceres diff --git a/internal/ceres/implicit_schur_complement.h b/internal/ceres/implicit_schur_complement.h index c992bdc20..99b67af1f 100644 --- a/internal/ceres/implicit_schur_complement.h +++ b/internal/ceres/implicit_schur_complement.h @@ -97,7 +97,7 @@ class ImplicitSchurComplement : public LinearOperator { // // TODO(sameeragarwal): Get rid of the two bools below and replace // them with enums. - ImplicitSchurComplement(const LinearSolver::Options& options); + explicit ImplicitSchurComplement(const LinearSolver::Options& options); virtual ~ImplicitSchurComplement(); // Initialize the Schur complement for a linear least squares diff --git a/internal/ceres/implicit_schur_complement_test.cc b/internal/ceres/implicit_schur_complement_test.cc index 3369ecb82..8b40da496 100644 --- a/internal/ceres/implicit_schur_complement_test.cc +++ b/internal/ceres/implicit_schur_complement_test.cc @@ -74,7 +74,7 @@ class ImplicitSchurComplementTest : public ::testing::Test { Vector* solution) { const CompressedRowBlockStructure* bs = A_->block_structure(); const int num_col_blocks = bs->cols.size(); - vector blocks(num_col_blocks - num_eliminate_blocks_, 0); + std::vector blocks(num_col_blocks - num_eliminate_blocks_, 0); for (int i = num_eliminate_blocks_; i < num_col_blocks; ++i) { blocks[i - num_eliminate_blocks_] = bs->cols[i].size; } diff --git a/internal/ceres/lapack.cc b/internal/ceres/lapack.cc index e124d7570..a3d9980c8 100644 --- a/internal/ceres/lapack.cc +++ b/internal/ceres/lapack.cc @@ -110,7 +110,7 @@ LinearSolverTerminationType LAPACK::SolveInPlaceUsingCholesky( *message = "Success"; return LINEAR_SOLVER_SUCCESS; #endif -}; +} int LAPACK::EstimateWorkSizeForQR(int num_rows, int num_cols) { #ifdef CERES_NO_LAPACK diff --git a/internal/ceres/levenberg_marquardt_strategy.cc b/internal/ceres/levenberg_marquardt_strategy.cc index ce3b69a80..e47ef48bc 100644 --- a/internal/ceres/levenberg_marquardt_strategy.cc +++ b/internal/ceres/levenberg_marquardt_strategy.cc @@ -79,7 +79,8 @@ TrustRegionStrategy::Summary LevenbergMarquardtStrategy::ComputeStep( jacobian->SquaredColumnNorm(diagonal_.data()); for (int i = 0; i < num_parameters; ++i) { - diagonal_[i] = min(max(diagonal_[i], min_diagonal_), max_diagonal_); + diagonal_[i] = std::min(std::max(diagonal_[i], min_diagonal_), + max_diagonal_); } } diff --git a/internal/ceres/line_search.cc b/internal/ceres/line_search.cc index 8c2624e16..d9343c93e 100644 --- a/internal/ceres/line_search.cc +++ b/internal/ceres/line_search.cc @@ -44,6 +44,11 @@ namespace ceres { namespace internal { + +using std::map; +using std::ostream; +using std::vector; + namespace { // Precision used for floating point values in error message output. const int kErrorMessageNumericPrecision = 8; @@ -54,7 +59,7 @@ FunctionSample ValueSample(const double x, const double value) { sample.value = value; sample.value_is_valid = true; return sample; -}; +} FunctionSample ValueAndGradientSample(const double x, const double value, @@ -66,15 +71,15 @@ FunctionSample ValueAndGradientSample(const double x, sample.value_is_valid = true; sample.gradient_is_valid = true; return sample; -}; +} } // namespace -std::ostream& operator<<(std::ostream &os, const FunctionSample& sample); +ostream& operator<<(ostream &os, const FunctionSample& sample); // Convenience stream operator for pushing FunctionSamples into log messages. -std::ostream& operator<<(std::ostream &os, const FunctionSample& sample) { +ostream& operator<<(ostream &os, const FunctionSample& sample) { os << sample.ToDebugString(); return os; } @@ -208,7 +213,7 @@ double LineSearch::InterpolatingPolynomialMinimizingStepSize( max_step_size <= current.x)) { // Either: sample is invalid; or we are using BISECTION and contracting // the step size. - return min(max(current.x * 0.5, min_step_size), max_step_size); + return std::min(std::max(current.x * 0.5, min_step_size), max_step_size); } else if (interpolation_type == BISECTION) { CHECK_GT(max_step_size, current.x); // We are expanding the search (during a Wolfe bracketing phase) using diff --git a/internal/ceres/line_search_direction.cc b/internal/ceres/line_search_direction.cc index dddcecdb1..2d86c22d0 100644 --- a/internal/ceres/line_search_direction.cc +++ b/internal/ceres/line_search_direction.cc @@ -86,7 +86,7 @@ class NonlinearConjugateGradient : public LineSearchDirection { LOG(WARNING) << "Restarting non-linear conjugate gradients: " << directional_derivative; *search_direction = -current.gradient; - }; + } return true; } diff --git a/internal/ceres/line_search_minimizer.cc b/internal/ceres/line_search_minimizer.cc index d36545df0..85cc0315f 100644 --- a/internal/ceres/line_search_minimizer.cc +++ b/internal/ceres/line_search_minimizer.cc @@ -290,9 +290,9 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, // iteration. const double initial_step_size = (iteration_summary.iteration == 1 || !line_search_status) - ? min(1.0, 1.0 / current_state.gradient_max_norm) - : min(1.0, 2.0 * (current_state.cost - previous_state.cost) / - current_state.directional_derivative); + ? std::min(1.0, 1.0 / current_state.gradient_max_norm) + : std::min(1.0, 2.0 * (current_state.cost - previous_state.cost) / + current_state.directional_derivative); // By definition, we should only ever go forwards along the specified search // direction in a line search, most likely cause for this being violated // would be a numerical failure in the line search direction calculation. diff --git a/internal/ceres/linear_least_squares_problems.cc b/internal/ceres/linear_least_squares_problems.cc index 24ba565da..b6a6a8c98 100644 --- a/internal/ceres/linear_least_squares_problems.cc +++ b/internal/ceres/linear_least_squares_problems.cc @@ -97,11 +97,11 @@ LinearLeastSquaresProblem* LinearLeastSquaresProblem0() { int counter = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j< 2; ++j) { - Ai[counter]=i; - Aj[counter]=j; + Ai[counter] = i; + Aj[counter] = j; ++counter; } - }; + } Ax[0] = 1.; Ax[1] = 2.; @@ -527,7 +527,7 @@ bool DumpLinearLeastSquaresProblemToConsole(const SparseMatrix* A, LOG(INFO) << "x: \n" << ConstVectorRef(x, A->num_cols()); } return true; -}; +} void WriteArrayToFileOrDie(const string& filename, const double* x, @@ -619,7 +619,7 @@ bool DumpLinearLeastSquaresProblem(const string& filename_base, num_eliminate_blocks); default: LOG(FATAL) << "Unknown DumpFormatType " << dump_format_type; - }; + } return true; } diff --git a/internal/ceres/linear_solver.h b/internal/ceres/linear_solver.h index 5f59765f0..14f171c82 100644 --- a/internal/ceres/linear_solver.h +++ b/internal/ceres/linear_solver.h @@ -144,7 +144,7 @@ class LinearSolver { // elimination group must form an independent set in the normal // equations. The first elimination group corresponds to the // num_eliminate_blocks in the Schur type solvers. - vector elimination_groups; + std::vector elimination_groups; // Iterative solvers, e.g. Preconditioned Conjugate Gradients // maintain a cheap estimate of the residual which may become @@ -296,12 +296,12 @@ class LinearSolver { // that the base class implementation does not have to worry about // life time issues. Further, these calls are not expected to be // frequent or performance sensitive. - virtual map CallStatistics() const { - return map(); + virtual std::map CallStatistics() const { + return std::map(); } - virtual map TimeStatistics() const { - return map(); + virtual std::map TimeStatistics() const { + return std::map(); } // Factory @@ -331,11 +331,11 @@ class TypedLinearSolver : public LinearSolver { return SolveImpl(down_cast(A), b, per_solve_options, x); } - virtual map CallStatistics() const { + virtual std::map CallStatistics() const { return execution_summary_.calls(); } - virtual map TimeStatistics() const { + virtual std::map TimeStatistics() const { return execution_summary_.times(); } diff --git a/internal/ceres/local_parameterization.cc b/internal/ceres/local_parameterization.cc index a4832c574..3d2e9d6b2 100644 --- a/internal/ceres/local_parameterization.cc +++ b/internal/ceres/local_parameterization.cc @@ -36,6 +36,8 @@ namespace ceres { +using std::vector; + LocalParameterization::~LocalParameterization() { } diff --git a/internal/ceres/local_parameterization_test.cc b/internal/ceres/local_parameterization_test.cc index 6e7e87b46..6d52e4f63 100644 --- a/internal/ceres/local_parameterization_test.cc +++ b/internal/ceres/local_parameterization_test.cc @@ -71,7 +71,7 @@ TEST(IdentityParameterization, EverythingTest) { } TEST(SubsetParameterization, DeathTests) { - vector constant_parameters; + std::vector constant_parameters; EXPECT_DEATH_IF_SUPPORTED( SubsetParameterization parameterization(1, constant_parameters), "at least"); @@ -98,7 +98,7 @@ TEST(SubsetParameterization, NormalFunctionTest) { double x[kGlobalSize] = {1.0, 2.0, 3.0, 4.0}; for (int i = 0; i < kGlobalSize; ++i) { - vector constant_parameters; + std::vector constant_parameters; constant_parameters.push_back(i); SubsetParameterization parameterization(kGlobalSize, constant_parameters); double delta[kLocalSize] = {1.0, 2.0, 3.0}; @@ -146,7 +146,7 @@ TEST(SubsetParameterization, NormalFunctionTest) { Matrix expected_local_matrix = global_matrix * MatrixRef(jacobian, kGlobalSize, kLocalSize); EXPECT_EQ((local_matrix - expected_local_matrix).norm(), 0.0); - }; + } } // Functor needed to implement automatically differentiated Plus for diff --git a/internal/ceres/low_rank_inverse_hessian.cc b/internal/ceres/low_rank_inverse_hessian.cc index 4816e3c20..3a20c9b8c 100644 --- a/internal/ceres/low_rank_inverse_hessian.cc +++ b/internal/ceres/low_rank_inverse_hessian.cc @@ -37,6 +37,8 @@ namespace ceres { namespace internal { +using std::list; + // The (L)BFGS algorithm explicitly requires that the secant equation: // // B_{k+1} * s_k = y_k @@ -126,7 +128,7 @@ void LowRankInverseHessian::RightMultiply(const double* x_ptr, const int num_corrections = indices_.size(); Vector alpha(num_corrections); - for (std::list::const_reverse_iterator it = indices_.rbegin(); + for (list::const_reverse_iterator it = indices_.rbegin(); it != indices_.rend(); ++it) { const double alpha_i = delta_x_history_.col(*it).dot(search_direction) / @@ -173,7 +175,7 @@ void LowRankInverseHessian::RightMultiply(const double* x_ptr, << "approximation."; } - for (std::list::const_iterator it = indices_.begin(); + for (list::const_iterator it = indices_.begin(); it != indices_.end(); ++it) { const double beta = delta_gradient_history_.col(*it).dot(search_direction) / diff --git a/internal/ceres/map_util.h b/internal/ceres/map_util.h index 929c6b369..9ba81e5bf 100644 --- a/internal/ceres/map_util.h +++ b/internal/ceres/map_util.h @@ -87,8 +87,8 @@ bool InsertIfNotPresent( Collection * const collection, const typename Collection::value_type::first_type& key, const typename Collection::value_type::second_type& value) { - pair ret = - collection->insert(typename Collection::value_type(key, value)); + std::pair ret = + collection->insert(typename Collection::value_type(key, value)); return ret.second; } diff --git a/internal/ceres/minimizer.cc b/internal/ceres/minimizer.cc index 558921b84..50fbef704 100644 --- a/internal/ceres/minimizer.cc +++ b/internal/ceres/minimizer.cc @@ -68,7 +68,8 @@ bool Minimizer::RunCallbacks(const Minimizer::Options& options, return true; case SOLVER_TERMINATE_SUCCESSFULLY: summary->termination_type = USER_SUCCESS; - summary->message = "User callback returned SOLVER_TERMINATE_SUCCESSFULLY."; + summary->message = + "User callback returned SOLVER_TERMINATE_SUCCESSFULLY."; VLOG_IF(1, is_not_silent) << "Terminating: " << summary->message; return false; case SOLVER_ABORT: diff --git a/internal/ceres/minimizer.h b/internal/ceres/minimizer.h index dabf07e58..24c8e676e 100644 --- a/internal/ceres/minimizer.h +++ b/internal/ceres/minimizer.h @@ -132,7 +132,7 @@ class Minimizer { bool jacobi_scaling; bool use_nonmonotonic_steps; int max_consecutive_nonmonotonic_steps; - vector trust_region_minimizer_iterations_to_dump; + std::vector trust_region_minimizer_iterations_to_dump; DumpFormatType trust_region_problem_dump_format_type; string trust_region_problem_dump_directory; int max_num_consecutive_invalid_steps; @@ -163,7 +163,7 @@ class Minimizer { // of each iteration. // // The Options struct does not own these pointers. - vector callbacks; + std::vector callbacks; // Object responsible for evaluating the cost, residuals and // Jacobian matrix. diff --git a/internal/ceres/ordered_groups_test.cc b/internal/ceres/ordered_groups_test.cc index 9e16c1d5b..09569e1f4 100644 --- a/internal/ceres/ordered_groups_test.cc +++ b/internal/ceres/ordered_groups_test.cc @@ -166,7 +166,7 @@ TEST(OrderedGroups, BulkRemove) { ordering.AddElementToGroup(x + 1, 2); ordering.AddElementToGroup(x + 2, 2); - vector elements_to_remove; + std::vector elements_to_remove; elements_to_remove.push_back(x); elements_to_remove.push_back(x + 2); @@ -181,7 +181,7 @@ TEST(OrderedGroups, BulkRemoveWithNoElements) { ParameterBlockOrdering ordering; double x[3]; - vector elements_to_remove; + std::vector elements_to_remove; elements_to_remove.push_back(x); elements_to_remove.push_back(x + 2); diff --git a/internal/ceres/parameter_block.h b/internal/ceres/parameter_block.h index 7bc823d4e..1ef86731b 100644 --- a/internal/ceres/parameter_block.h +++ b/internal/ceres/parameter_block.h @@ -193,7 +193,7 @@ class ParameterBlock { } upper_bounds_[index] = upper_bound; - }; + } void SetLowerBound(int index, double lower_bound) { CHECK_LT(index, size_); diff --git a/internal/ceres/parameter_block_ordering.cc b/internal/ceres/parameter_block_ordering.cc index 1525de90d..2df698847 100644 --- a/internal/ceres/parameter_block_ordering.cc +++ b/internal/ceres/parameter_block_ordering.cc @@ -43,6 +43,10 @@ namespace ceres { namespace internal { +using std::map; +using std::set; +using std::vector; + int ComputeStableSchurOrdering(const Program& program, vector* ordering) { CHECK_NOTNULL(ordering)->clear(); diff --git a/internal/ceres/parameter_block_ordering.h b/internal/ceres/parameter_block_ordering.h index 5de995111..5a923e9df 100644 --- a/internal/ceres/parameter_block_ordering.h +++ b/internal/ceres/parameter_block_ordering.h @@ -56,13 +56,13 @@ class ParameterBlock; // complement of the independent set, // fixed blocks] int ComputeSchurOrdering(const Program& program, - vector* ordering); + std::vector* ordering); // Same as above, except that ties while computing the independent set // ordering are resolved in favour of the order in which the parameter // blocks occur in the program. int ComputeStableSchurOrdering(const Program& program, - vector* ordering); + std::vector* ordering); // Use an approximate independent set ordering to decompose the // parameter blocks of a problem in a sequence of independent @@ -81,7 +81,7 @@ Graph* CreateHessianGraph(const Program& program); // Iterate over each of the groups in order of their priority and fill // summary with their sizes. void OrderingToGroupSizes(const ParameterBlockOrdering* ordering, - vector* group_sizes); + std::vector* group_sizes); } // namespace internal } // namespace ceres diff --git a/internal/ceres/parameter_block_ordering_test.cc b/internal/ceres/parameter_block_ordering_test.cc index bc497d0f7..dfc7b20a5 100644 --- a/internal/ceres/parameter_block_ordering_test.cc +++ b/internal/ceres/parameter_block_ordering_test.cc @@ -45,6 +45,8 @@ namespace ceres { namespace internal { +using std::vector; + typedef Graph HessianGraph; typedef HashSet VertexSet; @@ -82,7 +84,8 @@ class SchurOrderingTest : public ::testing::Test { TEST_F(SchurOrderingTest, NoFixed) { const Program& program = problem_.program(); - const vector& parameter_blocks = program.parameter_blocks(); + const vector& parameter_blocks = + program.parameter_blocks(); scoped_ptr graph(CreateHessianGraph(program)); const VertexSet& vertices = graph->vertices(); @@ -136,7 +139,8 @@ TEST_F(SchurOrderingTest, OneFixed) { problem_.SetParameterBlockConstant(x_); const Program& program = problem_.program(); - const vector& parameter_blocks = program.parameter_blocks(); + const vector& parameter_blocks = + program.parameter_blocks(); scoped_ptr graph(CreateHessianGraph(program)); const VertexSet& vertices = graph->vertices(); diff --git a/internal/ceres/parameter_block_test.cc b/internal/ceres/parameter_block_test.cc index 5a2db3c67..f01e0ad7f 100644 --- a/internal/ceres/parameter_block_test.cc +++ b/internal/ceres/parameter_block_test.cc @@ -41,7 +41,7 @@ TEST(ParameterBlock, SetLocalParameterization) { ParameterBlock parameter_block(x, 3, -1); // The indices to set constant within the parameter block (used later). - vector indices; + std::vector indices; indices.push_back(1); // Can't set the parameterization if the sizes don't match. diff --git a/internal/ceres/partitioned_matrix_view_impl.h b/internal/ceres/partitioned_matrix_view_impl.h index ae7f776e6..ff041b9d0 100644 --- a/internal/ceres/partitioned_matrix_view_impl.h +++ b/internal/ceres/partitioned_matrix_view_impl.h @@ -61,7 +61,7 @@ PartitionedMatrixView( // explicit_schur_complement_solver.h num_row_blocks_e_ = 0; for (int r = 0; r < bs->rows.size(); ++r) { - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; if (cells[0].block_id < num_col_blocks_e_) { ++num_row_blocks_e_; } @@ -131,7 +131,7 @@ RightMultiplyF(const double* x, double* y) const { for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -146,7 +146,7 @@ RightMultiplyF(const double* x, double* y) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -197,7 +197,7 @@ LeftMultiplyF(const double* x, double* y) const { for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -212,7 +212,7 @@ LeftMultiplyF(const double* x, double* y) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_pos = bs->rows[r].block.position; const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_pos = bs->cols[col_block_id].position; @@ -339,7 +339,7 @@ UpdateBlockDiagonalFtF(BlockSparseMatrix* block_diagonal) const { const double* values = matrix_.values(); for (int r = 0; r < num_row_blocks_e_; ++r) { const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 1; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_size = bs->cols[col_block_id].size; @@ -358,7 +358,7 @@ UpdateBlockDiagonalFtF(BlockSparseMatrix* block_diagonal) const { for (int r = num_row_blocks_e_; r < bs->rows.size(); ++r) { const int row_block_size = bs->rows[r].block.size; - const vector& cells = bs->rows[r].cells; + const std::vector& cells = bs->rows[r].cells; for (int c = 0; c < cells.size(); ++c) { const int col_block_id = cells[c].block_id; const int col_block_size = bs->cols[col_block_id].size; diff --git a/internal/ceres/polynomial.cc b/internal/ceres/polynomial.cc index 75f43de40..848fbee8e 100644 --- a/internal/ceres/polynomial.cc +++ b/internal/ceres/polynomial.cc @@ -42,6 +42,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // Balancing function as described by B. N. Parlett and C. Reinsch, diff --git a/internal/ceres/polynomial.h b/internal/ceres/polynomial.h index 80ce77e6a..aaa44019c 100644 --- a/internal/ceres/polynomial.h +++ b/internal/ceres/polynomial.h @@ -32,6 +32,7 @@ #ifndef CERES_INTERNAL_POLYNOMIAL_SOLVER_H_ #define CERES_INTERNAL_POLYNOMIAL_SOLVER_H_ +#include #include #include "ceres/internal/eigen.h" #include "ceres/internal/port.h" @@ -115,7 +116,7 @@ struct FunctionSample { // Of course its possible to sample a polynomial any number of times, // in which case, generally speaking the spurious higher order // coefficients will be zero. -Vector FindInterpolatingPolynomial(const vector& samples); +Vector FindInterpolatingPolynomial(const std::vector& samples); // Interpolate the function described by samples with a polynomial, // and minimize it on the interval [x_min, x_max]. Depending on the @@ -123,7 +124,7 @@ Vector FindInterpolatingPolynomial(const vector& samples); // finding algorithms may fail due to numerical difficulties. But the // function is guaranteed to return its best guess of an answer, by // considering the samples and the end points as possible solutions. -void MinimizeInterpolatingPolynomial(const vector& samples, +void MinimizeInterpolatingPolynomial(const std::vector& samples, double x_min, double x_max, double* optimal_x, diff --git a/internal/ceres/polynomial_test.cc b/internal/ceres/polynomial_test.cc index 333997361..de111f6f0 100644 --- a/internal/ceres/polynomial_test.cc +++ b/internal/ceres/polynomial_test.cc @@ -40,6 +40,9 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { // For IEEE-754 doubles, machine precision is about 2e-16. diff --git a/internal/ceres/preconditioner.h b/internal/ceres/preconditioner.h index e8d599426..5db5356f8 100644 --- a/internal/ceres/preconditioner.h +++ b/internal/ceres/preconditioner.h @@ -80,7 +80,7 @@ class Preconditioner : public LinearOperator { // elimination group must form an independent set in the normal // equations. The first elimination group corresponds to the // num_eliminate_blocks in the Schur type solvers. - vector elimination_groups; + std::vector elimination_groups; // If the block sizes in a BlockSparseMatrix are fixed, then in // some cases the Schur complement based solvers can detect and diff --git a/internal/ceres/preprocessor.h b/internal/ceres/preprocessor.h index b4ca5b117..5269eeb3f 100644 --- a/internal/ceres/preprocessor.h +++ b/internal/ceres/preprocessor.h @@ -31,6 +31,9 @@ #ifndef CERES_INTERNAL_PREPROCESSOR_H_ #define CERES_INTERNAL_PREPROCESSOR_H_ +#include +#include + #include "ceres/coordinate_descent_minimizer.h" #include "ceres/evaluator.h" #include "ceres/internal/eigen.h" @@ -65,7 +68,7 @@ struct PreprocessedProblem; // The output of the Preprocessor is stored in a PreprocessedProblem // object. class Preprocessor { -public: + public: // Factory. static Preprocessor* Create(MinimizerType minimizer_type); virtual ~Preprocessor(); @@ -97,7 +100,7 @@ struct PreprocessedProblem { shared_ptr evaluator; shared_ptr inner_iteration_minimizer; - vector removed_parameter_blocks; + std::vector removed_parameter_blocks; Vector reduced_parameters; double fixed_cost; }; diff --git a/internal/ceres/problem.cc b/internal/ceres/problem.cc index bbfaa9876..5f914bc6f 100644 --- a/internal/ceres/problem.cc +++ b/internal/ceres/problem.cc @@ -37,6 +37,8 @@ namespace ceres { +using std::vector; + Problem::Problem() : problem_impl_(new internal::ProblemImpl) {} Problem::Problem(const Problem::Options& options) : problem_impl_(new internal::ProblemImpl(options)) {} @@ -225,11 +227,11 @@ int Problem::NumResiduals() const { int Problem::ParameterBlockSize(const double* parameter_block) const { return problem_impl_->ParameterBlockSize(parameter_block); -}; +} int Problem::ParameterBlockLocalSize(const double* parameter_block) const { return problem_impl_->ParameterBlockLocalSize(parameter_block); -}; +} bool Problem::HasParameterBlock(const double* values) const { return problem_impl_->HasParameterBlock(values); diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc index 67cac94d6..a36324885 100644 --- a/internal/ceres/problem_impl.cc +++ b/internal/ceres/problem_impl.cc @@ -55,7 +55,10 @@ namespace ceres { namespace internal { -typedef map ParameterMap; +using std::vector; +using std::map; + +typedef std::map ParameterMap; namespace { internal::ParameterBlock* FindParameterBlockOrDie( @@ -784,12 +787,12 @@ int ProblemImpl::NumResiduals() const { int ProblemImpl::ParameterBlockSize(const double* parameter_block) const { return FindParameterBlockOrDie(parameter_block_map_, const_cast(parameter_block))->Size(); -}; +} int ProblemImpl::ParameterBlockLocalSize(const double* parameter_block) const { return FindParameterBlockOrDie( parameter_block_map_, const_cast(parameter_block))->LocalSize(); -}; +} bool ProblemImpl::HasParameterBlock(const double* parameter_block) const { return (parameter_block_map_.find(const_cast(parameter_block)) != diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h index 3d84de83c..f527d157c 100644 --- a/internal/ceres/problem_impl.h +++ b/internal/ceres/problem_impl.h @@ -63,7 +63,7 @@ class ResidualBlock; class ProblemImpl { public: - typedef map ParameterMap; + typedef std::map ParameterMap; typedef HashSet ResidualBlockSet; ProblemImpl(); @@ -72,9 +72,10 @@ class ProblemImpl { ~ProblemImpl(); // See the public problem.h file for description of these methods. - ResidualBlockId AddResidualBlock(CostFunction* cost_function, - LossFunction* loss_function, - const vector& parameter_blocks); + ResidualBlockId AddResidualBlock( + CostFunction* cost_function, + LossFunction* loss_function, + const std::vector& parameter_blocks); ResidualBlockId AddResidualBlock(CostFunction* cost_function, LossFunction* loss_function, double* x0); @@ -136,8 +137,8 @@ class ProblemImpl { bool Evaluate(const Problem::EvaluateOptions& options, double* cost, - vector* residuals, - vector* gradient, + std::vector* residuals, + std::vector* gradient, CRSMatrix* jacobian); int NumParameterBlocks() const; @@ -150,12 +151,12 @@ class ProblemImpl { bool HasParameterBlock(const double* parameter_block) const; - void GetParameterBlocks(vector* parameter_blocks) const; - void GetResidualBlocks(vector* residual_blocks) const; + void GetParameterBlocks(std::vector* parameter_blocks) const; + void GetResidualBlocks(std::vector* residual_blocks) const; void GetParameterBlocksForResidualBlock( const ResidualBlockId residual_block, - vector* parameter_blocks) const; + std::vector* parameter_blocks) const; const CostFunction* GetCostFunctionForResidualBlock( const ResidualBlockId residual_block) const; @@ -164,7 +165,7 @@ class ProblemImpl { void GetResidualBlocksForParameterBlock( const double* values, - vector* residual_blocks) const; + std::vector* residual_blocks) const; const Program& program() const { return *program_; } Program* mutable_program() { return program_.get(); } @@ -182,15 +183,15 @@ class ProblemImpl { bool InternalEvaluate(Program* program, double* cost, - vector* residuals, - vector* gradient, + std::vector* residuals, + std::vector* gradient, CRSMatrix* jacobian); // Delete the arguments in question. These differ from the Remove* functions // in that they do not clean up references to the block to delete; they // merely delete them. template - void DeleteBlockInVector(vector* mutable_blocks, + void DeleteBlockInVector(std::vector* mutable_blocks, Block* block_to_remove); void DeleteBlock(ResidualBlock* residual_block); void DeleteBlock(ParameterBlock* parameter_block); @@ -198,7 +199,7 @@ class ProblemImpl { const Problem::Options options_; // The mapping from user pointers to parameter blocks. - map parameter_block_map_; + std::map parameter_block_map_; // Iff enable_fast_removal is enabled, contains the current residual blocks. ResidualBlockSet residual_block_set_; @@ -212,9 +213,9 @@ class ProblemImpl { // residual or parameter blocks, buffer them until destruction. // // TODO(keir): See if it makes sense to use sets instead. - vector cost_functions_to_delete_; - vector loss_functions_to_delete_; - vector local_parameterizations_to_delete_; + std::vector cost_functions_to_delete_; + std::vector loss_functions_to_delete_; + std::vector local_parameterizations_to_delete_; CERES_DISALLOW_COPY_AND_ASSIGN(ProblemImpl); }; diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc index 36e4996fb..7f8c1589d 100644 --- a/internal/ceres/problem_test.cc +++ b/internal/ceres/problem_test.cc @@ -35,7 +35,7 @@ #include "ceres/casts.h" #include "ceres/cost_function.h" #include "ceres/crs_matrix.h" -#include "ceres/evaluator_test_utils.cc" +#include "ceres/evaluator_test_utils.h" #include "ceres/internal/eigen.h" #include "ceres/internal/scoped_ptr.h" #include "ceres/local_parameterization.h" @@ -51,6 +51,8 @@ namespace ceres { namespace internal { +using std::vector; + // The following three classes are for the purposes of defining // function signatures. They have dummy Evaluate functions. diff --git a/internal/ceres/program.cc b/internal/ceres/program.cc index 1d0a1573e..77bc63ad6 100644 --- a/internal/ceres/program.cc +++ b/internal/ceres/program.cc @@ -50,6 +50,9 @@ namespace ceres { namespace internal { +using std::set; +using std::vector; + Program::Program() {} Program::Program(const Program& program) @@ -261,9 +264,10 @@ bool Program::IsFeasible(string* message) const { return true; } -Program* Program::CreateReducedProgram(vector* removed_parameter_blocks, - double* fixed_cost, - string* error) const { +Program* Program::CreateReducedProgram( + vector* removed_parameter_blocks, + double* fixed_cost, + string* error) const { CHECK_NOTNULL(removed_parameter_blocks); CHECK_NOTNULL(fixed_cost); CHECK_NOTNULL(error); @@ -279,9 +283,10 @@ Program* Program::CreateReducedProgram(vector* removed_parameter_blocks return reduced_program.release(); } -bool Program::RemoveFixedBlocks(vector* removed_parameter_blocks, - double* fixed_cost, - string* error) { +bool Program::RemoveFixedBlocks( + vector* removed_parameter_blocks, + double* fixed_cost, + string* error) { CHECK_NOTNULL(removed_parameter_blocks); CHECK_NOTNULL(fixed_cost); CHECK_NOTNULL(error); @@ -342,7 +347,8 @@ bool Program::RemoveFixedBlocks(vector* removed_parameter_blocks, for (int i = 0; i < parameter_blocks_.size(); ++i) { ParameterBlock* parameter_block = parameter_blocks_[i]; if (parameter_block->index() == -1) { - removed_parameter_blocks->push_back(parameter_block->mutable_user_state()); + removed_parameter_blocks->push_back( + parameter_block->mutable_user_state()); } else { parameter_blocks_[num_active_parameter_blocks++] = parameter_block; } @@ -360,14 +366,14 @@ bool Program::RemoveFixedBlocks(vector* removed_parameter_blocks, return true; } -bool Program::IsParameterBlockSetIndependent(const set& independent_set) const { +bool Program::IsParameterBlockSetIndependent( + const set& independent_set) const { // Loop over each residual block and ensure that no two parameter // blocks in the same residual block are part of // parameter_block_ptrs as that would violate the assumption that it // is an independent set in the Hessian matrix. - for (vector::const_iterator it = residual_blocks_.begin(); - it != residual_blocks_.end(); - ++it) { + vector::const_iterator it = residual_blocks_.begin(); + for (; it != residual_blocks_.end(); ++it) { ParameterBlock* const* parameter_blocks = (*it)->parameter_blocks(); const int num_parameter_blocks = (*it)->NumParameterBlocks(); int count = 0; @@ -462,8 +468,8 @@ int Program::MaxScratchDoublesNeededForEvaluate() const { int max_scratch_bytes_for_evaluate = 0; for (int i = 0; i < residual_blocks_.size(); ++i) { max_scratch_bytes_for_evaluate = - max(max_scratch_bytes_for_evaluate, - residual_blocks_[i]->NumScratchDoublesForEvaluate()); + std::max(max_scratch_bytes_for_evaluate, + residual_blocks_[i]->NumScratchDoublesForEvaluate()); } return max_scratch_bytes_for_evaluate; } @@ -478,7 +484,7 @@ int Program::MaxDerivativesPerResidualBlock() const { derivatives += residual_block->NumResiduals() * residual_block->parameter_blocks()[j]->LocalSize(); } - max_derivatives = max(max_derivatives, derivatives); + max_derivatives = std::max(max_derivatives, derivatives); } return max_derivatives; } @@ -486,8 +492,8 @@ int Program::MaxDerivativesPerResidualBlock() const { int Program::MaxParametersPerResidualBlock() const { int max_parameters = 0; for (int i = 0; i < residual_blocks_.size(); ++i) { - max_parameters = max(max_parameters, - residual_blocks_[i]->NumParameterBlocks()); + max_parameters = std::max(max_parameters, + residual_blocks_[i]->NumParameterBlocks()); } return max_parameters; } @@ -495,8 +501,8 @@ int Program::MaxParametersPerResidualBlock() const { int Program::MaxResidualsPerResidualBlock() const { int max_residuals = 0; for (int i = 0; i < residual_blocks_.size(); ++i) { - max_residuals = max(max_residuals, - residual_blocks_[i]->NumResiduals()); + max_residuals = std::max(max_residuals, + residual_blocks_[i]->NumResiduals()); } return max_residuals; } diff --git a/internal/ceres/program.h b/internal/ceres/program.h index c7b22c4d2..54dc271e0 100644 --- a/internal/ceres/program.h +++ b/internal/ceres/program.h @@ -60,10 +60,10 @@ class Program { explicit Program(const Program& program); // The ordered parameter and residual blocks for the program. - const vector& parameter_blocks() const; - const vector& residual_blocks() const; - vector* mutable_parameter_blocks(); - vector* mutable_residual_blocks(); + const std::vector& parameter_blocks() const; + const std::vector& residual_blocks() const; + std::vector* mutable_parameter_blocks(); + std::vector* mutable_residual_blocks(); // Serialize to/from the program and update states. // @@ -120,7 +120,8 @@ class Program { // blocks in the same residual block are part of // parameter_blocks as that would violate the assumption that it // is an independent set in the Hessian matrix. - bool IsParameterBlockSetIndependent(const set& independent_set) const; + bool IsParameterBlockSetIndependent( + const std::set& independent_set) const; // Create a TripletSparseMatrix which contains the zero-one // structure corresponding to the block sparsity of the transpose of @@ -142,7 +143,7 @@ class Program { // If there was a problem, then the function will return a NULL // pointer and error will contain a human readable description of // the problem. - Program* CreateReducedProgram(vector* removed_parameter_blocks, + Program* CreateReducedProgram(std::vector* removed_parameter_blocks, double* fixed_cost, string* error) const; @@ -174,13 +175,13 @@ class Program { // // If there was a problem, then the function will return false and // error will contain a human readable description of the problem. - bool RemoveFixedBlocks(vector* removed_parameter_blocks, + bool RemoveFixedBlocks(std::vector* removed_parameter_blocks, double* fixed_cost, string* message); // The Program does not own the ParameterBlock or ResidualBlock objects. - vector parameter_blocks_; - vector residual_blocks_; + std::vector parameter_blocks_; + std::vector residual_blocks_; friend class ProblemImpl; }; diff --git a/internal/ceres/program_evaluator.h b/internal/ceres/program_evaluator.h index 672c233b3..24ed3aefa 100644 --- a/internal/ceres/program_evaluator.h +++ b/internal/ceres/program_evaluator.h @@ -297,11 +297,11 @@ class ProgramEvaluator : public Evaluator { return program_->NumResiduals(); } - virtual map CallStatistics() const { + virtual std::map CallStatistics() const { return execution_summary_.calls(); } - virtual map TimeStatistics() const { + virtual std::map TimeStatistics() const { return execution_summary_.times(); } @@ -332,8 +332,9 @@ class ProgramEvaluator : public Evaluator { }; static void BuildResidualLayout(const Program& program, - vector* residual_layout) { - const vector& residual_blocks = program.residual_blocks(); + std::vector* residual_layout) { + const std::vector& residual_blocks = + program.residual_blocks(); residual_layout->resize(program.NumResidualBlocks()); int residual_pos = 0; for (int i = 0; i < residual_blocks.size(); ++i) { @@ -369,7 +370,7 @@ class ProgramEvaluator : public Evaluator { JacobianWriter jacobian_writer_; scoped_array evaluate_preparers_; scoped_array evaluate_scratch_; - vector residual_layout_; + std::vector residual_layout_; ::ceres::internal::ExecutionSummary execution_summary_; }; diff --git a/internal/ceres/program_test.cc b/internal/ceres/program_test.cc index 10bfa1296..77a1c4431 100644 --- a/internal/ceres/program_test.cc +++ b/internal/ceres/program_test.cc @@ -42,6 +42,8 @@ namespace ceres { namespace internal { +using std::vector; + // A cost function that simply returns its argument. class UnaryIdentityCostFunction : public SizedCostFunction<1, 1> { public: @@ -222,7 +224,8 @@ TEST(Program, RemoveFixedBlocksFixedCost) { problem.AddResidualBlock(new BinaryCostFunction(), NULL, &x, &y); problem.SetParameterBlockConstant(&x); - ResidualBlock *expected_removed_block = problem.program().residual_blocks()[0]; + ResidualBlock *expected_removed_block = + problem.program().residual_blocks()[0]; scoped_array scratch( new double[expected_removed_block->NumScratchDoublesForEvaluate()]); double expected_fixed_cost; @@ -307,7 +310,7 @@ TEST(Program, CreateJacobianBlockSparsityTranspose) { rows[13] = 1; cols[13] = 7; - fill(values, values + 14, 1.0); + std::fill(values, values + 14, 1.0); expected_block_sparse_jacobian.set_num_nonzeros(14); } @@ -374,7 +377,7 @@ TEST(Program, ReallocationInCreateJacobianBlockSparsityTranspose) { } double* values = expected_block_sparse_jacobian.mutable_values(); - fill(values, values + 20, 1.0); + std::fill(values, values + 20, 1.0); expected_block_sparse_jacobian.set_num_nonzeros(20); } diff --git a/internal/ceres/reorder_program.cc b/internal/ceres/reorder_program.cc index aa3d4cec3..fad69f968 100644 --- a/internal/ceres/reorder_program.cc +++ b/internal/ceres/reorder_program.cc @@ -56,6 +56,11 @@ namespace ceres { namespace internal { + +using std::map; +using std::set; +using std::vector; + namespace { // Find the minimum index of any parameter block to the given @@ -87,7 +92,7 @@ Eigen::SparseMatrix CreateBlockJacobian( const int* rows = block_jacobian_transpose.rows(); const int* cols = block_jacobian_transpose.cols(); int num_nonzeros = block_jacobian_transpose.num_nonzeros(); - std::vector triplets; + vector triplets; triplets.reserve(num_nonzeros); for (int i = 0; i < num_nonzeros; ++i) { triplets.push_back(Triplet(cols[i], rows[i], 1)); @@ -220,13 +225,11 @@ bool ApplyOrdering(const ProblemImpl::ParameterMap& parameter_map, const map >& groups = ordering.group_to_elements(); - for (map >::const_iterator group_it = groups.begin(); - group_it != groups.end(); - ++group_it) { + map >::const_iterator group_it = groups.begin(); + for ( ; group_it != groups.end(); ++group_it) { const set& group = group_it->second; - for (set::const_iterator parameter_block_ptr_it = group.begin(); - parameter_block_ptr_it != group.end(); - ++parameter_block_ptr_it) { + set::const_iterator parameter_block_ptr_it = group.begin(); + for ( ; parameter_block_ptr_it != group.end(); ++parameter_block_ptr_it) { ProblemImpl::ParameterMap::const_iterator parameter_block_it = parameter_map.find(*parameter_block_ptr_it); if (parameter_block_it == parameter_map.end()) { @@ -252,8 +255,10 @@ bool LexicographicallyOrderResidualBlocks( // Create a histogram of the number of residuals for each E block. There is an // extra bucket at the end to catch all non-eliminated F blocks. - vector residual_blocks_per_e_block(size_of_first_elimination_group + 1); - vector* residual_blocks = program->mutable_residual_blocks(); + vector residual_blocks_per_e_block( + size_of_first_elimination_group + 1); + vector* residual_blocks = + program->mutable_residual_blocks(); vector min_position_per_residual(residual_blocks->size()); for (int i = 0; i < residual_blocks->size(); ++i) { ResidualBlock* residual_block = (*residual_blocks)[i]; @@ -409,7 +414,8 @@ void MaybeReorderSchurComplementColumnsUsingEigen( Eigen::PermutationMatrix perm; amd_ordering(block_schur_complement, perm); - const vector& parameter_blocks = program->parameter_blocks(); + const vector& parameter_blocks = + program->parameter_blocks(); vector ordering(num_cols); // The ordering of the first size_of_first_elimination_group does diff --git a/internal/ceres/reorder_program_test.cc b/internal/ceres/reorder_program_test.cc index 2a0c4eb42..6f2b1b073 100644 --- a/internal/ceres/reorder_program_test.cc +++ b/internal/ceres/reorder_program_test.cc @@ -41,6 +41,8 @@ namespace ceres { namespace internal { +using std::vector; + // Templated base class for the CostFunction signatures. template class MockCostFunctionBase : public @@ -158,7 +160,8 @@ TEST(_, ApplyOrderingNormal) { linear_solver_ordering, program, &message)); - const vector& parameter_blocks = program->parameter_blocks(); + const vector& parameter_blocks = + program->parameter_blocks(); EXPECT_EQ(parameter_blocks.size(), 3); EXPECT_EQ(parameter_blocks[0]->user_state(), &x); diff --git a/internal/ceres/residual_block.cc b/internal/ceres/residual_block.cc index 621082ac0..5eb211771 100644 --- a/internal/ceres/residual_block.cc +++ b/internal/ceres/residual_block.cc @@ -49,10 +49,11 @@ using Eigen::Dynamic; namespace ceres { namespace internal { -ResidualBlock::ResidualBlock(const CostFunction* cost_function, - const LossFunction* loss_function, - const vector& parameter_blocks, - int index) +ResidualBlock::ResidualBlock( + const CostFunction* cost_function, + const LossFunction* loss_function, + const std::vector& parameter_blocks, + int index) : cost_function_(cost_function), loss_function_(loss_function), parameter_blocks_( diff --git a/internal/ceres/residual_block.h b/internal/ceres/residual_block.h index 9c3671bb0..b93606481 100644 --- a/internal/ceres/residual_block.h +++ b/internal/ceres/residual_block.h @@ -71,7 +71,7 @@ class ResidualBlock { // residual_blocks array. ResidualBlock(const CostFunction* cost_function, const LossFunction* loss_function, - const vector& parameter_blocks, + const std::vector& parameter_blocks, int index); // Evaluates the residual term, storing the scalar cost in *cost, the residual diff --git a/internal/ceres/residual_block_test.cc b/internal/ceres/residual_block_test.cc index b37f50f45..22873e721 100644 --- a/internal/ceres/residual_block_test.cc +++ b/internal/ceres/residual_block_test.cc @@ -39,6 +39,8 @@ namespace ceres { namespace internal { +using std::vector; + // Trivial cost function that accepts three arguments. class TernaryCostFunction: public CostFunction { public: diff --git a/internal/ceres/residual_block_utils_test.cc b/internal/ceres/residual_block_utils_test.cc index d3c917ab8..64bf0db02 100644 --- a/internal/ceres/residual_block_utils_test.cc +++ b/internal/ceres/residual_block_utils_test.cc @@ -46,7 +46,7 @@ namespace internal { void CheckEvaluation(const CostFunction& cost_function, bool is_good) { double x = 1.0; ParameterBlock parameter_block(&x, 1, -1); - vector parameter_blocks; + std::vector parameter_blocks; parameter_blocks.push_back(¶meter_block); ResidualBlock residual_block(&cost_function, diff --git a/internal/ceres/rotation_test.cc b/internal/ceres/rotation_test.cc index 2764e6647..ef1adf702 100644 --- a/internal/ceres/rotation_test.cc +++ b/internal/ceres/rotation_test.cc @@ -44,6 +44,8 @@ namespace ceres { namespace internal { +using std::swap; + const double kPi = 3.14159265358979323846; const double kHalfSqrt2 = 0.707106781186547524401; @@ -53,7 +55,7 @@ double RandDouble() { } // A tolerance value for floating-point comparisons. -static double const kTolerance = numeric_limits::epsilon() * 10; +static double const kTolerance = std::numeric_limits::epsilon() * 10; // Looser tolerance used for numerically unstable conversions. static double const kLooseTolerance = 1e-9; @@ -241,7 +243,7 @@ TEST(Rotation, SmallAngleAxisToQuaternion) { // Test that approximate conversion works for very small angles. TEST(Rotation, TinyAngleAxisToQuaternion) { // Very small value that could potentially cause underflow. - double theta = pow(numeric_limits::min(), 0.75); + double theta = pow(std::numeric_limits::min(), 0.75); double axis_angle[3] = { theta, 0, 0 }; double quaternion[4]; double expected[4] = { cos(theta/2), sin(theta/2.0), 0, 0 }; @@ -302,7 +304,7 @@ TEST(Rotation, SmallQuaternionToAngleAxis) { // Test that approximate conversion works for very small angles. TEST(Rotation, TinyQuaternionToAngleAxis) { // Very small value that could potentially cause underflow. - double theta = pow(numeric_limits::min(), 0.75); + double theta = pow(std::numeric_limits::min(), 0.75); double quaternion[4] = { cos(theta/2), sin(theta/2.0), 0, 0 }; double axis_angle[3]; double expected[3] = { theta, 0, 0 }; @@ -604,9 +606,9 @@ TEST(Rotation, AngleAxisToRotationMatrixAndBackNearZero) { // Transposes a 3x3 matrix. static void Transpose3x3(double m[9]) { - std::swap(m[1], m[3]); - std::swap(m[2], m[6]); - std::swap(m[5], m[7]); + swap(m[1], m[3]); + swap(m[2], m[6]); + swap(m[5], m[7]); } // Convert Euler angles from radians to degrees. @@ -699,7 +701,7 @@ bool IsClose(double x, double y) { if (x == 0 || y == 0) { return absdiff <= kTolerance; } - double reldiff = absdiff / max(fabs(x), fabs(y)); + double reldiff = absdiff / std::max(fabs(x), fabs(y)); return reldiff <= kTolerance; } @@ -735,11 +737,11 @@ void ExpectJetArraysClose(const Jet *x, const Jet *y) { // Log-10 of a value well below machine precision. static const int kSmallTinyCutoff = - static_cast(2 * log(numeric_limits::epsilon())/log(10.0)); + static_cast(2 * log(std::numeric_limits::epsilon())/log(10.0)); // Log-10 of a value just below values representable by double. static const int kTinyZeroLimit = - static_cast(1 + log(numeric_limits::min())/log(10.0)); + static_cast(1 + log(std::numeric_limits::min())/log(10.0)); // Test that exact conversion works for small angles when jets are used. TEST(Rotation, SmallAngleAxisToQuaternionForJets) { diff --git a/internal/ceres/schur_complement_solver.cc b/internal/ceres/schur_complement_solver.cc index 33f812b8c..0c72eb373 100644 --- a/internal/ceres/schur_complement_solver.cc +++ b/internal/ceres/schur_complement_solver.cc @@ -57,10 +57,16 @@ namespace ceres { namespace internal { + +using std::make_pair; +using std::pair; +using std::set; +using std::vector; + namespace { class BlockRandomAccessSparseMatrixAdapter : public LinearOperator { - public: + public: explicit BlockRandomAccessSparseMatrixAdapter( const BlockRandomAccessSparseMatrix& m) : m_(m) { @@ -86,7 +92,7 @@ class BlockRandomAccessSparseMatrixAdapter : public LinearOperator { }; class BlockRandomAccessDiagonalMatrixAdapter : public LinearOperator { - public: + public: explicit BlockRandomAccessDiagonalMatrixAdapter( const BlockRandomAccessDiagonalMatrix& m) : m_(m) { @@ -130,7 +136,7 @@ LinearSolver::Summary SchurComplementSolver::SolveImpl( eliminator_.reset(CHECK_NOTNULL(SchurEliminatorBase::Create(options_))); eliminator_->Init(options_.elimination_groups[0], A->block_structure()); }; - fill(x, x + A->num_cols(), 0.0); + std::fill(x, x + A->num_cols(), 0.0); event_logger.AddEvent("Setup"); eliminator_->Eliminate(A, b, per_solve_options.D, lhs_.get(), rhs_.get()); diff --git a/internal/ceres/schur_complement_solver.h b/internal/ceres/schur_complement_solver.h index 93d23e3d0..59d900f7a 100644 --- a/internal/ceres/schur_complement_solver.h +++ b/internal/ceres/schur_complement_solver.h @@ -188,7 +188,7 @@ class SparseSchurComplementSolver : public SchurComplementSolver { double* solution); // Size of the blocks in the Schur complement. - vector blocks_; + std::vector blocks_; SuiteSparse ss_; // Symbolic factorization of the reduced linear system. Precomputed diff --git a/internal/ceres/schur_eliminator.h b/internal/ceres/schur_eliminator.h index 8fe8b9c88..abe2a606c 100644 --- a/internal/ceres/schur_eliminator.h +++ b/internal/ceres/schur_eliminator.h @@ -263,7 +263,7 @@ class SchurEliminator : public SchurEliminatorBase { // buffer_layout[z1] = 0 // buffer_layout[z5] = y1 * z1 // buffer_layout[z2] = y1 * z1 + y1 * z5 - typedef map BufferLayoutType; + typedef std::map BufferLayoutType; struct Chunk { Chunk() : size(0) {} int size; @@ -315,11 +315,11 @@ class SchurEliminator : public SchurEliminatorBase { // position of each f block in the row/col of the reduced linear // system. Thus lhs_row_layout_[i] is the row/col position of the // i^th f block. - vector lhs_row_layout_; + std::vector lhs_row_layout_; // Combinatorial structure of the chunks in A. For more information // see the documentation of the Chunk object above. - vector chunks_; + std::vector chunks_; // TODO(sameeragarwal): The following two arrays contain per-thread // storage. They should be refactored into a per thread struct. @@ -346,7 +346,7 @@ class SchurEliminator : public SchurEliminatorBase { // Locks for the blocks in the right hand side of the reduced linear // system. - vector rhs_locks_; + std::vector rhs_locks_; }; } // namespace internal diff --git a/internal/ceres/schur_eliminator_impl.h b/internal/ceres/schur_eliminator_impl.h index 305d94e8c..3318061c5 100644 --- a/internal/ceres/schur_eliminator_impl.h +++ b/internal/ceres/schur_eliminator_impl.h @@ -139,7 +139,7 @@ Init(int num_eliminate_blocks, const CompressedRowBlockStructure* bs) { } } - buffer_size_ = max(buffer_size, buffer_size_); + buffer_size_ = std::max(buffer_size, buffer_size_); ++chunk.size; } diff --git a/internal/ceres/schur_eliminator_test.cc b/internal/ceres/schur_eliminator_test.cc index bed8f3a26..f36ec0f35 100644 --- a/internal/ceres/schur_eliminator_test.cc +++ b/internal/ceres/schur_eliminator_test.cc @@ -129,7 +129,7 @@ class SchurEliminatorTest : public ::testing::Test { const double relative_tolerance) { const CompressedRowBlockStructure* bs = A->block_structure(); const int num_col_blocks = bs->cols.size(); - vector blocks(num_col_blocks - num_eliminate_blocks, 0); + std::vector blocks(num_col_blocks - num_eliminate_blocks, 0); for (int i = num_eliminate_blocks; i < num_col_blocks; ++i) { blocks[i - num_eliminate_blocks] = bs->cols[i].size; } diff --git a/internal/ceres/schur_jacobi_preconditioner.cc b/internal/ceres/schur_jacobi_preconditioner.cc index cbdb70861..2b5ef564f 100644 --- a/internal/ceres/schur_jacobi_preconditioner.cc +++ b/internal/ceres/schur_jacobi_preconditioner.cc @@ -54,7 +54,7 @@ SchurJacobiPreconditioner::SchurJacobiPreconditioner( << "Jacobian should have atleast 1 f_block for " << "SCHUR_JACOBI preconditioner."; - vector blocks(num_blocks); + std::vector blocks(num_blocks); for (int i = 0; i < num_blocks; ++i) { blocks[i] = bs.cols[i + options_.elimination_groups[0]].size; } diff --git a/internal/ceres/single_linkage_clustering_test.cc b/internal/ceres/single_linkage_clustering_test.cc index 95692eacb..cd31f5ec0 100644 --- a/internal/ceres/single_linkage_clustering_test.cc +++ b/internal/ceres/single_linkage_clustering_test.cc @@ -109,7 +109,7 @@ TEST(SingleLinkageClustering, ComponentWithWeakLinkAndStrongLink) { // 0-1-2-3 4-5 graph.AddEdge(0, 1, 1.0); graph.AddEdge(1, 2, 1.0); - graph.AddEdge(2, 3, 0.5); // Weak link + graph.AddEdge(2, 3, 0.5); // Weak link graph.AddEdge(0, 3, 1.0); // This component should break up into two. diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc index 738828bf6..b60efd908 100644 --- a/internal/ceres/solver.cc +++ b/internal/ceres/solver.cc @@ -49,6 +49,9 @@ namespace ceres { namespace { +using std::vector; +using std::map; + #define OPTION_OP(x, y, OP) \ if (!(options.x OP y)) { \ std::stringstream ss; \ @@ -625,7 +628,7 @@ string Solver::Summary::BriefReport() const { initial_cost, final_cost, TerminationTypeToString(termination_type)); -}; +} string Solver::Summary::FullReport() const { using internal::VersionString; @@ -844,7 +847,7 @@ string Solver::Summary::FullReport() const { StringAppendF(&report, "Termination: %25s (%s)\n", TerminationTypeToString(termination_type), message.c_str()); return report; -}; +} bool Solver::Summary::IsSolutionUsable() const { return internal::IsSolutionUsable(*this); diff --git a/internal/ceres/solver_test.cc b/internal/ceres/solver_test.cc index 4069578fa..e4abdef7a 100644 --- a/internal/ceres/solver_test.cc +++ b/internal/ceres/solver_test.cc @@ -79,7 +79,7 @@ struct RememberingCallback : public IterationCallback { } int calls; double *x; - vector x_values; + std::vector x_values; }; TEST(Solver, UpdateStateEveryIterationOption) { diff --git a/internal/ceres/solver_utils.cc b/internal/ceres/solver_utils.cc index bd304e7ac..86440ebc4 100644 --- a/internal/ceres/solver_utils.cc +++ b/internal/ceres/solver_utils.cc @@ -31,6 +31,7 @@ #include #include "ceres/internal/port.h" +#include "ceres/solver_utils.h" #include "ceres/version.h" namespace ceres { diff --git a/internal/ceres/solver_utils.h b/internal/ceres/solver_utils.h index 41c8a6e12..2d1edf886 100644 --- a/internal/ceres/solver_utils.h +++ b/internal/ceres/solver_utils.h @@ -31,6 +31,9 @@ #include #include +#include "ceres/iteration_callback.h" +#include "ceres/types.h" + namespace ceres { namespace internal { @@ -48,7 +51,7 @@ void SetSummaryFinalCost(SummaryType* summary) { // iteration because the minimizer maybe making non-monotonic steps. for (int i = 0; i < summary->iterations.size(); ++i) { const IterationSummary& iteration_summary = summary->iterations[i]; - summary->final_cost = min(iteration_summary.cost, summary->final_cost); + summary->final_cost = std::min(iteration_summary.cost, summary->final_cost); } } diff --git a/internal/ceres/sparse_normal_cholesky_solver.h b/internal/ceres/sparse_normal_cholesky_solver.h index 12c052450..73edf4860 100644 --- a/internal/ceres/sparse_normal_cholesky_solver.h +++ b/internal/ceres/sparse_normal_cholesky_solver.h @@ -120,7 +120,7 @@ class SparseNormalCholeskySolver : public CompressedRowSparseMatrixSolver { #endif scoped_ptr outer_product_; - vector pattern_; + std::vector pattern_; const LinearSolver::Options options_; CERES_DISALLOW_COPY_AND_ASSIGN(SparseNormalCholeskySolver); }; diff --git a/internal/ceres/split.cc b/internal/ceres/split.cc index 3edbc2813..0afe1c5f6 100644 --- a/internal/ceres/split.cc +++ b/internal/ceres/split.cc @@ -30,12 +30,16 @@ #include "ceres/split.h" +#include #include #include -#include + #include "ceres/internal/port.h" namespace ceres { +namespace internal { + +using std::vector; // If we know how much to allocate for a vector of strings, we can allocate the // vector only once and directly to the right size. This saves in @@ -110,8 +114,9 @@ void SplitStringUsing(const string& full, const char* delim, vector* result) { result->reserve(result->size() + CalculateReserveForVector(full, delim)); - back_insert_iterator< vector > it(*result); + std::back_insert_iterator > it(*result); SplitStringToIteratorUsing(full, delim, it); } +} // namespace internal } // namespace ceres diff --git a/internal/ceres/split.h b/internal/ceres/split.h index 2334d2603..ada6676c7 100644 --- a/internal/ceres/split.h +++ b/internal/ceres/split.h @@ -36,13 +36,15 @@ #include "ceres/internal/port.h" namespace ceres { +namespace internal { // Split a string using one or more character delimiters, presented as a // nul-terminated c string. Append the components to 'result'. If there are // consecutive delimiters, this function skips over all of them. void SplitStringUsing(const string& full, const char* delim, - vector* res); + std::vector* res); +} // namespace internal } // namespace ceres #endif // CERES_INTERNAL_SPLIT_H_ diff --git a/internal/ceres/suitesparse.cc b/internal/ceres/suitesparse.cc index 1df7566e0..d8b1a492f 100644 --- a/internal/ceres/suitesparse.cc +++ b/internal/ceres/suitesparse.cc @@ -44,6 +44,8 @@ namespace ceres { namespace internal { +using std::vector; + SuiteSparse::SuiteSparse() { cholmod_start(&cc_); } diff --git a/internal/ceres/suitesparse.h b/internal/ceres/suitesparse.h index baab8998b..5aa9cb90f 100644 --- a/internal/ceres/suitesparse.h +++ b/internal/ceres/suitesparse.h @@ -42,7 +42,6 @@ #include #include -#include "ceres/internal/port.h" #include "ceres/linear_solver.h" #include "cholmod.h" #include "glog/logging.h" @@ -147,8 +146,8 @@ class SuiteSparse { cholmod_factor* AnalyzeCholesky(cholmod_sparse* A, string* message); cholmod_factor* BlockAnalyzeCholesky(cholmod_sparse* A, - const vector& row_blocks, - const vector& col_blocks, + const std::vector& row_blocks, + const std::vector& col_blocks, string* message); // If A is symmetric, then compute the symbolic Cholesky @@ -162,9 +161,10 @@ class SuiteSparse { // message contains an explanation of the failures if any. // // Caller owns the result. - cholmod_factor* AnalyzeCholeskyWithUserOrdering(cholmod_sparse* A, - const vector& ordering, - string* message); + cholmod_factor* AnalyzeCholeskyWithUserOrdering( + cholmod_sparse* A, + const std::vector& ordering, + string* message); // Perform a symbolic factorization of A without re-ordering A. No // postordering of the elimination tree is performed. This ensures @@ -215,9 +215,9 @@ class SuiteSparse { // A. If this is the case, only the first sum(col_blocks) are used // to compute the ordering. bool BlockAMDOrdering(const cholmod_sparse* A, - const vector& row_blocks, - const vector& col_blocks, - vector* ordering); + const std::vector& row_blocks, + const std::vector& col_blocks, + std::vector* ordering); // Find a fill reducing approximate minimum degree // ordering. ordering is expected to be large enough to hold the @@ -236,7 +236,7 @@ class SuiteSparse { // being conservative and choosing the next minor version where // things are stable. static bool IsConstrainedApproximateMinimumDegreeOrderingAvailable() { - return (SUITESPARSE_VERSION>4001); + return (SUITESPARSE_VERSION > 4001); } // Find a fill reducing approximate minimum degree @@ -298,7 +298,7 @@ class SuiteSparse { return false; } - void Free(void*) {}; + void Free(void* arg) {} }; #endif // CERES_NO_SUITESPARSE diff --git a/internal/ceres/system_test.cc b/internal/ceres/system_test.cc index be56f20ca..54fd30a85 100644 --- a/internal/ceres/system_test.cc +++ b/internal/ceres/system_test.cc @@ -60,6 +60,8 @@ namespace ceres { namespace internal { +using std::vector; + const bool kAutomaticOrdering = true; const bool kUserOrdering = false; @@ -122,8 +124,9 @@ struct SolverConfig { // Solver::Options* mutable_solver_options(); // }; template -void RunSolversAndCheckTheyMatch(const vector& configurations, - const double max_abs_difference) { +void RunSolversAndCheckTheyMatch( + const vector& configurations, + const double max_abs_difference) { int num_configurations = configurations.size(); vector problems; vector > final_residuals(num_configurations); @@ -348,7 +351,7 @@ class BundleAdjustmentProblem { if (!fptr) { LOG(FATAL) << "File Error: unable to open file " << filename; - }; + } // This will die horribly on invalid files. Them's the breaks. FscanfOrDie(fptr, "%d", &num_cameras_); diff --git a/internal/ceres/test_util.cc b/internal/ceres/test_util.cc index 8af48abbd..9d252e9a0 100644 --- a/internal/ceres/test_util.cc +++ b/internal/ceres/test_util.cc @@ -30,6 +30,8 @@ // // Utility functions useful for testing. +#include "ceres/test_util.h" + #include #include #include "ceres/file.h" diff --git a/internal/ceres/triplet_sparse_matrix.cc b/internal/ceres/triplet_sparse_matrix.cc index 824b123bc..6fdd69c6b 100644 --- a/internal/ceres/triplet_sparse_matrix.cc +++ b/internal/ceres/triplet_sparse_matrix.cc @@ -128,7 +128,7 @@ void TripletSparseMatrix::Reserve(int new_max_num_nonzeros) { } void TripletSparseMatrix::SetZero() { - fill(values_.get(), values_.get() + max_num_nonzeros_, 0.0); + std::fill(values_.get(), values_.get() + max_num_nonzeros_, 0.0); num_nonzeros_ = 0; } @@ -136,7 +136,7 @@ void TripletSparseMatrix::set_num_nonzeros(int num_nonzeros) { CHECK_GE(num_nonzeros, 0); CHECK_LE(num_nonzeros, max_num_nonzeros_); num_nonzeros_ = num_nonzeros; -}; +} void TripletSparseMatrix::AllocateMemory() { rows_.reset(new int[max_num_nonzeros_]); diff --git a/internal/ceres/trust_region_minimizer.cc b/internal/ceres/trust_region_minimizer.cc index 605284da1..0a6ce8075 100644 --- a/internal/ceres/trust_region_minimizer.cc +++ b/internal/ceres/trust_region_minimizer.cc @@ -31,8 +31,8 @@ #include "ceres/trust_region_minimizer.h" #include -#include #include +#include #include #include #include @@ -417,7 +417,7 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, LOG_IF(WARNING, is_not_silent) << "Step failed to evaluate. " << "Treating it as a step with infinite cost"; - new_cost = numeric_limits::max(); + new_cost = std::numeric_limits::max(); } } else { LOG_IF(WARNING, is_not_silent) @@ -521,7 +521,7 @@ void TrustRegionMinimizer::Minimize(const Minimizer::Options& options, // reference iteration, allowing for non-monotonic steps. iteration_summary.relative_decrease = options.use_nonmonotonic_steps - ? max(relative_decrease, historical_relative_decrease) + ? std::max(relative_decrease, historical_relative_decrease) : relative_decrease; // Normally, the quality of a trust region step is measured by diff --git a/internal/ceres/trust_region_minimizer_test.cc b/internal/ceres/trust_region_minimizer_test.cc index 4cad989d2..0cc2af8dc 100644 --- a/internal/ceres/trust_region_minimizer_test.cc +++ b/internal/ceres/trust_region_minimizer_test.cc @@ -252,7 +252,7 @@ void IsTrustRegionSolveSuccessful(TrustRegionStrategyType strategy_type) { EXPECT_NEAR(0.0, parameters[1], 0.001); EXPECT_NEAR(0.0, parameters[2], 0.001); EXPECT_NEAR(0.0, parameters[3], 0.001); -}; +} TEST(TrustRegionMinimizer, PowellsSingularFunctionUsingLevenbergMarquardt) { // This case is excluded because this has a local minimum and does @@ -373,7 +373,7 @@ class CurveCostFunction : public CostFunction { TEST(TrustRegionMinimizer, JacobiScalingTest) { int N = 6; - std::vector< double* > y(N); + std::vector y(N); const double pi = 3.1415926535897932384626433; for (int i = 0; i < N; i++) { double theta = i * 2. * pi/ static_cast< double >(N); diff --git a/internal/ceres/trust_region_preprocessor.cc b/internal/ceres/trust_region_preprocessor.cc index 22ea1ec8c..129442ce6 100644 --- a/internal/ceres/trust_region_preprocessor.cc +++ b/internal/ceres/trust_region_preprocessor.cc @@ -48,12 +48,16 @@ namespace ceres { namespace internal { + +using std::vector; + namespace { ParameterBlockOrdering* CreateDefaultLinearSolverOrdering( const Program& program) { ParameterBlockOrdering* ordering = new ParameterBlockOrdering; - const vector& parameter_blocks = program.parameter_blocks(); + const vector& parameter_blocks = + program.parameter_blocks(); for (int i = 0; i < parameter_blocks.size(); ++i) { ordering->AddElementToGroup( const_cast(parameter_blocks[i]->user_state()), 0); diff --git a/internal/ceres/unsymmetric_linear_solver_test.cc b/internal/ceres/unsymmetric_linear_solver_test.cc index 0b82e6a89..b773627ce 100644 --- a/internal/ceres/unsymmetric_linear_solver_test.cc +++ b/internal/ceres/unsymmetric_linear_solver_test.cc @@ -57,8 +57,6 @@ class UnsymmetricLinearSolverTest : public ::testing::Test { } void TestSolver(const LinearSolver::Options& options) { - - LinearSolver::PerSolveOptions per_solve_options; LinearSolver::Summary unregularized_solve_summary; LinearSolver::Summary regularized_solve_summary; @@ -109,7 +107,8 @@ class UnsymmetricLinearSolverTest : public ::testing::Test { for (int i = 0; i < A_->num_cols(); ++i) { EXPECT_NEAR(sol_unregularized_[i], x_unregularized[i], 1e-8) << "\nExpected: " - << ConstVectorRef(sol_unregularized_.get(), A_->num_cols()).transpose() + << ConstVectorRef(sol_unregularized_.get(), + A_->num_cols()).transpose() << "\nActual: " << x_unregularized.transpose(); } diff --git a/internal/ceres/visibility.cc b/internal/ceres/visibility.cc index da8beedc6..9dfb0f453 100644 --- a/internal/ceres/visibility.cc +++ b/internal/ceres/visibility.cc @@ -49,6 +49,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::max; +using std::pair; +using std::set; +using std::vector; + void ComputeVisibility(const CompressedRowBlockStructure& block_structure, const int num_eliminate_blocks, vector< set >* visibility) { diff --git a/internal/ceres/visibility.h b/internal/ceres/visibility.h index 322efe9be..2ef00be60 100644 --- a/internal/ceres/visibility.h +++ b/internal/ceres/visibility.h @@ -59,7 +59,7 @@ struct CompressedRowBlockStructure; // points and f_blocks correspond to cameras. void ComputeVisibility(const CompressedRowBlockStructure& block_structure, int num_eliminate_blocks, - vector >* visibility); + std::vector >* visibility); // Given f_block visibility as computed by the ComputeVisibility // function above, construct and return a graph whose vertices are @@ -75,7 +75,7 @@ void ComputeVisibility(const CompressedRowBlockStructure& block_structure, // Caller acquires ownership of the returned WeightedGraph pointer // (heap-allocated). WeightedGraph* CreateSchurComplementGraph( - const vector >& visibility); + const std::vector >& visibility); } // namespace internal } // namespace ceres diff --git a/internal/ceres/visibility_based_preconditioner.cc b/internal/ceres/visibility_based_preconditioner.cc index c7ed0493d..125856ea0 100644 --- a/internal/ceres/visibility_based_preconditioner.cc +++ b/internal/ceres/visibility_based_preconditioner.cc @@ -58,6 +58,12 @@ namespace ceres { namespace internal { +using std::make_pair; +using std::pair; +using std::set; +using std::swap; +using std::vector; + // TODO(sameeragarwal): Currently these are magic weights for the // preconditioner construction. Move these higher up into the Options // struct and provide some guidelines for choosing them. @@ -399,7 +405,7 @@ bool VisibilityBasedPreconditioner::UpdateImpl(const BlockSparseMatrix& A, // matrix. Scaling these off-diagonal entries by 1/2 forces this // matrix to be positive definite. void VisibilityBasedPreconditioner::ScaleOffDiagonalCells() { - for (set< pair >::const_iterator it = block_pairs_.begin(); + for (set >::const_iterator it = block_pairs_.begin(); it != block_pairs_.end(); ++it) { const int block1 = it->first; @@ -484,7 +490,7 @@ bool VisibilityBasedPreconditioner::IsBlockPairInPreconditioner( int cluster1 = cluster_membership_[block1]; int cluster2 = cluster_membership_[block2]; if (cluster1 > cluster2) { - std::swap(cluster1, cluster2); + swap(cluster1, cluster2); } return (cluster_pairs_.count(make_pair(cluster1, cluster2)) > 0); } diff --git a/internal/ceres/visibility_based_preconditioner.h b/internal/ceres/visibility_based_preconditioner.h index 2f6922dce..10959d68b 100644 --- a/internal/ceres/visibility_based_preconditioner.h +++ b/internal/ceres/visibility_based_preconditioner.h @@ -151,15 +151,16 @@ class VisibilityBasedPreconditioner : public BlockSparseMatrixPreconditioner { LinearSolverTerminationType Factorize(); void ScaleOffDiagonalCells(); - void ClusterCameras(const vector< set >& visibility); + void ClusterCameras(const std::vector< std::set >& visibility); void FlattenMembershipMap(const HashMap& membership_map, - vector* membership_vector) const; - void ComputeClusterVisibility(const vector >& visibility, - vector >* cluster_visibility) const; + std::vector* membership_vector) const; + void ComputeClusterVisibility( + const std::vector >& visibility, + std::vector >* cluster_visibility) const; WeightedGraph* CreateClusterGraph( - const vector >& visibility) const; + const std::vector >& visibility) const; void ForestToClusterPairs(const WeightedGraph& forest, - HashSet >* cluster_pairs) const; + HashSet >* cluster_pairs) const; void ComputeBlockPairsInPreconditioner(const CompressedRowBlockStructure& bs); bool IsBlockPairInPreconditioner(int block1, int block2) const; bool IsBlockPairOffDiagonal(int block1, int block2) const; @@ -171,19 +172,19 @@ class VisibilityBasedPreconditioner : public BlockSparseMatrixPreconditioner { int num_clusters_; // Sizes of the blocks in the schur complement. - vector block_size_; + std::vector block_size_; // Mapping from cameras to clusters. - vector cluster_membership_; + std::vector cluster_membership_; // Non-zero camera pairs from the schur complement matrix that are // present in the preconditioner, sorted by row (first element of // each pair), then column (second). - set > block_pairs_; + std::set > block_pairs_; // Set of cluster pairs (including self pairs (i,i)) in the // preconditioner. - HashSet > cluster_pairs_; + HashSet > cluster_pairs_; scoped_ptr eliminator_; // Preconditioner matrix. diff --git a/internal/ceres/visibility_test.cc b/internal/ceres/visibility_test.cc index 01f2bdf3f..183ab8834 100644 --- a/internal/ceres/visibility_test.cc +++ b/internal/ceres/visibility_test.cc @@ -47,6 +47,9 @@ namespace ceres { namespace internal { +using std::set; +using std::vector; + class VisibilityTest : public ::testing::Test { };