All files in prim/fun and prim/constraint should have associated files in rev/fun, rev/constraint and fwd/fun, fwd/constrain

Abierto
#3,123 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp
Área
backend

Línea de trabajo

Comienza auditando los headers bajo prim/fun y prim/constraint; después, compara sus rutas equivalentes bajo rev/fun, rev/constraint, fwd/fun y fwd/constraint. Usa el ejemplo log1p_exp y sus dependencias log1p y exp como modelo; se considera terminado cuando cada header de modo requerido tiene los includes específicos del modo apropiados y la implementación de prim sigue disponible.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

feature

Description

When we do not have a reverse or forward mode specialization for a function we default to the function available in prim. When we write functions with no reverse or forward mode specializations we assume the sub functions (or sub sub functions) that make up that larger function will then use reverse or forward mode specializations. Take the log1p_exp example below, Stan has reverse and forward mode for this function but I'm just using it as an example. This log1p function is generically templated so that it would accept double, var, and fvar<T> types.

template <typename T>
inline auto log1p_exp(T a) {
  // like log_sum_exp below with b=0.0; prevents underflow
  if (a > 0.0) {
    return a + log1p(exp(-a));
  }
  return log1p(exp(a));
}

If the forward and reverse mode functions for log1p and exp are not included beforehand, Stan would either

  1. Default to the prim version of the function
  2. (worse case) call the standard library function
  3. (best case) Throw a compiler error

To make sure those includes come in correctly, for each file in prim that does not already have a specialization in rev or fwd we should have a file in the equivalent path of rev/fwd. That file will contain includes for any sub functions used in the prim function that have specializations in rev/(fwd). The final include will include the prim function that will then have the specializations for its sub-functions available to it. This will also simplify our include scheme for fwd/prim/rev as well. The new rules will be that all includes in rev(fwd) must come from rev(fwd), besides a prim implementation of the same file name.

For feature requests:

Given log1p above, it's rev file would look like the following

#include <stan/math/rev/core.hpp>
#include <stan/math/rev/fun/log1p.hpp>
#include <stan/math/rev/fun/exp.hpp>
#include <stan/math/prim/fun/log1p_exp.hpp>
Current Version:

v4.9.0

Lenguaje dominante
C++
Estrellas
845
Forks
225
Merge medio
3 d 9 h
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stan-dev/math

Todos los issues de stan-dev/math

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.