本文整理汇总了C++中DiagonalMatrix::ReSize方法的典型用法代码示例。如果您正苦于以下问题:C++ DiagonalMatrix::ReSize方法的具体用法?C++ DiagonalMatrix::ReSize怎么用?C++ DiagonalMatrix::ReSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiagonalMatrix
的用法示例。
在下文中一共展示了DiagonalMatrix::ReSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: diagonalise
void SpinAdapted::diagonalise(Matrix& sym, DiagonalMatrix& d, Matrix& vec)
{
int nrows = sym.Nrows();
int ncols = sym.Ncols();
assert(nrows == ncols);
d.ReSize(nrows);
vec.ReSize(nrows, nrows);
Matrix workmat;
workmat = sym;
vector<double> workquery(1);
int info = 0;
double* dptr = d.Store();
int query = -1;
DSYEV('V', 'L', nrows, workmat.Store(), nrows, dptr, &(workquery[0]), query, info); // do query to find best size
int optlength = static_cast<int>(workquery[0]);
vector<double> workspace(optlength);
DSYEV('V', 'U', nrows, workmat.Store(), nrows, dptr, &(workspace[0]), optlength, info); // do query to find best size
if (info > 0)
{
pout << "failed to converge " << endl;
abort();
}
for (int i = 0; i < nrows; ++i)
for (int j = 0; j < ncols; ++j)
vec(j+1,i+1) = workmat(i+1,j+1);
}
示例2: svd
void SpinAdapted::svd(Matrix& M, DiagonalMatrix& d, Matrix& U, Matrix& V)
{
int nrows = M.Nrows();
int ncols = M.Ncols();
assert(nrows >= ncols);
int minmn = min(nrows, ncols);
int maxmn = max(nrows, ncols);
int eigenrows = min(minmn, minmn);
d.ReSize(minmn);
Matrix Ut;
Ut.ReSize(nrows, nrows);
V.ReSize(ncols, ncols);
int lwork = maxmn * maxmn + 100;
double* workspace = new double[lwork];
// first transpose matrix
Matrix Mt;
Mt = M.t();
int info = 0;
DGESVD('A', 'A', nrows, ncols, Mt.Store(), nrows, d.Store(),
Ut.Store(), nrows, V.Store(), ncols, workspace, lwork, info);
U.ReSize(nrows, ncols);
SpinAdapted::Clear(U);
for (int i = 0; i < nrows; ++i)
for (int j = 0; j < ncols; ++j)
U(i+1,j+1) = Ut(j+1,i+1);
delete[] workspace;
}
示例3: et
static void tred3(const SymmetricMatrix& X, DiagonalMatrix& D,
DiagonalMatrix& E, SymmetricMatrix& A)
{
Tracer et("Evalue(tred3)");
Real tol =
FloatingPointPrecision::Minimum()/FloatingPointPrecision::Epsilon();
int n = X.Nrows(); A = X; D.ReSize(n); E.ReSize(n);
Real* ei = E.Store() + n;
for (int i = n-1; i >= 0; i--)
{
Real h = 0.0; Real f;
Real* d = D.Store(); Real* a = A.Store() + (i*(i+1))/2; int k = i;
while (k--) { f = *a++; *d++ = f; h += square(f); }
if (h <= tol) { *(--ei) = 0.0; h = 0.0; }
else
{
Real g = sign(-sqrt(h), f); *(--ei) = g; h -= f*g;
f -= g; *(d-1) = f; *(a-1) = f; f = 0.0;
Real* dj = D.Store(); Real* ej = E.Store(); int j;
for (j = 0; j < i; j++)
{
Real* dk = D.Store(); Real* ak = A.Store()+(j*(j+1))/2;
Real g = 0.0; k = j;
while (k--) g += *ak++ * *dk++;
k = i-j; int l = j;
while (k--) { g += *ak * *dk++; ak += ++l; }
g /= h; *ej++ = g; f += g * *dj++;
}
Real hh = f / (2 * h); Real* ak = A.Store();
dj = D.Store(); ej = E.Store();
for (j = 0; j < i; j++)
{
f = *dj++; g = *ej - hh * f; *ej++ = g;
Real* dk = D.Store(); Real* ek = E.Store(); k = j+1;
while (k--) { *ak++ -= (f * *ek++ + g * *dk++); }
}
}
*d = *a; *a = h;
}
}
示例4: GetHatDiagonal
void NonLinearLeastSquares::GetHatDiagonal(DiagonalMatrix& Hat) const
{
Hat.ReSize(n_obs);
for (int i = 1; i<=n_obs; i++) Hat(i) = X.Row(i).SumSquare();
}