Exemple #1
0
void check_distance(float distance, int test_id) {
    switch(test_id) {
        case 0: printf("Testing with self...%s\n", float_equals(distance,0)?"passed":"failed"); break;
        case 1: printf("Testing with translated image...%s\n", float_equals(distance,0)?"passed":"failed"); break;
        case 2: printf("Testing with rotated image...%s\n", float_equals(distance,0)?"passed":"failed"); break;
        case 3: printf("Testing with image flipped across x-axis...%s\n", float_equals(distance,0)?"passed":"failed"); break;
        case 4: printf("Testing with image flipped across y-axis...%s\n", float_equals(distance,0)?"passed":"failed"); break;
        default: printf("Unrecongized test"); return;
    }
}
Exemple #2
0
bool matrixFloatEquals(const Mat<T>& x, const Mat<T>& y) {
    if (x.numRows() != y.numRows() || x.numCols() != y.numCols())
        return false;
    
    for (size_t i = 0; i < x.numRows(); ++i)
        for (size_t j = 0; j < x.numCols(); ++j)
            if (!float_equals(x(i, j), y(i, j)))
                return false;
    return true;
}
/* Benchmarks a NxM image with a TxT template, where dimensions are
 * specified as (width)x(height).
 */
int benchmark_matrix(int N, int M, int T) {

    if (N < T || M < T)
        printf("Warning: T (%d) should be no larger than N (%d) or M (%d)\n", T, N, M);

    size_t image_matrix_size = sizeof(float) * N * M;
    size_t template_matrix_size = sizeof(float) * T * T;
    float *A = (float*) malloc(image_matrix_size);
    float *B = (float*) malloc(template_matrix_size);

    float average_distance = 5 * random_float();
    for (int i = 0; i < N * M; i++)
        A[i] = random_float() * 0.1 + average_distance * i / N / M;
    for (int i = 0; i < T * T; i++)
        B[i] = random_float() * 0.1;

    float distance_ref = oracle_calc_min_dist(A, N, M, B, T);
    float distance = calc_min_dist(A, N, M, B, T);

    printf("N=%d M=%d T=%d \t", N, M, T);
    if (!float_equals(distance, distance_ref)) {
        printf("Result does not match oracle (got = %.3f, expected = %.3f)!\n", distance, distance_ref);
        return 0;
    }

    double Gflop_s, seconds = -1.0;
    for (int n_iterations = 1; seconds < 0.25; n_iterations *= 2) {
        struct timeval start, end;
        gettimeofday(&start, NULL);
        for (int i = 0; i < n_iterations; i++)
            distance = calc_min_dist(A, N, M, B, T);
        gettimeofday(&end, NULL);
        seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);

        /** 8 total orientations, 3 operations (subtract, square, reduce-sum) */
        Gflop_s = 8.0 * 3 * T * T * (N - T + 1) * (M - T + 1) * 1e-9 * n_iterations / seconds;
    }
    printf("%.4f Gflop/s\n", Gflop_s);

    free(A);
    free(B);

    return 1;
}