X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=foosrank.cpp;h=03edcb5b4c1047572a644aa4122af70e288c32f7;hb=fa47b7b1367721a2e83f21d1bfcf943116e3d7d1;hp=b9208fd86b230e1ec950447f66f508d99ea00351;hpb=7cb34ae54799149c3f99c9f6f48485e9d114db62;p=foosball diff --git a/foosrank.cpp b/foosrank.cpp index b9208fd..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) {