#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <yepCore.h>
#include <yepMath.h>
#include <yepLibrary.h>
double compute_entropy_naive(const double *pPointer, size_t pLength) {
double entropy = 0.0;
for (; pLength != 0; pLength--) {
const double p = *pPointer++;
entropy -= p * log(p);
}
return entropy;
}
#define BLOCK_SIZE 1024
double compute_entropy_yeppp(const double *p, size_t length) {
for (index = 0; index < length; index += BLOCK_SIZE) {
blockLength = length - index;
if (blockLength > BLOCK_SIZE) {
blockLength = BLOCK_SIZE;
}
entropy -= dotProduct;
}
return entropy;
}
#define ARRAY_SIZE (1024*1024*16)
int main(int argc, char **argv) {
Yep64u startTimeNaive, startTimeYeppp, endTimeNaive, endTimeYeppp, frequency;
Yep64f entropyNaive, entropyYeppp;
for (i = 0; i < ARRAY_SIZE; i++) {
p[i] = ((double)(rand() + 1)) / ((double)(RAND_MAX) + 1.0);
}
entropyNaive = compute_entropy_naive(p, ARRAY_SIZE);
entropyYeppp = compute_entropy_yeppp(p, ARRAY_SIZE);
printf("Naive implementation:\n");
printf("\tEntropy = %lf\n", ((double)entropyNaive));
printf("\tTime = %lf\n", ((double)(endTimeNaive - startTimeNaive)) / ((double)(frequency)));
printf("Yeppp! implementation:\n");
printf("\tEntropy = %lf\n", ((double)entropyYeppp));
printf("\tTime = %lf\n", ((double)(endTimeYeppp - startTimeYeppp)) / ((double)(frequency)));
free(p);
return 0;
}