comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: how to copy complete column (or row) of matrix to another?
Date: Sun, 17 Sep 2017 05:01:45 -0700 (PDT)
Date: 2017-09-17T05:01:45-07:00	[thread overview]
Message-ID: <f2940549-4c01-43fc-8378-90fc2845eb45@googlegroups.com> (raw)
In-Reply-To: <oolo0a$1djr$1@gioia.aioe.org>

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?


      parent reply	other threads:[~2017-09-17 12:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05  8:41 how to copy complete column (or row) of matrix to another? Nasser M. Abbasi
2017-09-05 22:45 ` Randy Brukardt
2017-09-05 23:10   ` Nasser M. Abbasi
2017-09-06  5:34     ` faryumg
2018-03-21 13:58       ` Marius Amado-Alves
2018-03-30 21:25         ` gerdien.de.kruyf
2017-09-06  7:17     ` Simon Wright
2017-09-06  7:31   ` Dmitry A. Kazakov
2017-09-09 22:33 ` darek
2017-09-09 22:48 ` darek
2017-09-12 12:57   ` Lucretia
2017-10-02 23:08     ` Randy Brukardt
2017-09-12 21:22 ` Johan Söderlind Åström
2017-09-17 12:01 ` Robert Eachus [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox