[ADMB Users] use of .sub

dave fournier davef at otter-rsch.com
Thu Feb 28 10:59:20 PST 2013


On 13-02-28 10:44 AM, Fowler, Mark wrote:

It looks like this has been done.

void dmatrix::colfill(int j, const dvector& v)

void dvar_matrix::colfill(int j, const dvar_vector& v)


> Hi Dave,
>
> I was confounded by the row-first aspect of the matrix when attempting
> assignment along a column. Which explains why the syntax worked when
> filling in elements along the row dimension, e.g.
>
> popj(a+1).sub((tind.indexmin() + 1),(tind.indexmax() + 1)) =
>
> So I have to transpose the original matrix for column-as-row assignment.
> Works but a bit of juggling. Any one-liner trick for this that doesn't
> require defining a transposed matrix and re-transposing it back to the
> original to continue, or does the left-hand side of the assignment
> thwart it?
>
>> 	Mark Fowler
> 		Population Ecology Division
>> 	Bedford Inst of Oceanography
>> 	Dept Fisheries & Oceans
>> 	Dartmouth NS Canada
> 		B2Y 4A2
> 		Tel. (902) 426-3529
> 		Fax (902) 426-9710
> 		Email Mark.Fowler at dfo-mpo.gc.ca
> 		Home Tel. (902) 461-0708
> 		Home Email mark.fowler at ns.sympatico.ca
>
>
> -----Original Message-----
> From: users-bounces at admb-project.org
> [mailto:users-bounces at admb-project.org] On Behalf Of dave fournier
> Sent: February 28, 2013 11:57 AM
> To: users at admb-project.org
> Subject: Re: [ADMB Users] use of .sub
>
>> I'm trying to nail down the proper syntax for employing .sub to
>> identify portions of a matrix. Made some progress by trial and error,
>> but still some obstacles. For instance below I try to fill a single
>> given column with a vector, but get an error message that
>> dvar_matrix::operator cannot be matched to dvar_vector. This a syntax
> and/or format problem?
>> A matrix of age (row) by year (column), trying to fill the right
> margin.
>> 	utfmat.sub(1,na).sub(ny,ny) = fly;
> Easiest way for someone to understand this stuff (overloaded operators
> in C++) is to compile in debug mode and walk through the code.  then you
> would see that
>
>          utfmat.sub(1,na)
>
> is a matrix so think of it as M. then the second sub is
>
>       M.sub(ny,ny)
>
> which is another matrix with 1 row (not 1 column).
>
> The problme is that a matrix can either be stored by rows or by columns.
> In ADMB it is stored by rows. so
>
>        column(M,ny)
>
> is a vector whose elements are equal of the ny column of M, but it is
> *NOT* the ny column of M so if you write
>
>              column(M,ny)=v;
>
> M will not get changed.
>
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users




More information about the Users mailing list