[ADMB Users] vector powers
Ben Bolker
bbolker at gmail.com
Fri Sep 24 09:09:35 PDT 2010
[responding to previous question about vectorizing pow() on both the
bases and the exponents -- I suggested
an explicit for loop ... posting back to the list for comment/correction]
On 10-09-24 11:55 AM, Mollie Brooks wrote:
> That's what I've done, but I was hoping to be more efficient.
I think (not positive) that encapsulating for loops in ADMB doesn't
make things more efficient -- it just simplifies the code.
(If you want, I think you can write your own function -- for example, I
*think* that if you put this in your GLOBALS_SECTION
it should automatically overload the "pow()" function for vectorized
bases and exponents ... (based on previous contributions
from the list).
df1b2vector pow(const df1b2vector& v,const df1b2vector & x)
{
int mmin=v.indexmin();
int mmax=v.indexmax();
// ?? add check that vectors have the same extents ??
df1b2vector tmp(mmin,mmax);
for (int i=mmin;i<=mmax;i++)
{
tmp(i)=pow(v(i),x(i));
}
return tmp;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20100924/fc66eab2/attachment.html>
More information about the Users
mailing list