Re: Is subscripting a slice useful
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Oct 12, 2004
- 553 views
> Date: Tue, 12 Oct 2004 02:03:10 +0100 From: Pete Lomax <petelomax at > blueyonder.co.uk> Subject: Re: Is subscripting a slice useful On 11 Oct 2004 > 11:56:47 +0200, Christian Cuvier <Christian.CUVIER at agriculture.gouv.fr> wrote: > >>>You are using a typo from the original message to make your point > > Would that be the same typo mercilessly repeated no less than NINE > times in a subsequent post? ) > >>>about your personal dislike of this construct. > > I'm entitled to an opinion, last time I checked. > Of course, but using methods that rely on an error borders on the unfair. Well, that's not the main point abyway. >>> >> >>>>> There is *no* way that asdf[1..2] should return anything other than a >>>>> sequence of length 2, >> >>> >>>True >>> >> >>>>> and hence a nested subscript of that could not >>>>> possibly yield a sequence of length 4. >> >>> >>>False, if the intermediate sequence is made of sequences itself. > > I don't understand what you mean. Please give me an example. Let's call this question Q0, see below. >>> >> >>>>> This whole idea (which has been extensively discussed before) is so >>>>> open to misinterpretation it should definitely NOT be "standard". >>>>> Every application needs something different. >> >>> >>>Really? Most of them need vertical slicing anyway, so it is desirable for it >>>to become a standard. Could you give some examples of different schemes that >>>might be concurrently needed? > > The complexities this introduces worry me, and I fear it is not > flexible enough to justify it. Suppose that > c = > {{{2,4,6,20}, {8,10,12,22}, {14,16,18,24}}, > {{3,6,9,30}, {12,15,18,33}, {21,24,27,36}}, > {{24,25,26,33}, {27,28,29,34}, {30,31,32,35}}} > > How do you get {8,14,12,21}? > You need the [] construct, which would mean "skip this level of sequencing". Then you can go to this point by using c[1..2][2..3][][][1]. Not flexible enough, you said? Slicing just restricts the range of available indexes; you need another operator to reduce depth. > For that matter, and to spoil your fun, what is c[1..2][2..3][1..1]? > Can you explain to me why that should _not_ be > {{{8,10,12,22}}, {{12,15,18,33}}} ? Well, I can undestand how you got there, but it's not consistent: c[1..2] is {{{2,4,6,20}, {8,10,12,22}, {14,16,18,24}}, {{3,6,9,30}, {12,15,18,33}, {21,24,27,36}}} Apply [2..3] to it -> {{{8,10,12,22}, {14,16,18,24}}, {{12,15,18,33}, {21,24,27,36}}} (answers Q0 btw) Apply [1..1] to it -> {{{8}, {14}}, {{12}, {21}}} Explanation is: c[1..2][2..3][1..1] restricts the first index level to lie between 1 and 2, the second one between 2 and 3 and the third one between 1 and 1. {{{8,10,12,22}}, {{12,15,18,33}}} would be (c[1..2][2..3])[1..2][1..1] by considering the intermediate result above as a 2x2 matrix and operating on it *as such*. Forgetting the parens would be an error, since there are 3 index levels only, not 4. > Also, do you believe that eg > > c[2..3][2][3..4]+=1 > > should be supported? No, but c[2..3][2..2][3..4]+=1 would. Result would be {{{2,4,6,20}, {8,10,12,22}, {14,16,18,24}}, {{3,6,9,30}, {12,15,19,34}, {21,24,28,37}}, {{24,25,26,33}, {27,28,30,35}, {30,31,33,36}}} c[2..3][2][3..4] is {{18,33},{29,34}}. You can add 1 to this, but then how to plug it back in? > If so, what should the result be? > >>> >>>[snipped remainder] >>> >>>Consider a sequence with at least two levels, and look at how you access it. >>>Each index specification (like [3]) just selects one element. Each slice >>>specification (like [1..3]) selects a *range* of elements. >>>Vertical slicing is not ambiguous if you consider that [3] and [3..3] are >>>unambiguously referring to different objects. Slices operate on matrices >>>(well, tensors in dimensions >2), and slices selectt individual elements as >>>probably expected. >>> >>>To come back to the original example above: >>> >>>-asdf[1..2][1] would print {97,97}: select element #1 in all subsequences of >>>asdf[1..2]. >>>-asdf[1..2][3..4] would print {{100,102},{100,102}}: slice [3..4] of all >>>elements of asdf[1..2]. >>>-asdf[1][1..2] would print {97,115}, as usual. > > Yes, that's fine. > >>> >>>Could you elaborate an example where this extended slicing, compatible with >>>the current EU syntax, could lead to two different interpretations? > > Someone once posted that a[x..y][z] would just return a[x+z-1], and > there is certainly some logical reasoning to that, I hope so, but I can't grasp it atm. > though of course it > would be utterly pointless to make a change which works that way. > > Maybe something like: > c = > {{{1,1}, {1,1}, {1,1}}, {{1,1}, {1,1}, {1,1}}, {{1,1}, {1,1}, {1,1}}} > > c[2..3][2..3]+={2,3} > > could give > > {{{1,1}, {1,1}, {1,1}}, {{1,1}, {3,3}, {4,4}}, {{1,1}, {3,3}, {4,4}}} > > or > > {{{1,1}, {1,1}, {1,1}}, {{1,1}, {3,3}, {3,3}}, {{1,1}, {4,4}, {4,4}}} > > or > > {{{1,1}, {1,1}, {1,1}}, {{1,1}, {3,4}, {3,4}}, {{1,1}, {3,4}, {3,4}}} > > To be honest I have no idea which would be correct. > I'd say the second one. You get the third one by c[2..3][2..3]+={{2,3}}, and the first one by c[2..3][2..3]+={{2},{3}}. > Regards, > Pete Regards CChris Fire at will...