本文整理汇总了C++中MATRIX::resizeAndWipe方法的典型用法代码示例。如果您正苦于以下问题:C++ MATRIX::resizeAndWipe方法的具体用法?C++ MATRIX::resizeAndWipe怎么用?C++ MATRIX::resizeAndWipe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MATRIX
的用法示例。
在下文中一共展示了MATRIX::resizeAndWipe方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eigensystem
//////////////////////////////////////////////////////////////////////
// solve for the eigensystem of the matrix
//////////////////////////////////////////////////////////////////////
void MATRIX::eigensystem(VECTOR& eigenvalues, MATRIX& eigenvectors)
{
// basic error checking
if (_rows != _cols)
{
cout << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " : " << endl;
cout << " Matrix must be square to get eigenvalues! " << endl;
return;
}
// resize result space
eigenvalues.resizeAndWipe(_rows);
eigenvectors.resizeAndWipe(_rows, _rows);
// OSX specific - clapack stuff
__CLPK_integer rowsize = _rows;
__CLPK_integer worksize = 5 * _rows;
double* work = new double[worksize];
double* valuesReal = new double[2 * _rows];
double* valuesImag = valuesReal + _rows;
double* vectors = new double[_rows * _rows];
double* matrix = new double[_rows * _cols];
for (int x = 0; x < _rows * _cols; x++)
matrix[x] = _matrix[x];
// the actual LAPACK call
__CLPK_integer error;
char V = 'V';
char N = 'N';
dgeev_(&V,&N, &rowsize, matrix, &rowsize,
valuesReal, valuesImag,
vectors, &rowsize, NULL, &rowsize,
work, &worksize, &error);
if (error != 0)
{
cout << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " : " << endl;
cout << " eigenvalue solver bombed!" << endl;
}
cout << " Error value: " << error << endl;
// copy the results into sortable form
vector<EIGENPAIR> pairs;
for (int x = 0; x < _rows; x++)
{
EIGENPAIR pair;
pair.value = valuesReal[x];
VECTOR singleVector(_rows);
for (int y = 0; y < _rows; y++)
singleVector[y] = vectors[y + x * _cols];
pair.eigenvector = singleVector;
pairs.push_back(pair);
}
// sort it
sort(pairs.begin(), pairs.end());
// copy out results
eigenvalues.resizeAndWipe(_rows);
for (int x = 0; x < _rows; x++)
eigenvalues(x) = pairs[x].value;
eigenvectors.resizeAndWipe(_rows, _rows);
for (int x = 0; x < _rows; x++)
for (int y = 0; y < _rows; y++)
eigenvectors(x,y) = pairs[y].eigenvector[x];
// cleanup
delete[] work;
delete[] valuesReal;
delete[] vectors;
delete[] matrix;
}