diff --git a/include/ceres/internal/autodiff.h b/include/ceres/internal/autodiff.h index 0bc41f262..cefcfb4c0 100644 --- a/include/ceres/internal/autodiff.h +++ b/include/ceres/internal/autodiff.h @@ -181,14 +181,24 @@ namespace internal { // // is what would get put in dst if N was 3, offset was 3, and the jet type JetT // was 8-dimensional. -template -inline void Make1stOrderPerturbation(const T* src, JetT* dst) { - DCHECK(src); - DCHECK(dst); - for (int j = 0; j < N; ++j) { - dst[j] = JetT(src[j], Offset + j); +template +struct Make1stOrderPerturbation { + public: + static void Apply(const T* src, JetT* dst) { + if (j == 0) { + DCHECK(src); + DCHECK(dst); + } + dst[j] = JetT(src[j], j + Offset); + Make1stOrderPerturbation::Apply(src, dst); } -} +}; + +template +struct Make1stOrderPerturbation { + public: + static void Apply(const T* src, JetT* dst) {} +}; // Calls Make1stOrderPerturbation for every parameter block. // @@ -208,7 +218,8 @@ struct Make1stOrderPerturbations, Offset> { template static void Apply(T const* const* parameters, JetT* x) { - Make1stOrderPerturbation(parameters[ParameterIdx], x + Offset); + Make1stOrderPerturbation<0, N, Offset, T, JetT>::Apply( + parameters[ParameterIdx], x + Offset); Make1stOrderPerturbations, ParameterIdx + 1, Offset + N>::Apply(parameters, x);