void copy(const MidpointConfiguration & other){ this->MPType = other.MPType; this->systems = other.systems; system_name_mid = other.system_name_mid; system_name_top = other.system_name_top; system_name_bottom = other.system_name_bottom; set_mp(v_target,other.v_target); set_mp(u_target,other.u_target); set_mp(crit_val_left,other.crit_val_left); set_mp(crit_val_right,other.crit_val_right); for (int ii=0; ii<other.num_projections; ii++) { add_projection(other.pi[ii]); } }
int change_sphere_eval_prec(void const *ED, int new_prec) { sphere_eval_data_mp *BED = (sphere_eval_data_mp *)ED; // to avoid having to cast every time BED->SLP->precision = new_prec; // change the precision for the patch changePatchPrec_mp(new_prec, &BED->patch); if (new_prec != BED->curr_prec){ if (BED->verbose_level() >=8){ std::cout << color::brown(); printf("prec %ld\t-->\t%d\n",BED->curr_prec, new_prec); std::cout << color::console_default(); } BED->curr_prec = new_prec; setprec_mp(BED->gamma, new_prec); mpf_set_q(BED->gamma->r, BED->gamma_rat[0]); mpf_set_q(BED->gamma->i, BED->gamma_rat[1]); for (int ii=0; ii<1; ++ii){ change_prec_point_mp(BED->starting_linear[ii],new_prec); vec_cp_mp(BED->starting_linear[ii], BED->starting_linear_full_prec[ii]); } for (int ii=0; ii<BED->num_static_linears; ++ii){ change_prec_point_mp(BED->static_linear[ii],new_prec); vec_cp_mp(BED->static_linear[ii], BED->static_linear_full_prec[ii]); } change_prec_point_mp(BED->center, new_prec); vec_cp_mp(BED->center, BED->center_full_prec); setprec_mp(BED->radius, new_prec); set_mp(BED->radius, BED->radius_full_prec); setprec_mp(BED->two, new_prec); set_mp(BED->two, BED->two_full_prec); BED->randomizer()->change_prec(new_prec); } return 0; }
/** \brief add a projection to the set, and get its index. Add a projection to the set, and get its index. Does not test for uniqueness of the projection, assumes it is not in there yet. \return the index of the added projection \param proj the projection to add. */ int add_projection(vec_mp proj){ if (this->num_projections_==0) { projections_ = (vec_mp *) br_malloc(sizeof(vec_mp)); } else{ this->projections_ = (vec_mp *)br_realloc(this->projections_, (this->num_projections_+1) * sizeof(vec_mp)); } init_vec_mp2(this->projections_[num_projections_],num_natural_variables_,T_->AMP_max_prec); this->projections_[num_projections_]->size = num_natural_variables_; if (proj->size != num_natural_variables_) { vec_mp tempvec; init_vec_mp2(tempvec,num_natural_variables_,T_->AMP_max_prec); tempvec->size = num_natural_variables_; for (int kk=0; kk<num_natural_variables_; kk++) { set_mp(&tempvec->coord[kk], &proj->coord[kk]); } vec_cp_mp(projections_[num_projections_], tempvec); clear_vec_mp(tempvec); } else { vec_cp_mp(projections_[num_projections_], proj); } num_projections_++; return num_projections_; }
void WitnessSet::only_first_vars(int num_vars) { vec_mp tempvec; init_vec_mp2(tempvec, num_vars, 1024); tempvec->size = num_vars; for (unsigned int ii=0; ii<num_points(); ii++) { vec_mp & curr_point = point(ii); for (int jj=0; jj<num_vars; jj++) { set_mp(&tempvec->coord[jj], &curr_point->coord[jj]); } change_size_vec_mp(curr_point, num_vars); curr_point->size = num_vars; vec_cp_mp(curr_point, tempvec); } this->num_vars_ = num_vars; int patch_size_counter = 0, trim_from_here = 0; for (unsigned int ii=0; ii<num_patches(); ii++) { patch_size_counter += patch(ii)->size; if (patch_size_counter == num_vars) { trim_from_here = ii+1; } } if (trim_from_here==0) { std::cerr << "problem: the sum of the patch sizes never equalled the number of variables to trim to...\nhence, the trimming operation could not complete." << std::endl; this->print_to_screen(); deliberate_segfault(); } for (unsigned int ii=trim_from_here; ii<num_patches(); ii++) { clear_vec_mp(patch(ii)); } patch_mp_ = (vec_mp *) br_realloc(patch_mp_, trim_from_here* sizeof(vec_mp)); num_patches_ = trim_from_here; for (unsigned int ii=0; ii<num_linears(); ii++) { linear(ii)->size = num_vars; } clear_vec_mp(tempvec); return; }
void phase2( struct xfs_mount *mp, int scan_threads) { int j; ino_tree_node_t *ino_rec; /* now we can start using the buffer cache routines */ set_mp(mp); /* Check whether this fs has internal or external log */ if (mp->m_sb.sb_logstart == 0) { if (!x.logname) do_error(_("This filesystem has an external log. " "Specify log device with the -l option.\n")); do_log(_("Phase 2 - using external log on %s\n"), x.logname); } else do_log(_("Phase 2 - using internal log\n")); /* Zero log if applicable */ if (!no_modify) { do_log(_(" - zero log...\n")); zero_log(mp); } do_log(_(" - scan filesystem freespace and inode maps...\n")); bad_ino_btree = 0; set_progress_msg(PROG_FMT_SCAN_AG, (__uint64_t) glob_agcount); scan_ags(mp, scan_threads); print_final_rpt(); /* * make sure we know about the root inode chunk */ if ((ino_rec = find_inode_rec(0, mp->m_sb.sb_rootino)) == NULL) { ASSERT(mp->m_sb.sb_rbmino == mp->m_sb.sb_rootino + 1 && mp->m_sb.sb_rsumino == mp->m_sb.sb_rootino + 2); do_warn(_("root inode chunk not found\n")); /* * mark the first 3 used, the rest are free */ ino_rec = set_inode_used_alloc(0, (xfs_agino_t) mp->m_sb.sb_rootino); set_inode_used(ino_rec, 1); set_inode_used(ino_rec, 2); for (j = 3; j < XFS_INODES_PER_CHUNK; j++) set_inode_free(ino_rec, j); /* * also mark blocks */ set_bmap_ext(0, XFS_INO_TO_AGBNO(mp, mp->m_sb.sb_rootino), mp->m_ialloc_blks, XR_E_INO); } else { do_log(_(" - found root inode chunk\n")); /* * blocks are marked, just make sure they're in use */ if (is_inode_free(ino_rec, 0)) { do_warn(_("root inode marked free, ")); set_inode_used(ino_rec, 0); if (!no_modify) do_warn(_("correcting\n")); else do_warn(_("would correct\n")); } if (is_inode_free(ino_rec, 1)) { do_warn(_("realtime bitmap inode marked free, ")); set_inode_used(ino_rec, 1); if (!no_modify) do_warn(_("correcting\n")); else do_warn(_("would correct\n")); } if (is_inode_free(ino_rec, 2)) { do_warn(_("realtime summary inode marked free, ")); set_inode_used(ino_rec, 2); if (!no_modify) do_warn(_("correcting\n")); else do_warn(_("would correct\n")); } } }
void phase2(xfs_mount_t *mp, libxfs_init_t *args) { xfs_agnumber_t i; xfs_agblock_t b; int j; ino_tree_node_t *ino_rec; /* now we can start using the buffer cache routines */ set_mp(mp); /* Check whether this fs has internal or external log */ if (mp->m_sb.sb_logstart == 0) { if (!args->logname) { fprintf (stderr, "This filesystem has an external log. " "Specify log device with the -l option.\n"); exit (1); } fprintf (stderr, "Phase 2 - using external log on %s\n", args->logname); } else fprintf (stderr, "Phase 2 - using internal log\n"); /* Zero log if applicable */ if (!no_modify) { do_log(" - zero log...\n"); zero_log(mp, args); } do_log(" - scan filesystem freespace and inode maps...\n"); /* * account for space used by ag headers and log if internal */ set_bmap_log(mp); set_bmap_fs(mp); bad_ino_btree = 0; for (i = 0; i < mp->m_sb.sb_agcount; i++) { scan_ag(i); #ifdef XR_INODE_TRACE print_inode_list(i); #endif } /* * make sure we know about the root inode chunk */ if ((ino_rec = find_inode_rec(0, mp->m_sb.sb_rootino)) == NULL) { ASSERT(mp->m_sb.sb_rbmino == mp->m_sb.sb_rootino + 1 && mp->m_sb.sb_rsumino == mp->m_sb.sb_rootino + 2); do_warn("root inode chunk not found\n"); /* * mark the first 3 used, the rest are free */ ino_rec = set_inode_used_alloc(0, (xfs_agino_t) mp->m_sb.sb_rootino); set_inode_used(ino_rec, 1); set_inode_used(ino_rec, 2); for (j = 3; j < XFS_INODES_PER_CHUNK; j++) set_inode_free(ino_rec, j); /* * also mark blocks */ for (b = 0; b < mp->m_ialloc_blks; b++) { set_agbno_state(mp, 0, b + XFS_INO_TO_AGBNO(mp, mp->m_sb.sb_rootino), XR_E_INO); } } else { do_log(" - found root inode chunk\n"); /* * blocks are marked, just make sure they're in use */ if (is_inode_free(ino_rec, 0)) { do_warn("root inode marked free, "); set_inode_used(ino_rec, 0); if (!no_modify) do_warn("correcting\n"); else do_warn("would correct\n"); } if (is_inode_free(ino_rec, 1)) { do_warn("realtime bitmap inode marked free, "); set_inode_used(ino_rec, 1); if (!no_modify) do_warn("correcting\n"); else do_warn("would correct\n"); } if (is_inode_free(ino_rec, 2)) { do_warn("realtime summary inode marked free, "); set_inode_used(ino_rec, 2); if (!no_modify) do_warn("correcting\n"); else do_warn("would correct\n"); } } }
void copy(const midpoint_eval_data_mp & other) { SolverMultiplePrecision::copy(other); this->num_mid_vars = other.num_mid_vars; this->num_top_vars = other.num_top_vars; this->num_bottom_vars = other.num_bottom_vars; this->bottom_memory = other.bottom_memory; this->top_memory = other.top_memory; this->mid_memory = other.mid_memory; this->SLP_mid = other.SLP_mid; this->SLP_top = other.SLP_top; this->SLP_bottom = other.SLP_bottom; for (int ii=0; ii<other.num_projections; ii++) { if (other.MPType==2) { add_projection(other.pi_full_prec[ii]); } else{ add_projection(other.pi[ii]); } } //patch already lives in the base class. set_mp(v_target,other.v_target); set_mp(u_target,other.u_target); randomizer_bottom = other.randomizer_bottom; randomizer_top = other.randomizer_top; set_mp(crit_val_left,other.crit_val_left); set_mp(crit_val_right,other.crit_val_right); set_mp(u_start, other.u_start); set_mp(v_start, other.v_start); if (this->MPType==2) { set_mp(v_target_full_prec,other.v_target_full_prec); set_mp(u_target_full_prec,other.u_target_full_prec); set_mp(crit_val_left_full_prec,other.crit_val_left_full_prec); set_mp(crit_val_right_full_prec,other.crit_val_right_full_prec); set_mp(u_start_full_prec, other.u_start_full_prec); set_mp(v_start_full_prec, other.v_start_full_prec); } } // re: copy
void nullspace_config_setup_right(NullspaceConfiguration *ns_config, vec_mp *pi, // an array of projections, the number of which is the target dimensions int ambient_dim, int *max_degree, // a pointer to the value std::shared_ptr<SystemRandomizer> randomizer, const WitnessSet & W, SolverConfiguration & solve_options) { ns_config->set_side(nullspace_handedness::RIGHT); int toss; parse_input_file(W.input_filename(), &toss); // re-create the parsed files for the stuffs (namely the SLP). ns_config->set_randomizer(randomizer); // set the pointer. this randomizer is for the underlying system. *max_degree = randomizer->max_degree()-1; // minus one for differentiated degree ns_config->max_degree = *max_degree; // set some integers ns_config->num_projections = ambient_dim; ns_config->num_v_vars = W.num_natural_variables()-1; ns_config->num_synth_vars = W.num_synth_vars(); // this may get a little crazy if we chain into this more than once. this code is written to be called into only one time beyond the first. ns_config->num_natural_vars = W.num_natural_variables(); ns_config->ambient_dim = ambient_dim; ns_config->target_projection = (vec_mp *) br_malloc(ns_config->num_projections * sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_projections; ii++) { init_vec_mp2(ns_config->target_projection[ii], W.num_variables(),solve_options.T.AMP_max_prec); ns_config->target_projection[ii]->size = W.num_variables(); vec_cp_mp(ns_config->target_projection[ii], pi[ii]); } ns_config->num_jac_equations = (ns_config->num_natural_vars - 1);// N-1; the subtraction of 1 is for the 1 hom-var. // me must omit any previously added synthetic vars. ns_config->num_additional_linears = ambient_dim-1; ns_config->num_v_linears = ns_config->num_jac_equations; // this check is correct. int check_num_func = randomizer->num_rand_funcs() + ns_config->num_jac_equations + ns_config->num_additional_linears + W.num_patches() + 1; // +1 for v patch from this incoming computation int check_num_vars = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars; if (check_num_func != check_num_vars) { std::cout << color::red(); std::cout << "mismatch in number of equations...\n" << std::endl; std::cout << "left: " << check_num_func << " right " << check_num_vars << std::endl; std::cout << color::console_default(); throw std::logic_error("logic error in nullspace_left"); } // set up the linears in $v$ ( the M_i linears) ns_config->v_linears = (vec_mp *)br_malloc(ns_config->num_v_linears*sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_v_linears; ii++) { init_vec_mp2(ns_config->v_linears[ii],ns_config->num_v_vars,solve_options.T.AMP_max_prec); ns_config->v_linears[ii]->size = ns_config->num_v_vars; for (int jj=0; jj<ns_config->num_v_vars; jj++){ get_comp_rand_mp(&ns_config->v_linears[ii]->coord[jj]); // should this be real? no. } } // the last of the linears will be used for the slicing, and passed on to later routines int offset = 1; ns_config->additional_linears_terminal = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp)); ns_config->additional_linears_starting = (vec_mp *)br_malloc((ns_config->num_additional_linears)*sizeof(vec_mp)); for (int ii=0; ii<ns_config->num_additional_linears; ii++) { init_vec_mp2(ns_config->additional_linears_terminal[ii],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->additional_linears_terminal[ii]->size = W.num_variables(); for (int jj=0; jj<W.num_natural_variables(); jj++){ get_comp_rand_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); // should this be real? no. } for (int jj=W.num_natural_variables(); jj<W.num_variables(); jj++) { set_zero_mp(&ns_config->additional_linears_terminal[ii]->coord[jj]); } init_vec_mp2(ns_config->additional_linears_starting[ii],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->additional_linears_starting[ii]->size = W.num_variables(); vec_cp_mp(ns_config->additional_linears_starting[ii], W.linear(ii+offset)); } // set up the patch in $v$. we will include this in an inversion matrix to get the starting $v$ values. init_vec_mp2(ns_config->v_patch,ns_config->num_v_vars,solve_options.T.AMP_max_prec); ns_config->v_patch->size = ns_config->num_v_vars; for (int ii=0; ii<ns_config->num_v_vars; ii++) { get_comp_rand_mp(&ns_config->v_patch->coord[ii]); } mat_mp temp_getter; init_mat_mp2(temp_getter,0, 0,solve_options.T.AMP_max_prec); temp_getter->rows = 0; temp_getter->cols = 0; //the 'ns_config->starting_linears' will be used for the x variables. we will homotope to these 1 at a time ns_config->starting_linears = (vec_mp **)br_malloc( randomizer->num_rand_funcs()*sizeof(vec_mp *)); for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) { int curr_degree = std::max(0,randomizer->randomized_degree(ii)-1); ns_config->starting_linears[ii] = (vec_mp *) br_malloc(curr_degree*sizeof(vec_mp)); make_matrix_random_mp(temp_getter,curr_degree, W.num_natural_variables(), solve_options.T.AMP_max_prec); // this matrix is nearly orthogonal for (unsigned int jj=0; jj<curr_degree; jj++) { init_vec_mp2(ns_config->starting_linears[ii][jj],W.num_variables(),solve_options.T.AMP_max_prec); ns_config->starting_linears[ii][jj]->size = W.num_variables(); for (int kk=0; kk<W.num_natural_variables(); kk++) { set_mp(&ns_config->starting_linears[ii][jj]->coord[kk], &temp_getter->entry[jj][kk]); } for (int kk=W.num_natural_variables(); kk<W.num_variables(); kk++) { set_zero_mp(&ns_config->starting_linears[ii][jj]->coord[kk]); } } } clear_mat_mp(temp_getter); return; }
int compute_crit_nullspace_right(SolverOutput & solve_out, // the returned value const WitnessSet & W, std::shared_ptr<SystemRandomizer> randomizer, vec_mp *pi, // an array of projections, the number of which is the target dimensions int ambient_dim, BertiniRealConfig & program_options, SolverConfiguration & solve_options, NullspaceConfiguration *ns_config) { //many of the 1's here should be replaced by the number of patch equations, or the number of variable_groups // get the max degree of the derivative functions. this is unique to the left nullspace formulation, as the functions become mixed together int max_degree; nullspace_config_setup_right(ns_config, pi, ambient_dim, &max_degree, randomizer, W, solve_options); if (max_degree==0) { // this will probably need tweaking when the dimension is higher than 1. but who really is going to decompose a linear surface? solve_out.copy_patches(W); ns_concluding_modifications(solve_out, W, ns_config); std::cout << "the highest degree of any derivative equation is 0. Returning empty SolverOutput." << std::endl; //then there cannot possibly be any critical points, with respect to ANY projection. simply return an empty but complete set. return 0; } // /// ///// end setup //////// ////////////// /////////////////////////// int offset; WitnessSet Wtemp, Wtemp2; // 2. Do a bunch of homotopies in $x$, each set of which will be followed by a single linear solve in $v$. if (program_options.verbose_level()>=3) { std::cout << "building up linprod start system for left nullspace" << std::endl; } // setup for the multilin moves // these are for feeding into the multilin solver -- and that's it. the majority will be overridden in the while loop as the start x linears vec_mp *multilin_linears = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp)); // target dim is the number of linears in the input witness set for (unsigned int ii=0; ii<W.num_linears(); ii++) { init_vec_mp2(multilin_linears[ii],W.num_variables(), solve_options.T.AMP_max_prec); multilin_linears[ii]->size = W.num_variables(); vec_cp_mp(multilin_linears[ii], W.linear(ii)); } MultilinConfiguration ml_config(solve_options,randomizer); // this is for performing the matrix inversion to get ahold of the $v$ values corresponding to $x$ mat_mp tempmat; init_mat_mp2(tempmat, ns_config->num_v_vars, ns_config->num_v_vars,solve_options.T.AMP_max_prec); tempmat->rows = tempmat->cols = ns_config->num_v_vars; offset = ns_config->num_v_vars-1; for (int jj=0; jj<ns_config->num_v_vars; jj++) set_mp(&tempmat->entry[offset][jj], &ns_config->v_patch->coord[jj]); // for holding the result of the matrix inversion vec_mp result; init_vec_mp2(result,ns_config->num_v_vars,solve_options.T.AMP_max_prec); result->size = ns_config->num_v_vars; // use this for the matrix inversion vec_mp invert_wrt_me; init_vec_mp2(invert_wrt_me,ns_config->num_v_vars,solve_options.T.AMP_max_prec); invert_wrt_me->size = ns_config->num_v_vars; for (int ii=0; ii<ns_config->num_v_vars-1; ii++) set_zero_mp(&invert_wrt_me->coord[ii]); // set zero set_one_mp(&invert_wrt_me->coord[ns_config->num_v_vars-1]); // the last entry is set to 1 for the patch equation vec_mp temppoint; init_vec_mp2(temppoint, ns_config->num_natural_vars +ns_config->num_synth_vars + ns_config->num_v_vars,solve_options.T.AMP_max_prec); temppoint->size = ns_config->num_natural_vars + ns_config->num_synth_vars + ns_config->num_v_vars; WitnessSet W_step_one; W_step_one.set_num_variables(W.num_variables()); W_step_one.set_num_natural_variables(W.num_natural_variables()); W_step_one.copy_patches(W); W_step_one.copy_names(W); WitnessSet W_linprod; W_linprod.set_num_variables(ns_config->num_natural_vars + ns_config->num_v_vars + ns_config->num_synth_vars); W_linprod.set_num_natural_variables(W.num_natural_variables()); if (program_options.quick_run()<=1) solve_options.robust = true; else solve_options.robust = false; for (int ii=0; ii<randomizer->num_rand_funcs(); ii++) { int differentiated_degree = randomizer->randomized_degree(ii)-1; // the -1 is for differentiating. this could be 0. if (differentiated_degree==0) { continue; } else{ for (int jj=0; jj<differentiated_degree; jj++) { //copy in the linear for the solve vec_cp_mp(multilin_linears[0], ns_config->starting_linears[ii][jj]); // the remainder of the linears are left alone (stay stationary). if (program_options.verbose_level()>=6) { std::cout << "moving FROM this set:\n"; for (unsigned int ii=0; ii<W.num_linears(); ii++) { print_point_to_screen_matlab(W.linear(ii),"L"); } std::cout << "\nTO this set:\n"; for (unsigned int ii=0; ii<W.num_linears(); ii++) { print_point_to_screen_matlab(multilin_linears[ii],"ELL"); } } // actually solve WRT the linears SolverOutput fillme; multilin_solver_master_entry_point(W, // WitnessSet fillme, // the new data is put here! multilin_linears, ml_config, solve_options); WitnessSet Wtemp; fillme.get_noninfinite_w_mult_full(Wtemp); // should be ordered W_step_one.merge(Wtemp, &solve_options.T); Wtemp.reset(); } int curr_index = 0; for (int kk=0; kk<ns_config->num_v_vars; kk++) { // subtract one from upper limit because of the patch equation if (kk!=ii) { for (int mm=0; mm<ns_config->num_v_vars; mm++){ set_mp(&tempmat->entry[curr_index][mm], &ns_config->v_linears[kk]->coord[mm]);} curr_index++; } } // invert the matrix for the v variables. matrixSolve_mp(result, tempmat, invert_wrt_me); //set the bottom part of the temppoint, which will be a startpoint for the nullspace call later. offset = ns_config->num_natural_vars+ns_config->num_synth_vars; for (int mm=0; mm<ns_config->num_v_vars; mm++) set_mp(&temppoint->coord[mm+offset], &result->coord[mm]); //set the top part, x, of the start point, and copy it in. for (unsigned int kk=0; kk<W_step_one.num_points(); kk++) { for (int mm=0; mm<ns_config->num_natural_vars+ns_config->num_synth_vars; mm++) { set_mp(&temppoint->coord[mm], & W_step_one.point(kk)->coord[mm]); } W_linprod.add_point(temppoint); } W_step_one.reset(); W_step_one.set_num_variables(W.num_variables()); W_step_one.set_num_natural_variables(W.num_natural_variables()); W_step_one.copy_patches(W); // necessary? W_step_one.copy_names(W); // necessary? } } for (int ii=0; ii<1; ii++) clear_vec_mp(multilin_linears[ii]); free(multilin_linears); clear_vec_mp(temppoint); int num_before = W_linprod.num_points(); W_linprod.sort_for_unique(&solve_options.T); if (num_before - W_linprod.num_points()>0) { std::cout << "there were non-unique start points" << std::endl; mypause(); } W_linprod.set_num_natural_variables(ns_config->num_v_vars+ns_config->num_synth_vars); W_linprod.copy_patches(W); W_linprod.copy_names(W); //set some solver options if (program_options.quick_run()<=0) solve_options.robust = true; else solve_options.robust = false; solve_options.use_midpoint_checker = 0; if (program_options.verbose_level()>=6) ns_config->print(); if (program_options.verbose_level()>=3) { std::cout << "running nullspace right method" << std::endl; } nullspacejac_solver_master_entry_point(solve_options.T.MPType, W_linprod, // carries with it the start points, but not the linears. solve_out, // the created data goes in here. ns_config, solve_options); ns_concluding_modifications(solve_out, W, ns_config); clear_mat_mp(tempmat); clear_vec_mp(invert_wrt_me); clear_vec_mp(result); return SUCCESSFUL; }
int sphere_eval_data_mp::setup(SphereConfiguration & config, const WitnessSet & W, SolverConfiguration & solve_options) { if (config.randomizer().use_count()==0) { std::cout << "don't have randomizer set up!" << std::endl; br_exit(-97621); } if (!config.have_mem) { std::cout << "don't have memory!" << std::endl; br_exit(-3231); } this->SLP_memory = config.SLP_memory; num_natural_vars = W.num_natural_variables(); num_variables = W.num_variables(); // set up the vectors to hold the linears. if (this->num_static_linears==0) { static_linear = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp)); } else { static_linear = (vec_mp *) br_realloc(static_linear, W.num_linears()*sizeof(vec_mp)); } for (unsigned int ii=0; ii<W.num_linears(); ii++) { init_vec_mp(static_linear[ii],0); vec_cp_mp(static_linear[ii],W.linear(ii)); } set_mp(this->radius, config.radius); vec_cp_mp(this->center, config.center); if (this->center->size < W.num_variables()) { int old_size = this->center->size; increase_size_vec_mp(this->center, W.num_variables()); this->center->size = W.num_variables(); for (int ii=old_size; ii<W.num_variables(); ii++) { set_zero_mp(&this->center->coord[ii]); } } if (this->MPType==2) { set_mp(this->radius_full_prec, config.radius); vec_cp_mp(this->center_full_prec, config.center); if (this->center_full_prec->size < W.num_variables()) { int old_size = this->center_full_prec->size; increase_size_vec_mp(this->center_full_prec, W.num_variables()); this->center_full_prec->size = W.num_variables(); for (int ii=old_size; ii<W.num_variables(); ii++) { set_zero_mp(&this->center_full_prec->coord[ii]); } } if (this->num_static_linears==0) { static_linear_full_prec = (vec_mp *) br_malloc(W.num_linears()*sizeof(vec_mp)); } else { static_linear_full_prec = (vec_mp *) br_realloc(static_linear_full_prec, W.num_linears()*sizeof(vec_mp)); } for (unsigned int ii=0; ii<W.num_linears(); ii++) { init_vec_mp2(static_linear_full_prec[ii],0,1024); vec_cp_mp(static_linear_full_prec[ii], W.linear(ii)); } } this->num_static_linears = W.num_linears(); for (int ii=0; ii<2; ii++) { vec_cp_mp( this->starting_linear[ii], config.starting_linear[ii]); if (MPType==2) { vec_cp_mp(this->starting_linear_full_prec[ii], config.starting_linear[ii]); } } // the usual verbose_level(solve_options.verbose_level()); SolverMultiplePrecision::setup(config.SLP, config.randomizer()); generic_setup_patch(&patch,W); if (solve_options.use_gamma_trick==1) get_comp_rand_mp(this->gamma); // set gamma to be random complex value else{ set_one_mp(this->gamma); } comp_d temp; if (this->MPType==2) { if (solve_options.use_gamma_trick==1){ get_comp_rand_rat(temp, this->gamma, this->gamma_rat, 64, solve_options.T.AMP_max_prec, 0, 0); } else{ set_one_mp(this->gamma); set_one_rat(this->gamma_rat); } } return 0; }
int sphere_dehom(point_d out_d, point_mp out_mp, int *out_prec, point_d in_d, point_mp in_mp, int in_prec, void const *ED_d, void const *ED_mp) { sphere_eval_data_d *BED_d = NULL; sphere_eval_data_mp *BED_mp = NULL; *out_prec = in_prec; if (in_prec < 64) { // compute out_d sphere_eval_data_d *BED_d = (sphere_eval_data_d *)ED_d; comp_d denom; change_size_vec_d(out_d,in_d->size-1); out_d->size = in_d->size-1; set_d(denom, &in_d->coord[0]); for (int ii=0; ii<BED_d->num_variables-1; ++ii) { set_d(&out_d->coord[ii],&in_d->coord[ii+1]); div_d(&out_d->coord[ii],&out_d->coord[ii],denom); // result[ii] = dehom_me[ii+1]/dehom_me[0]. } // print_point_to_screen_matlab(in_d,"in"); // print_point_to_screen_matlab(out_d,"out"); } else { // compute out_mp sphere_eval_data_mp *BED_mp = (sphere_eval_data_mp *)ED_mp; setprec_point_mp(out_mp, *out_prec); comp_mp denom; init_mp(denom); change_size_vec_mp(out_mp,in_mp->size-1); out_mp->size = in_mp->size-1; set_mp(denom, &in_mp->coord[0]); for (int ii=0; ii<BED_mp->num_variables-1; ++ii) { set_mp(&out_mp->coord[ii],&in_mp->coord[ii+1]); div_mp(&out_mp->coord[ii],&out_mp->coord[ii],denom); // result[ii] = dehom_me[ii+1]/dehom_me[0]. } clear_mp(denom); // set prec on out_mp // print_point_to_screen_matlab(in_mp,"in"); // print_point_to_screen_matlab(out_mp,"out"); } BED_d = NULL; BED_mp = NULL; return 0; }
int sphere_eval_data_mp::receive(ParallelismConfig & mpi_config) { int *buffer = new int[2]; MPI_Bcast(buffer, 1, MPI_INT, mpi_config.head(), mpi_config.comm()); if (buffer[0] != SPHERE_SOLVER) { std::cout << "worker failed to confirm it is receiving the SPHERE_SOLVER type eval data" << std::endl; mpi_config.abort(777); } SolverMultiplePrecision::receive(mpi_config); // now can actually receive the data from whoever. MPI_Bcast(buffer, 2, MPI_INT, mpi_config.head(), mpi_config.comm()); num_natural_vars = buffer[0]; num_static_linears = buffer[1]; delete[] buffer; //starting linears already created and initted static_linear = (vec_mp *) br_malloc(num_static_linears*sizeof(vec_mp)); if (this->MPType==2) { static_linear_full_prec = (vec_mp *) br_malloc(num_static_linears*sizeof(vec_mp)); for (int ii=0; ii<num_static_linears; ii++) { init_vec_mp(static_linear[ii],1); init_vec_mp2(static_linear_full_prec[ii],1,1024); bcast_vec_mp(static_linear_full_prec[ii], mpi_config.id(), mpi_config.head()); vec_cp_mp(static_linear[ii],static_linear_full_prec[ii]); } for (int ii=0; ii<2; ii++) { bcast_vec_mp(starting_linear_full_prec[ii], mpi_config.id(), mpi_config.head()); vec_cp_mp(starting_linear[ii],starting_linear_full_prec[ii]); } bcast_vec_mp(center_full_prec, mpi_config.id(), mpi_config.head()); bcast_comp_mp(radius_full_prec, mpi_config.id(), mpi_config.head()); vec_cp_mp(center, center_full_prec); set_mp(radius, radius_full_prec); } else{ // MPType == 1 for (int ii=0; ii<num_static_linears; ii++) { init_vec_mp(static_linear[ii],1); bcast_vec_mp(static_linear[ii], mpi_config.id(), mpi_config.head()); } for (int ii=0; ii<2; ii++) { bcast_vec_mp(starting_linear[ii], mpi_config.id(), mpi_config.head()); } bcast_vec_mp(center, mpi_config.id(), mpi_config.head()); bcast_comp_mp(radius, mpi_config.id(), mpi_config.head()); } return SUCCESSFUL; }
//this derived from basic_eval_d int sphere_eval_mp(point_mp funcVals, point_mp parVals, vec_mp parDer, mat_mp Jv, mat_mp Jp, point_mp current_variable_values, comp_mp pathVars, void const *ED) { // evaluates a special homotopy type, built for bertini_real // print_comp_mp_matlab(pathVars,"pathvars"); sphere_eval_data_mp *BED = (sphere_eval_data_mp *)ED; // to avoid having to cast every time BED->SLP_memory.set_globals_to_this(); int ii, jj, mm; // counters int offset; comp_mp one_minus_s, gamma_s; comp_mp temp, temp2; comp_mp func_val_sphere, func_val_start; init_mp(one_minus_s); init_mp(gamma_s); init_mp(temp); init_mp(temp2); init_mp(func_val_start); init_mp(func_val_sphere); set_one_mp(one_minus_s); sub_mp(one_minus_s, one_minus_s, pathVars); // one_minus_s = (1 - s) mul_mp(gamma_s, BED->gamma, pathVars); // gamma_s = gamma * s vec_mp patchValues; init_vec_mp(patchValues, 0); vec_mp temp_function_values; init_vec_mp(temp_function_values,0); vec_mp AtimesF; init_vec_mp(AtimesF,BED->randomizer()->num_rand_funcs()); AtimesF->size = BED->randomizer()->num_rand_funcs();// declare // initialize mat_mp temp_jacobian_functions; init_mat_mp(temp_jacobian_functions,BED->randomizer()->num_base_funcs(),BED->num_variables); temp_jacobian_functions->rows = BED->randomizer()->num_base_funcs(); temp_jacobian_functions->cols = BED->num_variables; mat_mp temp_jacobian_parameters; init_mat_mp(temp_jacobian_parameters,0,0); mat_mp Jv_Patch; init_mat_mp(Jv_Patch, 0, 0); mat_mp AtimesJ; init_mat_mp(AtimesJ,BED->randomizer()->num_rand_funcs(),BED->num_variables); AtimesJ->rows = BED->randomizer()->num_rand_funcs(); AtimesJ->cols = BED->num_variables; //set the sizes change_size_vec_mp(funcVals,BED->num_variables); funcVals->size = BED->num_variables; change_size_mat_mp(Jv, BED->num_variables, BED->num_variables); Jv->rows = Jv->cols = BED->num_variables; // -> this should be square!!! for (ii=0; ii<BED->num_variables; ii++) for (jj=0; jj<BED->num_variables; jj++) set_zero_mp(&Jv->entry[ii][jj]); // evaluate the SLP to get the system's whatnot. evalProg_mp(temp_function_values, parVals, parDer, temp_jacobian_functions, temp_jacobian_parameters, current_variable_values, pathVars, BED->SLP); // evaluate the patch patch_eval_mp(patchValues, parVals, parDer, Jv_Patch, Jp, current_variable_values, pathVars, &BED->patch); // Jp is ignored // we assume that the only parameter is s = t and setup parVals & parDer accordingly. // note that you can only really do this AFTER you are done calling other evaluators. // set parVals & parDer correctly // i.e. these must remain here, or below. \/ change_size_point_mp(parVals, 1); change_size_vec_mp(parDer, 1); change_size_mat_mp(Jp, BED->num_variables, 1); Jp->rows = BED->num_variables; Jp->cols = 1; for (ii=0; ii<BED->num_variables; ii++) set_zero_mp(&Jp->entry[ii][0]); parVals->size = parDer->size = 1; set_mp(&parVals->coord[0], pathVars); // s = t set_one_mp(&parDer->coord[0]); // ds/dt = 1 /////////////////////////// // // the original (randomized) functions. // /////////////////////////////////// BED->randomizer()->randomize(AtimesF,AtimesJ,temp_function_values,temp_jacobian_functions,¤t_variable_values->coord[0]); for (ii=0; ii<AtimesF->size; ii++) // for each function, after (real orthogonal) randomization set_mp(&funcVals->coord[ii], &AtimesF->coord[ii]); for (ii = 0; ii < BED->randomizer()->num_rand_funcs(); ii++) for (jj = 0; jj < BED->num_variables; jj++) set_mp(&Jv->entry[ii][jj],&AtimesJ->entry[ii][jj]); //Jp is 0 for the equations. /////////////////// // // the sphere equation. // ////////////////////////// offset = BED->randomizer()->num_rand_funcs(); mul_mp(func_val_sphere, BED->radius, BED->radius); neg_mp(func_val_sphere, func_val_sphere); mul_mp(func_val_sphere, func_val_sphere, ¤t_variable_values->coord[0]); mul_mp(func_val_sphere, func_val_sphere, ¤t_variable_values->coord[0]); //f_sph = -r^2*h^2 for (int ii=1; ii<BED->num_natural_vars; ii++) { mul_mp(temp2, &BED->center->coord[ii-1], ¤t_variable_values->coord[0]); // temp2 = c_{i-1}*h sub_mp(temp, ¤t_variable_values->coord[ii], temp2); // temp = x_i - h*c_{i-1} mul_mp(temp2, temp, temp); // temp2 = (x_i - h*c_{i-1})^2 add_mp(func_val_sphere, func_val_sphere, temp2); // f_sph += (x_i - h*c_{i-1})^2 } set_one_mp(func_val_start); for (mm=0; mm<2; ++mm) { dot_product_mp(temp, BED->starting_linear[mm], current_variable_values); mul_mp(func_val_start, func_val_start, temp); //f_start *= L_i (x) } // combine the function values mul_mp(temp, one_minus_s, func_val_sphere); mul_mp(temp2, gamma_s, func_val_start); add_mp(&funcVals->coord[offset], temp, temp2); // f = (1-t) f_sph + gamma t f_start //// / / / / / / now the derivatives wrt x // first we store the derivatives of the target function, the sphere. then we will add the part for the linear product start. //ddx for sphere for (int ii=1; ii<BED->num_natural_vars; ii++) { mul_mp(temp2, &BED->center->coord[ii-1], ¤t_variable_values->coord[0]); // temp2 = c_{i-1}*h sub_mp(temp, ¤t_variable_values->coord[ii], temp2) // temp = x_i - c_{i-1}*h mul_mp(&Jv->entry[offset][ii], BED->two, temp); // Jv = 2*(x_i - c_{i-1}*h) mul_mp(&Jv->entry[offset][ii], &Jv->entry[offset][ii], one_minus_s); // Jv = (1-t)*2*(x_i - c_{i-1}*h) mul_mp(temp2, &BED->center->coord[ii-1], temp); // temp2 = c_{i-1} * ( x_i - c_{i-1} * h ) add_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], temp2); // Jv[0] += c_{i-1} * ( x_i - c_{i-1} * h ) } // multiply these entries by (1-t) // the homogenizing var deriv mul_mp(temp, ¤t_variable_values->coord[0], BED->radius); mul_mp(temp, temp, BED->radius); // temp = r^2 h add_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], temp); // Jv[0] = \sum_{i=1}^n {c_{i-1} * ( x_i - c_{i-1} * h )} + r^2 h neg_mp(&Jv->entry[offset][0], &Jv->entry[offset][0]); // Jv[0] = -Jv[0] mul_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], BED->two); // Jv[0] *= 2 mul_mp(&Jv->entry[offset][0], &Jv->entry[offset][0], one_minus_s); // Jv[0] *= (1-t) // f = \sum{ ( x_i - c_{i-1} * h )^2 } - r^2 h^2 //Jv = -2(1-t) ( \sum_{i=1}^n { c_{i-1} * ( x_i - c_{i-1} * h ) } + r^2 h ) // a hardcoded product rule for the two linears. for (int ii=0; ii<BED->num_variables; ii++) { dot_product_mp(temp, BED->starting_linear[0], current_variable_values); mul_mp(temp, temp, &BED->starting_linear[1]->coord[ii]); dot_product_mp(temp2, BED->starting_linear[1], current_variable_values); mul_mp(temp2, temp2, &BED->starting_linear[0]->coord[ii]); add_mp(temp, temp, temp2); mul_mp(temp2, temp, gamma_s); //temp2 = gamma s * (L_1(x) * L_0[ii] + L_0(x) * L_1[ii]) //temp2 now has the value of the derivative of the start system wrt x_i add_mp(&Jv->entry[offset][ii], &Jv->entry[offset][ii], temp2); } // finally, the Jp entry for sphere equation's homotopy. //Jp = -f_sph + gamma f_start neg_mp(&Jp->entry[offset][0], func_val_sphere); mul_mp(temp, BED->gamma, func_val_start); add_mp(&Jp->entry[offset][0], &Jp->entry[offset][0], temp); ////////////// // // function values for the static linears // //////////////////// offset++; for (mm=0; mm<BED->num_static_linears; ++mm) { dot_product_mp(&funcVals->coord[mm+offset], BED->static_linear[mm], current_variable_values); } for (mm=0; mm<BED->num_static_linears; ++mm) { for (ii=0; ii<BED->num_variables; ii++) { set_mp(&Jv->entry[offset+mm][ii], &BED->static_linear[mm]->coord[ii]); } } //Jp is 0 for the static linears ////////////// // // the entries for the patch equations. // //////////////////// if (offset+BED->num_static_linears != BED->num_variables-BED->patch.num_patches) { std::cout << color::red() << "mismatch in offset!\nleft: " << offset+BED->num_static_linears << " right " << BED->num_variables-BED->patch.num_patches << color::console_default() << std::endl; mypause(); } offset = BED->num_variables-BED->patch.num_patches; for (ii=0; ii<BED->patch.num_patches; ii++) set_mp(&funcVals->coord[ii+offset], &patchValues->coord[ii]); for (ii = 0; ii<BED->patch.num_patches; ii++) // for each patch equation { // Jv = Jv_Patch for (jj = 0; jj<BED->num_variables; jj++) // for each variable set_mp(&Jv->entry[ii+offset][jj], &Jv_Patch->entry[ii][jj]); } //Jp is 0 for the patch. // done! yay! if (BED->verbose_level()==16 || BED->verbose_level()==-16) { //uncomment to see screen output of important variables at each solve step. print_comp_matlab(pathVars, "t_mp"); print_comp_matlab(BED->gamma, "gamma_mp"); print_point_to_screen_matlab(current_variable_values,"currvars_mp"); print_point_to_screen_matlab(funcVals,"F_mp"); print_matrix_to_screen_matlab(Jv,"Jv_mp"); print_matrix_to_screen_matlab(Jp,"Jp_mp"); } BED->SLP_memory.set_globals_null(); clear_mp(temp); clear_mp(temp2); clear_mp(gamma_s); clear_mp(one_minus_s); clear_mp(func_val_sphere); clear_mp(func_val_start); clear_vec_mp(patchValues); clear_vec_mp(temp_function_values); clear_vec_mp(AtimesF); clear_mat_mp(temp_jacobian_functions); clear_mat_mp(temp_jacobian_parameters); clear_mat_mp(Jv_Patch); clear_mat_mp(AtimesJ); return 0; }
/** \brief set the projection value of the left critical edge \param new_left_crit_val the new value of the projection for left edge */ void set_left_crit_val(comp_mp new_left_crit_val) { set_mp(left_crit_val_,new_left_crit_val); }
/** \brief set the projection value of the right critical edge \param new_right_crit_val the new value of the projection for right edge */ void set_right_crit_val(comp_mp new_right_crit_val) { set_mp(right_crit_val_,new_right_crit_val); }