comp.lang.ada
 help / color / mirror / Atom feed
From: "Nasser M. Abbasi" <nma@12000.org>
Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix?
Date: Mon, 25 Jun 2012 12:36:00 -0500
Date: 2012-06-25T12:36:00-05:00	[thread overview]
Message-ID: <jsa7ht$dvb$1@speranza.aioe.org> (raw)
In-Reply-To: 4FE896B5.10405@obry.net

On 6/25/2012 11:49 AM, Pascal Obry wrote:
> Le 25/06/2012 08:32, Nasser M. Abbasi a �crit :
>> In Mathematica for example, I do this whole operation in one line:
>>
>> ---------------------------
>> Table[ReplacePart[A,{{i},{i,_},{_,j}}:>Sequence[]],{i,nRow},{j,nCol}];
>> ---------------------------
>
> Which is just unreadable if you ask me...
>
> Pascal.
>

Well, it is just because you are not used to the syntax. I am sure.

Just like when I read Perl, I do not understand it at all, but
I am sure someone who knows Perl, they would be able to write
in few words or lines some code to parse some strings, in what would
take me pages to write.

Once one gets used to the syntax and using pattern matching and
functional programming, it will become easy to read and understand,
and one will probably find it hard to go back to writing long
imperative code to do what they can do in few lines of functional
code.

Here is another one: Given a square matrix, determine if the
matrix is diagonal or not.

The function will return true if matirx is diagonal, and
false otherwise.

A diagonal matrix is one which have zeros everywhere off
the diagonal.

In Mathematica, this one line function does it

diagQ[m_] := m === DiagonalMatrix[Diagonal[m]]

Hence, given a matrix such as

a={{1,0,0},
    {0,2,0},
    {0,0,0}}

diagQ[a]
     ----> True

All what it does, is build up a diagonal matrix using the diagonal
elements of the matrix, and checks if the result is identical to
the matrix itself.

If I have to do this in Ada (unless there is build in function
to do this), I might have to use loops and check each element
off the diagonal, exist loop once I find non-zero element off
the diagonal, etc... and end up writing 20 lines of code at
least. (also I might have to make a contract pre/post may be,
not sure, may be not).

And I am not sure that will be more readable or easier to maintain
at the end.

ps. the above function does not have checks on its arguments, but
I can add these easily to make it more robust (using MatrixQ check
for example, and a check for matrix being square matrix, all easy/short
code to do).

regards,
--Nasser



  reply	other threads:[~2012-06-25 17:36 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-24  8:05 Any easy/build-in construct to extract submatrices from larger matrix? Nasser M. Abbasi
2012-06-24  8:24 ` Dmitry A. Kazakov
2012-06-24  8:55   ` Nasser M. Abbasi
2012-06-24 11:10     ` Dmitry A. Kazakov
2012-06-24 12:16       ` Nasser M. Abbasi
2012-06-24 16:11         ` Dmitry A. Kazakov
2012-06-24 17:14           ` Nasser M. Abbasi
2012-06-24 18:33             ` Dmitry A. Kazakov
2012-06-25  5:44             ` J-P. Rosen
2012-06-25  6:32               ` Nasser M. Abbasi
2012-06-25  7:54                 ` J-P. Rosen
2012-06-25  8:20                   ` Dmitry A. Kazakov
2012-06-25 14:21                   ` Nasser M. Abbasi
2012-06-25  8:36                 ` Georg Bauhaus
2012-06-25 13:17                   ` Nasser M. Abbasi
2012-06-26 11:44                     ` Georg Bauhaus
2012-06-25 16:49                 ` Pascal Obry
2012-06-25 17:36                   ` Nasser M. Abbasi [this message]
2012-06-25 18:49                     ` stefan-lucks
2012-06-26  4:41                       ` Nasser M. Abbasi
2012-06-26  7:15                 ` Jacob Sparre Andersen
2012-06-26  9:51                   ` Nasser M. Abbasi
2012-06-25  9:33               ` Simon Wright
2012-06-26  2:48 ` Jerry
2012-06-26  4:19   ` Nasser M. Abbasi
2012-06-26  7:06   ` Nasser M. Abbasi
2012-06-26 12:54     ` Robert A Duff
2012-06-26 15:19       ` Adam Beneschan
2012-06-26 21:14         ` Robert A Duff
2012-06-27 23:42     ` Shark8
2012-06-26  7:10   ` Dmitry A. Kazakov
2012-06-26 15:06   ` Adam Beneschan
2012-06-26 21:19     ` Robert A Duff
2012-06-26 21:40       ` Adam Beneschan
2012-07-03  4:22         ` Randy Brukardt
2012-07-03  8:37           ` Dmitry A. Kazakov
2012-07-05  1:33             ` Randy Brukardt
2012-07-05  7:08               ` Dmitry A. Kazakov
2012-07-06 23:47                 ` Randy Brukardt
2012-07-07  8:22                   ` Dmitry A. Kazakov
2012-07-05 18:56               ` Adam Beneschan
replies disabled

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