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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b375f07e05d12c7a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-06 19:59:13 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!netnews.com!newsfeed.nyc.globix.net!newsfeed.sjc.globix.net!cyclone-sf.pbi.net!206.13.28.143!news.pacbell.net.POSTED!not-for-mail Message-ID: <3B6F5ABC.3C40E189@sneakemail.com> From: "Russ P." <18k11tm001@sneakemail.com> X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.3-20mdk i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: efficient vector/matrix operations in Ada References: <3B6F40C1.FD215D1D@sneakemail.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 06 Aug 2001 20:04:28 -0700 NNTP-Posting-Host: 63.194.87.148 X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 997153152 63.194.87.148 (Mon, 06 Aug 2001 19:59:12 PDT) NNTP-Posting-Date: Mon, 06 Aug 2001 19:59:12 PDT Organization: SBC Internet Services Xref: archiver1.google.com comp.lang.ada:11440 Date: 2001-08-06T20:04:28-07:00 List-Id: tmoran@acm.org wrote: > > >tacky, ambiguous expressions like > > PlusEquals(A,B); > but is > Inc(A, B); > so bad or non-obvious? Fortran programmers, no slouch at fast matrix > operations, seem to have figured out a satisfactory approach. If you > are really pressed for speed, you are going to be calling an optimized > library anyway. I'm not looking for high-level optimization, I'm just looking for something that is reasonably efficient. > > > A = A + B; // inefficient > > > >is much less efficient than > > > > A += B; // efficient > > > >The former requires the dynamic construction of a temporary matrix to > >hold the sum (A + B), which must then be passed by value and copied into > >A. > Is A = A+B, an O(n**2) operation, going to be limiting the speed of > your matrix arithmetic, which probably involves some O(n**3) operations > if it does anything substantial? > Just because one way of doing it is slow doesn't mean there isn't a > fast way. For instance why does a temporary need to be dynamic? > Register oriented CPUs don't dynamically create a new register > every time they need one. One could easily imagine a machine with > vector instructions that can do A+B->C very fast, but has no special > instruction for A+B->A. In the case of a temporary matrix, of > course, "dynamic construction" could mean something as simple as > "move the stack pointer". Or your aithmetic operations could create > expressions, moving just pointers and op-codes, and the assignment > operator could analyze the expression and decide the fastest way > to actually calculate the result. Think outside of the box. ;) No, you really need the dynamically instantiated temporary matrix, I believe. I've been through this little lesson years ago. Don't forget that you also need to be able to handle expressions such as "A = B + C + D;". You can play complicated games with static arrays of "work" matrices, but you are asking for trouble and the resulting code is likely to not be re-entrant. -- Russ P. http://RussP.org