Esempio n. 1
0
int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows = 300)
{
  typedef typename MatrixType::Scalar Scalar;
  int rows = internal::random<int>(1,maxRows);
  int cols = internal::random<int>(1,rows);
  double density = (std::max)(8./(rows*cols), 0.01);
  
  A.resize(rows,cols);
  dA.resize(rows,cols);
  initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
  A.makeCompressed();
  int nop = internal::random<int>(0, internal::random<double>(0,1) > 0.5 ? cols/2 : 0);
  for(int k=0; k<nop; ++k)
  {
    int j0 = internal::random<int>(0,cols-1);
    int j1 = internal::random<int>(0,cols-1);
    Scalar s = internal::random<Scalar>();
    A.col(j0)  = s * A.col(j1);
    dA.col(j0) = s * dA.col(j1);
  }
  
//   if(rows<cols) {
//     A.conservativeResize(cols,cols);
//     dA.conservativeResize(cols,cols);
//     dA.bottomRows(cols-rows).setZero();
//   }
  
  return rows;
}
Esempio n. 2
0
int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows = 300, int maxCols = 300)
{
  eigen_assert(maxRows >= maxCols);
  typedef typename MatrixType::Scalar Scalar;
  int rows = internal::random<int>(1,maxRows);
  int cols = internal::random<int>(1,rows);
  double density = (std::max)(8./(rows*cols), 0.01);
  
  A.resize(rows,rows);
  dA.resize(rows,rows);
  initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
  A.makeCompressed();
  return rows;
}
Esempio n. 3
0
static
void create_cluster_dist_mat(
    DenseMat& distMat,
    int cls,
    std::vector<int>& cluster_nodes,
    std::vector<WgtType>& nodes_radii,
    DenseMat& clusterDistMat)
{
    // Steps
    // 1. resize cluster distance matrix
    // 2. match the distance from distMat to clusterDistMat
    // 3. add central node influence

    // Step 1
    clusterDistMat.resize(cluster_nodes.size()+1, cluster_nodes.size()+1);
    clusterDistMat.fill(0);

    // Step 2
    int rowIdx;
    int colIdx;
    for (int c=0; c<cluster_nodes.size(); ++c)
    {
        for (int r=0; r<cluster_nodes.size(); ++r)
        {
            rowIdx = cluster_nodes.at(r);
            colIdx = cluster_nodes.at(c);
            clusterDistMat(r+1, c+1) = distMat(rowIdx, colIdx);
        }
    }

    // Step 3
    for (int i=0; i<nodes_radii.size(); ++i)
    {
        clusterDistMat(0, i+1) = nodes_radii.at(i);
        clusterDistMat(i+1, 0) = nodes_radii.at(i);

    }
}