The following explains a common train of thought concerning writing only a select portion of an array, as in the C code below.
The Ct Scatter function requires a default value, which does not make it makes it useful in this type of code. In the Ct code below, the Scatter forces all values not indexed to the default value, which means it can't be used to update only select elements of the array.
That begs the question, is there some other Ct construct that can do an update of only select elements of an array? The answer is both Yes and No. Read on.

Ct has a version of 'scatter' that takes an existing array and “scatters into it” (note that it doesn't actually modify the existing array, but rather returns a new array with the values coming from the existing or scattered array).
This seems to be a viable option...only if your array is small. What if your array is *very* large? Copying will not perform well in that case. It would stress virtual and physical memory limits.
Another alternative: Unpack, but it also puts in default values for unused indexes.
Semantically, the scatter copies. But if you immediately get rid of the original (or even stop using it), it should just do it in-place.
One option is that the C code should be:
data[*idx++] += delta;
Unless you change the index array into a bool array in the C++ code, only those elements at the positions specified by index are true.
Then you do:
dstVec = select(needChange, srcVec + delta, srcVec);
This workaround is confirmed to work and be a great option for larger arrays.
The Ct Scatter function requires a default value, which does not make it makes it useful in this type of code. In the Ct code below, the Scatter forces all values not indexed to the default value, which means it can't be used to update only select elements of the array.
That begs the question, is there some other Ct construct that can do an update of only select elements of an array? The answer is both Yes and No. Read on.
Ct has a version of 'scatter' that takes an existing array and “scatters into it” (note that it doesn't actually modify the existing array, but rather returns a new array with the values coming from the existing or scattered array).
This seems to be a viable option...only if your array is small. What if your array is *very* large? Copying will not perform well in that case. It would stress virtual and physical memory limits.
Another alternative: Unpack, but it also puts in default values for unused indexes.
Semantically, the scatter copies. But if you immediately get rid of the original (or even stop using it), it should just do it in-place.
One option is that the C code should be:
data[*idx++] += delta;
Unless you change the index array into a bool array in the C++ code, only those elements at the positions specified by index are true.
Then you do:
dstVec = select(needChange, srcVec + delta, srcVec);
This workaround is confirmed to work and be a great option for larger arrays.
