-
Notifications
You must be signed in to change notification settings - Fork 71
scatter
myArray.scatter(indices, defaultValue, conflictFunction, length)
##Arguments
indices array of indices in the resulting array
defaultValue optional argument indicating the value of elements not set by scatter
*When not present, the default value is undefined
conflictFunction optional function to resolve conflicts, details below.
length optional argument indicating the length of the resulting array. If absent, the length is the same as the length of the indices argument.
##Returns
A freshly minted ParallelArray A where each element A[i] is defined as
-
A[indices[i]] = this[i], when indices[i] is unique
-
A[indices[i]] = conflictFunction(A[indices[i]]), when A[indices[i]] has a previously assigned value. The value of
thisduring the evaluation ofconflictFunctionis the value of the source array at the current positioni. -
defaultValue, when
iis not present inindicesarray
##Example: an identity function
pa.scatter(indices); where indices is a ParallelArray where element === index
##Conflict Function
A conflict occurs when multiple elements are scattered to the same location. It results in a call to conflictFunction, which is an optional third argument to scatter. If conflictFunction is undefined, conflicts are non-deterministically resolved.
function (other)
this is the value at the current index in the input array, i.e., the value that is currently being scattered.
other is the value that has already been written to the target index of the current scatter operation.
It is the programmer’s responsibility to provide a conflict function that is associative and commutative, since there is no guarantee in what order the conflicts will be resolved. Otherwise the result will be non-deterministic.
###Returns
Value to place in result[indices[index]]
###Example: Resolve conflict with larger number
chooseMax(other){
return (this>other)?this:other;
}