[Developers] d4_array

Jim Ianelli - NOAA Federal jim.ianelli at noaa.gov
Thu Jul 24 13:42:14 PDT 2014


cool, thanks!


On Thu, Jul 24, 2014 at 11:37 AM, dave fournier <davef at otter-rsch.com>
wrote:

>  On 07/24/2014 11:06 AM, Jim Ianelli - NOAA Federal wrote:
>
> You are starting at the wrong place.  Here is what I would do.
>
> 1.) put it into a tpl and run tpl2cpp (or tpl2rem if that is appropriate)
> Here I use simple.tpl and add a 3darray as well to compare
>
> DATA_SECTION
>   init_int nobs
>   init_vector Y(1,nobs)
>   init_vector x(1,nobs)
>   // add 4d array and 3darray
>   3darray yyy
>   4darray  xxxx
> PARAMETER_SECTION
>   init_number a
>   init_number b
>   vector pred_Y(1,nobs)
>   objective_function_value f
> PROCEDURE_SECTION
>   pred_Y=a*x+b;
>   f=(norm2(pred_Y-Y));
>   f=nobs/2.*log(f);    // make it a likelihood function so that
>                        // covariance matrix is correct
>
> what I get is
>
>
> warning -- creating unallocated 3darray() at line 38
> Error in line 39 while reading
> x
>
> so tpl2cpp knows about 3darrays but not 4darrays.
>
> So check out the lex code for tpl2cpp to see what neds to be added.
>
> code for 3darray is
>
> <DEFINE_DATA>3darray {
>     likelihood_found=1;
>     BEGIN IN_NAMED_THREE_ARRAY_DEF;
>     fprintf(fdat,"%s","  d3_array ");
>                      }
>
> What this does is to switch the state of the lexer to
> IN_NAMED_THREE_ARRAY_DEF stuff.
> so in there will be a case when there are no arguments.  Here it is.
>
> <IN_NAMED_THREE_ARRAY_DEF>{name} {
>     if (warn_unallocated) write_unallocated("3darray()");
>
>     strcpy(tmp_string,yytext);  // get x in x(1,4)
>     fprintf(fdat,"%s",tmp_string);
>     fprintf(fall,"  %s",tmp_string);
>     fprintf(fall,"%s",".allocate()");
>     //fprintf(fall,"%s",".allocate");
>     //after_part(tmp_string1,yytext,'(');  // get x in x(1,4)
>     //before_part(tmp_string2,tmp_string1,')');
>     //fprintf(fall,"%s)",tmp_string2);
>     fprintf(fdat,"%s",";\n");
>     fprintf(fall,"%s",";\n");
>     if (!params_defined)
>     {
>       if(likelihood_found) {
>         if(likelihood_counter<MAX_LIKE_CHECK)
> sprintf(likelihood_checker[likelihood_counter++],"%s",tmp_string);
>         likelihood_found=0;
>       }
>       BEGIN DEFINE_DATA;
>     }
>     else
>     {
>       BEGIN DEFINE_PARAMETERS;
>     }
>                             }
>
> So we need a corresponding entry for 4darrays.
> So dup the above and change THREE to FOUR and 3darray to 4darray
>
> <IN_NAMED_FOUR_ARRAY_DEF>{name} {
>     if (warn_unallocated) write_unallocated("4darray()");
>
>     strcpy(tmp_string,yytext);  // get x in x(1,4)
>     fprintf(fdat,"%s",tmp_string);
>     fprintf(fall,"  %s",tmp_string);
>     fprintf(fall,"%s",".allocate()");
>     //fprintf(fall,"%s",".allocate");
>     //after_part(tmp_string1,yytext,'(');  // get x in x(1,4)
>     //before_part(tmp_string2,tmp_string1,')');
>     //fprintf(fall,"%s)",tmp_string2);
>     fprintf(fdat,"%s",";\n");
>     fprintf(fall,"%s",";\n");
>     if (!params_defined)
>     {
>       if(likelihood_found) {
>         if(likelihood_counter<MAX_LIKE_CHECK)
> sprintf(likelihood_checker[likelihood_counter++],"%s",tmp_string);
>         likelihood_found=0;
>       }
>       BEGIN DEFINE_DATA;
>     }
>     else
>     {
>       BEGIN DEFINE_PARAMETERS;
>     }
>                             }
>
>
> and remake tpl2cpp and run again on the modified simple.tpl
> and you will get
>
> t/bin/tpl2cpp simple
> warning -- creating unallocated 3darray() at line 38
> warning -- creating unallocated 4darray() at line 39
>
> check the code simple.htp for xxxx and yyyy
>
> class model_data : public ad_comm{
>   data_int nobs;
>   data_vector Y;
>   data_vector x;
>   d3_array yyyy;
>   d4_array xxxx;
>   ~model_data();
>   model_data(int argc,char * argv[]);
>   friend class model_parameters;
> };
>
> so they are there.  and in simple.cpp
>
> model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
> {
>   nobs.allocate("nobs");
>   Y.allocate(1,nobs,"Y");
>   x.allocate(1,nobs,"x");
>   yyyy.allocate();
>   xxxx.allocate();
> }
>
> So now it is a question of whether admb knows about unallocated  d4_arrays.
> So compile simple.cpp.
>
> I think you will find that it compiles so you are done.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> f I grep d3_array in nh99 I get 104 lines of code
>
>
>  grepping d4_array gets 34 lines...
>
>  below are the hits (they keep coming...).
>
>  Question is how to identify where the code didn't write itself. Ignore
> if this is stupid, as always.
>  admodel.h:  named_dvar3_array& operator=(const d3_array& m);
> admodel.h:class named_d3_array : public d3_array, public model_name_tag
> admodel.h:  named_d3_array(void) : d3_array(), model_name_tag() {;}
> admodel.h:  named_d3_array& operator=(const d3_array& m);
> admodel.h:class data_3array : public named_d3_array
> admodel.h:  data_3array(void) : named_d3_array() {;}
> admodel.h:  dll_data_3array& operator=(const d3_array &);
> admodel.h:    const d3_array& eigenvals,d3_array& curvcor);
> admodel.h:  dll_param_init_d3array& operator=(const d3_array&);
> admodel.h:  dll_param_d3array& operator=(const d3_array&);
> getbigs.cpp:      d3_array & H=*(lapprox->block_diagonal_hessian);
> getbigs.cpp:      d3_array & Dux=*(lapprox->block_diagonal_Dux);
> getbigs.cpp:      d3_array & H=*(lapprox->block_diagonal_hessian);
> lex.yy.c:    fprintf(fdat,"%s","  d3_array ");
> mod_pmin.cpp:    //d3_array hesses(-num_pp,num_pp,1,nvar,1,nvar);
> mod_pmin.cpp:    d3_array eigenvals(0,nlp-1,-num_pp,num_pp,1,nvar-1);
> mod_pmin.cpp:    d3_array curvcor(0,nlp-1,-num_pp,num_pp,1,nvar-1);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model.cpp:    named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
> model.cpp:      *(ad_comm::global_datafile) >> d3_array(*this);
> model11.cpp:named_dvar3_array& named_dvar3_array::operator=(const
> d3_array& m)
> model11.cpp:void named_d3_array::allocate(int hsl,int hsu,int rmin,int
> rmax,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl,int hsu,int rmin,int
> rmax,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax);
> model11.cpp:void named_d3_array::allocate(int hsl,int hsu,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax);
> model11.cpp:void named_d3_array::allocate(int hsl,int hsu,const char * s)
> model11.cpp:  d3_array::allocate(hsl,hsu);
> model11.cpp:void named_d3_array::allocate(const char * s)
> model11.cpp:  d3_array::allocate();
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, const
> index_type& rmin,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, const ivector&
> rmin,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl,int hsu,int rmin,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, const ivector&
> rmin,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, int rmin, int
> rmax,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, int rmin, int
> rmax,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:void named_d3_array::allocate(int hsl, int hsu, int rmin, int
> rmax,
> model11.cpp:  d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax);
> model11.cpp:named_d3_array& named_d3_array::operator=(const d3_array& m)
> model11.cpp:  d3_array::operator=(m);
> model35.cpp:  named_d3_array::allocate(hmin,hmax,rmin,rmax,cmin,cmax,_s);
> model35.cpp:dll_data_3array& dll_data_3array::operator=(const d3_array &m)
> model35.cpp:  d3_array::operator = (m);
> model35.cpp:dll_param_d3array& dll_param_d3array::operator=(const d3_array
> &m)
> model35.cpp:dll_param_init_d3array&
> dll_param_init_d3array::operator=(const d3_array &m)
> newmodmn.cpp:    const d3_array& eigenvals,d3_array& curvcor)
> newmodmn.cpp:    const d3_array& eigenvals,d3_array& curvcor)
> tpl2cpp.c:    fprintf(fdat,"%s","  d3_array ");
> tpl2cpp.lex:    fprintf(fdat,"%s","  d3_array ");
>
>  admodel.h:  named_dvar4_array& operator=(const d4_array& m);
> admodel.h:class named_d4_array : public d4_array, public model_name_tag
> admodel.h:  named_d4_array(void) : d4_array(), model_name_tag() {;}
> admodel.h:  named_d4_array& operator=(const d4_array& m);
> admodel.h:class data_4array : public named_d4_array
> admodel.h:  data_4array(void) : named_d4_array() {;}
> lex.yy.c:    fprintf(fdat,"%s","  d4_array ");
> model15.cpp:void named_d4_array::allocate(int hhsl,int hhsu,int hsl,int
> hsu,
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax,cmin,cmax);
> model15.cpp:void named_d4_array::allocate(int hhsl,int hhsu,int hsl,int
> hsu,
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax);
> model15.cpp:void named_d4_array::allocate(int hhsl,int hhsu,int hsl,int
> hsu, const char* s)
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu);
> model15.cpp:void named_d4_array::allocate(int hhsl,int hhsu,const char* s)
> model15.cpp:  d4_array::allocate(hhsl,hhsu);
> model15.cpp:void named_d4_array::allocate(const char* s)
> model15.cpp:  d4_array::allocate();
> model15.cpp:void named_d4_array::allocate(ad_integer hhsl, ad_integer hhsu,
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax,cmin,cmax);
> model15.cpp:void named_d4_array::allocate(ad_integer hhsl,ad_integer hhsu,
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu);
> model15.cpp:void named_d4_array::allocate(ad_integer hhsl,ad_integer
> hhsu,const char* s)
> model15.cpp:  d4_array::allocate(hhsl,hhsu);
> model15.cpp:void named_d4_array::allocate(ad_integer hhsl,ad_integer hhsu,
> model15.cpp:  d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax);
> model15.cpp:named_d4_array& named_d4_array::operator=(const d4_array& m)
> model15.cpp:  this->d4_array::operator=(m);
> model15.cpp:named_dvar4_array& named_dvar4_array::operator=(const
> d4_array& m)
> model16.cpp:
>  named_d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax,cmin,cmax,s);
> model16.cpp:  *(ad_comm::global_datafile) >> d4_array(*this);
> model16.cpp:
>  named_d4_array::allocate(hhsl,hhsu,hsl,hsu,rmin,rmax,cmin,cmax,s);
> model16.cpp:  *(ad_comm::global_datafile) >> d4_array(*this);
> tpl2cpp.c:    fprintf(fdat,"%s","  d4_array ");
> tpl2cpp.lex:    fprintf(fdat,"%s","  d4_array ");
>
>
>
> On Thu, Jul 24, 2014 at 10:51 AM, dave fournier <davef at otter-rsch.com>
> wrote:
>
>> On 07/24/2014 10:41 AM, John Sibert wrote:
>>
>> Probably never wrote itself.  Unallocated objects were a later
>> development.
>> Wouldn't be much work to implement, but getting it into the code base ...
>>
>>
>>  I was looking for a null constructor to use in the DATA_SECTION
>>>   4darray effort_proxy;
>>>
>>> and then allocate later
>>>   effort_proxy.allocate(int,int, int,int, ivector&,ivector&,
>>> ivector&,ivector&)
>>>
>>> I do this routinely with d3_arrays:
>>>    3darray effort;
>>>
>>>    effort.allocate(0, nfleet, ilbv, iubv, jlbm, jubm);
>>>
>>> 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/
>>>
>>> On 07/23/2014 04:22 PM, dave fournier wrote:
>>>
>>>> On 07/23/2014 06:54 PM, John Sibert wrote:
>>>>
>>>>> How does one declare a d4_array in a tpl file?
>>>>>
>>>>>  init_4darray
>>>>
>>>> for initial one but maybe that is not what you want?
>>>> _______________________________________________
>>>> Developers mailing list
>>>> Developers at admb-project.org
>>>> http://lists.admb-project.org/mailman/listinfo/developers
>>>>
>>>>
>>>
>>>
>> _______________________________________________
>> Developers mailing list
>> Developers at admb-project.org
>> http://lists.admb-project.org/mailman/listinfo/developers
>>
>
>
>
>  --
>
> James Ianelli
> NMFS/NOAA Building 4
> 7600 Sand Pt Way NE
> Seattle WA 98115
>
>  206 526 6510
>
> Visit the ADMB project http://admb-project.org/
>
>
>


-- 

James Ianelli
NMFS/NOAA Building 4
7600 Sand Pt Way NE
Seattle WA 98115

 206 526 6510

Visit the ADMB project http://admb-project.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/developers/attachments/20140724/4ff2054a/attachment-0001.html>


More information about the Developers mailing list