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

Aperta
#3,123 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Inizia eseguendo l’audit degli header sotto prim/fun e prim/constraint, quindi confronta i relativi percorsi equivalenti sotto rev/fun, rev/constraint, fwd/fun e fwd/constraint. Usa l’esempio log1p_exp e le sue dipendenze log1p ed exp come modello; il lavoro è completato quando ogni header di modalità richiesto contiene gli include appropriati specifici per la modalità e l’implementazione prim rimane disponibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C++
Stelle
845
Fork
225
Merge medio
3g 9h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stan-dev/math

Tutte le issue di stan-dev/math

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.