In Chapel, is there a way to combine domains? - Stack Overflow

For example, could I combine the domain {1..2, 1..5} and {1..6} to form {1..2, 1..5, 1..6}?I have look

For example, could I combine the domain {1..2, 1..5} and {1..6} to form {1..2, 1..5, 1..6}?

I have looked at the spec for Domains, and can't find anything that would allow me to do this.

For example, could I combine the domain {1..2, 1..5} and {1..6} to form {1..2, 1..5, 1..6}?

I have looked at the spec for Domains, and can't find anything that would allow me to do this.

Share Improve this question asked Mar 3 at 8:21 Boris KaptsanovBoris Kaptsanov 626 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Thanks for the question, Boris. This combining of domains can be done by using the .dim() and/or .dims() queries on domains along with standard Chapel features for domain literals and tuples.

A simple—but not terribly satisfying—way to do it, if you know the ranks of your domains a priori, would be to create a new domain literal by querying the specific dimensions of the original two domains using the .dim() query, which takes a 0-based dimension number and returns the range for that dimension. For example:

const D1 = {1..2, 1..5},
      D2 = {1..6};

const D3 = {D1.dim(0), D1.dim(1), D2.dim(0)};

writeln(D3);  // prints {1..2, 1..5, 1..6}

A more general approach that doesn't require knowing the dimensions of the two domains is to use the .dims() query, which returns a tuple of the ranges defining the domain. This can be combined with Chapel's (…myTuple) expression, which turns a tuple into a comma-separated list of its components. For example, the following expression queries the tuples of ranges for both domains, expands them into their comma-separated components (the per-dim ranges), and then separates the two lists by another comma:

const D4 = {(...D1.dims()), (...D2.dims())};
writeln(D4);  // prints {1..2, 1..5, 1..6}

Here is a link to an ATO example that contains the above patterns, as well as some variations using a utility routine to demonstrate creating 2D or 4D domains by combining D1 and itself or D2 and itself.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745103990a4611448.html

相关推荐

  • In Chapel, is there a way to combine domains? - Stack Overflow

    For example, could I combine the domain {1..2, 1..5} and {1..6} to form {1..2, 1..5, 1..6}?I have look

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信