comp.lang.ada
 help / color / mirror / Atom feed
From: "Nasser M. Abbasi" <nma@12000.org>
Subject: questions on using the array component iterator for 2012
Date: Sat, 23 Jun 2012 07:02:18 -0500
Date: 2012-06-23T07:02:18-05:00	[thread overview]
Message-ID: <js4b8m$21r$1@speranza.aioe.org> (raw)

reference

http://www.ada-auth.org/standards/12rm/html/RM-5-5-2.html

The  array component iterator seems nice, but I was not sure
if it can be used access elements in the matrix that are
indexed off the current iterator.

For example, assume I write

---------------------------------------------
with Ada.Numerics.Real_Arrays;  use Ada.Numerics.Real_Arrays;
procedure foo is
    A : constant Real_Matrix :=
          ( ( 1.0,  2.0, 3.0 ) ,
            ( 3.0,  5.0, 6.0 ) ,
            ( 7.0,  8.0, 9.0 ) );
begin
    FOR e of A  LOOP
        e := e + 1 ;
    END
end Matrix_Product;
---------------------------------------------

So the above adds '1' to each element in the matrix.
(order of iterations is defined in the RM, say I used
FORTRAN order).

But suppose I want to implement say a Jacobi relaxation
iteration to solve a 2D Laplace pde on that grid, which
is defined to update each element in the grid using

A(i) := (1/4) (  A(i-1,j)+A(i+1,j)+A(i,j-1)+A(i,j+1)

where here 'i' is row index, and 'j' is column index.

http://en.wikipedia.org/wiki/Relaxation_%28iterative_method%29

(iteration has to start from the second row and second column,
to avoid falling off the edge of the grid ofcourse, but this
is not important now)

i.e the above just replaces the current element in the matrix by
the average of the 4 adjacent elements in the little grid around
the current element.

My question is:

using 'e', this new iterator, can one somehow implement the above,
by somehow referencing these 4 adjacent elements in the grid?
(above, left, right, below)?

My point is that, if the iterator can be used only to access
the current element, then this might not be too useful.

For example, in the above example toy example, I do not
even need an iterator, I can use direct operation in Fortran or
Matlab say and just type

           A = 1.0 + A

(I do not know if one can do this in Ada btw?) May be
one needs to just define a "+" function for this. (I am not
too experienced in Ada, will try it).

Thanks
--Nasser



             reply	other threads:[~2012-06-23 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-23 12:02 Nasser M. Abbasi [this message]
2012-06-23 12:04 ` questions on using the array component iterator for 2012 Nasser M. Abbasi
2012-06-25 18:19 ` Adam Beneschan
2012-06-25 18:53   ` Nasser M. Abbasi
2012-06-27 23:31 ` Shark8
replies disabled

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