Skip to content

Instantly share code, notes, and snippets.

@chriskiefer
Created August 26, 2011 08:15
Show Gist options
  • Save chriskiefer/1172964 to your computer and use it in GitHub Desktop.
Save chriskiefer/1172964 to your computer and use it in GitHub Desktop.
Stl Vector Contiguity Test
#include <iostream>
#include <Accelerate/Accelerate.h>
using namespace std;
#include <vector>
int main (int argc, char * const argv[]) {
// insert code here...
cout << "Vector Test\n";
int datasize = 100000;
float x[datasize];
vector<float> y;
for(int i=0; i < datasize; i++) {
float r = (float) rand() / (float)RAND_MAX;
x[i] = r;
y.push_back(r);
}
int contiguous = memcmp(x, &(y[0]), sizeof(float) * datasize);
if (contiguous == 0) {
cout << "Test 1: Passed";
}
else{
cout << "Test 1: Failed";
}
cout << endl;
//do some vector processing
vDSP_vrvrs(x, 1, datasize);
vDSP_vrvrs(&(y[0]), 1, datasize);
vDSP_vssq(x, 1, x, 1, datasize);
vDSP_vssq(&(y[0]), 1, &(y[0]), 1, datasize);
contiguous = memcmp(x, &(y[0]), sizeof(float) * datasize);
if (contiguous == 0) {
cout << "Test 2: Passed";
}
else{
cout << "Test 2: Failed";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment