[ADMB Users] Question about vectors

Skip to first unread message


Dec 9, 2014, 7:51:37 PM12/9/14
to Us...@admb-project.org
Hi Users,

I have a few questions about vectors. 
First, was there a conscious decision by ADMB to start counting at 1 rather than 0?
The second is perhaps a historical question. I know the stl was probably not around when AUTODIF was written, were the datatypes based on another C++ library? Most array's can be accessed by square brackets, what protection is given to the user by using parenthesis?


Below is a FINAL_SECTION I put on the simple example. 

 for(int i=1; i<nobs;i++){cout<<i<<"\t";} // write out the index
  cout<<"\n"<<endl; //give a bit of space
 for(int i=1; i<nobs;i++){cout<<pred_Y[i]<<"\t";}// write out vector of predicted Y's
   cout<<"\n"<<endl;// space
 for(int i=1; i<4;i++){ //counting from 1 works
   cout<<pred_Y[i]<<endl; //square brackets
   cout<<pred_Y(i)<<endl;// parenthesis

 for(int i=0; i<4;i++){// counting from zero doesn't work

John Sibert

Dec 10, 2014, 11:19:26 AM12/10/14
to bigA, Us...@admb-project.org
Vectors can be indexed at the user's pleasure. The construtors take 2
arguments, the lower and upper values of the index. Thus it you can
declare dvector myvector(0,10); which will have 11 elements indexed from
0 to 10l

I don't understand the second question. The data types were determined
by the requirements of the software.

There is no difference between () and []. There protection given to the
user or anyone else by []. Compiling in "safe mode" invokes subscript
checking for both types operators.

John Sibert
Emeritus Researcher, SOEST
University of Hawaii at Manoa
Honolulu HI (GMT-10)
808-294-3842 (mobile)

Visit the ADMB project http://admb-project.org/
> _______________________________________________
> Users mailing list
> Us...@admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users

Users mailing list

dave fournier

Dec 11, 2014, 7:03:55 PM12/11/14
to us...@admb-project.org
There is one difference between () and []

[] can only take one argument while () can take any number of arguments.

So for a matrix you would have to write M[i][j] rather than M(i,j)

since it is nice to have M(i,j) one might as well have v(i) for a vector
as well,

otherwise you would be asking why use [] for vectors and () for matrices.

It was a conscious decision by me to permit arbitary offsets in
arrays. ADMB had nothing to do with it.

You are free to use 0 offset vectors if you want. It may uncover the
odd bug where there is code
that relies on the offset being 1. if so report it and it will get fixed.

The stl wasn't even a bad idea yet when admb was written. All was done
on DOS with a 32 bit DOS extender coming
along. First compiler was Turbo C++ from Borland. User had about 350KB
memory to play with. Then came Zortech
with a Dos extender. Also at some point microsoft. They all had
different IO and different bugs in the compiler.
Reply all
Reply to author
0 new messages