void Hamming_Code::generate_H(void) { int i, j, NextPos; char NotUsed; bvec temp; ivec indexes(n); indexes.zeros(); for (i = 1; i <= n - k; i++) { indexes(i - 1) = pow2i(n - k - i); } NextPos = n - k; for (i = 1; i <= n; i++) { NotUsed = 1; for (j = 0; j < n; j++) if (i == indexes(j)) { NotUsed = 0; } if (NotUsed) { indexes(NextPos) = i; NextPos = NextPos + 1; } } for (i = 0; i < n; i++) { temp = dec2bin(n - k, indexes(i)); //<-CHECK THIS OUT!!!! for (j = 0; j < (n - k); j++) { H(j, i) = temp(j); } } }
void Sym::draw(QPainter* painter, qreal mag, const QPointF& pos, int n) const { #ifdef USE_GLYPHS QVector<quint32> indexes(n); QVector<QPointF> positions(n); QGlyphRun nglyphs; nglyphs.setRawFont(glyphs.rawFont()); positions[0] = QPointF(); for (int i = 0; i < n; ++i) { indexes[i] = glyphs.glyphIndexes()[0]; if (i) positions[i] = QPointF(w * i, 0.0); } nglyphs.setGlyphIndexes(indexes); nglyphs.setPositions(positions); #endif painter->scale(mag, mag); qreal imag = 1.0 / mag; #ifdef USE_GLYPHS painter->drawGlyphRun(pos * imag, nglyphs); #else painter->setFont(font()); painter->drawText(pos * imag, QString(n, _code)); #endif painter->scale(imag, imag); }
void threads::output() { set_cpu(1); /*fill the indexes*/ std::vector<size_t> indexes(blocks.size()); for (size_t i = 0; i < blocks.size(); i++) { indexes[i] = i; } /*initialize stored last-output counts*/ std::vector<size_t> counts(blocks.size(), 0); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmissing-noreturn" while (true) { /*mix around the indexes*/ std::shuffle(indexes.begin(), indexes.end(), primary_rng); for (size_t i = 0; i < blocks.size(); i++) { /*if the block is new*/ if (blocks[indexes[i]].count > counts[indexes[i]]) { /*update the block count*/ counts[indexes[i]] = blocks[indexes[i]].count; output_stream.write((const char *) blocks[indexes[i]].data, blocksize); output_stream.flush(); } } } #pragma clang diagnostic pop }
void Utils::getCommonLinks(PathBasedFlowMove *paths, std::list<StarLink*> &list, int nbLinks){ std::vector<int> indexes(nbLinks); std::vector<int> indexesTmp(nbLinks); std::vector<StarLink*> links(nbLinks); int size = 0; for (int i = 0; i < nbLinks; ++i) { indexes[i] = 0; indexesTmp[i] = 0; links[i] = NULL; } int index = -1; Path *path = NULL; int nbPaths = 0; for (PathAndDirection *pathDir = paths->beginPathDirection(); pathDir != NULL; pathDir = paths->getNextPathDirection()) { path = pathDir->getPath(); ++nbPaths; for(StarLinkIterator it = path->begin(); it != path->end(); ++it){ StarLink* link = *it; index = link->getIndex(); if (indexes[index] == 0) { indexesTmp[size] = index; ++size; links[index] = link; } ++indexes[index]; } } for (int i = 0; i < size; ++i) { index = indexesTmp[i]; if (indexes[index] == nbPaths) { list.push_back(links[index]); } } };
void getAllUnitShifts(const Mat& rgbImg, vector<Mat> &shifts) { vector<int> indexes(9); iota(indexes.begin(), indexes.end(), 0); // (0..8) indexes.erase(indexes.begin() + 4); // (0..3, 5..8) vector<CvPoint> points; transform(indexes.begin(), indexes.end(), back_inserter(points), [](int i) { return cvPoint(i/3, i%3); }); // (0, 0) -> [1,0,0; 0,0,0; 0,0,0] // (0, 1) -> [0,0,0; 1,0,0; 0,0,0] // (0, 2) -> [0,0,0; 0,0,0; 1,0,0] // (1, 0) -> [0,1,0; 0,0,0; 0,0,0] // (1, 1) -> [0,0,0; 0,1,0; 0,0,0] <-- erased (identical shift) // (1, 2) -> [0,0,0; 0,0,0; 0,1,0] // (2, 0) -> [0,0,1; 0,0,0; 0,0,0] // (2, 1) -> [0,0,0; 0,0,1; 0,0,0] // (2, 2) -> [0,0,0; 0,0,0; 0,0,1] transform(points.begin(), points.end(), back_inserter(shifts), [rgbImg] (const CvPoint &delta) { Mat kernel(3, 3, rgbImg.depth(), Scalar().all(0)); kernel.at<float>(1, 1) = 1.0f; Mat shift = Mat(rgbImg.rows, rgbImg.cols, rgbImg.type(), Scalar().all(0)); filter2D(rgbImg, shift, -1 , kernel, delta, 0, BORDER_CONSTANT); return shift; }); }
void paintVerticalSection (QPainter *painter, const QRect& sectionRect, int logicalLeafIndex, const QHeaderView* hv, const QStyleOptionHeader& styleOptions, const QModelIndex& leafIndex) const { QPointF oldBO(painter->brushOrigin()); int left=sectionRect.x(); QModelIndexList indexes(parentIndexes(leafIndex)); for(int i=0; i<indexes.size(); ++i) { QStyleOptionHeader realStyleOptions(styleOptions); if( i<indexes.size()-1 && ( realStyleOptions.state.testFlag(QStyle::State_Sunken) || realStyleOptions.state.testFlag(QStyle::State_On))) { QStyle::State t(QStyle::State_Sunken | QStyle::State_On); realStyleOptions.state&=(~t); } left=paintVerticalCell(painter, hv, indexes[i], leafIndex, logicalLeafIndex, realStyleOptions, sectionRect, left); } painter->setBrushOrigin(oldBO); }
void ExecutionVisitor::onPreVisit(CreateTableStatement& createTable) { // Create attributes vector<ColumnSchema> columns; for(auto& iter : createTable.attributes) columns.push_back(dbi::ColumnSchema{iter.name, iter.type, iter.notNull, 0}); // Create indexes vector<IndexSchema> indexes(createTable.uniqueColumns.size()); for(uint32_t k=0; k<createTable.uniqueColumns.size(); k++) { indexes[k].unique = true; indexes[k].sid = segmentManager.createSegment(SegmentType::BT, 1); indexes[k].type = IndexSchema::Type::kBTree; for(auto& columnName : createTable.uniqueColumns[k]) { for(uint32_t i=0; i<columns.size(); i++) { if(columnName == columns[i].name) { indexes[k].indexedColumns.push_back(i); break; } } } } // Add relation auto schema = util::make_unique<RelationSchema>(createTable.tableName, move(columns), move(indexes)); SegmentId sid = segmentManager.createSegment(SegmentType::SP, kInitialPagesPerRelation); schema->setSegmentId(sid); schema->optimizePadding(); schemaManager.addRelation(move(schema)); result.addCreate(chrono::nanoseconds(-1), createTable.tableName); }
std::string encode_base58(const data_chunk& unencoded) { size_t leading_zeros = count_leading_zeros(unencoded); // size = log(256) / log(58), rounded up. const size_t number_nonzero = unencoded.size() - leading_zeros; const size_t indexes_size = number_nonzero * 138 / 100 + 1; // Allocate enough space in big-endian base58 representation. data_chunk indexes(indexes_size); // Process the bytes. for (auto it = unencoded.begin() + leading_zeros; it != unencoded.end(); ++it) { pack_value(indexes, *it); } // Skip leading zeroes in base58 result. auto first_nonzero = search_first_nonzero(indexes); // Translate the result into a string. std::string encoded; const size_t estimated_size = leading_zeros + (indexes.end() - first_nonzero); encoded.reserve(estimated_size); encoded.assign(leading_zeros, '1'); // Set actual main bytes. for (auto it = first_nonzero; it != indexes.end(); ++it) { const size_t index = *it; encoded += base58_chars[index]; } return encoded; }
void Utils::getDisjointLinks(Path *path1, Path *path2, std::list<StarLink*> &list, int nbLinks){ std::vector<int> indexes(nbLinks); for (int i = 0; i < nbLinks; ++i) { indexes[i] = 0; } for (StarLinkIterator it = path1->begin(); it != path1->end(); ++it) { indexes[(*it)->getIndex()] = 1; } int index = -1; for (StarLinkIterator it = path2->begin(); it != path2->end(); ++it) { StarLink* link = *it; index = link->getIndex(); if (indexes[index] == 0) { list.push_back(link); } else { indexes[index] = -1; } } for (StarLinkIterator it = path1->begin(); it != path1->end(); ++it) { StarLink* link = *it; if (indexes[link->getIndex()] == 1) { list.push_back(link); } } assert(!list.empty()); };
Ints get_triangles(PolygonGeometry *sg) { Ints indexes(sg->get_geometry().size()); for (unsigned int i = 0; i < indexes.size(); ++i) { indexes[i] = i; } return get_triangulation_of_face(indexes, sg->get_geometry()); }
void unProjectMouse() { GLdouble wx, wy, wz; get_world_coordinates(wx, wy, wz, true); printf("World Coordinates: %f %f %f\n", wx, wy, wz); vector< float > world(3); world[0] = wx; world[1] = wy; world[2] = wz; if(cube!=NULL){ vector< int > indexes(3); cube->micrometersToIndexes(world, indexes); /* layerToDrawXY = indexes[2]%512; */ /* layerToDrawXZ = indexes[1]%512; */ /* layerToDrawYZ = indexes[0]%512; */ /* printf("Indexes: %i %i %i\n", indexes[0], indexes[1], indexes[2]); */ on_drawing3D_expose_event(drawing3D,NULL, NULL); } /** If the mode is MOD_ASCEDITOR, change the asc.*/ if(majorMode == MOD_ASCEDITOR){ unProjectMouseAsc(mouse_last_x, mouse_last_y); } if(majorMode == MOD_CONTOUREDITOR){ unProjectMouseContour(mouse_last_x, mouse_last_y, CPT_SOURCE); } }
void DocumentSourceOut::prepTempCollection() { verify(_conn); verify(_tempNs.size() == 0); _tempNs = StringData(str::stream() << _outputNs.db() << ".tmp.agg_out." << aggOutCounter.addAndFetch(1) ); { BSONObj info; bool ok =_conn->runCommand(_outputNs.db().toString(), BSON("create" << _tempNs.coll() << "temp" << true), info); uassert(16994, str::stream() << "failed to create temporary $out collection '" << _tempNs.ns() << "': " << info.toString(), ok); } // copy indexes on _outputNs to _tempNs scoped_ptr<DBClientCursor> indexes(_conn->getIndexes(_outputNs)); while (indexes->more()) { MutableDocument index(Document(indexes->nextSafe())); index.remove("_id"); // indexes shouldn't have _ids but some existing ones do index["ns"] = Value(_tempNs.ns()); BSONObj indexBson = index.freeze().toBson(); _conn->insert(_tempNs.getSystemIndexesCollection(), indexBson); BSONObj err = _conn->getLastErrorDetailed(); uassert(16995, str::stream() << "copying index for $out failed." << " index: " << indexBson << " error: " << err, DBClientWithCommands::getLastErrorString(err).empty()); } }
void GroupedIconView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) { QVector<QModelIndex> indexes(IntersectingItems(rect.translated(horizontalOffset(), verticalOffset()))); QItemSelection selection; foreach (const QModelIndex& index, indexes) { selection << QItemSelectionRange(index); }
void FEMLaplaceAssembler::visit(Brick8 *el) { Epetra_SerialDenseMatrix Kloc(8, 8); int numOfGP = 8; GaussPoint** gP = Brick::getGaussPoints(numOfGP); for (int i = 0; i < numOfGP; i++) { std::vector<Epetra_SerialDenseMatrix> basis = Brick::getGaussBasis(8, gP[i]); Epetra_SerialDenseMatrix J = el->getJacobian(basis[1]); Epetra_SerialDenseMatrix TempJ(J); Epetra_SerialDenseSolver JSolver; JSolver.SetMatrix(TempJ); JSolver.Factor(); double detJ = 1; for (int j = 0; j < TempJ.RowDim(); j++) { detJ *= TempJ(j, j); } detJ = fabs(detJ); JSolver.SetMatrix(J); JSolver.Invert(); Epetra_SerialDenseMatrix B(3, 8); Epetra_SerialDenseMatrix BtS(8, 3); B.Multiply('N', 'T', 1, J, basis[1], 0); BtS.Multiply('T', 'N', 1, B, *(el->getInfo()->getMaterial()->getC()), 0); Kloc.Multiply('N', 'N', detJ * gP[i]->getWeigth(), BtS, B, 1); } Epetra_IntSerialDenseVector indexes(8); for (int i = 0; i < 8; i++) indexes(i) = dofMap[el->getPoint(i)][0]; K->SumIntoGlobalValues(indexes, indexes, Kloc); }
int Seq_Matrix::determinant() { assert(this->matrix_row == this->matrix_col); std::vector<int> indexes(this->matrix_row); std::iota(indexes.begin(), indexes.end(), 0); auto ret = Seq_Matrix::rec_determinant(indexes, indexes); return ret; }
bool ListModelBase::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) { auto * mdata = qobject_cast<const ListModel_MimeData *>(data); if (!mdata) return false; const QModelIndexList & elements = mdata->elements; if (elements.empty()) return true; auto * model = const_cast<QAbstractItemModel *>(elements[0].model()); std::vector<int> indexes(elements.size()); auto first = indexes.data(); auto last = first + indexes.size(); std::transform(elements.begin(), elements.end(), first, std::mem_fn(&QModelIndex::row)); std::sort(first, last); // в нашем случае parent всегда invalid, поскольку мы не TreeModel // если row >= 0 - row указывает что скидывание произошло строго перед элементом с индексом row, для заданного parent'а // если же row == -1 мы: // * или скидываем на элемент и тогда parent его идентифицирует, // в нашем случае невозможно, поскольку мы запретили это методом flags // * или скидываем после последнего элемента bool onto; if (row != -1) onto = false; else { if (parent.isValid()) { onto = true; row = parent.row(); } else { onto = false; row = rowCount(); } } switch (action) { default: return false; case Qt::CopyAction: return onto ? DndCopyOnto(*model, first, last, row) : DndCopyBefore(*model, first, last, row); case Qt::MoveAction: return onto ? DndMoveOnto(*model, first, last, row) : DndMoveBefore(*model, first, last, row); } }
std::string ShortestCommonSuperstring(const std::vector<std::string>& strings) { std::string sequence; std::vector<int> indexes(strings.size()); std::string minimum_length_string = std::accumulate(strings.begin(), strings.end(), std::string{}); ShortestCommonSuperstring(strings, &indexes, &minimum_length_string, &sequence); return minimum_length_string; }
/*! Returns the glyph indexes for this QGlyphRun object. \sa setGlyphIndexes(), setPositions() */ QVector<quint32> QGlyphRun::glyphIndexes() const { if (d->glyphIndexes.constData() == d->glyphIndexData) { return d->glyphIndexes; } else { QVector<quint32> indexes(d->glyphIndexDataSize); qMemCopy(indexes.data(), d->glyphIndexData, d->glyphIndexDataSize * sizeof(quint32)); return indexes; } }
const QList<Item*> ListItems::getSelectedItems() const { QList<Item*> items; QModelIndexList indexes( view->selectionModel()->selectedIndexes()); for( int i = 0; i < indexes.count(); i++) if( qVariantCanConvert<Item*>( indexes[i].data())) items << qVariantValue<Item*>( indexes[i].data()); return items; }
const QList<Item*> ListItems::getSelectedItems() const { QList<Item*> items; QModelIndexList indexes( m_view->selectionModel()->selectedIndexes()); for( int i = 0; i < indexes.count(); i++) if( Item::isItemP( indexes[i].data())) items << Item::toItemP( indexes[i].data()); return items; }
aig_graph aig_cone( const aig_graph& aig, const std::vector<std::string>& names, const properties::ptr& settings, const properties::ptr& statistics ) { std::vector<unsigned> indexes( names.size() ); const auto& info = aig_info( aig ); boost::transform( names, indexes.begin(), [&info]( const std::string& name ) { return aig_output_index( info, name ); } ); return aig_cone( aig, indexes, settings, statistics ); }
int nthSuperUglyNumber(int n, vector<int>& primes) { // track all the prime index vector<int> indexes(primes.size(),0); vector<int> ugly(n,INT_MAX); ugly[0] = 1; for(int i=1; i<n; i++){ for(int j=0; j<primes.size(); j++) ugly[i] = min(ugly[i], ugly[indexes[j]]*primes[j]); for(int j=0; j<primes.size(); j++) indexes[j] += (ugly[i]%primes[j] == 0); } return ugly[n-1]; }
const std::vector<int> ListItems::getSelectedIds() const { std::vector<int> ids; QModelIndexList indexes(m_view->selectionModel()->selectedIndexes()); for (int i = 0; i < indexes.count(); i++) if (Item::isItemP(indexes[i].data())) { Item * item = Item::toItemP(indexes[i].data()); if (false == item->isHidden()) ids.push_back(item->getId()); } return ids; }
FPType DAGraphBWithStep::calcFlowStep(Path* minPath, Path* maxPath) const{ int nbLinks = net_->getNbLinks(); std::vector<FPType> x(nbLinks); std::vector<FPType> y(nbLinks); std::vector<int> indexes(nbLinks); for(StarLinkIterator it = maxPath->begin(); it != maxPath->end(); ++it){ y[(*it)->getIndex()] = 0.0; } for (StarLinkIterator it = minPath->begin(); it != minPath->end(); ++it) { y[(*it)->getIndex()] = 0.0; } int linkIndex = -1; int size = 0; // projecting path direction onto links FPType descDirection = minPath->getCurrCost() - maxPath->getCurrCost(); FPType oFlow = 0.0; FPType maxPathFlow = std::numeric_limits<FPType>::infinity( ); for(StarLinkIterator it = maxPath->begin(); it != maxPath->end(); ++it){ StarLink* link = *it; linkIndex = link->getIndex(); x[linkIndex] = link->getFlow(); y[linkIndex] += descDirection; indexes[size] = linkIndex; ++size; oFlow = getOriginFlow(linkIndex); if (oFlow < maxPathFlow) maxPathFlow = oFlow; } if (maxPathFlow == 0.0) { return 0.0; } for (StarLinkIterator it = minPath->begin(); it != minPath->end(); ++it) { StarLink* link = *it; linkIndex = link->getIndex(); x[linkIndex] = link->getFlow(); y[linkIndex] -= descDirection; indexes[size] = linkIndex; ++size; } (lineSearch_->getDerivative())->setDataPointers(size, x, y, indexes); // calculating upper bound for line search FPType ub = -maxPathFlow / descDirection; assert(ub > 0.0); return (lineSearch_->execute(0.0, ub) * -descDirection); };
/** \brief Draws the */ void cwTile::draw() { TriangleIndexBuffer.bind(); TriangleVertexBuffer.bind(); Program->setAttributeBuffer(vVertex, GL_FLOAT, 0, 2); Program->enableAttributeArray(vVertex); glDrawElements(GL_TRIANGLES, indexes().size(), GL_UNSIGNED_INT, NULL); TriangleVertexBuffer.release(); TriangleIndexBuffer.release(); }
int nthSuperUglyNumber(int n, vector<int>& primes) { vector<int> indexes(primes.size(), 0); vector<int> ugly{ 1 }; while (ugly.size() < n) { int index = 0; int next = min(primes, indexes, ugly, index); indexes[index]++; if(next != ugly.back()) ugly.push_back(next); } return ugly[n - 1]; }
void ListItems::action( af::MCGeneral& mcgeneral, int type) { QModelIndexList indexes( view->selectionModel()->selectedIndexes()); for( int i = 0; i < indexes.count(); i++) if( qVariantCanConvert<Item*>( indexes[i].data())) mcgeneral.addId( qVariantValue<Item*>( indexes[i].data())->getId()); if( mcgeneral.getCount() == 0) return; //printf("ListNodes::action:\n"); mcgeneral.stdOut( true); af::Msg * msg = new af::Msg( type, &mcgeneral); Watch::sendMsg( msg); }
void InputMatrix::sortMatrix() { std::vector<int> counts(_r2Count); for(auto i=0; i<_rowsCount; ++i) { counts[_r2Matrix[i]] += 1; } std::vector<std::tuple<int, int>> sortedCounts(_r2Count); for(auto i=0; i<_r2Count; ++i) { sortedCounts[i] = std::make_tuple(i, counts[i]); } std::sort(sortedCounts.begin(), sortedCounts.end(), [](std::tuple<int, int> a, std::tuple<int, int> b){ return std::get<1>(a) > std::get<1>(b); }); std::vector<int> indexes(_r2Count); int currentIndex = 0; for(auto i=0; i<_r2Count; ++i) { indexes[std::get<0>(sortedCounts[i])] = currentIndex; currentIndex += std::get<1>(sortedCounts[i]); } std::vector<int> newIndexes(_rowsCount); for(auto i=0; i<_rowsCount; ++i) { newIndexes[i] = indexes[_r2Matrix[i]]; indexes[_r2Matrix[i]] += 1; } auto oldQMatrix = _qMatrix; auto oldRMatrix = _rMatrix; auto oldR2Matrix = _r2Matrix; _qMatrix = new int[_rowsCount * _qColsCount]; _rMatrix = new int[_rowsCount * _rColsCount]; _r2Matrix = new int[_rowsCount]; for(auto i=0; i<_rowsCount; ++i) { for(auto j=0; j<_qColsCount; ++j) { _qMatrix[newIndexes[i]*_qColsCount + j] = oldQMatrix[i*_qColsCount + j]; } for(auto j=0; j<_rColsCount; ++j) { _rMatrix[newIndexes[i]*_rColsCount + j] = oldRMatrix[i*_rColsCount + j]; } _r2Matrix[newIndexes[i]] = oldR2Matrix[i]; } delete[] oldQMatrix; delete[] oldRMatrix; delete[] oldR2Matrix; }
void FEMLaplaceAssembler::visit(Triangle3 *t) { //cout << force->getValue(t->getCenter()) << endl; Epetra_SerialDenseMatrix R(2, 2); R(0, 0) = t->getPoint(0)->getCoord(0) - t->getPoint(1)->getCoord(0); R(1, 0) = t->getPoint(0)->getCoord(1) - t->getPoint(1)->getCoord(1); R(0, 1) = t->getPoint(2)->getCoord(0) - t->getPoint(0)->getCoord(0); R(1, 1) = t->getPoint(2)->getCoord(1) - t->getPoint(0)->getCoord(1); double detR = R(0, 0) * R(1, 1) - R(1, 0) * R(0, 1); Epetra_SerialDenseSolver RSolv; RSolv.SetMatrix(R); RSolv.Invert(); Epetra_SerialDenseMatrix maper(2, 3); maper(0, 0) = -1; maper(0, 1) = 1; maper(1, 0) = -1; maper(1, 2) = 1; Epetra_SerialDenseMatrix B(2, 3); B.Multiply('T', 'N', 1, R, maper, 0); Epetra_SerialDenseMatrix Kloc(3, 3); Kloc.Multiply('T', 'N', fabs(detR) / 2, B, B, 0); Epetra_IntSerialDenseVector indexes(3); for (int i = 0; i < 3; i++) indexes(i) = dofMap[t->getPoint(i)][0]; K->SumIntoGlobalValues(indexes, indexes, Kloc); }
//____________________________________________________________ QModelIndexList ItemModel::indexes( int column, const QModelIndex& parent ) const { QModelIndexList out; int rows( rowCount( parent ) ); for( int row = 0; row < rows; row++ ) { QModelIndex index( this->index( row, column, parent ) ); if( !index.isValid() ) continue; out.append( index ); out += indexes( column, index ); } return out; }