Chapel: Copying Rolling Domains

I want to keep an array of domains. My code is like this:

var doms:[1..10] domain(1);
...
doms[i]={0..30 by 3}

      

I am getting the following error:

cannot assign from stridable domain to an unstridable domain without an an explicit cast

      

By using the cast dom[i]={0..30 by 3} : domain(1)

I am losing pitch information. How to copy domains without losing a step?

thank

+3


source to share


1 answer


Type rectangular domain, as in the example shown, actually has three parameters that define him rank

, idxType

and stridable

(for example in question indicates rank=1

). The stridable

default is false

, so a rebuildable domain cannot be assigned. To indicate that the domain should be smooth, you can declare the domain type with stridable=true

:

var doms: [1..10] domain(1, stridable=true);
...
doms[i] = {0..30 by 3};

      



As you've found, casting a strided domain to type domain(1)

silently discards a step, since a domain(1)

can only have a single step. If you would rather have an error instead of silently discarding the step, you can use safeCast

. A safeCast

will check that the original domain has a one step before dropping it and will throw an error if not:

doms[i] = {0..30 by 1}.safeCast(domain(1)); // This is allowed.
doms[i] = {0..30 by 3}.safeCast(domain(1)); // This is a runtime error.

      

+3


source







All Articles