void m(char16_t c0, char32_t c1) { f_c (c0); /* { dg-warning "conversion from .char16_t. to .char. may change value" } */ fsc (c0); /* { dg-warning "change value" } */ fuc (c0); /* { dg-warning "change value" } */ f_s (c0); /* { dg-warning "change the sign" } */ fss (c0); /* { dg-warning "change the sign" } */ fus (c0); f_i (c0); fsi (c0); fui (c0); f_l (c0); fsl (c0); ful (c0); f_ll (c0); fsll (c0); full (c0); f_c (c1); /* { dg-warning "change value" } */ fsc (c1); /* { dg-warning "change value" } */ fuc (c1); /* { dg-warning "change value" } */ f_s (c1); /* { dg-warning "change value" } */ fss (c1); /* { dg-warning "change value" } */ fus (c1); /* { dg-warning "change value" } */ f_i (c1); /* { dg-warning "change the sign" } */ fsi (c1); /* { dg-warning "change the sign" } */ fui (c1); f_l (c1); /* { dg-warning "change the sign" "" { target { llp64 || ilp32 } } } */ fsl (c1); /* { dg-warning "change the sign" "" { target { llp64 || ilp32 } } } */ ful (c1); f_ll (c1); fsll (c1); full (c1); }
void m (char16_t c0, char32_t c1) { f_c (c0); /* { dg-warning "alter its value" } */ fsc (c0); /* { dg-warning "alter its value" } */ fuc (c0); /* { dg-warning "alter its value" } */ f_s (c0); /* { dg-warning "change the sign" } */ fss (c0); /* { dg-warning "change the sign" } */ fus (c0); f_i (c0); fsi (c0); fui (c0); f_l (c0); fsl (c0); ful (c0); f_ll (c0); fsll (c0); full (c0); f_c (c1); /* { dg-warning "alter its value" } */ fsc (c1); /* { dg-warning "alter its value" } */ fuc (c1); /* { dg-warning "alter its value" } */ f_s (c1); /* { dg-warning "alter its value" } */ fss (c1); /* { dg-warning "alter its value" } */ fus (c1); /* { dg-warning "alter its value" } */ f_i (c1); /* { dg-warning "change the sign" "" { target { ! int16 } } } */ fsi (c1); /* { dg-warning "change the sign" "" { target { ! int16 } } } */ fui (c1); f_l (c1); /* { dg-warning "change the sign" "" { target { llp64 || ilp32 } } } */ fsl (c1); /* { dg-warning "change the sign" "" { target { llp64 || ilp32 } } } */ ful (c1); f_ll (c1); fsll (c1); full (c1); }
int main() { setbuf(stdout, NULL); for (long l = 256; l <= 16384; l *= 2) { // for (long n = 256; n <= 16384; n *= 2) { for (long idx = 0; idx < 13; idx ++) { long n = 256*(1L << idx/2); if (idx & 1) n += n/2; SetSeed((ZZ(l) << 64) + ZZ(n)); ZZX a, b, c; a.SetLength(n); for (long i = 0; i < n; i++) RandomBits(a[i], l); a.normalize(); b.SetLength(n); for (long i = 0; i < n; i++) RandomBits(b[i], l); b.normalize(); double t; mul(c, a, b); long iter = 1; do { t = GetTime(); for (long i = 0; i < iter; i++) mul(c, a, b); t = GetTime() - t; iter *= 2; } while (t < 3); iter /= 2; t = GetTime(); for (long i = 0; i < iter; i++) mul(c, a, b); t = GetTime()-t; double NTLTime = t; FlintZZX f_a(a), f_b(b), f_c(c); fmpz_poly_mul(f_c.value, f_a.value, f_b.value); t = GetTime(); for (long i = 0; i < iter; i++) fmpz_poly_mul(f_c.value, f_a.value, f_b.value); t = GetTime()-t; double FlintTime = t; printf("%8.2f", FlintTime/NTLTime); } printf("\n"); } }
explicit FlintZZX(const ZZX& a) { long da = deg(a); fmpz_poly_init2(value, da+1); for (long i = 0; i <= da; i++) { FlintZZ f_c(a[i]); fmpz_poly_set_coeff_fmpz(value, i, f_c.value); } }
explicit FlintZZ_pX(const ZZ_pX& a) { long da = deg(a); FlintZZ f_p(ZZ_p::modulus()); fmpz_mod_poly_init2(value, f_p.value, da+1); for (long i = 0; i <= da; i++) { FlintZZ f_c(rep(a[i])); fmpz_mod_poly_set_coeff_fmpz(value, i, f_c.value); } }
Vector_double stf::deconvolve(const Vector_double& data, const Vector_double& templ, int SR, double hipass, double lopass, stfio::ProgressInfo& progDlg) { bool skipped = false; progDlg.Update( 0, "Starting deconvolution...", &skipped ); if (data.size()<=0 || templ.size() <=0 || templ.size() > data.size()) { std::out_of_range e("subscript out of range in stf::filter()"); throw e; } /* pad templ */ Vector_double templ_padded(data.size()); std::copy(templ.begin(), templ.end(), templ_padded.begin()); if (templ.size() < templ_padded.size()) { std::fill(templ_padded.begin()+templ.size(), templ_padded.end(), 0); } Vector_double data_return(data.size()); if (skipped) { data_return.resize(0); return data_return; } double *in_data, *in_templ_padded; //fftw_complex is a double[2]; hence, out is an array of //double[2] with out[n][0] being the real and out[n][1] being //the imaginary part. fftw_complex *out_data, *out_templ_padded; fftw_plan p_data, p_templ, p_inv; //memory allocation as suggested by fftw: in_data =(double *)fftw_malloc(sizeof(double) * data.size()); out_data = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * ((int)(data.size()/2)+1)); in_templ_padded =(double *)fftw_malloc(sizeof(double) * templ_padded.size()); out_templ_padded = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * ((int)(templ_padded.size()/2)+1)); std::copy(data.begin(), data.end(), &in_data[0]); std::copy(templ_padded.begin(), templ_padded.end(), &in_templ_padded[0]); //plan the ffts and execute them: p_data =fftw_plan_dft_r2c_1d((int)data.size(), in_data, out_data, FFTW_ESTIMATE); fftw_execute(p_data); p_templ =fftw_plan_dft_r2c_1d((int)templ_padded.size(), in_templ_padded, out_templ_padded, FFTW_ESTIMATE); fftw_execute(p_templ); double SI=1.0/SR; //the sampling interval progDlg.Update( 25, "Performing deconvolution...", &skipped ); if (skipped) { data_return.resize(0); return data_return; } Vector_double f_c(1); for (std::size_t n_point=0; n_point < (unsigned int)(data.size()/2)+1; ++n_point) { /* highpass filter */ double f = n_point / (data.size()*SI); double rslt_hi = 1.0; if (hipass > 0) { f_c[0] = hipass; rslt_hi = 1.0-fgaussColqu(f, f_c); } /* lowpass filter */ double rslt_lo = 1.0; if (lopass > 0) { f_c[0] = lopass; rslt_lo= fgaussColqu(f, f_c); } /* do the division in place */ double a = out_data[n_point][0]; double b = out_data[n_point][1]; double c = out_templ_padded[n_point][0]; double d = out_templ_padded[n_point][1]; double mag2 = c*c + d*d; out_data[n_point][0] = rslt_hi * rslt_lo * (a*c + b*d)/mag2; out_data[n_point][1] = rslt_hi * rslt_lo * (b*c - a*d)/mag2; } //do the reverse fft: p_inv = fftw_plan_dft_c2r_1d((int)data.size(),out_data, in_data, FFTW_ESTIMATE); fftw_execute(p_inv); //fill the return array, adding the offset, and scaling by data.size() //(because fftw computes an unnormalized transform): for (std::size_t n_point=0; n_point < data.size(); ++n_point) { data_return[n_point]= in_data[n_point]/data.size(); } fftw_destroy_plan(p_data); fftw_destroy_plan(p_templ); fftw_destroy_plan(p_inv); fftw_free(in_data); fftw_free(out_data); fftw_free(in_templ_padded); fftw_free(out_templ_padded); progDlg.Update( 50, "Computing data histogram...", &skipped ); if (skipped) { data_return.resize(0); return data_return; } int nbins = int(data_return.size()/500.0); std::map<double, int> histo = histogram(data_return, nbins); double max_value = -1; double max_time = 0; double maxhalf_time = 0; Vector_double histo_fit(0); for (std::map<double,int>::const_iterator it=histo.begin(); it != histo.end(); ++it) { if (it->second > max_value) { max_value = it->second; max_time = it->first; } histo_fit.push_back(it->second); #ifdef _STFDEBUG std::cout << it->first << "\t" << it->second << std::endl; #endif } for (std::map<double,int>::const_iterator it=histo.begin(); it != histo.end(); ++it) { if (it->second > 0.5*max_value) { maxhalf_time = it->first; break; } } maxhalf_time = fabs(max_time-maxhalf_time); progDlg.Update( 75, "Fitting Gaussian...", &skipped ); if (skipped) { data_return.resize(0); return data_return; } /* Fit Gaussian to histogram */ Vector_double opts = LM_default_opts(); std::string info; int warning; std::vector< stf::storedFunc > funcLib = stf::GetFuncLib(); double interval = (++histo.begin())->first-histo.begin()->first; /* Initial parameter guesses */ Vector_double pars(3); pars[0] = max_value; pars[1] = (max_time - histo.begin()->first); pars[2] = maxhalf_time *sqrt(2.0)/2.35482; #ifdef _STFDEBUG std::cout << "nbins: " << nbins << std::endl; std::cout << "initial values:" << std::endl; for (std::size_t np=0; np<pars.size(); ++np) { std::cout << pars[np] << std::endl; } #endif #ifdef _STFDEBUG double chisqr = #endif lmFit(histo_fit, interval, funcLib[funcLib.size()-1], opts, true, pars, info, warning ); #ifdef _STFDEBUG std::cout << chisqr << "\t" << interval << std::endl; std::cout << "final values:" << std::endl; for (std::size_t np=0; np<pars.size(); ++np) { std::cout << pars[np] << std::endl; } #endif double sigma = pars[2]/sqrt(2.0); /* return data in terms of sigma */ for (std::size_t n_point=0; n_point < data.size(); ++n_point) { data_return[n_point] /= sigma; } progDlg.Update( 100, "Done.", &skipped ); return data_return; }
size_t btrd_binomial_distribution(size_t n_orig, double p, mrg_state* state) { /* BTRD algorithm from pages 6--7 of "The Generation of Binomial Random * Variates" (Wolfgang Hoermann) -- * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.8407 */ if (p == 0.) return 0; if (p > .5) return n_orig - btrd_binomial_distribution(n_orig, 1. - p, state); if (n_orig * p < 10) { /* First waiting time algorithm from page 525 of * http://cg.scs.carleton.ca/~luc/chapter_ten.pdf */ int x = 0; int sum = 0; double recip_log_1_minus_p; /* Approximation to ln(1-p) from second sequence in exercise 1 of * http://cg.scs.carleton.ca/~luc/chapter_ten.pdf page 500; done to avoid * use of C99 log1p function. */ { double r = 1. - 2. / p; double recip_r = 1. / r; double recip_r2 = recip_r * recip_r; double recip_r4 = recip_r2 * recip_r2; double recip_r6 = recip_r4 * recip_r2; double log_1_minus_p = 2. * recip_r * (1 + recip_r2 / 3. + recip_r4 / 5. + recip_r6 / 7.); recip_log_1_minus_p = 1. / log_1_minus_p; } #if 0 /* Old version using C99 log1p: */ recip_log_1_minus_p = 1. / log1p(-p); /* 1 / ln(1 - p) */ #endif do { /* From page 500 of http://cg.scs.carleton.ca/~luc/chapter_ten.pdf * (geometric variate generator). */ sum += (int)ceil(log(mrg_get_double_orig(state)) * recip_log_1_minus_p); ++x; } while (sum <= n_orig); return x - 1; } if (n_orig > 1000000000) { return btrd_binomial_distribution(1000000000, p, state) + btrd_binomial_distribution(n_orig - 1000000000, p, state); } { int n = (int)n_orig; /* Setup */ int m = (int)floor((n + 1) * p); double r = p / (1. - p); double nr = (n + 1) * r; double npq = n * p * (1. - p); double sqrt_npq = sqrt(npq); double b = 1.15 + 2.53 * sqrt_npq; double a = -.0873 + .0248 * b + .01 * p; double c = n * p + .5; double alpha = (2.83 + 5.1 / b) * sqrt_npq; double v_r = .92 - 4.2 / b; double u_rv_r = .86 * v_r; while (1) { /* 1 */ double v = mrg_get_double_orig(state); double u, us, temp_random_num; int k, km; if (v <= u_rv_r) { u = v / v_r - .43; return (int)floor((2 * a / (.5 + fabs(u)) + b) * u + c); } /* 2 */ temp_random_num = mrg_get_double_orig(state); if (v >= v_r) { u = temp_random_num - .5; } else { u = v / v_r - .93; u = (u > 0. ? 1. : u < 0. ? -1. : 0.) * .5 - u; v = v_r * temp_random_num; } /* 3.0 */ us = .5 - fabs(u); k = (int)floor((2 * a / us + b) * u + c); if (k < 0 || k > n) continue; v *= alpha / (a / (us * us) + b); km = (k >= m ? k - m : m - k); if (km > 15) { /* 3.2 */ double rho = (km / npq) * (((km / 3 + .625) * km + 1. / 6) / npq + .5); double t = -km * km / (2 * npq); int nm, nk; double h, threshold; v = log(v); if (v < t - rho) return k; if (v > t + rho) continue; /* 3.3 */ nm = n - m + 1; h = (m + .5) * log((m + 1) / (r * nm)) + f_c(m) + f_c(n - m); /* 3.4 */ nk = n - k + 1; threshold = h + (n + 1) * log((double)nm / nk) + (k + .5) * log(nk * r / (k + 1)) - f_c(k) - f_c(n - k); if (v <= threshold) return k; } else { /* 3.1 */ double f = 1.; int i; if (m < k) { for (i = m; i != k; ++i) f *= nr / i - r; } else if (m > k) { for (i = k; i != m; ++i) v *= nr / i + r; } if (v <= f) return k; } } } }
int main(int argc, char**argv){ fun_t *f; f = f_mult(f_window(f_cu(0,SEC),f_cu(3,SEC)), f_sin(f_c(1),f_cu(50,HZ),f_c(0)) ); f = f_add(f, f_mult(f_window(f_cu(3,SEC),f_cu(6,SEC)), f_tri(f_c(1),f_cu(50,HZ),f_c(0)) )); f = f_add(f, f_mult(f_window(f_cu(6,SEC),f_cu(9,SEC)), f_square(f_c(1),f_cu(50,HZ),f_c(0),f_c(0.5)) )); set_bpm(f_ramp(f_cu(2,SEC),f_cu(8,SEC),f_c(60),f_c(70))); set_period(f_c(4)); /* fun_print(f); */ f = s_down_sample(f_c(10),f); fun_record_16b(f,0,SAMPLING_RATE*10,2,buffer); audio_write_stereo_16b(buffer,SAMPLING_RATE*2*2*10,"test.wav"); return 0; }