comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: old problem
Date: Fri, 31 May 2019 13:37:52 +0100
Date: 2019-05-31T13:37:52+01:00	[thread overview]
Message-ID: <ly1s0e91sd.fsf@pushface.org> (raw)
In-Reply-To: 6df29358-0e30-4478-9473-6580d5cb555c@googlegroups.com

Gilbert Gosseyn <hnptz@yahoo.de> writes:

> How to keep the dimensions Dx,Dy,gK open until execution?

You could make allx a generic, as in the following. I used gnatpp &
adjusted casing; I used 'Range rather than 1 .. Dx etc, but it would
have been possible to make the values visible in the generic
instantiation, e.g.

   Actual_Dx : constant := Dx;

but using the attribute ('Range) is better.

with Ada.Numerics.Generic_Real_Arrays;
generic
   with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (<>);
   Dx, Dy, gK : Positive;
package Allx is
   subtype RM is Real_Arrays.Real_Matrix (1 .. Dy, 1 .. Dx);
   type Weight_Array is array (1 .. gK) of RM;
end Allx;

with Ada.Numerics.Generic_Real_Arrays;
with Allx;
with Ada.Text_IO; use Ada.Text_IO;
procedure Testall is
   type Real is digits 18;
   package RIO is new Ada.Text_IO.Float_IO (Real);
   package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
   package My_Allx is new Allx (Real_Arrays => Real_Arrays,
                                Dx => 3,
                                Dy => 5,
                                Gk => 3);
   use My_Allx;
   W : Weight_Array;
   D : RM := (others => (others => 1.0));
   procedure Testallx (D1 : RM; W1 : in out Weight_Array) is
      use Real_Arrays;
   begin
      for I in W1'Range loop
         W1 (I) := Real (I) * D1;
      end loop;
   end Testallx;
begin
   Testallx (D, W);
   for K in D'Range (2) loop
      New_Line;
      for I in D'Range (1) loop
         New_Line;
         for J in W'Range loop
            RIO.Put (W (K) (I, J));
         end loop;
      end loop;
      New_Line;
   end loop;
end Testall;

      parent reply	other threads:[~2019-05-31 12:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-30 10:26 old problem Gilbert Gosseyn
2019-05-30 17:08 ` Anh Vo
2019-05-31  1:04 ` Keith Thompson
2019-05-31 12:37 ` Simon Wright [this message]
replies disabled

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