#include <stdio.h>
{
for (
int ii = 0; ii < (int)a.
dims(1); ii++) {
for (
int jj = 0; jj < (int)b.
dims(1); jj++) {
for (
int kk = 0; kk < (int)a.
dims(0); kk++) {
dist_mat(ii, jj) +=
abs(a(kk, ii) - b(kk, jj));
}
}
}
return dist_mat;
}
{
for (
int ii = 0; ii < (int)a.
dims(1); ii++) {
for (
int jj = 0; jj < (int)b.
dims(1); jj++) {
dist_mat(ii, jj) =
sum(
abs(avec - bvec));
}
}
return dist_mat;
}
{
for (
int jj = 0; jj < (int)b.
dims(1); jj++) {
dist_mat(ii, jj) =
sum(
abs(avec - bvec));
}
}
return dist_mat;
}
{
for (
int ii = 0; ii < (int)a.
dims(1); ii++) {
dist_mat(ii, jj) =
sum(
abs(avec - bvec));
}
}
return dist_mat;
}
{
int alen = (int)a.
dims(1);
int blen = (int)b.
dims(1);
for (int jj = 0; jj < blen; jj++) {
dist_mat(
span, jj) = sad.
T();
}
return dist_mat;
}
{
int feat_len = (int)a.
dims(0);
int alen = (int)a.
dims(1);
int blen = (int)b.
dims(1);
return dist_mat;
}
static void bench_naive()
{
dist_naive(A, B);
}
static void bench_vec()
{
dist_vec(A, B);
}
static void bench_gfor1()
{
dist_gfor1(A, B);
}
static void bench_gfor2()
{
dist_gfor2(A, B);
}
static void bench_tile1()
{
dist_tile1(A, B);
}
static void bench_tile2()
{
dist_tile2(A, B);
}
int main(int argc, char **argv)
{
try {
array d1 = dist_naive(A, B);
array d2 = dist_vec (A, B);
array d3 = dist_gfor1(A, B);
array d4 = dist_gfor2(A, B);
array d5 = dist_tile1(A, B);
array d6 = dist_tile2(A, B);
printf(
"Max. Error for dist_vec : %f\n", max<float>(
abs(d1 - d2)));
printf(
"Max. Error for dist_gfor1: %f\n", max<float>(
abs(d1 - d3)));
printf(
"Max. Error for dist_gfor2: %f\n", max<float>(
abs(d1 - d4)));
printf(
"Max. Error for dist_tile1: %f\n", max<float>(
abs(d1 - d5)));
printf(
"Max. Error for dist_tile2: %f\n", max<float>(
abs(d1 - d6)));
printf("\n");
printf(
"Time for dist_naive: %2.2fms\n", 1000 *
timeit(bench_naive));
printf(
"Time for dist_vec : %2.2fms\n", 1000 *
timeit(bench_vec ));
printf(
"Time for dist_gfor1: %2.2fms\n", 1000 *
timeit(bench_gfor1));
printf(
"Time for dist_gfor2: %2.2fms\n", 1000 *
timeit(bench_gfor2));
printf(
"Time for dist_tile1: %2.2fms\n", 1000 *
timeit(bench_tile1));
printf(
"Time for dist_tile2: %2.2fms\n", 1000 *
timeit(bench_tile2));
fprintf(stderr,
"%s\n", ex.
what());
throw;
}
return 0;
}