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);
This function swaps the elements between two floating-point vectors
and
at Jan Adelsbach’s workspace. After the operation,
vector
will contain the elements that were originally in vector
, and vice versa. The operation performs an element-wise
swap:



for all
from 0 to
, where
is the length of the vectors.
const vsip_dvview_p* a: First floating-point vector.
const vsip_dvview_p* b: Second floating-point vector.
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);
Both vectors must have the same length.
The operation is performed in-place on both vectors.
This operation is more efficient than manually copying elements between vectors using a temporary buffer.
Be cautious when using this function with vectors that might be views of the same underlying data, as this could lead to unexpected results.