33#include <math.h>
44#include <assert.h>
55
6+ #include "test_utils.h"
7+
68#define __builtin_autodiff __enzyme_autodiff
79double __enzyme_autodiff (void * , ...);
8- //float man_max(float* a, float* b) {
9- // if (*a > *b) {
10- // return *a;
11- // } else {
12- // return *b;
13- // }
14- //}
15-
1610
1711// size of array
1812float * unsorted_array_init (int N ) {
@@ -37,36 +31,19 @@ void insertion_sort_inner(float* array, int i) {
3731// sums the first half of a sorted array.
3832void insertsort_sum (float * __restrict array , int N , float * __restrict ret ) {
3933 float sum = 0 ;
40- //qsort(array, N, sizeof(float), cmp);
4134
4235 for (int i = 1 ; i < N ; i ++ ) {
4336 insertion_sort_inner (array , i );
4437 }
4538
46-
4739 for (int i = 0 ; i < N /2 ; i ++ ) {
4840 //printf("Val: %f\n", array[i]);
4941 sum += array [i ];
5042 }
5143 * ret = sum ;
5244}
5345
54-
55-
56-
5746int main (int argc , char * * argv ) {
58-
59-
60-
61- float a = 2.0 ;
62- float b = 3.0 ;
63-
64-
65-
66- float da = 0 ;//(float*) malloc(sizeof(float));
67- float db = 0 ;//(float*) malloc(sizeof(float));
68-
69-
7047 float ret = 0 ;
7148 float dret = 1.0 ;
7249
@@ -85,15 +62,11 @@ int main(int argc, char** argv) {
8562 for (int i = 0 ; i < N ; i ++ ) {
8663 printf ("Diffe for index %d is %f\n" , i , d_array [i ]);
8764 if (i %2 == 0 ) {
88- assert (d_array [i ] == 0.0 );
65+ assert (approx_fp_equality_float ( d_array [i ], 0.0 , 1e-10 ) );
8966 } else {
90- assert (d_array [i ] == 1.0 );
67+ assert (approx_fp_equality_float ( d_array [i ], 1.0 , 1e-10 ) );
9168 }
9269 }
9370
94- //assert(da == 100*1.0f);
95- //assert(db == 100*1.0f);
96-
97- //printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db);
9871 return 0 ;
9972}
0 commit comments