[Developers] Help on traits
Steve Martell
SteveM at iphc.int
Mon Jul 21 11:55:26 PDT 2014
Hola Mark,
I'm not clear on what your objective with this example is, but if I'm right in assuming that your trying to write a growth function that is robust to the permutations of the different arguments, then you might be better of writing a class template. With a class you can overload the constructor such that a number of different combinations could be accommodated.
Steve
On Jul 19, 2014, at 10:18 AM, dave fournier <davef at otter-rsch.com<mailto:davef at otter-rsch.com>> wrote:
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 assessmenthttp://www.fisheriesstockassessment.com/
_______________________________________________
Developers mailing list
Developers at admb-project.org<mailto:Developers at admb-project.org>
http://lists.admb-project.org/mailman/listinfo/developers
<capam_growth.hpp><gtest.tpl>_______________________________________________
Developers mailing list
Developers at admb-project.org<mailto:Developers at admb-project.org>
http://lists.admb-project.org/mailman/listinfo/developers
________________________________
This internet e-mail message, and any files transmitted with it, contains confidential, privileged information that is intended only for the addressee. If you have received this e-mail message in error, please call us at (206) 634-1838 collect if necessary) and ask to speak to the message sender. Nothing in this e-mail or the act of transmitting it, is to be construed as a waiver of any rights or privileges enjoyed by the sender or the International Pacific Halibut Commission pursuant to the International Organizations Immunities Act, 22 U.S.C. Sec. 288 et seq.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140721/9f6c231e/attachment.html>
More information about the Developers
mailing list