Slightly naive Q: since (AFAIK) the R functions for pt() and dt()
are available in TMB and since the derivative of pt() is dt() (by
definition), it would seem not too hard (for some definition of "hard")
to define a new atomic function following
http://kaskr.github.io/adcomp/_book/AtomicFunctions.html
The code below *almost* compiles, but gets an error
error: expected constructor, destructor, or type conversion before ‘(’ token
34 | VECTORIZE_1t(pt)
There's probably some tiny syntax error (see
<
https://stackoverflow.com/questions/8958044/expected-constructor-destructor-or-type-conversion-before-token>:
"If the compiler can't match the definition's signature to the
declaration's signature it thinks the definition is not a constructor
and then doesn't know how to parse the code and displays this error")
Maybe someone else can see what's wrong, or can tell me why this
wouldn't work.
====
#include <TMB.hpp>
extern "C" {
double Rf_pt(double q);
double Rf_dt(double x);
}
TMB_ATOMIC_VECTOR_FUNCTION(
// ATOMIC_NAME
pt
,
// OUTPUT_DIM
1,
// ATOMIC_DOUBLE
ty[0] = Rf_pt(tx[0]); // Call the 'double' version
,
// ATOMIC_REVERSE
Type x = ty[0]; // Function value from forward pass
Type dp = Rf_dt(x); // Derivative (do we need a cast here??)
px[0] = dp * py[0]; // Reverse mode chain rule
)
template<class Type>
Type pt(Type x){
CppAD::vector<Type> tx(1);
tx[0] = x;
return pt(tx)[0];
}
// Vectorized version
VECTORIZE_1t(pt)
> --
> To post to this group, send email to
us...@tmb-project.org. Before
> posting, please check the wiki and issuetracker at
>
https://github.com/kaskr/adcomp/ <
https://github.com/kaskr/adcomp/>.
> Please try to create a simple repeatable example to go with your
> question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
> ---
> You received this message because you are subscribed to the Google
> Groups "TMB Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
tmb-users+...@googlegroups.com
> <mailto:
tmb-users+...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/tmb-users/a5679c00-80d9-4195-904b-0373adfb9401n%40googlegroups.com
> <
https://groups.google.com/d/msgid/tmb-users/a5679c00-80d9-4195-904b-0373adfb9401n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics