* old problem
@ 2019-05-30 10:26 Gilbert Gosseyn
2019-05-30 17:08 ` Anh Vo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gilbert Gosseyn @ 2019-05-30 10:26 UTC (permalink / raw)
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Generic_Real_Arrays;
package allx is
type Real is digits 18;
package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
use RA;
Dx,Dy,gK : Positive;
subtype RM is Real_Matrix(1..Dy,1..Dx);
type weight_array is array(1..gK) of RM;
end allx;
with allx; use allx;
with Ada.Text_IO;use Ada.Text_IO;
procedure testall is
package RIO is new Float_IO(Real);
use RIO;
use allx.RA;
W : weight_array;
D : RM := (others => (others => 1.0));
procedure testallx(D1 : RM;
W1 : in out weight_array) is
begin
for i in 1..gK loop
W1(i) := Real(i)*D1;
end loop;
end testallx;
begin
Dx := 3;
Dy := 5;
gK := 3;
testallx(D,W);
for k in 1..Dx loop
new_line(2);
for i in 1..Dy loop
new_line;
for j in 1..gK loop
RIO.put(W(k)(i,j));
end loop;
end loop;
end loop;
end testall;
raised CONSTRAINT_ERROR : testall.adb:13 (W1(i) := ...) index check failed, and of course if I use numbers in package allx, then W1(i) is known.
How to keep the dimensions Dx,Dy,gK open until execution?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: old problem
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
2 siblings, 0 replies; 4+ messages in thread
From: Anh Vo @ 2019-05-30 17:08 UTC (permalink / raw)
On Thursday, May 30, 2019 at 3:26:17 AM UTC-7, Gilbert Gosseyn wrote:
> with Ada.Numerics; use Ada.Numerics;
> with Ada.Numerics.Generic_Real_Arrays;
> package allx is
> type Real is digits 18;
> package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
> use RA;
> Dx,Dy,gK : Positive;
> subtype RM is Real_Matrix(1..Dy,1..Dx);
> type weight_array is array(1..gK) of RM;
> end allx;
>
> with allx; use allx;
> with Ada.Text_IO;use Ada.Text_IO;
> procedure testall is
> package RIO is new Float_IO(Real);
> use RIO;
> use allx.RA;
> W : weight_array;
> D : RM := (others => (others => 1.0));
> procedure testallx(D1 : RM;
> W1 : in out weight_array) is
> begin
> for i in 1..gK loop
> W1(i) := Real(i)*D1;
> end loop;
> end testallx;
>
> begin
> Dx := 3;
> Dy := 5;
> gK := 3;
> testallx(D,W);
> for k in 1..Dx loop
> new_line(2);
> for i in 1..Dy loop
> new_line;
> for j in 1..gK loop
> RIO.put(W(k)(i,j));
> end loop;
> end loop;
> end loop;
> end testall;
>
> raised CONSTRAINT_ERROR : testall.adb:13 (W1(i) := ...) index check failed, and of course if I use numbers in package allx, then W1(i) is known.
> How to keep the dimensions Dx,Dy,gK open until execution?
Lines 7 and 8 will trigger a CONSTRAINT_ERROR warning when this problem is compiled under GNAT.
Replace
subtype RM is Real_Matrix(1..Dy,1..Dx);
type weight_array is array(1..gK) of RM;
with
Max : constant := 100; -- can be adjusted
subtype Index_Range is Positive range 1 .. Max;
subtype RM is Real_Matrix(Index_Range, Index_Range);
type weight_array is array(Index_Range) of RM;
Anh Vo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: old problem
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
2 siblings, 0 replies; 4+ messages in thread
From: Keith Thompson @ 2019-05-31 1:04 UTC (permalink / raw)
Gilbert Gosseyn <hnptz@yahoo.de> writes:
> with Ada.Numerics; use Ada.Numerics;
> with Ada.Numerics.Generic_Real_Arrays;
> package allx is
> type Real is digits 18;
> package RA is new Ada.Numerics.Generic_Real_Arrays(Real);
> use RA;
> Dx,Dy,gK : Positive;
> subtype RM is Real_Matrix(1..Dy,1..Dx);
> type weight_array is array(1..gK) of RM;
> end allx;
[...]
Dy and Dx are uninitialized when Real_Matrix is defined. Their values
will be arbitrary garbage when the declaration of RM is elaborated.
(I'm a bit surprised you didn't get a compile-time warning.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: old problem
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
2 siblings, 0 replies; 4+ messages in thread
From: Simon Wright @ 2019-05-31 12:37 UTC (permalink / raw)
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;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-05-31 12:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox