void Palette::mouseMoveEvent(QMouseEvent* ev) { if ((currentIdx != -1) && (dragIdx == currentIdx) && (ev->buttons() & Qt::LeftButton) && (ev->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance()) { PaletteCell* cell = cells[currentIdx]; if (cell && cell->element) { QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData; Element* el = cell->element; qreal mag = PALETTE_SPATIUM * extraMag / gscore->spatium(); QPointF spos = QPointF(dragStartPosition) / mag; spos -= QPointF(cells[currentIdx]->x, cells[currentIdx]->y); // DEBUG: spos.setX(0.0); mimeData->setData(mimeSymbolFormat, el->mimeData(spos)); drag->setMimeData(mimeData); dragSrcIdx = currentIdx; emit startDragElement(el); if (_readOnly) { drag->start(Qt::CopyAction); } else { /*Qt::DropAction action = */ drag->start(Qt::DropActions(Qt::CopyAction | Qt::MoveAction)); } } } else { QRect r; if (currentIdx != -1) r = idxRect(currentIdx); currentIdx = idx(ev->pos()); if (currentIdx != -1) { if (cells[currentIdx] == 0) currentIdx = -1; else r |= idxRect(currentIdx); } update(r); } }
MatHandler CreateMat(int cols, int rows, TYPE *nums){ matrix_t *m = (matrix_t *)calloc(1, sizeof(matrix_t)); if (m){ assert(cols > 0 && rows > 0); m->cols = cols; m->rows = rows; m->data = (TYPE *)calloc(cols*rows, sizeof(TYPE)); if (m->data){ if (nums){ for (int i = 0; i < cols; ++i){ for (int j = 0; j < rows; ++j){ m->data[idx(i, cols, j)] = *(nums + j*cols + i); } } } return (MatHandler *)m; } } return NULL; }
int IndexedTriangleIO::insertFlattenedVertexVTN(const int v, const int t, const int n) { Vec3i idx(v,t,n); std::map<Vec3i,size_t>::iterator it = mIndicesCache.find(idx); //vertex does not exist if(it==mIndicesCache.end()) { it = (mIndicesCache.insert(std::make_pair(idx,mVertexPosition.size()))).first; mVertexPosition.push_back(mVertexPositionCache[v-1]); // copy / duplicate texcoords and normals if appropriate if(t >= 0) mVertexTextureCoordinate.push_back(mVertexTextureCoordinateCache[t-1]); if(n >= 0) mVertexNormal.push_back(mVertexNormalCache[n-1]); } return int(it->second); }
STD1::uint32_t Document::writeNameMap( std::FILE* out ) { STD1::uint32_t offset( 0 ); if( !isInf() && !nameMap.empty() ) { offset = std::ftell( out ); ConstNameMapIter itr; for( itr = nameMap.begin(); itr != nameMap.end(); ++itr ) { STD1::uint16_t index( itr->first->index() ); if( std::fwrite( &index, sizeof( STD1::uint16_t ), 1, out ) != 1 ) throw FatalError( ERR_WRITE ); } for( itr = nameMap.begin(); itr != nameMap.end(); ++itr ) { STD1::uint16_t idx( itr->second.index() ); if( std::fwrite( &idx, sizeof( STD1::uint16_t ), 1, out ) != 1 ) throw FatalError( ERR_WRITE ); } } return offset; }
static int pyGeometrySpan_setIndices(pyGeometrySpan* self, PyObject* value, void*) { if (value == NULL || !PySequence_Check(value)) { PyErr_SetString(PyExc_TypeError, "indices should be a sequence of unsigned shorts"); return -1; } size_t count = PySequence_Size(value); for (size_t i = 0; i < count; ++i) { if (!PyInt_Check(PySequence_Fast_GET_ITEM(value, i))) { PyErr_SetString(PyExc_TypeError, "indices should be a sequence of unsigned shorts"); return -1; } } std::vector<unsigned short> idx(PySequence_Size(value)); for (size_t i = 0; i < idx.size(); ++i) idx[i] = PyInt_AsLong(PySequence_Fast_GET_ITEM(value, i)); self->fThis->setIndices(idx); return 0; }
void update_map_pos() { // z (blender x) 100m // x (blender y) 100m float ratio = (float) screen_map_len / 100; float half = screen_map_len / 2; map_pos_u = mypos.x * ratio + half; map_pos_v =-mypos.z * ratio + half; float mu = (float) map_len_u / screen_map_len; float mv = (float) map_len_v / screen_map_len; iu = map_pos_u * mu; iv = map_pos_v * mv; altura_terreno = idx(); }
SparseMatrix* MainWindow::buildModel(const QImage &img) { SparseMatrix *ret = new SparseMatrix(5,this); //Dims: 0=north 1=south 2=east 3=west 4=pos for(int row = 0; row<img.height(); row++) { for(int col = 0; col<img.width(); col++) { Vector_t idx(5); idx[0] = (row == 0) ? 5 : QColor(img.pixel(col,row-1)).lightness()&0xFF; idx[1] = (row+1 == img.height()) ? 5 : QColor(img.pixel(col,row+1)).lightness()&0xFF; idx[2] = (col == 0) ? 5 : QColor(img.pixel(col-1,row)).lightness()&0xFF; idx[3] = (col+1 == img.width()) ? 5 : QColor(img.pixel(col+1,row)).lightness()&0xFF; idx[4] = QColor(img.pixel(col,row)).lightness()&0xFF; if(!idx.contains(5)) //ignore edge pixels ret->inc(idx); } } return ret; }
int CreateMinorMat(MatHandler mat, int icol, int jrow, MatHandler *ans){ /* Создает минор только n-1-ого порядка*/ matrix_t *a, *m = (matrix_t *)mat; assert(m->cols > 1 && m->rows > 1); a = (matrix_t *)(*ans) = (matrix_t *)CreateMat(m->cols - 1, m->rows - 1, NULL); if (!a) return M_ERR_ALLOC; a->cols = m->cols - 1; a->rows = m->rows - 1; int id = 0; for (int i = 0; i < m->cols; ++i){ if (i == icol) continue; for (int j = 0; j < m->rows; ++j){ if (j == jrow) continue; int r = idx(i, m->cols, j); a->data[id] = m->data[r]; ++id; } } return M_OK; }
int main(int narg, char* arg[]) { Kokkos::initialize (narg, arg); int size = 1000000; idx_type idx("Idx",size,64); idx_type_host h_idx = Kokkos::create_mirror_view (idx); view_type dest ("Dest", size); view_type src ("Src", size); srand(134231); for (int i = 0; i < size; i++) { for (view_type::size_type j = 0; j < h_idx.dimension_1 (); ++j) { h_idx(i,j) = (size + i + (rand () % 500 - 250)) % size; } } // Deep copy the initial data to the device Kokkos::deep_copy(idx,h_idx); // Run the first kernel to warmup caches Kokkos::parallel_for(size,localsum<view_type,view_type_rnd>(idx,dest,src)); Kokkos::fence(); // Run the localsum functor using the RandomAccess trait. On CPUs there should // not be any different in performance to not using the RandomAccess trait. // On GPUs where can be a dramatic difference Kokkos::Impl::Timer time1; Kokkos::parallel_for(size,localsum<view_type,view_type_rnd>(idx,dest,src)); Kokkos::fence(); double sec1 = time1.seconds(); Kokkos::Impl::Timer time2; Kokkos::parallel_for(size,localsum<view_type,view_type>(idx,dest,src)); Kokkos::fence(); double sec2 = time2.seconds(); printf("Time with Trait RandomAccess: %f with Plain: %f \n",sec1,sec2); Kokkos::finalize(); }
local_mirror_t<Object>::local_mirror_t(fh_map_t *map_, Object b, boost::uint32_t v, const std::string &migr_svc) : version(v), snapshot_marker(v), blob(b), fh_map(map_), blob_size(b->get_size(v)), page_size(b->get_page_size()), chunk_map(blob_size / page_size, CHUNK_UNTOUCHED), written_map(blob_size / page_size, false), async_io_thread(boost::bind(&local_mirror_t<Object>::async_io_exec, this)), migration_thread(boost::bind(&migration_wrapper::migr_exec, blob.get(), (migration_wrapper::updater_t) boost::bind(&local_mirror_t<Object>::schedule_chunk, this, _1), (migration_wrapper::updater_t) boost::bind(&local_mirror_t<Object>::cancel_chunk, this, _1), boost::cref(migr_svc))), migr_flag(false) { std::stringstream ss; ss << "/tmp/blob-mirror-" << b->get_id() << "-" << version; local_name = ss.str(); if ((fd = open(local_name.c_str(), O_RDWR | O_CREAT | O_NOATIME, 0666)) == -1) throw std::runtime_error("could not open temporary file: " + local_name); flock lock; lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = blob_size; if (fcntl(fd, F_SETLK, &lock) == -1) { close(fd); throw std::runtime_error("could not lock temporary file: " + local_name); } if (lseek(fd, 0, SEEK_END) != (off_t)blob_size) { lseek(fd, blob_size - 1, SEEK_SET); if (::write(fd, &blob_size, 1) != 1) { close(fd); throw std::runtime_error("could not adjust temporary file: " + local_name); } } std::ifstream idx((local_name + ".idx").c_str(), std::ios_base::in | std::ios_base::binary); if (idx.good()) { boost::archive::binary_iarchive ar(idx); ar >> chunk_map >> written_map; }
unsigned int Histogram::markCellsOfQuantilesColumn(unsigned int c, CELLMARKER& cm) const { double bi = m_interv[c]; double bs = m_interv[c+1]; unsigned int nb=m_dataIdx.size(); unsigned int i=0; while ((i<nb) && (data(i)< bi)) ++i; unsigned int nbc=0; while ((i<nb) && (data(i)< bs)) { cm.mark(idx(i++)); ++nbc; } return nbc; }
static bool chunk_visitor( const RBTree_Node *node, RBTree_Direction dir, void *visitor_arg ) { rtems_rbheap_chunk *chunk = rtems_rbheap_chunk_of_node(node); chunk_visitor_context *context = visitor_arg; rtems_test_assert(context->index_current != context->index_end); rtems_test_assert(context->free_current != context->free_end); rtems_test_assert(idx(chunk) == *context->index_current); rtems_test_assert(rtems_rbheap_is_chunk_free(chunk) == *context->free_current); ++context->index_current; ++context->free_current; return false; }
vector<int> sort_indexes(const vector<double> &v) { // initialize original index locations vector<int> idx(v.size()); for (int i = 0; i != idx.size(); ++i) idx[i] = i; // sort indexes based on comparing values in v //I can't use std::sort because c++ is super gay int temp; for(int j=idx.size();j>0;j--){ for(int i=0;i<j-1;i++){ if(v[idx[i]]>v[idx[i+1]]){ temp=idx[i]; idx[i]=idx[i+1]; idx[i+1]=temp; } } } return idx; }
Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path) : dat(io::Open(dat_path)) { std::unique_ptr<std::ifstream> idx(io::Open(idx_path)); std::string encoding_name; getline(*idx, encoding_name); std::string unused_entry_count; getline(*idx, unused_entry_count); // Read the list of words and file offsets for those words for (line_iterator<std::string> iter(*idx, encoding_name), end; iter != end; ++iter) { std::vector<std::string> chunks; boost::split(chunks, *iter, _1 == '|'); if (chunks.size() == 2) offsets[chunks[0]] = atoi(chunks[1].c_str()); } conv.reset(new charset::IconvWrapper(encoding_name.c_str(), "utf-8")); }
Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path) : dat(make_unique<read_file_mapping>(dat_path)) { read_file_mapping idx_file(idx_path); boost::interprocess::ibufferstream idx(idx_file.read(), static_cast<size_t>(idx_file.size())); std::string encoding_name; getline(idx, encoding_name); std::string unused_entry_count; getline(idx, unused_entry_count); conv = make_unique<charset::IconvWrapper>(encoding_name.c_str(), "utf-8"); // Read the list of words and file offsets for those words for (auto const& line : line_iterator<std::string>(idx, encoding_name)) { auto pos = line.find('|'); if (pos != line.npos && line.find('|', pos + 1) == line.npos) offsets[line.substr(0, pos)] = static_cast<size_t>(atoi(line.c_str() + pos + 1)); } }
double pcac_correlation_function(int t) { complex double C = 0; for (int x = 0; x < X1; x ++) { int index = idx(x, t, X1); complex double a = R1[index].s1; complex double b = R1[index].s2; complex double c = R2[index].s1; complex double d = R2[index].s2; //C += I * (a * cconj(c) - c * cconj(a) + b * cconj(d) - d * cconj(b)); C += -cimag(a * cconj(c)) - cimag(b * cconj(d)); //C += -cimag(c); //C += -cimag(a * cconj(b)) - cimag(c * cconj(d)); } C *= 2; if (fabs(cimag(C)) > 1e-6) printf("\nImaginary part of PCAC correlation function detected!\n"); return fabs(C); }
void sev_valuecache_double::write( int index) { int ii = idx(index); double wval, wtime; if ( m_type == sev_eCvType_Mean) { if ( fabs(m_last_k) < 1) { m_wval.val = m_wval.val + m_last_k * (m_val[ii].time - m_wval.time); m_wval.time = m_val[ii].time; } else { m_wval.time = m_wval.time + (m_val[ii].val - m_wval.val) / m_last_k; m_wval.val = m_val[ii].val; } wval = m_wval.val; wtime = m_wval.time; } else { wval = m_val[ii].val; wtime = m_val[ii].time; m_wval = m_val[ii]; } if ( index == 0) { m_last = m_first = 0; m_length = 0; } else { m_first = ii + 1; if ( m_first >= m_size) m_first -= m_size; m_length = m_last - m_first + 1; if ( m_length < 0) m_length += m_size; } if ( m_write_cb) { pwr_tTime time; time_Aadd( &time, &m_start_time, time_Float64ToD( 0, wtime)); (m_write_cb)( m_userdata, m_useridx, &wval, &time); } }
void getAllData(Container& vals, int rank) const { assert(this->rank == rank); for (int i = 0;i < ndim;i++) { if (len[i] == 0) { vals.clear(); return; } } std::vector<tkv_pair<T> > pairs; std::vector<int> idx(ndim, 0); first_packed_indices(ndim, len.data(), sym.data(), idx.data()); do { int64_t key = 0, stride = 1; for (int i = 0;i < ndim;i++) { key += idx[i]*stride; stride *= len[i]; } pairs.push_back(tkv_pair<T>(key, (T)0)); } while (next_packed_indices(ndim, len.data(), sym.data(), idx.data())); dt->read(pairs.size(), pairs.data()); sort(pairs.begin(), pairs.end()); size_t npair = pairs.size(); vals.resize(npair); for (size_t i = 0;i < npair;i++) { vals[i] = pairs[i].d; } }
TYPED_TEST(EvaluationDomainTest, FFT) { const size_t m = 4; std::vector<TypeParam> f = { 2, 5, 3, 8 }; std::shared_ptr<evaluation_domain<TypeParam> > domain; for (int key = 0; key < 5; key++) { try { if (key == 0) domain.reset(new basic_radix2_domain<TypeParam>(m)); else if (key == 1) domain.reset(new extended_radix2_domain<TypeParam>(m)); else if (key == 2) domain.reset(new step_radix2_domain<TypeParam>(m)); else if (key == 3) domain.reset(new geometric_sequence_domain<TypeParam>(m)); else if (key == 4) domain.reset(new arithmetic_sequence_domain<TypeParam>(m)); std::vector<TypeParam> a(f); domain->FFT(a); std::vector<TypeParam> idx(m); for (size_t i = 0; i < m; i++) { idx[i] = domain->get_domain_element(i); } for (size_t i = 0; i < m; i++) { TypeParam e = evaluate_polynomial(m, f, idx[i]); EXPECT_TRUE(e == a[i]); } } catch(DomainSizeException &e) { printf("%s - skipping\n", e.what()); } catch(InvalidSizeException &e) { printf("%s - skipping\n", e.what()); } } }
void check( const BSONObj &spec ) { _c.ensureIndex( ns(), idx() ); Client::Context ctx( ns() ); FieldRangeSet frs( ns(), spec ); boost::shared_ptr< FieldRangeVector > frv( new FieldRangeVector( frs, idx(), direction() ) ); BtreeCursor c( nsdetails( ns() ), 1, nsdetails( ns() )->idx( 1 ), frv, direction() ); Matcher m( spec ); int count = 0; while( c.ok() ) { ASSERT( m.matches( c.current() ) ); c.advance(); ++count; } int expectedCount = 0; for( vector< BSONObj >::const_iterator i = _objs.begin(); i != _objs.end(); ++i ) { if ( m.matches( *i ) ) { ++expectedCount; } } ASSERT_EQUALS( expectedCount, count ); }
void AccountListWidget::updateEntries( const QModelIndex& topLeft, const QModelIndex& bottomRight ) { for( int row = topLeft.row(); row <= bottomRight.row(); ++row ) { QPersistentModelIndex idx( m_model->index( row, 0 ) ); int newCount = idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) .value< QList< Tomahawk::Accounts::Account* > >().count(); if( m_entries.value( idx ).count() == newCount ) { updateEntry( idx ); } else { removeEntries( idx.parent(), idx.row(), idx.row() ); insertEntries( idx.parent(), idx.row(), idx.row() ); } } }
void QgsMapToolAddCircularString::createCenterPointRubberBand() { if ( !mShowCenterPointRubberBand || mPoints.size() < 2 || mPoints.size() % 2 != 0 ) { return; } mCenterPointRubberBand = createGeometryRubberBand( Qgis::Polygon ); mCenterPointRubberBand->show(); if ( mTempRubberBand ) { const QgsAbstractGeometryV2* rubberBandGeom = mTempRubberBand->geometry(); if ( rubberBandGeom ) { QgsVertexId idx( 0, 0, 2 ); QgsPointV2 pt = rubberBandGeom->vertexAt( idx ); updateCenterPointRubberBand( pt ); } } }
static PyObject* py_glGetActiveAttrib(PyObject *, PyObject *args) { CHECK_ARG_COUNT(args, 2); Uint prg(PyTuple_GetItem(args, 0)); Uint idx(PyTuple_GetItem(args, 1)); GLint len = 0; glGetProgramiv(prg, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len); //GLchar *name = new GLchar[len+1]; Array1D<Char> name(len+1); GLint size; GLenum type; glGetActiveAttrib(prg, idx, len, NULL, &size, &type, name); //lua_pushinteger(L, size); //lua_pushinteger(L, type); //lua_pushstring(L, name); PyObject *rv = PyTuple_New(3); PyTuple_SetItem(rv, 0, PyInt_FromLong(size)); PyTuple_SetItem(rv, 1, PyInt_FromLong(type)); PyTuple_SetItem(rv, 2, PyString_FromString(name)); //delete[] name; return rv; }
static array helper(const array &n, intptr_t i) { // Get the nd::array 'self' parameter intptr_t undim = n.get_ndim(); ndt::type udt = n.get_dtype(); if (udt.get_kind() == expr_kind) { std::string field_name = udt.value_type().extended<ndt::struct_type>()->get_field_name(i); return n.replace_dtype(ndt::make_type<ndt::adapt_type>( udt.value_type().extended<ndt::struct_type>()->get_field_type(i), udt, nd::callable(), nd::callable())); } else { if (undim == 0) { return n(i); } else { shortvector<irange> idx(undim + 1); idx[undim] = irange(i); return n.at_array(undim + 1, idx.get()); } } }
void CPoints::Render() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glColor4f(1.0, 1.0,1.0, 1.0); CVector v1; CVector v2; CVector v3; int len = sqrt(points.size()); glColor4f(1.0, 1,1, 1.0); for(int i=0;i<len-1;i++) { for(int j=0;j<len-1;j++) { glBegin(GL_TRIANGLES); v1 = points[idx(i,j,len)].pos; v2 = points[idx(i+1,j,len)].pos; v3 = points[idx(i,j+1,len)].pos; glColor4f(0.2+v1.z, 0,0, 1.0); glVertex3f(v1.x,v1.y,v1.z); glVertex3f(v2.x,v2.y,v2.z); glVertex3f(v3.x,v3.y,v3.z); glEnd(); glBegin(GL_TRIANGLES); v1 = points[idx(i+1,j+1,len)].pos; v2 = points[idx(i+1,j,len)].pos; v3 = points[idx(i,j+1,len)].pos; glVertex3f(v1.x,v1.y,v1.z); glVertex3f(v2.x,v2.y,v2.z); glVertex3f(v3.x,v3.y,v3.z); glEnd(); } } // glEnd(); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); }
bool GEOObjects::appendSurfaceVec(const std::vector<Surface*> &surfaces, const std::string &name) { // search vector std::size_t idx (0); bool nfound (true); for (idx = 0; idx < _sfc_vecs.size() && nfound; idx++) if ( (_sfc_vecs[idx]->getName()).compare (name) == 0 ) nfound = false; if (!nfound) { idx--; std::size_t n_sfcs (surfaces.size()); // append surfaces for (std::size_t k(0); k < n_sfcs; k++) _sfc_vecs[idx]->push_back (surfaces[k]); return true; } else return false; }
bool GEOObjects::appendPolylineVec(const std::vector<Polyline*> &polylines, const std::string &name) { // search vector std::size_t idx (0); bool nfound (true); for (idx = 0; idx < _ply_vecs.size() && nfound; idx++) if ( (_ply_vecs[idx]->getName()).compare (name) == 0 ) nfound = false; if (!nfound) { idx--; std::size_t n_plys (polylines.size()); // append lines for (std::size_t k(0); k < n_plys; k++) _ply_vecs[idx]->push_back (polylines[k]); return true; } else return false; }
void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer ) { if ( layer->layerType() != "SvgMarker" ) return; // layer type is correct, we can do the cast mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>( layer ); // set values QAbstractItemModel* m = viewImages->model(); QItemSelectionModel* selModel = viewImages->selectionModel(); for ( int i = 0; i < m->rowCount(); i++ ) { QModelIndex idx( m->index( i, 0 ) ); if ( m->data( idx ).toString() == mLayer->path() ) { selModel->select( idx, QItemSelectionModel::SelectCurrent ); selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent ); setName( idx ); break; } } spinSize->setValue( mLayer->size() ); spinAngle->setValue( mLayer->angle() ); // without blocking signals the value gets changed because of slot setOffset() spinOffsetX->blockSignals( true ); spinOffsetX->setValue( mLayer->offset().x() ); spinOffsetX->blockSignals( false ); spinOffsetY->blockSignals( true ); spinOffsetY->setValue( mLayer->offset().y() ); spinOffsetY->blockSignals( false ); setGuiForSvg( mLayer ); }
int query(char *s) { int n, now = 0, ans = 0; n = strlen(s); for (int i = 0; i < n; i++) { int id = idx(s[i]); while (now && !ch[now][id]) { now = fail[now]; } now = ch[now][id]; int t = now; while (t && val[t] != -1) { ans += val[t]; val[t] = -1; t = fail[t]; } } return ans; }
int nthSuperUglyNumber(int n, vector<int>& primes) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> heap; vector<int> uglies(n), idx(primes.size()); uglies[0] = 1; for (int k = 0; k < primes.size(); ++k) { heap.emplace(primes[k], k); } for (int i = 1; i < n; ++i) { int k; tie(uglies[i], k) = heap.top(); while (heap.top().first == uglies[i]) { // worst time: O(klogk) tie(uglies[i], k) = heap.top(); heap.pop(); heap.emplace(primes[k] * uglies[++idx[k]], k); } } return uglies[n - 1]; }