void PointMatcher<T>::DataPoints::removeField(const std::string& name, Labels& labels, MatrixType& data) const { const unsigned deleteId = getFieldStartingRow(name, labels); const unsigned span = getFieldDimension(name, labels); const unsigned keepAfterId = deleteId + span; const unsigned lastId = data.rows() - 1; const unsigned sizeKeep = data.rows() - keepAfterId; const unsigned nbPoints = data.cols(); // check if the data to be removed at the end if(keepAfterId <= lastId) { data.block(deleteId, 0, sizeKeep, nbPoints) = data.block(keepAfterId, 0, sizeKeep, nbPoints); } //Remove the last rows data.conservativeResize(data.rows()-span, nbPoints); // remove label from the label list for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { labels.erase(it); break; } } }
void PointMatcher<T>::DataPoints::assertConsistency(const std::string& dataName, const int dataRows, const int dataCols, const Labels& labels) const { if (dataRows == 0) { if (dataCols != 0) throw std::runtime_error( (boost::format("Point cloud has degenerate %2% dimensions of rows=0, cols=%1%") % dataCols % dataName).str() ); if (labels.size() > 0) throw std::runtime_error( (boost::format("Point cloud has no %2% data but %1% descriptor labels") % labels.size() % dataName).str() ); } else { if (dataCols != features.cols()) throw std::runtime_error( (boost::format("Point cloud has %1% points in features but %2% points in %3%") % features.cols() % dataCols % dataName).str() ); int descDim(0); for (BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) descDim += it->span; if (dataRows != descDim) throw std::runtime_error( (boost::format("Labels from %3% return %1% total dimensions but there are %2% in the %3% matrix") % descDim % dataRows % dataName).str() ); } }
unsigned PointMatcher<T>::DataPoints::getFieldDimension(const std::string& name, const Labels& labels) const { for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) return it->span; } return 0; }
unsigned PointMatcher<T>::DataPoints::getFieldStartingRow(const std::string& name, const Labels& labels) const { unsigned row(0); for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) return row; row += it->span; } return 0; }
bool PointMatcher<T>::DataPoints::fieldExists(const std::string& name, const unsigned dim, const Labels& labels) const { for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { if (dim == 0 || it->span == dim) return true; else return false; } } return false; }
typename Eigen::Block<MatrixType> PointMatcher<T>::DataPoints::getViewByName(const std::string& name, const Labels& labels, MatrixType& data, const int viewRow) const { unsigned row(0); for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == name) { if (viewRow >= 0) { if (viewRow >= int(it->span)) throw InvalidField( (boost::format("Requesting row %1% of field %2% that only has %3% rows") % viewRow % name % it->span).str() ); return data.block(row + viewRow, 0, 1, data.cols()); } else return data.block(row, 0, it->span, data.cols()); } row += it->span; } throw InvalidField("Field " + name + " not found"); }
void PointMatcher<T>::DataPoints::allocateFields(const Labels& newLabels, Labels& labels, MatrixType& data) const { typedef vector<bool> BoolVector; BoolVector present(newLabels.size(), false); // for fields that exist, take note and check dimension size_t additionalDim(0); for (size_t i = 0; i < newLabels.size(); ++i) { const string& newName(newLabels[i].text); const size_t newSpan(newLabels[i].span); for(BOOST_AUTO(it, labels.begin()); it != labels.end(); ++it) { if (it->text == newName) { if (it->span != newSpan) throw InvalidField( (boost::format("The existing field %1% has dimension %2%, different than requested dimension %3%") % newName % it->span % newSpan).str() ); present[i] = true; break; } } if (!present[i]) additionalDim += newSpan; } // for new fields allocate const int oldDim(data.rows()); const int totalDim(oldDim + additionalDim); const int pointCount(features.cols()); data.conservativeResize(totalDim, pointCount); for (size_t i = 0; i < newLabels.size(); ++i) { if (!present[i]) labels.push_back(newLabels[i]); } }
double test_set(DBN& dbn, const Samples& images, const Labels& labels, Functor&& f) { return test_set(dbn, images.begin(), images.end(), labels.begin(), labels.end(), std::forward<Functor>(f)); }
void PointMatcher<T>::DataPoints::concatenateLabelledMatrix(Labels* labels, MatrixType* data, const Labels extraLabels, const MatrixType extraData) { const int nbPoints1 = data->cols(); const int nbPoints2 = extraData.cols(); const int nbPointsTotal = nbPoints1 + nbPoints2; if (*labels == extraLabels) { if (labels->size() > 0) { // same descriptors, fast merge data->conservativeResize(Eigen::NoChange, nbPointsTotal); data->rightCols(nbPoints2) = extraData; } } else { // different descriptors, slow merge // collect labels to be kept Labels newLabels; for(BOOST_AUTO(it, labels->begin()); it != labels->end(); ++it) { for(BOOST_AUTO(jt, extraLabels.begin()); jt != extraLabels.end(); ++jt) { if (it->text == jt->text) { if (it->span != jt->span) throw InvalidField( (boost::format("The field %1% has dimension %2% in this, different than dimension %3% in that") % it->text % it->span % jt->span).str() ); newLabels.push_back(*it); break; } } } // allocate new descriptors if (newLabels.size() > 0) { MatrixType newData; Labels filledLabels; this->allocateFields(newLabels, filledLabels, newData); assert(newLabels == filledLabels); // fill unsigned row(0); for(BOOST_AUTO(it, newLabels.begin()); it != newLabels.end(); ++it) { Eigen::Block<MatrixType> view(newData.block(row, 0, it->span, newData.cols())); view.leftCols(nbPoints1) = getViewByName(it->text, *labels, *data); view.rightCols(nbPoints2) = getViewByName(it->text, extraLabels, extraData); row += it->span; } // swap descriptors data->swap(newData); *labels = newLabels; } else { *data = MatrixType(); *labels = Labels(); } } }
// Pre-Processamento: // Remove os comentarios e linhas em branco // E coloca o codigo numa estrutura do tipo CodeLines // Tambem verifica os labels e equs e ifs void readAndPreProcess (const char* fileName) { ifstream infile(fileName); string line; int textMemAddr = textStartAddress; int dataMemAddr = 0; int BSSMemAddr = 0; stringstream tempSS; CodeSection codeSection = NONE; // Le linha a linha for (int lineCount = 1; getline(infile, line); ++lineCount) { // Troca virgulas por espaco strReplace(line, ",", " "); // Ignora linhas em branco if (line.empty()) continue; // Pega palavra a palavra de acordo com os espacos istringstream iss(line); string tempStr; while (iss >> tempStr) { if ("SECTION" == tempStr) { string tempStr2; iss >> tempStr2; if ("TEXT" == tempStr2) codeSection = TEXT; else if ("DATA" == tempStr2) codeSection = DATA; codeLines[lineCount].push_back(tempStr); codeLines[lineCount].push_back(tempStr2); continue; } // Ignora comentarios if (";" == tempStr.substr(0,1)) break; // Desconsidera o caso (maiusculas/minusculas) transform(tempStr.begin(), tempStr.end(), tempStr.begin(), ::toupper); // Ve se eh um label / define if (":" == tempStr.substr(tempStr.length() - 1, 1)) { // Ve se ainda restam tokens na linha if (iss.rdbuf()->in_avail() != 0) { // Remove o ':' tempStr = tempStr.substr(0, tempStr.length() - 1); string tempStr2; iss >> tempStr2; // Ve se o proximo token eh EQU if ("EQU" == tempStr2) { string tempStr3; iss >> tempStr3; // Se define já existe if (defines.find(tempStr3) != defines.end()){ tempSS << lineCount; errors.push("ERRO NA LINHA " + tempSS.str() + ": EQU ja declarado."); tempSS.str(""); } else { // Coloca o valor do EQU na tabela de defines defines[tempStr] = tempStr3; } // Se nao eh so um label // Com algo a mais na mesma linha } else { if ( (labels.find(tempStr) != labels.end()) || (dataLabels.find(tempStr) != dataLabels.end()) ){ tempSS << lineCount; errors.push("ERRO NA LINHA " + tempSS.str() + ": Label ja declarado."); tempSS.str(""); } else { // Adiciona na tabela de labels if(codeSection == TEXT){ labels[tempStr] = textMemAddr; } else if (codeSection == DATA) { dataLabels[tempStr] = dataMemAddr; dataMemAddr += 4; } } // Adiciona endereco de memoria if (instructions.find(tempStr2) != instructions.end()) textMemAddr += get<3>(instructions[tempStr2]); // Adiciona os tokens ao vetor codeLines[lineCount].push_back(tempStr+":"); codeLines[lineCount].push_back(tempStr2); } // Se nao eh um label "sozinho" // Adiciona no vetor } else {
//------------------------------------------------------------------------------ void ImagePlaneProbeWidget::UpdateGUI() { if( mol_ == 0 ) return; updatingGUI_ = true; /// Grid data if( mol_->HasGridData() ) { typedef MolekelMolecule::SurfaceLabels Labels; Labels labels = mol_->GetGridLabels(); gridsComboBox_->setEnabled( labels.size() != 0 ); Labels::const_iterator i = labels.begin(); const Labels::const_iterator end = labels.end(); for( i; i != end; ++i ) gridsComboBox_->addItem( i->c_str() ); const double minValue = mol_->GetGridDataMin( labels.size() ? *( labels.begin() ) : "" ); const double maxValue = mol_->GetGridDataMax( labels.size() ? *( labels.begin() ) : "" ); gridDataRangeLabel_->setText( QString( "(%1, %2)" ).arg( minValue ).arg( maxValue ) ); } else gridDataGroup_->setEnabled( false ); /// Electron density if( mol_->CanComputeElectronDensity() ) eldensGroup_->setEnabled( true ); else eldensGroup_->setEnabled( false ); /// Spin density if( mol_->CanComputeSpinDensity() ) spindensGroup_->setEnabled( true ); else spindensGroup_->setEnabled( false ); /// MEP if( mol_->CanComputeMEP() ) mepGroup_->setEnabled( true ); else mepGroup_->setEnabled( false ); /// Orbitals orbitalsGroup_->setEnabled( false ); if( mol_->GetNumberOfOrbitals() != 0 ) { // update orbitals const int orbitals = mol_->GetNumberOfOrbitals(); table_->setRowCount( orbitals ); QStringList verticalHeaders; for( int i = 0; i != orbitals; ++i ) { QTableWidgetItem *eigenValueItem = new QTableWidgetItem; eigenValueItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); eigenValueItem->setText( QString( "%1" ).arg( mol_->GetOrbitalEigenValue( i ) ) ); QTableWidgetItem *occupationItem = new QTableWidgetItem; occupationItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); occupationItem->setText( QString( "%1" ).arg( mol_->GetOrbitalOccupation( i ) ) ); QTableWidgetItem *typeItem = new QTableWidgetItem; typeItem->setText( QString( "%1" ).arg( mol_->GetOrbitalType( i ) ) ); QTableWidgetItem *selectedItem = new QTableWidgetItem; selectedItem->setCheckState( Qt::Unchecked ); selectedItem->setData( Qt::UserRole, i ); table_->setItem( i, 0, selectedItem ); table_->setItem( i, 1, eigenValueItem ); table_->setItem( i, 2, occupationItem ); table_->setItem( i, 3, typeItem ); if( mol_->IsAlphaOrbital( i ) ) { verticalHeaders << QString( "%1 (%2)" ).arg( i ).arg( tr( "alpha" ) ); } else if( mol_->IsBetaOrbital( i ) ) { verticalHeaders << QString( "%1 (%2)" ).arg( i ).arg( tr( "beta" ) ); } } table_->setVerticalHeaderLabels( verticalHeaders ); table_->resizeColumnsToContents(); /// @todo do we need the following to make sure everything is unselected ? /// table_->setRangeSelected( QTableWidgetSelectionRange( 0, 0, table_->rowCount() - 1, 3 ), false ); } stepSizeSpinBox_->setValue( 0.25 ); updatingGUI_ = false; if( mol_->GetNumberOfOrbitals() != 0 ) orbitalsGroup_->setEnabled( true ); // signals are not emitted since slot are not active during UI update; // emit signals with default value to make sure all observers are // properly initialized // toggle group checkboxes to disable group content orbitalsGroup_->setChecked( true ); orbitalsGroup_->setChecked( false ); emit OrbitalSelected( -1 ); emit StepChanged( stepSizeSpinBox_->value() ); }