本文整理汇总了C++中GMatrix::GetNumColumns方法的典型用法代码示例。如果您正苦于以下问题:C++ GMatrix::GetNumColumns方法的具体用法?C++ GMatrix::GetNumColumns怎么用?C++ GMatrix::GetNumColumns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GMatrix
的用法示例。
在下文中一共展示了GMatrix::GetNumColumns方法的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;
}
示例2:
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];
}
}
}
示例3: A
void LinearSystem<Real>::BackwardEliminate (int reduceRow,
BandedMatrix<Real>& A, GMatrix<Real>& B)
{
int rowMax = reduceRow - 1;
int rowMin = reduceRow - A.GetNumUBands();
if (rowMin < 0)
{
rowMin = 0;
}
for (int row = rowMax; row >= rowMin; --row)
{
Real mult = A(row,reduceRow);
A(row,reduceRow) = (Real)0;
for (int col = 0; col < B.GetNumColumns(); ++col)
{
B(row,col) -= mult*B(reduceRow,col);
}
}
}
示例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();
}
示例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);
}
}