#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, char **) {
    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;
}
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
array T() const
Get the transposed the array.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
seq is used to create sequences for indexing af::array
array abs(const array &in)
C++ Interface to calculate the absolute value.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
array moddims(const array &in, const dim4 &dims)
C++ Interface to modify the dimensions of an input array to a specified shape.
array tile(const array &in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)
C++ Interface to generate a tiled array.
array randu(const dim4 &dims, const dtype ty, randomEngine &r)
C++ Interface to create an array of random numbers uniformly distributed.
array max(const array &in, const int dim=-1)
C++ Interface to return the maximum along a given dimension.
array sum(const array &in, const int dim=-1)
C++ Interface to sum array elements over a given dimension.
double timeit(void(*fn)())
seq span
A special value representing the entire axis of an af::array.