void vsip_vscatter_i(const vsip_vview_i *a, const vsip_vview_i *r, const vsip_vview_vi *b); void vsip_vscatter_f(const vsip_vview_f *a, const vsip_vview_f *r, const vsip_vview_vi *b); void vsip_cvscatter_f(const vsip_cvview_f *a, const vsip_cvview_f *r, const vsip_vview_vi *b);
This function scatters elements from an input integer vector
into specific positions of an output vector
, with the positions
specified by the index vector
. The operation performs:

for all
from 0 to
, where
is the length of the input and index vectors.
const vsip_dvview_p* a: Input integer vector containing elements to scatter.
const vsip_dvview_p* r: Output integer vector that will receive the scattered elements.
const vsip_vview_vi* b: Index vector containing the positions in
where elements from
should be placed.
vsip_vview_i *data, *result; vsip_vview_vi *indices; vsip_length n = 10; // Number of elements to scatter vsip_length result_size = 100; // Size of output vector // Create vectors data = vsip_vcreate_i(n, VSIP_MEM_NONE); result = vsip_vcreate_i(result_size, VSIP_MEM_NONE); indices = vsip_vcreate_vi(n, VSIP_MEM_NONE); // Initialize data vector with values to scatter for (vsip_length i = 0; i < n; i++) { vsip_vput_i(data, i, i * i); // Example: square numbers } // Initialize result vector (e.g., with zeros) vsip_vfill_i(result, 0); // Set up indices where to scatter elements (e.g., every 10th position) for (vsip_length i = 0; i < n; i++) { vsip_vput_vi(indices, i, i * 10); } // Scatter elements to result vector vsip_vscatter_i(data, result, indices); // The result vector now has non-zero values at positions: // 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 // containing the values from the data vector // Print some results printf("Scattered elements at positions:\n"); for (vsip_length i = 0; i < n; i++) { vsip_length pos = vsip_vget_vi(indices, i); printf("Position %ld: %d\n", pos, vsip_vget_i(result, pos)); } // Clean up vsip_valldestroy_i(data); vsip_valldestroy_i(result); vsip_valldestroy_vi(indices);
The index vector
must contain valid indices for the output vector
(i.e.,
).
The input vector
and index vector
must have the same length.