示例#1
0
文件: P.cpp 项目: lwhay/ICDMS
void P::factor() {
	returnAST = RefBasicAST(ANTLR_USE_NAMESPACE(antlr)nullAST);
	ANTLR_USE_NAMESPACE(antlr)ASTPair currentAST;
	RefBasicAST factor_AST = RefBasicAST(ANTLR_USE_NAMESPACE(antlr)nullAST);
	
	try {      // for error handling
		factor2();
		astFactory->addASTChild(currentAST, ANTLR_USE_NAMESPACE(antlr)RefAST(returnAST));
		{ // ( ... )*
		for (;;) {
			if ((LA(1) == MOD || LA(1) == EXP)) {
				{
				switch ( LA(1)) {
				case EXP:
				{
					RefBinaryCompArithOpAST tmp11_AST = RefBinaryCompArithOpAST(RefBasicAST(ANTLR_USE_NAMESPACE(antlr)nullAST));
					tmp11_AST = astFactory->create(LT(1));
					astFactory->makeASTRoot(currentAST, ANTLR_USE_NAMESPACE(antlr)RefAST(tmp11_AST));
					match(EXP);
					break;
				}
				case MOD:
				{
					RefBinaryCompArithOpAST tmp12_AST = RefBinaryCompArithOpAST(RefBasicAST(ANTLR_USE_NAMESPACE(antlr)nullAST));
					tmp12_AST = astFactory->create(LT(1));
					astFactory->makeASTRoot(currentAST, ANTLR_USE_NAMESPACE(antlr)RefAST(tmp12_AST));
					match(MOD);
					break;
				}
				default:
				{
					throw ANTLR_USE_NAMESPACE(antlr)NoViableAltException(LT(1), getFilename());
				}
				}
				}
				factor2();
				astFactory->addASTChild(currentAST, ANTLR_USE_NAMESPACE(antlr)RefAST(returnAST));
			}
			else {
				goto _loop14;
			}
			
		}
		_loop14:;
		} // ( ... )*
		factor_AST = RefBasicAST(currentAST.root);
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		reportError(ex);
		recover(ex,_tokenSet_3);
	}
	returnAST = factor_AST;
}
void sLinsys::factor(Data *prob_, Variables *vars)
{
#ifdef TIMING
  double tTot=MPI_Wtime();
#endif
  // the call to the the parent's method takes care of all necessary updates
  // to the KKT system (updating diagonals mainly). This is done reccursevely,
  // we don't have to worry about it anymore. 
  NlpGenLinsys::factorNoMatChange(prob_, vars, NULL);

  // now DO THE LINEAR ALGEBRA!
  
  sData* prob = dynamic_cast<sData*>(prob_);
  // in order to avoid a call to NlpGenLinsys::factor, call factor2 method.
  factor2(prob, vars);

#ifdef TIMING
  tTot = MPI_Wtime()-tTot;
  MPI_Barrier(MPI_COMM_WORLD);
  int myRank; MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
  //if(128*(myRank/128)==0)
  if(0==myRank)
      cout << "Outer fact. total time " << tTot << endl;
#endif
}
/**
 * \brief main function for the convolve program
 */
int	main(int argc, char *argv[]) {
	// parse command line
	int	c;
	int	longindex;
	while (EOF != (c = getopt_long(argc, argv, "dh?",
		longopts, &longindex)))
		switch (c) {
		case 'd':
			debuglevel = LOG_DEBUG;
			break;
		case 'h':
		case '?':
			usage(argv[0]);
			return EXIT_SUCCESS;
		default:
			throw std::runtime_error("unknown option");
		}

	// next two arguments must be filenames
	if ((argc - optind) != 3) {
		std::cerr << "need exactly three file name arguments"
			<< std::endl;
		return EXIT_FAILURE;
	}
	const char	*in1filename = argv[optind++];
	const char	*in2filename = argv[optind++];
	const char	*outfilename = argv[optind++];

	// read the image from the file
	FITSin	in1file(in1filename);
	ImagePtr	image1 = in1file.read();
	Image<double>	*img1 = dynamic_cast<Image<double> *>(&*image1);
	if (NULL == img1) {
		debug(LOG_ERR, DEBUG_LOG, 0, "can only convolve double images");
	}
	ConvolutionResult	factor1(*img1, ImagePoint(0, 0));

	FITSin	in2file(in2filename);
	ImagePtr	image2 = in2file.read();
	Image<double>	*img2 = dynamic_cast<Image<double> *>(&*image2);
	if (NULL == img2) {
		debug(LOG_ERR, DEBUG_LOG, 0, "can only convolve double images");
	}
	ConvolutionResult	factor2(*img2, ImagePoint(0, 0));

	// compute the convolution
	ConvolutionResultPtr	result = factor1 * factor2;

	// write the result image
	FITSout	outfile(outfilename);
	outfile.setPrecious(false);
	outfile.write(result->image());

	// that's it
	return EXIT_SUCCESS;
}
示例#4
0
/*
 calculate the scaliung factor to pull spectra to measurement
 */
double spectrum_generator_cpu::get_factor_to_scale_spectra_to_measurement(){
    //weighted squared errors
    std::vector<double> factor1(this->mes_nspecsteps);
    std::vector<double> factor2(this->mes_nspecsteps);
    
    //loop over wavelenghts
    for( int wave=0 ; wave<this->mes_nspecsteps;wave++){
        //counting the factor with err
        if ( this->mes_spec_mask[wave] == 0 && this->mes_spec_err[wave]!=0  ){
            factor1[wave]= (this->mes_spec[wave] * this->result[wave])  / (this->mes_spec_err[wave] * this->mes_spec_err[wave] );
            factor2[wave]= (this->result[wave] * this->result[wave] ) / (this->mes_spec_err[wave] * this->mes_spec_err[wave]);
        }
        else { //problems in mes
            factor1[wave]=0;
            factor2[wave]=0;
        }
    }
    
    //temp1, temp2 are sums of vectors factor1,factor2
    //they are use to calculate the "factor" that pulls together observed
    //and model spectra
    double temp_1,temp_2,scale_factor;
    
    //get factors
    
    //summing factors, to pull spectra together
    //summing is sequential on CPU paralell summing would an overkill for 3-4000 numbers i guess
    temp_1=0;
    temp_2=0;
    for(int i=0;i<this->mes_nspecsteps;i++){
        temp_1+=factor1[i];
        temp_2+=factor2[i];
    }
    scale_factor=temp_1/temp_2;
    
    return scale_factor;
}
示例#5
0
int
jacobi(int a, int b)
{
	int a1, a2;

	if (a >= b)			/* 4 */
		a %= b;
	if (a == 0)			/* 0 */
		return 0;
	if (a == 1)			/* 1 */
		return 1;
	if (a == 2)			/* 3 */
		if (((b*b-1) / 8) % 2 == 0)
			return 1;
		else
			return -1;

	/* 5' */
	if (a & b & 1)	/* both a and b are odd */
		if (((a-1)*(b-1)/4) % 2 == 0)
			return +jacobi(b, a);
		else
			return -jacobi(b, a);
	/* 5 */
/* is the if-case correct?  If so remove these comment markers...
	if (gcd(a, b) == 1)
		if (((a-1)*(b-1)/4) % 2 == 0)
			return +jacobi(b, a);
		else
			return -jacobi(b, a);
*/

	/* 2 */
	factor2(a, &a1, &a2);
	return jacobi(a1, b) * jacobi(a2, b);
}
void sLinsys::factor(Data *prob_, Variables *vars_in,RegularizationAlg *RegInfo)
{
  sData* prob = dynamic_cast<sData*>(prob_);
  sVars* vars = dynamic_cast<sVars*>(vars_in);
  
  bool skipUpdateReg=false;
  long long Num_NegEVal=-1;
  double priReg=0.0,dualReg=0.0;

#ifdef TIMING
  double tTot=MPI_Wtime();
#endif
  // DoEvalReg =   1 -> when factorizing the matrix, add regularizations to correct inertia and singularity 
  //				  	(we ONLY calling this routine once in IBR)
  //			  2 -> when factorizing the matrix, add regularizations to correct singularity only 
  //					(this is always the 1st call of this routine when IFR is used)
  //			  0 -> when factorizing the matrix, force to use primal regularizaion. called iff xWx tests fail  
  //					(the other calls of this routine when IFR is used, now matrix is nonsingular for sure)
  if(RegInfo->DoEvalReg >= 1){
  	RegInfo->newLinearSystem();

	if(RegInfo->ForceReg)
	  NlpGenLinsys::factorNoMatChange(prob_, vars, RegInfo);
	else
      NlpGenLinsys::factorNoMatChange(prob_, vars, NULL);	

    // now DO THE LINEAR ALGEBRA!
    // in order to avoid a call to NlpGenLinsys::factor, call factor2 method.
    Num_NegEVal = factor2(prob, vars);

	long long gbMy = prob->getGlobalMy();
	long long gbMz = prob->getGlobalMz();

	// check if matrix is singular
	if(Num_NegEVal < 0 || (Num_NegEVal < gbMy + gbMz && RegInfo->DoEvalReg == 1) )
	  RegInfo->MatrixSingular = 1;
	else
	  RegInfo->MatrixSingular = 0;	

	// skip update regularizaion if: 	1) have correct inertia and mat is nonsingular 
	//						OR 	2) mat is nonsingular and we will do inertia-free test later	
	if( (RegInfo->DoEvalReg==1 && Num_NegEVal == gbMy + gbMz) || (RegInfo->DoEvalReg == 2 && Num_NegEVal != -1)){
	  skipUpdateReg=true;
	}
  }

  // update regularization
  while( !skipUpdateReg ){
	RegInfo->computeRegularization(priReg,dualReg,prob->currMu);
	
    NlpGenLinsys::factorNoMatChange(prob_, vars, RegInfo);
	Num_NegEVal=(long long)factor2(prob, vars);

	// check if matrix is singular
	if(Num_NegEVal < 0)
	  RegInfo->MatrixSingular = 1;
	else
	  RegInfo->MatrixSingular = 0;

	// skip update regularizaion if: 	1) have correct inertia and mat is nonsingular 
	//						OR 	2) mat is nonsingular and we will do inertia-free test later	
	//						OR  	3) we are doing inertia-free test now (mat is defenitly nonsingular)
	if( (RegInfo->DoEvalReg == 1 && Num_NegEVal == prob->getGlobalMy() + prob->getGlobalMz())
		|| (RegInfo->DoEvalReg == 2 && Num_NegEVal != -1) || RegInfo->DoEvalReg == 0 )
	{
	  skipUpdateReg = true;
	}  	  
  }  

#ifdef TIMING
  tTot = MPI_Wtime()-tTot;
  MPI_Barrier(MPI_COMM_WORLD);
  int myRank; MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
  if(0==myRank)
      cout << "Outer fact. total time " << tTot << endl;
#endif
}