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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,bf03d731a6ef511f,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!postnews3.readnews.com!not-for-mail Message-Id: <4b6637a1$0$4586$4d3efbfe@news.sover.net> From: "Peter C. Chapin" Subject: Copying rows in a two dimensional array. Newsgroups: comp.lang.ada Date: Sun, 31 Jan 2010 21:11:12 -0500 User-Agent: KNode/0.10.9 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Organization: SoVerNet (sover.net) NNTP-Posting-Host: fdf49e76.news.sover.net X-Trace: DXC=P[PZ\1kHbAQ9LDU4]1BWK_K6_LM2JZB_SjTL1_ed;P:Y:WUUlR<856_`Rn;M9ja1b]1[JE7`M_DRT X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:8842 Date: 2010-01-31T21:11:12-05:00 List-Id: This is something of a newbie question.. I'm working with a two dimensional array of floating point values. Lets call it A. The array has type type Matrix is array(Positive range <>, Positive range <>) of Floating_Type; I need to exchange two rows in this array. What I'd like to do is something along these lines: Temp_Array := A(I, 1 .. Size); A(I, 1 .. Size) := A(K, 1 .. Size); A(K, 1 .. Size) := Temp_Array; The compiler (GNAT GPL 2009) has a problem with this syntax and, after looking into it some, I think that's because slicing only works for one dimensional arrays. Fair enough. So I thought, "Perhaps A needs to be an array of arrays." type Matrix is array(Positive range <>) of WHAT_EXACTLY? Apparently the component type of an array needs to be fully constrained (which again makes sense) yet I don't know the size I'll want to use at the point where this type is declared. So now I'm thinking that I'll have to write a procedure to explicity swap each row element one at a time. Of course this is not a terrible thing, but I'm wondering if there is a more elegant way that I'm missing. I have some confidence that the compiler can optimize slice operations reasonably well. I'm less confident about its ability to optimize element by element operations (maybe I'm overly pessimistic). Peter