Commit a2e19f16 authored by Sameer Agarwal's avatar Sameer Agarwal
Browse files

Fix example code in the documentation.

The example code for DynamicNumericDiffCostFunction and
DynamicAutoDiffCostFunction in the documentation was
allocating the cost function objects on the stack rather
than the heap.

Thanks to Rodney Hoskinson for reporting this.

Change-Id: I217aee02d1e2c1e9c25b8197451e9f9e0482915d
Showing with 10 additions and 9 deletions
+10 -9
......@@ -332,11 +332,12 @@ the corresponding accessors. This information will be verified by the
.. code-block:: c++
DynamicAutoDiffCostFunction<MyCostFunctor, 4> cost_function(
DynamicAutoDiffCostFunction<MyCostFunctor, 4>* cost_function =
new DynamicAutoDiffCostFunction<MyCostFunctor, 4>(
new MyCostFunctor());
cost_function.AddParameterBlock(5);
cost_function.AddParameterBlock(10);
cost_function.SetNumResiduals(21);
cost_function->AddParameterBlock(5);
cost_function->AddParameterBlock(10);
cost_function->SetNumResiduals(21);
Under the hood, the implementation evaluates the cost function
multiple times, computing a small set of the derivatives (four by
......@@ -561,11 +562,11 @@ the corresponding accessors. This information will be verified by the
.. code-block:: c++
DynamicNumericDiffCostFunction<MyCostFunctor> cost_function(
new MyCostFunctor());
cost_function.AddParameterBlock(5);
cost_function.AddParameterBlock(10);
cost_function.SetNumResiduals(21);
DynamicNumericDiffCostFunction<MyCostFunctor>* cost_function =
new DynamicNumericDiffCostFunction<MyCostFunctor>(new MyCostFunctor);
cost_function->AddParameterBlock(5);
cost_function->AddParameterBlock(10);
cost_function->SetNumResiduals(21);
As a rule of thumb, try using :class:`NumericDiffCostFunction` before
you use :class:`DynamicNumericDiffCostFunction`.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment