I noticed that this works in Chapel. I can turn an integer array into a set by casting it to domain(int)
var x: [1..4] int = (4,5,6,6);
var d = x : domain(int);
writeln(x);
> {4,6,5}
This is extremely helpful, but I'm wondering if there are instances when it will fail, like in a distributed context.
Another feature I'm using is the de-duping of a set when cast to a domain.
var y = {11,13,15,15};
writeln(y);
> {15,11, 13}
Is there a more efficient way to do this or is this a preferred method? I was not able to time it since I don't have access to a large enough cluster A.T.M.
I'm wondering if there are instances when it will fail, like in a distributed context.
It shouldn't. Well-behaved Chapel programs like this should be functionally equivalent in shared- and distributed-memory execution contexts. Of course, performance is likely to differ (for better or worse, depending on how your data and computation are distributed).
Is there a more efficient way to do this or is this a preferred method?
I doubt that Chapel defines a preferred method, but this should be O(n) (linear in the number of elements), so I think it should be reasonable, asymptotically speaking. I don't have any direct experience trying to optimize this idiom in Chapel or other languages, so am not aware of a preferred method.