Exemplo n.º 1
0
//反日差天数
int  revD0(int y,int x,int calType)   // y年日差天数D0为x
{
    int  j,m,mL;

    for(j=1; j<=12; j++)
    {
        mL=D0(y,j+1,1,calType)-D0(y,j,1,calType);

        if(x<=mL||j==12)
        {
            m=j;
            break;
        }
        else
        {
            x-=mL;
        }

    }

    if((calType==1)&&(y==1582&&m==10&&x>=5&&x<=14))
    {
        return Infinity;
    }

    return 100*m+x;
}
Exemplo n.º 2
0
void print_event(int event)
{
  switch (event) {
    case COALESCE:                      D0("Coalesce success:"); break;
    case EXTENSION:                     D0("Heap Extension  :"); break;
    case COALESCE_AND_EXTENSION:        D0("Coalesce-Extend :"); break;
  }
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
bool intersectsRect(Vector2 A, Vector2 B, double x, double y, double width, double height) {
    Vector2 C0(x, y);
    Vector2 D0(x + width, y);

    Vector2 C1(x + width, y);
    Vector2 D1(x + width, y + height);

    Vector2 C2(x + width, y + height);
    Vector2 D2(x, y + height);

    Vector2 C3(x, y + height);
    Vector2 D3(x, y);

    bool I0, I1, I2, I3;

    Vector2 buf;

    I0 = intersects(A, B, C0, D0, buf);
    I1 = intersects(A, B, C1, D1, buf);
    I2 = intersects(A, B, C2, D2, buf);
    I3 = intersects(A, B, C3, D3, buf);
    if(I0 || I1 || I2 || I3) {
        return false;
    }
    return true;
}
Exemplo n.º 5
0
void
_ShellEscape ( char * str )
{
    int returned = system ( str ) ;
    if ( _Q_->Verbosity > 1 ) Printf ( c_dd ( "\nCfrTil : system ( \"%s\" ) returned %d.\n" ), str, returned ) ;
    D0 ( CfrTil_PrintDataStack ( ) ) ;
    Interpreter_SetState ( _Context_->Interpreter0, DONE, true ) ; // 
}
Exemplo n.º 6
0
void
_Compile_InstructionX86 ( int opCode, int mod, int reg, int rm, int modFlag, int sib, int32 disp,
    int32 imm, int immSize )
{
    D0 ( byte *here = Here ) ;
    _Compile_Int8 ( ( byte ) opCode ) ;
    int32 modRm = _CalculateModRmByte ( mod, reg, rm, disp, sib ) ;
    _Compile_ModRmSibDisplacement ( modRm, modFlag, sib, disp ) ;
    _Compile_ImmediateData ( imm, immSize ) ;
    PeepHole_Optimize ( ) ;
    D0 ( if ( _CfrTil_->Debugger0 ) Debugger_UdisOneInstruction ( _CfrTil_->Debugger0, here, ( byte* ) "", ( byte* ) "" ) ; )
    }
Exemplo n.º 7
0
//标准天数(Standard Days)(y年m月d日距该历制的1年1月0日的天数)
int  SD(int y,int m,int d,int calType)
{
    if(ifGr(y,m,d,calType)==-1)
        return Infinity;

    if(ifGr(y,m,d,calType)==1)
        return (y-1)*365+floor((float)((y-1)/4))-floor((float)((y-1)/100))+floor((float)((y-1)/400))+D0(y,m,d,calType);   //Gregorian的标准天数

    else
        return (y-1)*365+floor((float)((y-1)/4))+D0(y,m,d,calType);                                     //Julian的标准天数

}
Exemplo n.º 8
0
void
ilinrec ( block ifBlock, block thenBlock, block else1Block, block else2Block )
{
    _Block_Eval ( ifBlock ) ;
    if ( _DataStack_Pop ( ) )
    {
        _Block_Eval ( thenBlock ) ;
    }
    else
    {
        _Block_Eval ( else1Block ) ;
        D0 ( CfrTil_PrintDataStack ( ) ) ;
        ilinrec ( ifBlock, thenBlock, else1Block, else2Block ) ;
        _Block_Eval ( else2Block ) ;
    }
}
Exemplo n.º 9
0
TYPED_TEST(Intesection_TEST, intersection_ray_triangle)
{
	using Scalar = typename cgogn::geometry::vector_traits<TypeParam>::Scalar;
	TypeParam p0(Scalar(1), Scalar(1), Scalar(96.1));
	TypeParam p1(Scalar(5), Scalar(1), Scalar(92.3));
	TypeParam p2(Scalar(3), Scalar(5), Scalar(94.2));

	TypeParam A0(Scalar(3), Scalar(3), Scalar(0));
	TypeParam D0(Scalar(0.001), Scalar(0.001), Scalar(1.0));

	TypeParam A1(Scalar(3), Scalar(1), Scalar(0));
	TypeParam D1(Scalar(0), Scalar(0), Scalar(1.0));
	TypeParam A2(Scalar(5), Scalar(1), Scalar(0));
	TypeParam A3(Scalar(9), Scalar(5), Scalar(0));

	EXPECT_TRUE(cgogn::geometry::intersection_ray_triangle(A0,D0,p0,p1,p2));
	EXPECT_TRUE(cgogn::geometry::intersection_ray_triangle(A1,D1,p0,p1,p2));
	EXPECT_TRUE(cgogn::geometry::intersection_ray_triangle(A2,D1,p0,p1,p2));
	EXPECT_FALSE(cgogn::geometry::intersection_ray_triangle(A3,D0,p0,p1,p2));

}
Exemplo n.º 10
0
//反标准天数
int  revSD(int x,int calType,int ifG)   //当calType==1且x==577736或x<=577737时,ifG才起作用,ifG=1表示返回的是标准日历的10-15和10-16日(是Gregorian),ifG=0表示返回的是标准日历的10-3和10-4日(是Julian)
{

    double u0=floor(x/365.25)+1;  //试探一个最小估计的年份值

    double u0D0=x-D(u0,calType);  //x的日差天数

    if((calType==1&&ifG==0)&&(x>=577461&&x<=577737))
    {
        u0D0-=12;
    }

    double u0L=D0(u0,12,31,calType);  //u0年的长度

    if(u0D0>u0L)
    {
        u0D0-=u0L;
        u0++;
    }

    return (int)(u0*10000+revD0(u0,u0D0,calType));
}
Exemplo n.º 11
0
static void MakeEventRec(int thisEvent, Event type, size_t size)
{
  statsP->nextEvent = thisEvent + 1;
  thisEvent %= MAXEVENTS;
  statsP->events[thisEvent].event = type;
  statsP->events[thisEvent].blockThatCausedEvent = size;
  statsP->events[thisEvent].userHeap = statsP->stats.userHeap;
  statsP->events[thisEvent].totalFree = totalFree;
  statsP->events[thisEvent].allocates = statsP->stats.blocksAllocated;
  statsP->events[thisEvent].deallocates = statsP->stats.blocksDeallocated;
  statsP->events[thisEvent].bytesAllocated = statsP->stats.bytesAllocated;
  statsP->events[thisEvent].bytesDeallocated = statsP->stats.bytesDeallocated;
  D0("!!MakeEventRec ");
  print_event(statsP->events[thisEvent].event);
  D1(" blockThatCausedEvent %u\n",
                               statsP->events[thisEvent].blockThatCausedEvent);
  D1("  userHeap %u, ", statsP->events[thisEvent].userHeap);
  D1("totalFree %u, ", statsP->events[thisEvent].totalFree);
  D1("allocates %u, ", statsP->events[thisEvent].allocates);
  D1("deallocates %u\n", statsP->events[thisEvent].deallocates);
  D1("  bytesAllocated %u, ", statsP->events[thisEvent].bytesAllocated);
  D1("bytesDeallocated %u, ", statsP->events[thisEvent].bytesDeallocated);
}
Exemplo n.º 12
0
	int test()
	{
		int Error = 0;

		int A0 = static_cast<int>(glm::log2(16.f));
		glm::ivec1 B0(glm::log2(glm::vec1(16.f)));
		glm::ivec2 C0(glm::log2(glm::vec2(16.f)));
		glm::ivec3 D0(glm::log2(glm::vec3(16.f)));
		glm::ivec4 E0(glm::log2(glm::vec4(16.f)));

		int A1 = glm::log2(int(16));
		glm::ivec1 B1 = glm::log2(glm::ivec1(16));
		glm::ivec2 C1 = glm::log2(glm::ivec2(16));
		glm::ivec3 D1 = glm::log2(glm::ivec3(16));
		glm::ivec4 E1 = glm::log2(glm::ivec4(16));

		Error += A0 == A1 ? 0 : 1;
		Error += glm::all(glm::equal(B0, B1)) ? 0 : 1;
		Error += glm::all(glm::equal(C0, C1)) ? 0 : 1;
		Error += glm::all(glm::equal(D0, D1)) ? 0 : 1;
		Error += glm::all(glm::equal(E0, E1)) ? 0 : 1;

		glm::uint64 A2 = glm::log2(glm::uint64(16));
		glm::u64vec1 B2 = glm::log2(glm::u64vec1(16));
		glm::u64vec2 C2 = glm::log2(glm::u64vec2(16));
		glm::u64vec3 D2 = glm::log2(glm::u64vec3(16));
		glm::u64vec4 E2 = glm::log2(glm::u64vec4(16));

		Error += A2 == glm::uint64(4) ? 0 : 1;
		Error += glm::all(glm::equal(B2, glm::u64vec1(4))) ? 0 : 1;
		Error += glm::all(glm::equal(C2, glm::u64vec2(4))) ? 0 : 1;
		Error += glm::all(glm::equal(D2, glm::u64vec3(4))) ? 0 : 1;
		Error += glm::all(glm::equal(E2, glm::u64vec4(4))) ? 0 : 1;

		return Error;
	}
Exemplo n.º 13
0
	int test()
	{
		int Error = 0;

		int A0(glm::log2(10.f));
		glm::ivec1 B0(glm::log2(glm::vec1(10.f)));
		glm::ivec2 C0(glm::log2(glm::vec2(10.f)));
		glm::ivec3 D0(glm::log2(glm::vec3(10.f)));
		glm::ivec4 E0(glm::log2(glm::vec4(10.f)));

		int A1 = glm::log2(int(10.f));
		glm::ivec1 B1 = glm::log2(glm::ivec1(10.f));
		glm::ivec2 C1 = glm::log2(glm::ivec2(10.f));
		glm::ivec3 D1 = glm::log2(glm::ivec3(10.f));
		glm::ivec4 E1 = glm::log2(glm::ivec4(10.f));

		Error += A0 == A1 ? 0 : 1;
		Error += glm::all(glm::equal(B0, B1)) ? 0 : 1;
		Error += glm::all(glm::equal(C0, C1)) ? 0 : 1;
		Error += glm::all(glm::equal(D0, D1)) ? 0 : 1;
		Error += glm::all(glm::equal(E0, E1)) ? 0 : 1;

		return Error;
	}
Exemplo n.º 14
0
void Trr2kNNNT
( UpperOrLower uplo,
  Orientation orientationOfD,
  T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B,
           const DistMatrix<T>& C, const DistMatrix<T>& D,
  T beta,        DistMatrix<T>& E )
{
#ifndef RELEASE
    PushCallStack("internal::Trr2kNNNT");
    if( E.Height() != E.Width()  || A.Width()  != C.Width()  ||
        A.Height() != E.Height() || C.Height() != E.Height() ||
        B.Width()  != E.Width()  || D.Height() != E.Width()  ||
        A.Width()  != B.Height() || C.Width()  != D.Width() )
        throw std::logic_error("Nonconformal Trr2kNNNT");
#endif
    const Grid& g = E.Grid();

    DistMatrix<T> AL(g), AR(g),
                  A0(g), A1(g), A2(g);
    DistMatrix<T> BT(g),  B0(g),
                  BB(g),  B1(g),
                          B2(g);

    DistMatrix<T> CL(g), CR(g),
                  C0(g), C1(g), C2(g);
    DistMatrix<T> DL(g), DR(g),
                  D0(g), D1(g), D2(g);

    DistMatrix<T,MC,  STAR> A1_MC_STAR(g);
    DistMatrix<T,MR,  STAR> B1Trans_MR_STAR(g);
    DistMatrix<T,MC,  STAR> C1_MC_STAR(g);
    DistMatrix<T,VR,  STAR> D1_VR_STAR(g);
    DistMatrix<T,STAR,MR  > D1AdjOrTrans_STAR_MR(g);

    A1_MC_STAR.AlignWith( E );
    B1Trans_MR_STAR.AlignWith( E );
    C1_MC_STAR.AlignWith( E );
    D1_VR_STAR.AlignWith( E );
    D1AdjOrTrans_STAR_MR.AlignWith( E );

    LockedPartitionRight( A, AL, AR, 0 );
    LockedPartitionDown
    ( B, BT,
         BB, 0 );
    LockedPartitionRight( C, CL, CR, 0 );
    LockedPartitionRight( D, DL, DR, 0 );
    while( AL.Width() < A.Width() )
    {
        LockedRepartitionRight
        ( AL, /**/ AR,
          A0, /**/ A1, A2 );
        LockedRepartitionDown
        ( BT,  B0,
         /**/ /**/
               B1,
          BB,  B2 );
        LockedRepartitionRight
        ( CL, /**/ CR,
          C0, /**/ C1, C2 );
        LockedRepartitionRight
        ( CL, /**/ CR,
          C0, /**/ C1, C2 );

        //--------------------------------------------------------------------//
        A1_MC_STAR = A1;
        C1_MC_STAR = C1;
        B1Trans_MR_STAR.TransposeFrom( B1 );
        D1_VR_STAR = D1;
        if( orientationOfD == ADJOINT )
            D1AdjOrTrans_STAR_MR.AdjointFrom( D1_VR_STAR );
        else
            D1AdjOrTrans_STAR_MR.TransposeFrom( D1_VR_STAR );
        LocalTrr2k
        ( uplo, TRANSPOSE, 
          alpha, A1_MC_STAR, B1Trans_MR_STAR, 
                 C1_MC_STAR, D1AdjOrTrans_STAR_MR,
          beta,  E );
        //--------------------------------------------------------------------//

        SlideLockedPartitionRight
        ( DL,     /**/ DR,
          D0, D1, /**/ D2 );
        SlideLockedPartitionRight
        ( CL,     /**/ CR,
          C0, C1, /**/ C2 );
        SlideLockedPartitionDown
        ( BT,  B0,
               B1,
         /**/ /**/
          BB,  B2 );
        SlideLockedPartitionRight
        ( AL,     /**/ AR,
          A0, A1, /**/ A2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Exemplo n.º 15
0
complex LoopToolsWrapper::PV_D0(const double s, const double t, const double m02,
                                const double m12, const double m22, const double m32) const
{
    std::complex<double> D0val = D0(0.0, 0.0, 0.0, 0.0, s, t, m02, m12, m22, m32);
    return complex( D0val.real(), D0val.imag(), false );
}
Exemplo n.º 16
0
	typename IntrEllipsoid3Ellipsoid3<Real>::Classification
		IntrEllipsoid3Ellipsoid3<Real>::GetClassification () const
	{
		// Get the parameters of ellipsoid0.
		Vector3<Real> K0 = mEllipsoid0->Center;
		Matrix3<Real> R0(mEllipsoid0->Axis, true);
		Matrix3<Real> D0(
			((Real)1)/(mEllipsoid0->Extent[0]*mEllipsoid0->Extent[0]),
			((Real)1)/(mEllipsoid0->Extent[1]*mEllipsoid0->Extent[1]),
			((Real)1)/(mEllipsoid0->Extent[2]*mEllipsoid0->Extent[2]));

		// Get the parameters of ellipsoid1.
		Vector3<Real> K1 = mEllipsoid1->Center;
		Matrix3<Real> R1(mEllipsoid1->Axis, true);
		Matrix3<Real> D1(
			((Real)1)/(mEllipsoid1->Extent[0]*mEllipsoid1->Extent[0]),
			((Real)1)/(mEllipsoid1->Extent[1]*mEllipsoid1->Extent[1]),
			((Real)1)/(mEllipsoid1->Extent[2]*mEllipsoid1->Extent[2]));

		// Compute K2.
		Matrix3<Real> D0NegHalf(
			mEllipsoid0->Extent[0],
			mEllipsoid0->Extent[1],
			mEllipsoid0->Extent[2]);
		Matrix3<Real> D0Half(
			((Real)1)/mEllipsoid0->Extent[0],
			((Real)1)/mEllipsoid0->Extent[1],
			((Real)1)/mEllipsoid0->Extent[2]);
		Vector3<Real> K2 = D0Half*((K1 - K0)*R0);

		// Compute M2.
		Matrix3<Real> R1TR0D0NegHalf = R1.TransposeTimes(R0*D0NegHalf);
		Matrix3<Real> M2 = R1TR0D0NegHalf.TransposeTimes(D1)*R1TR0D0NegHalf;

		// Factor M2 = R*D*R^T.
		Matrix3<Real> R, D;
		M2.EigenDecomposition(R, D);

		// Compute K = R^T*K2.
		Vector3<Real> K = K2*R;

		// Transformed ellipsoid0 is Z^T*Z = 1 and transformed ellipsoid1 is
		// (Z-K)^T*D*(Z-K) = 0.

		// The minimum and maximum squared distances from the origin of points on
		// transformed ellipsoid1 are used to determine whether the ellipsoids
		// intersect, are separated, or one contains the other.
		Real minSqrDistance = Math<Real>::MAX_REAL;
		Real maxSqrDistance = (Real)0;
		int i;

		if (K == Vector3<Real>::ZERO)
		{
			// The special case of common centers must be handled separately.  It
			// is not possible for the ellipsoids to be separated.
			for (i = 0; i < 3; ++i)
			{
				Real invD = ((Real)1)/D[i][i];
				if (invD < minSqrDistance)
				{
					minSqrDistance = invD;
				}
				if (invD > maxSqrDistance)
				{
					maxSqrDistance = invD;
				}
			}

			if (maxSqrDistance < (Real)1)
			{
				return EC_ELLIPSOID0_CONTAINS_ELLIPSOID1;
			}
			else if (minSqrDistance > (Real)1)
			{
				return EC_ELLIPSOID1_CONTAINS_ELLIPSOID0;
			}
			else
			{
				return EC_ELLIPSOIDS_INTERSECTING;
			}
		}

		// The closest point P0 and farthest point P1 are solutions to
		// s0*D*(P0 - K) = P0 and s1*D*(P1 - K) = P1 for some scalars s0 and s1
		// that are roots to the function
		//   f(s) = d0*k0^2/(d0*s-1)^2+d1*k1^2/(d1*s-1)^2+d2*k2^2/(d2*s-1)^2-1
		// where D = diagonal(d0,d1,d2) and K = (k0,k1,k2).
		Real d0 = D[0][0], d1 = D[1][1], d2 = D[2][2];
		Real c0 = K[0]*K[0], c1 = K[1]*K[1], c2 = K[2]*K[2];

		// Sort the values so that d0 >= d1 >= d2.  This allows us to bound the
		// roots of f(s), of which there are at most 6.
		std::vector<std::pair<Real,Real> > param(3);
		param[0] = std::make_pair(d0, c0);
		param[1] = std::make_pair(d1, c1);
		param[2] = std::make_pair(d2, c2);
		std::sort(param.begin(), param.end(),
			std::greater<std::pair<Real,Real> >());

		std::vector<std::pair<Real,Real> > valid;
		valid.reserve(3);
		if (param[0].first > param[1].first)
		{
			if (param[1].first > param[2].first)
			{
				// d0 > d1 > d2
				for (i = 0; i < 3; ++i)
				{
					if (param[i].second > (Real)0)
					{
						valid.push_back(param[i]);
					}
				}
			}
			else
			{
				// d0 > d1 = d2
				if (param[0].second > (Real)0)
				{
					valid.push_back(param[0]);
				}
				param[1].second += param[0].second;
				if (param[1].second > (Real)0)
				{
					valid.push_back(param[1]);
				}
			}
		}
		else
		{
			if (param[1].first > param[2].first)
			{
				// d0 = d1 > d2
				param[0].second += param[1].second;
				if (param[0].second > (Real)0)
				{
					valid.push_back(param[0]);
				}
				if (param[2].second > (Real)0)
				{
					valid.push_back(param[2]);
				}
			}
			else
			{
				// d0 = d1 = d2
				param[0].second += param[1].second + param[2].second;
				if (param[0].second > (Real)0)
				{
					valid.push_back(param[0]);
				}
			}
		}

		size_t numValid = valid.size();
		int numRoots;
		Real roots[6];
		if (numValid == 3)
		{
			GetRoots(
				valid[0].first, valid[1].first, valid[2].first,
				valid[0].second, valid[1].second, valid[2].second,
				numRoots, roots);
		}
		else if (numValid == 2)
		{
			GetRoots(
				valid[0].first, valid[1].first,
				valid[0].second, valid[1].second,
				numRoots, roots);
		}
		else if (numValid == 1)
		{
			GetRoots(
				valid[0].first,
				valid[0].second,
				numRoots, roots);
		}
		else
		{
			// numValid cannot be zero because we already handled case K = 0
			assertion(false, "Unexpected condition.\n");
			return EC_ELLIPSOIDS_INTERSECTING;
		}

		for (i = 0; i < numRoots; ++i)
		{
			Real s = roots[i];
			Real p0 = d0*K[0]*s/(d0*s - (Real)1);
			Real p1 = d1*K[1]*s/(d1*s - (Real)1);
			Real p2 = d2*K[2]*s/(d2*s - (Real)1);
			Real sqrDistance = p0*p0 + p1*p1 + p2*p2;
			if (sqrDistance < minSqrDistance)
			{
				minSqrDistance = sqrDistance;
			}
			if (sqrDistance > maxSqrDistance)
			{
				maxSqrDistance = sqrDistance;
			}
		}

		if (maxSqrDistance < (Real)1)
		{
			return EC_ELLIPSOID0_CONTAINS_ELLIPSOID1;
		}

		if (minSqrDistance > (Real)1)
		{
			if (d0*c0 + d1*c1 + d2*c2 > (Real)1)
			{
				return EC_ELLIPSOIDS_SEPARATED;
			}
			else
			{
				return EC_ELLIPSOID1_CONTAINS_ELLIPSOID0;
			}
		}

		return EC_ELLIPSOIDS_INTERSECTING;
	}
Exemplo n.º 17
0
void SumProduct::accumulateEigenCounts (vguard<vguard<double> >& rootCounts, vguard<vguard<vguard<gsl_complex> > >& eigenCounts, double weight) const {
  LogThisAt(8,"Accumulating eigencounts, column " << join(gappedCol,"") << ", weight " << weight << endl);
  accumulateRootCounts (rootCounts, weight);

  const auto rootNode = columnRoot();
  const int A = model.alphabetSize();
  vguard<double> U (A), D (A);
  vguard<gsl_complex> Ubasis (A), Dbasis (A);
  vguard<double> U0 (A), D0 (A);
  for (auto node : ungappedRows)
    if (node != rootNode) {
      LogThisAt(9,"Accumulating eigencounts, column " << join(gappedCol,"") << " node " << tree.seqName(node) << endl);
      const TreeNodeIndex parent = tree.parentNode(node);
      const TreeNodeIndex sibling = tree.getSibling(node);
      for (int cpt = 0; cpt < components(); ++cpt) {
	LogThisAt(9,"Accumulating eigencounts, column " << join(gappedCol,"") << " node " << tree.seqName(node) << " component #" << cpt << endl);
	const vguard<double>& U0 = F[cpt][node];
	for (AlphTok i = 0; i < A; ++i)
	  D0[i] = G[cpt][parent][i] * E[cpt][sibling][i];
	const double maxU0 = *max_element (U0.begin(), U0.end());
	const double maxD0 = *max_element (D0.begin(), D0.end());
	const double norm = exp (colLogLike - logCptWeight[cpt] - logF[cpt][node] - logG[cpt][parent] - logE[cpt][sibling]) / (maxU0 * maxD0);

	// U[b] = U0[b] / maxU0; Ubasis[l] = sum_b U[b] * evecInv[l][b]
	for (AlphTok b = 0; b < A; ++b)
	  U[b] = U0[b] / maxU0;

	for (AlphTok l = 0; l < A; ++l) {
	  Ubasis[l] = gsl_complex_rect (0, 0);
	  for (AlphTok b = 0; b < A; ++b)
	    Ubasis[l] = gsl_complex_add
	      (Ubasis[l],
	       gsl_complex_mul_real (gsl_matrix_complex_get (eigen.evecInv[cpt], l, b),
				     U[b]));
	}

	// D[a] = D0[a] / maxD0; Dbasis[k] = sum_a D[a] * evec[a][k]
	for (AlphTok a = 0; a < A; ++a)
	  D[a] = D0[a] / maxD0;

	for (AlphTok k = 0; k < A; ++k) {
	  Dbasis[k] = gsl_complex_rect (0, 0);
	  for (AlphTok a = 0; a < A; ++a)
	    Dbasis[k] = gsl_complex_add
	      (Dbasis[k],
	       gsl_complex_mul_real (gsl_matrix_complex_get (eigen.evec[cpt], a, k),
				     D[a]));
	}

	// R = evec * evals * evecInv
	// exp(RT) = evec * exp(evals T) * evecInv
	// count(i,j|a,b,T) = Q / exp(RT)_ab
	// where...
	// Q = \sum_a \sum_b \int_{t=0}^T D_a exp(Rt)_ai R_ij exp(R(T-t))_jb U_b dt
	//   = \sum_a \sum_b \int_{t=0}^T D_a (\sum_k evec_ak exp(eval_k t) evecInv_ki) R_ij (\sum_l evec_jl exp(eval_l (T-t)) evecInv_lb) U_b dt
	//   = \sum_a \sum_b D_a \sum_k evec_ak evecInv_ki R_ij \sum_l evec_jl evecInv_lb U_b \int_{t=0}^T exp(eval_k t) exp(eval_l (T-t)) dt
	//   = \sum_a \sum_b D_a \sum_k evec_ak evecInv_ki R_ij \sum_l evec_jl evecInv_lb U_b eigenSubCount(k,l,T)
	//   = R_ij \sum_k evecInv_ki \sum_l evec_jl (\sum_a D_a evec_ak) (\sum_b U_b evecInv_lb) eigenSubCount(k,l,T)
	//   = R_ij \sum_k evecInv_ki \sum_l evec_jl Dbasis_k Ubasis_l eigenSubCount(k,l,T)

	// eigenCounts[k][l] += Dbasis[k] * eigenSub[k][l] * Ubasis[l] / norm
	for (AlphTok k = 0; k < A; ++k)
	  for (AlphTok l = 0; l < A; ++l)
	    eigenCounts[cpt][k][l] =
	      gsl_complex_add
	      (eigenCounts[cpt][k][l],
	       gsl_complex_mul_real
	       (gsl_complex_mul
		(Dbasis[k],
		 gsl_complex_mul
		 (gsl_matrix_complex_get (branchEigenSubCount[cpt][node], k, l),
		  Ubasis[l])),
		weight / norm));

	//	LogThisAt(9,"colLogLike=" << colLogLike << " logF[cpt][node]=" << logF[cpt][node] << " logG[cpt][parent]=" << logG[cpt][parent] << " logE[cpt][sibling]=" << logE[cpt][sibling] << " maxU0=" << maxU0 << " maxD0=" << maxD0 << endl);
	//	LogThisAt(8,"Component #" << cpt << " eigencounts matrix (norm=" << norm << "):" << endl << complexMatrixToString(eigenCounts[cpt]) << endl);
      }
    }
}
Exemplo n.º 18
0
void Trr2kNTTN
( UpperOrLower uplo,
  Orientation orientationOfB, Orientation orientationOfC,
  T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B,
           const DistMatrix<T>& C, const DistMatrix<T>& D,
  T beta,        DistMatrix<T>& E )
{
#ifndef RELEASE
    CallStackEntry entry("internal::Trr2kNTTN");
    if( E.Height() != E.Width()  || A.Width()  != C.Height() ||
        A.Height() != E.Height() || C.Width()  != E.Height() ||
        B.Height() != E.Width()  || D.Width()  != E.Width()  ||
        A.Width()  != B.Width()  || C.Height() != D.Height() )
        LogicError("Nonconformal Trr2kNTTN");
#endif
    const Grid& g = E.Grid();

    DistMatrix<T> AL(g), AR(g),
                  A0(g), A1(g), A2(g);
    DistMatrix<T> BL(g), BR(g),
                  B0(g), B1(g), B2(g);

    DistMatrix<T> CT(g),  C0(g),
                  CB(g),  C1(g),
                          C2(g);
    DistMatrix<T> DT(g),  D0(g),
                  DB(g),  D1(g),
                          D2(g);

    DistMatrix<T,MC,  STAR> A1_MC_STAR(g);
    DistMatrix<T,VR,  STAR> B1_VR_STAR(g);
    DistMatrix<T,STAR,MR  > B1AdjOrTrans_STAR_MR(g);
    DistMatrix<T,STAR,MC  > C1_STAR_MC(g);
    DistMatrix<T,MR,  STAR> D1Trans_MR_STAR(g);

    A1_MC_STAR.AlignWith( E );
    B1_VR_STAR.AlignWith( E );
    B1AdjOrTrans_STAR_MR.AlignWith( E );
    C1_STAR_MC.AlignWith( E );
    D1Trans_MR_STAR.AlignWith( E );

    LockedPartitionRight( A, AL, AR, 0 );
    LockedPartitionRight( B, BL, BR, 0 );
    LockedPartitionDown
    ( C, CT,
         CB, 0 );
    LockedPartitionDown
    ( D, DT,
         DB, 0 );
    while( AL.Width() < A.Width() )
    {
        LockedRepartitionRight
        ( AL, /**/ AR,
          A0, /**/ A1, A2 );
        LockedRepartitionRight
        ( BL, /**/ BR,
          B0, /**/ B1, B2 );
        LockedRepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );
        LockedRepartitionDown
        ( DT,  D0,
         /**/ /**/
               D1,
          DB,  D2 );

        //--------------------------------------------------------------------//
        A1_MC_STAR = A1;
        C1_STAR_MC = C1;
        B1_VR_STAR = B1;
        if( orientationOfB == ADJOINT )
            B1AdjOrTrans_STAR_MR.AdjointFrom( B1_VR_STAR );
        else
            B1AdjOrTrans_STAR_MR.TransposeFrom( B1_VR_STAR );
        D1Trans_MR_STAR.TransposeFrom( D1 );
        LocalTrr2k 
        ( uplo, orientationOfC, TRANSPOSE,
          alpha, A1_MC_STAR, B1AdjOrTrans_STAR_MR,
                 C1_STAR_MC, D1Trans_MR_STAR,
          beta,  E );
        //--------------------------------------------------------------------//

        SlideLockedPartitionRight
        ( AL,     /**/ AR,
          A0, A1, /**/ A2 );
        SlideLockedPartitionRight
        ( BL,     /**/ BR,
          B0, B1, /**/ B2 );
        SlideLockedPartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
        SlideLockedPartitionDown
        ( DT,  D0,
               D1,
         /**/ /**/
          DB,  D2 );
    }
}
Exemplo n.º 19
0
static void ShowStats(void)
{
  _GetStorageInfo(&statsP->stat);

  statsP->nextBase = NULL;
  statsP->totFree = 0; statsP->totUsed = 0;
  statsP->totHole = 0; statsP->totMaps = 0;
  statsP->holeBlocks = 0; statsP->freeBlocks = 0;
  statsP->usedBlocks = 0; statsP->mapsBlocks = 0;
  statsP->largestFreeBlock = 0;
  D0("Storage description. (All sizes in bytes)\n");
  D0("Current storage analysis (by traversing heap):");
  do {
    statsP->elementBase = statsP->nextBase;
    _NextHeapElement(&statsP->nextBase, &statsP->guard, &statsP->size,
                    &statsP->freeBlk, &statsP->heapHole, &statsP->bitmap,
                                                       &statsP->firstWord);
    if (statsP->heapHole)
      { statsP->holeBlocks++; statsP->totHole += statsP->size; }
    else if (statsP->freeBlk) {
      if (statsP->size > statsP->largestFreeBlock)
        statsP->largestFreeBlock = statsP->size;
      statsP->freeBlocks++; statsP->totFree += statsP->size;
    } else if (statsP->bitmap)
        {statsP->mapsBlocks++; statsP->totMaps += statsP->size;}
    else {statsP->usedBlocks++; statsP->totUsed += statsP->size;}
  } while (statsP->nextBase != NULL);

  D0("\n");
  D4("Free memory of %d in %d blocks + overhead of %d = %d\n",
     statsP->totFree, statsP->freeBlocks, statsP->freeBlocks*OVERHEAD,
                           statsP->totFree+statsP->freeBlocks*OVERHEAD);
  D1("Largest free block = %d\n", statsP->largestFreeBlock);
  D4("Used memory of %d in %d blocks + overhead of %d = %d\n",
     statsP->totUsed, statsP->usedBlocks, statsP->usedBlocks*OVERHEAD,
                           statsP->totUsed+statsP->usedBlocks*OVERHEAD);
  D4("Memory taken by heap holes = %d in %d blocks + overhead of %d = %d\n",
     statsP->totHole, statsP->holeBlocks, statsP->holeBlocks*OVERHEAD,
                         statsP->totHole + statsP->holeBlocks*OVERHEAD);
  D4("Memory taken by GC bitmaps = %d in %d blocks + overhead of %d = %d\n",
     statsP->totMaps, statsP->mapsBlocks, statsP->mapsBlocks*OVERHEAD,
                         statsP->totMaps + statsP->mapsBlocks*OVERHEAD);
  D1("Current heap requirement (all except user free blocks) = %d\n",
                      (statsP->totHole+statsP->holeBlocks*OVERHEAD) +
                      (statsP->totUsed+statsP->usedBlocks*OVERHEAD) +
                      (statsP->totMaps+statsP->mapsBlocks*OVERHEAD) +
                             (statsP->freeBlocks*OVERHEAD) - OVERHEAD);
  D1("total heap usage = %d\n",
      (statsP->totHole+statsP->holeBlocks*OVERHEAD) +
      (statsP->totUsed+statsP->usedBlocks*OVERHEAD) +
      (statsP->totMaps+statsP->mapsBlocks*OVERHEAD) +
      (statsP->totFree+statsP->freeBlocks*OVERHEAD) - OVERHEAD);
  D0("\n");
  D0("Current storage statistics:\n");
  D3("%d coalesces, %d heap extensions, %d garbage collects\n",
      statsP->stat.coalesces, statsP->stat.heapExtensions,
                                   statsP->stat.garbageCollects);
  D3("Heap base = &%X, heap top = &%X, size of user heap = %d\n",
      (unsigned) statsP->stat.heapLow, (unsigned) statsP->stat.heapHigh,
                                                   statsP->stat.userHeap);
  D2("Maximum storage requested = %d, current storage requested = %d\n",
      statsP->stat.maxHeapRequirement, statsP->stat.currentHeapRequirement);
  D4("total allocated = %d in %d blocks, deallocated = %d in %d\n",
      statsP->stat.bytesAllocated, statsP->stat.blocksAllocated,
      statsP->stat.bytesDeallocated, statsP->stat.blocksDeallocated);
  D0("\n");

  statsP->eventNo = _GetLastEvent();
  D0("Description of past events in storage (most recent first):\n");
  while (_GetEventData(statsP->eventNo, &statsP->eventInfo)) {
    print_event(statsP->eventInfo.event);
    D3(" block size = %d, user heap size %d, %d usable\n",
       statsP->eventInfo.blockThatCausedEvent, statsP->eventInfo.userHeap,
                                               statsP->eventInfo.totalFree);
    D4("   allocated %d in %d, deallocated %d in %d since last event\n",
       statsP->eventInfo.bytesAllocated, statsP->eventInfo.allocates,
       statsP->eventInfo.bytesDeallocated, statsP->eventInfo.deallocates);
    statsP->eventNo--;
  }
}
Exemplo n.º 20
0
inline void
Trr2kTTTT
( UpperOrLower uplo,
  Orientation orientationOfA, Orientation orientationOfB,
  Orientation orientationOfC, Orientation orientationOfD, 
  T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B,
           const DistMatrix<T>& C, const DistMatrix<T>& D,
  T beta,        DistMatrix<T>& E )
{
#ifndef RELEASE
    PushCallStack("internal::Trr2kTTTT");
    if( E.Height() != E.Width()  || A.Height() != C.Height() ||
        A.Width()  != E.Height() || C.Width()  != E.Height() ||
        B.Height() != E.Width()  || D.Height() != E.Width()  ||
        A.Height() != B.Width()  || C.Height() != D.Width() )
        throw std::logic_error("Nonconformal Trr2kTTTT");
#endif
    const Grid& g = E.Grid();

    DistMatrix<T> AT(g),  A0(g),
                  AB(g),  A1(g),
                          A2(g);
    DistMatrix<T> BL(g), BR(g),
                  B0(g), B1(g), B2(g);

    DistMatrix<T> CT(g),  C0(g),
                  CB(g),  C1(g),
                          C2(g);
    DistMatrix<T> DL(g), DR(g),
                  D0(g), D1(g), D2(g);

    DistMatrix<T,STAR,MC  > A1_STAR_MC(g);
    DistMatrix<T,VR,  STAR> B1_VR_STAR(g);
    DistMatrix<T,STAR,MR  > B1AdjOrTrans_STAR_MR(g);
    DistMatrix<T,STAR,MC  > C1_STAR_MC(g);
    DistMatrix<T,VR,  STAR> D1_VR_STAR(g);
    DistMatrix<T,STAR,MR  > D1AdjOrTrans_STAR_MR(g);

    A1_STAR_MC.AlignWith( E );
    B1_VR_STAR.AlignWith( E );
    B1AdjOrTrans_STAR_MR.AlignWith( E );
    C1_STAR_MC.AlignWith( E );
    D1_VR_STAR.AlignWith( E );
    D1AdjOrTrans_STAR_MR.AlignWith( E );

    LockedPartitionDown
    ( A, AT,
         AB, 0 );
    LockedPartitionRight( B, BL, BR, 0 );
    LockedPartitionDown
    ( C, CT,
         CB, 0 );
    LockedPartitionRight( D, DL, DR, 0 );
    while( AT.Height() < A.Height() )
    {
        LockedRepartitionDown
        ( AT,  A0,
         /**/ /**/
               A1,
          AB,  A2 );
        LockedRepartitionRight
        ( BL, /**/ BR,
          B0, /**/ B1, B2 );
        LockedRepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );
        LockedRepartitionRight
        ( DL, /**/ DR,
          D0, /**/ D1, D2 );

        //--------------------------------------------------------------------//
        A1_STAR_MC = A1;
        C1_STAR_MC = C1;
        B1_VR_STAR = B1;
        D1_VR_STAR = D1;
        if( orientationOfB == ADJOINT )
            B1AdjOrTrans_STAR_MR.AdjointFrom( B1_VR_STAR );
        else
            B1AdjOrTrans_STAR_MR.TransposeFrom( B1_VR_STAR );
        if( orientationOfD == ADJOINT )
            D1AdjOrTrans_STAR_MR.AdjointFrom( D1_VR_STAR );
        else
            D1AdjOrTrans_STAR_MR.TransposeFrom( D1_VR_STAR );
        LocalTrr2k
        ( uplo, orientationOfA, orientationOfC,
          alpha, A1_STAR_MC, B1AdjOrTrans_STAR_MR,
                 C1_STAR_MC, D1AdjOrTrans_STAR_MR,
          beta,  E );
        //--------------------------------------------------------------------//

        SlideLockedPartitionRight
        ( DL,     /**/ DR,
          D0, D1, /**/ D2 );
        SlideLockedPartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
        SlideLockedPartitionRight
        ( BL,     /**/ BR,
          B0, B1, /**/ B2 );
        SlideLockedPartitionDown
        ( AT,  A0,
               A1,
         /**/ /**/
          AB,  A2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Exemplo n.º 21
0
int Rsimp(int m, int n, double **A, double *b, double *c,
          double *x, int *basis, int *nonbasis,
          double **R, double **Q, double *t1, double *t2){
    int i,j,k,l,q,qv;
    int max_steps=20;
    double r,a,at;
    void GQR(int,int,double**,double**);
    max_steps=4*n;

    for(k=0; k<=max_steps;k++){
        /*
   ++ Step 0) load new basis matrix and factor it
   */
        for(i=0;i<m;i++)for(j=0;j<m;j++)R0(i,j)=AB0(i,j);
        GQR(m,m,Q,R);

        /*
   ++ Step 1) solving system  B'*w=c(basis)
   ++      a) forward solve R'*y=c(basis)
   */
        for(i=0;i<m;i++){
            Y0(i)=0.0;
            for(j=0;j<i;j++)Y0(i)+=R0(j,i)*Y0(j);
            if (R0(i,i)!=0.0) Y0(i)=(CB0(i)-Y0(i))/R0(i,i);
            else {
                printf("Warning Singular Matrix Found\n");
                return LP_FAIL;
            }
        }
        /*
   ++      b) find w=Q*y
   ++         note: B'*w=(Q*R)'*Q*y= R'*(Q'*Q)*y=R'*y=c(basis)
   */
        for(i=0;i<m;i++){
            W0(i)=0.0;
            for(j=0;j<m;j++)W0(i)+=Q0(i,j)*Y0(j);
        }

        /*
   ++ Step 2)find entering variable,
   ++ (use lexicographically first variable with negative reduced cost)
   */
        q=n;
        for(i=0;i<n-m;i++){
            /* calculate reduced cost */
            r=CN0(i);
            for(j=0;j<m;j++) r-=W0(j)*AN0(j,i);
            if (r<-zero_tol && (q==n || nonbasis0(i)<nonbasis0(q))) q=i;
        }

        /*
   ++ if ratios were all nonnegative current solution is optimal
   */
        if (q==n){
            if (verbose>0) printf("optimal solution found in %d iterations\n",k);
            return LP_OPT;
        }
        /*
   ++ Step 3)Calculate translation direction for q entering
   ++        by solving system  B*d=-A(:,nonbasis(q));
   ++   a) let y=-Q'*A(:,nonbasis(q));
   */
        for(i=0;i<m;i++){
            Y0(i)=0.0;
            for(j=0;j<m;j++) Y0(i)-=Q0(j,i)*AN0(j,q);
        }

        /*
   ++  b) back solve Rd=y  (d=R\y)
   ++     note B*d= Q*R*d=Q*y=Q*-Q'*A(:nonbasis(q))=-A(:,nonbasis(q))
   */
        for(i=m-1;i>=0;i--){
            D0(i)=0.0;
            for(j=m-1;j>=i+1;j--)D0(i)+=R0(i,j)*D0(j);
            if (R0(i,i)!=0.0) D0(i)=(Y0(i)-D0(i))/R0(i,i);
            else {
                printf("Warning Singular Matrix Found\n");
                return LP_FAIL;
            }
        }
        /*
   ++ Step 4 Choose leaving variable
   ++     (first variable to become negative, by moving in direction D)
   ++     (if none become negative, then objective function unbounded)
   */
        a=0;
        l=-1;
        for(i=0;i<m;i++){
            if (D0(i)<-zero_tol){
                at=-1*XB0(i)/D0(i);
                if (l==-1 || at<a){ a=at; l=i;}
            }
        }
        if (l==-1){
            if (verbose>0){
                printf("Objective function Unbounded (%d iterations)\n",k);
            }
            return LP_UNBD;
        }
        /*
   ++ Step 5) Update solution and basis data
   */
        XN0(q)=a;
        for(j=0;j<m;j++) XB0(j)+=a*D0(j);
        XB0(l)=0.0;             /* enforce strict zeroness of nonbasis variables */
        qv=nonbasis0(q);
        nonbasis0(q)=basis0(l);
        basis0(l)=qv;
    }
    if (verbose>=0){
        printf("Simplex Algorithm did not Terminate in %d iterations\n",k);
    }
    return LP_FAIL;
}
Exemplo n.º 22
0
inline void
Trr2kNNTN
( UpperOrLower uplo,
  Orientation orientationOfC,
  T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B,
           const DistMatrix<T>& C, const DistMatrix<T>& D,
  T beta,        DistMatrix<T>& E )
{
#ifndef RELEASE
    PushCallStack("internal::Trr2kNNTN");
    if( E.Height() != E.Width()  || A.Width()  != C.Height() ||
        A.Height() != E.Height() || C.Width()  != E.Height() ||
        B.Width()  != E.Width()  || D.Width()  != E.Width()  ||
        A.Width()  != B.Height() || C.Height() != D.Height() )
        throw std::logic_error("Nonconformal Trr2kNNTN");
#endif
    const Grid& g = E.Grid();

    DistMatrix<T> AL(g), AR(g),
                  A0(g), A1(g), A2(g);
    DistMatrix<T> BT(g),  B0(g),
                  BB(g),  B1(g),
                          B2(g);

    DistMatrix<T> CT(g),  C0(g),
                  CB(g),  C1(g),
                          C2(g);
    DistMatrix<T> DT(g),  D0(g),
                  DB(g),  D1(g),
                          D2(g);

    DistMatrix<T,MC,  STAR> A1_MC_STAR(g);
    DistMatrix<T,MR,  STAR> B1Trans_MR_STAR(g);
    DistMatrix<T,STAR,MC  > C1_STAR_MC(g);
    DistMatrix<T,MR,  STAR> D1Trans_MR_STAR(g);

    A1_MC_STAR.AlignWith( E );
    B1Trans_MR_STAR.AlignWith( E );
    C1_STAR_MC.AlignWith( E );
    D1Trans_MR_STAR.AlignWith( E );

    LockedPartitionRight( A, AL, AR, 0 );
    LockedPartitionDown
    ( B, BT,
         BB, 0 );
    LockedPartitionDown
    ( C, CT,
         CB, 0 );
    LockedPartitionDown
    ( D, DT,
         DB, 0 );
    while( AL.Width() < A.Width() )
    {
        LockedRepartitionRight
        ( AL, /**/ AR,
          A0, /**/ A1, A2 );
        LockedRepartitionDown
        ( BT,  B0,
         /**/ /**/
               B1,
          BB,  B2 );
        LockedRepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );
        LockedRepartitionDown
        ( DT,  D0,
         /**/ /**/
               D1,
          DB,  D2 );

        //--------------------------------------------------------------------//
        A1_MC_STAR = A1;
        C1_STAR_MC = C1;
        B1Trans_MR_STAR.TransposeFrom( B1 );
        D1Trans_MR_STAR.TransposeFrom( D1 );
        LocalTrr2k
        ( uplo, TRANSPOSE, orientationOfC, TRANSPOSE,
          alpha, A1_MC_STAR, B1Trans_MR_STAR, 
                 C1_STAR_MC, D1Trans_MR_STAR,
          beta,  E );
        //--------------------------------------------------------------------//

        SlideLockedPartitionDown
        ( DT,  D0,
               D1,
         /**/ /**/
          DB,  D2 );
        SlideLockedPartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
        SlideLockedPartitionDown
        ( BT,  B0,
               B1,
         /**/ /**/
          BB,  B2 );
        SlideLockedPartitionRight
        ( AL,     /**/ AR,
          A0, A1, /**/ A2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}