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 autolearn=ham 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-7-bit Received: by 10.68.219.170 with SMTP id pp10mr16011777pbc.1.1340694943968; Tue, 26 Jun 2012 00:15:43 -0700 (PDT) Path: l9ni21120pbj.0!nntp.google.com!news1.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!newsfeed.x-privat.org!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix? Date: Tue, 26 Jun 2012 09:15:39 +0200 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: <878vfay25g.fsf@adaheads.sparre-andersen.dk> References: <1xzo3825h9yt7$.45flobqwlel6.dlg@40tude.net> NNTP-Posting-Host: 95.209.229.11.bredband.3.dk Mime-Version: 1.0 X-Trace: munin.nbi.dk 1340694940 4599 95.209.229.11 (26 Jun 2012 07:15:40 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 26 Jun 2012 07:15:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:SfhZGk20nuprslsrtfKaKS7Hm20= Content-Type: text/plain; charset=us-ascii Date: 2012-06-26T09:15:39+02:00 List-Id: Nasser M. Abbasi wrote: > J-P. Rosen wrote: >> function Exclude (A : Complex_Matrix; I, J : Integer) >> return Complex_Matrix is >> AI, AJ : Integer := A'First (1); I suspect a compiler would advise that the above line is changed to: BI, BJ : Integer; >> 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; > In Mathematica for example, I do this whole operation in one line: > > --------------------------- > Table[ReplacePart[A,{{i},{i,_},{_,j}}:>Sequence[]],{i,nRow},{j,nCol}]; > --------------------------- I'm not sure if Mathematica has sufficient syntax highlighting to make it easy to keep track of the grouping of the various parentheses, but as it appears here, I would definitely want to break it up a bit, to make it more readable. - My Mathematica so rusty that even when I do that, I'm still not quite certain that your function works correctly. Yes, the Ada solution Jean-Pierre presented is more verbose. (And yes, there was an error in it. ;-) But to an Ada programmer with a bit of experience, the challenging part is to make sure the indexes aren't mixed up anywhere. This takes some time. - But (to me) counting parenteses and making sure they match up also takes time. (But probably not quite as much.) Greetings, Jacob -- "It ain't rocket science!"