From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Extend slices for n dimensional arrays for Ada 202X
Date: Thu, 26 Jan 2017 17:54:52 -0800 (PST)
Date: 2017-01-26T17:54:52-08:00 [thread overview]
Message-ID: <fb3687c7-0a40-4f8e-abfc-0438a45d2374@googlegroups.com> (raw)
In-Reply-To: <o6df5i$i1l$1@franka.jacob-sparre.dk>
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 Ada
> implementation strategies.
Randy, I hope you are confused. First, if you are copying one array to another with correct (possibly sliding) bounds, you should check the bounds, then do whatever copy is fastest on the current hardware. (This is moving from 64 to 128 bits at a time, and current hardware supports single instruction 256-bit and even 512-bit moves.) Yes, technically, if in strict mode and the floating-point type you are using does not use non-signalling infinities, 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 signalling infinities would be to scan the data for signalling entries, then do the copy. Having to back out half the copy is messy.
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. Take simple matrix multiplication for example A * B --> C. If I declare B as "with Convention => Fortran;" now I get significantly faster results from:
for I in A'Range(1) loop
for J in B'Range(2) loop
Temp := 0.0;
for K in A'Range(2) loop
Temp := Temp + A(I,K) * B(K,J);
end loop;
C(I,J) := Temp;
end loop;
end loop;
If you try it for reasonably large I, J, and K, you should find that the payoff is large compared to the cost of transposing B once. (It is possible to transpose B in place (the J=K case is a lot easier than the general case) but I'm used to having way more (virtual and real) memory than I need
In this case, B is accessed in the proper fashion. But the "ugly" computations you complained about would be needed to iterate over B in row major order. I just assumed that all compilers generate the correct code for the hard case, which I don't use anyway. ;-)
next prev parent reply other threads:[~2017-01-27 1:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 13:29 REQ: Extend slices for n dimensional arrays for Ada 202X Lucretia
2017-01-26 14:01 ` Lucretia
2017-01-26 14:03 ` Lucretia
2017-01-26 14:52 ` Dmitry A. Kazakov
2017-01-27 9:19 ` Alejandro R. Mosteo
2017-01-27 14:04 ` Lucretia
2017-01-26 18:29 ` Randy Brukardt
2017-01-27 1:54 ` Robert Eachus [this message]
2017-01-27 5:39 ` Robert Eachus
2017-01-27 14:06 ` Lucretia
2017-01-27 23:30 ` Randy Brukardt
2017-01-28 0:58 ` Robert Eachus
2017-01-27 9:34 ` Dmitry A. Kazakov
2017-01-27 13:53 ` G.B.
2017-01-27 14:20 ` Dmitry A. Kazakov
2017-01-27 23:37 ` Randy Brukardt
2017-01-28 9:08 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox