当前位置: 首页>>代码示例>>C++>>正文


C++ SparseMatrix::cols方法代码示例

本文整理汇总了C++中eigen::SparseMatrix::cols方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::cols方法的具体用法?C++ SparseMatrix::cols怎么用?C++ SparseMatrix::cols使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eigen::SparseMatrix的用法示例。


在下文中一共展示了SparseMatrix::cols方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: slice_into

IGL_INLINE void igl::slice_into(
  const Eigen::SparseMatrix<T>& X,
  const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  Eigen::SparseMatrix<T>& Y)
{

  int xm = X.rows();
  int xn = X.cols();
  assert(R.size() == xm);
  assert(C.size() == xn);
#ifndef NDEBUG
  int ym = Y.size();
  int yn = Y.size();
  assert(R.minCoeff() >= 0);
  assert(R.maxCoeff() < ym);
  assert(C.minCoeff() >= 0);
  assert(C.maxCoeff() < yn);
#endif

  // create temporary dynamic sparse matrix
  Eigen::DynamicSparseMatrix<T, Eigen::RowMajor>  dyn_Y(Y);
  // Iterate over outside
  for(int k=0; k<X.outerSize(); ++k)
  {
    // Iterate over inside
    for(typename Eigen::SparseMatrix<T>::InnerIterator it (X,k); it; ++it)
    {
      dyn_Y.coeffRef(R(it.row()),C(it.col())) = it.value();
    }
  }
  Y = Eigen::SparseMatrix<T>(dyn_Y);
}
开发者ID:azer89,项目名称:BBW,代码行数:33,代码来源:slice_into.cpp

示例2: assert

IGL_INLINE void igl::matlab::prepare_lhs_double(
    const Eigen::SparseMatrix<Vtype> & M,
    mxArray *plhs[])
{
    using namespace std;
    const int m = M.rows();
    const int n = M.cols();
    // THIS WILL NOT WORK FOR ROW-MAJOR
    assert(n==M.outerSize());
    const int nzmax = M.nonZeros();
    plhs[0] = mxCreateSparse(m, n, nzmax, mxREAL);
    mxArray * mx_data = plhs[0];
    // Copy data immediately
    double * pr = mxGetPr(mx_data);
    mwIndex * ir = mxGetIr(mx_data);
    mwIndex * jc = mxGetJc(mx_data);

    // Iterate over outside
    int k = 0;
    for(int j=0; j<M.outerSize(); j++)
    {
        jc[j] = k;
        // Iterate over inside
        for(typename Eigen::SparseMatrix<Vtype>::InnerIterator it (M,j); it; ++it)
        {
            // copy (cast to double)
            pr[k] = it.value();
            ir[k] = it.row();
            k++;
        }
    }
    jc[M.outerSize()] = k;

}
开发者ID:Codermay,项目名称:libigl,代码行数:34,代码来源:prepare_lhs.cpp

示例3: convert_from_Eigen

ColCompressedMatrix convert_from_Eigen(const Eigen::SparseMatrix<double> &m)
{
	assert(m.rows() == m.cols());
	assert(m.isCompressed());
	return ColCompressedMatrix(m.rows, m.nonZeros(), 
		m.valuePtr(), m.outerIndexPtr(), m.innerIndexPtr());
}
开发者ID:timbailey74,项目名称:visual-slam,代码行数:7,代码来源:sparse_inverse.hpp

示例4: min

IGL_INLINE void igl::min(
  const Eigen::SparseMatrix<AType> & A,
  const int dim,
  Eigen::PlainObjectBase<DerivedB> & B,
  Eigen::PlainObjectBase<DerivedI> & I)
{
  const int n = A.cols();
  const int m = A.rows();
  B.resize(dim==1?n:m);
  B.setConstant(std::numeric_limits<typename DerivedB::Scalar>::max());
  I.resize(dim==1?n:m);
  for_each(A,[&B,&I,&dim](int i, int j,const typename DerivedB::Scalar v)
    {
      if(dim == 2)
      {
        std::swap(i,j);
      }
      // Coded as if dim == 1, assuming swap for dim == 2
      if(v < B(j))
      {
        B(j) = v;
        I(j) = i;
      }
    });
  Eigen::VectorXi Z;
  find_zero(A,dim,Z);
  for(int j = 0;j<I.size();j++)
  {
    if(Z(j) != (dim==1?m:n) && 0 < B(j))
    {
      B(j) = 0;
      I(j) = Z(j);
    }
  }
}
开发者ID:bbrrck,项目名称:libigl,代码行数:35,代码来源:min.cpp

示例5: erodeSparse

void place::erodeSparse(const Eigen::SparseMatrix<double> &src,
                        Eigen::SparseMatrix<double> &dst) {
  dst = Eigen::SparseMatrix<double>(src.rows(), src.cols());
  std::vector<Eigen::Triplet<double>> tripletList;
  Eigen::MatrixXd srcNS = Eigen::MatrixXd(src);

  for (int i = 0; i < srcNS.cols(); ++i) {
    for (int j = 0; j < srcNS.rows(); ++j) {
      double value = 0.0;
      for (int k = -1; k < 1; ++k) {
        for (int l = -1; l < 1; ++l) {
          if (i + k < 0 || i + k >= srcNS.cols() || j + l < 0 ||
              j + l >= srcNS.rows())
            continue;
          else
            value = std::max(value, srcNS(j + l, i + k));
        }
      }

      if (value != 0)
        tripletList.push_back(Eigen::Triplet<double>(j, i, value));
    }
  }
  dst.setFromTriplets(tripletList.begin(), tripletList.end());
}
开发者ID:erikwijmans,项目名称:WashU_Research,代码行数:25,代码来源:placeScanHelper.cpp

示例6: invertSparseMatrix

matrix<Type> invertSparseMatrix(Eigen::SparseMatrix<Type> A){
  matrix<Type> I(A.rows(),A.cols());
  I.setIdentity();
  Eigen::SimplicialLDLT< Eigen::SparseMatrix<Type> > ldlt(A);
  matrix<Type> ans = ldlt.solve(I);
  return ans;
}
开发者ID:colinpmillar,项目名称:adcomp,代码行数:7,代码来源:spmat.hpp

示例7: assert

/// return the extremal eigenvalues of Ax=cBx
std::pair<double, double>
generalized_extreme_eigenvalues(const Eigen::SparseMatrix<double> &Ain,
                                const Eigen::SparseMatrix<double> &Bin) {
  assert(Ain.rows() == Ain.cols());
  assert(Ain.rows() == Ain.cols());
  assert(Ain.rows() == Bin.rows());
  assert(Ain.isCompressed());
  assert(Bin.isCompressed());
  const int N = static_cast<int>(Ain.rows());

  /* mkl_sparse_d_gv input parameters */
  char which =
      'S';     /* Which eigenvalues to calculate. ('L' - largest (algebraic)
                  eigenvalues, 'S' - smallest (algebraic) eigenvalues) */
  int pm[128]; /* This array is used to pass various parameters to Extended
                  Eigensolver Extensions routines. */
  int k0 = 1;  /* Desired number of max/min eigenvalues */

  /* mkl_sparse_d_gv output parameters */
  int k;             /* Number of eigenvalues found (might be less than k0). */
  double E_small[3]; /* Eigenvalues */
  double E_large[3]; /* Eigenvalues */
  double X[3];       /* Eigenvectors */
  double res[3];     /* Residual */

  /* Local variables */
  int compute_vectors = 0; /* Flag to compute eigenvectors */
  int tol = 7;             /* Tolerance */

  /* Sparse BLAS IE variables */
  sparse_status_t status;

  ConvertToMklResult A = to_mkl(Ain, status); // TODO: check A.status;
  ConvertToMklResult B = to_mkl(Bin, status); // TODO: check B.status;

  /* Step 2. Call mkl_sparse_ee_init to define default input values */
  mkl_sparse_ee_init(pm);

  pm[1] = tol; /* Set tolerance */
  pm[6] = compute_vectors;

  /* Step 3. Solve the standard Ax = ex eigenvalue problem. */
  which = 'S';
  const int infoS = mkl_sparse_d_gv(&which, pm, A.matrix, A.descr, B.matrix,
                                    B.descr, k0, &k, E_small, X, res);
  assert(infoS == 0);

  which = 'L';
  const int infoL = mkl_sparse_d_gv(&which, pm, A.matrix, A.descr, B.matrix,
                                    B.descr, k0, &k, E_large, X, res);
  assert(infoL == 0);

  mkl_sparse_destroy(A.matrix);
  mkl_sparse_destroy(B.matrix);

  return {E_small[0], E_large[0]}; // todo: return the right thing
}
开发者ID:essex-edwards,项目名称:algebraic-ddg,代码行数:58,代码来源:generalized_condition_number.cpp

示例8:

Eigen::SparseMatrix<double> Condi2Joint(Eigen::SparseMatrix<double> Condi, Eigen::SparseVector<double> Pa)
{	// second dimension of Condi is the parent
	Eigen::SparseMatrix<double> Joint;
	Joint.resize(Condi.rows(), Condi.cols());

	for (int cols = 0; cols < Condi.cols(); cols++)
	{
		Eigen::SparseVector<double> tmp_vec = Condi.block(0, cols, Condi.rows(), 1)*Pa.coeff(cols);
		for (int id_rows = 0; id_rows < tmp_vec.size(); id_rows++)
		{
			Joint.coeffRef(id_rows, cols) = tmp_vec.coeff(id_rows);
		}

	}
	Joint.prune(TOLERANCE);
	return Joint;

}
开发者ID:mapleyustat,项目名称:StructureParameterLatentTree,代码行数:18,代码来源:MathProbabilities.cpp

示例9:

Mat::Mat(vector<string> _row_names, vector<string> _col_names,
	Eigen::SparseMatrix<double> _matrix,MatType _mattype)
{
	row_names = _row_names;
	col_names = _col_names;
	assert(row_names.size() == _matrix.rows());
	assert(col_names.size() == _matrix.cols());
	matrix = _matrix;
	mattype = _mattype;
}
开发者ID:smwesten-usgs,项目名称:pestpp,代码行数:10,代码来源:covariance.cpp

示例10: components

IGL_INLINE void igl::components(
  const Eigen::SparseMatrix<AScalar> & A,
  Eigen::PlainObjectBase<DerivedC> & C,
  Eigen::PlainObjectBase<Derivedcounts> & counts)
{
  using namespace Eigen;
  using namespace std;
  assert(A.rows() == A.cols() && "A should be square.");
  const size_t n = A.rows();
  Array<bool,Dynamic,1> seen = Array<bool,Dynamic,1>::Zero(n,1);
  C.resize(n,1);
  typename DerivedC::Scalar id = 0;
  vector<typename Derivedcounts::Scalar> vcounts;
  // breadth first search
  for(int k=0; k<A.outerSize(); ++k)
  {
    if(seen(k))
    {
      continue;
    }
    queue<int> Q;
    Q.push(k);
    vcounts.push_back(0);
    while(!Q.empty())
    {
      const int f = Q.front();
      Q.pop();
      if(seen(f))
      {
        continue;
      }
      seen(f) = true;
      C(f,0) = id;
      vcounts[id]++;
      // Iterate over inside
      for(typename SparseMatrix<AScalar>::InnerIterator it (A,f); it; ++it)
      {
        const int g = it.index();
        if(!seen(g) && it.value())
        {
          Q.push(g);
        }
      }
    }
    id++;
  }
  assert((size_t) id == vcounts.size());
  const size_t ncc = vcounts.size();
  assert((size_t)C.maxCoeff()+1 == ncc);
  counts.resize(ncc,1);
  for(size_t i = 0;i<ncc;i++)
  {
    counts(i) = vcounts[i];
  }
}
开发者ID:bbrrck,项目名称:libigl,代码行数:55,代码来源:components.cpp

示例11:

inline
void
space_operator(
    Eigen::SparseMatrix<double>& result,
    Eigen::SparseMatrix<double>& laplace,
    const double multiplier,
    Eigen::SparseMatrix<double>& unit_matrix)
{
  result.resize(unit_matrix.rows(), unit_matrix.cols());
  result = laplace*multiplier+unit_matrix;
}
开发者ID:aoboturov,项目名称:m2-mo-pde-numerical-methods,代码行数:11,代码来源:lod_cn_travelling_wave.cpp

示例12: B

TEST(slice_into, sparse_identity)
{
  Eigen::SparseMatrix<double> A = Eigen::MatrixXd::Random(10,9).sparseView();
  Eigen::VectorXi I = Eigen::VectorXi::LinSpaced(A.rows(),0,A.rows()-1);
  Eigen::VectorXi J = Eigen::VectorXi::LinSpaced(A.cols(),0,A.cols()-1);
  {
    Eigen::SparseMatrix<double> B(I.maxCoeff()+1,J.maxCoeff()+1);
    igl::slice_into(A,I,J,B);
    test_common::assert_eq(A,B);
  }
  {
    Eigen::SparseMatrix<double> B(I.maxCoeff()+1,A.cols());
    igl::slice_into(A,I,1,B);
    test_common::assert_eq(A,B);
  }
  {
    Eigen::SparseMatrix<double> B(A.rows(),J.maxCoeff()+1);
    igl::slice_into(A,J,2,B);
    test_common::assert_eq(A,B);
  }
}
开发者ID:qnzhou,项目名称:libigl-unit-tests,代码行数:21,代码来源:slice_into.cpp

示例13:

TEST(slice, sparse_identity)
{
  Eigen::SparseMatrix<double> A = Eigen::MatrixXd::Random(10,9).sparseView();
  Eigen::VectorXi I = igl::LinSpaced<Eigen::VectorXi >(A.rows(),0,A.rows()-1);
  Eigen::VectorXi J = igl::LinSpaced<Eigen::VectorXi >(A.cols(),0,A.cols()-1);
  {
    Eigen::SparseMatrix<double> B;
    igl::slice(A,I,J,B);
    test_common::assert_eq(A,B);
  }
  {
    Eigen::SparseMatrix<double> B;
    igl::slice(A,I,1,B);
    test_common::assert_eq(A,B);
  }
  {
    Eigen::SparseMatrix<double> B;
    igl::slice(A,J,2,B);
    test_common::assert_eq(A,B);
  }
}
开发者ID:hankstag,项目名称:libigl,代码行数:21,代码来源:slice.cpp

示例14: cat

IGL_INLINE void igl::cat(
    const int dim, 
    const Eigen::SparseMatrix<Scalar> & A, 
    const Eigen::SparseMatrix<Scalar> & B, 
    Eigen::SparseMatrix<Scalar> & C)
{
  assert(dim == 1 || dim == 2);
  using namespace Eigen;
  // Special case if B or A is empty
  if(A.size() == 0)
  {
    C = B;
    return;
  }
  if(B.size() == 0)
  {
    C = A;
    return;
  }

  DynamicSparseMatrix<Scalar, RowMajor> dyn_C;
  if(dim == 1)
  {
    assert(A.cols() == B.cols());
    dyn_C.resize(A.rows()+B.rows(),A.cols());
  }else if(dim == 2)
  {
    assert(A.rows() == B.rows());
    dyn_C.resize(A.rows(),A.cols()+B.cols());
  }else
  {
    fprintf(stderr,"cat.h: Error: Unsupported dimension %d\n",dim);
  }

  dyn_C.reserve(A.nonZeros()+B.nonZeros());

  // Iterate over outside of A
  for(int k=0; k<A.outerSize(); ++k)
  {
    // Iterate over inside
    for(typename SparseMatrix<Scalar>::InnerIterator it (A,k); it; ++it)
    {
      dyn_C.coeffRef(it.row(),it.col()) += it.value();
    }
  }

  // Iterate over outside of B
  for(int k=0; k<B.outerSize(); ++k)
  {
    // Iterate over inside
    for(typename SparseMatrix<Scalar>::InnerIterator it (B,k); it; ++it)
    {
      int r = (dim == 1 ? A.rows()+it.row() : it.row());
      int c = (dim == 2 ? A.cols()+it.col() : it.col());
      dyn_C.coeffRef(r,c) += it.value();
    }
  }

  C = SparseMatrix<Scalar>(dyn_C);
}
开发者ID:daniel-perry,项目名称:libigl,代码行数:60,代码来源:cat.cpp

示例15: repdiag

IGL_INLINE void igl::repdiag(
  const Eigen::SparseMatrix<T>& A,
  const int d,
  Eigen::SparseMatrix<T>& B)
{
  using namespace std;
  using namespace Eigen;
  int m = A.rows();
  int n = A.cols();

  vector<Triplet<T> > IJV;
  IJV.reserve(A.nonZeros()*d);
  // Loop outer level
  for (int k=0; k<A.outerSize(); ++k)
  {
    // loop inner level
    for (typename Eigen::SparseMatrix<T>::InnerIterator it(A,k); it; ++it)
    {
      for(int i = 0;i<d;i++)
      {
        IJV.push_back(Triplet<T>(i*m+it.row(),i*n+it.col(),it.value()));
      }
    }
  }
  B.resize(m*d,n*d);
  B.setFromTriplets(IJV.begin(),IJV.end());
  

  // Q: Why is this **Very** slow?

  //int m = A.rows();
  //int n = A.cols();

  //B.resize(m*d,n*d);
  //// Reserve enough space for new non zeros
  //B.reserve(d*A.nonZeros());

  //// loop over reps
  //for(int i=0;i<d;i++)
  //{
  //  // Loop outer level
  //  for (int k=0; k<A.outerSize(); ++k)
  //  {
  //    // loop inner level
  //    for (typename Eigen::SparseMatrix<T>::InnerIterator it(A,k); it; ++it)
  //    {
  //      B.insert(i*m+it.row(),i*n+it.col()) = it.value();
  //    }
  //  }
  //}
  //B.makeCompressed();
}
开发者ID:Emisage,项目名称:libigl,代码行数:52,代码来源:repdiag.cpp


注:本文中的eigen::SparseMatrix::cols方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。