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 badges1 Answer
Reset to default 2Thanks 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
评论列表(0条)