Esempio n. 1
0
// simple {DM,IM} and {DV,IV} arrays
void dumpDM(const DM& A, const char* s) { 
  DMat M; M.load(A.num_rows(),A.num_cols(), A.data());
  M.print(g_MSGFile, s, "lf", 4, 8, 51,0,50); 
}
Esempio n. 2
0
int main(int argc, char** argv)
{
    
    DM DualMesh;
    if ((argc!=4) && (argc!=6))
    {
       cout<<endl;
       cout<<" -------------------- Curvature Filter ------------------------- "<<endl;
       cout<<" Please cite Yuanhao's PhD thesis and related papers. Thank you! "<<endl;
       cout<<" --------------------------------------------------------------- \n\n";
       cout<<"usage: main imageName filterType Iterations.\n For example: ./cf lena.bmp m 30\n";
       cout<<"             or              "<<endl;
       cout<<"usage: main imageName filterType MaxItNum lambda DataFitOrder.\n For example: ./cf lena.bmp m 30 1.2 1.5\n";
       cout<<"************************************************\n";
       cout<<"Possible Filter Type: t (Total Variation) \n";
       cout<<"                      m (Mean Curvature) \n";
       cout<<"                      g (Gaussian Curvature) \n";
       cout<<"                      d (Difference Curvature) \n";
       cout<<"                      b (Bernstein Filter) \n";
       return -1;
    }

    DualMesh.read(argv[1]);

    char * filterType = argv[2];
    if (*filterType == 't') Type = 0;
    if (*filterType == 'm') Type = 1;
    if (*filterType == 'd') Type = 3;
    if (*filterType == 'b') Type = 4;

    ItNum = atoi(argv[3]);

    if (argc==6)
    {
    	lambda = atof(argv[4]);
    	DataFitOrder = atof(argv[5]);
    }

    DualMesh.split();
    double mytime;
    DualMesh.Filter(Type, mytime, ItNum);
    cout<<"runtime is "<<mytime<<" milliseconds."<<endl;

    DualMesh.merge();
    DualMesh.write();

    DualMesh.read(argv[1]);
    DualMesh.FilterNoSplit(Type, mytime, ItNum);
    cout<<"runtime (noSplit) is "<<mytime<<" milliseconds."<<endl;
    DualMesh.write("CF_NoSplit_result.png");
    
    if (argc==6)
    {
        //filter solver for the variational models
        DualMesh.read(argv[1]);
	    DualMesh.Solver(Type, mytime, ItNum, lambda, DataFitOrder);
	    cout<<"runtime is "<<mytime<<" milliseconds."<<endl;
	    DualMesh.write("CF_Solver.png");
    }
    
    return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{

  // A
  int ncol = 5, nrow = 5;
  vector<int> colind = {0, 3, 6, 8, 10, 12};
  vector<int> row = {0, 1, 4, 1, 2, 4, 0, 2, 0, 3, 3, 4};
  vector<double> nz = {19, 12, 12, 21, 12, 12, 21, 16, 21, 5, 21, 18};
  DM A(Sparsity(nrow, ncol, colind, row), nz);

  // Right hand side
  DM b = DM::ones(ncol);

  // Type of linear systems
  enum SymType {UNSYM, SYM, PD};

  // All Linear solvers to be tested
  struct Test {
    string solver;
    SymType type;
  };
  vector<Test> tests;
  tests.push_back({"csparse", UNSYM});
  tests.push_back({"csparsecholesky", PD});
  tests.push_back({"lapacklu", UNSYM});
  tests.push_back({"lapackqr", UNSYM});
  tests.push_back({"ma27", SYM});
  tests.push_back({"symbolicqr", UNSYM});

  // Test all combinations
  for (auto s : {UNSYM, SYM, PD}) {
    DM A_test;
    switch (s) {
    case UNSYM:
      cout << "Unsymmetric linear system" << endl;
      A_test = A;
      break;
    case SYM:
      cout << "Symmetric linear system" << endl;
      A_test = A + A.T();
      break;
    case PD:
      cout << "Positive definite linear system" << endl;
      A_test = mtimes(A.T(), A);
      break;
    }
    for (auto t : tests) {
      if (t.type > s) continue; // Cannot be solved
      if (!Linsol::has_plugin(t.solver)) {
        cout << t.solver << " not available" << endl;
        continue;
      }

      // Create a solver instance
      Linsol F("F", t.solver);

      // Solve
      F.reset(A_test.sparsity());
      F.pivoting(A_test.ptr());
      F.factorize(A_test.ptr());
      DM x = densify(b);
      F.solve(x.ptr(), x.size2());

      // Print the solution
      cout << "solution: " << x << " (" <<  t.solver << ")" << endl;
    }
  }

  return 0;
}