Thyra::ModelEvaluatorBase::InArgs<double> init_nominal_values_( const std::shared_ptr<const Tpetra::Vector<double,int,int>> & x ) { const auto f_params = f_->get_scalar_parameters(); const auto jac_params = jac_->get_scalar_parameters(); const auto dfdp_params = dfdp_->get_scalar_parameters(); std::map<std::string, double> all_params; all_params.insert(f_params.begin(), f_params.end()); all_params.insert(jac_params.begin(), jac_params.end()); all_params.insert(dfdp_params.begin(), dfdp_params.end()); auto p_init = Thyra::createMember(this->get_p_space(0)); int k = 0; for (auto it = all_params.begin(); it != all_params.end(); ++it) { Thyra::set_ele(k, it->second, p_init()); k++; } auto nominal_values = this->createInArgs(); const Teuchos::RCP<const Tpetra::Vector<double,int,int>> initial_x = Teuchos::rcp(x); const auto xxx = Thyra::createConstVector(initial_x, space_); nominal_values.set_p(0, p_init); nominal_values.set_x(xxx); return nominal_values; }
void librandom::BinomialRandomDev::set_status(const DictionaryDatum &d) { double p_tmp; if ( updateValue<double>(d, "p", p_tmp) ) set_p(p_tmp); long n_tmp; if ( updateValue<long>(d, "n", n_tmp) ) set_n(n_tmp); }
int mpx_test (int argc, const char **argv) { int *p; set_p (p); rd (p, 0); rd (p, 99); return 0; }
static int get_impropers(t_atoms *atoms, t_hackblock hb[], t_param **improper, gmx_bool bAllowMissing) { t_rbondeds *impropers; int nimproper, i, j, k, start, ninc, nalloc; atom_id ai[MAXATOMLIST]; gmx_bool bStop; ninc = 500; nalloc = ninc; snew(*improper, nalloc); /* Add all the impropers from the residue database to the list. */ nimproper = 0; start = 0; if (hb != NULL) { for (i = 0; (i < atoms->nres); i++) { impropers = &hb[i].rb[ebtsIDIHS]; for (j = 0; (j < impropers->nb); j++) { bStop = FALSE; for (k = 0; (k < 4) && !bStop; k++) { ai[k] = search_atom(impropers->b[j].a[k], start, atoms, "improper", bAllowMissing); if (ai[k] == NO_ATID) { bStop = TRUE; } } if (!bStop) { if (nimproper == nalloc) { nalloc += ninc; srenew(*improper, nalloc); } /* Not broken out */ set_p(&((*improper)[nimproper]), ai, NULL, impropers->b[j].s); nimproper++; } } while ((start < atoms->nr) && (atoms->atom[start].resind == i)) { start++; } } } return nimproper; }
obj* LinkedList() { obj* self = Object(); self->dealloc = dealloc; list* list = ll_create(); set_p(self, "value", &list, sizeof(struct llist_*)); bind(self, "push back", push_back); bind(self, "push front", push_front); bind_o(self, "back", back); bind_o(self, "front", front); return self; }
static int get_impropers(t_atoms *atoms,t_hackblock hb[],t_param **idih, bool bMissing) { char *a0; t_rbondeds *idihs; t_rbonded *hbidih; int nidih,i,j,k,r,start,ninc,nalloc; atom_id ai[MAXATOMLIST]; bool bStop; ninc = 500; nalloc = ninc; snew(*idih,nalloc); /* Add all the impropers from the residue database to the list. */ nidih = 0; start = 0; if (hb != NULL) { for(i=0; (i<atoms->nres); i++) { idihs=&hb[i].rb[ebtsIDIHS]; for(j=0; (j<idihs->nb); j++) { bStop=FALSE; for(k=0; (k<4) && !bStop; k++) { ai[k] = search_atom(idihs->b[j].a[k],start, atoms->nr,atoms->atom,atoms->atomname, "improper",bMissing); if (ai[k] == NO_ATID) bStop = TRUE; } if (!bStop) { if (nidih == nalloc) { nalloc += ninc; srenew(*idih,nalloc); } /* Not broken out */ set_p(&((*idih)[nidih]),ai,NULL,idihs->b[j].s); nidih++; } } while ((start<atoms->nr) && (atoms->atom[start].resind == i)) start++; } } return nidih; }
Thyra::ModelEvaluatorBase::InArgs<double> init_nominal_values_( const Teuchos::RCP<const Tpetra::Vector<double,int,int>> & x, const double alpha0 ) { auto p_init = Thyra::createMember(this->get_p_space(0)); Thyra::set_ele(0, alpha0, p_init()); const auto xxx = Thyra::createConstVector(x, space_); auto nominal_values = this->createInArgs(); nominal_values.set_p(0, p_init); nominal_values.set_x(xxx); return nominal_values; }
int main(void) { char *line; char p[20]; char c; char *co; t_game *filler; c = 'p'; line = NULL; get_next_line(0, &co); c = init_char(co); ft_strcpy(p, "5 11\n"); while (get_next_line(0, &line)) if (ft_strlen(line) > 0) { filler = get_data(c, line); set_p(p, filler); free_filler(&filler); write(1, p, ft_strlen(p)); } return (0); }
void librandom::GSL_BinomialRandomDev::set_p_n( double p_s, unsigned n_s ) { set_p( p_s ); set_n( n_s ); }
int main(void) { mp_bitcnt_t bits; mp_size_t j, k, n, w, limbs, d; mp_limb_t * nn, * r; mpz_t p, m1, m2, mn1, mn2; gmp_randstate_t state; tests_start(); fflush(stdout); gmp_randinit_default(state); mpz_init(m1); mpz_init(m2); mpz_init(mn1); mpz_init(mn2); mpz_init(p); /* normalisation mod p = 2^wn + 1 where B divides nw and n is a power of 2 */ for (bits = GMP_LIMB_BITS; bits < 16*GMP_LIMB_BITS; bits += GMP_LIMB_BITS) { for (j = 1; j < 32; j++) { for (k = 1; k <= GMP_LIMB_BITS; k <<= 1) { for (d = 0; d < GMP_LIMB_BITS; d++) { n = bits/k; w = j*k; limbs = (n*w)/GMP_LIMB_BITS; nn = malloc((limbs + 1)*sizeof(mp_limb_t)); r = malloc((limbs + 1)*sizeof(mp_limb_t)); mpir_random_fermat(nn, state, limbs); mpir_fermat_to_mpz(mn1, nn, limbs); set_p(p, n, w); mpn_div_2expmod_2expp1(r, nn, limbs, d); mpir_fermat_to_mpz(m2, r, limbs); mpz_mod(m2, m2, p); mpz_mod(m1, mn1, p); mpz_mul_2exp(m2, m2, d); mpz_mod(m2, m2, p); if (mpz_cmp(m1, m2) != 0) { printf("FAIL:\n"); printf("mpn_div_2expmod_2expp1 error\n"); gmp_printf("want %Zx\n\n", m1); gmp_printf("got %Zx\n", m2); abort(); } } free(nn); free(r); } } } mpz_clear(mn2); mpz_clear(mn1); mpz_clear(m2); mpz_clear(m1); mpz_clear(p); gmp_randclear(state); tests_end(); return 0; }
int main(void) { mp_size_t c, bits, j, k, x, y, n, w, limbs; mpz_t p, ma, mb, m2a, m2b, mn1, mn2; mp_limb_t * nn1, * nn2, * r1, * r2; flint_rand_t state; printf("butterfly_rshB...."); fflush(stdout); flint_randinit(state); _flint_rand_init_gmp(state); mpz_init(p); mpz_init(ma); mpz_init(mb); mpz_init(m2a); mpz_init(m2b); mpz_init(mn1); mpz_init(mn2); for (bits = FLINT_BITS; bits < 20*FLINT_BITS; bits += FLINT_BITS) { for (j = 1; j < 10; j++) { for (k = 1; k <= FLINT_BITS; k <<= 1) { n = bits/k; w = j*k; limbs = (n*w)/FLINT_BITS; for (c = 0; c < limbs; c++) { x = n_randint(state, limbs); y = n_randint(state, limbs); nn1 = flint_malloc((limbs + 1)*sizeof(mp_limb_t)); nn2 = flint_malloc((limbs + 1)*sizeof(mp_limb_t)); r1 = flint_malloc((limbs + 1)*sizeof(mp_limb_t)); r2 = flint_malloc((limbs + 1)*sizeof(mp_limb_t)); mpn_rrandom(nn1, state->gmp_state, limbs); random_fermat(nn1, state, limbs); random_fermat(nn2, state, limbs); fermat_to_mpz(mn1, nn1, limbs); fermat_to_mpz(mn2, nn2, limbs); set_p(p, n, w); butterfly_rshB(r1, r2, nn1, nn2, limbs, x, y); fermat_to_mpz(m2a, r1, limbs); fermat_to_mpz(m2b, r2, limbs); mpz_mod(m2a, m2a, p); mpz_mod(m2b, m2b, p); ref_butterfly_rshB(ma, mb, mn1, mn2, p, x, y); if (mpz_cmp(ma, m2a) != 0) { printf("FAIL:\n"); printf("butterfly_rshB error a\n"); printf("x = %ld, y = %ld, limbs = %ld\n", x, y, limbs); printf("n = %ld, w = %ld, k = %ld, c = %ld\n", n, w, k, c); gmp_printf("want %Zx\n\n", ma); gmp_printf("got %Zx\n", m2a); abort(); } if (mpz_cmp(mb, m2b) != 0) { printf("FAIL:\n"); printf("butterfly_rshB error b\n"); printf("x = %ld, y = %ld, limbs = %ld\n", x, y, limbs); printf("n = %ld, w = %ld, k = %ld, c = %ld\n", n, w, k, c); gmp_printf("want %Zx\n\n", mb); gmp_printf("got %Zx\n", m2b); abort(); } flint_free(nn1); flint_free(nn2); flint_free(r1); flint_free(r2); } } } } mpz_clear(p); mpz_clear(ma); mpz_clear(mb); mpz_clear(m2a); mpz_clear(m2b); mpz_clear(mn1); mpz_clear(mn2); flint_randclear(state); printf("PASS\n"); return 0; }
int main(void) { mp_bitcnt_t bits; mp_size_t j, k, n, w, limbs; mp_limb_t * nn; mpz_t p, m1, m2; FLINT_TEST_INIT(state); flint_printf("normmod_2expp1...."); fflush(stdout); _flint_rand_init_gmp(state); mpz_init(m1); mpz_init(m2); mpz_init(p); /* normalisation mod p = 2^wn + 1 where B divides nw and n is a power of 2 */ for (bits = FLINT_BITS; bits < 32*FLINT_BITS; bits += FLINT_BITS) { for (j = 1; j < 32; j++) { for (k = 1; k <= GMP_NUMB_BITS; k <<= 1) { n = bits/k; w = j*k; limbs = (n*w)/GMP_LIMB_BITS; nn = flint_malloc((limbs + 1)*sizeof(mp_limb_t)); random_fermat(nn, state, limbs); fermat_to_mpz(m1, nn, limbs); set_p(p, n, w); mpn_normmod_2expp1(nn, limbs); fermat_to_mpz(m2, nn, limbs); mpz_mod(m1, m1, p); if (mpz_cmp(m1, m2) != 0) { flint_printf("FAIL:\n"); flint_printf("mpn_normmod_2expp1 error\n"); gmp_printf("want %Zx\n\n", m1); gmp_printf("got %Zx\n", m2); abort(); } flint_free(nn); } } } mpz_clear(m2); mpz_clear(m1); mpz_clear(p); FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
// ============================================================================= void testComputeF( const std::string & input_filename_base, const double mu, const double control_norm_1, const double control_norm_2, const double control_norm_inf ) { // Read the data from the file. auto comm = Teuchos::DefaultComm<int>::getComm(); const int size = comm->getSize(); const std::string input_filename = (size == 1) ? "data/" + input_filename_base + ".h5m" : "data/" + input_filename_base + "-" + std::to_string(size) + ".h5m" ; // Read the data from the file. auto mesh = nosh::read(input_filename); // Cast the data into something more accessible. auto z = mesh->get_complex_vector("psi"); // Set the thickness field. auto thickness = std::make_shared<nosh::scalar_field::constant>(*mesh, 1.0); auto mvp = std::make_shared<nosh::vector_field::explicit_values>(*mesh, "A", mu); auto sp = std::make_shared<nosh::scalar_field::constant>(*mesh, -1.0); auto model_eval = Teuchos::rcp(new nosh::model_evaluator::nls( mesh, mvp, sp, 1.0, thickness, z, "mu" )); // Create in_args.x auto in_args = model_eval->createInArgs(); in_args.set_x(Thyra::createVector(Teuchos::rcp(z), model_eval->get_f_space())); // in_args.p auto p = Thyra::createMember(model_eval->get_p_space(0)); Thyra::set_ele(0, 1.0, p()); // g Thyra::set_ele(1, 0.01, p()); // mu in_args.set_p(0, p); // Create out_args. auto out_args = model_eval->createOutArgs(); auto f = Thyra::createMember(model_eval->get_f_space()); out_args.set_f(f); // Fetch. model_eval->evalModel(in_args, out_args); // check the norms REQUIRE(Thyra::norm_1(*f) == Approx(control_norm_1)); REQUIRE(Thyra::norm_2(*f) == Approx(control_norm_2)); REQUIRE(Thyra::norm_inf(*f) == Approx(control_norm_inf)); return; }
PauliChannel::PauliChannel(uint_t nq, rvector_t p_pauli) : n(nq) { set_p(p_pauli); }