X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=foosrank.cpp;h=03edcb5b4c1047572a644aa4122af70e288c32f7;hb=HEAD;hp=4d09eb5d4a992e26e618a00f1bea1ade54cc07c8;hpb=77c87920bd53f36c10512c824e1c39768182ba43;p=foosball diff --git a/foosrank.cpp b/foosrank.cpp index 4d09eb5..03edcb5 100644 --- a/foosrank.cpp +++ b/foosrank.cpp @@ -106,27 +106,31 @@ static void compute_opponent_rating_pdf(int k, int a, double mu2, double sigma2, int sz = (6000.0 - 0.0) / int_step_size; double h = (6000.0 - 0.0) / sz; - fftw_plan f1, f2, b; - complex *func1, *func2, *res; - - func1 = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); - func2 = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); - res = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); - f1 = fftw_plan_dft_1d(sz*2, - reinterpret_cast(func1), - reinterpret_cast(func1), - FFTW_FORWARD, - FFTW_MEASURE); - f2 = fftw_plan_dft_1d(sz*2, - reinterpret_cast(func2), - reinterpret_cast(func2), - FFTW_FORWARD, - FFTW_MEASURE); - b = fftw_plan_dft_1d(sz*2, - reinterpret_cast(res), - reinterpret_cast(res), - FFTW_BACKWARD, - FFTW_MEASURE); + static bool inited = false; + static fftw_plan f1, f2, b; + static complex *func1, *func2, *res; + + if (!inited) { + func1 = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); + func2 = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); + res = reinterpret_cast *>(fftw_malloc(sz*2*sizeof(complex))); + f1 = fftw_plan_dft_1d(sz*2, + reinterpret_cast(func1), + reinterpret_cast(func1), + FFTW_FORWARD, + FFTW_MEASURE); + f2 = fftw_plan_dft_1d(sz*2, + reinterpret_cast(func2), + reinterpret_cast(func2), + FFTW_FORWARD, + FFTW_MEASURE); + b = fftw_plan_dft_1d(sz*2, + reinterpret_cast(res), + reinterpret_cast(res), + FFTW_BACKWARD, + FFTW_MEASURE); + inited = true; + } // start off by zero for (int i = 0; i < sz*2; ++i) { @@ -366,7 +370,7 @@ static void least_squares(const vector > &curve, double mu1 *sigma_result = sigma; } -static void compute_new_rating(double mu1, double sigma1, double mu2, double sigma2, int score1, int score2, double *mu, double *sigma, double *probability) +void compute_new_rating(double mu1, double sigma1, double mu2, double sigma2, int score1, int score2, double *mu, double *sigma, double *probability) { vector > curve;