Exemplo n.º 1
0
int MetricAnIso::IntersectWith(const MetricAnIso M2) 
{
  //cerr << " - " << *this << M2 <<  endl;
  int r=0;
  MetricAnIso & M1 = *this;
  D2xD2 M;
  double l1,l2;
      
  ReductionSimultanee(*this,M2,l1,l2,M);
  // cerr << M << endl;
  R2 v1(M.x.x,M.y.x);
  R2 v2(M.x.y,M.y.y);
  double l11=M1(v1,v1);
  double l12=M1(v2,v2);
  double l21=M2(v1,v1);
  double l22=M2(v2,v2);
  if ( l11 < l21 )  r=1,l11=l21;
  if ( l12 < l22 )  r=1,l12=l22; 
  // cerr << r << endl;
  if (r) { // change
    D2xD2 M_1(M.inv());
    D2xD2 D(l11,0,0,l12); 
    D2xD2 Mi(M_1.t()*D*M_1);
    a11=Mi.x.x;
    a21=0.5*(Mi.x.y+Mi.y.x);
    a22=Mi.y.y; }
  return r;
}
Exemplo n.º 2
0
void scalar_multiply_test()
{
    quan::mass::kg M1(1.1);
    quan::mass::kg M2 = M1 * 25;
    // not sure if we can guarantee this?
    // may need to use QUAN_CHECK_CLOSE?
    QUAN_CHECK_EQUAL(M2.numeric_value(),
        (QUAN_FLOAT_TYPE(1.1) * QUAN_FLOAT_TYPE(25))
    );
    //check other orientation
    quan::mass::kg M2a = 25 * M1;
    // not sure if we can guarantee this?
    // may need to use QUAN_CHECK_CLOSE?
    QUAN_CHECK_EQUAL(M2a.numeric_value(),
        (QUAN_FLOAT_TYPE(25) * QUAN_FLOAT_TYPE(1.1) )
    );

    // similar comment
    quan::force::kgf F1(100);
    quan::force::kgf F2  = F1 * 0.3;
    QUAN_CHECK_EQUAL(F2.numeric_value(),
        (QUAN_FLOAT_TYPE(100) * QUAN_FLOAT_TYPE(0.3))
    );
     //check other orientation
    quan::force::kgf F2a  = 0.3 * F1 ;
    QUAN_CHECK_EQUAL(F2.numeric_value(),
        (QUAN_FLOAT_TYPE(0.3) * QUAN_FLOAT_TYPE(100))
    );
    
}
Exemplo n.º 3
0
void foo() {
  M1(
    M2);
  // CHECK: {{.*}}:7:{{[0-9]+}}: warning: expression result unused
  // CHECK: {{.*}}:4:{{[0-9]+}}: note: expanded from macro 'M2'
  // CHECK: {{.*}}:3:{{[0-9]+}}: note: expanded from macro 'M1'
}
Exemplo n.º 4
0
int main()
{
  vpMatrix M ;
  vpMatrix M1(2,3) ;
  vpMatrix M2(3,3) ;
  vpMatrix M3(2,2) ;

  std::cout << "** test matrix exception during multiplication" << std::endl;

  try {
    M = M1*M3 ;
  }
  catch (vpException &e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }

  std::cout << "** test matrix exception during addition" << std::endl;

  try {
    M = M1+M3 ;
  }
  catch (vpException &e)  {
    std::cout << "Catch an exception: " << e << std::endl;
  }
}
void foo() {
  M1(
    M2);
  // CHECK: :7:{{[0-9]+}}: warning: expression result unused
  // CHECK: :4:{{[0-9]+}}: note: expanded from macro: M2
  // CHECK: :3:{{[0-9]+}}: note: expanded from macro: M1
}
Exemplo n.º 6
0
// Checks if given number if prime 
bool isPrime(XLong& number)
{
	// if number is even it can't ne prime
	if (!number.bt(0)) return false;

	/*
	// algorithm #1 (school like)
	// if (P mod i) == 0, for all (i = 2..t) or (i = 2..sqrt(t))
	// then P is prime 
	//
	XLong i(0,number.GetBitLength());
	XLong t(0,number.GetBitLength());
	t = root(number,2);	//t = number;
	//
    for (i=2; i< t; i++)
    {
        if (number % i == 0)  // check 
            return false;
    }
    return true;*/


/*
	// algorithm #2 (strong)
	// if  M^P,mod P = M, where M <= P
	// then P is prime 
	//
	XLong M(0,number.GetBitLength());
	XLong M1(0,number.GetBitLength());
	M = 2; // any constant < number
#if 1 
	M1 = modexp(M,number,number); 
#else
	M1 = power(M,number);M1 = M1%number;
#endif
	if (M1 == M)
	{
		return true;
	}
*/
	
	
	// algorithm #3 (strongest)
	// if  M^((P-1)/2),mod P = +-1 (1 or P-1), where M <= P
	// then P is prime 
	//
	XLong M(0,number.GetBitLength());
	XLong M1(0,number.GetBitLength());
	M = 2; // any constant
	M1 = modexp(M,(number-1)/2,number);
	if ((M1 == 1) || (M1 == (number-1)))
	{
		//printf("ff");
		return true;
	}
	//
	//
	return false;
}
Exemplo n.º 7
0
void T7(void)
{
    assert(TEMP(3) == 123);
    assert(TEMP2(1) == 123);
    assert(xcat(xcat(1,2),3) == 123);
    assert(strcmp("abc123abc123abc123abc",
		  S1(M1(123))) == 0);
}
Exemplo n.º 8
0
SEXP wink_true_coincidences( SEXP data1, SEXP data2, SEXP windows, SEXP Rdelta )
{
    parameters param;
    if( !param.load(data1,data2,windows,Rdelta,NULL,false) )
        return R_NilValue;
    
    //==========================================================================
    // create the return vector
    //==========================================================================
    SEXP Rval;
    PROTECT(Rval = allocVector(INTSXP,param.num_windows) );
    int *ans = INTEGER(Rval);

    try 
    {
        //======================================================================
        // transform R data intro C++ objects
        //======================================================================
        wink::c_matrix     M1(param.nrow1,param.ncol1);
        wink::c_matrix     M2(param.nrow2,param.ncol2);
        
        M1.loadR( REAL(data1) );
        M2.loadR( REAL(data2) );
        
        //======================================================================
        // make C++ neuro_pair, init random generator
        //======================================================================
        wink::neuro_pair   NP(M1,M2,param.B);
        
                
        //======================================================================
        // outer loop on windows
        //======================================================================
        for( size_t i=0; i < param.num_windows; ++i )
        {
            //------------------------------------------------------------------
            // get the boundaries
            //------------------------------------------------------------------
            const double a = param.ptr_windows[0+2*i];
            const double b = param.ptr_windows[1+2*i];
            
            //------------------------------------------------------------------
            // call the integrated function
            //------------------------------------------------------------------
            const size_t true_coinc = NP.true_coincidences_on(a,b,param.delta);            
            ans[i] = true_coinc;
        }
        UNPROTECT(1);
        
        return Rval;
        
    }
    catch(...)
    {
        Rprintf("Exception in wink_true_coincidences");
    }
    return R_NilValue;
}
Exemplo n.º 9
0
SCMatrix operator*(const double s, const SCMatrix& M){
  SCMatrix M1(M);
  for (int i=0;i<M.Rows();i++){
    for (int j=0;j<M.Columns();j++){
      M1.data[i][j]=s*M.data[i][j];
    }
  }
  return M1;
}
Exemplo n.º 10
0
int main(int argc, char** argv) {
	Manoscritto M1(0, "aaa", "aaa", 10),
				M2(1, "bbb", "bbb", 10),
				M3(3, "bbb", "bbb", 10);
	Lettera L1(4, "aaa", "aaa", 10, "aaa", "aaa"),
			L2(5, "bbb", "bbb", 10, "bbb", "bbb"),
			L3=L1;
			
			
	cout <<"Stampa normale:\n";		
	cout << M1 <<'\n'<< M2 <<'\n' << M3 <<"\n\n";
	cout << L1 <<'\n'<< L2 <<'\n' << L3 ;
		
		
	cout <<"\n\nStampa polimorfismo:\n";
	Manoscritto * v[2];
	v[0] = &M1;
	v[1] = &L2;
	
	for(int i=0; i<2; i++) {
		v[i] -> visualizzaDati();
		cout<<'\n';
	}
	
	cout <<"\n\nElenco:\n";
	Elenco E1, E2;
	
	E1.push(&M1);
	E1.push(&M2);
	E1.push(&L1);
	E1.push(&L2);
	E1.push(&M3);
	E1.pop(0); 
	E1.stampa();
	
	ofstream file;
	file.open("./test.txt", ios::out);
	if(!file) {
		cout << "Errore file";
	} else {
		E1.memorizzaDati(file);
	}
	file.close();
	
	cout <<"\n\nEccezione:\n";
	try {
		E2.push(&M1);
		E2.push(&M1);
	} catch (Duplicato e) {
		cout << e.what() << endl;
	}
	
	
	
	
}
Exemplo n.º 11
0
void ResHalfGCD(zz_pX& U, zz_pX& V, vec_zz_p& cvec, vec_long& dvec)
{
   long d_red = (deg(U)+1)/2;

   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
      return;
   }

   long du = deg(U);


   long d1 = (d_red + 1)/2;
   if (d1 < 1) d1 = 1;
   if (d1 >= d_red) d1 = d_red - 1;

   zz_pXMatrix M1;

   ResHalfGCD(M1, U, V, d1, cvec, dvec);
   mul(U, V, M1);

   long d2 = deg(V) - du + d_red;

   if (IsZero(V) || d2 <= 0) {
      return;
   }

   M1(0,0).kill();
   M1(0,1).kill();
   M1(1,0).kill();
   M1(1,1).kill();


   zz_pX Q;

   append(cvec, LeadCoeff(V));
   append(dvec, dvec[dvec.length()-1]-deg(U)+deg(V));
   DivRem(Q, U, U, V);
   swap(U, V);

   ResHalfGCD(M1, U, V, d2, cvec, dvec);

   mul(U, V, M1); 
}
Exemplo n.º 12
0
void HalfGCD(zz_pX& U, zz_pX& V)
{
   long d_red = (deg(U)+1)/2;

   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
      return;
   }

   long du = deg(U);


   long d1 = (d_red + 1)/2;
   if (d1 < 1) d1 = 1;
   if (d1 >= d_red) d1 = d_red - 1;

   zz_pXMatrix M1;

   HalfGCD(M1, U, V, d1);
   mul(U, V, M1);

   long d2 = deg(V) - du + d_red;

   if (IsZero(V) || d2 <= 0) {
      return;
   }

   M1(0,0).kill();
   M1(0,1).kill();
   M1(1,0).kill();
   M1(1,1).kill();


   zz_pX Q;

   DivRem(Q, U, U, V);
   swap(U, V);

   HalfGCD(M1, U, V, d2);

   mul(U, V, M1); 
}
Exemplo n.º 13
0
cElHomographie cElHomographie::operator * (const cElHomographie & H2) const
{
    ElMatrix<REAL> M1(3,3);
    ElMatrix<REAL> M2(3,3);
    ElMatrix<REAL> Res(3,3);

     this->ToMatrix(M1);
     H2.ToMatrix(M2);

    Res.mul(M1,M2);
    return FromMatrix(Res);
}
Exemplo n.º 14
0
int main (int narg, const char** argv) {

	typedef Range<false> R;
	typedef Range<true> CR;

	Matrix<double> M1(10, 1), M2, M3(M1), M4(3, 4), M6(4, 3), M5(3, 4, 2), M7(3, 4, 2), M8, M9, M10, M11;
    M1 = 0.0;
    M2 = M1;

    for (size_t i = 1; i < M1.Size(); ++i)
        M1[i] = i;
    for (size_t i = 1; i < M4.Size(); ++i)
        M4[i] = i;
    for (size_t i = 1; i < M5.Size(); ++i)
        M5[i] = i;

    M3(R(7,-2,2)) = M1(CR(2,4));
    M6(R(3,-2,0),R(0,1)) = M4(CR(0,1),CR(1,2));
    M7(R(2,-2,0),R(0,1),R(0,0)) =  M5(CR(0,1),CR(1,2),CR(0,0));
    M8 = M6(CR(1,-1,0),CR(1,2));
    M6(R(0,1),R(1,2)) = M8;
    M9 = M6(CR("1:-1:0"),CR("1:2"));
    M10 = M6(CR("1:-1:0,1"),CR("1:2"));
    M11 = M6(CR(),CR()) * M6(CR(),CR());
    M11 = M6 * M6(CR(),CR());
    std::cout << M3 << std::endl<< std::endl;
    std::cout << M4 << std::endl<< std::endl;
    std::cout << M6 << std::endl<< std::endl;
    std::cout << M5 << std::endl<< std::endl;
    std::cout << M7 << std::endl<< std::endl;
    std::cout << M8 << std::endl<< std::endl;
    std::cout << M9 << std::endl<< std::endl;
    std::cout << M10 << std::endl<< std::endl;
    std::cout << M11 << std::endl<< std::endl;
    return 0;
}
Exemplo n.º 15
0
flag CPipeTerm::GetModelAction(CMdlActionArray & Acts)
  {
  //CMdlAction {MAT_NULL, MAT_State, MAT_Value};
  CMdlAction M0(0, MAT_State, !m_VPB.On(), "Open", 1);
  CMdlAction M1(1, MAT_State, m_VPB.On(),  "Close", 0);
  CMdlAction M2(2, MAT_Value, m_VPB.On(),  "Manual Posn (%)", true,
                  m_VPB.ManualPosition(this)*100, 0.0, 100.0,
                  m_VPB.ActualPosition(this, &m_FRB)*100);

  Acts.SetSize(0);
  Acts.SetAtGrow(0, M0);
  Acts.SetAtGrow(1, M1);
  Acts.SetAtGrow(2, M2);
  Acts.SetAtGrow(3, CMdlAction(3, MAT_Switch));
  return True;
  };
Exemplo n.º 16
0
/*** contributions from the mirror image HIII ***/
static double
strikexHIII (MagComp component, const fault_params *fault, const magnetic_params *mag, double xi, double et, double qq, double y, double z)
{
	double val;
	double h = mag->dcurier;
	double qd = y * sd + (fault->fdepth - h) * cd;
	double K1_val = K1 (component, 1.0, xi, et, qq);
	double atan_xe_qr_val = atan_xe_qr (component, 1.0, xi, et, qq);
	double J1_val = J1 (component, 1.0, xi, et, qq);
	double M1_val = M1 (component, 1.0, xi, et, qq);
	double L1_val = L1 (component, 1.0, xi, et, qq);

	val = - alpha4 * K1_val
		+ alpha1 * atan_xe_qr_val + alpha3 * J1_val
		+ alpha3 * (qd * M1_val + (z - h) * L1_val * sd);

	return val;
}
Exemplo n.º 17
0
///////////////////////////////////////////////////////////////////////////////
//
// Calculate the fundamental matrix and set to F, returning the residual of
// the fit.
//
///////////////////////////////////////////////////////////////////////////////
double FSolver::solve() {
  Frprmn<FSolver>	mySolver(*this, 1e-7);	// solver
  VecDoub 		p(9);			// parameters for solver
  int			n;
  transformMatrix	M1(inverse_intrinsic,1.0,1.0,0.0,0.0);

  // --- initial guess
  // -----------------
  F() = M1;

  for(n = 0; n<9; ++n) {
    p[n] = F()[n/3][n%3];
  }
  p = mySolver.minimize(p);
  for(n = 0; n<9; ++n) {
    F()[n/3][n%3] = p[n];
  }
  return((*this)(p));
}
Exemplo n.º 18
0
VRDisplayNode* VRLookAtNode::create(VRMainInterface *vrMain, VRDataIndex *config, const std::string &nameSpace) {
	
	VRMatrix4 lookAtMatrix;

	if (config->exists("LookAtMatrix", nameSpace)){
		lookAtMatrix = config->getValue("LookAtMatrix", nameSpace);
	} 
	else if (config->exists("LookAtUp", nameSpace) && config->exists("LookAtEye", nameSpace) && config->exists("LookAtCenter", nameSpace))
	{
		VRVector3 up = config->getValue("LookAtUp", nameSpace);
		VRVector3 eye = config->getValue("LookAtEye", nameSpace);
		VRVector3 center = config->getValue("LookAtCenter", nameSpace);

		VRVector3 z = center - eye;
		z = z.normalize();
		VRVector3 x = up.cross(z);
		x = x.normalize();
		VRVector3 y = z.cross(x);
		
		VRMatrix4 M1(	x[0], y[0], z[0], 0,
						x[1], y[1], z[1], 0,
						x[2], y[2], z[2], 0,
						0, 0, 0, 1);

		VRMatrix4 M2(	1, 0, 0, -eye[0],
						0, 1, 0, -eye[1],
						0, 0, 1, -eye[2],
						0, 0, 0, 1);

		lookAtMatrix =  M1 * M2;
	}
	else
	{
		std::cerr << "Warning : no LookAtMatrix defined for " << nameSpace << std::endl;
		std::cerr << "Either Define  LookAtMatrix or LookAtUp,LookAEye and LookAtCenter" << std::endl;
		std::cerr << "Using IdentityMatrix as default 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 " << std::endl;
	}

	VRLookAtNode *node = new VRLookAtNode(nameSpace, lookAtMatrix);

	return node;
}
Exemplo n.º 19
0
//======================================================================
tensor EightNode_Brick_u_p::getMassTensorM1()
{
    int M1_dim[] = {Num_Nodes,Num_Nodes};
    tensor M1(2,M1_dim,0.0);
    tensor Mm1(2,M1_dim,0.0);

    double r  = 0.0;
    double rw = 0.0;
    double s  = 0.0;
    double sw = 0.0;
    double t  = 0.0;
    double tw = 0.0;
    double weight = 0.0;
    double det_of_Jacobian = 1.0;

    tensor h;
    tensor Jacobian;
    double rho_0 = (1.0-nf)*rho_s + nf*rho_f;

    int GP_c_r, GP_c_s, GP_c_t;

    for( GP_c_r = 0 ; GP_c_r < Num_IntegrationPts; GP_c_r++ ) {
      r = pts[GP_c_r];
      rw = wts[GP_c_r];
      for( GP_c_s = 0 ; GP_c_s < Num_IntegrationPts; GP_c_s++ ) {
        s = pts[GP_c_s];
        sw = wts[GP_c_s];
        for( GP_c_t = 0 ; GP_c_t < Num_IntegrationPts; GP_c_t++ ) {
          t = pts[GP_c_t];
          tw = wts[GP_c_t];
          Jacobian = this->Jacobian_3D(r,s,t);
          det_of_Jacobian  = Jacobian.determinant();
          h = shapeFunction(r,s,t);
          weight = rw * sw * tw * det_of_Jacobian;
          Mm1 = h("m")*h("n");
          M1 += Mm1*(weight*rho_0);
        }
      }
    }

    return M1;
}
Exemplo n.º 20
0
TEST(ResMonoidDense, create)
{
  ResMonoidDense M1(4,
                    std::vector<int>{1, 1, 1, 1},
                    std::vector<int>{},
                    MonomialOrderingType::GRevLex);

  ResMonoidDense M2(4,
                    std::vector<int>{1, 2, 3, 4},
                    std::vector<int>{1, 1, 1, 1, 1, 1, 0, 0},
                    MonomialOrderingType::Weights);

  ResMonoidDense M3(4,
                    std::vector<int>{1, 1, 1, 1},
                    std::vector<int>{},
                    MonomialOrderingType::Lex);

  EXPECT_EQ(4, M1.n_vars());
  std::vector<res_monomial_word> monomspace(100);
  EXPECT_EQ(100, monomspace.size());
}
Exemplo n.º 21
0
/*** contributions from the mirror image H0 ***/
static double
strikexH0 (MagComp component, const fault_params *fault, const magnetic_params *mag, double xi, double et, double qq, double y, double z)
{
	double val;
	double h = mag->dcurier;
	double qd = y * sd + (fault->fdepth - h) * cd;
	double K1_val = K1 (component, 1.0, xi, et, qq);
	double atan_xe_qr_val = atan_xe_qr (component, 1.0, xi, et, qq);
	double J1_val = J1 (component, 1.0, xi, et, qq);
	double M1_val = M1 (component, 1.0, xi, et, qq);
	double L1_val = L1 (component, 1.0, xi, et, qq);
	double M1y_val = M1y (component, 1.0, xi, et, qq);
	double M1z_val = M1z (component, 1.0, xi, et, qq);

	val = - (2.0 - alpha4) * K1_val
		- alpha1 * atan_xe_qr_val - alpha3 * J1_val
		- alpha3 * (qd * M1_val + (z - h) * L1_val * sd)
		- 2.0 * alpha4 * h * (M1_val * cd - L1_val * sd)
		- 4.0 * alpha1 * h * L1_val * sd
		+ 2.0 * alpha2 * h * ((qd + h * cd) * M1z_val - (z - 2.0 * h) * M1y_val * sd);

	return val;
}
Exemplo n.º 22
0
int main()
{
  try {
    vpMatrix M ;
    vpMatrix M1(2,3) ;
    vpMatrix M2(3,3) ;
    vpMatrix M3(2,2) ;

    vpTRACE("test matrix size in multiply") ;

    try
    {
      M = M1*M3 ;
    }
    catch (vpMatrixException me)
    {
      std::cout << me << std::endl ;
    }


    vpTRACE("test matrix size in addition") ;

    try
    {
      M = M1+M3 ;
    }
    catch (vpMatrixException me)
    {
      std::cout << me << std::endl ;
    }
  }
  catch(vpException e) {
    std::cout << "Catch an exception: " << e << std::endl;
    return 1;
  }
}
Exemplo n.º 23
0
SEXP wink_both_par( SEXP data1, SEXP data2, SEXP windows, SEXP Rdelta, SEXP RB, SEXP Rnt) throw()
{
    
    
    parameters param;
    if( !param.load(data1,data2,windows,Rdelta,RB) )
        return R_NilValue;
    
    //==========================================================================
    // Get num_threads
    //==========================================================================
    Rnt = coerceVector(Rnt,INTSXP);
    size_t num_threads = INTEGER(Rnt)[0];
    Rprintf("\t#### num_threads=%u\n",unsigned(num_threads));
    if(num_threads<=0)
        num_threads = 1;
    
    
    try
    {
        //======================================================================
        // transform R data intro C++ objects
        //======================================================================
        wink::c_matrix     M1(param.nrow1,param.ncol1);
        wink::c_matrix     M2(param.nrow2,param.ncol2);
        
        M1.loadR( REAL(data1) );
        M2.loadR( REAL(data2) );
        
        //======================================================================
        // create the return vector
        //======================================================================
        SEXP Rval;
        PROTECT(Rval = allocMatrix(REALSXP,2,param.num_windows) );
        double *pvalues = REAL(Rval);
        
        //======================================================================
        // create the team of threads, starting ASAP
        //======================================================================
        wink::workers team(M1,
                           M2,
                           param.B,
                           num_threads,
                           param.num_windows,
                           param.ptr_windows,
                           pvalues,
                           param.delta,
                           &wink::worker::compute_pvalues_both);
        
        //======================================================================
        // wait for threads to complete
        //======================================================================
        team.wait();
        
        UNPROTECT(1);
        return Rval;
    }
    catch(...)
    {
        Rprintf("Exception in wink_both_par");
    }
    
    return R_NilValue;
}
Exemplo n.º 24
0
void XHalfGCD(zz_pXMatrix& M_out, zz_pX& U, zz_pX& V, long d_red)
{
   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
      set(M_out(0,0));   clear(M_out(0,1));
      clear(M_out(1,0)); set(M_out(1,1));
 
      return;
   }

   long du = deg(U);

   if (d_red <= NTL_zz_pX_HalfGCD_CROSSOVER) {
      IterHalfGCD(M_out, U, V, d_red);
      return;
   }

   long d1 = (d_red + 1)/2;
   if (d1 < 1) d1 = 1;
   if (d1 >= d_red) d1 = d_red - 1;

   zz_pXMatrix M1;

   HalfGCD(M1, U, V, d1);
   mul(U, V, M1);

   long d2 = deg(V) - du + d_red;

   if (IsZero(V) || d2 <= 0) {
      M_out = M1;
      return;
   }


   zz_pX Q;
   zz_pXMatrix M2;

   DivRem(Q, U, U, V);
   swap(U, V);

   XHalfGCD(M2, U, V, d2);

   zz_pX t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);

   mul(t, Q, M1(1,0));
   sub(t, M1(0,0), t);
   swap(M1(0,0), M1(1,0));
   swap(M1(1,0), t);

   t.kill();

   t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);

   mul(t, Q, M1(1,1));
   sub(t, M1(0,1), t);
   swap(M1(0,1), M1(1,1));
   swap(M1(1,1), t);

   t.kill();

   mul(M_out, M2, M1); 
}
Exemplo n.º 25
0
void HalfGCD(zz_pXMatrix& M_out, const zz_pX& U, const zz_pX& V, long d_red)
{
   if (IsZero(V) || deg(V) <= deg(U) - d_red) {
      set(M_out(0,0));   clear(M_out(0,1));
      clear(M_out(1,0)); set(M_out(1,1));
 
      return;
   }


   long n = deg(U) - 2*d_red + 2;
   if (n < 0) n = 0;

   zz_pX U1, V1;

   RightShift(U1, U, n);
   RightShift(V1, V, n);

   if (d_red <= NTL_zz_pX_HalfGCD_CROSSOVER) {
      IterHalfGCD(M_out, U1, V1, d_red);
      return;
   }

   long d1 = (d_red + 1)/2;
   if (d1 < 1) d1 = 1;
   if (d1 >= d_red) d1 = d_red - 1;

   zz_pXMatrix M1;

   HalfGCD(M1, U1, V1, d1);
   mul(U1, V1, M1);

   long d2 = deg(V1) - deg(U) + n + d_red;

   if (IsZero(V1) || d2 <= 0) {
      M_out = M1;
      return;
   }


   zz_pX Q;
   zz_pXMatrix M2;

   DivRem(Q, U1, U1, V1);
   swap(U1, V1);

   HalfGCD(M2, U1, V1, d2);

   zz_pX t(INIT_SIZE, deg(M1(1,1))+deg(Q)+1);

   mul(t, Q, M1(1,0));
   sub(t, M1(0,0), t);
   swap(M1(0,0), M1(1,0));
   swap(M1(1,0), t);

   t.kill();

   t.SetMaxLength(deg(M1(1,1))+deg(Q)+1);

   mul(t, Q, M1(1,1));
   sub(t, M1(0,1), t);
   swap(M1(0,1), M1(1,1));
   swap(M1(1,1), t);

   t.kill();

   mul(M_out, M2, M1); 
}
Exemplo n.º 26
0
	inline Float R(int m, int n) const {
		return M1(m+1, n+1);
	}
Exemplo n.º 27
0
SEXP wink_both_ser( SEXP data1, SEXP data2, SEXP windows, SEXP Rdelta, SEXP RB) throw()
{
    
    parameters param;
    if( !param.load(data1,data2,windows,Rdelta,RB) )
        return R_NilValue;
    
    //==========================================================================
    // create the return matrix
    //==========================================================================
    SEXP Rval;
    PROTECT(Rval = allocMatrix(REALSXP,2,param.num_windows) );
    double *ans = REAL(Rval);

    try 
    {
        //======================================================================
        // transform R data intro C++ objects
        //======================================================================
        wink::c_matrix     M1(param.nrow1,param.ncol1);
        wink::c_matrix     M2(param.nrow2,param.ncol2);
        
        M1.loadR( REAL(data1) );
        M2.loadR( REAL(data2) );
        
        //======================================================================
        // make C++ neuro_pair, init random generator
        //======================================================================
        wink::neuro_pair   NP(M1,M2,param.B);
        NP.g.seed( wink::neuro_pair::shared_seed + uint32_t(time(NULL)) );
        
        
               
        //======================================================================
        // outer loop on windows
        //======================================================================
        for( size_t i=0; i < param.num_windows; ++i )
        {
            const size_t i2 = i*2;
            const size_t i3 = i2+1;
            //------------------------------------------------------------------
            // get the boundaries
            //------------------------------------------------------------------
            const double a = param.ptr_windows[i2];
            const double b = param.ptr_windows[i3];
            
            //------------------------------------------------------------------
            // call the integrated function
            //------------------------------------------------------------------
            double &pvalue_geq = ans[ i2 ];
            double &pvalue_leq = ans[ i3 ];
            //Rprintf("[%10.6f,%10.6f] :  true_coinc=%6u : pvalue= %.8f\n",a,b,unsigned(NP.true_coinc),pvalue);
            NP.both_pvalues(pvalue_geq,pvalue_leq,a,b,param.delta);
        }
        UNPROTECT(1);
        
        return Rval;
    }
    catch(...)
    {
        Rprintf("Exception in code");
    }
    return R_NilValue;
    
}
Exemplo n.º 28
0
int test_string_cast_vector()
{
	int Error = 0;

	{
		glm::vec2 A1(1, 2);
		std::string A2 = glm::to_string(A1);
		Error += A2 != std::string("vec2(1.000000, 2.000000)") ? 1 : 0;
	
		glm::vec3 B1(1, 2, 3);
		std::string B2 = glm::to_string(B1);
		Error += B2 != std::string("vec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;

		glm::vec4 C1(1, 2, 3, 4);
		std::string C2 = glm::to_string(C1);
		Error += C2 != std::string("vec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
	
		glm::dvec2 J1(1, 2);
		std::string J2 = glm::to_string(J1);
		Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
	
		glm::dvec3 K1(1, 2, 3);
		std::string K2 = glm::to_string(K1);
		Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
	
		glm::dvec4 L1(1, 2, 3, 4);
		std::string L2 = glm::to_string(L1);
		Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
	}

	{
		glm::bvec2 M1(false, true);
		std::string M2 = glm::to_string(M1);
		Error += M2 != std::string("bvec2(false, true)") ? 1 : 0;
	
		glm::bvec3 O1(false, true, false);
		std::string O2 = glm::to_string(O1);
		Error += O2 != std::string("bvec3(false, true, false)") ? 1 : 0;

		glm::bvec4 P1(false, true, false, true);
		std::string P2 = glm::to_string(P1);
		Error += P2 != std::string("bvec4(false, true, false, true)") ? 1 : 0;
	}

	{
		glm::ivec2 D1(1, 2);
		std::string D2 = glm::to_string(D1);
		Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
	
		glm::ivec3 E1(1, 2, 3);
		std::string E2 = glm::to_string(E1);
		Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
	
		glm::ivec4 F1(1, 2, 3, 4);
		std::string F2 = glm::to_string(F1);
		Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
	}

	{
		glm::i8vec2 D1(1, 2);
		std::string D2 = glm::to_string(D1);
		Error += D2 != std::string("i8vec2(1, 2)") ? 1 : 0;
	
		glm::i8vec3 E1(1, 2, 3);
		std::string E2 = glm::to_string(E1);
		Error += E2 != std::string("i8vec3(1, 2, 3)") ? 1 : 0;
	
		glm::i8vec4 F1(1, 2, 3, 4);
		std::string F2 = glm::to_string(F1);
		Error += F2 != std::string("i8vec4(1, 2, 3, 4)") ? 1 : 0;
	}

	{
		glm::i16vec2 D1(1, 2);
		std::string D2 = glm::to_string(D1);
		Error += D2 != std::string("i16vec2(1, 2)") ? 1 : 0;
	
		glm::i16vec3 E1(1, 2, 3);
		std::string E2 = glm::to_string(E1);
		Error += E2 != std::string("i16vec3(1, 2, 3)") ? 1 : 0;
	
		glm::i16vec4 F1(1, 2, 3, 4);
		std::string F2 = glm::to_string(F1);
		Error += F2 != std::string("i16vec4(1, 2, 3, 4)") ? 1 : 0;
	}

	{
		glm::i64vec2 D1(1, 2);
		std::string D2 = glm::to_string(D1);
		Error += D2 != std::string("i64vec2(1, 2)") ? 1 : 0;
	
		glm::i64vec3 E1(1, 2, 3);
		std::string E2 = glm::to_string(E1);
		Error += E2 != std::string("i64vec3(1, 2, 3)") ? 1 : 0;
	
		glm::i64vec4 F1(1, 2, 3, 4);
		std::string F2 = glm::to_string(F1);
		Error += F2 != std::string("i64vec4(1, 2, 3, 4)") ? 1 : 0;
	}

	return Error;
}
Exemplo n.º 29
0
unsigned
vcl_fixed_token(const char *p, const char **q)
{

	switch (p[0]) {
	case '!':
		M2('=', T_NEQ);
		M2('~', T_NOMATCH);
		M1();
	case '%':
		M1();
	case '&':
		M2('&', T_CAND);
		M1();
	case '(':
		M1();
	case ')':
		M1();
	case '*':
		M2('=', T_MUL);
		M1();
	case '+':
		M2('+', T_INC);
		M2('=', T_INCR);
		M1();
	case ',':
		M1();
	case '-':
		M2('-', T_DEC);
		M2('=', T_DECR);
		M1();
	case '.':
		M1();
	case '/':
		M2('=', T_DIV);
		M1();
	case ';':
		M1();
	case '<':
		M2('<', T_SHL);
		M2('=', T_LEQ);
		M1();
	case '=':
		M2('=', T_EQ);
		M1();
	case '>':
		M2('=', T_GEQ);
		M2('>', T_SHR);
		M1();
	case 'e':
		if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' &&
		    p[4] == 'i' && p[5] == 'f' && !isvar(p[6])) {
			*q = p + 6;
			return (T_ELSEIF);
		}
		if (p[1] == 'l' && p[2] == 's' && p[3] == 'i' &&
		    p[4] == 'f' && !isvar(p[5])) {
			*q = p + 5;
			return (T_ELSIF);
		}
		if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' &&
		    !isvar(p[4])) {
			*q = p + 4;
			return (T_ELSE);
		}
		return (0);
	case 'i':
		if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' &&
		    p[4] == 'u' && p[5] == 'd' && p[6] == 'e' &&
		    !isvar(p[7])) {
			*q = p + 7;
			return (T_INCLUDE);
		}
		M2('f', T_IF);
		return (0);
	case '{':
		M1();
	case '|':
		M2('|', T_COR);
		M1();
	case '}':
		M1();
	case '~':
		M1();
	default:
		return (0);
	}
}
Exemplo n.º 30
0
void InitSLState( 
    const dTensorBC4& q, const dTensorBC4& aux, SL_state& sl_state )
{

    void ComputeElecField(double t, const dTensor2& node1d,
            const dTensorBC4& qvals, dTensorBC3& Evals);
    void ConvertQ2dToQ1d(const int &mopt, int istart, int iend, 
                     const dTensorBC4& qin, dTensorBC3& qout);
    void IntegrateQ1dMoment1(const dTensorBC4& q2d, dTensorBC3& q1d);

    const int space_order = dogParams.get_space_order();

    const int mx   = q.getsize(1);
    const int my   = q.getsize(2);
    const int meqn = q.getsize(3);
    const int maux = aux.getsize(2);
    const int kmax = q.getsize(4);
    const int mbc  = q.getmbc();
    const int mpoints = space_order*space_order;
    const int kmax1d  = space_order;

    const double tn     = sl_state.tn;

    //////////////////////// Compute Electric Field E(t) ////////////////////
    // save 1d grid points ( this is used for poisson solve )
    dTensorBC3 Enow(mx, meqn, kmax1d, mbc, 1);
    ComputeElecField( tn, *sl_state.node1d, *sl_state.qnew, Enow);

    //////////// Necessary terms for Et = -M1 + g(x,t) /////////////////////
    dTensorBC3 M1(mx, meqn, kmax1d,mbc,1); 
    IntegrateQ1dMoment1(q, M1);  // first moment

    //////////// Necessary terms for Ett = 2*KE_x - rho*E + g_t - psi_u ///////
    dTensorBC3 KE(mx, meqn, kmax1d,mbc,1); 
    void IntegrateQ1dMoment2(const dTensorBC4& q2d, dTensorBC3& q1d);
    IntegrateQ1dMoment2(q, KE);  // 1/2 * \int v^2 * f dv //

    SetBndValues1D( KE );
    SetBndValues1D( Enow );
    SetBndValues1D( M1 );

    // do something to compute KE_x ... //
    dTensorBC3 gradKE(mx,2,kmax1d,mbc,1);
    FiniteDiff( 1, 2, KE, gradKE ); // compute KE_x and KE_xx //

    dTensorBC3 rho(mx,meqn,kmax1d,mbc,1);
    dTensorBC3 prod(mx,meqn,kmax1d,mbc,1);
    void IntegrateQ1d(const int mopt, const dTensorBC4& q2d, dTensorBC3& q1d);
    void MultiplyFunctions(const dTensorBC3& Q1, const dTensorBC3& Q2,
        dTensorBC3& qnew);
    IntegrateQ1d( 1, q, rho );
    MultiplyFunctions( rho, Enow, prod );

    /////////////////////// Save E, Et, Ett, //////////////////////////////////
    for( int i = 1; i <= mx; i++ )
    for( int k = 1; k <= kmax1d; k ++ )
    {
        double E     =  Enow.get  ( i, 1, k );
        double Et    = -M1.get ( i, 1, k );  // + g(x,t)
        double Ett   = -prod.get(i,1,k) + 2.0*gradKE.get(i,1,k); // + others //

        sl_state.aux1d->set(i,2,1, k, E     );
        sl_state.aux1d->set(i,2,2, k, Et    );
        sl_state.aux1d->set(i,2,3, k, Ett   );

    }
    ///////////////////////////////////////////////////////////////////////////

    // terms used for 4th order stuff ... //
    // Ettt = -M3_xx + (2*E_x+rho)*M1 + 3*E*(M1)_x
    dTensorBC3 tmp0(mx,2*meqn,kmax1d,mbc,1);
    dTensorBC3 tmp1(mx,meqn,kmax1d,mbc,1);

    // compute the third moment and its 2nd derivative 
    dTensorBC3 M3    (mx,meqn,kmax1d,mbc,1);
    dTensorBC3 M3_x  (mx,2*meqn,kmax1d,mbc,1);
    void IntegrateQ1dMoment3(const dTensorBC4& q2d, dTensorBC3& q1d);
    IntegrateQ1dMoment3(q, M3 );
    SetBndValues1D( M3 );
    FiniteDiff( 1, 2, M3, M3_x );

    // Compute 2*Ex+rho //
    FiniteDiff(1, 2*meqn, Enow, tmp0);
    for( int i=1; i <= mx; i++ )
    for( int k=1; k <= kmax1d; k++ )
    { tmp1.set(i,1,k, 2.0*tmp0.get(i,1,k) + rho.get(i,1,k) ); }

    // compute (2Ex+rho) * M1
    dTensorBC3 prod1(mx,meqn,kmax1d,mbc,1);
    MultiplyFunctions( tmp1, M1, prod1 );

    // compute M1_x and M1_xx
    dTensorBC3 M1_x  (mx,2*meqn,kmax1d,mbc,1);
    FiniteDiff( 1, 2, M1, M1_x );

    //compute 3*M1_x and E * (3*M1)_x
    dTensorBC3 prod2(mx,meqn,kmax1d,mbc,1);
    for( int i=1; i <= mx; i++ )
    for( int k=1; k <= kmax1d; k++ )
    { tmp1.set(i, 1, k, 3.0*M1_x.get(i, 1, k) ); }
    MultiplyFunctions( Enow, tmp1, prod2 );

    /////////////////////// Save Ettt /////////////////////////////////////////
    for( int i = 1; i <= mx; i++ )
    for( int k = 1; k <= kmax1d; k ++ )
    {
        double Ettt  = -M3_x.get(i,2,k) + prod1.get(i,1,k) + prod2.get(i,1,k);
        sl_state.aux1d->set(i,2,4, k, Ettt );
    }
    ///////////////////////////////////////////////////////////////////////////

    if ( dogParams.get_source_term()>0 )
    {


        double* t_ptr = new double;
        *t_ptr = tn;

        // 2D Electric field, and 1D Electric Field
        dTensorBC4* ExactE;
        ExactE     = new dTensorBC4(mx,1,4,kmax,mbc);

        dTensorBC3* ExactE1d;
        ExactE1d   = new dTensorBC3(mx,4,kmax1d,mbc,1);

        // Extra Source terms needed for the electric field
        dTensorBC4* ExtraE;
        ExtraE     = new dTensorBC4(mx,1,4,kmax,mbc);

        dTensorBC3* ExtraE1d;
        ExtraE1d   = new dTensorBC3(mx,4,kmax1d,mbc,1);


        // Exact, electric field: (TODO - REMOVE THIS!)
//      void ElectricField(const dTensor2& xpts, dTensor2& e, void* data);
//      L2Project_extra(1-mbc, mx+mbc, 1, 1, space_order, -1, ExactE, 
//                      &ElectricField, (void*)t_ptr );
//      ConvertQ2dToQ1d(1, 1, mx, *ExactE, *ExactE1d);

        // Extra Source terms:
        void ExtraSourceWrap(const dTensor2& xpts, 
			     const dTensor2& NOT_USED_1, 
			     const dTensor2& NOT_USED_2,
			     dTensor2& e, 
			     void* data);
        L2Project_extra(1, mx, 1, 1, 20, space_order,
			space_order, space_order,
			&q, &aux, ExtraE, &ExtraSourceWrap, (void*)t_ptr );
        ConvertQ2dToQ1d(1, 1, mx, *ExtraE, *ExtraE1d);
  
        for( int i=1; i <= mx; i++ )
        for( int k=1; k <= kmax1d; k++ )
        {

            // electric fields w/o source term parts added in //
            double Et    = sl_state.aux1d->get(i,2,2,k);
            double Ett   = sl_state.aux1d->get(i,2,3,k);
            double Ettt  = sl_state.aux1d->get(i,2,4,k); 

            // add in missing terms from previously set values //
            sl_state.aux1d->set(i,2,2, k, Et    + ExtraE1d->get(i,2,k) );
            sl_state.aux1d->set(i,2,3, k, Ett   + ExtraE1d->get(i,3,k) );
            sl_state.aux1d->set(i,2,4, k, Ettt  + ExtraE1d->get(i,4,k) );

//          sl_state.aux1d->set(i,2,1, k, 0. );
//          sl_state.aux1d->set(i,2,2, k, 0. );
//          sl_state.aux1d->set(i,2,3, k, 0. );
//          sl_state.aux1d->set(i,2,4, k, 0. );


            // ADD IN EXACT ELECTRIC FIELD HERE:
//          sl_state.aux1d->set(i,2,1, k, ExactE1d->get(i,1,k) );
//          sl_state.aux1d->set(i,2,2, k, ExactE1d->get(i,2,k) );
//          sl_state.aux1d->set(i,2,3, k, ExactE1d->get(i,3,k) );
//          sl_state.aux1d->set(i,2,4, k, ExactE1d->get(i,4,k) );


        }

        delete ExactE;
        delete ExactE1d;
        delete t_ptr;
        delete ExtraE;
        delete ExtraE1d;

    }

    
}