From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4692663255b51613 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: on using array index, vectorized operation Date: Sun, 27 Mar 2011 13:44:41 -0700 Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:19480 Date: 2011-03-27T13:44:41-07:00 List-Id: On 3/27/2011 1:01 PM, Cyrille wrote: >> >> This is what I tried so far, and my goal to see if I can >> shorten this more: >> >> ------------------------ >> procedure t is >> i: constant array (1..4) of integer:=(2,3,4,5); >> A: array(1..5) of integer := (10,20,30,40,50); >> >> begin >> --A(2..5) := A(1..4); >> --A(i-1) := A(i); --error >> >> A(i(1)-1..i(4)-1) := A(i(1)..i(4)); >> end t; > > you can write: > > A(A'First+1 .. A'Last) := A(A'First .. A'Last-1); > > Thanks, Yes, I could I suppose, but it is not really practical. Is there a way to make A'First .. A'Last into one variable, say 'i', so I can just write i+1 or i-1 etc..? Here is one typical equation I have, using the 'vectored' notation, and if I have to write it in the above 'expanded' solution you showed, then the code becomes very hard to work with and one can make an error. Let me explain. Here is lax-wendroff scheme for 1-D advection pde, where 'u' below is the solution: u(i):=u(i)-(a/2.0)*(u(i+1)-u(i-1))+(a**2)/2.0*(u(i-1)-2.0*u(i)+u(i+1)); Where in the above, 'i' is the index range that I set up myself before. In Ada, I put the above line inside a loop over 'i'. Using your solution, I would have to write u(u'first+1..u'last-1) :=u(u'first+1..u'last-1) - (a/2.0)* (u(u'first+2..u'last) - u(u'first..u'last-2))+ (a**2)/2.0* ( u(u'first..u'last-2)-2.0*u(u'first+1..u'last-1) + u(u'first+2..u'last)) ; ie, I had to do the index adjustment by hand, adding one, subtract one, etc... where needed, instead of just writing i-1 or i+1 and let the computer figure it out. So, your solution can work, but not practical. The above also is one simple scheme, I have such things that work on 2D grids, which is even more complicated. If I can figure how to make the index itself a variable, like I can with Fortran or Matlab for example, then I'd be happy :) --Nasser