double __floatsidf(int i) { double_t res; res.data = int_to_double(i); return res.val; }
int create_beagle_instance(t_tree *tree, int quiet, option* io) { if(UNINITIALIZED != tree->b_inst){ // fprintf(stdout,"\n\tWARNING: Creating a BEAGLE instance on a tree with an existing BEAGLE instance:%d\n",tree->b_inst); } if(!quiet){ // print_beagle_resource_list(); } int i; BeagleInstanceDetails inst_d; int num_rate_catg = tree->mod->ras->n_catg; int num_branches = 2*tree->n_otu-1; //rooted tree //Recall that in PhyML, each edge has a "left" and "right" partial vectors. Therefore, //in BEAGLE we have 2*num_branches number of partials. //BEAGLE's partials buffer = [ tax1, tax2, ..., taxN, b1Left, b2Left, b3Left,...,bMLeft, b1Rght, b2Rght, b3Rght,...,bMRght] (N taxa, M branches) int num_partials = 2*(tree->n_otu + num_branches); /* TODO: This does not seem correct; suspect poor indexing elsewhere */ /* In update_operations, indexes range from 0 to almost 2 (n_otu + num_branches), but not all integers are used */ int resourceList[1]; resourceList[0] = io->beagle_resource; // DUMP_I(tree->n_otu, num_rate_catg, num_partials, num_branches, tree->mod->ns, tree->n_pattern, tree->mod->whichmodel); int beagle_inst = beagleCreateInstance( tree->n_otu, /**< Number of tip data elements (input) */ num_partials, /**< Number of partial buffer (input) */ /* PhyML uses partials */ 0, /**< Number of compact state representation buffers to create (input) */ tree->mod->ns, /**< Number of states in the continuous-time Markov chain (input) */ tree->n_pattern, /**< Number of site patterns to be handled by the instance (input) */ 1, /**< Number of rate matrix eigen-decomposition,state freqs, and category weight buffers*/ num_branches, /**< Number of rate matrix buffers (input) */ num_rate_catg, /**< Number of rate categories (input) */ -1, /**< Number of scaling buffers. Unused because we use SCALING_ALWAYS */ resourceList, /**< List of potential resource on which this instance is allowed (input, NULL implies no restriction */ 1, /**< Length of resourceList list (input) */ BEAGLE_FLAG_FRAMEWORK_CPU | BEAGLE_FLAG_PROCESSOR_CPU | BEAGLE_FLAG_SCALING_ALWAYS | BEAGLE_FLAG_EIGEN_REAL | ((sizeof(float)==sizeof(phydbl)) ? BEAGLE_FLAG_PRECISION_SINGLE:BEAGLE_FLAG_PRECISION_DOUBLE), 0, /**< Bit-flags indicating required implementation characteristics, see BeagleFlags (input) */ &inst_d); if (beagle_inst < 0){ fprintf(stderr, "beagleCreateInstance() failed:%i\n\n",beagle_inst); return beagle_inst; } if(!quiet){ fprintf(stdout, "\n\tUnique BEAGLE instance id:%i\n", beagle_inst); print_beagle_instance_details(&inst_d); } //Set the tips for(i=0; i<2*tree->n_otu-1; ++i) //taxa+internal nodes { // Print_Tip_Partials(tree, tree->a_nodes[i]); if(tree->a_nodes[i]->tax) { assert(tree->a_nodes[i]->c_seq->len == tree->n_pattern); // number of compacts sites == number of distinct site patterns double* tip = short_to_double(tree->a_nodes[i]->b[0]->p_lk_tip_r, tree->n_pattern*tree->mod->ns); //The tip states are stored on the branch leading to the tip //Recall we store tip partials on the branch leading to the tip, rather than the tip itself. int ret = beagleSetTipPartials(beagle_inst, tree->a_nodes[i]->b[0]->p_lk_tip_idx, tip); if(ret<0){ fprintf(stderr, "beagleSetTipPartials() on instance %i failed:%i\n\n",beagle_inst,ret); Free(tip); return ret; } Free(tip); } } //Set the pattern weights double* pwts = int_to_double(tree->data->wght,tree->n_pattern); //BTW, These weights are absolute counts, and not freqs int ret = beagleSetPatternWeights(beagle_inst, pwts); if(ret<0){ fprintf(stderr, "beagleSetPatternWeights() on instance %i failed:%i\n\n",beagle_inst,ret); Free(pwts); return ret; } Free(pwts); tree->mod->b_inst=beagle_inst; update_beagle_ras(tree->mod); update_beagle_efrqs(tree->mod); return beagle_inst; }