当前位置: 首页>>代码示例>>C++>>正文


C++ GMatrix::GetNumRows方法代码示例

本文整理汇总了C++中GMatrix::GetNumRows方法的典型用法代码示例。如果您正苦于以下问题:C++ GMatrix::GetNumRows方法的具体用法?C++ GMatrix::GetNumRows怎么用?C++ GMatrix::GetNumRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GMatrix的用法示例。


在下文中一共展示了GMatrix::GetNumRows方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assertion

bool LinearSystem<Real>::SolveSymmetricCG (const GMatrix<Real>& A,
    const Real* B, Real* X)
{
    // Based on the algorithm in "Matrix Computations" by Golum and Van Loan.
    assertion(A.GetNumRows() == A.GetNumColumns(), "Matrix must be square\n");
    int size = A.GetNumRows();
    Real* R = new1<Real>(size);
    Real* P = new1<Real>(size);
    Real* W = new1<Real>(size);

    // The first iteration.
    size_t numBytes = size*sizeof(Real);
    memset(X, 0, numBytes);
    memcpy(R, B, numBytes);
    Real rho0 = Dot(size, R, R);
    memcpy(P, R, numBytes);
    Multiply(A, P, W);
    Real alpha = rho0/Dot(size, P, W);
    UpdateX(size, X, alpha, P);
    UpdateR(size, R, alpha, W);
    Real rho1 = Dot(size, R, R);

    // The remaining iterations.
    const int imax = 1024;
    int i;
    for (i = 1; i < imax; ++i)
    {
        Real root0 = Math<Real>::Sqrt(rho1);
        Real norm = Dot(size, B, B);
        Real root1 = Math<Real>::Sqrt(norm);
        if (root0 <= ZeroTolerance*root1)
        {
            break;
        }

        Real beta = rho1/rho0;
        UpdateP(size, P, beta, R);
        Multiply(A, P, W);
        alpha = rho1/Dot(size, P, W);
        UpdateX(size, X, alpha, P);
        UpdateR(size, R, alpha, W);
        rho0 = rho1;
        rho1 = Dot(size, R, R);
    }

    delete1(W);
    delete1(P);
    delete1(R);

    return i < imax;
}
开发者ID:2asoft,项目名称:GeometricTools,代码行数:51,代码来源:Wm5LinearSystem.cpp

示例2: memset

void LinearSystem<Real>::Multiply (const GMatrix<Real>& A, const Real* X,
    Real* Prod)
{
    int size = A.GetNumRows();
    memset(Prod, 0, size*sizeof(Real));
    for (int row = 0; row < size; ++row)
    {
        for (int col = 0; col < size; ++col)
        {
            Prod[row] += A[row][col]*X[col];
        }
    }
}
开发者ID:2asoft,项目名称:GeometricTools,代码行数:13,代码来源:Wm5LinearSystem.cpp

示例3:

void SingularValueDecomposition<Real>::HouseholderPostmultiply (
    const GVector<Real>& V, GMatrix<Real>& A)
{
	GVector<Real> W = (((Real)-2)/V.SquaredLength())*(A*V);
	int numRows = A.GetNumRows();
	int numCols = A.GetNumColumns();
	for (int row = 0; row < numRows; ++row)
	{
		for (int col = 0; col < numCols; ++col)
		{
			A[row][col] += W[row]*V[col];
		}
	}
}
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:14,代码来源:Wm5SingularValueDecomposition.cpp

示例4: es

SingularValueDecomposition<Real>::SingularValueDecomposition (
    const GMatrix<Real>& M, GMatrix<Real>& L, GMatrix<Real>& D,
    GMatrix<Real>& RTranspose)
{
	// TODO.  Implement other QR factorizations and SVD code from "Matrix
	// Computations", and then give the user the ability to specify which
	// methods are used here.

	int numRows = M.GetNumRows();
	int numCols = M.GetNumColumns();
	L.SetSize(numRows, numRows);
	D.SetSize(numRows, numCols);
	RTranspose.SetSize(numCols, numCols);

	GMatrix<Real> kMTM = M.TransposeTimes(M);
	EigenDecomposition<Real> es(kMTM);
	es.Solve(false);
	GMatrix<Real> V = es.GetEigenvectors();
	GMatrix<Real> MV = M*V;
	HouseholderQR(MV, L, D);
	RTranspose = V.Transpose();
}
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:22,代码来源:Wm5SingularValueDecomposition.cpp

示例5: columns

void SingularValueDecomposition<Real>::HouseholderQR (
    const GMatrix<Real>& A, GMatrix<Real>& Q, GMatrix<Real>& R)
{
	// The matrix R gets a copy of A, and is then overwritten during the
	// algorithm with the correct entries to be upper triangular.
	R = A;
	int numRows = R.GetNumRows();
	int numCols = R.GetNumColumns();
	assertion(numRows >= numCols, "Too many columns (use transpose)\n");
	int row, col;
	GVector<Real> V(numRows);
	std::vector<GVector<Real> > VSave;
	for (col = 0; col < numCols; ++col)
	{
		// Create the Householder vector for the partial column of A.
		for (row = 0; row < col; ++row)
		{
			V[row] = (Real)0;
		}
		Real length = (Real)0;
		for (row = col; row < numRows; ++row)
		{
			V[row] = R[row][col];
			length += V[row]*V[row];
		}
		length = Math<Real>::Sqrt(length);
		Real beta = V[col] + Math<Real>::Sign(V[col])*length;
		if (beta != (Real)0)
		{
			Real invBeta = ((Real)1)/beta;
			for (int i = col + 1; i < numRows; ++i)
			{
				V[i] *= invBeta;
			}
		}
		V[col] = (Real)1;

		// Premultiply A by the V-reflection matrix.
		HouseholderPremultiply(V, R);

		// Save the Householder vectors.
		VSave.push_back(V);
	}

	// First, make Q the identity.  Second, extract the Householder vectors
	// and premultiply by the V-reflections to build Q.
	memset(Q.GetElements(), 0, Q.GetNumElements()*sizeof(Real));
	for (row = 0; row < numRows; ++row)
	{
		Q[row][row] = (Real)1;
	}

	for (col = numCols - 1; col >= 0; --col)
	{
		// Get the Householder vector.
		V = VSave[col];

		// Premultiply Q by the V-reflection matrix.
		HouseholderPremultiply(V, Q);
	}
}
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:61,代码来源:Wm5SingularValueDecomposition.cpp


注:本文中的GMatrix::GetNumRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。