/** Set up the internal matrices used to accumulate image statistics, * and initialize the batch size. */ void cv_mean_extractor::set(const unsigned int width, const unsigned int height, const unsigned int n_ch, const unsigned int batch_sz) { if (!m_sum.empty() || (width == 0u) || (height == 0u) || (n_ch == 0u) || (batch_sz == 0u)) { std::stringstream err; err << __FILE__ << " " << __LINE__ << " :: cv_mean_extractor: either using an invalid " << "parameter or attempting to reconfigure"; throw lbann_exception(err.str()); } m_batch_size = batch_sz; create_matrices(width, height, n_ch); reset(); }
/** * If the size or the number of channels of the given image is different * from what is expected, fails. */ bool cv_mean_extractor::determine_transform(const cv::Mat& image) { m_enabled = false; _LBANN_SILENT_EXCEPTION(image.empty(), "", false); // If it has not been configured (other than batch size), do it here if (m_sum.empty()) { create_matrices(image.cols, image.rows, image.channels()); reset(); m_enabled = true; } else { m_enabled = check_if_cv_Mat_has_same_shape(image, m_avg); } return m_enabled; }
/* Find the DBBD form */ int shylu_symbolic_factor ( Epetra_CrsMatrix *A, // i/p: A matrix shylu_symbolic *ssym, // symbolic structure shylu_data *data, // numeric structure, TODO: Required ? shylu_config *config // i/p: library configuration ) { #ifdef TIMING_OUTPUT Teuchos::Time symtime("symbolic time"); symtime.start(); #endif int myPID = A->Comm().MyPID(); int n = A->NumGlobalRows(); int Dnr; int Snr; int *DRowElems; int *SRowElems; int sym = config->sym; checkMaps(A); // Get column map Epetra_Map AColMap = A->ColMap(); int ncols = AColMap.NumMyElements(); int *cols = AColMap.MyGlobalElements(); // Get row map Epetra_Map ARowMap = A->RowMap(); int nrows = ARowMap.NumMyElements(); int *rows = ARowMap.MyGlobalElements(); // Find all columns in this proc int *gvals = new int[n]; // vector of size n, not ncols ! // gvals[local cols] = 1, gvals[shared cols] > 1. int SNumGlobalCols; findLocalColumns(A, gvals, SNumGlobalCols); // See if you can shrink the separator by assigning more rows/columns to // the block diagonals // TODO: This is because of a bug in coloring remove the if once that is // fixed //if (config->schurApproxMethod == 2) if (config->sep_type == 2) findNarrowSeparator(A, gvals); // 3. Assemble diagonal block and the border in convenient form [ /* In each processor, we have (in a permuted form) * | D_i C_i | * | R_i S_i | * D_i - diagonal block, C_i - Column Separator, R_i - Row separator * S_i - A22 block corresponding to Schur complement part of A * Assemble all four blocks in local matrices. */ ostringstream ssmsg1; ssmsg1 << "PID =" << myPID << " "; string msg = ssmsg1.str(); ssmsg1.clear(); ssmsg1.str(""); // Find #cols in each block int Dnc = 0; // #cols in diagonal block int Snc = 0; // #cols in the col. separator /* Looping on cols will work only for wide separator * as for narrow sep there will be some sep cols with gvals[col] ==1 * */ /*for (int i = 0; i < ncols ; i++) { if (gvals[cols[i]] == 1) Dnc++; else Snc++; } // Find #rows in each block Dnr = Dnc; // #rows in square diagonal block Snr = nrows - Dnr; // #rows in the row separator*/ // Find #rows in each block Dnr = 0; Snr = 0; for (int i = 0; i < nrows ; i++) { if (gvals[rows[i]] == 1) Dnr++; else Snr++; } Dnc = Dnr; // TODO: Snc is no longer useful, should remove it for (int i = 0; i < ncols ; i++) { if (gvals[cols[i]] != 1) Snc++; } assert(Snc >= 0); // TODO : The above assignment may not be correct in the unsymetric case ////config->dm.print(2, msg + " Mycols="); cout << msg << " Mycols="<< ncols << "Myrows ="<< nrows << endl; cout << msg << " #rows and #cols in diagonal blk ="<< Dnr << endl; cout << msg << " #columns in S ="<< Snc << endl; cout << msg << " #rows in S ="<< Snr << endl; ostringstream pidstr; pidstr << myPID ; // Create a row map for the D and S blocks [ DRowElems = new int[Dnr]; SRowElems = new int[Snr]; int gid; // Assemble row ids in two arrays (for D and R blocks) if (sym) { findBlockElems(A, nrows, rows, gvals, Dnr, DRowElems, Snr, SRowElems, "D"+pidstr.str()+"Rows", "S"+pidstr.str()+"Rows", false) ; } else { // SRowElems are not known until factorization, TODO assert(0 == 1); } data->Dnr = Dnr; data->Snr = Snr; data->Dnc = Dnc; data->DRowElems = DRowElems; data->SRowElems = SRowElems; // Create a column map for the D and S blocks [ int *DColElems = new int[Dnc]; // Elems in column map of D int *SColElems = new int[Snc]; // Elems in column map of C TODO: Unused // Assemble column ids in two arrays (for D and C blocks) findBlockElems(A, ncols, cols, gvals, Dnc, DColElems, Snc, SColElems, "D"+pidstr.str()+"Cols", "S"+pidstr.str()+"Cols", true) ; data->DColElems = DColElems; data->gvals = gvals; for (int i = 0; i < Snr; i++) { // Epetra guarentees columns corresponding to local rows will be first // in the column map. assert(SRowElems[i] == SColElems[i]); } // ] /*--Create the Epetra Matrices with the maps (does not insert values) --- */ create_matrices(A, ssym, data, config); /*--Extract the Epetra Matrices and call fillComplete --- */ extract_matrices(A, ssym, data, config, true); delete[] SColElems; Amesos Factory; const char* SolverType = config->diagonalBlockSolver.c_str(); bool IsAvailable = Factory.Query(SolverType); assert(IsAvailable == true); Teuchos::RCP<Epetra_LinearProblem> LP = Teuchos::RCP<Epetra_LinearProblem> (new Epetra_LinearProblem()); LP->SetOperator((ssym->D).getRawPtr()); //LP->SetOperator((ssym->DT).getRawPtr()); // for transpose // Create temp vectors ssym->Dlhs = Teuchos::RCP<Epetra_MultiVector> (new Epetra_MultiVector(ssym->D->RowMap(), 16)); ssym->Drhs = Teuchos::RCP<Epetra_MultiVector> (new Epetra_MultiVector(ssym->D->RowMap(), 16)); ssym->Gvec = Teuchos::RCP<Epetra_MultiVector> (new Epetra_MultiVector(ssym->G->RowMap(), 16)); LP->SetRHS(ssym->Drhs.getRawPtr()); LP->SetLHS(ssym->Dlhs.getRawPtr()); ssym->ReIdx_LP = Teuchos::RCP< EpetraExt::ViewTransform<Epetra_LinearProblem> > (new EpetraExt::LinearProblem_Reindex2(0)); ssym->LP = Teuchos::RCP<Epetra_LinearProblem>(&((*(ssym->ReIdx_LP))(*LP)), false); Teuchos::RCP<Amesos_BaseSolver> Solver = Teuchos::RCP<Amesos_BaseSolver> (Factory.Create(SolverType, *(ssym->LP))); //config->dm.print(5, "Created the diagonal solver"); #ifdef TIMING_OUTPUT Teuchos::Time ftime("setup time"); ftime.start(); #endif //Solver->SetUseTranspose(true); // for transpose Teuchos::ParameterList aList; aList.set("TrustMe", true); Solver->SetParameters(aList); Solver->SymbolicFactorization(); //config->dm.print(3, "Symbolic Factorization done"); #ifdef TIMING_OUTPUT ftime.stop(); cout << "Symbolic Factorization Time" << ftime.totalElapsedTime() << endl; ftime.reset(); #endif ssym->OrigLP = LP; //ssym->LP = LP; ssym->Solver = Solver; if (config->schurApproxMethod == 1) { Teuchos::ParameterList pList; Teuchos::RCP<Isorropia::Epetra::Prober> prober = Teuchos::RCP<Isorropia::Epetra::Prober> (new Isorropia::Epetra::Prober((ssym->Sg).getRawPtr(), pList, false)); //config->dm.print(3, "Doing Coloring"); #ifdef TIMING_OUTPUT ftime.start(); #endif prober->color(); #ifdef TIMING_OUTPUT ftime.stop(); cout << "Time to color" << ftime.totalElapsedTime() << endl; ftime.reset(); ftime.start(); #endif ssym->prober = prober; } #ifdef TIMING_OUTPUT symtime.stop(); cout << "Symbolic Time" << symtime.totalElapsedTime() << endl; symtime.reset(); #endif }