In Chapel, I can count the number of array elements equal to a given value as
var a = [1,2,5,5,5];
writeln( a.count( 5 ) ); // this gives 3
but a similar method does not seem to work for counting the number of true elements:
writeln( count( a > 1 ) );
writeln( ( a > 1 ).count( true ) );
In this case, do I need to write an explicit for-loop, or is there any other function (or method) for this purpose...?
Update
After some more experiment, it seems that if I save the result of a == 5
to a new array
var mask = ( a == 5 );
then it works as expected
writeln( mask.count( true ) ); // gives 3
So, a == 5
may be representing something different from an array object and so does not provide .count()
directly?