From: "(see below)" <yaldnif.w@blueyonder.co.uk>
Subject: Re: Copying rows in a two dimensional array.
Date: Tue, 09 Feb 2010 01:03:07 +0000
Date: 2010-02-09T01:03:07+00:00 [thread overview]
Message-ID: <C79664CB.1359AF%yaldnif.w@blueyonder.co.uk> (raw)
In-Reply-To: hkqamr$8mq$1@munin.nbi.dk
On 09/02/2010 00:36, in article hkqamr$8mq$1@munin.nbi.dk, "Randy Brukardt"
<randy@rrsoftware.com> wrote:
>
> "(see below)" <yaldnif.w@blueyonder.co.uk> wrote in message
> news:C7964E2E.135979%yaldnif.w@blueyonder.co.uk...
>> On 08/02/2010 21:20, in article wccd40fpgpu.fsf@shell01.TheWorld.com,
>> "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote:
>>
>>> It's trivial if you only want slices as R-values.
>>> And anyway, slices as L-values don't really work:
>>
>> I can't agree. I have this code:
>>
>> procedure FFT_to_HWT (FFTCs : in complex_array; ...
>> HWT_tree : out complex_array; ...) is
>> ...
>> iFFTCs : complex_array (1..f(FFTCs'length));
>> begin
>> ...
>> iFFTCs(1..nr_bins) := FFTCs(first_bin..last_bin);
>> iFFTCs(nr_bins+1..iFFT_size) := (others => (0.0,0.0));
>> inverse_FFT(iFFTCs(1..iFFT_size));
>> ...
>> HWT_tree(next_HWTC..next_HWTC+iFFT_size-1) := iFFTCs(1..iFFT_size);
>> ...
>> end FFT_to_HWT;
>>
>> I think that using slices as L-values as well as R-values helps to make
>> this
>> a lot clearer than it otherwise would be, and probably faster as well.
>
> It's cases like this that make both the pro and con for slices. Expressions
> like these are probably easier to read and probably faster than the
> equivalent non-slice code.
>
> But on the flip side, it's very hard to get the bounds right (I think I get
> these sorts of slices wrong 25% of the time). So you end up spending a lot
> of time debugging (at least Ada detects this). Moreover, it's hard to figure
> out from the code whether or not the bounds are right -- I'll often end
> drawing a picture and plug in various values to see if it makes sense. Case
But you rraly have to do that reasoning in any case.
> in point is the first statement; it fails unless last_bin - first_bin + 1 =
> nr_bins. So it's not clear how that is saving anything.
The elided statements include:
if ... then
nr_bins := ...;
last_bin := nr_bins + first_bin - 1;
else
last_bin := ...;
nr_bins := last_bin - first_bin + 1;
end if;
I was hoping the compiler would be able to propagate the bounds down to the
slices, and then note that:
iFFTCs(1..nr_bins)'Length == FFTCs(first_bin..last_bin)'Length
Perhaps that is asking too much.
Recoding thus:
iFFTCs(1..last_bin-first_bin+1) := FFTCs(first_bin..last_bin);
iFFTCs(last_bin-first_bin+2..iFFT_size) := (others => (0.0,0.0));
might even be an improvement in clarity, and I'd be disappointed if the
compiler did not then notice the identity of lengths.
--
Bill Findlay
<surname><forename> chez blueyonder.co.uk
next prev parent reply other threads:[~2010-02-09 1:03 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-01 2:11 Copying rows in a two dimensional array Peter C. Chapin
2010-02-01 4:42 ` Jeffrey R. Carter
2010-02-01 6:55 ` Niklas Holsti
2010-02-01 23:36 ` Peter C. Chapin
2010-02-04 4:27 ` Hibou57 (Yannick Duchêne)
2010-02-01 8:37 ` Dmitry A. Kazakov
2010-02-02 0:11 ` Randy Brukardt
2010-02-07 16:13 ` Robert A Duff
2010-02-08 6:30 ` tmoran
2010-02-08 13:15 ` Robert A Duff
2010-02-08 13:45 ` Dmitry A. Kazakov
2010-02-08 21:20 ` Robert A Duff
2010-02-08 23:26 ` (see below)
2010-02-09 0:36 ` Randy Brukardt
2010-02-09 1:03 ` (see below) [this message]
2010-02-09 7:11 ` Pascal Obry
2010-02-09 8:14 ` AdaMagica
2010-02-09 14:33 ` Robert A Duff
2010-02-09 1:05 ` Adam Beneschan
2010-02-09 14:45 ` Robert A Duff
2010-02-09 18:50 ` tmoran
2010-02-09 19:51 ` Pascal Obry
2010-02-09 23:03 ` Robert A Duff
2010-02-08 18:53 ` tmoran
2010-02-08 21:14 ` Robert A Duff
2010-02-08 21:29 ` Pascal Obry
2010-02-09 8:56 ` Jean-Pierre Rosen
2010-02-09 9:14 ` AdaMagica
2010-02-09 11:19 ` Jean-Pierre Rosen
2010-02-09 14:26 ` Robert A Duff
2010-02-09 6:34 ` tmoran
2010-02-09 14:29 ` Robert A Duff
2010-02-09 18:49 ` tmoran
2010-02-09 22:58 ` Robert A Duff
2010-02-01 22:10 ` Jerry
2010-02-02 0:07 ` Randy Brukardt
2010-02-02 8:52 ` Jean-Pierre Rosen
2010-02-02 22:23 ` Jerry
2010-02-03 1:24 ` Adam Beneschan
2010-02-04 4:42 ` Hibou57 (Yannick Duchêne)
2010-02-14 0:42 ` jonathan
2010-02-14 1:54 ` Hibou57 (Yannick Duchêne)
2010-02-14 16:16 ` jonathan
2010-03-22 8:56 ` Ole-Hjalmar Kristensen
2010-02-16 6:51 ` David Thompson
2010-02-04 4:13 ` Hibou57 (Yannick Duchêne)
2010-02-04 9:10 ` Dmitry A. Kazakov
2010-02-04 9:23 ` Hibou57 (Yannick Duchêne)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox