From ab4ed32cda004befd29a0b4b02f1d907e0c4dab7 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Mon, 3 Aug 2020 04:17:33 -0700 Subject: [PATCH] Replace NULL with nullptr in the documentation. Change-Id: I995f68770e2a4b6027c0a1d3edf5eb5132b081d7 --- docs/source/gradient_solver.rst | 4 +-- docs/source/gradient_tutorial.rst | 2 +- docs/source/interfacing_with_autodiff.rst | 2 +- docs/source/nnls_modeling.rst | 38 +++++++++++------------ docs/source/nnls_tutorial.rst | 22 ++++++------- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/source/gradient_solver.rst b/docs/source/gradient_solver.rst index 1356e7475..dde9d7e1a 100644 --- a/docs/source/gradient_solver.rst +++ b/docs/source/gradient_solver.rst @@ -33,10 +33,10 @@ Modeling .. function:: bool FirstOrderFunction::Evaluate(const double* const parameters, double* cost, double* gradient) const Evaluate the cost/value of the function. If ``gradient`` is not - ``NULL`` then evaluate the gradient too. If evaluation is + ``nullptr`` then evaluate the gradient too. If evaluation is successful return, ``true`` else return ``false``. - ``cost`` guaranteed to be never ``NULL``, ``gradient`` can be ``NULL``. + ``cost`` guaranteed to be never ``nullptr``, ``gradient`` can be ``nullptr``. .. function:: int FirstOrderFunction::NumParameters() const diff --git a/docs/source/gradient_tutorial.rst b/docs/source/gradient_tutorial.rst index 0bbdee45c..3fef6b64e 100644 --- a/docs/source/gradient_tutorial.rst +++ b/docs/source/gradient_tutorial.rst @@ -40,7 +40,7 @@ squares problems in Ceres. const double y = parameters[1]; cost[0] = (1.0 - x) * (1.0 - x) + 100.0 * (y - x * x) * (y - x * x); - if (gradient != NULL) { + if (gradient != nullptr) { gradient[0] = -2.0 * (1.0 - x) - 200.0 * (y - x * x) * 2.0 * x; gradient[1] = 200.0 * (y - x * x); } diff --git a/docs/source/interfacing_with_autodiff.rst b/docs/source/interfacing_with_autodiff.rst index b79ed457d..02f58b2d1 100644 --- a/docs/source/interfacing_with_autodiff.rst +++ b/docs/source/interfacing_with_autodiff.rst @@ -181,7 +181,7 @@ The resulting code will look as follows: double* residuals, double** jacobians) const { if (!jacobians) { - ComputeDistortionValueAndJacobian(parameters[0][0], residuals, NULL); + ComputeDistortionValueAndJacobian(parameters[0][0], residuals, nullptr); } else { ComputeDistortionValueAndJacobian(parameters[0][0], residuals, jacobians[0]); } diff --git a/docs/source/nnls_modeling.rst b/docs/source/nnls_modeling.rst index 257c5eb3e..593fcab72 100644 --- a/docs/source/nnls_modeling.rst +++ b/docs/source/nnls_modeling.rst @@ -108,29 +108,29 @@ the corresponding accessors. This information will be verified by the that contains the :math:`i^{\text{th}}` parameter block that the ``CostFunction`` depends on. - ``parameters`` is never ``NULL``. + ``parameters`` is never ``nullptr``. ``residuals`` is an array of size ``num_residuals_``. - ``residuals`` is never ``NULL``. + ``residuals`` is never ``nullptr``. ``jacobians`` is an array of arrays of size ``CostFunction::parameter_block_sizes_.size()``. - If ``jacobians`` is ``NULL``, the user is only expected to compute + If ``jacobians`` is ``nullptr``, the user is only expected to compute the residuals. ``jacobians[i]`` is a row-major array of size ``num_residuals x parameter_block_sizes_[i]``. - If ``jacobians[i]`` is **not** ``NULL``, the user is required to + If ``jacobians[i]`` is **not** ``nullptr``, the user is required to compute the Jacobian of the residual vector with respect to ``parameters[i]`` and store it in this array, i.e. ``jacobians[i][r * parameter_block_sizes_[i] + c]`` = :math:`\frac{\displaystyle \partial \text{residual}[r]}{\displaystyle \partial \text{parameters}[i][c]}` - If ``jacobians[i]`` is ``NULL``, then this computation can be + If ``jacobians[i]`` is ``nullptr``, then this computation can be skipped. This is the case when the corresponding parameter block is marked constant. @@ -914,7 +914,7 @@ Numeric Differentiation & LocalParameterization std::vector local_parameterizations; local_parameterizations.push_back(my_parameterization); - local_parameterizations.push_back(NULL); + local_parameterizations.push_back(nullptr); std::vector parameter1; std::vector parameter2; @@ -1109,8 +1109,8 @@ their shape graphically. More details can be found in Given a loss function :math:`\rho(s)` and a scalar :math:`a`, :class:`ScaledLoss` implements the function :math:`a \rho(s)`. - Since we treat a ``NULL`` Loss function as the Identity loss - function, :math:`rho` = ``NULL``: is a valid input and will result + Since we treat a ``nullptr`` Loss function as the Identity loss + function, :math:`rho` = ``nullptr``: is a valid input and will result in the input being scaled by :math:`a`. This provides a simple way of implementing a scaled ResidualBlock. @@ -1587,7 +1587,7 @@ quaternion, a local parameterization can be constructed as the parameter blocks it expects. The function checks that these match the sizes of the parameter blocks listed in ``parameter_blocks``. The program aborts if a mismatch is - detected. ``loss_function`` can be ``NULL``, in which case the cost + detected. ``loss_function`` can be ``nullptr``, in which case the cost of the term is just the squared norm of the residuals. The user has the option of explicitly adding the parameter blocks @@ -1752,7 +1752,7 @@ quaternion, a local parameterization can be constructed as parameter blocks it expects. The function checks that these match the sizes of the parameter blocks listed in parameter_blocks. The program aborts if a mismatch is detected. loss_function can be - NULL, in which case the cost of the term is just the squared norm + nullptr, in which case the cost of the term is just the squared norm of the residuals. The parameter blocks may be passed together as a @@ -1791,10 +1791,10 @@ quaternion, a local parameterization can be constructed as Problem problem; - problem.AddResidualBlock(new MyUnaryCostFunction(...), NULL, x1); - problem.AddResidualBlock(new MyBinaryCostFunction(...), NULL, x2, x1); - problem.AddResidualBlock(new MyUnaryCostFunction(...), NULL, v1); - problem.AddResidualBlock(new MyBinaryCostFunction(...), NULL, v2); + problem.AddResidualBlock(new MyUnaryCostFunction(...), nullptr, x1); + problem.AddResidualBlock(new MyBinaryCostFunction(...), nullptr, x2, x1); + problem.AddResidualBlock(new MyUnaryCostFunction(...), nullptr, v1); + problem.AddResidualBlock(new MyBinaryCostFunction(...), nullptr, v2); .. function:: void Problem::AddParameterBlock(double* values, int size, LocalParameterization* local_parameterization) @@ -1871,7 +1871,7 @@ quaternion, a local parameterization can be constructed as Get the local parameterization object associated with this parameter block. If there is no parameterization object associated - then `NULL` is returned + then `nullptr` is returned .. function:: void Problem::SetParameterLowerBound(double* values, int index, double lower_bound) @@ -2018,7 +2018,7 @@ quaternion, a local parameterization can be constructed as .. function:: bool Problem::Evaluate(const Problem::EvaluateOptions& options, double* cost, vector* residuals, vector* gradient, CRSMatrix* jacobian) Evaluate a :class:`Problem`. Any of the output pointers can be - `NULL`. Which residual blocks and parameter blocks are used is + `nullptr`. Which residual blocks and parameter blocks are used is controlled by the :class:`Problem::EvaluateOptions` struct below. .. NOTE:: @@ -2032,10 +2032,10 @@ quaternion, a local parameterization can be constructed as Problem problem; double x = 1; - problem.Add(new MyCostFunction, NULL, &x); + problem.Add(new MyCostFunction, nullptr, &x); double cost = 0.0; - problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); + problem.Evaluate(Problem::EvaluateOptions(), &cost, nullptr, nullptr, nullptr); The cost is evaluated at `x = 1`. If you wish to evaluate the problem at `x = 2`, then @@ -2043,7 +2043,7 @@ quaternion, a local parameterization can be constructed as .. code-block:: c++ x = 2; - problem.Evaluate(Problem::EvaluateOptions(), &cost, NULL, NULL, NULL); + problem.Evaluate(Problem::EvaluateOptions(), &cost, nullptr, nullptr, nullptr); is the way to do so. diff --git a/docs/source/nnls_tutorial.rst b/docs/source/nnls_tutorial.rst index fb7059c15..6c89032d3 100644 --- a/docs/source/nnls_tutorial.rst +++ b/docs/source/nnls_tutorial.rst @@ -111,7 +111,7 @@ Ceres solve it. // auto-differentiation to obtain the derivative (jacobian). CostFunction* cost_function = new AutoDiffCostFunction(new CostFunctor); - problem.AddResidualBlock(cost_function, NULL, &x); + problem.AddResidualBlock(cost_function, nullptr, &x); // Run the solver! Solver::Options options; @@ -212,7 +212,7 @@ Which is added to the :class:`Problem` as: CostFunction* cost_function = new NumericDiffCostFunction( new NumericDiffCostFunctor); - problem.AddResidualBlock(cost_function, NULL, &x); + problem.AddResidualBlock(cost_function, nullptr, &x); Notice the parallel from when we were using automatic differentiation @@ -220,7 +220,7 @@ Notice the parallel from when we were using automatic differentiation CostFunction* cost_function = new AutoDiffCostFunction(new CostFunctor); - problem.AddResidualBlock(cost_function, NULL, &x); + problem.AddResidualBlock(cost_function, nullptr, &x); The construction looks almost identical to the one used for automatic differentiation, except for an extra template parameter that indicates @@ -261,7 +261,7 @@ x`. residuals[0] = 10 - x; // Compute the Jacobian if asked for. - if (jacobians != NULL && jacobians[0] != NULL) { + if (jacobians != nullptr && jacobians[0] != nullptr) { jacobians[0][0] = -1; } return true; @@ -358,13 +358,13 @@ respectively. Using these, the problem can be constructed as follows: // Add residual terms to the problem using the using the autodiff // wrapper to get the derivatives automatically. problem.AddResidualBlock( - new AutoDiffCostFunction(new F1), NULL, &x1, &x2); + new AutoDiffCostFunction(new F1), nullptr, &x1, &x2); problem.AddResidualBlock( - new AutoDiffCostFunction(new F2), NULL, &x3, &x4); + new AutoDiffCostFunction(new F2), nullptr, &x3, &x4); problem.AddResidualBlock( - new AutoDiffCostFunction(new F3), NULL, &x2, &x3) + new AutoDiffCostFunction(new F3), nullptr, &x2, &x3) problem.AddResidualBlock( - new AutoDiffCostFunction(new F4), NULL, &x1, &x4); + new AutoDiffCostFunction(new F4), nullptr, &x1, &x4); Note that each ``ResidualBlock`` only depends on the two parameters @@ -496,7 +496,7 @@ Assuming the observations are in a :math:`2n` sized array called CostFunction* cost_function = new AutoDiffCostFunction( new ExponentialResidual(data[2 * i], data[2 * i + 1])); - problem.AddResidualBlock(cost_function, NULL, &m, &c); + problem.AddResidualBlock(cost_function, nullptr, &m, &c); } Compiling and running `examples/curve_fitting.cc @@ -568,7 +568,7 @@ outliers. To associate a loss function with a residual block, we change .. code-block:: c++ - problem.AddResidualBlock(cost_function, NULL , &m, &c); + problem.AddResidualBlock(cost_function, nullptr , &m, &c); to @@ -697,7 +697,7 @@ as follows: bal_problem.observations()[2 * i + 0], bal_problem.observations()[2 * i + 1]); problem.AddResidualBlock(cost_function, - NULL /* squared loss */, + nullptr /* squared loss */, bal_problem.mutable_camera_for_observation(i), bal_problem.mutable_point_for_observation(i)); }