Example #1
0
int
main(int argc, char *argv[])
{
	char all = 0;
	struct statfs *mp;
	struct fstab *fs;
	int cnt;

	func = douser;
#ifndef	COMPAT
	header = getbsize(&headerlen,&blocksize);
#endif
	while (--argc > 0 && **++argv == '-') {
		while (*++*argv) {
			switch (**argv) {
			case 'n':
				func = donames;
				break;
			case 'c':
				func = dofsizes;
				break;
			case 'a':
				all = 1;
				break;
			case 'f':
				count = 1;
				break;
			case 'h':
				estimate = 1;
				break;
#ifndef	COMPAT
			case 'k':
				blocksize = 1024;
				break;
#endif	/* COMPAT */
			case 'v':
				unused = 1;
				break;
			default:
				usage();
			}
		}
	}
	if (all) {
		cnt = getmntinfo(&mp,MNT_NOWAIT);
		for (; --cnt >= 0; mp++) {
			if (!strncmp(mp->f_fstypename, "ufs", MFSNAMELEN))
				quot(mp->f_mntfromname, mp->f_mntonname);
		}
	}
	while (--argc >= 0) {
		if ((fs = getfsfile(*argv)) != NULL)
			quot(fs->fs_spec, 0);
		else
			quot(*argv,0);
		argv++;
	}
	return 0;
}
Example #2
0
// Compile code in boot image so that we can execute the startup quotation
// Allocates memory
void factor_vm::prepare_boot_image() {
  std::cout << "*** Stage 2 early init... " << std::flush;

  // Compile all words.
  data_root<array> words(instances(WORD_TYPE), this);

  cell n_words = array_capacity(words.untagged());
  for (cell i = 0; i < n_words; i++) {
    data_root<word> word(array_nth(words.untagged(), i), this);

    FACTOR_ASSERT(!word->entry_point);
    jit_compile_word(word.value(), word->def, false);
  }
  update_code_heap_words(true);

  // Initialize all quotations
  data_root<array> quotations(instances(QUOTATION_TYPE), this);

  cell n_quots = array_capacity(quotations.untagged());
  for (cell i = 0; i < n_quots; i++) {
    data_root<quotation> quot(array_nth(quotations.untagged(), i), this);

    if (!quot->entry_point)
      quot->entry_point = lazy_jit_compile_entry_point();
  }

  special_objects[OBJ_STAGE2] = special_objects[OBJ_CANONICAL_TRUE];

  std::cout << "done" << std::endl;
}
Example #3
0
	std::pair<uint32_t, uint32_t> quot_rem(uint32_t dividend)
	{
		uint32_t quotient = quot(dividend);
		uint32_t remainder = dividend - quotient * divisor;
		
		return std::make_pair(quotient, remainder);
	}
Example #4
0
// Allocates memory
void factor_vm::jit_compile_quotation(cell quot_, bool relocating) {
  data_root<quotation> quot(quot_, this);
  if (!quotation_compiled_p(quot.untagged())) {
    code_block* compiled =
        jit_compile_quotation(quot.value(), quot.value(), relocating);
    quot.untagged()->entry_point = compiled->entry_point();
  }
}
Example #5
0
// Allocates memory
cell factor_vm::lazy_jit_compile(cell quot_) {
  data_root<quotation> quot(quot_, this);

  FACTOR_ASSERT(!quotation_compiled_p(quot.untagged()));

  code_block* compiled =
      jit_compile_quotation(quot.value(), quot.value(), true);
  quot.untagged()->entry_point = compiled->entry_point();

  return quot.value();
}
Example #6
0
/* Allocates memory */
cell factor_vm::begin_callback(cell quot_) {
  data_root<object> quot(quot_, this);

  ctx->reset();
  spare_ctx = new_context();
  callback_ids.push_back(callback_id++);

  init_context(ctx);

  return quot.value();
}
Example #7
0
// Allocates memory
fixnum factor_vm::quot_code_offset_to_scan(cell quot_, cell offset) {
  data_root<quotation> quot(quot_, this);
  data_root<array> array(quot->array, this);

  quotation_jit compiler(quot.value(), false, false, this);
  compiler.init_quotation(quot.value());
  compiler.compute_position(offset);
  compiler.iterate_quotation();

  return compiler.get_position();
}
Example #8
0
//------------------------------------------------------------------------------
//  Rmatrix66 operator/(Real scalar) const
//------------------------------------------------------------------------------
Rmatrix66 Rmatrix66::operator/(Real scalar) const 
{
   Rmatrix66 quot(false);
   
   if (GmatMathUtil::IsZero(scalar))
      throw Rmatrix::DivideByZero();
   
   for (int i = 0; i < rowsD*colsD; i++)
      quot.elementD[i] = elementD[i]/scalar;
   
   return quot;
}
Example #9
0
// Returns NxN matrix D so D*H is "as diagonal as possible while preserving the diagonal"
BigRealMatrix PSLQ::createHermiteReducingMatrix(const BigRealMatrix &H) const {
  BigRealMatrix D = BigRealMatrix::one(m_n,m_digits);
  for(int i = 0; i < m_n; i++) {
    for(int j = i-1; j >= 0; j--) {
      BigReal sum;
      for(int k = j+1; k <= i; k++) {
        sum -= D(i,k) * H(k,j);
      }
      D(i,j) = floor(quot(sum,H(j,j),e(BIGREAL_1,-10)) + BIGREAL_HALF);
    }
  }
  return D;
}
Example #10
0
// Returns NxN matrix D0 so D*H is diagonal
BigRealMatrix PSLQ::createHermiteReducingMatrix0(const BigRealMatrix &H) const {
  BigRealMatrix D0 = BigRealMatrix::one(m_n,m_digits);
  for(int i = 0; i < m_n; i++) {
    for(int j = i-1; j >= 0; j--) {
      BigReal sum;
      for(int k = j+1; k <= i; k++) {
        sum += D0(i,k) * H(k,j);
      }
      D0(i,j) = -quot(sum,H(j,j),e(BIGREAL_1,-10));
    }
  }
  return D0;
}
Example #11
0
t_tree				*lexor_and_parsor(t_shell *shell, char **line)
{
	t_lex			*lex;

	while (!quot(shell, line))
		;
	if (*line && (lex = syntax_error(shell, *line)) != NULL)
	{
		return (make_parsing(&lex));
	}
	ft_memdel((void **)line);
	return (NULL);
}
Example #12
0
// Allocates memory conditionally
void quotation_jit::emit_quotation(cell quot_) {
  data_root<quotation> quot(quot_, parent);

  array* elements = untag<array>(quot->array);

  // If the quotation consists of a single word, compile a direct call
  // to the word.
  if (trivial_quotation_p(elements))
    literal(array_nth(elements, 0));
  else {
    if (compiling)
      parent->jit_compile_quotation(quot.value(), relocate);
    literal(quot.value());
  }
}
Example #13
0
void factor_vm::primitive_set_innermost_stack_frame_quot()
{
	data_root<callstack> callstack(ctx->pop(),this);
	data_root<quotation> quot(ctx->pop(),this);

	callstack.untag_check(this);
	quot.untag_check(this);

	jit_compile_quot(quot.value(),true);

	stack_frame *inner = innermost_stack_frame(callstack.untagged());
	cell offset = (char *)FRAME_RETURN_ADDRESS(inner,this) - (char *)inner->entry_point;
	inner->entry_point = quot->entry_point;
	FRAME_RETURN_ADDRESS(inner,this) = (char *)quot->entry_point + offset;
}
Example #14
0
inline void factorvm::vmprim_set_innermost_stack_frame_quot()
{
	gc_root<callstack> callstack(dpop(),this);
	gc_root<quotation> quot(dpop(),this);

	callstack.untag_check(this);
	quot.untag_check(this);

	jit_compile(quot.value(),true);

	stack_frame *inner = innermost_stack_frame_quot(callstack.untagged());
	cell offset = (char *)FRAME_RETURN_ADDRESS(inner) - (char *)inner->xt;
	inner->xt = quot->xt;
	FRAME_RETURN_ADDRESS(inner) = (char *)quot->xt + offset;
}
Example #15
0
void factor_vm::primitive_set_innermost_stack_frame_quot()
{
	data_root<callstack> stack(ctx->pop(),this);
	data_root<quotation> quot(ctx->pop(),this);

	stack.untag_check(this);
	quot.untag_check(this);

	jit_compile_quot(quot.value(),true);

	void *inner = stack->top();
	void *addr = frame_return_address(inner);
	code_block *block = code->code_block_for_address((cell)addr);
	cell offset = block->offset(addr);
	set_frame_return_address(inner, (char*)quot->entry_point + offset);
}
Example #16
0
// Allocates memory
code_block* factor_vm::jit_compile_quotation(cell owner_, cell quot_,
                                             bool relocating) {
  data_root<object> owner(owner_, this);
  data_root<quotation> quot(quot_, this);

  quotation_jit compiler(owner.value(), true, relocating, this);
  compiler.init_quotation(quot.value());
  compiler.iterate_quotation();

  cell frame_size = compiler.word_stack_frame_size(owner_);

  code_block* compiled = compiler.to_code_block(CODE_BLOCK_UNOPTIMIZED,
                                                frame_size);
  if (relocating)
    initialize_code_block(compiled);

  return compiled;
}
Example #17
0
//------------------------------------------------------------------------------
//  Rmatrix operator/(Real scalar)const
//------------------------------------------------------------------------------
Rmatrix Rmatrix::operator/(Real scalar) const 
{
   if (isSizedD == false)
   {
      throw TableTemplateExceptions::UnsizedTable();
   }

   Rmatrix quot(rowsD, colsD);
   
   if (GmatMathUtil::IsZero(scalar))
      throw Rmatrix::DivideByZero();
   
   int i;
   for (i = 0; i < rowsD*colsD; i++)
      quot.elementD[i] = elementD[i]/scalar;

   return quot;
}
Example #18
0
cell factor_vm::code_block_owner(code_block *compiled)
{
	tagged<object> owner(compiled->owner);

	/* Cold generic word call sites point to quotations that call the
	inline-cache-miss and inline-cache-miss-tail primitives. */
	if(owner.type_p(QUOTATION_TYPE))
	{
		tagged<quotation> quot(owner.as<quotation>());
		tagged<array> elements(quot->array);
#ifdef FACTOR_DEBUG
		assert(array_capacity(elements.untagged()) == 5);
		assert(array_nth(elements.untagged(),4) == special_objects[PIC_MISS_WORD]
			|| array_nth(elements.untagged(),4) == special_objects[PIC_MISS_TAIL_WORD]);
#endif
		tagged<wrapper> word_wrapper(array_nth(elements.untagged(),0));
		return word_wrapper->object;
	}
	else
		return compiled->owner;
}
Example #19
0
  DoubleReal LowessSmoothing::tricube_(DoubleReal u, DoubleReal t)
  {
    // In our case, u represents a distance and hence should be strictly positive.
    if (u < 0)
    {
      throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Value of u must be strictly positive! Aborting...", String(u));
    }

    // 0 <= u < t; u is regarded as 0.0 if fabs(u) falls below epsilon
    if ((fabs(u) < std::numeric_limits<double>::epsilon() || (0.0 < u)) && (u < t))
    {
      // (1 - (u/t)^3)^3
      // return pow( ( 1.0 - pow(u/t, 3.0)), 3.0 );
      DoubleReal quot(u / t);
      DoubleReal inner_term(1.0 - quot * quot * quot);

      return inner_term * inner_term * inner_term;
    }
    // u >= t
    else
    {
      return 0.0;
    }
  }
Example #20
0
	void initial (double *a, double *b,int *arows,int *acols,int *PARAMATERrev, double *PARAMATERval, int * maxits, int *lk, double *noisevar,double *minmaxdiff) {
		
		int ItNum=maxits[0];
		int likelihood=lk[0];
		double MinDeltaLogBeta = 1e-6,AlignmentMax=1-1e-3;
		double MinDeltaLogAlpha=minmaxdiff[0];
		
		bool PriorityAddition=0,PriorityDeletion=1,BasisAlignmentTest=1;
		//Reporting on the iterations
		int monitor_its=10;
		int rows=arows[0];
		int cols=acols[0];
		
		//Assume BASIS has number cols same as number of DATA points
		matrix BASIS(rows,cols,a);
		matrix Targets(cols,1,b);
		std::vector<int> Used;

		
		//NoiseSTD to be set as a parameter
			double NoiseStd=noisevar[0];
			
			int BetaUpdateStart=10;
			int BetaUpdateFrequency=5;
			double BetaMaxFactor=1000000;
			double varTargets=0;
			double sums=0.0,sums2=0.0;
			
			for(int i=0; i<Targets.rows; i++){
				sums+=Targets.data[i];
				sums2+=(Targets.data[i]*Targets.data[i]);
			}
			
			varTargets=(Targets.rows/((Targets.rows-1)*1.0))*((sums2/Targets.rows)-((sums/Targets.rows)*(sums/Targets.rows)));
				
				
		//***************************************************
		//***************** INITIALISE **********************
		//***************************************************
		
		Rprintf("Initialise\n");
		double GAUSSIAN_SNR_INIT	= 0.1;
		double	INIT_ALPHA_MAX	= 1e3;
		double INIT_ALPHA_MIN	= 1e-3;
		//Normalise each Basis vector
		matrix Scales(1,BASIS.cols);
		matrix beta(rows,1);
		
		for (int k=0; k<BASIS.rows; k++){
			Scales.data[k]=0;
			for (int i=0; i<BASIS.cols; i++){
				Scales.data[k]+=pow(BASIS.data[(k*BASIS.rows)+i],2);
			}
			Scales.data[k]=sqrt(Scales.data[k]);
			if (Scales.data[k]==0){
				Scales.data[k]=1;
			}
		}
		
		for (int i=0; i<BASIS.rows; i++){
			for (int k=0; k<BASIS.cols; k++){
				BASIS.data[(k*BASIS.rows)+i]=BASIS.data[(k*BASIS.rows)+i]/Scales.data[k];
			}
		}
		
		matrix LogOut(arows[0],1);
		matrix TargetsPseudoLinear(arows[0],1);
		
		for (int i=0; i<arows[0]; i++){
			if(likelihood==0){
				TargetsPseudoLinear.data[i]=Targets.data[i];
			}
			else{
				TargetsPseudoLinear.data[i]=(2*Targets.data[i]-1);
				
				LogOut.data[i]	= (TargetsPseudoLinear.data[i]*0.9+1)/2.0;
				LogOut.data[i]=log(LogOut.data[i]/(1-LogOut.data[i]));
			}
		}
		
		matrix proj;
		vprod(BASIS,TargetsPseudoLinear,proj,1);

		
		double max=0.0;
		int maxindex=0;
		for(int i=0; i<proj.rows; i++){
			if (fabs(proj.data[i])>max) {
				max=fabs(proj.data[i]);
				maxindex=i;
			}
		}
		
		Rprintf("Initialising with maximally aligned basis vector (%d)\n",maxindex+1);
		matrix PHI,Mu,Alpha;
		PHI.AddColumn(BASIS, maxindex);
		Used.push_back(maxindex);
		
		if (likelihood==1){
			linalg(PHI, LogOut,Mu,0);
			Alpha.data=new double[1];
			Alpha.rows=1;
			Alpha.cols=1;
		
			if (Mu.data[0]==0)
				Alpha.data[0]=1;
			else{
				double value=1/(Mu.data[0]*Mu.data[0]);
				if (value<INIT_ALPHA_MIN) 
					Alpha.data[0]=INIT_ALPHA_MIN;
				else if(value>INIT_ALPHA_MAX)
					Alpha.data[0]=INIT_ALPHA_MAX;
				else
					Alpha.data[0]=value;
			}
		}
		else{
			matrix temp;
			mprod(PHI,PHI,temp,1,1.0);
			
			beta.reset(1,1);
			
			beta.data[0]=1.0/(NoiseStd*NoiseStd);

			double p=temp.data[0]*beta.data[0];
			
			mprod(PHI,Targets,temp,1,1.0);
			double q=temp.data[0]*beta.data[0];
			
			Alpha.data=new double[1];
			Alpha.rows=1;
			Alpha.cols=1;
			Alpha.data[0]=(p*p)/((q*q)-p);
		}
			
		Rprintf("Initial Alpha = ");
		Rprintf("%f\n", Alpha.data[0]);

		
		//***************************************************
		//**************** END OF INITIALISE ****************
		//***************************************************
		
		matrix BASIS2(BASIS.rows,BASIS.cols);
		for (int i=0; i<BASIS.rows; i++) {
			for (int k=0; k<BASIS.cols; k++) {
				BASIS2.data[i+BASIS.rows*k]=(BASIS.data[i+BASIS.rows*k]*BASIS.data[i+BASIS.rows*k]);
			}
		}
		matrix BASIS_PHI,BASIS_B_PHI;
		matrix BASIS_Targets;
		mprod(BASIS,Targets,BASIS_Targets,1,1.0);
		matrix S_out,Q_in,S_in,Q_out,Gamma;
		matrix SIGMA,Factor;
		double logML;
		
		if(likelihood==0){
			//It will be computationally advantageous to "cache" this quantity in regression case
			mprod(BASIS,PHI,BASIS_PHI,1,1.0);
			
		}
		
		int test_fullstatistics=fullstatistics(likelihood, PHI, BASIS,BASIS2,beta,SIGMA,Mu,Alpha,logML,Targets,Used,Factor,S_out,Q_in,S_in,Q_out,BASIS_B_PHI,BASIS_PHI,BASIS_Targets,Gamma);
		
		
		if(test_fullstatistics==0){
			
		
		
		int N=BASIS.rows;
		int M_full=BASIS.cols;
		int M=PHI.rows;
		
		int addCount=0;
		int deleteCount=0;
		int updateCount=0;
		
		//Control not present for betaupdatestart and BetaUpdateFrequency
		int maxLogSize=ItNum+10+(int)(ItNum/5);
		
		matrix logMarginalLog(maxLogSize,1);
		int count=0;
		
		std::vector<double> Aligned_out,Aligned_in;
		int alignDeferCount=0;
		
		//Action Codes
		const int ACTION_REESTIMATE=0;
		const int ACTION_ADD=1;
		const int ACTION_DELETE=-1;
		
		const int ACTION_TERMINATE=10;
		const int ACTION_NOISE_ONLY=11;
		const int ACTION_ALIGNMENT_SKIP=12;
		
		int selectedAction;
		 
		/*
		 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		 %%
		 %% MAIN LOOP
		 %%
		 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		 */
		
		int iteration_counter=0;
		bool LAST_ITERATION=1;
		
		while (LAST_ITERATION) {
			
			iteration_counter+=1;

			bool UpdateIteration=0;
			if(likelihood==0){
				UpdateIteration=1;
			}
		 
			/*
			 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			 
			 %% DECISION PHASE
			 %%
			 %% Assess all potential actions
			 %%
			 */
		
			std::vector<double> GoodFactor(M_full);
			matrix DeltaML(M_full,1);
			matrix Action(M_full,1);
			
			for(int i=0; i<M_full; i++){
				DeltaML.data[i]=0;
				if (Factor.data[i]>1e-12) {
					GoodFactor[i]=1;
				}
				Action.data[i]*=ACTION_REESTIMATE;
			}
			
			
			matrix UsedFactor(Used.size(),1);
			std::vector<int> index_c,index_c_neg;
			std::vector<int> iu,iu_neg;
			
			for (int i=0; i<UsedFactor.rows; i++) {
				UsedFactor.data[i]=Factor.data[Used[i]];
				GoodFactor[Used[i]]=0;
				if (Factor.data[Used[i]]>1e-12){
					index_c.push_back(Used[i]);
					iu.push_back(i);
				}
				else {
					index_c_neg.push_back(Used[i]);
					iu_neg.push_back(i);
				}
				
			}
			if (BasisAlignmentTest){
				for (int i=0; i<Aligned_out.size(); i++) {
					GoodFactor[Aligned_out[i]]=0;
				}
			}
			
			matrix NewAlpha(index_c.size(),1);
			matrix Delta(index_c.size(),1);
			
			
			for(int i=0; i<index_c.size(); i++){
				NewAlpha.data[i]=(S_out.data[index_c[i]]*S_out.data[index_c[i]])/Factor.data[index_c[i]];
				Delta.data[i]=(1.0/NewAlpha.data[i])-(1.0/Alpha.data[iu[i]]);
				DeltaML.data[index_c[i]]= (Delta.data[i]*(Q_in.data[index_c[i]]*Q_in.data[index_c[i]])/(Delta.data[i]*S_in.data[index_c[i]]+1)-log(1+S_in.data[index_c[i]]*Delta.data[i]))/2.0;
			}
			
	
			//FREE BASIS OPTION NOT AVAILABLE
			bool anytoDelete=0;
			if(index_c_neg.size()!=0 and Mu.rows>1){
				for(int i=0; i<index_c_neg.size(); i++){
					DeltaML.data[index_c_neg[i]]= -(Q_out.data[index_c_neg[i]]*Q_out.data[index_c_neg[i]]/(S_out.data[index_c_neg[i]]+Alpha.data[iu_neg[i]])
													-log(1+S_out.data[index_c_neg[i]]/Alpha.data[iu_neg[i]]))/2.0;
					Action.data[index_c_neg[i]]=ACTION_DELETE;
					anytoDelete=1;
				}
			}
			
			
			//ANYTHING TO ADD
			index_c.clear();
			for(int i=0; i<GoodFactor.size(); i++){
				if(GoodFactor[i]==1){
					index_c.push_back(i);
				}
			}
			bool anytoADD=0;
			if(index_c.size()!=0){
				matrix quot(index_c.size(),1);
				for(int i=0; i<index_c.size(); i++){
					quot.data[i]=Q_in.data[index_c[i]]*Q_in.data[index_c[i]]/S_in.data[index_c[i]];
					DeltaML.data[index_c[i]]=(quot.data[i]-1-log(quot.data[i]))/2.0;
					Action.data[index_c[i]]=ACTION_ADD;
					anytoADD=1;
				}
			}
			
			
			//NOT TESTED? 
			if ((anytoADD && PriorityAddition) || (anytoDelete && PriorityDeletion)){
				//We won't perform re-estimation this iteration, which we achieve by
				//zero-ing out the delta
				for(int i=0; i<Action.rows; i++){
					if (Action.data[i]==ACTION_REESTIMATE)
						DeltaML.data[i]	= 0;
					//Furthermore, we should enforce ADD if preferred and DELETE is not
					// - and vice-versa
					if (anytoADD && PriorityAddition && PriorityDeletion){
						if (Action.data[i]==ACTION_DELETE)
							DeltaML.data[i]	= 0;
						
					}
					if (anytoDelete && PriorityDeletion && !PriorityAddition){
						if (Action.data[i]==ACTION_ADD)
							DeltaML.data[i]	= 0;	
						
					}
				}
			}
			
			//Choose the one with largest likelihood
			double deltaLogMallrginal=0.0;
			int nu=0;
			selectedAction=0;
			bool anyWorthwhileAction;
			for (int i=0; i<DeltaML.rows; i++) {
				if (DeltaML.data[i]>deltaLogMallrginal){
					//Updated 23/03/10 so that we do not delete when only one relevance vector
					if(Action.data[i]==-1 && Mu.rows==1){
						std::cout << "TRYING TO DELETE WHEN MU=1" << std::endl;
					}
					else{
						deltaLogMallrginal=DeltaML.data[i];
						nu=i;
						selectedAction=Action.data[i];
					}
				}
			}
			
			int j=0;
			anyWorthwhileAction=deltaLogMallrginal>0;
			if (selectedAction==ACTION_REESTIMATE || selectedAction==ACTION_DELETE){
				for	(int i=0; i<Used.size(); i++){
					if (Used[i]==nu)
						j=i;
				}
			}
		
		 
			//DIFFERENCE TO MATLAB WITH NU being selected./RVM-Speed -b 0.99 -k Binary -d kbd420
			//MATLAB 72	0.7476216971706305	0.7476216971706305
			//C++ 
			/*
			 if (iteration_counter>220) {
			 printf("%d\t%.16f\t%.16f\n",nu,deltaLogMallrginal ,DeltaML.data[71]);
			 }
			 */
			
		
			matrix Phi;
			std::string act;
			Phi.AddColumn(BASIS, nu);
			
			double newAlpha=S_out.data[nu]*S_out.data[nu]/Factor.data[nu];
			
			
			
			if (!anyWorthwhileAction || (selectedAction==ACTION_REESTIMATE && fabs(log(newAlpha)-log(Alpha.data[j]))<MinDeltaLogAlpha && !anytoDelete)){
				selectedAction=ACTION_TERMINATE;
				act="potential termination";
			}
			

			if (BasisAlignmentTest){
				if (selectedAction==ACTION_ADD){
					matrix p;
					mprod(Phi,PHI,p,1,1.0);
					if (p.rows>1){
						Rprintf("BELIEVED ERROR: check p, should be a single row\n");
						exit(1);
					}
					std::vector<int> findAligned;
					for (int i=0; i<p.cols; i++){
						if(p.data[i]>AlignmentMax){
							findAligned.push_back(i);
						}
					}
					int numAligned=findAligned.size();
					if (numAligned>0){
						selectedAction=ACTION_ALIGNMENT_SKIP;
						act="alignment-deferred addition";
						alignDeferCount+=1;
						for(int i=0; i<numAligned; i++){
							Aligned_out.push_back(nu);
							Aligned_in.push_back(Used[findAligned[i]]);
						}
					}
				}
				if (selectedAction==ACTION_DELETE){
					std::vector<int> findAligned;
					for(int i=0; i<Aligned_in.size(); i++){
						if(Aligned_in[i]==nu){
							findAligned.push_back(i);
						}
					}
					int numAligned=findAligned.size();
					//COuld include DIAGNOSTICS here
					if(numAligned>0){
						for (int i=(numAligned-1); i>-1; i--) {
							Aligned_in.erase(Aligned_in.begin()+findAligned[i]);
							Aligned_out.erase(Aligned_out.begin()+findAligned[i]);
						}
					}
				}
				
			}
			
			
			/*	
			 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			 
			 %% ACTION PHASE
			 %%
			 %% Implement above decision
			 %%
			 */

			bool UPDATE_REQUIRED=0;
			matrix SIGMANEW;
			switch (selectedAction) {
				case ACTION_REESTIMATE:{
					

					double oldAlpha=Alpha.data[j];
					Alpha.data[j]=newAlpha;
					matrix s_j;
					
					s_j.AddColumn(SIGMA, j);
					double deltaInv=1.0/(newAlpha-oldAlpha);
					double kappa=1.0/(SIGMA.data[j+j*SIGMA.rows]+deltaInv);
					
					matrix tmp(s_j.rows,s_j.cols);
					matrix deltaMu(tmp.rows,tmp.cols);
					
					for (int i=0; i<s_j.rows; i++) {
						for (int k=0; k<s_j.cols; k++) {
							tmp.data[i+s_j.rows*k]=s_j.data[i+s_j.rows*k]*kappa;
							deltaMu.data[i+s_j.rows*k]=tmp.data[i+s_j.rows*k]*-Mu.data[j];
						}
					}
					
					for (int i=0; i<s_j.rows; i++) {
						for (int k=0; k<s_j.cols; k++) {
							Mu.data[i+s_j.rows*k]+=deltaMu.data[i+s_j.rows*k];
						}
					}

					mprod(tmp, s_j, SIGMANEW, 2, 1.0);
					for (int i=0; i<SIGMA.rows; i++) {
						for (int k=0; k<SIGMA.cols; k++) {
							SIGMANEW.data[i+SIGMANEW.rows*k]=SIGMA.data[i+SIGMA.rows*k]-SIGMANEW.data[i+SIGMANEW.rows*k];
						}
					}
					
					if (UpdateIteration){
						matrix tempbbpsj;
						mprod(BASIS_B_PHI,s_j,tempbbpsj,0,1.0);
						
						for (int i=0; i<S_in.rows; i++) {
							S_in.data[i]=S_in.data[i]+kappa*(tempbbpsj.data[i]*tempbbpsj.data[i]);
							
						}
						//printoutMatrix(S_in);
						matrix tmpq;
						mprod(BASIS_B_PHI, deltaMu, tmpq, 0, 1.0);

						
						for (int i=0; i<Q_in.rows; i++) {
							Q_in.data[i]=Q_in.data[i]-tmpq.data[i];

						}
						
					}
					updateCount+=1;
					act="re-estimation";
					UPDATE_REQUIRED=1;
				}
					break;
				case ACTION_ADD:{
					
					matrix B_Phi;
					matrix BASIS_B_phi;

					if (likelihood==0){
						
						matrix BASIS_Phi;
						mprod(BASIS,Phi,BASIS_Phi,1,1.0);
						
						BASIS_PHI.AddColumn(BASIS_Phi, 0);
						
						if(beta.rows!=1 || beta.cols!=1){
							Rprintf("Error: Beta is not 1,1\n");
						}
						
						B_Phi.reset(Phi.rows,Phi.cols);
						for(int i=0; i<(Phi.rows*Phi.cols); i++){
							B_Phi.data[i]=beta.data[0]*Phi.data[i];
						}
						
						BASIS_B_phi.reset(BASIS_Phi.rows,BASIS_Phi.cols);
						for(int i=0; i<(BASIS_Phi.rows*BASIS_Phi.cols); i++){
							BASIS_B_phi.data[i]=beta.data[0]*BASIS_Phi.data[i];
						}
					}

					else if(likelihood==1){
						
						B_Phi.reset(beta.rows,beta.cols);
						
					for(int i=0; i<B_Phi.rows; i++){
						for (int k=0; k<B_Phi.cols; k++) {
							B_Phi.data[i+B_Phi.rows*k]=Phi.data[i+B_Phi.rows*k]*beta.data[i+B_Phi.rows*k];
						}
					}
					
					
					mprod(BASIS,B_Phi,BASIS_B_phi,1,1.0);
					}
					
					matrix tmp0;
					matrix tmp;
					mprod(B_Phi, PHI, tmp0, 1, 1.0);
					mprod(tmp0, SIGMA, tmp, 0, 1.0);
					tmp.rows=tmp.cols;
					tmp.cols=1;
					
					//cout << "tmp "<<endl;
					double *tmpalphadata=new double[Alpha.rows*Alpha.cols];
					
					
					Alpha.resize(Alpha.rows+1, Alpha.cols);
					Alpha.data[Alpha.rows-1]=newAlpha;
					PHI.AddColumn(Phi, 0);

					double s_ii=1/(newAlpha+S_in.data[nu]);
					matrix s_i(tmp.rows,1);
					for (int i=0; i<tmp.rows; i++) {
						s_i.data[i]=-s_ii*tmp.data[i];
					}
					matrix TAU;
					mprod(s_i,tmp,TAU,2,-1.0);
					SIGMANEW.resize(s_i.rows+1, s_i.rows+1);

					for(int i=0; i<SIGMANEW.rows; i++){
						for(int k=0; k<SIGMANEW.cols; k++){
							if(i<SIGMA.rows and k<SIGMA.cols){
								SIGMANEW.data[i+SIGMANEW.rows*k]=SIGMA.data[i+SIGMA.rows*k]+TAU.data[i+TAU.rows*k];
							}
							else if (i==SIGMA.rows and k<s_i.rows){
								SIGMANEW.data[i+SIGMANEW.rows*k]=s_i.data[k];
							}
							else if(k==SIGMA.rows and i<s_i.rows){
								SIGMANEW.data[i+SIGMANEW.rows*k]=s_i.data[i];
							}
							else if(i==SIGMA.rows and k==SIGMA.rows){
								SIGMANEW.data[i+SIGMANEW.rows*k]=s_ii;
							}
							else {
								Rprintf("ERROR IN ACTION ADD STATEMENT\n");
								exit(1);
							}
						}
					}
					

					double mu_i=s_ii*Q_in.data[nu];
					matrix deltaMu(tmp.rows+1,1);
					for (int i=0; i<deltaMu.rows-1; i++) {
						deltaMu.data[i]=-mu_i*tmp.data[i];
					}
					deltaMu.data[deltaMu.rows-1]=mu_i;
					//cout << "MU is being updated" <<endl;
					//printoutMatrix(deltaMu);
					Mu.resize(Mu.rows+1, Mu.cols);
					Mu.data[Mu.rows-1]=0;
					for (int i=0; i<Mu.rows; i++) {
						Mu.data[i]+=deltaMu.data[i];
						
					}
					

					//printoutMatrix(Mu);
					if(UpdateIteration){
						matrix mctmp;
						mprod(BASIS_B_PHI,tmp,mctmp,0,1.0);
						
						matrix mCi(mctmp.rows,1);
						
						for(int i=0; i<mctmp.rows; i++){
							mCi.data[i] = BASIS_B_phi.data[i] - mctmp.data[i];
							S_in.data[i]=S_in.data[i]-s_ii*(mCi.data[i]*mCi.data[i]);
							Q_in.data[i]=Q_in.data[i]-mu_i*mCi.data[i];
						}
					}
					Used.push_back(nu);
					addCount+=1;
					act="addition";
					UPDATE_REQUIRED=true;
					
				}
					break;
				case ACTION_DELETE:{
					
					if(likelihood==0){
						BASIS_PHI.RemoveColumn(j);
					}
					
					PHI.RemoveColumn(j);
					Alpha.RemoveRow(j);
					double s_jj=SIGMA.data[j+SIGMA.rows*j];
					matrix s_j;
					s_j.AddColumn(SIGMA, j);
					
					matrix tmp(s_j.rows,s_j.cols);
					for(int i=0; i<s_j.rows; i++){
						tmp.data[i]=s_j.data[i]/s_jj;
					}
					
					mprod(tmp, s_j, SIGMANEW, 2, 1.0);
					
					for(int i=0; i<SIGMANEW.rows; i++){
						for (int k=0; k<SIGMANEW.cols; k++) {
							SIGMANEW.data[i+SIGMANEW.rows*k]=SIGMA.data[i+SIGMA.rows*k]-SIGMANEW.data[i+SIGMANEW.rows*k];
						}
					}
					SIGMANEW.RemoveRow(j);
					SIGMANEW.RemoveColumn(j);
									
					matrix deltaMu(tmp.rows,1);
					for (int i=0; i<tmp.rows; i++) {
						deltaMu.data[i]=-Mu.data[j]*tmp.data[i];
						
					}
					
					double mu_j=Mu.data[j];

					for(int i=0; i<Mu.rows; i++){
						Mu.data[i]+=deltaMu.data[i];
					}

					Mu.RemoveRow(j);
					if (UpdateIteration){
						matrix jPm;
						mprod(BASIS_B_PHI,s_j,jPm,0,1.0);

						for (int i=0; i<S_in.rows; i++) {
							S_in.data[i]=S_in.data[i]+(jPm.data[i]*jPm.data[i])/s_jj;
							
						}
						//printoutMatrix(S_in);
						for (int i=0; i<Q_in.rows; i++) {
							Q_in.data[i]=Q_in.data[i]+jPm.data[i]*(mu_j/s_jj);
							
						}

					}
					Used.erase(Used.begin()+(j));
					deleteCount+=1;
					act="deletion";
					UPDATE_REQUIRED=true;
				}
					break;
					
				default:
					break;
			}
			M=Used.size();
			
			//Rprintf("ACTION: %s of %d (%g)\n" ,act.c_str(),nu,deltaLogMallrginal);

			 /*
			 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			 
			 %% UPDATE STATISTICS
			 
			 % If we've performed a meaningful action,
			 % update the relevant variables
			 % 
			 */


			if (UPDATE_REQUIRED){
				if(UpdateIteration){

					S_out.reset(S_in.rows,S_in.cols);
					Q_out.reset(Q_in.rows,Q_in.cols);
					
					for(int i=0; i<S_in.rows; i++){
						S_out.data[i]=S_in.data[i];
						Q_out.data[i]=Q_in.data[i];
					}
					
					 matrix tmp(Used.size(),1);
					 for (int i=0; i<Used.size(); i++) {
						 tmp.data[i]=Alpha.data[i]/(Alpha.data[i]-S_in.data[Used[i]]);
						 S_out.data[Used[i]]=tmp.data[i]*S_in.data[Used[i]];
						 Q_out.data[Used[i]]=tmp.data[i]*Q_in.data[Used[i]];
					 }
					 
					for (int i=0; i<Q_out.rows; i++) {
						Factor.data[i]=(Q_out.data[i]*Q_out.data[i])-S_out.data[i];
					}
					 
					SIGMA.reset(SIGMANEW.rows,SIGMANEW.cols);
					for(int i=0; i<(SIGMA.rows*SIGMA.cols); i++){
						SIGMA.data[i]=SIGMANEW.data[i];
					}
					
					
					
					Gamma.reset(Alpha.rows,1);
					 for (int i=0; i<Alpha.rows; i++) {
					 Gamma.data[i]=1-Alpha.data[i]*SIGMA.data[i*SIGMA.cols+i];
					 }
					
					BASIS_B_PHI.reset(BASIS_PHI.rows,BASIS_PHI.cols);
					
					for(int i=0; i<(BASIS_PHI.rows*BASIS_PHI.cols); i++){
						BASIS_B_PHI.data[i]=beta.data[0]*BASIS_PHI.data[i];
					}
				}
				else{
					double newLogML=0.0;
					test_fullstatistics=fullstatistics(likelihood, PHI, BASIS,BASIS2,beta,SIGMA,Mu,Alpha,newLogML,Targets,Used,Factor,S_out,Q_in,S_in,Q_out,BASIS_B_PHI,BASIS_PHI,BASIS_Targets,Gamma);;
					deltaLogMallrginal=newLogML-logML;
				}
				
				if(UpdateIteration && deltaLogMallrginal<0){
					Rprintf("** Alert **  DECREASE IN LIKELIHOOD !!\n");
				}
				
				logML=logML+deltaLogMallrginal;
				count+=1;
				logMarginalLog.data[count]=logML;
			}
			
			if(likelihood==0 &(selectedAction==ACTION_TERMINATE || iteration_counter<=BetaUpdateStart || iteration_counter%BetaUpdateFrequency==0 )){
	
				double betaz1=beta.data[0];
				
				matrix y;
				
				mprod(PHI,Mu,y,0,1.0);
				
				
				
				double e=0.0;
				for(int i=0; i<y.rows; i++){
					e+=(Targets.data[i]-y.data[i])*(Targets.data[i]-y.data[i]);
				}
				
				double sumgamma=0.0;
				
				for(int i=0; i<(Gamma.rows*Gamma.cols); i++){
					sumgamma+=Gamma.data[i];
				}
				
				
				beta.data[0]=(rows-sumgamma)/(e);
				
			

				if((BetaMaxFactor/varTargets)<beta.data[0])
					beta.data[0]=(BetaMaxFactor/varTargets);
				

				
				double deltaLogBeta = log(beta.data[0])-log(betaz1);

				if(fabs(deltaLogBeta)>MinDeltaLogBeta){


					test_fullstatistics=fullstatistics(likelihood, PHI, BASIS,BASIS2,beta,SIGMA,Mu,Alpha,logML,Targets,Used,Factor,S_out,Q_in,S_in,Q_out,BASIS_B_PHI,BASIS_PHI,BASIS_Targets,Gamma);
					count+=1;

					logMarginalLog.data[count]=logML;
				
					if(selectedAction==ACTION_TERMINATE){
						selectedAction=ACTION_NOISE_ONLY;
					}
				}
			}
			
			
			
			

				
	
			/*
			 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			 
			 % END OF CYCLE PROCESSING
			 % 
			 % Check if termination still specified, and output diagnostics
			 % 
			 */
		
			double sumgamma=0.0;
			for (int i=0; i<Gamma.rows; i++) {
				sumgamma+=Gamma.data[i];
			}
			
			double sqrtbeta=0.0;
			for (int i=0; i<beta.rows; i++) {
				sqrtbeta+=sqrt(1.0/beta.data[i]);
			}		
			if(selectedAction==ACTION_TERMINATE){
				Rprintf("** Stopping at iteration %d (Max_delta_ml=%e) **",iteration_counter,deltaLogMallrginal);
				Rprintf("'%4d> L = %.6f\t Gamma = %.2f (M = %d)\n",iteration_counter, logML/N,sumgamma, M);
				break;
			}
			
			//NO TIME LIMIT AS OF YET!!!!!!
			
			
			if ((iteration_counter%monitor_its==0 || iteration_counter==1)){
				if(likelihood==0){
					Rprintf("%5d> L = %.6f\t Gamma = %.2f (M = %d)\t s=%.3f \n",iteration_counter, logML/N, sumgamma, M,sqrtbeta);
				}
				else{
				Rprintf("%5d> L = %.6f\t Gamma = %.2f (M = %d)\n",iteration_counter, logML/(N*1.0), sumgamma, M);
				}
			}
			
			if(iteration_counter==ItNum || test_fullstatistics==1){
				break;
			}
			

			
		}

		/*
		 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		 
		 %%
		 %% POST-PROCESSING
		 %%
		 
		 %
		 % Warn if we exited the main loop without terminating automatically
		 % 
		 */
		if (selectedAction!=ACTION_TERMINATE){
			if (test_fullstatistics==1){
				Rprintf("** Warning Problem with Cholskey Decomposition\n");
			}
			else{
				Rprintf("** Iteration limit: algorithm did not converge\n");
			}
		}
		int total	= addCount + deleteCount + updateCount;
		if(BasisAlignmentTest)
			total	= total+alignDeferCount;
			if(test_fullstatistics==0){
		Rprintf("Action Summary\n");
		Rprintf("==============\n");
		Rprintf("Added\t\t\t%6d (%.0f%%)\n",addCount, 100*addCount/(total*1.0));
		Rprintf("Deleted\t\t%6d (%.0f%%)\n",deleteCount, 100*deleteCount/(total*1.0));
		Rprintf("Reestimated\t%6d (%.0f%%)\n",updateCount, 100*updateCount/(total*1.0));
		if (BasisAlignmentTest && alignDeferCount){
			Rprintf("--------------\n");
			Rprintf("Deferred\t%6d (%.0f%%)\n",alignDeferCount, 100*alignDeferCount/(total*1.0));
		}
		Rprintf("==============\n");
		Rprintf("Total of %d likelihood updates\n", count);
			
		//std::vector<int> PARAMATERrev;
		//matrix PARAMATERval;
		
		//int *PARAMATERrev;
		//double *PARAMATERval;
		//PARAMATERrev = (int*)R_alloc( Used.size(),sizeof(int) );
		//PARAMATERval = (double*)R_alloc(Used.size(),sizeof(double));
		
		//std::vector<size_t> index;
		for (unsigned i = 0; i < Used.size(); ++i)
			PARAMATERrev[i]=Used[i];
		
		//	index.push_back(i);
		//sort(index.begin(), index.end(), index_cmp<std::vector<int>&>(PARAMATERrev));
		//sort (PARAMATERrev.begin(), PARAMATERrev.end());
		
		//PARAMATERval.reset(index.size(),1);
		for (int i=0; i<Used.size(); i++) {
			PARAMATERval[i]=(Mu.data[i]/(Scales.data[Used[i]]));
		}
		
			}
		}
	}
Example #21
0
int
main(int argc, char *argv[])
{
	int cnt, all, i;
	char dev[MNAMELEN], *nm, *mountpoint, *cp;
	struct statfs *mp;

	all = 0;
	func = douser;
#ifndef	COMPAT
	header = getbsize(&headerlen, &blocksize);
#endif
	while (--argc > 0 && **++argv == '-') {
		while (*++*argv) {
			switch (**argv) {
			case 'n':
				func = donames;
				break;
			case 'c':
				func = dofsizes;
				break;
			case 'a':
				all = 1;
				break;
			case 'f':
				count = 1;
				break;
			case 'h':
				estimate = 1;
				break;
#ifndef	COMPAT
			case 'k':
				blocksize = 1024;
				break;
#endif	/* COMPAT */
			case 'v':
				unused = 1;
				break;
			default:
				usage();
			}
		}
	}
	cnt = getmntinfo(&mp, MNT_NOWAIT);
	if (all) {
		for (; --cnt >= 0; mp++) {
			if (strcmp(mp->f_fstypename, MOUNT_FFS) == 0 ||
			    strcmp(mp->f_fstypename, "ufs") == 0) {
				if ((nm = strrchr(mp->f_mntfromname, '/'))) {
					snprintf(dev, sizeof(dev), "%sr%s",
					    _PATH_DEV, nm + 1);
					nm = dev;
				} else
					nm = mp->f_mntfromname;
				quot(nm, mp->f_mntonname);
			}
		}
	}
	for (; --argc >= 0; argv++) {
		mountpoint = NULL;
		nm = *argv;

		/* Remove trailing slashes from name. */
		cp = nm + strlen(nm);
		while (*(--cp) == '/' && cp != nm)
			*cp = '\0';

		/* Look up the name in the mount table. */
		for (i = 0; i < cnt; i++) {
			/* Remove trailing slashes from name. */
			cp = mp[i].f_mntonname + strlen(mp[i].f_mntonname);
			while (*(--cp) == '/' && cp != mp[i].f_mntonname)
				*cp = '\0';

			if ((!strcmp(mp->f_fstypename, MOUNT_FFS) ||
			     !strcmp(mp->f_fstypename, MOUNT_MFS) ||
			     !strcmp(mp->f_fstypename, "ufs")) &&
			    strcmp(nm, mp[i].f_mntonname) == 0) {
				nm = mp[i].f_mntfromname;
				mountpoint = mp[i].f_mntonname;
				break;
			}
		}

		/* Make sure we have the raw device... */
		if (strncmp(nm, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0 &&
		    nm[sizeof(_PATH_DEV) - 1] != 'r') {
			snprintf(dev, sizeof(dev), "%sr%s", _PATH_DEV,
			    nm + sizeof(_PATH_DEV) - 1);
			nm = dev;
		}
		quot(nm, mountpoint);
	}
	exit(0);
}
void quotRemainder(const BigReal &x,  const BigReal &y, BigInt *quotient, BigReal *remainder) {
  DEFINEMETHODNAME;
  if(y.isZero()) {
    throwBigRealInvalidArgumentException(method, _T("Division by zero. (%s / 0)."), x.toString().cstr());
  }
  if(quotient == remainder) { // also takes care of the stupid situation where both are NULL
    throwBigRealInvalidArgumentException(method, _T("quotient is the same variable as remainder"));
  }
  if(quotient == &x || quotient == &y) {
    throwBigRealInvalidArgumentException(method, _T("quotient cannot be the same variable as x or y"));
  }
  if(remainder == &x || remainder == &y) {
    throwBigRealInvalidArgumentException(method, _T("remainder cannot be the same variable as x or y"));
  }

  if(x.isZero()) {
    if(quotient ) quotient->setToZero();
    if(remainder) remainder->setToZero();
    return;
  }

  DigitPool *pool = x.getDigitPool();
  const int cmpAbs = compareAbs(x, y);
  if(cmpAbs < 0) {
    if(remainder) *remainder = x;
    if(quotient)  quotient->setToZero();
    return;
  } else if(cmpAbs == 0) {
    if(remainder) remainder->setToZero();
    if(quotient) {
      *quotient = quotient->getDigitPool()->get1();
    }
    return;
  }

  BigReal tmpX(x);
  tmpX.setPositive();
  BigReal tmpY(y);
  tmpY.setPositive();
  BigInt q   = floor(quot(tmpX, tmpY, modulusC1));
  BigReal mod = tmpX - q * tmpY;

  if(mod.isNegative()) {
    if(remainder) {
      *remainder = mod + tmpY;
    }
    if(quotient) {
      --q;
      *quotient = q;
    }
  } else if(mod >= tmpY) {
    if(remainder) {
      *remainder = mod - tmpY;
    }
    if(quotient) {
      ++q;
      *quotient = q;
    }
  } else {
    if(remainder) {
      *remainder = mod;
    }
    if(quotient) {
      *quotient = q;
    }
  }

  if(remainder && (remainder->m_negative != x.m_negative)) {
    remainder->m_negative = x.m_negative; // sign(x % y) = sign(x), equivalent to build-in % operator
  }
}
Example #23
0
// Allocates memory (from_unsigned_cell)
void factor_vm::primitive_quotation_code() {
  data_root<quotation> quot(ctx->pop(), this);

  ctx->push(from_unsigned_cell(quot->entry_point));
  ctx->push(from_unsigned_cell((cell)quot->code() + quot->code()->size()));
}
Example #24
0
File: r_alpha.c Project: 8l/insieme
void r__alpha(signed int var0_0_0, signed int var0_0_1, signed int var0_1_0, signed int var0_1_1, RealNum var0_2, signed int *out_0, complex *out_1) {
  signed int var10[35] = {11,23,31,47,59,71,89,107,113,139,179,191,211,239,283,293,317,359,383,431,479,523,571,599,647,719,761,863,887,953,971,1069,1151,1193,1291};
  signed int var13[35] = {12,24,36,48,60,72,96,108,120,144,180,192,216,240,288,300,324,360,384,432,480,540,576,600,648,720,768,864,900,960,972,1080,1152,1200,1296};
  signed int var21;
  signed int var26;
  signed int var28;
  signed int var29;
  signed int var32;
  int var36;
  signed int var37;
  signed int var42;
  signed int var43;
  signed int var46;
  int var50;
  signed int var51;
  signed int var56;
  signed int var61;
  signed int var63;
  
  (* out_0) = (var0_1_1 - var0_1_0);
  var21 = 0;
  {
    int var17;
    int var18;
        
    var17 = (var21 < 35);
    if(var17) {
      var18 = (var13[var21] != var0_0_1);
    } else {
      var18 = 0;
    }
    while(var18) {
      var21 = (var21 + 1);
      var17 = (var21 < 35);
      if(var17) {
	var18 = (var13[var21] != var0_0_1);
      } else {
	var18 = 0;
      }
    }
  }
  var26 = (var0_0_0 % 30);
  var28 = (var10[var21] * (var26 + 1));
  quot(var28, 31, &var29);
  quot(var28, 31, &var32);
  var36 = (((var28 % 31) != 0) && (var28 < 0));
  if(var36) {
    var37 = (var29 - 1);
  } else {
    var37 = var32;
  }
  var42 = ((var10[var21] * (var26 + 1)) * 2);
  quot(var42, 31, &var43);
  quot(var42, 31, &var46);
  var50 = (((var42 % 31) != 0) && (var42 < 0));
  if(var50) {
    var51 = (var43 - 1);
  } else {
    var51 = var46;
  }
  var56 = ((var37 + 1) + (0 * (1 - (2 * (var51 % 2)))));
  var61 = (2 * var10[var21]);
  quot(32767, var10[var21], &var63);
  {
    signed int var2;

    for(var2 = 0; var2 < (* out_0); var2 += 1) {
      signed int var3;
      RealNum var4;
      RealNum var5;
      RealNum var6;
      RealNum var7;
      complex var8;
      signed int var57;
      RealNum var66;
      RealNum var67;
      RealNum var68;
      complex var69;

      var3 = (var2 + var0_1_0);
      intToReal(var3, &var4);
      mul_RealNum(var4, var0_2, &var5);
      cos_feldspar(var5, &var6);
      sin_feldspar(var5, &var7);
      mkComplexReal(var6, var7, &var8);
      var57 = (var3 % var10[var21]);
      intToReal((65536 - ((((var56 * var57) * (var57 + 1)) % var61) * var63)), &var66);
      cos_feldspar(var66, &var67);
      sin_feldspar(var66, &var68);
      mkComplexReal(var67, var68, &var69);
      mul_ComplexReal(var8, var69, &(out_1[var2]));
    }
  }
}
BigReal rQuot(const BigReal &x, const BigReal &y, size_t digits, DigitPool *digitPool) {
  DigitPool *pool = digitPool ? digitPool : x.getDigitPool();
  return quot(x,y,e(_1,BigReal::getExpo10(x) - BigReal::getExpo10(y) - (BRExpoType)digits - 2),pool);
}