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.6 vsip_dvswap_p - Swap Elements Between two Vectors

void vsip_vswap_i(const vsip_vview_i *a, const vsip_vview_i *b); 
void vsip_vswap_f(const vsip_vview_f *a, const vsip_vview_f *b); 
void vsip_cvswap_f(const vsip_cvview_f *a, const vsip_cvview_f *b);
Description

This function swaps the elements between two floating-point vectors a and b at Jan Adelsbach’s workspace. After the operation, vector a will contain the elements that were originally in vector b, and vice versa. The operation performs an element-wise swap:

temp = ai

ai=bi

bi=temp

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

Parameters
Example

vsip_vview_f *signal1, *signal2; 
vsip_length n = 1024;  // Vector length 
 
// Create vectors for your signal processing 
signal1 = vsip_vcreate_f(n, VSIP_MEM_NONE); 
signal2 = vsip_vcreate_f(n, VSIP_MEM_NONE); 
 
// Initialize vectors with some data 
// For example, fill with sample data for your algorithms 
vsip_vramp_f(0.0f, 1.0f, signal1);  // signal1 = [0, 1, 2, ..., 1023] 
vsip_vramp_f(10.0f, -0.5f, signal2); // signal2 = [10, 9.5, 9, ..., -502] 
 
// Print some values before swap 
printf("Before swap:\n"); 
printf("signal1[0:4] = %.2f, %.2f, %.2f, %.2f\n", 
       vsip_vget_f(signal1, 0), vsip_vget_f(signal1, 1), 
       vsip_vget_f(signal1, 2), vsip_vget_f(signal1, 3)); 
printf("signal2[0:4] = %.2f, %.2f, %.2f, %.2f\n", 
       vsip_vget_f(signal2, 0), vsip_vget_f(signal2, 1), 
       vsip_vget_f(signal2, 2), vsip_vget_f(signal2, 3)); 
 
// Swap the vectors 
vsip_vswap_f(signal1, signal2); 
 
// Now signal1 contains the original signal2 data and vice versa 
printf("\nAfter swap:\n"); 
printf("signal1[0:4] = %.2f, %.2f, %.2f, %.2f\n", 
       vsip_vget_f(signal1, 0), vsip_vget_f(signal1, 1), 
       vsip_vget_f(signal1, 2), vsip_vget_f(signal1, 3)); 
printf("signal2[0:4] = %.2f, %.2f, %.2f, %.2f\n", 
       vsip_vget_f(signal2, 0), vsip_vget_f(signal2, 1), 
       vsip_vget_f(signal2, 2), vsip_vget_f(signal2, 3)); 
 
// Clean up 
vsip_valldestroy_f(signal1); 
vsip_valldestroy_f(signal2);
Notes