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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.157.36.76 with SMTP id p70mr1498035ota.101.1485482092585; Thu, 26 Jan 2017 17:54:52 -0800 (PST) X-Received: by 10.157.18.211 with SMTP id g77mr462728otg.14.1485482092551; Thu, 26 Jan 2017 17:54:52 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!r185no538736ita.0!news-out.google.com!15ni11049itm.0!nntp.google.com!r185no533483ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 26 Jan 2017 17:54:52 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:5985:2c17:9409:aa9c References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Extend slices for n dimensional arrays for Ada 202X From: Robert Eachus Injection-Date: Fri, 27 Jan 2017 01:54:52 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:33183 Date: 2017-01-26T17:54:52-08:00 List-Id: On Thursday, January 26, 2017 at 1:29:07 PM UTC-5, Randy Brukardt wrote: > So I don't see this happening - it doesn't make sense in the context of A= da=20 > implementation strategies. Randy, I hope you are confused. First, if you are copying one array to ano= ther with correct (possibly sliding) bounds, you should check the bounds, t= hen do whatever copy is fastest on the current hardware. (This is moving f= rom 64 to 128 bits at a time, and current hardware supports single instruct= ion 256-bit and even 512-bit moves.) Yes, technically, if in strict mode a= nd the floating-point type you are using does not use non-signalling infini= ties, you might need to discover where an exception occurs and do a partial= copy. But if this is an object to object assignment, the best code with s= ignalling infinities would be to scan the data for signalling entries, then= do the copy. Having to back out half the copy is messy.=20 For decades I've been doing linear algebra in Ada where sometimes it helps = to have some arrays in row-major order and others in column-major order. T= ake simple matrix multiplication for example A * B --> C. If I declare B a= s "with Convention =3D> Fortran;" now I get significantly faster results f= rom: for I in A'Range(1) loop for J in B'Range(2) loop Temp :=3D 0.0; for K in A'Range(2) loop Temp :=3D Temp + A(I,K) * B(K,J); end loop; C(I,J) :=3D Temp; end loop; end loop; If you try it for reasonably large I, J, and K, you should find that the pa= yoff is large compared to the cost of transposing B once. (It is possible t= o transpose B in place (the J=3DK case is a lot easier than the general cas= e) but I'm used to having way more (virtual and real) memory than I need=20 In this case, B is accessed in the proper fashion. But the "ugly" computat= ions you complained about would be needed to iterate over B in row major or= der. I just assumed that all compilers generate the correct code for the h= ard case, which I don't use anyway. ;-)