Exemplo n.º 1
0
void update_beagle_eigen(t_mod* mod)
{
    assert(UNINITIALIZED != mod->b_inst);

    int whichmodel = mod->whichmodel;
    //We use Eigen Decomposition only for GTR models and AA datasets
    if((mod->io->datatype == AA || whichmodel==GTR || whichmodel==CUSTOM) && mod->use_m4mod == NO)
    {
        //Beagle expects untransformed eigen-values (i.e. recall e_val is EXP() scaled, so we undo that)
        phydbl* evals = (phydbl*)malloc(mod->ns * sizeof(phydbl));
        int i;
        for(i=0;i<mod->ns;++i)  evals[i]=LOG(mod->eigen->e_val[i]);
        int ret=-1;
        if((sizeof(float)==sizeof(phydbl)))//Need to convert to doubles?
        {
            double* eigen_vects     = float_to_double(mod->eigen->r_e_vect, mod->eigen->size*mod->eigen->size);
            double* eigen_vects_inv = float_to_double(mod->eigen->l_e_vect, mod->eigen->size*mod->eigen->size);
            double* eigen_vals      = float_to_double(evals,mod->eigen->size);
            ret = beagleSetEigenDecomposition(mod->b_inst,0,eigen_vects,eigen_vects_inv,eigen_vals);
            Free(eigen_vects);Free(eigen_vects_inv);Free(eigen_vals);
        } else {
            ret = beagleSetEigenDecomposition(mod->b_inst,0,mod->eigen->r_e_vect,mod->eigen->l_e_vect,evals);
        }
        if(ret<0){
          fprintf(stderr, "beagleSetEigenDecomposition() on instance %i failed:%i\n\n",mod->b_inst,ret);
          Free(evals);
          Exit("");
        }
        Free(evals);
    }
}
Exemplo n.º 2
0
unsigned int sw_location(char* hardwareId, float lat, float lon, float ele, int64_t eventDate,
		uint8_t* buffer, size_t length, char* originator) {
	pb_ostream_t stream = pb_ostream_from_buffer(buffer, length);

	SiteWhere_Header header = { };
	header.command = SiteWhere_Command_DEVICELOCATION;
	if (originator != NULL) {
		header.has_originator = true;
		strcpy(header.originator, originator);
	}
	if (!pb_encode_delimited(&stream, SiteWhere_Header_fields, &header)) {
		return 0;
	}

	SiteWhere_DeviceLocation location = { };
	strcpy(location.hardwareId, hardwareId);
	location.latitude = float_to_double(lat);
	location.longitude = float_to_double(lon);
	location.elevation = float_to_double(ele);
	location.has_elevation = true;

	if (eventDate != NULL) {
		location.has_eventDate = true;
		location.eventDate = eventDate;
	}
	if (!pb_encode_delimited(&stream, SiteWhere_DeviceLocation_fields, &location)) {
		return 0;
	}

	return stream.bytes_written;
}
Exemplo n.º 3
0
unsigned int sw_measurement(char* hardwareId, char* name, float value, int64_t eventDate,
		uint8_t* buffer, size_t length, char* originator) {
	pb_ostream_t stream = pb_ostream_from_buffer(buffer, length);

	SiteWhere_Header header = { };
	header.command = SiteWhere_Command_DEVICEMEASUREMENT;
	if (originator != NULL) {
		header.has_originator = true;
		strcpy(header.originator, originator);
	}
	if (!pb_encode_delimited(&stream, SiteWhere_Header_fields, &header)) {
		return 0;
	}

	SiteWhere_DeviceMeasurements measurements = { };
	strcpy(measurements.hardwareId, hardwareId);

	SiteWhere_Measurement measurement = { };
	strcpy(measurement.measurementId, name);
	measurement.measurementValue = float_to_double(value);
	measurements.measurement[0] = measurement;
	measurements.measurement_count = 1;

	if (eventDate != NULL) {
		measurements.has_eventDate = true;
		measurements.eventDate = eventDate;
	}
	if (!pb_encode_delimited(&stream, SiteWhere_DeviceMeasurements_fields, &measurements)) {
		return 0;
	}

	return stream.bytes_written;
}
Exemplo n.º 4
0
double __extendsfdf2(float a)
{
	float_t fa;
	double_t res;
	
	fa.val = a;
	res.data = float_to_double(fa.data);
	
	return res.val;
}
Exemplo n.º 5
0
void update_beagle_ras(t_mod* mod)
{
  assert(UNINITIALIZED != mod->b_inst);
  
  int ret=-1;
  if((sizeof(float)==sizeof(phydbl))) //Do we need to convert?
    {
      double* catg_rates = float_to_double(mod->ras->gamma_rr->v, mod->ras->n_catg);
      ret = beagleSetCategoryRates(mod->b_inst, catg_rates);
      Free(catg_rates);
      if(ret<0){
        fprintf(stderr, "beagleSetCategoryRates() on instance %i failed:%i\n\n",mod->b_inst,ret);
        Exit("");
      }
      double* catg_wts = float_to_double(mod->ras->gamma_r_proba->v, mod->ras->n_catg);
      if(!mod->optimizing_topology) {
        ret = beagleSetCategoryWeights(mod->b_inst, 0, catg_wts);
        Free(catg_wts);
        if(ret<0){
          fprintf(stderr, "beagleSetCategoryWeights() on instance %i failed:%i\n\n",mod->b_inst,ret);
          Exit("");
        }
      }
    }
  else
    {
      ret = beagleSetCategoryRates(mod->b_inst, mod->ras->gamma_rr->v);
      if(ret<0){
        fprintf(stderr, "beagleSetCategoryRates() on instance %i failed:%i\n\n",mod->b_inst,ret);
        Exit("");
      }
      if(!mod->optimizing_topology) {
        ret = beagleSetCategoryWeights(mod->b_inst, 0, mod->ras->gamma_r_proba->v);
        if(ret<0){
          fprintf(stderr, "beagleSetCategoryWeights() on instance %i failed:%i\n\n",mod->b_inst,ret);
          Exit("");
        }
        
      }
    }
}
Exemplo n.º 6
0
void update_beagle_efrqs(t_mod* mod)
{
  assert(UNINITIALIZED != mod->b_inst);
  
  int ret=-1;
  if((sizeof(float)==sizeof(phydbl))) {
    double* efrqs = float_to_double(mod->e_frq->pi->v, mod->ns);
        ret = beagleSetStateFrequencies(mod->b_inst, 0, efrqs);
        Free(efrqs);
  } else {
    ret = beagleSetStateFrequencies(mod->b_inst, 0, mod->e_frq->pi->v);
  }
  if(ret<0){
    fprintf(stderr, "beagleSetStateFrequencies() on instance %i failed:%i\n\n",mod->b_inst,ret);
    Exit("");
  }
}