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.36.172.79 with SMTP id m15mr9614704iti.36.1511558900284; Fri, 24 Nov 2017 13:28:20 -0800 (PST) X-Received: by 10.157.95.5 with SMTP id f5mr1253539oti.9.1511558900194; Fri, 24 Nov 2017 13:28:20 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.stack.nl!usenet-its.stanford.edu!usenet.stanford.edu!i6no5606332itb.0!news-out.google.com!193ni1072iti.0!nntp.google.com!d140no5613672itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 24 Nov 2017 13:28:19 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.209.130.105; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 71.209.130.105 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to access an array using two different indexing schemes From: Jerry Injection-Date: Fri, 24 Nov 2017 21:28:20 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: feeder.eternal-september.org comp.lang.ada:48179 Date: 2017-11-24T13:28:19-08:00 List-Id: On Friday, November 24, 2017 at 11:37:42 AM UTC-7, Per Sandberg wrote: > Hi a reflection. > Why the different indexing ? > /P >=20 Maybe I was unclear in my original post. There are numerous situations when being able to use different indexing wou= ld be a wonderful feature. And I believe doing so is in the spirit of abstr= action in Ada, possibly contrary to the comment in Norman Cohen's book to t= he contrary, at least in this one case. In signal processing* and other fields where sequences of numbers are often= used to represent values of a function over time, it is traditional to sta= rt indexing from zero, representing "zero time," the beginning of the exist= ence of the function. If sampling of a continuous function is involved, the= n with a sample period of T, the time t_n of each sample can be derived fro= m the sample index n as simply t_n =3D nT, aligning n =3D 0 with t =3D 0. = All time series are indexed this way in books and papers. Further, the same= data are often subject to mathematical manipulations involving such operat= ions as the discrete Fourier transform, an operation which is naturally exp= ressed with a zero-based indexing and which becomes a symbolic nightmare wh= en other indexing is used. However, the same people who deal with time series often need to place thes= e data into vectors and matrices for a whole host of reasons. Any textbook = in the world will use one-based indexing for both vectors and matrices. If = the programmer is locked into either zero-based indexing (e.g. C, Python, e= tc.) or one-based indexing (e.g. (old?) Fortran, Matlab, Mathematica), ther= e is a constant struggle to convert indices from one scheme to the other fo= r the various representations and operations, or else to adapt algorithms t= hemselves to accommodate the awkward scheme, and this not only makes ugly a= nd hard-to-read code, it is very prone to off-by-one errors. Alternately, in image processing, it might be convenient to assume the cent= er of the image is indexed as (0, 0), or it might derive naturally from the= underlying problem such as the center of a radar ground patch, thus requir= ing both negative and positive indices, perhaps (-1024 .. 1023, -1024 .. 10= 23). This convenience, again, might refer directly to the user's applicatio= n space. Now, if a DFT is required, it is almost certainly required that th= e matrix be indexed as (0, 2047, 0, 2047); if the indexing cannot be change= d, either the data must be copied to a suitable new matrix or the offsets c= omputed implicitly before being passed to the DFT or the DFT rewritten with= the offsets built into its internal indexing; none of these three methods = clears the programmer's head of the indexing mess, as it never actually goe= s away. Generally, I find languages that force a fixed indexing (always either 0 or= 1) to be unsuitable for the kind of work that I describe above. I find the= flame wars over zero- or one-based indexing to be humorously irrelevant an= d I would be delighted to see an Ada solution for this problem. As an elect= rical engineer working in signal processing, Pascal and then Ada have been = my workhorses for many years. I hope that helps. Jerry * Within the Institute of Electrical and Electronics Engineers, IEEE, the l= argest professional society in the world, the Signal Processing Society is = the second-largest after the Computer Society. The signal processing commun= ity is always at pains to have people understand what they do, when in fact= signal processing theory and practice permeates virtually every electronic= device.