comp.lang.ada
 help / color / mirror / Atom feed
From: "Nasser M. Abbasi" <nma@12000.org>
Subject: Re: on using array index, vectorized operation
Date: Sun, 27 Mar 2011 13:44:41 -0700
Date: 2011-03-27T13:44:41-07:00	[thread overview]
Message-ID: <imo7jn$ll4$1@speranza.aioe.org> (raw)
In-Reply-To: dd2a546a-50d8-4dc4-8455-a50aa1454f1b@34g2000pru.googlegroups.com

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



  reply	other threads:[~2011-03-27 20:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-27  1:31 on using array index, vectorized operation Nasser M. Abbasi
2011-03-27 18:48 ` Nasser M. Abbasi
2011-03-27 20:01 ` Cyrille
2011-03-27 20:44   ` Nasser M. Abbasi [this message]
2011-03-27 21:02     ` Pascal Obry
2011-03-27 21:30     ` Shark8
2011-03-27 22:00       ` Nasser M. Abbasi
2011-03-27 22:37         ` Phil Clayton
2011-03-27 22:43           ` Nasser M. Abbasi
2011-03-27 22:59             ` Phil Clayton
2011-03-27 22:09     ` Phil Clayton
2011-03-27 22:12       ` Nasser M. Abbasi
2011-03-27 22:23       ` Nasser M. Abbasi
2011-03-29  2:50         ` Randy Brukardt
2011-03-29  4:55           ` Nasser M. Abbasi
2011-03-29 20:11             ` Phil Clayton
2011-03-29 21:17               ` Nasser M. Abbasi
2011-03-29 22:49                 ` Phil Clayton
2011-03-29 23:47                   ` Nasser M. Abbasi
2011-03-30 13:00                     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox