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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.205.139 with SMTP id d133mr6622500iog.70.1505649705724; Sun, 17 Sep 2017 05:01:45 -0700 (PDT) X-Received: by 10.36.250.140 with SMTP id v134mr395480ith.0.1505649705689; Sun, 17 Sep 2017 05:01:45 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.unit0.net!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!o200no1577890itg.0!news-out.google.com!c139ni3131itb.0!nntp.google.com!o200no1577889itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 17 Sep 2017 05:01:45 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:9147:330:e79e:de46; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:9147:330:e79e:de46 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: how to copy complete column (or row) of matrix to another? From: Robert Eachus Injection-Date: Sun, 17 Sep 2017 12:01:45 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 2607 X-Received-Body-CRC: 4178158818 Xref: news.eternal-september.org comp.lang.ada:48169 Date: 2017-09-17T05:01:45-07:00 List-Id: On Tuesday, September 5, 2017 at 4:41:49 AM UTC-4, Nasser M. Abbasi wrote: > Here is a toy example. I want to copy one matrix > to another using a loop (to see if this is allowed) > -------------------------- > procedure t1 is > type Matrix is array (Integer range <>, Integer range <>) of Integer; > A : Matrix := > (( 1, 2, 3), > ( 4, 5, 6), > ( 7, 8, 9)); > B: Matrix(1..3,1..3); > begin -- copy A to B one row at a time If you don't insist on a loop, A := B; works just fine. If you really need to work with Rows and Columns I define: function Row(M: in Matrix; I: in Index) return Vector; function Column(M: in Matrix; I: in Index) return Vector; The reason the language doesn't define these operations is that there are lots of Matrix and Vector types to be dealt with. (I have some algorithms that use slices of arrays of Booleans--and stores them in 64-bit Unsigned types.) What if you also need to assign to rows or columns without copying the matrix? You could use access types, but I just depend on the compiler being sane and define: procedure Replace_Row (M: in out Matrix; I: in Index; V: in Vector); I suppose I could provide these as a generic. Would that be useful? Hmmm. Probably should have separate index types for matrices, rows, and columns (a total of four). Or is that too complex, even if it is only really visible in the generic parameters?