[ADMB Users] dvariable vs. prevariable

dave fournier davef at otter-rsch.com
Wed May 23 16:09:30 PDT 2012


Hi all,

I had a quick coding question that I couldn't answer online.  What is the
difference between dvariables and prevariables?  They seem to be used
interchangably in calls to SEPARABLE_FUNCTIONS, and it appears that
dvariables are defined based on prevariables.  Is one faster to use than
the other, or more appropriate for particular uses?

Seems like a useful question to have documented on the redmine (where I
understand, perhaps mistakenly, that any answers to this inquiry will be
stored)..

Cheers,
Jim


prevariable is better for separable_functions.

The difference is between  say x(i) when x is a dvar_vector. then x(i) is a prevariable.
If you pass x(i) to a function which takes a dvariable a constructor is invoked to change
it to a dvariable. This incurs a bit of overhead.  Also if you changed the value of argument
corresponding to x(i) inside the function the original x(i) would not be changed
since you are actually changing a different object.

If this seems bizarre it was done so that
the access functions x(i) and x[i] which involve a copy
constructor would not incur extra overhead.







More information about the Users mailing list