void ListView::adjustColumn() { if (m_expandingColumn >= 0){ int w = width(); QScrollBar *vBar = verticalScrollBar(); if (vBar->isVisible()) w -= vBar->width(); for (int i = 0; i < columns(); i++){ if (i == m_expandingColumn) continue; w -= columnWidth(i); } if (w < 40) w = 40; setColumnWidth(m_expandingColumn, w - 4); viewport()->repaint(); } }
XMLRowOutputStream::XMLRowOutputStream(WriteBuffer & ostr_, const Block & sample_) : dst_ostr(ostr_) { NamesAndTypesList columns(sample_.getColumnsList()); fields.assign(columns.begin(), columns.end()); field_tag_names.resize(sample_.columns()); bool have_non_numeric_columns = false; for (size_t i = 0; i < sample_.columns(); ++i) { if (!sample_.unsafeGetByPosition(i).type->isNumeric()) have_non_numeric_columns = true; /// В качестве имён элементов будем использовать имя столбца, если оно имеет допустимый вид, или "field", иначе. /// Условие, приведённое ниже, более строгое, чем того требует стандарт XML. bool is_column_name_suitable = true; const char * begin = fields[i].name.data(); const char * end = begin + fields[i].name.size(); for (const char * pos = begin; pos != end; ++pos) { char c = *pos; if (!( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (pos != begin && c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.')) { is_column_name_suitable = false; break; } } field_tag_names[i] = is_column_name_suitable ? fields[i].name : "field"; } if (have_non_numeric_columns) { validating_ostr.reset(new WriteBufferValidUTF8(dst_ostr)); ostr = validating_ostr.get(); } else ostr = &dst_ostr; }
QList<QPoint> PrimMaze::neighbors(const QPoint& cell) { QList<QPoint> n; if (cell.x() > 0) { n.append(cell + QPoint(-1, 0)); } if (cell.y() > 0) { n.append(cell + QPoint(0, -1)); } if (cell.y() < rows() - 1) { n.append(cell + QPoint(0, 1)); } if (cell.x() < columns() - 1) { n.append(cell + QPoint(1, 0)); } return n; }
rePTerrainRenderable::rePTerrainRenderable() { node = 0; columns(256); rows(256); size(reVec2(2, 2)); textures[3] = new reTexture(); textures[3]->fileName("/materials/textures/tiles/arctic/Snow0095_2_S.jpg"); textures[1] = new reTexture(); textures[1]->fileName("materials/textures/tiles/arctic/Snow0041_5_S.jpg"); textures[2] = new reTexture(); textures[2]->fileName("materials/textures/tiles/arctic/Snow0041_5_S.jpg"); textures[0] = new reTexture(); textures[0]->fileName("materials/textures/tiles/arctic/Snow0041_5_S.jpg"); mesh = new reMesh; load(); }
ProgressResult TimerRecordDialog::PreActionDelay(int iActionIndex, TimerRecordCompletedActions eCompletedActions) { wxString sAction = m_pTimerAfterCompleteChoiceCtrl->GetString(iActionIndex); wxString sCountdownLabel; sCountdownLabel.Printf("%s in:", sAction); // Two column layout. TimerProgressDialog::MessageTable columns(2); auto &column1 = columns[0]; auto &column2 = columns[1]; column1.push_back(_("Timer Recording completed.")); column2.push_back( {} ); column1.push_back( {} ); column2.push_back( {} ); column1.push_back(_("Recording Saved:")); column2.push_back(((eCompletedActions & TR_ACTION_SAVED) ? _("Yes") : _("No"))); column1.push_back(_("Recording Exported:")); column2.push_back(((eCompletedActions & TR_ACTION_EXPORTED) ? _("Yes") : _("No"))); column1.push_back(_("Action after Timer Recording:")); column2.push_back(sAction); wxDateTime dtNow = wxDateTime::UNow(); wxTimeSpan tsWait = wxTimeSpan(0, 1, 0, 0); wxDateTime dtActionTime = dtNow.Add(tsWait); TimerProgressDialog dlgAction(tsWait.GetMilliseconds().GetValue(), _("Audacity Timer Record - Waiting"), columns, pdlgHideStopButton | pdlgHideElapsedTime, sCountdownLabel); auto iUpdateResult = ProgressResult::Success; bool bIsTime = false; while (iUpdateResult == ProgressResult::Success && !bIsTime) { iUpdateResult = dlgAction.UpdateProgress(); wxMilliSleep(10); bIsTime = (dtActionTime <= wxDateTime::UNow()); } return iUpdateResult; }
bool Matrix<Type>::equalWithTolerance(const Matrix& otherMatrix, const Type tolerance) const { if (size != otherMatrix.size) { return false; } for (long int i = 0; i < rows(); i++) { for (long int j = 0; j < columns(); j++) { Type first = access(i, j), second = otherMatrix.access(i, j); if (((first - second) > tolerance) || (second - first) > tolerance) { return false; } } } return true; }
ColumnPtr FunctionArrayIntersect::castRemoveNullable(const ColumnPtr & column, const DataTypePtr & data_type) const { if (auto column_nullable = checkAndGetColumn<ColumnNullable>(column.get())) { auto nullable_type = checkAndGetDataType<DataTypeNullable>(data_type.get()); const auto & nested = column_nullable->getNestedColumnPtr(); if (nullable_type) { auto casted_column = castRemoveNullable(nested, nullable_type->getNestedType()); return ColumnNullable::create(casted_column, column_nullable->getNullMapColumnPtr()); } return castRemoveNullable(nested, data_type); } else if (auto column_array = checkAndGetColumn<ColumnArray>(column.get())) { auto array_type = checkAndGetDataType<DataTypeArray>(data_type.get()); if (!array_type) throw Exception{"Cannot cast array column to column with type " + data_type->getName() + " in function " + getName(), ErrorCodes::LOGICAL_ERROR}; auto casted_column = castRemoveNullable(column_array->getDataPtr(), array_type->getNestedType()); return ColumnArray::create(casted_column, column_array->getOffsetsPtr()); } else if (auto column_tuple = checkAndGetColumn<ColumnTuple>(column.get())) { auto tuple_type = checkAndGetDataType<DataTypeTuple>(data_type.get()); if (!tuple_type) throw Exception{"Cannot cast tuple column to type " + data_type->getName() + " in function " + getName(), ErrorCodes::LOGICAL_ERROR}; auto columns_number = column_tuple->getColumns().size(); Columns columns(columns_number); const auto & types = tuple_type->getElements(); for (auto i : ext::range(0, columns_number)) { columns[i] = castRemoveNullable(column_tuple->getColumnPtr(i), types[i]); } return ColumnTuple::create(columns); } return column; }
void ListView::resizeColums() { int c = columns(); if(c == 0) { return; } int w1 = viewport()->width(); int w2 = w1 / c; int w3 = w1 - (c - 1) * w2; for(int i = 0; i < c - 1; i++) { setColumnWidth(i, w2); } setColumnWidth(c - 1, w3); }
// get the covariance of a contrast given a contrast vector // if this matrix is X, this function computes c' pinv(X'X) c double RtDesignMatrix::computeContrastCovariance( vnl_vector<double> &contrastVector) { if (contrastVector.size() != columns()) { cerr << "ERROR: number of elements in contrast vector does not match the " << "number of columns in the design matrix" << endl; return std::numeric_limits<double>::quiet_NaN(); } // compute the contrast covariance based on the currently known regressors // NOTE: this will not be the same as computing it at the end of the // experiment when all regressors are known. it would be nice to compute // final values using the known design. vnl_matrix<double> convec(contrastVector.data_block(), contrastVector.size(), 1); vnl_svd<double> pinv(transpose() * (*this)); vnl_matrix<double> result = convec.transpose() * pinv.pinverse() * convec; return result.get(0, 0); }
/** * Perform an LU decomposition. LAPACK routine DGBTRF is used. * The factorization is saved in ludata. */ int BandMatrix::factor() { int info=0; copy(data.begin(), data.end(), ludata.begin()); ct_dgbtrf(rows(), columns(), nSubDiagonals(), nSuperDiagonals(), DATA_PTR(ludata), ldim(), DATA_PTR(ipiv()), info); // if info = 0, LU decomp succeeded. if (info == 0) { m_factored = true; } else { m_factored = false; ofstream fout("bandmatrix.csv"); fout << *this << endl; fout.close(); } return info; }
bool QGLPixmapConvolutionFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const { QGLPixmapConvolutionFilter *filter = const_cast<QGLPixmapConvolutionFilter *>(this); m_srcSize = src.size(); int kernelSize = rows() * columns(); if (m_prevKernelSize == -1 || m_prevKernelSize != kernelSize) { filter->setSource(generateConvolutionShader()); m_prevKernelSize = kernelSize; } filter->setOnPainter(painter); painter->drawPixmap(pos, src, srcRect); filter->removeFromPainter(painter); return true; }
storage::atable_ptr_t createRawTable() { metadata_vec_t columns({ *ColumnMetadata::metadataFromString("INTEGER", "col1"), *ColumnMetadata::metadataFromString("STRING", "col2"), *ColumnMetadata::metadataFromString("FLOAT", "col3") }); auto main = std::make_shared<RawTable<>>(columns); storage::rawtable::RowHelper rh(columns); unsigned char *data = nullptr; for(size_t i=0; i<10; i++) { rh.set<storage::hyrise_int_t>(0, i); rh.set<storage::hyrise_string_t>(1, "SomeText" + std::to_string(i)); rh.set<storage::hyrise_float_t>(2, 1.1*i); data = rh.build(); main->appendRow(data); free(data); } return main; }
QString MultiModelPrinter::printGvars() { QString str = printTitle(tr("Global Variables")); int gvars = firmware->getCapability(Gvars); MultiColumns columns(models.size()); columns.append("<table border='0' cellspacing='0' cellpadding='1' width='100%'><tr>"); for (int i=0; i<gvars; i++) { columns.append(QString("<td><b>") + tr("GV%1").arg(i+1) + "</b></td>"); } columns.append("</tr><tr>"); for (int i=0; i<gvars; i++) { columns.append("<td>"); COMPARE(model->flightModeData[0].gvars[i]); columns.append("</td>"); } columns.append("</tr>"); str.append(columns.print()); return str; }
TEST_F(VirtualTableTests, test_tableplugin_options) { auto table = std::make_shared<optionsTablePlugin>(); EXPECT_EQ(ColumnOptions::INDEX | ColumnOptions::REQUIRED, std::get<2>(table->columns()[0])); PluginResponse response; PluginRequest request = {{"action", "columns"}}; EXPECT_TRUE(table->call(request, response).ok()); auto index_required = static_cast<size_t>(ColumnOptions::INDEX | ColumnOptions::REQUIRED); EXPECT_EQ(INTEGER(index_required), response[0]["op"]); response = table->routeInfo(); EXPECT_EQ(INTEGER(index_required), response[0]["op"]); std::string expected_statement = "(`id` INTEGER PRIMARY KEY, `username` TEXT, `name` TEXT) WITHOUT ROWID"; EXPECT_EQ(expected_statement, columnDefinition(response, true)); }
sparse<double> sprand(size_t nrow, size_t ncol, double density) { assert(density <= 1 && density > 0); size_t n = (size_t)(density * nrow * ncol); dense_vector<size_t> rows(n); dense_vector<size_t> columns(n); dense_vector<double> values(n); for (size_t i = 0; i < n; ++i) { rows[i] = (size_t)RANDI(0, nrow - 1); columns[i] = (size_t)RANDI(0, ncol - 1); values[i] = RAND(); } return triplet<double>(rows, columns, values, nrow, ncol, n).to_sparse(); }
Block ODBCBlockInputStream::readImpl() { if (iterator == result.end()) return {}; MutableColumns columns(description.sample_block.columns()); for (const auto i : ext::range(0, columns.size())) columns[i] = description.sample_block.getByPosition(i).column->cloneEmpty(); size_t num_rows = 0; while (iterator != result.end()) { Poco::Data::Row & row = *iterator; for (const auto idx : ext::range(0, row.fieldCount())) { const Poco::Dynamic::Var & value = row[idx]; if (!value.isEmpty()) { if (description.types[idx].second) { ColumnNullable & column_nullable = static_cast<ColumnNullable &>(*columns[idx]); insertValue(column_nullable.getNestedColumn(), description.types[idx].first, value); column_nullable.getNullMapData().emplace_back(0); } else insertValue(*columns[idx], description.types[idx].first, value); } else insertDefaultValue(*columns[idx], *description.sample_block.getByPosition(idx).column); } ++iterator; ++num_rows; if (num_rows == max_block_size) break; } return description.sample_block.cloneWithColumns(std::move(columns)); }
int TextDisplay::_putc(int value) { if(value == '\n') { _column = 0; _row++; if(_row >= rows()) { _row = 0; } } else { character(_column, _row, value); _column++; if(_column >= columns()) { _column = 0; _row++; if(_row >= rows()) { _row = 0; } } } return value; }
int GridLayoutItem::rows() const { int result = 0; if( m_listController ) { int count = m_listController->count(); int _columns = columns(); result = count / _columns; if( (count % _columns) != 0 ) { result++; } } return result; }
/** Sets the file format for the file to import, which * may cause the file to be reloaded as well if the * previously set file format was different and a * filename was already set. * @param format the new format to set * @exception std::ifstream::failure if file reloading fails */ void GncTxImport::file_format(GncImpFileFormat format) { if (m_tokenizer && m_settings.m_file_format == format) return; auto new_encoding = std::string("UTF-8"); auto new_imp_file = std::string(); // Recover common settings from old tokenizer if (m_tokenizer) { new_encoding = m_tokenizer->encoding(); new_imp_file = m_tokenizer->current_file(); if (file_format() == GncImpFileFormat::FIXED_WIDTH) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); if (!fwtok->get_columns().empty()) m_settings.m_column_widths = fwtok->get_columns(); } } m_settings.m_file_format = format; m_tokenizer = gnc_tokenizer_factory(m_settings.m_file_format); // Set up new tokenizer with common settings // recovered from old tokenizer m_tokenizer->encoding(new_encoding); load_file(new_imp_file); // Restore potentially previously set separators or column_widths if ((file_format() == GncImpFileFormat::CSV) && !m_settings.m_separators.empty()) separators (m_settings.m_separators); else if ((file_format() == GncImpFileFormat::FIXED_WIDTH) && !m_settings.m_column_widths.empty()) { auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get()); fwtok->columns (m_settings.m_column_widths); } }
int show_sysfs(const char *seat, const char *prefix, unsigned n_columns) { _cleanup_udev_unref_ struct udev *udev; _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL; struct udev_list_entry *first = NULL; int r; if (n_columns <= 0) n_columns = columns(); if (!prefix) prefix = ""; if (isempty(seat)) seat = "seat0"; udev = udev_new(); if (!udev) return -ENOMEM; e = udev_enumerate_new(udev); if (!e) return -ENOMEM; if (!streq(seat, "seat0")) r = udev_enumerate_add_match_tag(e, seat); else r = udev_enumerate_add_match_tag(e, "seat"); if (r < 0) return r; r = udev_enumerate_scan_devices(e); if (r < 0) return r; first = udev_enumerate_get_list_entry(e); if (first) show_sysfs_one(udev, seat, &first, "/", prefix, n_columns); return r; }
void SEQListView::savePrefs() { // only save the preferences if visible if (isVisible()) { int i; int width; QString columnName; QString show = "Show"; // save the column width's/visibility for (i = 0; i < columns(); i++) { columnName = columnPreferenceName(i); width = columnWidth(i); if (width != 0) { pSEQPrefs->setPrefInt(columnName + "Width", preferenceName(), width); pSEQPrefs->setPrefBool(show + columnName, preferenceName(), true); } else pSEQPrefs->setPrefBool(show + columnName, preferenceName(), false); } // save the column order QString tempStr, tempStr2; if (header()->count() > 0) tempStr.sprintf("%d", header()->mapToSection(0)); for(i=1; i < header()->count(); i++) { tempStr2.sprintf(":%d", header()->mapToSection(i)); tempStr += tempStr2; } pSEQPrefs->setPrefString("ColumnOrder", preferenceName(), tempStr); // save the current sorting state pSEQPrefs->setPrefInt("SortColumn", preferenceName(), m_sortColumn); pSEQPrefs->setPrefBool("SortIncreasing", preferenceName(), m_sortIncreasing); } }
void Restore::release_file(FilePtr file_ptr) { LocalDataBuffer<15> pages(m_databuffer_pool, file_ptr.p->m_pages); LocalDataBuffer<15> columns(m_databuffer_pool, file_ptr.p->m_columns); List::Iterator it; for (pages.first(it); !it.isNull(); pages.next(it)) { if (* it.data == RNIL) continue; m_global_page_pool.release(* it.data); } { Uint64 millis = NdbTick_CurrentMillisecond() - file_ptr.p->m_restore_start_time; if (millis == 0) millis = 1; Uint64 bps = file_ptr.p->m_bytes_restored * 1000 / millis; g_eventLogger->info("LDM instance %u: Restored T%dF%u LCP %llu rows, " "%llu bytes, %llu millis, %llu bytes/s)", instance(), file_ptr.p->m_table_id, file_ptr.p->m_fragment_id, file_ptr.p->m_rows_restored, file_ptr.p->m_bytes_restored, millis, bps); m_rows_restored+= file_ptr.p->m_rows_restored; m_bytes_restored+= file_ptr.p->m_bytes_restored; m_millis_spent+= millis; m_frags_restored++; } columns.release(); pages.release(); m_file_list.release(file_ptr); }
int main (int argc, char const* argv[]) { int sudoku[SUDOKU_SIZE][SUDOKU_SIZE]; read_sudoku_from_file(sudoku); int blanks = count_blanks(sudoku); std::vector<int> possible_numbers; while(blanks) { for(int i = 0; i < SUDOKU_SIZE; ++i) { for(int j = 0; j < SUDOKU_SIZE; ++j) { if(!sudoku[i][j]) { for(int k = 1; k <= 9; ++k) { if(rows(sudoku, i, k) && columns(sudoku, j, k) && square(sudoku, i, j, k)) { possible_numbers.push_back(k); } } if(possible_numbers.size() == 1) { sudoku[i][j] = possible_numbers[0]; --blanks; } else { possible_numbers.clear(); } } } } } print_sudoku(sudoku); return 0; }
void TableView::setColumns(std::initializer_list<ColumnProperties> columnList) { auto numCol = columns(); // save column count since we are changing it if( numCol >= columnList.size() ) { int c = 0; for( auto it = columnList.begin(); it != columnList.end(); ++it,++c ) { setColumn(c,*it); } for( ; c < numCol; ++c ) { deleteColumn(c); } } else { auto it = columnList.begin(); for( int c = 0; c < numCol; ++c, ++it ) { setColumn(c,*it); } for( ; it != columnList.end(); ++it ) { addColumn(*it); } } }
JSONNode *Database::CreateTable(const string &name, const vector<string> &columnNames) { if (this->FindTable(name)) return NULL; JSONNode table; table.set_name(name); JSONNode columns(JSON_ARRAY); columns.set_name("columns"); for (auto i = columnNames.begin(); i != columnNames.end(); i++) columns.push_back(JSONNode("", *i)); table.push_back(columns); JSONNode rows(JSON_ARRAY); rows.set_name("rows"); table.push_back(rows); auto tables = data.find("tables"); tables->push_back(table); //cout << tables->write_formatted() << endl; //cout << data.write_formatted() << endl; auto t = tables->find(name); return t == tables->end() ? NULL : &*t; }
void TilesetImage::store_directions(Glib::ustring filename) { std::ofstream file(Glib::filename_from_utf8(filename).c_str()); if (!file) throw(std::runtime_error("Could not open CSV file.")); std::vector<uint16_t>::const_iterator iter; // shorthand int ncolumns = columns(); // shorthand int i; for(iter=m_directions.begin(), i=0; iter != m_directions.end(); iter++, i++) { file << *iter; if(div(i + 1, ncolumns).rem == 0) // (i + 1) mod ncolumns == 0 file << std::endl; else file << ","; } file.close(); }
Value* NaiveMatrix::reduceSumAlongColumns() const { auto result = new NaiveMatrix(rows(), 1); size_t rowCount = rows(); size_t columnCount = columns(); for(size_t row = 0; row < rowCount; ++row) { float value = 0.0f; for(size_t column = 0; column < columnCount; ++column) { value += data()[getPosition(row, column)]; } result->data()[result->getPosition(row, 0)] = value; } return result; }
logical pc_ADK_FieldControl :: AddColumn (char *propnames, int32 indx0 ) { pc_ADK_Field columns(GPH("columns")); char propname[ID_SIZE]; logical term = NO; BEGINSEQ if ( indx0 >= columns.GetCount() ) indx0 = LAST_INSTANCE; gvtxstb(propname,propnames,ID_SIZE); columns.Add(indx0,propname); CTXCERR columns.Save(); CTXCERR SetActionResult(columns.GPH("sys_ident")->GetString()); RECOVER SetActionResult(""); term = YES; ENDSEQ return(term); }
std::string packFishState(const FishState fishState) { rapidjson::Document document; document.SetObject(); rapidjson::Value columns(rapidjson::kArrayType); for (int column = 0; column < fishState.blindFishStartPos.size(); ++column) { Vec2 startPos = fishState.blindFishStartPos[column]; rapidjson::Value startPosJson(rapidjson::kObjectType); startPosJson.AddMember("x", startPos.x, document.GetAllocator()); startPosJson.AddMember("y", startPos.y, document.GetAllocator()); columns.PushBack(startPosJson, document.GetAllocator()); } document.AddMember("blindFishStartPos", columns, document.GetAllocator()); rapidjson::Value indexes(rapidjson::kArrayType); for (int index = 0; index < fishState.blindFishStartPos.size(); ++index) { Vec2 targetPos = fishState.blindFishTargetPos[index]; rapidjson::Value targetPosJson(rapidjson::kObjectType); targetPosJson.AddMember("x", targetPos.x, document.GetAllocator()); targetPosJson.AddMember("y", targetPos.y, document.GetAllocator()); indexes.PushBack(targetPosJson, document.GetAllocator()); } document.AddMember("blindFishTargetPos", indexes, document.GetAllocator()); document.AddMember("dataType", fishStateDataType, document.GetAllocator()); rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); document.Accept(writer); std::string returnString(buffer.GetString(), buffer.Size()); return returnString; }
LayerModel::LayerModel() { g_assert(!_singleton); _singleton = this; try { pb_visible = Gdk::Pixbuf::create_from_file(apply_filename_macros("$(exe-share)/icons/scalable/visible-layer.svg")); pb_invisible = Gdk::Pixbuf::create_from_file(apply_filename_macros("$(exe-share)/icons/scalable/invisible-layer.svg")); }CATCH_ALL("**LayerModel::LayerModel**", NOTHING_MACRO) gtk_tree_model = Gtk::ListStore::create(columns()); register_base_texture_layer(); register_night_texture_layer(); register_weight_texture_layer(); register_cloud_texture_layer(); register_atmosphere_layer(); register_ring_layer(); for(gsize i=0; i<N_LIGHT_LAYERS; ++i) register_light_layer(i); }