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,38fc011071df5a27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-09 08:52:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.cwix.com!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Mon, 09 Jun 2003 11:51:56 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030529 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ideas for Ada 200X References: <07yEa.45802$ca5.25203@nwrdny02.gnilink.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1055173916.550383@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1055173917 26143 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:38862 Date: 2003-06-09T11:51:56-04:00 List-Id: Russ wrote: > Interesting. Where can I learn more about this? Here's a general explanation of how expression templates work in C++. The language features used are the ability to overload the array indexing and function call operators and automatic type deduction and instantiation of function templates. We declare our matrix types, and whatever other types we need. We define the arithmetic and indexing operators on these types not to actually do anything except note the operator and references to the operands, in effect making a runtime parse tree of the expression. Finally, when an actual value is required, suc has upon assignment, the entire structure can be evaluated, with the compiler doing massive inlining to achieve the efficiency of handwritten code. For example, suppose we have the matrix expression C = A + B. When A + B is evaluated, the result is a special "addition" object which holds references to A and B. This object has an overloaded indexing operator, such that when add_obj(i,j) is requested, it produces a(i,j) + b(i,j), where a and b are the saved operand references. The Matrix class has an assignment operator which simply (or complexly, sometimes) iterates, doing c(i,j) = rhs(i,j). This works for expressions of any complexity, as long as the compiler is willing to inline. The iteration pattern itself can be modified to take advantage of cache coherency; the Blitz++ library includes the ability to traverse multidimensional matrices using a space-filling curve to stay local.