From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: old problem
Date: Thu, 30 May 2019 10:08:12 -0700 (PDT)
Date: 2019-05-30T10:08:12-07:00 [thread overview]
Message-ID: <386cd03d-641d-451e-9c42-f8e157ac290b@googlegroups.com> (raw)
In-Reply-To: <6df29358-0e30-4478-9473-6580d5cb555c@googlegroups.com>
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
next prev parent reply other threads:[~2019-05-30 17:08 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 [this message]
2019-05-31 1:04 ` Keith Thompson
2019-05-31 12:37 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox