# Tuples of ranges

**URL:** <https://chapel.discourse.group/t/tuples-of-ranges/18201>\
**Category:** Users\
**Created:** [December 15, 2022, 10:11am UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201 "2022-12-15T10:11:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [December 15, 2022, 10:11am UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/1 "2022-12-15T10:11:36Z")

</div>

Why can I have a tuple of ranges which have the same stride but not, as below, a tuple of ranges which have different strides.

```chapel
// computea matrix's cross diagonal waves, the ranges
// which go from the bottom left to the top right 

proc crossDiagonalWave(rMax : int, cMax : int)
{
	param rmin = 2, cmin = 2;
	const rmax = rMax - 1, cmax = cMax -1;
	var isiz = 1, siz : [1..rmax + cmax-3] (range, range);

	// process a cross (semi-)diagonal - bottom left to upper right

	proc wave(_r : int, _c : int)
	{
		var r = _r, c = _c;

		while c >= cmin && r <= rmax do
		{
			r += 1;
			c -= 1;
		}
		return (_r .. r - 1, c + 1 .. _c by -1);
	}

	assert(rMax > rmin && cMax > cmin);

	siz[isiz] = (rmin..rmin, cmin..cmin by -1);

	for c in cmin + 1 .. cmax do // process above the cross diagonal
	{
		isiz += 1; siz[isiz] = wave(rmin, c);
	}
	for r in rmin + 1 .. rmax do // process below the cross diagonal 
	{
		isiz += 1; siz[isiz] = wave(r, cmax);
	}
	return siz;
}

```

What have I done wrong?

---

<div class="post-metadata">

**Author:** ![vass](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/vass/32/692_2.png) [@vass](https://chapel.discourse.group/u/vass)\
**Post date:** [December 15, 2022, 10:13pm UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/2 "2022-12-15T22:13:07Z")

</div>

Hello Damian,

Maybe the issue is not in the tuple? The following compiles and runs for me:

```Chapel
proc wave(_r : int, _c : int)
	{
		var r = _r, c = _c;

		while c >= 10 && r <= 0 do
		{
			r += 1;
			c -= 1;
		}
		return (_r .. r - 1, c + 1 .. _c by -1);
	}

writeln(wave(1,1));

```

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [December 15, 2022, 11:24pm UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/3 "2022-12-15T23:24:55Z")

</div>

The clause in your while loop would be a No-Op. But, even when I use it, I get:

```Chapel
front.chpl:4: In function 'periDiagonalWave':
front.chpl:26: error: type mismatch in assignment of ranges with different stridable parameters

```

Here is the complete code which fails. I am using a special version of 1.28.0 from Brad. The special mods have nothing to do with ranges. They just allow me to see the underlying hexadecimal unsigned integral value inside a floating point **param** eter. So, it should look like standard 1.28.0 compiler for our purposes here. Maybe I should try it with 1.30.0 next week.

```chapel
// compute matrix's cross diagonal waves, the ranges
// which go from the bottom left to the top right 

proc periDiagonalWave(rMax : int, cMax : int)
{
        param rmin = 2, cmin = 2;
        const rmax = rMax - 1, cmax = cMax -1;
        var isiz = 1, siz : [1..rmax + cmax-3] (range, range);

        // process a cross (semi-)diagonal - bottom left to upper right

        proc wave(_r : int, _c : int)
        {
                var r = _r, c = _c;

                while c >= cmin && r <= rmax do
                {
                        r += 1;
                        c -= 1;
                }
                return (_r .. r - 1, c + 1 .. _c by -1);
        }

        assert(rMax > rmin && cMax > cmin);

        siz[isiz] = (rmin..rmin, cmin..cmin by -1);

        for c in cmin + 1 .. cmax do // process above the cross diagonal
        {
                isiz += 1; siz[isiz] = wave(rmin, c);
        }
        for r in rmin + 1 .. rmax do // process below the cross diagonal 
        {
                isiz += 1; siz[isiz] = wave(r, cmax);
        }
        return siz;
}

config const c = 10;
config const r = 10;

proc main
{
        writeln("TRY ", r, ",", c);

        const rcpairs = periDiagonalWave(r, c);
        const size = c + r - 5;

        for (rows, columns) in rcpairs do
        {
                write(' next ');
                for (r, c) in zip(rows, columns by -1) do
                {
                        write(' (', r, ',', c, ')');
                }
                writeln('|');
        }
        writeln('Size ', rcpairs.domain);
        return 0;
}

```

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [December 16, 2022, 5:41am UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/4 "2022-12-16T05:41:56Z")

</div>

The fix is in the type definition

```Chapel
 var isiz = 1, siz : [1..rmax + cmax-3] (range, range(stridable=true));

```

Once I do this, I can then use a stridable range as the second component of the tuple.

Sorry. I will switch my brain on next time. Silly me.

---

<div class="post-metadata">

**Author:** ![vass](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/vass/32/692_2.png) [@vass](https://chapel.discourse.group/u/vass)\
**Post date:** [December 16, 2022, 7:43am UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/5 "2022-12-16T07:43:46Z")

</div>

Me too. I missed the scrollbar in your original code.

Glad you fixed the issue. Also we are intending to have the compiler issue a hint in cases like this.

Vass

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [December 16, 2022, 3:05pm UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/6 "2022-12-16T15:05:00Z")

</div>

Access to Discourse has been problematic for last few hours

- login (via Github) times out

- display of replies to a topic times out

This is from Australia. No idea what it is like elsewhere.

I am curious if this makes it as I am replying directly by email.

- Damian

---

<div class="post-metadata">

**Author:** ![vass](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/vass/32/692_2.png) [@vass](https://chapel.discourse.group/u/vass)\
**Post date:** [December 17, 2022, 4:40am UTC](https://chapel.discourse.group/t/tuples-of-ranges/18201/7 "2022-12-17T04:40:07Z")

</div>

Same here. See:

> **[Discourse Status Page](https://status.discourse.org/)**
>
> Current system status. View active incidents or upcoming maintenances. Subscribe to receive status notifications.
