本文整理汇总了C++中GMatrix::GetRows方法的典型用法代码示例。如果您正苦于以下问题:C++ GMatrix::GetRows方法的具体用法?C++ GMatrix::GetRows怎么用?C++ GMatrix::GetRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GMatrix
的用法示例。
在下文中一共展示了GMatrix::GetRows方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
bool LinearSystem<Real>::SolveSymmetricCG (const GMatrix<Real>& rkA,
const Real* afB, Real* afX)
{
// based on the algorithm in "Matrix Computations" by Golum and Van Loan
assert( rkA.GetRows() == rkA.GetColumns() );
int iSize = rkA.GetRows();
Real* afR = new Real[iSize];
Real* afP = new Real[iSize];
Real* afW = new Real[iSize];
// first iteration
memset(afX,0,iSize*sizeof(Real));
memcpy(afR,afB,iSize*sizeof(Real));
Real fRho0 = Dot(iSize,afR,afR);
memcpy(afP,afR,iSize*sizeof(Real));
Multiply(rkA,afP,afW);
Real fAlpha = fRho0/Dot(iSize,afP,afW);
UpdateX(iSize,afX,fAlpha,afP);
UpdateR(iSize,afR,fAlpha,afW);
Real fRho1 = Dot(iSize,afR,afR);
// remaining iterations
const int iMax = 1024;
int i;
for (i = 1; i < iMax; i++)
{
Real fRoot0 = Math<Real>::Sqrt(fRho1);
Real fNorm = Dot(iSize,afB,afB);
Real fRoot1 = Math<Real>::Sqrt(fNorm);
if ( fRoot0 <= ms_fTolerance*fRoot1 )
break;
Real fBeta = fRho1/fRho0;
UpdateP(iSize,afP,fBeta,afR);
Multiply(rkA,afP,afW);
fAlpha = fRho1/Dot(iSize,afP,afW);
UpdateX(iSize,afX,fAlpha,afP);
UpdateR(iSize,afR,fAlpha,afW);
fRho0 = fRho1;
fRho1 = Dot(iSize,afR,afR);
}
delete[] afW;
delete[] afP;
delete[] afR;
return i < iMax;
}
示例2: assert
Eigen<Real>::Eigen (const GMatrix<Real>& rkM)
:
m_kMat(rkM)
{
m_iSize = rkM.GetRows();
assert(m_iSize >= 2 && (rkM.GetColumns() == m_iSize));
m_afDiag = WM4_NEW Real[m_iSize];
m_afSubd = WM4_NEW Real[m_iSize];
m_bIsRotation = false;
}
示例3: memset
void LinearSystem<Real>::Multiply (const GMatrix<Real>& rkA, const Real* afX,
Real* afProd)
{
int iSize = rkA.GetRows();
memset(afProd,0,iSize*sizeof(Real));
for (int iRow = 0; iRow < iSize; iRow++)
{
for (int iCol = 0; iCol < iSize; iCol++)
afProd[iRow] += rkA[iRow][iCol]*afX[iCol];
}
}
示例4: assert
Eigen<Real>::Eigen (const GMatrix<Real>& rkM)
:
m_kMat(rkM)
{
m_iSize = rkM.GetRows();
assert( m_iSize >= 2 && (rkM.GetColumns() == m_iSize) );
m_afDiag = new Real[m_iSize];
m_afSubd = new Real[m_iSize];
// set according to the parity of the number of Householder reflections
m_bIsRotation = ((m_iSize % 2) == 0);
}
示例5: mMatrix
EigenDecomposition<Real>::EigenDecomposition (const GMatrix<Real>& mat)
:
mMatrix(mat)
{
mSize = mat.GetRows();
assertion(mSize >= 2 && (mat.GetColumns() == mSize),
"Square matrix required in EigenDecomposition constructor\n");
mDiagonal = new1<Real>(mSize);
mSubdiagonal = new1<Real>(mSize);
mIsRotation = false;
}
示例6: assert
bool LinearSystem<Real>::Inverse (const GMatrix<Real>& rkA,
GMatrix<Real>& rkInvA)
{
// computations are performed in-place
assert(rkA.GetRows() == rkA.GetColumns());
int iSize = rkInvA.GetRows();
rkInvA = rkA;
int* aiColIndex = WM4_NEW int[iSize];
int* aiRowIndex = WM4_NEW int[iSize];
bool* abPivoted = WM4_NEW bool[iSize];
memset(abPivoted,0,iSize*sizeof(bool));
int i1, i2, iRow = 0, iCol = 0;
Real fSave;
// elimination by full pivoting
for (int i0 = 0; i0 < iSize; i0++)
{
// search matrix (excluding pivoted rows) for maximum absolute entry
Real fMax = 0.0f;
for (i1 = 0; i1 < iSize; i1++)
{
if (!abPivoted[i1])
{
for (i2 = 0; i2 < iSize; i2++)
{
if (!abPivoted[i2])
{
Real fAbs = Math<Real>::FAbs(rkInvA[i1][i2]);
if (fAbs > fMax)
{
fMax = fAbs;
iRow = i1;
iCol = i2;
}
}
}
}
}
if (fMax == (Real)0.0)
{
// matrix is not invertible
WM4_DELETE[] aiColIndex;
WM4_DELETE[] aiRowIndex;
WM4_DELETE[] abPivoted;
return false;
}
abPivoted[iCol] = true;
// swap rows so that A[iCol][iCol] contains the pivot entry
if (iRow != iCol)
{
rkInvA.SwapRows(iRow,iCol);
}
// keep track of the permutations of the rows
aiRowIndex[i0] = iRow;
aiColIndex[i0] = iCol;
// scale the row so that the pivot entry is 1
Real fInv = ((Real)1.0)/rkInvA[iCol][iCol];
rkInvA[iCol][iCol] = (Real)1.0;
for (i2 = 0; i2 < iSize; i2++)
{
rkInvA[iCol][i2] *= fInv;
}
// zero out the pivot column locations in the other rows
for (i1 = 0; i1 < iSize; i1++)
{
if (i1 != iCol)
{
fSave = rkInvA[i1][iCol];
rkInvA[i1][iCol] = (Real)0.0;
for (i2 = 0; i2 < iSize; i2++)
{
rkInvA[i1][i2] -= rkInvA[iCol][i2]*fSave;
}
}
}
}
示例7: assert
bool LinearSystem<Real>::Inverse (const GMatrix<Real>& rkA,
GMatrix<Real>& rkInvA)
{
// computations are performed in-place
assert( rkA.GetRows() == rkA.GetColumns() );
int iSize = rkInvA.GetRows();
rkInvA = rkA;
if (aiColIndex == NULL)
aiColIndex = new int[iSize];
//assert( aiColIndex );
if (aiRowIndex == NULL)
aiRowIndex = new int[iSize];
//assert( aiRowIndex );
if (abPivoted == NULL)
abPivoted = new bool[iSize];
//assert( abPivoted );
memset(abPivoted,0,iSize*sizeof(bool));
int i1, i2, iRow = 0, iCol = 0;
Real fSave;
// elimination by full pivoting
for (int i0 = 0; i0 < iSize; i0++)
{
// search matrix (excluding pivoted rows) for maximum absolute entry
Real fMax = 0.0f;
for (i1 = 0; i1 < iSize; i1++)
{
if ( !abPivoted[i1] )
{
for (i2 = 0; i2 < iSize; i2++)
{
if ( !abPivoted[i2] )
{
Real fAbs = fabs(rkInvA[i1][i2]);
if ( fAbs > fMax )
{
fMax = fAbs;
iRow = i1;
iCol = i2;
}
}
}
}
}
if ( fMax == (Real)0.0 )
{
// matrix is not invertible
delete[] aiColIndex;
delete[] aiRowIndex;
delete[] abPivoted;
return false;
}
abPivoted[iCol] = true;
// swap rows so that A[iCol][iCol] contains the pivot entry
if ( iRow != iCol )
rkInvA.SwapRows(iRow,iCol);
// keep track of the permutations of the rows
aiRowIndex[i0] = iRow;
aiColIndex[i0] = iCol;
// scale the row so that the pivot entry is 1
Real fInv = ((Real)1.0)/rkInvA[iCol][iCol];
rkInvA[iCol][iCol] = (Real)1.0;
for (i2 = 0; i2 < iSize; i2++)
rkInvA[iCol][i2] *= fInv;
// zero out the pivot column locations in the other rows
for (i1 = 0; i1 < iSize; i1++)
{
if ( i1 != iCol )
{
fSave = rkInvA[i1][iCol];
rkInvA[i1][iCol] = (Real)0.0;
for (i2 = 0; i2 < iSize; i2++)
rkInvA[i1][i2] -= rkInvA[iCol][i2]*fSave;
}
}
}
// reorder rows so that A[][] stores the inverse of the original matrix
for (i1 = iSize-1; i1 >= 0; i1--)
{
if ( aiRowIndex[i1] != aiColIndex[i1] )
{
for (i2 = 0; i2 < iSize; i2++)
{
fSave = rkInvA[i2][aiRowIndex[i1]];
rkInvA[i2][aiRowIndex[i1]] = rkInvA[i2][aiColIndex[i1]];
rkInvA[i2][aiColIndex[i1]] = fSave;
}
}
//.........这里部分代码省略.........