23 template<
typename CostFunctor,
typename Dual,
typename Scalar,
int JacobianLayout = Eigen::ColMajor>
26 static_assert(std::is_convertible_v<typename Dual::Scalar, Scalar>,
"The chosen Jet and Scalar types are not compatible.");
27 static_assert(std::is_convertible_v<Scalar, typename Dual::Scalar>,
"The chosen Jet and Scalar types are not compatible.");
36 std::vector<Dual> inputs(
function.NumParameters());
37 for (
size_t i = 0;
i < inputs.size(); ++
i) {
38 inputs[
i].a = parameters[
i];
39 inputs[
i].v.setZero();
43 static auto constexpr D{Dual::DIMENSION};
46 for (
int s = 0;
s < inputs.size();
s +=
D) {
47 int r = std::min(
static_cast<int>(inputs.size()),
s +
D);
49 for (
int i =
s;
i < r; ++
i) {
50 inputs[
i].v[
i -
s] = 1.0;
57 for (
int i =
s;
i < r; ++
i) {
58 inputs[
i].v[
i -
s] = 0.0;
63 for (
int i =
s;
i < r; ++
i) {
64 std::transform(
outputs.cbegin(),
outputs.cend(),
jmap.col(
i).data(), [&](
auto const&
jet) { return jet.v[i - s]; });
82 static constexpr int Stride = DualType::DIMENSION;
113 using QRSolver = Eigen::ColPivHouseholderQR<JacobianType>;
123 auto df(Eigen::Matrix<Scalar, -1, 1>
const&
input, Eigen::Matrix<Scalar, -1, -1> &
jacobian) ->
int
125 static_assert(
StorageOrder == Eigen::ColMajor,
"Eigen::LevenbergMarquardt requires the Jacobian to be stored in column-major format.");
void bind_engine(py::module &m, string name)
auto Autodiff(CostFunctor const &function, Scalar const *parameters, Scalar *residuals, Scalar *jacobian) -> bool
< nsga2 selection operator for getting the front
ceres::Jet< float, stride > fJet
static constexpr int Stride
auto values() const -> int
auto operator()(Scalar const *parameters, Scalar *residuals, Scalar *jacobian) const -> bool
auto Evaluate(Scalar const *parameters, Scalar *residuals, Scalar *jacobian) const -> bool
auto operator()(Eigen::Matrix< Scalar, -1, 1 > const &input, Eigen::Matrix< Scalar, -1, 1 > &residual) -> int
static constexpr int Storage
auto NumResiduals() const -> int
TinyCostFunction(CostFunctor const &functor)
Eigen::ColPivHouseholderQR< JacobianType > QRSolver
auto df(Eigen::Matrix< Scalar, -1, 1 > const &input, Eigen::Matrix< Scalar, -1, -1 > &jacobian) -> int
auto inputs() const -> int
Eigen::Matrix< Brush::Scalar, -1, -1 > JacobianType
auto NumParameters() const -> int