Re: Is subscripting a slice useful
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Oct 12, 2004
- 582 views
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. > >> 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. > >> 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}? 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}}} ? Also, do you believe that eg c[2..3][2][3..4]+=1 should be supported? 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, 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. Regards, Pete