Skip to content

forward-mode jacobian aborts for mappings R^n -> R^m with m != n #3385

Description

@sims1253

The fwd jacobian sizes both J and fx from the input dimension before evaluating f; J.col(0) = fx_fvar.d() then assigns an m-vector into an n-row column:

struct F {  // R^2 -> R^3
  template <typename T>
  Eigen::Matrix<T, Eigen::Dynamic, 1> operator()(
      const Eigen::Matrix<T, Eigen::Dynamic, 1>& x) const {
    Eigen::Matrix<T, Eigen::Dynamic, 1> out(3);
    out << x(0), x(0) + x(1), x(0) * x(1);
    return out;
  }
};
stan::math::jacobian(F{}, x, fx, J);   // x = [1.5, 2.0]
// fwd: Eigen assertion "DenseBase::resize() does not actually allow to resize." -> abort

The rev jacobian sizes from the output and handles the identical functor correctly (fx = 3-vector, J = 3×2). With assertions off, the fwd version writes past the storage instead of aborting.

Probably needs to evaluate f first and size from fx_fvar.size() simliar to the rev implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions