Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Those who can, do; those who can't, simulate.


devel / comp.lang.ada / 2-dimensional view on 1 dimensional array

SubjectAuthor
* 2-dimensional view on 1 dimensional arrayMarek
+* Re: 2-dimensional view on 1 dimensional arrayAdaMagica
|`* Re: 2-dimensional view on 1 dimensional arrayAdaMagica
| `- Re: 2-dimensional view on 1 dimensional arrayAdaMagica
`* Re: 2-dimensional view on 1 dimensional arrayJ-P. Rosen
 `* Re: 2-dimensional view on 1 dimensional arrayJeffrey R.Carter
  `- Re: 2-dimensional view on 1 dimensional arrayJ-P. Rosen

1
2-dimensional view on 1 dimensional array

<tj3c6q$178e9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8955&group=comp.lang.ada#8955

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ficorax@gmail.com (Marek)
Newsgroups: comp.lang.ada
Subject: 2-dimensional view on 1 dimensional array
Date: Sun, 23 Oct 2022 14:31:22 +0200
Organization: A noiseless patient Spider
Lines: 149
Message-ID: <tj3c6q$178e9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 23 Oct 2022 12:31:22 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="bf5d702cf9c441d4f50ef8eb9cd2c095";
logging-data="1286601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Usf13KML1ukaJv+0I9mCC"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.2.2
Cancel-Lock: sha1:RFR9JPy2cAa9AhHXiH5EgxGdkFQ=
Content-Language: en-US
 by: Marek - Sun, 23 Oct 2022 12:31 UTC

Hi.
Assume we have:

generic
type T is private;
type T_Array is array (Natural range <>) of aliased T;
type T_Array_Access is access all T_Array;
package Buffers is

type Row_Array is array (Natural range <>) of aliased
T_Array_Access;

type Row_Array_Access is access all Row_Array;

type Buffer is tagged
record
Raw_Buffer : T_Array_Access := null;
Rows_Table : Row_Array_Access := null;
Rows : Natural := 0;
Columns : Natural := 0;
Step : Integer := 0;
Max_Rows : Natural := 0;
end record;

procedure Init
(This : in out Buffer;
Buffer : T_Array_Access;
Rows : Natural;
Columns : Natural;
Step : Integer);

procedure Set_Value
(This : in out Buffer;
Value : T);

end Buffers;

...and:

with Ada.Unchecked_Deallocation;

package body Buffers is

type T_Access is access all T;

------------
-- Init --
------------

procedure Init
(This : in out Buffer;
Buffer : T_Array_Access;
Rows : Natural;
Columns : Natural;
Step : Integer)
is
procedure Free is
new Ada.Unchecked_Deallocation (Row_Array, Row_Array_Access);

Row_Index : Integer := 0;
begin
This.Raw_Buffer := Buffer;
This.Rows := Rows;
This.Columns := Columns;
This.Step := Step;

if Rows > This.Max_Rows then
if This.Rows_Table /= null then
Free (This.Rows_Table);
end if;

declare
New_Rows : constant Row_Array_Access :=
new Row_Array (0 .. Rows - 1);
begin
This.Rows_Table := New_Rows;
This.Max_Rows := Rows;
end;
end if;

for H in 0 .. Rows - 1 loop
declare
Row_Start : constant T_Access :=
This.Raw_Buffer (Row_Index * Step)'Access;
begin
This.Rows_Table (H) := ... -- What code here?

Row_Index := Row_Index + 1;
end;
end loop;

end Init;

-----------------
-- Set_Value --
-----------------

procedure Set_Value
(This : in out Buffer;
Value : T)
is
begin
if This.Rows > 0 then
for Y in 0 .. This.Rows - 1 loop
declare
Row : constant T_Array_Access := This.Rows_Table (Y);
begin
if This.Step > 0 then
for X in 0 .. This.Step - 1 loop
Row (X) := Value;
end loop;
end if;
end;
end loop;
end if;
end Set_Value;

end Buffers;

and finally:

with Buffers;

procedure Test is

type Float_Array is array (Natural range <>) of aliased Float;

type Float_Array_Access is access all Float_Array;

package Buffer_Package is
new Buffers (Float, Float_Array, Float_Array_Access);

use Buffer_Package;

A : aliased Float_Array := (0 .. 99 => 0.0);
B : Buffer_Package.Buffer;
begin

B.Init (A'Access, 10, 10, 10);
B.Set_Value (10.0);
end Test;

Is there any possibilities to get this working?
Idea is to have another (2 dimensional) view on 1 dimensional array.
Unchecked_Conversion is not working (different sizes of objects).
Address_To_Access conversion also (unconstrained array);

Marek

Re: 2-dimensional view on 1 dimensional array

<fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8958&group=comp.lang.ada#8958

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:24c9:b0:6ee:d791:9f84 with SMTP id m9-20020a05620a24c900b006eed7919f84mr22931424qkn.490.1666607479298;
Mon, 24 Oct 2022 03:31:19 -0700 (PDT)
X-Received: by 2002:a05:622a:15c7:b0:39b:2791:cd44 with SMTP id
d7-20020a05622a15c700b0039b2791cd44mr26404928qty.676.1666607479160; Mon, 24
Oct 2022 03:31:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 24 Oct 2022 03:31:18 -0700 (PDT)
In-Reply-To: <tj3c6q$178e9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.31.101.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 94.31.101.23
References: <tj3c6q$178e9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com>
Subject: Re: 2-dimensional view on 1 dimensional array
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Mon, 24 Oct 2022 10:31:19 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2461
 by: AdaMagica - Mon, 24 Oct 2022 10:31 UTC

Your code looks rather ununderstandable to me.
A quick attempt on what you claimed you are trying to do (no guarantee):

generic

type T is private;

type T_Array is array (Integer range <>) of T;

package Dim1_to_2 is

-- type T_Array_2Dim is array (Integer range <>, Integer range <>) of T;

procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T)
with Pre => Row in 1 .. Num_Row and Col in 1 .. Num_Col and
Num_Row * Num_col = TA'Length;

end Dim1_to_2;
package body Dim1_to_2 is

type T_Array_2Dim is array (Integer range <>, Integer range <>) of T;

procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T) is
TA2: T_Array_2Dim (1 .. Num_Row, 1 .. Num_Col);
for TA2'Address use TA'Address;
begin
if Num_Row * Num_Col /= TA'Length or
Row not in 1 .. Num_Row or Col not in 1 .. Num_Col then
raise Constraint_Error;
end if;
TA2 (Row, Col) := Value;
end Set;

end Dim1_to_2;
with Dim1_to_2;

procedure Ausprobieren is

type A is array (Integer range <>) of Integer;

X: aliased A (-10 .. 10) := (others => 0);

package To_2D is new Dim1_to_2 (Integer, A);

begin

To_2D.Set (X, Row => 2, Num_Row => 7, Col => 1, Num_Col => 3, Value => -1);

for V of X loop
Put_Line (V'Image);
end loop;

Re: 2-dimensional view on 1 dimensional array

<94f2dcb4-8708-4ff9-8f5d-b87231fa636fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8959&group=comp.lang.ada#8959

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:19a6:b0:6ee:d3d6:6b03 with SMTP id bm38-20020a05620a19a600b006eed3d66b03mr21775808qkb.376.1666607737084;
Mon, 24 Oct 2022 03:35:37 -0700 (PDT)
X-Received: by 2002:a05:6214:21ca:b0:4bb:4a55:b63b with SMTP id
d10-20020a05621421ca00b004bb4a55b63bmr12436460qvh.0.1666607736970; Mon, 24
Oct 2022 03:35:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 24 Oct 2022 03:35:36 -0700 (PDT)
In-Reply-To: <fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=94.31.101.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 94.31.101.23
References: <tj3c6q$178e9$1@dont-email.me> <fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <94f2dcb4-8708-4ff9-8f5d-b87231fa636fn@googlegroups.com>
Subject: Re: 2-dimensional view on 1 dimensional array
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Mon, 24 Oct 2022 10:35:37 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1238
 by: AdaMagica - Mon, 24 Oct 2022 10:35 UTC

The object X must be aliased because of the address clauses.

Re: 2-dimensional view on 1 dimensional array

<410365c1-8eb5-4c92-b930-e1c350cbd76an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8960&group=comp.lang.ada#8960

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:7dc4:0:b0:39c:f95f:57fe with SMTP id c4-20020ac87dc4000000b0039cf95f57femr28645064qte.612.1666695958021;
Tue, 25 Oct 2022 04:05:58 -0700 (PDT)
X-Received: by 2002:a05:6214:528f:b0:4bb:6376:5f8a with SMTP id
kj15-20020a056214528f00b004bb63765f8amr12276316qvb.71.1666695957893; Tue, 25
Oct 2022 04:05:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 25 Oct 2022 04:05:57 -0700 (PDT)
In-Reply-To: <94f2dcb4-8708-4ff9-8f5d-b87231fa636fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=94.31.101.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 94.31.101.23
References: <tj3c6q$178e9$1@dont-email.me> <fd437bfd-a4bd-4c31-b005-bb702f4419f5n@googlegroups.com>
<94f2dcb4-8708-4ff9-8f5d-b87231fa636fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <410365c1-8eb5-4c92-b930-e1c350cbd76an@googlegroups.com>
Subject: Re: 2-dimensional view on 1 dimensional array
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Tue, 25 Oct 2022 11:05:58 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1392
 by: AdaMagica - Tue, 25 Oct 2022 11:05 UTC

Also interesting: The array is an in-parameter. You get a variable view with the overlay. Clever Gnat gives you a warning. Don't know what other cmpilers say.

Re: 2-dimensional view on 1 dimensional array

<tj8mfa$1uilq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8961&group=comp.lang.ada#8961

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rosen@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: 2-dimensional view on 1 dimensional array
Date: Tue, 25 Oct 2022 14:57:15 +0200
Organization: Adalog
Lines: 22
Message-ID: <tj8mfa$1uilq$1@dont-email.me>
References: <tj3c6q$178e9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Oct 2022 12:57:14 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="05a4a621f64eef138ffa9a66b1247c44";
logging-data="2050746"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6ShVscWKX4WuKdaGEK5ZD"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.0
Cancel-Lock: sha1:H4hXhjUxKJuG18zMXdhtU/Xzp24=
Content-Language: fr
In-Reply-To: <tj3c6q$178e9$1@dont-email.me>
 by: J-P. Rosen - Tue, 25 Oct 2022 12:57 UTC

Le 23/10/2022 à 14:31, Marek a écrit :
> generic
>        type T is private;
>        type T_Array is array (Natural range <>) of aliased T;
>        type T_Array_Access is access all T_Array;
>     package Buffers is
>
>        type Row_Array is array (Natural range <>) of aliased
> T_Array_Access;
>
>        type Row_Array_Access is access all Row_Array;
Here I see a pointer to an array of pointers to an array whose
components can pointed to...
That's too much for my small head ( (c) Hoare)
Can you explain what you try to accomplish?

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr

Re: 2-dimensional view on 1 dimensional array

<tj90ph$225be$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8962&group=comp.lang.ada#8962

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: 2-dimensional view on 1 dimensional array
Date: Tue, 25 Oct 2022 17:53:21 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <tj90ph$225be$1@dont-email.me>
References: <tj3c6q$178e9$1@dont-email.me> <tj8mfa$1uilq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Oct 2022 15:53:21 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f26675eaee5c19d7d67bbdd2f2063da5";
logging-data="2168174"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MOJd/QMsXIsHGiYOgDJaSaXr+3s9/7BM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.2.2
Cancel-Lock: sha1:fPCgjwlu5VpxaZWCzSv2TciUXUs=
In-Reply-To: <tj8mfa$1uilq$1@dont-email.me>
Content-Language: en-US
 by: Jeffrey R.Carter - Tue, 25 Oct 2022 15:53 UTC

On 2022-10-25 14:57, J-P. Rosen wrote:
> That's too much for my small head ( (c) Hoare)

I am familiar with the Dijkstra quote, "I have a very small head and I had
better learn to live with it". Did Hoare say something along those lines, too?

--
Jeff Carter
"[Many] programmers do not use [languages with
automatic run-time checks] because 'They're not
efficient.' (Presumably this means that it is
vital to get the wrong answers quickly.)"
Elements of Programming Style
193

Re: 2-dimensional view on 1 dimensional array

<tj9evk$25vkq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=8965&group=comp.lang.ada#8965

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rosen@adalog.fr (J-P. Rosen)
Newsgroups: comp.lang.ada
Subject: Re: 2-dimensional view on 1 dimensional array
Date: Tue, 25 Oct 2022 21:55:33 +0200
Organization: Adalog
Lines: 12
Message-ID: <tj9evk$25vkq$1@dont-email.me>
References: <tj3c6q$178e9$1@dont-email.me> <tj8mfa$1uilq$1@dont-email.me>
<tj90ph$225be$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Oct 2022 19:55:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="af91fe6d064ef732e7e12213eb6d1e34";
logging-data="2293402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cJxBz3lag4uirl9CHtIMm"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.0
Cancel-Lock: sha1:f11dMwA9kUqz+bOrOLb8aVQPKwY=
In-Reply-To: <tj90ph$225be$1@dont-email.me>
Content-Language: fr
 by: J-P. Rosen - Tue, 25 Oct 2022 19:55 UTC

Le 25/10/2022 à 17:53, Jeffrey R.Carter a écrit :
> I am familiar with the Dijkstra quote, "I have a very small head and I
> had better learn to live with it". Did Hoare say something along those
> lines, too?
My confusion, must be Dijkstra. But that's the quote I wanted...

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr


devel / comp.lang.ada / 2-dimensional view on 1 dimensional array

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor