Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

4.6.5 vsip_dvscatter_p - Scatter Elements to a Vector

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);
Description

This function scatters elements from an input integer vector a into specific positions of an output vector r, with the positions specified by the index vector b. The operation performs:

rbi= ai

for all i from 0 to n-1, where n is the length of the input and index vectors.

Parameters
Example

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);
Notes