Skip to content

Eigen elementwise functions with autodiff variables #1783

@andrjohns

Description

@andrjohns
Collaborator

Description

Now that Eigen's SIMD-vectorised elementwise functions have been introduced for containers of doubles (in #1471 and #1727), they should also be added for containers of fvar<T> and var.

Example

A quick example for using exp with fvar<T>:

template <typename Container,
          require_container_st<is_container, is_fvar, Container>...>
inline auto exp(const Container& x) {
  return apply_vector_unary<Container>::apply(
      x, [](const auto& v) {
        auto exp_val = exp(v.val());
        return to_fvar(exp_val,exp_val.cwiseProduct(v.d()));
});
}

Current Version:

v3.1.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @SteveBronder@andrjohns

      Issue actions

        Eigen elementwise functions with autodiff variables · Issue #1783 · stan-dev/math