[Developers] Help on traits
dave fournier
davef at otter-rsch.com
Fri Jul 18 15:34:25 PDT 2014
On 07/14/2014 01:02 PM, Mark Maunder wrote:
Hi,
I think you are confusing two things here. One is to have a single
function vonB
which acts on different types in the same way. In this case the code
needs to depend on the types.
Note that in your code it is assumed that age is a vector
inline
typename Growthvectortrait<T>::GrowthvectorT vonBertalanffy(const T
&Linf, const T &K, const T &t0, const T1 &age)
{
typedef typename Growthvectortrait<T>::GrowthvectorT vonBT;
vonBT len;
cout << "HERE" << endl;
len.allocate(age.indexmin(),age.indexmax());
len.initialize();
for(int i = len.indexmin(); i <= len.indexmax(); i++ )
{
len(i) = Linf*(1.-mfexp(-K*(age(i)-t0)));
}
return len;
}
I think you have to specialize for when age is a number like this.
template <typename T>
inline
dvariable vonBertalanffy(const T &Linf, const T &K, const T &t0, double
&age)
{
dvariable len;
cout << "HERE1" << endl;
len = Linf*(1.-mfexp(-K*(age-t0)));
return len;
}
The original traits examples were for doing the same thing to the passed
objects on the
generated code level. So I'm not exactly sure what yoiu are trying to
accomplish here.
I have attached my code which compiles and runs for what its worth.
Dave
> Hi,
>
> I am working on using traits for growth functions. Steve provided me
> some example code and I have been trying to extend it. This looks like
> it uses templates inside templates and gets confusing. Attached is
> some example code and I would appreciate any help on debugging it. I
> think the problem is that for the same function parameter types I have
> two different return types, so I made two different traits. I think it
> is important to get this sorted out because it may be something we
> will use often in creating libraries of functions.
>
> Thanks,
>
> Mark
>
> The selectivity special issue of the journal Fisheries Research is now
> published
>
> http://www.sciencedirect.com/science/journal/01657836/158/supp/C
>
> The Stock Synthesis special issue of the journal Fisheries Research
>
> http://www.sciencedirect.com/science/journal/01657836/142
>
> Mark Maunder
>
> Head of the Stock Assessment Program
>
> Inter-American Tropical Tuna Commission
>
> 8901 La Jolla Shores Dr.
>
> La Jolla, CA 92037-1508, USA
>
> Tel: (858) 546-7027
>
> Fax: (858) 546-7133
>
> mmaunder at iattc.org <mailto:mmaunder at iattc.org>
>
> http://www.fisheriesstockassessment.com/TikiWiki/tiki-index.php?page=Mark+Maunder
>
> Visit the Center for the Advancement of Population Assessment
> Methodology at
>
> http://www.capamresearch.org/
>
> Visit the AD Model Builder project at
>
> http://admb-project.org/
>
> See the following website for information on fisheries stock
> assessment http://www.fisheriesstockassessment.com/
>
>
>
> _______________________________________________
> Developers mailing list
> Developers at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140718/e20b28dd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: capam_growth.hpp
Type: text/x-c++hdr
Size: 6153 bytes
Desc: not available
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140718/e20b28dd/attachment.hpp>
-------------- next part --------------
DATA_SECTION
vector age(1,10)
!!age.fill_seqadd(1,1);
number Linf_const
number K_const
number t0_const
!!Linf_const=100;
!!K_const=0.2;
!!t0_const=-0.5;
vector L_const(1,10)
int age_single_int
number age_single_double
!!age_single_int=5;
!!age_single_double=5.5;
number L_const_single
PARAMETER_SECTION
init_number tempfind
init_number Linf
init_number K
init_number t0
vector L(1,10)
//number L_single
objective_function_value f
INITIALIZATION_SECTION
Linf 100
K 0.2
t0 -0.5
PROCEDURE_SECTION
double L_single;
dvar_vector llength=vonBertalanffy(Linf, K, t0,age);
cout << llength << endl;
//double asd=age_single_double;
L_single=value(vonBertalanffy(Linf, K, t0,age_single_double));
cout << L_single << endl;
f=square(tempfind);
REPORT_SECTION
report<<"L"<<endl;
report<<L<<endl;
report<<"L_const"<<endl;
report<<L_const<<endl;
GLOBALS_SECTION
#include<capam_growth.hpp>
More information about the Developers
mailing list