June 01, 2010
On Tue, Jun 1, 2010 at 22:54, Philippe Sigaud <philippe.sigaud@gmail.com>wrote:

> I also found the (simple?) problem to enumerate a range of ranges to be
> more interesting than I thought.
> Given a range of ranges ... of ranges, of whatever rank, recursively
> enumerate it:
>
> [[a,b,c],[d,e,f],[g,h,i]]
>
> produce:
>
> (a,0,0),(b,0,1), (c,0,2),(d,1,0), ...
>
> the coordinates of each element, if you will. I have a working version now, but it sure taught me that my vision of recursion was flawed.
>
>
Ow, I meant, while conserving the original topology, not as a flat range:

[[(a,0,0),(b,0,1),(c,0,2)],
 [(d,1,0), (e,1,1),(f,1,2)],
 [(g,2,0), (h,2,1),(i,2,2)]]

Lazily, of course.
I wanted the to conserve the rank because

1- that was the goal of the module: map, produce, etc range of ranges
2- it allowed me to iterate to a 'line' and then descend into this
particular line.
3- the original idea was to generate an infinite n-dim grid of coordinates

Philippe


June 01, 2010
On Tue, 01 Jun 2010 17:12:29 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> On 06/01/2010 04:06 PM, Steven Schveighoffer wrote:
>> On Tue, 01 Jun 2010 13:54:01 -0400, Andrei Alexandrescu
>> <SeeWebsiteForEmail@erdani.org> wrote:
>>
>>> The output of the program is:
>>>
>>> 0 Tuple!(uint,uint)(0, 0)
>>> 1 Tuple!(uint,uint)(0, 1)
>>> 2 Tuple!(uint,uint)(1, 1)
>>> 3 Tuple!(uint,uint)(1, 0)
>>> 4 Tuple!(uint,uint)(0, 2)
>>> 5 Tuple!(uint,uint)(1, 2)
>>> 6 Tuple!(uint,uint)(2, 2)
>>> 7 Tuple!(uint,uint)(2, 0)
>>> 8 Tuple!(uint,uint)(2, 1)
>>> 9 Tuple!(uint,uint)(0, 3)
>>> 10 Tuple!(uint,uint)(1, 3)
>>> 11 Tuple!(uint,uint)(2, 3)
>>> 12 Tuple!(uint,uint)(0, 4)
>>> 13 Tuple!(uint,uint)(1, 4)
>>> 14 Tuple!(uint,uint)(2, 4)
>>
>> It looks like you're missing some iterations there.
>>
>> -Steve
>
> There should be 5 * 3 = 15 iterations.

Oh, I didn't realize the input was not two infinite ranges.  I was looking at this as the first 15 lines from the output of 2 infinite ranges.  I expected to see (3, 0), (3, 1), (3, 2), and (3, 3).

My bad, I guess I should have read the code.

-Steve
June 01, 2010
On Tue, Jun 1, 2010 at 23:12, Andrei Alexandrescu < SeeWebsiteForEmail@erdani.org> wrote:

> On 06/01/2010 04:06 PM, Steven Schveighoffer wrote:
>
>> It looks like you're missing some iterations there.
>>
>> -Steve
>>
>
> There should be 5 * 3 = 15 iterations.
>
> Andrei
>

The example is:

 auto c = xproduct(iota(3), iota(5));

so the first index only goes from 0 to 2.


Philippe


June 01, 2010
On 06/01/2010 04:20 PM, Steven Schveighoffer wrote:
> On Tue, 01 Jun 2010 17:12:29 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org> wrote:
>
>> On 06/01/2010 04:06 PM, Steven Schveighoffer wrote:
>>> On Tue, 01 Jun 2010 13:54:01 -0400, Andrei Alexandrescu
>>> <SeeWebsiteForEmail@erdani.org> wrote:
>>>
>>>> The output of the program is:
>>>>
>>>> 0 Tuple!(uint,uint)(0, 0)
>>>> 1 Tuple!(uint,uint)(0, 1)
>>>> 2 Tuple!(uint,uint)(1, 1)
>>>> 3 Tuple!(uint,uint)(1, 0)
>>>> 4 Tuple!(uint,uint)(0, 2)
>>>> 5 Tuple!(uint,uint)(1, 2)
>>>> 6 Tuple!(uint,uint)(2, 2)
>>>> 7 Tuple!(uint,uint)(2, 0)
>>>> 8 Tuple!(uint,uint)(2, 1)
>>>> 9 Tuple!(uint,uint)(0, 3)
>>>> 10 Tuple!(uint,uint)(1, 3)
>>>> 11 Tuple!(uint,uint)(2, 3)
>>>> 12 Tuple!(uint,uint)(0, 4)
>>>> 13 Tuple!(uint,uint)(1, 4)
>>>> 14 Tuple!(uint,uint)(2, 4)
>>>
>>> It looks like you're missing some iterations there.
>>>
>>> -Steve
>>
>> There should be 5 * 3 = 15 iterations.
>
> Oh, I didn't realize the input was not two infinite ranges. I was
> looking at this as the first 15 lines from the output of 2 infinite
> ranges. I expected to see (3, 0), (3, 1), (3, 2), and (3, 3).
>
> My bad, I guess I should have read the code.
>
> -Steve

Funniest thing is the infinite ranges code was _much_ easier to get right. I got it rolling in a few minutes. It was the limit conditions for the finite ranges that killed me.

Andrei
June 01, 2010
On 06/01/2010 04:20 PM, Philippe Sigaud wrote:
> On Tue, Jun 1, 2010 at 23:12, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@erdani.org>>
> wrote:
>
>     On 06/01/2010 04:06 PM, Steven Schveighoffer wrote:
>
>         It looks like you're missing some iterations there.
>
>         -Steve
>
>
>     There should be 5 * 3 = 15 iterations.
>
>     Andrei
>
>
> The example is:
>
>   auto c = xproduct(iota(3), iota(5));
>
> so the first index only goes from 0 to 2.
>
>
> Philippe
>

And by the way, I added the feature that will ease bearophile's coding by one order of magnitude: iota with one argument.

Andrei
June 01, 2010
Andrei Alexandrescu:
> And by the way, I added the feature that will ease bearophile's coding by one order of magnitude: iota with one argument.

Thank you. There's a long way to go still :o)

Bye,
bearophile
June 02, 2010
On Tue, Jun 1, 2010 at 23:45, bearophile <bearophileHUGS@lycos.com> wrote:

> Andrei Alexandrescu:
> > And by the way, I added the feature that will ease bearophile's coding by one order of magnitude: iota with one argument.
>
> Thank you. There's a long way to go still :o)
>
> Bye,
> bearophile
>

What, do you also need the no-arg version of iota?

:-p


June 02, 2010
Philippe Sigaud:
> What, do you also need the no-arg version of iota?
> 
> :-p

I'd like a generator (range) similar to the Python itertools.count, that yields numbers starting from the given number (defaulting to zero) and just goes on and on. You can use it in many situations:
http://docs.python.org/library/itertools.html#itertools.count

Bye,
bearophile
June 02, 2010
On Wed, Jun 2, 2010 at 19:57, bearophile <bearophileHUGS@lycos.com> wrote:

> Philippe Sigaud:
> > What, do you also need the no-arg version of iota?
> >
> > :-p
>
> I'd like a generator (range) similar to the Python itertools.count, that yields numbers starting from the given number (defaulting to zero) and just goes on and on. You can use it in many situations: http://docs.python.org/library/itertools.html#itertools.count
>
>
Yes, it's handy. It's one of the first range I made, a year ago.


June 02, 2010
On 06/02/2010 02:29 PM, Philippe Sigaud wrote:
>
>
> On Wed, Jun 2, 2010 at 19:57, bearophile <bearophileHUGS@lycos.com
> <mailto:bearophileHUGS@lycos.com>> wrote:
>
>     Philippe Sigaud:
>      > What, do you also need the no-arg version of iota?
>      >
>      > :-p
>
>     I'd like a generator (range) similar to the Python itertools.count,
>     that yields numbers starting from the given number (defaulting to
>     zero) and just goes on and on. You can use it in many situations:
>     http://docs.python.org/library/itertools.html#itertools.count
>
>
> Yes, it's handy. It's one of the first range I made, a year ago.

iota(n, n.max) is close. Well, it's not infinite, but cycle(iota(n, n.max)) is. Probably a version using BigInt would be most sensible.

Andrei