From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5556ca7de188d5ef X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-13 13:56:23 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!ppp-1-26.cvx4.telinco.NET!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Multidimensional array vs. array of array Date: Thu, 13 Dec 2001 21:49:35 -0000 Message-ID: <9vb864$e8rbj$3@ID-25716.news.dfncis.de> References: <3C17F5BF.AEBE40C3@worldnet.att.net> NNTP-Posting-Host: ppp-1-26.cvx4.telinco.net (212.1.148.26) X-Trace: fu-berlin.de 1008280581 14970227 212.1.148.26 (16 [25716]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Xref: archiver1.google.com comp.lang.ada:17882 Date: 2001-12-13T21:49:35+00:00 List-Id: "Lutz Donnerhacke" wrote in message news:slrna1grlf.k1.lutz@taranis.iks-jena.de... > >You can do it two different ways: > > > >1) Put the array of arrays in a record and return the record > > I'm unable to do this. Example? I don't think this can be done. > >2) Create an access type for the array of arrays. Dynamically > > allocate the array of arrays, and return its access value. > > *gna* No way. *drawing anti-satan symbols* Anyway that solves nothing, in itself. I suspect the only neat solution is for the next revision to permit multi-dimensional slices, and a new kind of 'dimension reducing' array conversion. In the meantime, I can only suggest that you fudge by: (1) using an appropriate multi-dimensional array; AND (1a) redefine all your row/column functions so that they accept this multidimensional array (and simply check that they have been given just one row or column); OR (1b) define a set of 'wrapper' functions that do this check, extract the row or column into an appropriate array type, and then call the proper function, perhaps doing the reverse conversion on the way back; OR (1c) redefine all your row/column functions so that they accept this multidimensional array plus an identification of the row/column to be operated upon. Horrid, yes, but I can't think of anything better. E.g.: type Matrix is array (Positive range <>, Positive range <>) of Float; ... function Sum_Row (M: in Matrix) return Float is R: Float := 0.0; begin if M'Length(1) /= 1 then raise Constraint_Error; -- or another exception end if; for i in M'Range(2) loop R := R + M(M'First(1),i); -- M'First(1)=M'Last(1)=row end loop; return R; end; An alternative with a wrapper function would be: type Vector is array (Positive range <>) of Float; ... function Sum (V: in Vector) return Float is R: Float := 0.0; begin for i in V'Range loop R := R + V(i); end loop; return R; end; ... function Sum_Row (M: in Matrix) return Float is V: Vector(M'Range(2)); begin if M'Length(1) /= 1 then raise Constraint_Error; -- or another exception end if; for i in M'Range(2) loop V(i) := M'(M'First(1),i); end loop; return Sum(V); end; Finally, you could pass the whole matrix (presumably this would actually be done by reference), and simply identify the row/column to be acted upon: function Sum_Row (M: in Matrix; Row: in Positive) return Float is R: Float := 0.0; begin for i in M'Range(2) loop R := R + M(Row,i); end loop; return R; end; It may be that the last solution, while ugly, is actually the fastest. Does this help at all? -- Best wishes, Nick Roberts