本文整理汇总了C++中eigen::SparseMatrix::transpose方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::transpose方法的具体用法?C++ SparseMatrix::transpose怎么用?C++ SparseMatrix::transpose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::transpose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Solve
void UnknownVars::Solve(const AAndBVars& aAndBVars)
{
// solve Ax = b using UmfPack:
Eigen::SparseMatrix<double> A = aAndBVars.GetA();
A.transpose();
Eigen::SparseLU<Eigen::SparseMatrix<double>,Eigen::UmfPack> lu_of_A(A);
wxASSERT(lu_of_A.succeeded());
bool success = lu_of_A.solve(aAndBVars.GetBVarsConst(),&m_u);
wxASSERT(success);
}
示例2: main
int main()
{
int n = 10;
Eigen::SparseMatrix<double> S = Eigen::MatrixXd::Random(n,n).sparseView(0.5,1);
S = S.transpose()*S;
MatrixReplacement A;
A.attachMyMatrix(S);
Eigen::VectorXd b(n), x;
b.setRandom();
// Solve Ax = b using various iterative solver with matrix-free version:
{
Eigen::ConjugateGradient<MatrixReplacement, Eigen::Lower|Eigen::Upper, Eigen::IdentityPreconditioner> cg;
cg.compute(A);
x = cg.solve(b);
std::cout << "CG: #iterations: " << cg.iterations() << ", estimated error: " << cg.error() << std::endl;
}
{
Eigen::BiCGSTAB<MatrixReplacement, Eigen::IdentityPreconditioner> bicg;
bicg.compute(A);
x = bicg.solve(b);
std::cout << "BiCGSTAB: #iterations: " << bicg.iterations() << ", estimated error: " << bicg.error() << std::endl;
}
{
Eigen::GMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
gmres.compute(A);
x = gmres.solve(b);
std::cout << "GMRES: #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
}
{
Eigen::DGMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
gmres.compute(A);
x = gmres.solve(b);
std::cout << "DGMRES: #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
}
{
Eigen::MINRES<MatrixReplacement, Eigen::Lower|Eigen::Upper, Eigen::IdentityPreconditioner> minres;
minres.compute(A);
x = minres.solve(b);
std::cout << "MINRES: #iterations: " << minres.iterations() << ", estimated error: " << minres.error() << std::endl;
}
}
开发者ID:muhammedabdelnasser,项目名称:Vehicle-Steering-Using-Model-Predictive-Control,代码行数:48,代码来源:matrixfree_cg.cpp
示例3: polyvector_field_poisson_reconstruction
IGL_INLINE double igl::polyvector_field_poisson_reconstruction(
const Eigen::PlainObjectBase<DerivedV> &Vcut,
const Eigen::PlainObjectBase<DerivedF> &Fcut,
const Eigen::PlainObjectBase<DerivedS> &sol3D_combed,
Eigen::PlainObjectBase<DerivedSF> &scalars,
Eigen::PlainObjectBase<DerivedS> &sol3D_recon,
Eigen::PlainObjectBase<DerivedE> &max_error )
{
Eigen::SparseMatrix<typename DerivedV::Scalar> gradMatrix;
igl::grad(Vcut, Fcut, gradMatrix);
Eigen::VectorXd FAreas;
igl::doublearea(Vcut, Fcut, FAreas);
FAreas = FAreas.array() * .5;
int nf = FAreas.rows();
Eigen::SparseMatrix<typename DerivedV::Scalar> M,M1;
Eigen::VectorXi II = igl::colon<int>(0, nf-1);
igl::sparse(II, II, FAreas, M1);
igl::repdiag(M1, 3, M) ;
int half_degree = sol3D_combed.cols()/3;
sol3D_recon.setZero(sol3D_combed.rows(),sol3D_combed.cols());
int numF = Fcut.rows();
scalars.setZero(Vcut.rows(),half_degree);
Eigen::SparseMatrix<typename DerivedV::Scalar> Q = gradMatrix.transpose()* M *gradMatrix;
//fix one point at Ik=fix, value at fixed xk=0
int fix = 0;
Eigen::VectorXi Ik(1);Ik<<fix;
Eigen::VectorXd xk(1);xk<<0;
//unknown indices
Eigen::VectorXi Iu(Vcut.rows()-1,1);
Iu<<igl::colon<int>(0, fix-1), igl::colon<int>(fix+1,Vcut.rows()-1);
Eigen::SparseMatrix<typename DerivedV::Scalar> Quu, Quk;
igl::slice(Q, Iu, Iu, Quu);
igl::slice(Q, Iu, Ik, Quk);
Eigen::SimplicialLDLT<Eigen::SparseMatrix<typename DerivedV::Scalar> > solver;
solver.compute(Quu);
Eigen::VectorXd vec; vec.setZero(3*numF,1);
for (int i =0; i<half_degree; ++i)
{
vec<<sol3D_combed.col(i*3+0),sol3D_combed.col(i*3+1),sol3D_combed.col(i*3+2);
Eigen::VectorXd b = gradMatrix.transpose()* M * vec;
Eigen::VectorXd bu = igl::slice(b, Iu);
Eigen::VectorXd rhs = bu-Quk*xk;
Eigen::MatrixXd yu = solver.solve(rhs);
Eigen::VectorXi index = i*Eigen::VectorXi::Ones(Iu.rows(),1);
igl::slice_into(yu, Iu, index, scalars);scalars(Ik[0],i)=xk[0];
}
// evaluate gradient of found scalar function
for (int i =0; i<half_degree; ++i)
{
Eigen::VectorXd vec_poisson = gradMatrix*scalars.col(i);
sol3D_recon.col(i*3+0) = vec_poisson.segment(0*numF, numF);
sol3D_recon.col(i*3+1) = vec_poisson.segment(1*numF, numF);
sol3D_recon.col(i*3+2) = vec_poisson.segment(2*numF, numF);
}
max_error.setZero(numF,1);
for (int i =0; i<half_degree; ++i)
{
Eigen::VectorXd diff = (sol3D_recon.block(0, i*3, numF, 3)-sol3D_combed.block(0, i*3, numF, 3)).rowwise().norm();
diff = diff.array() / sol3D_combed.block(0, i*3, numF, 3).rowwise().norm().array();
max_error = max_error.cwiseMax(diff.cast<typename DerivedE::Scalar>());
}
return max_error.mean();
}
开发者ID:adityasraghav,项目名称:OpenGL_SolarSystem,代码行数:80,代码来源:polyvector_field_poisson_reconstruction.cpp
示例4: lu_lagrange
IGL_INLINE bool igl::lu_lagrange(
const Eigen::SparseMatrix<T> & ATA,
const Eigen::SparseMatrix<T> & C,
Eigen::SparseMatrix<T> & L,
Eigen::SparseMatrix<T> & U)
{
#if EIGEN_VERSION_AT_LEAST(3,0,92)
#if defined(_WIN32)
#pragma message("lu_lagrange has not yet been implemented for your Eigen Version")
#else
#warning lu_lagrange has not yet been implemented for your Eigen Version
#endif
return false;
#else
// number of unknowns
int n = ATA.rows();
// number of lagrange multipliers
int m = C.cols();
assert(ATA.cols() == n);
if(m != 0)
{
assert(C.rows() == n);
if(C.nonZeros() == 0)
{
// See note above about empty columns in C
fprintf(stderr,"Error: lu_lagrange() C has columns but no entries\n");
return false;
}
}
// Check that each column of C has at least one entry
std::vector<bool> has_entry; has_entry.resize(C.cols(),false);
// Iterate over outside
for(int k=0; k<C.outerSize(); ++k)
{
// Iterate over inside
for(typename Eigen::SparseMatrix<T>::InnerIterator it (C,k); it; ++it)
{
has_entry[it.col()] = true;
}
}
for(int i=0;i<(int)has_entry.size();i++)
{
if(!has_entry[i])
{
// See note above about empty columns in C
fprintf(stderr,"Error: lu_lagrange() C(:,%d) has no entries\n",i);
return false;
}
}
// Cholesky factorization of ATA
//// Eigen fails if you give a full view of the matrix like this:
//Eigen::SparseLLT<SparseMatrix<T> > ATA_LLT(ATA);
Eigen::SparseMatrix<T> ATA_LT = ATA.template triangularView<Eigen::Lower>();
Eigen::SparseLLT<Eigen::SparseMatrix<T> > ATA_LLT(ATA_LT);
Eigen::SparseMatrix<T> J = ATA_LLT.matrixL();
//if(!ATA_LLT.succeeded())
if(!((J*0).eval().nonZeros() == 0))
{
fprintf(stderr,"Error: lu_lagrange() failed to factor ATA\n");
return false;
}
if(m == 0)
{
// If there are no constraints (C is empty) then LU decomposition is just L
// and L' from cholesky decomposition
L = J;
U = J.transpose();
}else
{
// Construct helper matrix M
Eigen::SparseMatrix<T> M = C;
J.template triangularView<Eigen::Lower>().solveInPlace(M);
// Compute cholesky factorizaiton of M'*M
Eigen::SparseMatrix<T> MTM = M.transpose() * M;
Eigen::SparseLLT<Eigen::SparseMatrix<T> > MTM_LLT(MTM.template triangularView<Eigen::Lower>());
Eigen::SparseMatrix<T> K = MTM_LLT.matrixL();
//if(!MTM_LLT.succeeded())
if(!((K*0).eval().nonZeros() == 0))
{
fprintf(stderr,"Error: lu_lagrange() failed to factor MTM\n");
return false;
}
// assemble LU decomposition of Q
Eigen::Matrix<int,Eigen::Dynamic,1> MI;
Eigen::Matrix<int,Eigen::Dynamic,1> MJ;
Eigen::Matrix<T,Eigen::Dynamic,1> MV;
//.........这里部分代码省略.........
示例5: predictLong_cpp
// [[Rcpp::export]]
List predictLong_cpp(Rcpp::List in_list)
{
//**********************************
// basic parameter
//**********************************
int nSim = Rcpp::as< int > (in_list["nSim"]);
int nBurnin = Rcpp::as< int > (in_list["nBurnin"] );
int silent = Rcpp::as< int > (in_list["silent"]);
//**********************************
// setting up the main data
//**********************************
//if(silent == 0){
// Rcpp::Rcout << " Setup data\n";
//}
Rcpp::List obs_list = Rcpp::as<Rcpp::List> (in_list["obs_list"]);
int nindv = obs_list.length(); //count number of patients
std::vector< Eigen::SparseMatrix<double,0,int> > As( nindv);
std::vector< Eigen::SparseMatrix<double,0,int> > As_pred( nindv);
std::vector< Eigen::VectorXd > Ys( nindv);
std::vector< Eigen::MatrixXd > pred_ind(nindv);
std::vector< Eigen::MatrixXd > obs_ind(nindv);
std::vector< Eigen::MatrixXd > Bfixed_pred(nindv);
std::vector< Eigen::MatrixXd > Brandom_pred(nindv);
int count;
count = 0;
for( List::iterator it = obs_list.begin(); it != obs_list.end(); ++it ) {
List obs_tmp = Rcpp::as<Rcpp::List>(*it);
As[count] = Rcpp::as<Eigen::SparseMatrix<double,0,int> >(obs_tmp["A"]);
As_pred[count] = Rcpp::as<Eigen::SparseMatrix<double,0,int> >(obs_tmp["Apred"]);
pred_ind[count] = Rcpp::as<Eigen::MatrixXd>(obs_tmp["pred_ind"]);
obs_ind[count] = Rcpp::as<Eigen::MatrixXd>(obs_tmp["obs_ind"]);
Ys[count] = Rcpp::as<Eigen::VectorXd>(obs_tmp["Y"]);
Brandom_pred[count] = Rcpp::as<Eigen::MatrixXd>(obs_tmp["Brandom_pred"]);
Bfixed_pred[count] = Rcpp::as<Eigen::MatrixXd>(obs_tmp["Bfixed_pred"]);
count++;
}
//**********************************
//operator setup
//***********************************
//if(silent == 0){
// Rcpp::Rcout << " Setup operator\n";
//}
Rcpp::List operator_list = Rcpp::as<Rcpp::List> (in_list["operator_list"]);
std::string type_operator = Rcpp::as<std::string>(operator_list["type"]);
operator_list["nIter"] = 1;
operatorMatrix* Kobj;
//Kobj = new MaternMatrixOperator;
operator_select(type_operator, &Kobj);
Kobj->initFromList(operator_list, List::create(Rcpp::Named("use.chol") = 1));
Eigen::VectorXd h = Rcpp::as<Eigen::VectorXd>( operator_list["h"]);
//Prior solver
cholesky_solver Qsolver;
Qsolver.init( Kobj->d, 0, 0, 0);
Qsolver.analyze( Kobj->Q);
Qsolver.compute( Kobj->Q);
//Create solvers for each patient
std::vector< cholesky_solver > Solver( nindv);
Eigen::SparseMatrix<double, 0, int> Q;
count = 0;
for( List::iterator it = obs_list.begin(); it != obs_list.end(); ++it ) {
List obs_tmp = Rcpp::as<Rcpp::List>( *it);
Solver[count].init(Kobj->d, 0, 0, 0);
Q = Eigen::SparseMatrix<double,0,int>(Kobj->Q.transpose());
Q = Q * Kobj->Q;
Q = Q + As[count].transpose()*As[count];
Solver[count].analyze(Q);
Solver[count].compute(Q);
count++;
}
//**********************************
// mixed effect setup
//***********************************
//if(silent == 0){
// Rcpp::Rcout << " Setup mixed effect\n";
//}
Rcpp::List mixedEffect_list = Rcpp::as<Rcpp::List> (in_list["mixedEffect_list"]);
std::string type_mixedEffect = Rcpp::as<std::string> (mixedEffect_list["noise"]);
MixedEffect *mixobj;
if(type_mixedEffect == "Normal")
mixobj = new NormalMixedEffect;
else
mixobj = new NIGMixedEffect;
mixobj->initFromList(mixedEffect_list);
//**********************************
// measurement setup
//***********************************
//.........这里部分代码省略.........