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.4 vsip_dvgather_p - Gather Elements from a Vector

void vsip_vgather_i(const vsip_vview_i *a, const vsip_vview_vi *b, const vsip_vview_i *r); 
void vsip_vgather_f(const vsip_vview_f *a, const vsip_vview_vi *b, const vsip_vview_f *r); 
void vsip_cvgather_f(const vsip_cvview_f *a, const vsip_vview_vi *b, const vsip_cvview_f *r);
Description

This function gathers elements from an input integer vector a according to the indices specified in vector b, and stores the results in output vector r. The operation performs:

ri= abi

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

Parameters
Example

vsip_vview_i *data, *result; 
vsip_vview_vi *indices; 
vsip_length n = 10;  // Number of elements to gather 
vsip_length data_size = 100;  // Size of input data vector 
 
// Create vectors 
data = vsip_vcreate_i(data_size, VSIP_MEM_NONE); 
result = vsip_vcreate_i(n, VSIP_MEM_NONE); 
indices = vsip_vcreate_vi(n, VSIP_MEM_NONE); 
 
// Initialize data vector with some values 
for (vsip_length i = 0; i < data_size; i++) { 
    vsip_vput_i(data, i, i * 10);  // Example data 
} 
 
// Set up indices to gather (e.g., every 10th element) 
for (vsip_length i = 0; i < n; i++) { 
    vsip_vput_vi(indices, i, i * 10); 
} 
 
// Gather elements from data vector 
vsip_vgather_i(data, indices, result); 
 
// The result vector now contains elements from data at positions: 
// 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 
 
// Print results 
printf("Gathered elements:\n"); 
for (vsip_length i = 0; i < n; i++) { 
    printf("%d ", vsip_vget_i(result, i)); 
} 
printf("\n"); 
 
// Clean up 
vsip_valldestroy_i(data); 
vsip_valldestroy_i(result); 
vsip_valldestroy_vi(indices);
Notes