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=2.0 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,32d9aa9d79729b31 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.228.227 with SMTP id sl3mr12124027pbc.5.1340605953637; Sun, 24 Jun 2012 23:32:33 -0700 (PDT) Path: l9ni17234pbj.0!nntp.google.com!news2.google.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix? Date: Mon, 25 Jun 2012 01:32:30 -0500 Organization: Aioe.org NNTP Server Message-ID: References: <1xzo3825h9yt7$.45flobqwlel6.dlg@40tude.net> Reply-To: nma@12000.org NNTP-Posting-Host: KdJUrTuvv3Zv/s8pPxNluw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-06-25T01:32:30-05:00 List-Id: On 6/25/2012 12:44 AM, J-P. Rosen wrote: > Le 24/06/2012 19:14, Nasser M. Abbasi a �crit : > > If you want to avoid "if" in "loop": > >>> If you want a function which would return a submatrix obtained by >>> removing >>> the row I and column J: >> > function Exclude (A : Complex_Matrix; I, J : Integer) > return Complex_Matrix is > AI, AJ : Integer := A'First (1); > begin > return B : Complex_Matrix (1..A'Length (1)-1, 1..A'Length (2)-1) do > BI := 1; > for AI in A'First (1) .. I-1 loop > BJ := 1; > for AJ in A'First (2) .. J-1 loop > B (BI, BJ) := A (AI, AJ); > BJ := BJ + 1; > end loop; > > for AJ in J+1 .. A'Last (2) loop > B (BI, BJ) := A (AI, AJ); > BJ := BJ + 1; > end loop; > BI := BI + 1; > end loop; > > for AI in I+1 .. A'Last (1) loop > BJ := 1; > for AJ in A'First (2) .. J-1 loop > B (BI, BJ) := A (AI, AJ); > BJ := BJ + 1; > end loop; > > for AJ in J+1 .. A'Last (2) loop > B (BI, BJ) := A (AI, AJ); > BJ := BJ + 1; > end loop; > BI := BI + 1; > end loop; > end return; > end Exclude; > > Thanks J-P. Rosen. Ada is nice as it strongly typed and catches common errors. But it is not as 'expressive' I am afraid as I'd like for this sort of thing. In Mathematica for example, I do this whole operation in one line: --------------------------- Table[ReplacePart[A,{{i},{i,_},{_,j}}:>Sequence[]],{i,nRow},{j,nCol}]; --------------------------- That is all. This generates all submatrices from A as needed in this problem :) I've been learning Mathematica, and I find functional programming really powerful vs imperative programming, but it needs much more time getting used to. But this is for another topic and place to discuss. Thanks again for your input! --Nasser