Reputation: 3136
The expand command in Chapel returns a new domain. I would like to increase a domain by one kinda like
var d: domain(1) = {1..5};
writeln(d);
--{1..5}
expand(d)(1);
writeln(d);
--{1..6};
Upvotes: 2
Views: 95
Reputation: 451
As of Chapel 1.15 there is no in-place option for the expand
method on domains. You would need to assign the result of expand
to the desired domain:
var eDom = {1..5};
eDom = eDom.expand(1);
writeln(eDom); // {0..6}
It doesn't sound like expand
is what you want though, because expand
will grow the domain in both directions in each dimension. To add one index to a rectangular domain, you can assign a domain literal to your domain:
var rDom = {1..5};
const hi = rDom.last + 1;
rDom = {rDom.first..hi};
writeln(rDom); // {1..6}
For irregular domains you can use the add
method:
var aDom = {1, 3, 5, 7}; // an associative domain
aDom.add(9);
writeln(aDom.sorted()); // 1 3 5 7 9
Note that you cannot use the add
method on rectangular domains. This is defined in section 19.8.6 in version 0.983 of the Chapel language specification.
Upvotes: 3
Reputation: 1
domain
expansion:some worked as documented, some not:
var d: domain(1) = {1..5};
writeln( d ); // SET {1..5}
// {1..5}
var e: domain(1) = d.expand(1);
writeln( e ); // OK, DOMAIN d == {1..5} EXTENDED ON BOTH ENDS INTO {0..6}
// {0..6}
var AonD: [d] int;
AonD.push_back(1);
writeln( AonD.domain ); // OK, DOMAIN EXTENDED INDIRECTLY ON DESIRED END INTO {1..6}
// {1..6}
// var f: domain(1) = {1..5}; // NEW {1..5} - A NON-SHARED, NON-USED ( NON-MAPPED ) DOMAIN
// f.add(6); // FAILS v/s A PROMISE IN: http://chapel.cray.com/docs/master/builtins/internal/ChapelArray.html#ChapelArray.add
// f += 6; // FAILS
// writeln( f );
Upvotes: 1