Skip to content

single templated implementation of constraints #2561

Open
@bob-carpenter

Description

@bob-carpenter

Description

After #2559 is merged, it'd be nice to refactor the implementations.

  • Single Jacobian-templated implementation. Those are going to look as follows.
template <bool Jacobian, typename T>
inline auto XXX_constrain(..., scalar_type_t<T>& lp) {
  value = ...value calculations...
  if (Jacobian)
    lp += ...Jacobian calc...
  return value;
}
  • Deprecate the untemplated XXX_constrain functions.

  • Delegate implementations of untemplated XXX_constrain functions to the Jacobian-templated version.

  • Make sure doc of templated version doesn't point to untemplated version; OK to point to the Stan Reference Manual chapter Constraint Transforms.

Finishing this should remove all the cut-and-paste in the constraining transform code.

What would really be nice is if we could somehow group the constraining and unconstraining transforms together as a unit we can manipulate, but we can save that for a subsequent issue.

Current Version:

v4.1.0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions