int main() { std::clock_t timer; timer = std::clock(); Image M; try { M = imProcess(IMAGE, COLORED); } catch (too_many_chars_per_pixel e) { std::cerr << "Too many chars per pixel\n"; exit(1); } catch (not_color_format e) { std::cerr << "Included XPM not in color format\n"; exit(1); } catch (std::out_of_range e) { std::cerr << "Pixel descriptor not in hash table\n"; exit(1); } // Problem: for some reason, the online xpm file converter only retains 256 colors, // diminishing image quality for color images Image sparseImage(M); makeSparse(sparseImage.R, 0.7); if (sparseImage.color) { makeSparse(sparseImage.G, 0.7); makeSparse(sparseImage.B, 0.7); } Image naiveRepair(sparseImage); naivenn(naiveRepair.R, 16); if (naiveRepair.color) { naivenn(naiveRepair.G, 16); naivenn(naiveRepair.B, 16); } std::ofstream f1, f2, f3; f1.open("./output/original.txt"); f2.open("./output/sparse.txt"); f3.open("./output/naiveRecon.txt"); printImage(f1, M); printImage(f2, sparseImage); printImage(f3, naiveRepair); f1.close(); f2.close(); f3.close(); timer = std::clock()-timer; std::cout << "Time elapsed: " << double(timer)/CLOCKS_PER_SEC << '\n'; return 0; }
void CSparseCholeskyInternal::prepare(){ prepared_ = false; // Get a reference to the nonzeros of the linear system const vector<double>& linsys_nz = input().data(); // Make sure that all entries of the linear system are valid for(int k=0; k<linsys_nz.size(); ++k){ casadi_assert_message(!isnan(linsys_nz[k]),"Nonzero " << k << " is not-a-number"); casadi_assert_message(!isinf(linsys_nz[k]),"Nonzero " << k << " is infinite"); } if(verbose()){ cout << "CSparseCholeskyInternal::prepare: numeric factorization" << endl; cout << "linear system to be factorized = " << endl; input(0).printSparse(); } if(L_) cs_nfree(L_); L_ = cs_chol(&AT_, S_) ; // numeric Cholesky factorization if(L_==0){ DMatrix temp = input(); makeSparse(temp); if (isSingular(temp.sparsity())) { stringstream ss; ss << "CSparseCholeskyInternal::prepare: factorization failed due to matrix being singular. Matrix contains numerical zeros which are structurally non-zero. Promoting these zeros to be structural zeros, the matrix was found to be structurally rank deficient. sprank: " << rank(temp.sparsity()) << " <-> " << temp.size1() << endl; if(verbose()){ ss << "Sparsity of the linear system: " << endl; input(LINSOL_A).sparsity().print(ss); // print detailed } throw CasadiException(ss.str()); } else { stringstream ss; ss << "CSparseCholeskyInternal::prepare: factorization failed, check if Jacobian is singular" << endl; if(verbose()){ ss << "Sparsity of the linear system: " << endl; input(LINSOL_A).sparsity().print(ss); // print detailed } throw CasadiException(ss.str()); } } casadi_assert(L_!=0); prepared_ = true; }