diff --git a/include/ceres/cost_function_to_functor.h b/include/ceres/cost_function_to_functor.h index e17bc0e0f..bba67a441 100644 --- a/include/ceres/cost_function_to_functor.h +++ b/include/ceres/cost_function_to_functor.h @@ -107,7 +107,7 @@ class CostFunctionToFunctor { // Takes ownership of cost_function. explicit CostFunctionToFunctor(CostFunction* cost_function) : cost_functor_(cost_function) { - CHECK_NOTNULL(cost_function); + CHECK(cost_function != nullptr); CHECK(kNumResiduals > 0 || kNumResiduals == DYNAMIC); // This block breaks the 80 column rule to keep it somewhat readable. diff --git a/include/ceres/dynamic_cost_function_to_functor.h b/include/ceres/dynamic_cost_function_to_functor.h index d4fce1cbd..7ae529102 100644 --- a/include/ceres/dynamic_cost_function_to_functor.h +++ b/include/ceres/dynamic_cost_function_to_functor.h @@ -105,7 +105,7 @@ class DynamicCostFunctionToFunctor { // Takes ownership of cost_function. explicit DynamicCostFunctionToFunctor(CostFunction* cost_function) : cost_function_(cost_function) { - CHECK_NOTNULL(cost_function); + CHECK(cost_function != nullptr); } bool operator()(double const* const* parameters, double* residuals) const { diff --git a/internal/ceres/block_jacobi_preconditioner_test.cc b/internal/ceres/block_jacobi_preconditioner_test.cc index 80e5fbacb..4a9a87169 100644 --- a/internal/ceres/block_jacobi_preconditioner_test.cc +++ b/internal/ceres/block_jacobi_preconditioner_test.cc @@ -48,7 +48,7 @@ class BlockJacobiPreconditionerTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A.reset(down_cast(problem->A.release())); D.reset(problem->D.release()); diff --git a/internal/ceres/block_jacobian_writer.cc b/internal/ceres/block_jacobian_writer.cc index 5714ada84..6998bd66e 100644 --- a/internal/ceres/block_jacobian_writer.cc +++ b/internal/ceres/block_jacobian_writer.cc @@ -205,7 +205,7 @@ SparseMatrix* BlockJacobianWriter::CreateJacobian() const { } BlockSparseMatrix* jacobian = new BlockSparseMatrix(bs); - CHECK_NOTNULL(jacobian); + CHECK(jacobian != nullptr); return jacobian; } diff --git a/internal/ceres/block_random_access_diagonal_matrix.cc b/internal/ceres/block_random_access_diagonal_matrix.cc index 9866e7536..526d173e4 100644 --- a/internal/ceres/block_random_access_diagonal_matrix.cc +++ b/internal/ceres/block_random_access_diagonal_matrix.cc @@ -137,8 +137,8 @@ void BlockRandomAccessDiagonalMatrix::Invert() { void BlockRandomAccessDiagonalMatrix::RightMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); const double* values = tsm_->values(); for (int i = 0; i < blocks_.size(); ++i) { const int block_size = blocks_[i]; diff --git a/internal/ceres/block_sparse_matrix.cc b/internal/ceres/block_sparse_matrix.cc index aabac61cd..8f50f3561 100644 --- a/internal/ceres/block_sparse_matrix.cc +++ b/internal/ceres/block_sparse_matrix.cc @@ -53,7 +53,7 @@ BlockSparseMatrix::BlockSparseMatrix( num_cols_(0), num_nonzeros_(0), block_structure_(block_structure) { - CHECK_NOTNULL(block_structure_.get()); + CHECK(block_structure_ != nullptr); // Count the number of columns in the matrix. for (int i = 0; i < block_structure_->cols.size(); ++i) { @@ -81,7 +81,7 @@ BlockSparseMatrix::BlockSparseMatrix( << num_nonzeros_ * sizeof(double) << " bytes."; // NOLINT values_.reset(new double[num_nonzeros_]); max_num_nonzeros_ = num_nonzeros_; - CHECK_NOTNULL(values_.get()); + CHECK(values_ != nullptr); } void BlockSparseMatrix::SetZero() { @@ -89,8 +89,8 @@ void BlockSparseMatrix::SetZero() { } void BlockSparseMatrix::RightMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); for (int i = 0; i < block_structure_->rows.size(); ++i) { int row_block_pos = block_structure_->rows[i].block.position; @@ -109,8 +109,8 @@ void BlockSparseMatrix::RightMultiply(const double* x, double* y) const { } void BlockSparseMatrix::LeftMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); for (int i = 0; i < block_structure_->rows.size(); ++i) { int row_block_pos = block_structure_->rows[i].block.position; @@ -129,7 +129,7 @@ void BlockSparseMatrix::LeftMultiply(const double* x, double* y) const { } void BlockSparseMatrix::SquaredColumnNorm(double* x) const { - CHECK_NOTNULL(x); + CHECK(x != nullptr); VectorRef(x, num_cols_).setZero(); for (int i = 0; i < block_structure_->rows.size(); ++i) { int row_block_size = block_structure_->rows[i].block.size; @@ -146,7 +146,7 @@ void BlockSparseMatrix::SquaredColumnNorm(double* x) const { } void BlockSparseMatrix::ScaleColumns(const double* scale) { - CHECK_NOTNULL(scale); + CHECK(scale != nullptr); for (int i = 0; i < block_structure_->rows.size(); ++i) { int row_block_size = block_structure_->rows[i].block.size; @@ -163,7 +163,7 @@ void BlockSparseMatrix::ScaleColumns(const double* scale) { } void BlockSparseMatrix::ToDenseMatrix(Matrix* dense_matrix) const { - CHECK_NOTNULL(dense_matrix); + CHECK(dense_matrix != nullptr); dense_matrix->resize(num_rows_, num_cols_); dense_matrix->setZero(); @@ -186,7 +186,7 @@ void BlockSparseMatrix::ToDenseMatrix(Matrix* dense_matrix) const { void BlockSparseMatrix::ToTripletSparseMatrix( TripletSparseMatrix* matrix) const { - CHECK_NOTNULL(matrix); + CHECK(matrix != nullptr); matrix->Reserve(num_nonzeros_); matrix->Resize(num_rows_, num_cols_); @@ -221,7 +221,7 @@ const CompressedRowBlockStructure* BlockSparseMatrix::block_structure() } void BlockSparseMatrix::ToTextFile(FILE* file) const { - CHECK_NOTNULL(file); + CHECK(file != nullptr); for (int i = 0; i < block_structure_->rows.size(); ++i) { const int row_block_pos = block_structure_->rows[i].block.position; const int row_block_size = block_structure_->rows[i].block.size; diff --git a/internal/ceres/block_sparse_matrix_test.cc b/internal/ceres/block_sparse_matrix_test.cc index 50b6766bf..26fa9a2bd 100644 --- a/internal/ceres/block_sparse_matrix_test.cc +++ b/internal/ceres/block_sparse_matrix_test.cc @@ -47,11 +47,11 @@ class BlockSparseMatrixTest : public ::testing::Test { virtual void SetUp() { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A_.reset(down_cast(problem->A.release())); problem.reset(CreateLinearLeastSquaresProblemFromId(1)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); B_.reset(down_cast(problem->A.release())); CHECK_EQ(A_->num_rows(), B_->num_rows()); diff --git a/internal/ceres/canonical_views_clustering.cc b/internal/ceres/canonical_views_clustering.cc index 95fc36e5a..b2fd49ff7 100644 --- a/internal/ceres/canonical_views_clustering.cc +++ b/internal/ceres/canonical_views_clustering.cc @@ -99,8 +99,10 @@ void CanonicalViewsClustering::ComputeClustering( vector* centers, IntMap* membership) { options_ = options; - CHECK_NOTNULL(centers)->clear(); - CHECK_NOTNULL(membership)->clear(); + CHECK(centers != nullptr); + CHECK(membership != nullptr); + centers->clear(); + membership->clear(); graph_ = &graph; IntSet valid_views; @@ -203,7 +205,8 @@ void CanonicalViewsClustering::UpdateCanonicalViewAssignments( void CanonicalViewsClustering::ComputeClusterMembership( const vector& centers, IntMap* membership) const { - CHECK_NOTNULL(membership)->clear(); + CHECK(membership != nullptr); + membership->clear(); // The i^th cluster has cluster id i. IntMap center_to_cluster_id; diff --git a/internal/ceres/compressed_col_sparse_matrix_utils.cc b/internal/ceres/compressed_col_sparse_matrix_utils.cc index ebb2a62c5..3f6672f85 100644 --- a/internal/ceres/compressed_col_sparse_matrix_utils.cc +++ b/internal/ceres/compressed_col_sparse_matrix_utils.cc @@ -47,8 +47,10 @@ void CompressedColumnScalarMatrixToBlockMatrix( const vector& col_blocks, vector* block_rows, vector* block_cols) { - CHECK_NOTNULL(block_rows)->clear(); - CHECK_NOTNULL(block_cols)->clear(); + CHECK(block_rows != nullptr); + CHECK(block_cols != nullptr); + block_rows->clear(); + block_cols->clear(); const int num_row_blocks = row_blocks.size(); const int num_col_blocks = col_blocks.size(); diff --git a/internal/ceres/compressed_row_sparse_matrix.cc b/internal/ceres/compressed_row_sparse_matrix.cc index bdb0b7abb..e56de16bf 100644 --- a/internal/ceres/compressed_row_sparse_matrix.cc +++ b/internal/ceres/compressed_row_sparse_matrix.cc @@ -246,7 +246,7 @@ CompressedRowSparseMatrix* CompressedRowSparseMatrix::FromTripletSparseMatrix( CompressedRowSparseMatrix::CompressedRowSparseMatrix(const double* diagonal, int num_rows) { - CHECK_NOTNULL(diagonal); + CHECK(diagonal != nullptr); num_rows_ = num_rows; num_cols_ = num_rows; @@ -275,8 +275,8 @@ void CompressedRowSparseMatrix::SetZero() { // block-aware for higher performance. void CompressedRowSparseMatrix::RightMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); if (storage_type_ == UNSYMMETRIC) { for (int r = 0; r < num_rows_; ++r) { @@ -336,8 +336,8 @@ void CompressedRowSparseMatrix::RightMultiply(const double* x, } void CompressedRowSparseMatrix::LeftMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); if (storage_type_ == UNSYMMETRIC) { for (int r = 0; r < num_rows_; ++r) { @@ -352,7 +352,7 @@ void CompressedRowSparseMatrix::LeftMultiply(const double* x, double* y) const { } void CompressedRowSparseMatrix::SquaredColumnNorm(double* x) const { - CHECK_NOTNULL(x); + CHECK(x != nullptr); std::fill(x, x + num_cols_, 0.0); if (storage_type_ == UNSYMMETRIC) { @@ -408,7 +408,7 @@ void CompressedRowSparseMatrix::SquaredColumnNorm(double* x) const { } } void CompressedRowSparseMatrix::ScaleColumns(const double* scale) { - CHECK_NOTNULL(scale); + CHECK(scale != nullptr); for (int idx = 0; idx < rows_[num_rows_]; ++idx) { values_[idx] *= scale[cols_[idx]]; @@ -416,7 +416,7 @@ void CompressedRowSparseMatrix::ScaleColumns(const double* scale) { } void CompressedRowSparseMatrix::ToDenseMatrix(Matrix* dense_matrix) const { - CHECK_NOTNULL(dense_matrix); + CHECK(dense_matrix != nullptr); dense_matrix->resize(num_rows_, num_cols_); dense_matrix->setZero(); @@ -504,7 +504,7 @@ void CompressedRowSparseMatrix::AppendRows(const CompressedRowSparseMatrix& m) { } void CompressedRowSparseMatrix::ToTextFile(FILE* file) const { - CHECK_NOTNULL(file); + CHECK(file != nullptr); for (int r = 0; r < num_rows_; ++r) { for (int idx = rows_[r]; idx < rows_[r + 1]; ++idx) { fprintf(file, "% 10d % 10d %17f\n", r, cols_[idx], values_[idx]); diff --git a/internal/ceres/compressed_row_sparse_matrix_test.cc b/internal/ceres/compressed_row_sparse_matrix_test.cc index 4351e3d0c..cf6e2e42d 100644 --- a/internal/ceres/compressed_row_sparse_matrix_test.cc +++ b/internal/ceres/compressed_row_sparse_matrix_test.cc @@ -75,7 +75,7 @@ class CompressedRowSparseMatrixTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(1)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); tsm.reset(down_cast(problem->A.release())); crsm.reset(CompressedRowSparseMatrix::FromTripletSparseMatrix(*tsm)); diff --git a/internal/ceres/conjugate_gradients_solver.cc b/internal/ceres/conjugate_gradients_solver.cc index 039b4f4e4..c6f85c15e 100644 --- a/internal/ceres/conjugate_gradients_solver.cc +++ b/internal/ceres/conjugate_gradients_solver.cc @@ -67,9 +67,9 @@ LinearSolver::Summary ConjugateGradientsSolver::Solve( const double* b, const LinearSolver::PerSolveOptions& per_solve_options, double* x) { - CHECK_NOTNULL(A); - CHECK_NOTNULL(x); - CHECK_NOTNULL(b); + CHECK(A != nullptr); + CHECK(x != nullptr); + CHECK(b != nullptr); CHECK_EQ(A->num_rows(), A->num_cols()); LinearSolver::Summary summary; diff --git a/internal/ceres/coordinate_descent_minimizer.cc b/internal/ceres/coordinate_descent_minimizer.cc index 558faed7c..c5d56f30b 100644 --- a/internal/ceres/coordinate_descent_minimizer.cc +++ b/internal/ceres/coordinate_descent_minimizer.cc @@ -60,7 +60,9 @@ using std::string; using std::vector; CoordinateDescentMinimizer::CoordinateDescentMinimizer(ContextImpl* context) - : context_(CHECK_NOTNULL(context)) {} + : context_(context) { + CHECK(context_ != nullptr); +} CoordinateDescentMinimizer::~CoordinateDescentMinimizer() { } @@ -222,14 +224,17 @@ void CoordinateDescentMinimizer::Solve(Program* program, Minimizer::Options minimizer_options; minimizer_options.evaluator.reset( - CHECK_NOTNULL(Evaluator::Create(evaluator_options_, program, &error))); + Evaluator::Create(evaluator_options_, program, &error)); + CHECK(minimizer_options.evaluator != nullptr); minimizer_options.jacobian.reset( - CHECK_NOTNULL(minimizer_options.evaluator->CreateJacobian())); + minimizer_options.evaluator->CreateJacobian()); + CHECK(minimizer_options.jacobian != nullptr); TrustRegionStrategy::Options trs_options; trs_options.linear_solver = linear_solver; minimizer_options.trust_region_strategy.reset( - CHECK_NOTNULL(TrustRegionStrategy::Create(trs_options))); + TrustRegionStrategy::Create(trs_options)); + CHECK(minimizer_options.trust_region_strategy != nullptr); minimizer_options.is_silent = true; TrustRegionMinimizer minimizer; diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc index 48041732e..d24f5c9b1 100644 --- a/internal/ceres/covariance_impl.cc +++ b/internal/ceres/covariance_impl.cc @@ -651,7 +651,7 @@ bool CovarianceImpl::ComputeCovarianceValuesUsingSuiteSparseQR() { &permutation, &cc); event_logger.AddEvent("Numeric Factorization"); - CHECK_NOTNULL(R); + CHECK(R != nullptr); if (rank < cholmod_jacobian.ncol) { LOG(ERROR) << "Jacobian matrix is rank deficient. " diff --git a/internal/ceres/dense_sparse_matrix.cc b/internal/ceres/dense_sparse_matrix.cc index 19db867d4..72e08360d 100644 --- a/internal/ceres/dense_sparse_matrix.cc +++ b/internal/ceres/dense_sparse_matrix.cc @@ -166,7 +166,7 @@ ColMajorMatrixRef DenseSparseMatrix::mutable_matrix() { void DenseSparseMatrix::ToTextFile(FILE* file) const { - CHECK_NOTNULL(file); + CHECK(file != nullptr); const int active_rows = (has_diagonal_reserved_ && !has_diagonal_appended_) ? (m_.rows() - m_.cols()) diff --git a/internal/ceres/dense_sparse_matrix_test.cc b/internal/ceres/dense_sparse_matrix_test.cc index 7c7e69a1b..4d52e81ad 100644 --- a/internal/ceres/dense_sparse_matrix_test.cc +++ b/internal/ceres/dense_sparse_matrix_test.cc @@ -72,7 +72,7 @@ class DenseSparseMatrixTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(1)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); tsm.reset(down_cast(problem->A.release())); dsm.reset(new DenseSparseMatrix(*tsm)); diff --git a/internal/ceres/dogleg_strategy.cc b/internal/ceres/dogleg_strategy.cc index b3c52b936..ecc6b8823 100644 --- a/internal/ceres/dogleg_strategy.cc +++ b/internal/ceres/dogleg_strategy.cc @@ -66,7 +66,7 @@ DoglegStrategy::DoglegStrategy(const TrustRegionStrategy::Options& options) dogleg_step_norm_(0.0), reuse_(false), dogleg_type_(options.dogleg_type) { - CHECK_NOTNULL(linear_solver_); + CHECK(linear_solver_ != nullptr); CHECK_GT(min_diagonal_, 0.0); CHECK_LE(min_diagonal_, max_diagonal_); CHECK_GT(max_radius_, 0.0); @@ -81,9 +81,9 @@ TrustRegionStrategy::Summary DoglegStrategy::ComputeStep( SparseMatrix* jacobian, const double* residuals, double* step) { - CHECK_NOTNULL(jacobian); - CHECK_NOTNULL(residuals); - CHECK_NOTNULL(step); + CHECK(jacobian != nullptr); + CHECK(residuals != nullptr); + CHECK(step != nullptr); const int n = jacobian->num_cols(); if (reuse_) { @@ -471,7 +471,7 @@ double DoglegStrategy::EvaluateSubspaceModel(const Vector2d& x) const { // In the failure case, another step should be taken, such as the traditional // dogleg step. bool DoglegStrategy::FindMinimumOnTrustRegionBoundary(Vector2d* minimum) const { - CHECK_NOTNULL(minimum); + CHECK(minimum != nullptr); // Return (0, 0) in all error cases. minimum->setZero(); diff --git a/internal/ceres/gradient_checker.cc b/internal/ceres/gradient_checker.cc index d231c8389..f00c76e6c 100644 --- a/internal/ceres/gradient_checker.cc +++ b/internal/ceres/gradient_checker.cc @@ -62,9 +62,9 @@ bool EvaluateCostFunction( Vector* residuals, std::vector* jacobians, std::vector* local_jacobians) { - CHECK_NOTNULL(residuals); - CHECK_NOTNULL(jacobians); - CHECK_NOTNULL(local_jacobians); + CHECK(residuals != nullptr); + CHECK(jacobians != nullptr); + CHECK(local_jacobians != nullptr); const vector& block_sizes = function->parameter_block_sizes(); const int num_parameter_blocks = block_sizes.size(); @@ -123,7 +123,7 @@ GradientChecker::GradientChecker( const vector* local_parameterizations, const NumericDiffOptions& options) : function_(function) { - CHECK_NOTNULL(function); + CHECK(function != nullptr); if (local_parameterizations != NULL) { local_parameterizations_ = *local_parameterizations; } else { diff --git a/internal/ceres/gradient_checking_cost_function.cc b/internal/ceres/gradient_checking_cost_function.cc index b40284431..a2bfa1cb0 100644 --- a/internal/ceres/gradient_checking_cost_function.cc +++ b/internal/ceres/gradient_checking_cost_function.cc @@ -175,7 +175,7 @@ ProblemImpl* CreateGradientCheckingProblemImpl( double relative_step_size, double relative_precision, GradientCheckingIterationCallback* callback) { - CHECK_NOTNULL(callback); + CHECK(callback != nullptr); // We create new CostFunctions by wrapping the original CostFunction // in a gradient checking CostFunction. So its okay for the // ProblemImpl to take ownership of it and destroy it. The diff --git a/internal/ceres/gradient_checking_cost_function_test.cc b/internal/ceres/gradient_checking_cost_function_test.cc index 2a0390c71..f08bcd072 100644 --- a/internal/ceres/gradient_checking_cost_function_test.cc +++ b/internal/ceres/gradient_checking_cost_function_test.cc @@ -326,8 +326,8 @@ class TernaryCostFunction: public CostFunction { // array and have the same LocalParameterization object. void ParameterBlocksAreEquivalent(const ParameterBlock* left, const ParameterBlock* right) { - CHECK_NOTNULL(left); - CHECK_NOTNULL(right); + CHECK(left != nullptr); + CHECK(right != nullptr); EXPECT_EQ(left->user_state(), right->user_state()); EXPECT_EQ(left->Size(), right->Size()); EXPECT_EQ(left->Size(), right->Size()); diff --git a/internal/ceres/gradient_problem_solver.cc b/internal/ceres/gradient_problem_solver.cc index 47d8ade79..1639e3066 100644 --- a/internal/ceres/gradient_problem_solver.cc +++ b/internal/ceres/gradient_problem_solver.cc @@ -109,7 +109,8 @@ void GradientProblemSolver::Solve(const GradientProblemSolver::Options& options, double start_time = WallTimeInSeconds(); - *CHECK_NOTNULL(summary) = Summary(); + CHECK(summary != nullptr); + *summary = Summary(); summary->num_parameters = problem.NumParameters(); summary->num_local_parameters = problem.NumLocalParameters(); summary->line_search_direction_type = options.line_search_direction_type; // NOLINT diff --git a/internal/ceres/graph_algorithms.h b/internal/ceres/graph_algorithms.h index 876846528..b06293131 100644 --- a/internal/ceres/graph_algorithms.h +++ b/internal/ceres/graph_algorithms.h @@ -100,7 +100,7 @@ int IndependentSetOrdering(const Graph& graph, const std::unordered_set& vertices = graph.vertices(); const int num_vertices = vertices.size(); - CHECK_NOTNULL(ordering); + CHECK(ordering != nullptr); ordering->clear(); ordering->reserve(num_vertices); @@ -165,7 +165,7 @@ int IndependentSetOrdering(const Graph& graph, template int StableIndependentSetOrdering(const Graph& graph, std::vector* ordering) { - CHECK_NOTNULL(ordering); + CHECK(ordering != nullptr); const std::unordered_set& vertices = graph.vertices(); const int num_vertices = vertices.size(); CHECK_EQ(vertices.size(), ordering->size()); diff --git a/internal/ceres/householder_vector.h b/internal/ceres/householder_vector.h index f54feea05..6d85217cd 100644 --- a/internal/ceres/householder_vector.h +++ b/internal/ceres/householder_vector.h @@ -46,8 +46,8 @@ template void ComputeHouseholderVector(const Eigen::Matrix& x, Eigen::Matrix* v, Scalar* beta) { - CHECK_NOTNULL(beta); - CHECK_NOTNULL(v); + CHECK(beta != nullptr); + CHECK(v != nullptr); CHECK_GT(x.rows(), 1); CHECK_EQ(x.rows(), v->rows()); diff --git a/internal/ceres/implicit_schur_complement_test.cc b/internal/ceres/implicit_schur_complement_test.cc index cbc0aeed0..3beb3867c 100644 --- a/internal/ceres/implicit_schur_complement_test.cc +++ b/internal/ceres/implicit_schur_complement_test.cc @@ -59,7 +59,7 @@ class ImplicitSchurComplementTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A_.reset(down_cast(problem->A.release())); b_.reset(problem->b.release()); D_.reset(problem->D.release()); @@ -91,7 +91,7 @@ class ImplicitSchurComplementTest : public ::testing::Test { std::unique_ptr eliminator( SchurEliminatorBase::Create(options)); - CHECK_NOTNULL(eliminator.get()); + CHECK(eliminator != nullptr); const bool kFullRankETE = true; eliminator->Init(num_eliminate_blocks_, kFullRankETE, bs); diff --git a/internal/ceres/iterative_schur_complement_solver.cc b/internal/ceres/iterative_schur_complement_solver.cc index 8ce907576..6076c38c7 100644 --- a/internal/ceres/iterative_schur_complement_solver.cc +++ b/internal/ceres/iterative_schur_complement_solver.cc @@ -67,7 +67,7 @@ LinearSolver::Summary IterativeSchurComplementSolver::SolveImpl( double* x) { EventLogger event_logger("IterativeSchurComplementSolver::Solve"); - CHECK_NOTNULL(A->block_structure()); + CHECK(A->block_structure() != nullptr); const int num_eliminate_blocks = options_.elimination_groups[0]; // Initialize a ImplicitSchurComplement object. if (schur_complement_ == NULL) { diff --git a/internal/ceres/iterative_schur_complement_solver_test.cc b/internal/ceres/iterative_schur_complement_solver_test.cc index 28c0d9966..3bf2d92f3 100644 --- a/internal/ceres/iterative_schur_complement_solver_test.cc +++ b/internal/ceres/iterative_schur_complement_solver_test.cc @@ -63,7 +63,7 @@ class IterativeSchurComplementSolverTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A_.reset(down_cast(problem->A.release())); b_.reset(problem->b.release()); D_.reset(problem->D.release()); diff --git a/internal/ceres/levenberg_marquardt_strategy.cc b/internal/ceres/levenberg_marquardt_strategy.cc index 856580068..e1a045488 100644 --- a/internal/ceres/levenberg_marquardt_strategy.cc +++ b/internal/ceres/levenberg_marquardt_strategy.cc @@ -55,7 +55,7 @@ LevenbergMarquardtStrategy::LevenbergMarquardtStrategy( max_diagonal_(options.max_lm_diagonal), decrease_factor_(2.0), reuse_diagonal_(false) { - CHECK_NOTNULL(linear_solver_); + CHECK(linear_solver_ != nullptr); CHECK_GT(min_diagonal_, 0.0); CHECK_LE(min_diagonal_, max_diagonal_); CHECK_GT(max_radius_, 0.0); @@ -69,9 +69,9 @@ TrustRegionStrategy::Summary LevenbergMarquardtStrategy::ComputeStep( SparseMatrix* jacobian, const double* residuals, double* step) { - CHECK_NOTNULL(jacobian); - CHECK_NOTNULL(residuals); - CHECK_NOTNULL(step); + CHECK(jacobian != nullptr); + CHECK(residuals != nullptr); + CHECK(step != nullptr); const int num_parameters = jacobian->num_cols(); if (!reuse_diagonal_) { diff --git a/internal/ceres/levenberg_marquardt_strategy_test.cc b/internal/ceres/levenberg_marquardt_strategy_test.cc index d5f746e71..cfbec7152 100644 --- a/internal/ceres/levenberg_marquardt_strategy_test.cc +++ b/internal/ceres/levenberg_marquardt_strategy_test.cc @@ -66,7 +66,7 @@ class RegularizationCheckingLinearSolver : public DenseSparseMatrixSolver { const double* b, const LinearSolver::PerSolveOptions& per_solve_options, double* x) { - CHECK_NOTNULL(per_solve_options.D); + CHECK(per_solve_options.D != nullptr); for (int i = 0; i < num_cols_; ++i) { EXPECT_NEAR(per_solve_options.D[i], diagonal_[i], kTolerance) << i << " " << per_solve_options.D[i] << " " << diagonal_[i]; diff --git a/internal/ceres/line_search.cc b/internal/ceres/line_search.cc index a08761504..352c64f50 100644 --- a/internal/ceres/line_search.cc +++ b/internal/ceres/line_search.cc @@ -192,7 +192,8 @@ void LineSearch::Search(double step_size_estimate, double initial_gradient, Summary* summary) const { const double start_time = WallTimeInSeconds(); - *CHECK_NOTNULL(summary) = LineSearch::Summary(); + CHECK(summary != nullptr); + *summary = LineSearch::Summary(); summary->cost_evaluation_time_in_seconds = 0.0; summary->gradient_evaluation_time_in_seconds = 0.0; diff --git a/internal/ceres/line_search_minimizer.cc b/internal/ceres/line_search_minimizer.cc index 38e645217..ac0a19289 100644 --- a/internal/ceres/line_search_minimizer.cc +++ b/internal/ceres/line_search_minimizer.cc @@ -90,7 +90,8 @@ void LineSearchMinimizer::Minimize(const Minimizer::Options& options, double start_time = WallTimeInSeconds(); double iteration_start_time = start_time; - Evaluator* evaluator = CHECK_NOTNULL(options.evaluator.get()); + CHECK(options.evaluator != nullptr); + Evaluator* evaluator = options.evaluator.get(); const int num_parameters = evaluator->NumParameters(); const int num_effective_parameters = evaluator->NumEffectiveParameters(); diff --git a/internal/ceres/line_search_preprocessor.cc b/internal/ceres/line_search_preprocessor.cc index 72c1dd829..17226add7 100644 --- a/internal/ceres/line_search_preprocessor.cc +++ b/internal/ceres/line_search_preprocessor.cc @@ -75,7 +75,7 @@ LineSearchPreprocessor::~LineSearchPreprocessor() { bool LineSearchPreprocessor::Preprocess(const Solver::Options& options, ProblemImpl* problem, PreprocessedProblem* pp) { - CHECK_NOTNULL(pp); + CHECK(pp != nullptr); pp->options = options; ChangeNumThreadsIfNeeded(&pp->options); diff --git a/internal/ceres/linear_least_squares_problems.cc b/internal/ceres/linear_least_squares_problems.cc index fb72d6301..7c523d399 100644 --- a/internal/ceres/linear_least_squares_problems.cc +++ b/internal/ceres/linear_least_squares_problems.cc @@ -614,7 +614,7 @@ bool DumpLinearLeastSquaresProblemToConsole(const SparseMatrix* A, const double* b, const double* x, int num_eliminate_blocks) { - CHECK_NOTNULL(A); + CHECK(A != nullptr); Matrix AA; A->ToDenseMatrix(&AA); LOG(INFO) << "A^T: \n" << AA.transpose(); @@ -637,10 +637,10 @@ bool DumpLinearLeastSquaresProblemToConsole(const SparseMatrix* A, void WriteArrayToFileOrDie(const string& filename, const double* x, const int size) { - CHECK_NOTNULL(x); + CHECK(x != nullptr); VLOG(2) << "Writing array to: " << filename; FILE* fptr = fopen(filename.c_str(), "w"); - CHECK_NOTNULL(fptr); + CHECK(fptr != nullptr); for (int i = 0; i < size; ++i) { fprintf(fptr, "%17f\n", x[i]); } @@ -653,7 +653,7 @@ bool DumpLinearLeastSquaresProblemToTextFile(const string& filename_base, const double* b, const double* x, int num_eliminate_blocks) { - CHECK_NOTNULL(A); + CHECK(A != nullptr); LOG(INFO) << "writing to: " << filename_base << "*"; string matlab_script; @@ -667,7 +667,7 @@ bool DumpLinearLeastSquaresProblemToTextFile(const string& filename_base, { string filename = filename_base + "_A.txt"; FILE* fptr = fopen(filename.c_str(), "w"); - CHECK_NOTNULL(fptr); + CHECK(fptr != nullptr); A->ToTextFile(fptr); fclose(fptr); StringAppendF(&matlab_script, diff --git a/internal/ceres/linear_solver.h b/internal/ceres/linear_solver.h index 51897fc5e..24c245dc3 100644 --- a/internal/ceres/linear_solver.h +++ b/internal/ceres/linear_solver.h @@ -306,9 +306,9 @@ class TypedLinearSolver : public LinearSolver { const LinearSolver::PerSolveOptions& per_solve_options, double* x) { ScopedExecutionTimer total_time("LinearSolver::Solve", &execution_summary_); - CHECK_NOTNULL(A); - CHECK_NOTNULL(b); - CHECK_NOTNULL(x); + CHECK(A != nullptr); + CHECK(b != nullptr); + CHECK(x != nullptr); return SolveImpl(down_cast(A), b, per_solve_options, x); } diff --git a/internal/ceres/loss_function.cc b/internal/ceres/loss_function.cc index 50612f571..bf41b9e91 100644 --- a/internal/ceres/loss_function.cc +++ b/internal/ceres/loss_function.cc @@ -133,10 +133,12 @@ void TukeyLoss::Evaluate(double s, double* rho) const { ComposedLoss::ComposedLoss(const LossFunction* f, Ownership ownership_f, const LossFunction* g, Ownership ownership_g) - : f_(CHECK_NOTNULL(f)), - g_(CHECK_NOTNULL(g)), + : f_(f), + g_(g), ownership_f_(ownership_f), ownership_g_(ownership_g) { + CHECK(f_ != nullptr); + CHECK(g_ != nullptr); } ComposedLoss::~ComposedLoss() { diff --git a/internal/ceres/parameter_block_ordering.cc b/internal/ceres/parameter_block_ordering.cc index ffae223be..ef521c0e1 100644 --- a/internal/ceres/parameter_block_ordering.cc +++ b/internal/ceres/parameter_block_ordering.cc @@ -51,7 +51,8 @@ using std::vector; int ComputeStableSchurOrdering(const Program& program, vector* ordering) { - CHECK_NOTNULL(ordering)->clear(); + CHECK(ordering != nullptr); + ordering->clear(); EventLogger event_logger("ComputeStableSchurOrdering"); std::unique_ptr > graph(CreateHessianGraph(program)); event_logger.AddEvent("CreateHessianGraph"); @@ -82,7 +83,8 @@ int ComputeStableSchurOrdering(const Program& program, int ComputeSchurOrdering(const Program& program, vector* ordering) { - CHECK_NOTNULL(ordering)->clear(); + CHECK(ordering != nullptr); + ordering->clear(); std::unique_ptr > graph(CreateHessianGraph(program)); int independent_set_size = IndependentSetOrdering(*graph, ordering); @@ -101,7 +103,8 @@ int ComputeSchurOrdering(const Program& program, void ComputeRecursiveIndependentSetOrdering(const Program& program, ParameterBlockOrdering* ordering) { - CHECK_NOTNULL(ordering)->Clear(); + CHECK(ordering != nullptr); + ordering->Clear(); const vector parameter_blocks = program.parameter_blocks(); std::unique_ptr > graph(CreateHessianGraph(program)); @@ -122,7 +125,8 @@ void ComputeRecursiveIndependentSetOrdering(const Program& program, } Graph* CreateHessianGraph(const Program& program) { - Graph* graph = CHECK_NOTNULL(new Graph); + Graph* graph = new Graph; + CHECK(graph != nullptr); const vector& parameter_blocks = program.parameter_blocks(); for (int i = 0; i < parameter_blocks.size(); ++i) { ParameterBlock* parameter_block = parameter_blocks[i]; @@ -157,7 +161,8 @@ Graph* CreateHessianGraph(const Program& program) { void OrderingToGroupSizes(const ParameterBlockOrdering* ordering, vector* group_sizes) { - CHECK_NOTNULL(group_sizes)->clear(); + CHECK(group_sizes != nullptr); + group_sizes->clear(); if (ordering == NULL) { return; } diff --git a/internal/ceres/partitioned_matrix_view_impl.h b/internal/ceres/partitioned_matrix_view_impl.h index 86fb278fa..f3f548c7a 100644 --- a/internal/ceres/partitioned_matrix_view_impl.h +++ b/internal/ceres/partitioned_matrix_view_impl.h @@ -50,7 +50,7 @@ PartitionedMatrixView( : matrix_(matrix), num_col_blocks_e_(num_col_blocks_e) { const CompressedRowBlockStructure* bs = matrix_.block_structure(); - CHECK_NOTNULL(bs); + CHECK(bs != nullptr); num_col_blocks_f_ = bs->cols.size() - num_col_blocks_e_; diff --git a/internal/ceres/partitioned_matrix_view_test.cc b/internal/ceres/partitioned_matrix_view_test.cc index 7eafff406..40b49ef94 100644 --- a/internal/ceres/partitioned_matrix_view_test.cc +++ b/internal/ceres/partitioned_matrix_view_test.cc @@ -52,7 +52,7 @@ class PartitionedMatrixViewTest : public ::testing::Test { srand(5); std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A_.reset(problem->A.release()); num_cols_ = A_->num_cols(); diff --git a/internal/ceres/polynomial.cc b/internal/ceres/polynomial.cc index 6462bdd69..20812f4de 100644 --- a/internal/ceres/polynomial.cc +++ b/internal/ceres/polynomial.cc @@ -52,7 +52,7 @@ namespace { // In: Numerische Mathematik, Volume 13, Number 4 (1969), 293-304, // Springer Berlin / Heidelberg. DOI: 10.1007/BF02165404 void BalanceCompanionMatrix(Matrix* companion_matrix_ptr) { - CHECK_NOTNULL(companion_matrix_ptr); + CHECK(companion_matrix_ptr != nullptr); Matrix& companion_matrix = *companion_matrix_ptr; Matrix companion_matrix_offdiagonal = companion_matrix; companion_matrix_offdiagonal.diagonal().setZero(); @@ -104,7 +104,7 @@ void BalanceCompanionMatrix(Matrix* companion_matrix_ptr) { void BuildCompanionMatrix(const Vector& polynomial, Matrix* companion_matrix_ptr) { - CHECK_NOTNULL(companion_matrix_ptr); + CHECK(companion_matrix_ptr != nullptr); Matrix& companion_matrix = *companion_matrix_ptr; const int degree = polynomial.size() - 1; diff --git a/internal/ceres/preconditioner.cc b/internal/ceres/preconditioner.cc index 82621dae5..f98374e0c 100644 --- a/internal/ceres/preconditioner.cc +++ b/internal/ceres/preconditioner.cc @@ -49,7 +49,8 @@ PreconditionerType Preconditioner::PreconditionerForZeroEBlocks( SparseMatrixPreconditionerWrapper::SparseMatrixPreconditionerWrapper( const SparseMatrix* matrix) - : matrix_(CHECK_NOTNULL(matrix)) { + : matrix_(matrix) { + CHECK(matrix != nullptr); } SparseMatrixPreconditionerWrapper::~SparseMatrixPreconditionerWrapper() { diff --git a/internal/ceres/problem_impl.cc b/internal/ceres/problem_impl.cc index 984e3ca0b..6fd6f7b7b 100644 --- a/internal/ceres/problem_impl.cc +++ b/internal/ceres/problem_impl.cc @@ -185,7 +185,7 @@ ParameterBlock* ProblemImpl::InternalAddParameterBlock(double* values, } void ProblemImpl::InternalRemoveResidualBlock(ResidualBlock* residual_block) { - CHECK_NOTNULL(residual_block); + CHECK(residual_block != nullptr); // Perform no check on the validity of residual_block, that is handled in // the public method: RemoveResidualBlock(). @@ -290,7 +290,7 @@ ResidualBlock* ProblemImpl::AddResidualBlock( CostFunction* cost_function, LossFunction* loss_function, const vector& parameter_blocks) { - CHECK_NOTNULL(cost_function); + CHECK(cost_function != nullptr); CHECK_EQ(parameter_blocks.size(), cost_function->parameter_block_sizes().size()); @@ -562,7 +562,7 @@ void ProblemImpl::DeleteBlockInVector(vector* mutable_blocks, } void ProblemImpl::RemoveResidualBlock(ResidualBlock* residual_block) { - CHECK_NOTNULL(residual_block); + CHECK(residual_block != nullptr); // Verify that residual_block identifies a residual in the current problem. const string residual_not_found_message = @@ -958,7 +958,7 @@ bool ProblemImpl::HasParameterBlock(const double* parameter_block) const { } void ProblemImpl::GetParameterBlocks(vector* parameter_blocks) const { - CHECK_NOTNULL(parameter_blocks); + CHECK(parameter_blocks != nullptr); parameter_blocks->resize(0); parameter_blocks->reserve(parameter_block_map_.size()); for (const auto& entry : parameter_block_map_) { @@ -968,7 +968,7 @@ void ProblemImpl::GetParameterBlocks(vector* parameter_blocks) const { void ProblemImpl::GetResidualBlocks( vector* residual_blocks) const { - CHECK_NOTNULL(residual_blocks); + CHECK(residual_blocks != nullptr); *residual_blocks = program().residual_blocks(); } @@ -976,7 +976,8 @@ void ProblemImpl::GetParameterBlocksForResidualBlock( const ResidualBlockId residual_block, vector* parameter_blocks) const { int num_parameter_blocks = residual_block->NumParameterBlocks(); - CHECK_NOTNULL(parameter_blocks)->resize(num_parameter_blocks); + CHECK(parameter_blocks != nullptr); + parameter_blocks->resize(num_parameter_blocks); for (int i = 0; i < num_parameter_blocks; ++i) { (*parameter_blocks)[i] = residual_block->parameter_blocks()[i]->mutable_user_state(); @@ -1007,8 +1008,8 @@ void ProblemImpl::GetResidualBlocksForParameterBlock( if (options_.enable_fast_removal) { // In this case the residual blocks that depend on the parameter block are // stored in the parameter block already, so just copy them out. - CHECK_NOTNULL(residual_blocks)->resize( - parameter_block->mutable_residual_blocks()->size()); + CHECK(residual_blocks != nullptr); + residual_blocks->resize(parameter_block->mutable_residual_blocks()->size()); std::copy(parameter_block->mutable_residual_blocks()->begin(), parameter_block->mutable_residual_blocks()->end(), residual_blocks->begin()); @@ -1016,7 +1017,8 @@ void ProblemImpl::GetResidualBlocksForParameterBlock( } // Find residual blocks that depend on the parameter block. - CHECK_NOTNULL(residual_blocks)->clear(); + CHECK(residual_blocks != nullptr); + residual_blocks->clear(); const int num_residual_blocks = NumResidualBlocks(); for (int i = 0; i < num_residual_blocks; ++i) { ResidualBlock* residual_block = diff --git a/internal/ceres/problem_test.cc b/internal/ceres/problem_test.cc index cdc0ef501..937f84e00 100644 --- a/internal/ceres/problem_test.cc +++ b/internal/ceres/problem_test.cc @@ -128,7 +128,7 @@ TEST(Problem, AddResidualWithNullCostFunctionDies) { problem.AddParameterBlock(z, 5); EXPECT_DEATH_IF_SUPPORTED(problem.AddResidualBlock(NULL, NULL, x), - "'cost_function' Must be non NULL"); + "cost_function != nullptr"); } TEST(Problem, AddResidualWithIncorrectNumberOfParameterBlocksDies) { @@ -1097,7 +1097,8 @@ class QuadraticCostFunction : public CostFunction { // Convert a CRSMatrix to a dense Eigen matrix. void CRSToDenseMatrix(const CRSMatrix& input, Matrix* output) { - Matrix& m = *CHECK_NOTNULL(output); + CHECK(output != nullptr); + Matrix& m = *output; m.resize(input.num_rows, input.num_cols); m.setZero(); for (int row = 0; row < input.num_rows; ++row) { diff --git a/internal/ceres/program.cc b/internal/ceres/program.cc index 994c5aa63..f1cd1bbdb 100644 --- a/internal/ceres/program.cc +++ b/internal/ceres/program.cc @@ -181,7 +181,7 @@ bool Program::IsValid() const { } bool Program::ParameterBlocksAreFinite(string* message) const { - CHECK_NOTNULL(message); + CHECK(message != nullptr); for (int i = 0; i < parameter_blocks_.size(); ++i) { const ParameterBlock* parameter_block = parameter_blocks_[i]; const double* array = parameter_block->user_state(); @@ -220,7 +220,7 @@ bool Program::IsBoundsConstrained() const { } bool Program::IsFeasible(string* message) const { - CHECK_NOTNULL(message); + CHECK(message != nullptr); for (int i = 0; i < parameter_blocks_.size(); ++i) { const ParameterBlock* parameter_block = parameter_blocks_[i]; const double* parameters = parameter_block->user_state(); @@ -273,9 +273,9 @@ 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); + CHECK(removed_parameter_blocks != nullptr); + CHECK(fixed_cost != nullptr); + CHECK(error != nullptr); std::unique_ptr reduced_program(new Program(*this)); if (!reduced_program->RemoveFixedBlocks(removed_parameter_blocks, @@ -291,9 +291,9 @@ Program* Program::CreateReducedProgram( bool Program::RemoveFixedBlocks(vector* removed_parameter_blocks, double* fixed_cost, string* error) { - CHECK_NOTNULL(removed_parameter_blocks); - CHECK_NOTNULL(fixed_cost); - CHECK_NOTNULL(error); + CHECK(removed_parameter_blocks != nullptr); + CHECK(fixed_cost != nullptr); + CHECK(error != nullptr); std::unique_ptr residual_block_evaluate_scratch; residual_block_evaluate_scratch.reset( diff --git a/internal/ceres/program_test.cc b/internal/ceres/program_test.cc index 677848496..52eaa4069 100644 --- a/internal/ceres/program_test.cc +++ b/internal/ceres/program_test.cc @@ -97,11 +97,8 @@ TEST(Program, RemoveFixedBlocksNothingConstant) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); EXPECT_EQ(reduced_program->NumParameterBlocks(), 3); EXPECT_EQ(reduced_program->NumResidualBlocks(), 3); @@ -121,11 +118,9 @@ TEST(Program, RemoveFixedBlocksAllParameterBlocksConstant) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); + EXPECT_EQ(reduced_program->NumParameterBlocks(), 0); EXPECT_EQ(reduced_program->NumResidualBlocks(), 0); EXPECT_EQ(removed_parameter_blocks.size(), 1); @@ -148,11 +143,8 @@ TEST(Program, RemoveFixedBlocksNoResidualBlocks) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); EXPECT_EQ(reduced_program->NumParameterBlocks(), 0); EXPECT_EQ(reduced_program->NumResidualBlocks(), 0); EXPECT_EQ(removed_parameter_blocks.size(), 3); @@ -177,11 +169,8 @@ TEST(Program, RemoveFixedBlocksOneParameterBlockConstant) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); EXPECT_EQ(reduced_program->NumParameterBlocks(), 1); EXPECT_EQ(reduced_program->NumResidualBlocks(), 1); } @@ -204,11 +193,8 @@ TEST(Program, RemoveFixedBlocksNumEliminateBlocks) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); EXPECT_EQ(reduced_program->NumParameterBlocks(), 2); EXPECT_EQ(reduced_program->NumResidualBlocks(), 2); } @@ -243,11 +229,8 @@ TEST(Program, RemoveFixedBlocksFixedCost) { double fixed_cost = 0.0; string message; std::unique_ptr reduced_program( - CHECK_NOTNULL(problem - .program() - .CreateReducedProgram(&removed_parameter_blocks, - &fixed_cost, - &message))); + problem.program().CreateReducedProgram( + &removed_parameter_blocks, &fixed_cost, &message)); EXPECT_EQ(reduced_program->NumParameterBlocks(), 2); EXPECT_EQ(reduced_program->NumResidualBlocks(), 2); diff --git a/internal/ceres/residual_block.cc b/internal/ceres/residual_block.cc index f73d54f6e..7582e92b2 100644 --- a/internal/ceres/residual_block.cc +++ b/internal/ceres/residual_block.cc @@ -50,16 +50,14 @@ namespace ceres { namespace internal { ResidualBlock::ResidualBlock( - const CostFunction* cost_function, - const LossFunction* loss_function, - const std::vector& parameter_blocks, - int index) - : cost_function_(CHECK_NOTNULL(cost_function)), + 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_( - new ParameterBlock* [ - cost_function->parameter_block_sizes().size()]), + new ParameterBlock*[cost_function->parameter_block_sizes().size()]), index_(index) { + CHECK(cost_function_ != nullptr); std::copy(parameter_blocks.begin(), parameter_blocks.end(), parameter_blocks_.get()); diff --git a/internal/ceres/residual_block_utils.cc b/internal/ceres/residual_block_utils.cc index dd2bd73a6..35e928bbc 100644 --- a/internal/ceres/residual_block_utils.cc +++ b/internal/ceres/residual_block_utils.cc @@ -68,8 +68,8 @@ string EvaluationToString(const ResidualBlock& block, double* cost, double* residuals, double** jacobians) { - CHECK_NOTNULL(cost); - CHECK_NOTNULL(residuals); + CHECK(cost != nullptr); + CHECK(residuals != nullptr); const int num_parameter_blocks = block.NumParameterBlocks(); const int num_residuals = block.NumResiduals(); diff --git a/internal/ceres/schur_complement_solver.cc b/internal/ceres/schur_complement_solver.cc index e051b9842..cf6e46ccd 100644 --- a/internal/ceres/schur_complement_solver.cc +++ b/internal/ceres/schur_complement_solver.cc @@ -131,7 +131,8 @@ LinearSolver::Summary SchurComplementSolver::SolveImpl( &options_.row_block_size, &options_.e_block_size, &options_.f_block_size); - eliminator_.reset(CHECK_NOTNULL(SchurEliminatorBase::Create(options_))); + eliminator_.reset(SchurEliminatorBase::Create(options_)); + CHECK(eliminator_ != nullptr); const bool kFullRankETE = true; eliminator_->Init( options_.elimination_groups[0], kFullRankETE, A->block_structure()); @@ -378,16 +379,14 @@ SparseSchurComplementSolver::SolveReducedLinearSystemUsingConjugateGradients( int sc_r, sc_c, sc_row_stride, sc_col_stride; CellInfo* sc_cell_info = - CHECK_NOTNULL(sc->GetCell(i, i, - &sc_r, &sc_c, - &sc_row_stride, &sc_col_stride)); + sc->GetCell(i, i, &sc_r, &sc_c, &sc_row_stride, &sc_col_stride); + CHECK(sc_cell_info != nullptr); MatrixRef sc_m(sc_cell_info->values, sc_row_stride, sc_col_stride); int pre_r, pre_c, pre_row_stride, pre_col_stride; - CellInfo* pre_cell_info = CHECK_NOTNULL( - preconditioner_->GetCell(i, i, - &pre_r, &pre_c, - &pre_row_stride, &pre_col_stride)); + CellInfo* pre_cell_info = preconditioner_->GetCell( + i, i, &pre_r, &pre_c, &pre_row_stride, &pre_col_stride); + CHECK(pre_cell_info != nullptr); MatrixRef pre_m(pre_cell_info->values, pre_row_stride, pre_col_stride); pre_m.block(pre_r, pre_c, block_size, block_size) = diff --git a/internal/ceres/schur_complement_solver_test.cc b/internal/ceres/schur_complement_solver_test.cc index a86c8ef2c..23d36747c 100644 --- a/internal/ceres/schur_complement_solver_test.cc +++ b/internal/ceres/schur_complement_solver_test.cc @@ -54,7 +54,7 @@ class SchurComplementSolverTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(problem_id)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A.reset(down_cast(problem->A.release())); b.reset(problem->b.release()); D.reset(problem->D.release()); diff --git a/internal/ceres/schur_eliminator.h b/internal/ceres/schur_eliminator.h index deae5a5d0..0baea93a5 100644 --- a/internal/ceres/schur_eliminator.h +++ b/internal/ceres/schur_eliminator.h @@ -225,8 +225,9 @@ class SchurEliminator : public SchurEliminatorBase { public: explicit SchurEliminator(const LinearSolver::Options& options) : num_threads_(options.num_threads), - context_(CHECK_NOTNULL(options.context)) { - } + context_(options.context) { + CHECK(context_ != nullptr); +} // SchurEliminatorBase Interface virtual ~SchurEliminator(); diff --git a/internal/ceres/schur_eliminator_test.cc b/internal/ceres/schur_eliminator_test.cc index 6197bfc34..2e8492f92 100644 --- a/internal/ceres/schur_eliminator_test.cc +++ b/internal/ceres/schur_eliminator_test.cc @@ -56,7 +56,7 @@ class SchurEliminatorTest : public ::testing::Test { void SetUpFromId(int id) { std::unique_ptr problem(CreateLinearLeastSquaresProblemFromId(id)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); SetupHelper(problem.get()); } diff --git a/internal/ceres/single_linkage_clustering.cc b/internal/ceres/single_linkage_clustering.cc index 2d3213a03..394492cdf 100644 --- a/internal/ceres/single_linkage_clustering.cc +++ b/internal/ceres/single_linkage_clustering.cc @@ -42,7 +42,8 @@ int ComputeSingleLinkageClustering( const SingleLinkageClusteringOptions& options, const WeightedGraph& graph, std::unordered_map* membership) { - CHECK_NOTNULL(membership)->clear(); + CHECK(membership != nullptr); + membership->clear(); // Initially each vertex is in its own cluster. const std::unordered_set& vertices = graph.vertices(); diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc index 7ac60ac99..f8ad2c91e 100644 --- a/internal/ceres/solver.cc +++ b/internal/ceres/solver.cc @@ -481,8 +481,8 @@ void Solver::Solve(const Solver::Options& options, using internal::Program; using internal::WallTimeInSeconds; - CHECK_NOTNULL(problem); - CHECK_NOTNULL(summary); + CHECK(problem != nullptr); + CHECK(summary != nullptr); double start_time = WallTimeInSeconds(); *summary = Summary(); diff --git a/internal/ceres/sparse_normal_cholesky_solver_test.cc b/internal/ceres/sparse_normal_cholesky_solver_test.cc index aa9dc627e..c4b4a0b82 100644 --- a/internal/ceres/sparse_normal_cholesky_solver_test.cc +++ b/internal/ceres/sparse_normal_cholesky_solver_test.cc @@ -57,7 +57,7 @@ class SparseNormalCholeskySolverTest : public ::testing::Test { std::unique_ptr problem( CreateLinearLeastSquaresProblemFromId(2)); - CHECK_NOTNULL(problem.get()); + CHECK(problem != nullptr); A_.reset(down_cast(problem->A.release())); b_.reset(problem->b.release()); D_.reset(problem->D.release()); diff --git a/internal/ceres/subset_preconditioner.cc b/internal/ceres/subset_preconditioner.cc index de6e9fa08..865c5f13f 100644 --- a/internal/ceres/subset_preconditioner.cc +++ b/internal/ceres/subset_preconditioner.cc @@ -56,8 +56,8 @@ SubsetPreconditioner::SubsetPreconditioner( SubsetPreconditioner::~SubsetPreconditioner() {} void SubsetPreconditioner::RightMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); + CHECK(x != nullptr); + CHECK(y != nullptr); std::string message; sparse_cholesky_->Solve(x, y, &message); } diff --git a/internal/ceres/suitesparse.cc b/internal/ceres/suitesparse.cc index f10f57ea0..190d1755a 100644 --- a/internal/ceres/suitesparse.cc +++ b/internal/ceres/suitesparse.cc @@ -164,7 +164,8 @@ cholmod_factor* SuiteSparse::AnalyzeCholesky(cholmod_sparse* A, return nullptr; } - return CHECK_NOTNULL(factor); + CHECK(factor != nullptr); + return factor; } cholmod_factor* SuiteSparse::BlockAnalyzeCholesky(cholmod_sparse* A, @@ -196,7 +197,8 @@ cholmod_factor* SuiteSparse::AnalyzeCholeskyWithUserOrdering( return nullptr; } - return CHECK_NOTNULL(factor); + CHECK(factor != nullptr); + return factor; } cholmod_factor* SuiteSparse::AnalyzeCholeskyWithNaturalOrdering( @@ -215,7 +217,8 @@ cholmod_factor* SuiteSparse::AnalyzeCholeskyWithNaturalOrdering( return nullptr; } - return CHECK_NOTNULL(factor); + CHECK(factor != nullptr); + return factor; } bool SuiteSparse::BlockAMDOrdering(const cholmod_sparse* A, @@ -262,8 +265,8 @@ bool SuiteSparse::BlockAMDOrdering(const cholmod_sparse* A, LinearSolverTerminationType SuiteSparse::Cholesky(cholmod_sparse* A, cholmod_factor* L, string* message) { - CHECK_NOTNULL(A); - CHECK_NOTNULL(L); + CHECK(A != nullptr); + CHECK(L != nullptr); // Save the current print level and silence CHOLMOD, otherwise // CHOLMOD is prone to dumping stuff to stderr, which can be diff --git a/internal/ceres/triplet_sparse_matrix.cc b/internal/ceres/triplet_sparse_matrix.cc index bbb35d2a7..15b96749d 100644 --- a/internal/ceres/triplet_sparse_matrix.cc +++ b/internal/ceres/triplet_sparse_matrix.cc @@ -178,7 +178,7 @@ void TripletSparseMatrix::LeftMultiply(const double* x, double* y) const { } void TripletSparseMatrix::SquaredColumnNorm(double* x) const { - CHECK_NOTNULL(x); + CHECK(x != nullptr); VectorRef(x, num_cols_).setZero(); for (int i = 0; i < num_nonzeros_; ++i) { x[cols_[i]] += values_[i] * values_[i]; @@ -186,7 +186,7 @@ void TripletSparseMatrix::SquaredColumnNorm(double* x) const { } void TripletSparseMatrix::ScaleColumns(const double* scale) { - CHECK_NOTNULL(scale); + CHECK(scale != nullptr); for (int i = 0; i < num_nonzeros_; ++i) { values_[i] = values_[i] * scale[cols_[i]]; } @@ -267,7 +267,7 @@ TripletSparseMatrix* TripletSparseMatrix::CreateSparseDiagonalMatrix( } void TripletSparseMatrix::ToTextFile(FILE* file) const { - CHECK_NOTNULL(file); + CHECK(file != nullptr); for (int i = 0; i < num_nonzeros_; ++i) { fprintf(file, "% 10d % 10d %17f\n", rows_[i], cols_[i], values_[i]); } diff --git a/internal/ceres/trust_region_minimizer.cc b/internal/ceres/trust_region_minimizer.cc index cd57abff7..e3d70b005 100644 --- a/internal/ceres/trust_region_minimizer.cc +++ b/internal/ceres/trust_region_minimizer.cc @@ -136,9 +136,12 @@ void TrustRegionMinimizer::Init(const Minimizer::Options& options, solver_summary_->num_unsuccessful_steps = 0; solver_summary_->is_constrained = options.is_constrained; - evaluator_ = CHECK_NOTNULL(options_.evaluator.get()); - jacobian_ = CHECK_NOTNULL(options_.jacobian.get()); - strategy_ = CHECK_NOTNULL(options_.trust_region_strategy.get()); + CHECK(options_.evaluator != nullptr); + CHECK(options_.jacobian != nullptr); + CHECK(options_.trust_region_strategy != nullptr); + evaluator_ = options_.evaluator.get(); + jacobian_ = options_.jacobian.get(); + strategy_ = options_.trust_region_strategy.get(); is_not_silent_ = !options.is_silent; inner_iterations_are_enabled_ = @@ -574,8 +577,8 @@ void TrustRegionMinimizer::DoLineSearch(const Vector& x, line_search_options.function = &line_search_function; std::string message; - std::unique_ptr line_search(CHECK_NOTNULL( - LineSearch::Create(ceres::ARMIJO, line_search_options, &message))); + std::unique_ptr line_search( + LineSearch::Create(ceres::ARMIJO, line_search_options, &message)); LineSearch::Summary line_search_summary; line_search_function.Init(x, *delta); line_search->Search(1.0, cost, gradient.dot(*delta), &line_search_summary); diff --git a/internal/ceres/trust_region_preprocessor.cc b/internal/ceres/trust_region_preprocessor.cc index cca2cf73a..aa7f095f2 100644 --- a/internal/ceres/trust_region_preprocessor.cc +++ b/internal/ceres/trust_region_preprocessor.cc @@ -334,7 +334,8 @@ void SetupMinimizerOptions(PreprocessedProblem* pp) { options.trust_region_strategy_type; strategy_options.dogleg_type = options.dogleg_type; pp->minimizer_options.trust_region_strategy.reset( - CHECK_NOTNULL(TrustRegionStrategy::Create(strategy_options))); + TrustRegionStrategy::Create(strategy_options)); + CHECK(pp->minimizer_options.trust_region_strategy != nullptr); } } // namespace @@ -345,7 +346,7 @@ TrustRegionPreprocessor::~TrustRegionPreprocessor() { bool TrustRegionPreprocessor::Preprocess(const Solver::Options& options, ProblemImpl* problem, PreprocessedProblem* pp) { - CHECK_NOTNULL(pp); + CHECK(pp != nullptr); pp->options = options; ChangeNumThreadsIfNeeded(&pp->options); diff --git a/internal/ceres/visibility.cc b/internal/ceres/visibility.cc index aa195b9bf..72a1c337e 100644 --- a/internal/ceres/visibility.cc +++ b/internal/ceres/visibility.cc @@ -54,7 +54,7 @@ using std::vector; void ComputeVisibility(const CompressedRowBlockStructure& block_structure, const int num_eliminate_blocks, vector>* visibility) { - CHECK_NOTNULL(visibility); + CHECK(visibility != nullptr); // Clear the visibility vector and resize it to hold a // vector for each camera. diff --git a/internal/ceres/visibility_based_preconditioner.cc b/internal/ceres/visibility_based_preconditioner.cc index 5eebb697f..41079aba0 100644 --- a/internal/ceres/visibility_based_preconditioner.cc +++ b/internal/ceres/visibility_based_preconditioner.cc @@ -162,10 +162,12 @@ void VisibilityBasedPreconditioner::ComputeClusterTridiagonalSparsity( // maximum spanning forest of this graph. vector> cluster_visibility; ComputeClusterVisibility(visibility, &cluster_visibility); - std::unique_ptr > cluster_graph( - CHECK_NOTNULL(CreateClusterGraph(cluster_visibility))); - std::unique_ptr > forest( - CHECK_NOTNULL(Degree2MaximumSpanningForest(*cluster_graph))); + std::unique_ptr> cluster_graph( + CreateClusterGraph(cluster_visibility)); + CHECK(cluster_graph != nullptr); + std::unique_ptr> forest( + Degree2MaximumSpanningForest(*cluster_graph)); + CHECK(forest != nullptr); ForestToClusterPairs(*forest, &cluster_pairs_); } @@ -184,8 +186,9 @@ void VisibilityBasedPreconditioner::InitStorage( // memberships for each camera block. void VisibilityBasedPreconditioner::ClusterCameras( const vector >& visibility) { - std::unique_ptr > schur_complement_graph( - CHECK_NOTNULL(CreateSchurComplementGraph(visibility))); + std::unique_ptr> schur_complement_graph( + CreateSchurComplementGraph(visibility)); + CHECK(schur_complement_graph != nullptr); std::unordered_map membership; @@ -430,9 +433,9 @@ LinearSolverTerminationType VisibilityBasedPreconditioner::Factorize() { void VisibilityBasedPreconditioner::RightMultiply(const double* x, double* y) const { - CHECK_NOTNULL(x); - CHECK_NOTNULL(y); - CHECK_NOTNULL(sparse_cholesky_.get()); + CHECK(x != nullptr); + CHECK(y != nullptr); + CHECK(sparse_cholesky_ != nullptr); std::string message; sparse_cholesky_->Solve(x, y, &message); } @@ -462,7 +465,8 @@ bool VisibilityBasedPreconditioner::IsBlockPairOffDiagonal( void VisibilityBasedPreconditioner::ForestToClusterPairs( const WeightedGraph& forest, std::unordered_set, pair_hash >* cluster_pairs) const { - CHECK_NOTNULL(cluster_pairs)->clear(); + CHECK(cluster_pairs != nullptr); + cluster_pairs->clear(); const std::unordered_set& vertices = forest.vertices(); CHECK_EQ(vertices.size(), num_clusters_); @@ -485,7 +489,8 @@ void VisibilityBasedPreconditioner::ForestToClusterPairs( void VisibilityBasedPreconditioner::ComputeClusterVisibility( const vector>& visibility, vector>* cluster_visibility) const { - CHECK_NOTNULL(cluster_visibility)->resize(0); + CHECK(cluster_visibility != nullptr); + cluster_visibility->resize(0); cluster_visibility->resize(num_clusters_); for (int i = 0; i < num_blocks_; ++i) { const int cluster_id = cluster_membership_[i]; @@ -540,7 +545,8 @@ WeightedGraph* VisibilityBasedPreconditioner::CreateClusterGraph( void VisibilityBasedPreconditioner::FlattenMembershipMap( const std::unordered_map& membership_map, vector* membership_vector) const { - CHECK_NOTNULL(membership_vector)->resize(0); + CHECK(membership_vector != nullptr); + membership_vector->resize(0); membership_vector->resize(num_blocks_, -1); std::unordered_map cluster_id_to_index;