Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 2 | // Copyright 2023 Google Inc. All rights reserved. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 3 | // http://ceres-solver.org/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: keir@google.com (Keir Mierle) |
| 30 | // |
| 31 | // Computation of the Jacobian matrix for vector-valued functions of multiple |
| 32 | // variables, using automatic differentiation based on the implementation of |
| 33 | // dual numbers in jet.h. Before reading the rest of this file, it is advisable |
| 34 | // to read jet.h's header comment in detail. |
| 35 | // |
| 36 | // The helper wrapper AutoDifferentiate() computes the jacobian of |
| 37 | // functors with templated operator() taking this form: |
| 38 | // |
| 39 | // struct F { |
| 40 | // template<typename T> |
| 41 | // bool operator()(const T *x, const T *y, ..., T *z) { |
| 42 | // // Compute z[] based on x[], y[], ... |
| 43 | // // return true if computation succeeded, false otherwise. |
| 44 | // } |
| 45 | // }; |
| 46 | // |
| 47 | // All inputs and outputs may be vector-valued. |
| 48 | // |
| 49 | // To understand how jets are used to compute the jacobian, a |
| 50 | // picture may help. Consider a vector-valued function, F, returning 3 |
| 51 | // dimensions and taking a vector-valued parameter of 4 dimensions: |
| 52 | // |
| 53 | // y x |
| 54 | // [ * ] F [ * ] |
| 55 | // [ * ] <--- [ * ] |
| 56 | // [ * ] [ * ] |
| 57 | // [ * ] |
| 58 | // |
| 59 | // Similar to the 2-parameter example for f described in jet.h, computing the |
| 60 | // jacobian dy/dx is done by substituting a suitable jet object for x and all |
| 61 | // intermediate steps of the computation of F. Since x is has 4 dimensions, use |
| 62 | // a Jet<double, 4>. |
| 63 | // |
| 64 | // Before substituting a jet object for x, the dual components are set |
| 65 | // appropriately for each dimension of x: |
| 66 | // |
| 67 | // y x |
| 68 | // [ * | * * * * ] f [ * | 1 0 0 0 ] x0 |
| 69 | // [ * | * * * * ] <--- [ * | 0 1 0 0 ] x1 |
| 70 | // [ * | * * * * ] [ * | 0 0 1 0 ] x2 |
| 71 | // ---+--- [ * | 0 0 0 1 ] x3 |
| 72 | // | ^ ^ ^ ^ |
| 73 | // dy/dx | | | +----- infinitesimal for x3 |
| 74 | // | | +------- infinitesimal for x2 |
| 75 | // | +--------- infinitesimal for x1 |
| 76 | // +----------- infinitesimal for x0 |
| 77 | // |
| 78 | // The reason to set the internal 4x4 submatrix to the identity is that we wish |
| 79 | // to take the derivative of y separately with respect to each dimension of x. |
| 80 | // Each column of the 4x4 identity is therefore for a single component of the |
| 81 | // independent variable x. |
| 82 | // |
| 83 | // Then the jacobian of the mapping, dy/dx, is the 3x4 sub-matrix of the |
| 84 | // extended y vector, indicated in the above diagram. |
| 85 | // |
| 86 | // Functors with multiple parameters |
| 87 | // --------------------------------- |
| 88 | // In practice, it is often convenient to use a function f of two or more |
| 89 | // vector-valued parameters, for example, x[3] and z[6]. Unfortunately, the jet |
| 90 | // framework is designed for a single-parameter vector-valued input. The wrapper |
| 91 | // in this file addresses this issue adding support for functions with one or |
| 92 | // more parameter vectors. |
| 93 | // |
| 94 | // To support multiple parameters, all the parameter vectors are concatenated |
| 95 | // into one and treated as a single parameter vector, except that since the |
| 96 | // functor expects different inputs, we need to construct the jets as if they |
| 97 | // were part of a single parameter vector. The extended jets are passed |
| 98 | // separately for each parameter. |
| 99 | // |
| 100 | // For example, consider a functor F taking two vector parameters, p[2] and |
| 101 | // q[3], and producing an output y[4]: |
| 102 | // |
| 103 | // struct F { |
| 104 | // template<typename T> |
| 105 | // bool operator()(const T *p, const T *q, T *z) { |
| 106 | // // ... |
| 107 | // } |
| 108 | // }; |
| 109 | // |
| 110 | // In this case, the necessary jet type is Jet<double, 5>. Here is a |
| 111 | // visualization of the jet objects in this case: |
| 112 | // |
| 113 | // Dual components for p ----+ |
| 114 | // | |
| 115 | // -+- |
| 116 | // y [ * | 1 0 | 0 0 0 ] --- p[0] |
| 117 | // [ * | 0 1 | 0 0 0 ] --- p[1] |
| 118 | // [ * | . . | + + + ] | |
| 119 | // [ * | . . | + + + ] v |
| 120 | // [ * | . . | + + + ] <--- F(p, q) |
| 121 | // [ * | . . | + + + ] ^ |
| 122 | // ^^^ ^^^^^ | |
| 123 | // dy/dp dy/dq [ * | 0 0 | 1 0 0 ] --- q[0] |
| 124 | // [ * | 0 0 | 0 1 0 ] --- q[1] |
| 125 | // [ * | 0 0 | 0 0 1 ] --- q[2] |
| 126 | // --+-- |
| 127 | // | |
| 128 | // Dual components for q --------------+ |
| 129 | // |
| 130 | // where the 4x2 submatrix (marked with ".") and 4x3 submatrix (marked with "+" |
| 131 | // of y in the above diagram are the derivatives of y with respect to p and q |
| 132 | // respectively. This is how autodiff works for functors taking multiple vector |
| 133 | // valued arguments (up to 6). |
| 134 | // |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 135 | // Jacobian null pointers (nullptr) |
| 136 | // -------------------------------- |
| 137 | // In general, the functions below will accept nullptr for all or some of the |
| 138 | // Jacobian parameters, meaning that those Jacobians will not be computed. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 139 | |
| 140 | #ifndef CERES_PUBLIC_INTERNAL_AUTODIFF_H_ |
| 141 | #define CERES_PUBLIC_INTERNAL_AUTODIFF_H_ |
| 142 | |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 143 | #include <array> |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 144 | #include <cstddef> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 145 | #include <utility> |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 146 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 147 | #include "ceres/internal/array_selector.h" |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 148 | #include "ceres/internal/eigen.h" |
| 149 | #include "ceres/internal/fixed_array.h" |
| 150 | #include "ceres/internal/parameter_dims.h" |
| 151 | #include "ceres/internal/variadic_evaluate.h" |
| 152 | #include "ceres/jet.h" |
| 153 | #include "ceres/types.h" |
| 154 | #include "glog/logging.h" |
| 155 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 156 | // If the number of parameters exceeds this values, the corresponding jets are |
| 157 | // placed on the heap. This will reduce performance by a factor of 2-5 on |
| 158 | // current compilers. |
| 159 | #ifndef CERES_AUTODIFF_MAX_PARAMETERS_ON_STACK |
| 160 | #define CERES_AUTODIFF_MAX_PARAMETERS_ON_STACK 50 |
| 161 | #endif |
| 162 | |
| 163 | #ifndef CERES_AUTODIFF_MAX_RESIDUALS_ON_STACK |
| 164 | #define CERES_AUTODIFF_MAX_RESIDUALS_ON_STACK 20 |
| 165 | #endif |
| 166 | |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 167 | namespace ceres::internal { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 168 | |
| 169 | // Extends src by a 1st order perturbation for every dimension and puts it in |
| 170 | // dst. The size of src is N. Since this is also used for perturbations in |
| 171 | // blocked arrays, offset is used to shift which part of the jet the |
| 172 | // perturbation occurs. This is used to set up the extended x augmented by an |
| 173 | // identity matrix. The JetT type should be a Jet type, and T should be a |
| 174 | // numeric type (e.g. double). For example, |
| 175 | // |
| 176 | // 0 1 2 3 4 5 6 7 8 |
| 177 | // dst[0] [ * | . . | 1 0 0 | . . . ] |
| 178 | // dst[1] [ * | . . | 0 1 0 | . . . ] |
| 179 | // dst[2] [ * | . . | 0 0 1 | . . . ] |
| 180 | // |
| 181 | // is what would get put in dst if N was 3, offset was 3, and the jet type JetT |
| 182 | // was 8-dimensional. |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 183 | template <int j, int N, int Offset, typename T, typename JetT> |
| 184 | struct Make1stOrderPerturbation { |
| 185 | public: |
| 186 | inline static void Apply(const T* src, JetT* dst) { |
| 187 | if (j == 0) { |
| 188 | DCHECK(src); |
| 189 | DCHECK(dst); |
| 190 | } |
| 191 | dst[j] = JetT(src[j], j + Offset); |
| 192 | Make1stOrderPerturbation<j + 1, N, Offset, T, JetT>::Apply(src, dst); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 193 | } |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | template <int N, int Offset, typename T, typename JetT> |
| 197 | struct Make1stOrderPerturbation<N, N, Offset, T, JetT> { |
| 198 | public: |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 199 | static void Apply(const T* /* NOT USED */, JetT* /* NOT USED */) {} |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 200 | }; |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 201 | |
| 202 | // Calls Make1stOrderPerturbation for every parameter block. |
| 203 | // |
| 204 | // Example: |
| 205 | // If one having three parameter blocks with dimensions (3, 2, 4), the call |
| 206 | // Make1stOrderPerturbations<integer_sequence<3, 2, 4>::Apply(params, x); |
| 207 | // will result in the following calls to Make1stOrderPerturbation: |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 208 | // Make1stOrderPerturbation<0, 3, 0>::Apply(params[0], x + 0); |
| 209 | // Make1stOrderPerturbation<0, 2, 3>::Apply(params[1], x + 3); |
| 210 | // Make1stOrderPerturbation<0, 4, 5>::Apply(params[2], x + 5); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 211 | template <typename Seq, int ParameterIdx = 0, int Offset = 0> |
| 212 | struct Make1stOrderPerturbations; |
| 213 | |
| 214 | template <int N, int... Ns, int ParameterIdx, int Offset> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 215 | struct Make1stOrderPerturbations<std::integer_sequence<int, N, Ns...>, |
| 216 | ParameterIdx, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 217 | Offset> { |
| 218 | template <typename T, typename JetT> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 219 | inline static void Apply(T const* const* parameters, JetT* x) { |
| 220 | Make1stOrderPerturbation<0, N, Offset, T, JetT>::Apply( |
| 221 | parameters[ParameterIdx], x + Offset); |
| 222 | Make1stOrderPerturbations<std::integer_sequence<int, Ns...>, |
| 223 | ParameterIdx + 1, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 224 | Offset + N>::Apply(parameters, x); |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | // End of 'recursion'. Nothing more to do. |
| 229 | template <int ParameterIdx, int Total> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 230 | struct Make1stOrderPerturbations<std::integer_sequence<int>, |
| 231 | ParameterIdx, |
| 232 | Total> { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 233 | template <typename T, typename JetT> |
| 234 | static void Apply(T const* const* /* NOT USED */, JetT* /* NOT USED */) {} |
| 235 | }; |
| 236 | |
| 237 | // Takes the 0th order part of src, assumed to be a Jet type, and puts it in |
| 238 | // dst. This is used to pick out the "vector" part of the extended y. |
| 239 | template <typename JetT, typename T> |
| 240 | inline void Take0thOrderPart(int M, const JetT* src, T dst) { |
| 241 | DCHECK(src); |
| 242 | for (int i = 0; i < M; ++i) { |
| 243 | dst[i] = src[i].a; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Takes N 1st order parts, starting at index N0, and puts them in the M x N |
| 248 | // matrix 'dst'. This is used to pick out the "matrix" parts of the extended y. |
| 249 | template <int N0, int N, typename JetT, typename T> |
| 250 | inline void Take1stOrderPart(const int M, const JetT* src, T* dst) { |
| 251 | DCHECK(src); |
| 252 | DCHECK(dst); |
| 253 | for (int i = 0; i < M; ++i) { |
| 254 | Eigen::Map<Eigen::Matrix<T, N, 1>>(dst + N * i, N) = |
| 255 | src[i].v.template segment<N>(N0); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | // Calls Take1stOrderPart for every parameter block. |
| 260 | // |
| 261 | // Example: |
| 262 | // If one having three parameter blocks with dimensions (3, 2, 4), the call |
| 263 | // Take1stOrderParts<integer_sequence<3, 2, 4>::Apply(num_outputs, |
| 264 | // output, |
| 265 | // jacobians); |
| 266 | // will result in the following calls to Take1stOrderPart: |
| 267 | // if (jacobians[0]) { |
| 268 | // Take1stOrderPart<0, 3>(num_outputs, output, jacobians[0]); |
| 269 | // } |
| 270 | // if (jacobians[1]) { |
| 271 | // Take1stOrderPart<3, 2>(num_outputs, output, jacobians[1]); |
| 272 | // } |
| 273 | // if (jacobians[2]) { |
| 274 | // Take1stOrderPart<5, 4>(num_outputs, output, jacobians[2]); |
| 275 | // } |
| 276 | template <typename Seq, int ParameterIdx = 0, int Offset = 0> |
| 277 | struct Take1stOrderParts; |
| 278 | |
| 279 | template <int N, int... Ns, int ParameterIdx, int Offset> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 280 | struct Take1stOrderParts<std::integer_sequence<int, N, Ns...>, |
| 281 | ParameterIdx, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 282 | Offset> { |
| 283 | template <typename JetT, typename T> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 284 | inline static void Apply(int num_outputs, JetT* output, T** jacobians) { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 285 | if (jacobians[ParameterIdx]) { |
| 286 | Take1stOrderPart<Offset, N>(num_outputs, output, jacobians[ParameterIdx]); |
| 287 | } |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 288 | Take1stOrderParts<std::integer_sequence<int, Ns...>, |
| 289 | ParameterIdx + 1, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 290 | Offset + N>::Apply(num_outputs, output, jacobians); |
| 291 | } |
| 292 | }; |
| 293 | |
| 294 | // End of 'recursion'. Nothing more to do. |
| 295 | template <int ParameterIdx, int Offset> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 296 | struct Take1stOrderParts<std::integer_sequence<int>, ParameterIdx, Offset> { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 297 | template <typename T, typename JetT> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 298 | static void Apply(int /* NOT USED*/, |
| 299 | JetT* /* NOT USED*/, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 300 | T** /* NOT USED */) {} |
| 301 | }; |
| 302 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 303 | template <int kNumResiduals, |
| 304 | typename ParameterDims, |
| 305 | typename Functor, |
| 306 | typename T> |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 307 | inline bool AutoDifferentiate(const Functor& functor, |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 308 | T const* const* parameters, |
| 309 | int dynamic_num_outputs, |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 310 | T* function_value, |
| 311 | T** jacobians) { |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 312 | using JetT = Jet<T, ParameterDims::kNumParameters>; |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 313 | using Parameters = typename ParameterDims::Parameters; |
| 314 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 315 | if (kNumResiduals != DYNAMIC) { |
| 316 | DCHECK_EQ(kNumResiduals, dynamic_num_outputs); |
| 317 | } |
| 318 | |
| 319 | ArraySelector<JetT, |
| 320 | ParameterDims::kNumParameters, |
| 321 | CERES_AUTODIFF_MAX_PARAMETERS_ON_STACK> |
| 322 | parameters_as_jets(ParameterDims::kNumParameters); |
| 323 | |
| 324 | // Pointers to the beginning of each parameter block |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 325 | std::array<JetT*, ParameterDims::kNumParameterBlocks> unpacked_parameters = |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 326 | ParameterDims::GetUnpackedParameters(parameters_as_jets.data()); |
| 327 | |
| 328 | // If the number of residuals is fixed, we use the template argument as the |
| 329 | // number of outputs. Otherwise we use the num_outputs parameter. Note: The |
| 330 | // ?-operator here is compile-time evaluated, therefore num_outputs is also |
| 331 | // a compile-time constant for functors with fixed residuals. |
| 332 | const int num_outputs = |
| 333 | kNumResiduals == DYNAMIC ? dynamic_num_outputs : kNumResiduals; |
| 334 | DCHECK_GT(num_outputs, 0); |
| 335 | |
| 336 | ArraySelector<JetT, kNumResiduals, CERES_AUTODIFF_MAX_RESIDUALS_ON_STACK> |
| 337 | residuals_as_jets(num_outputs); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 338 | |
| 339 | // Invalidate the output Jets, so that we can detect if the user |
| 340 | // did not assign values to all of them. |
| 341 | for (int i = 0; i < num_outputs; ++i) { |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 342 | residuals_as_jets[i].a = kImpossibleValue; |
| 343 | residuals_as_jets[i].v.setConstant(kImpossibleValue); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 346 | Make1stOrderPerturbations<Parameters>::Apply(parameters, |
| 347 | parameters_as_jets.data()); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 348 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 349 | if (!VariadicEvaluate<ParameterDims>( |
| 350 | functor, unpacked_parameters.data(), residuals_as_jets.data())) { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 351 | return false; |
| 352 | } |
| 353 | |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 354 | Take0thOrderPart(num_outputs, residuals_as_jets.data(), function_value); |
| 355 | Take1stOrderParts<Parameters>::Apply( |
| 356 | num_outputs, residuals_as_jets.data(), jacobians); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 357 | |
| 358 | return true; |
| 359 | } |
| 360 | |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 361 | } // namespace ceres::internal |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 362 | |
| 363 | #endif // CERES_PUBLIC_INTERNAL_AUTODIFF_H_ |