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


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

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


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

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