本文整理汇总了C++中x函数的典型用法代码示例。如果您正苦于以下问题:C++ x函数的具体用法?C++ x怎么用?C++ x使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了x函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: x
bool IntRect::intersects(const IntRect& other) const {
// Checking emptiness handles negative widths as well as zero.
return !isEmpty() && !other.isEmpty() && x() < other.maxX() &&
other.x() < maxX() && y() < other.maxY() && other.y() < maxY();
}
示例2: PositionMetaData
void ProcessorGraphicsItem::saveMeta() {
PositionMetaData* meta = new PositionMetaData(static_cast<int>(x()), static_cast<int>(y()));
processor_->getMetaDataContainer().addMetaData("ProcessorGraphicsItem", meta);
}
示例3: MPI_Comm_rank
void sLinsysRootAug::solveWithBiCGStab( sData *prob, SimpleVector& b)
{
int n = b.length();
const int maxit=500;
const double tol=1e-12, EPS=2e-16;
double iter=0.0;
int myRank; MPI_Comm_rank(mpiComm, &myRank);
SimpleVector r(n); //residual
SimpleVector s(n); //residual associated with half iterate
SimpleVector rt(n); //shadow residual
SimpleVector xmin(n); //minimal residual iterate
SimpleVector x(n); //iterate
SimpleVector xhalf(n); // half iterate of BiCG
SimpleVector p(n),paux(n);
SimpleVector v(n), t(n);
int flag; double imin;
double n2b; //norm of b
double normr, normrmin; //norm of the residual and norm of residual at min-resid iterate
double normr_act;
double tolb; //relative tolerance
double rho, omega, alpha;
int stag, maxmsteps, maxstagsteps, moresteps;
double relres;
//maxit = n/2+1;
//////////////////////////////////////////////////////////////////
// Problem Setup and intialization
//////////////////////////////////////////////////////////////////
n2b = b.twonorm();
tolb = n2b*tol;
#ifdef TIMING
taux = MPI_Wtime();
#endif
//initial guess
x.copyFrom(b);
solver->Dsolve(x);
//initial residual
r.copyFrom(b);
#ifdef TIMING
troot_total += (MPI_Wtime()-taux);
taux = MPI_Wtime();
#endif
//applyA(1.0, r, -1.0, x);
SCmult(1.0,r, -1.0,x, prob);
#ifdef TIMING
tchild_total += (MPI_Wtime()-taux);
#endif
normr=r.twonorm();
#ifdef TIMING
if(myRank==0)
cout << "BiCG: initial rel resid: " << normr/n2b << endl;
#endif
if(normr<tolb) {
//initial guess is good enough
b.copyFrom(x); flag=0; return;
}
rt.copyFrom(r); //Shadow residual
double* resvec = new double[2*maxit+1];
resvec[0] = normr; normrmin=normr;
rho=1.0; omega=1.0;
stag=0; maxmsteps=min(min(n/50, 5), n-maxit);
maxstagsteps=3; moresteps=0;
//////////////////////////////////////////////////////////////////
// loop over maxit iterations
//////////////////////////////////////////////////////////////////
int ii=0; while(ii<maxit) {
//cout << ii << " ";
flag=-1;
///////////////////////////////
// First half of the iterate
///////////////////////////////
double rho1=rho; double beta;
rho = rt.dotProductWith(r);
//printf("rho=%g\n", rho);
if(0.0==rho) { flag=4; break; }
if(ii==0) p.copyFrom(r);
else {
beta = (rho/rho1)*(alpha/omega);
if(beta==0.0) { flag=4; break; }
//-------- p = r + beta*(p - omega*v) --------
p.axpy(-omega, v); p.scale(beta); p.axpy(1.0, r);
}
#ifdef TIMING
//.........这里部分代码省略.........
示例4: Quaternion
Quaternion Quaternion::operator*(const float c) const {
return Quaternion(x() * c, y() * c, z() * c, w() * c);
}
示例5: x
HeapWord* GenCollectorPolicy::satisfy_failed_allocation(size_t size,
bool is_tlab) {
GenCollectedHeap *gch = GenCollectedHeap::heap();
GCCauseSetter x(gch, GCCause::_allocation_failure);
HeapWord* result = NULL;
assert(size != 0, "Precondition violated");
if (GC_locker::is_active_and_needs_gc()) {
// GC locker is active; instead of a collection we will attempt
// to expand the heap, if there's room for expansion.
if (!gch->is_maximal_no_gc()) {
result = expand_heap_and_allocate(size, is_tlab);
}
return result; // could be null if we are out of space
} else if (!gch->incremental_collection_will_fail()) {
// The gc_prologues have not executed yet. The value
// for incremental_collection_will_fail() is the remanent
// of the last collection.
// Do an incremental collection.
gch->do_collection(false /* full */,
false /* clear_all_soft_refs */,
size /* size */,
is_tlab /* is_tlab */,
number_of_generations() - 1 /* max_level */);
} else {
// Try a full collection; see delta for bug id 6266275
// for the original code and why this has been simplified
// with from-space allocation criteria modified and
// such allocation moved out of the safepoint path.
gch->do_collection(true /* full */,
false /* clear_all_soft_refs */,
size /* size */,
is_tlab /* is_tlab */,
number_of_generations() - 1 /* max_level */);
}
result = gch->attempt_allocation(size, is_tlab, false /*first_only*/);
if (result != NULL) {
assert(gch->is_in_reserved(result), "result not in heap");
return result;
}
// OK, collection failed, try expansion.
result = expand_heap_and_allocate(size, is_tlab);
if (result != NULL) {
return result;
}
// If we reach this point, we're really out of memory. Try every trick
// we can to reclaim memory. Force collection of soft references. Force
// a complete compaction of the heap. Any additional methods for finding
// free memory should be here, especially if they are expensive. If this
// attempt fails, an OOM exception will be thrown.
{
IntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted
gch->do_collection(true /* full */,
true /* clear_all_soft_refs */,
size /* size */,
is_tlab /* is_tlab */,
number_of_generations() - 1 /* max_level */);
}
result = gch->attempt_allocation(size, is_tlab, false /* first_only */);
if (result != NULL) {
assert(gch->is_in_reserved(result), "result not in heap");
return result;
}
// What else? We might try synchronous finalization later. If the total
// space available is large enough for the allocation, then a more
// complete compaction phase than we've tried so far might be
// appropriate.
return NULL;
}
示例6: assert
bool SolverSLAM2DLinear::solveOrientation()
{
assert(_optimizer->indexMapping().size() + 1 == _optimizer->vertices().size() && "Needs to operate on full graph");
assert(_optimizer->vertex(0)->fixed() && "Graph is not fixed by vertex 0");
VectorXD b, x; // will be used for theta and x/y update
b.setZero(_optimizer->indexMapping().size());
x.setZero(_optimizer->indexMapping().size());
typedef Eigen::Matrix<double, 1, 1, Eigen::ColMajor> ScalarMatrix;
ScopedArray<int> blockIndeces(new int[_optimizer->indexMapping().size()]);
for (size_t i = 0; i < _optimizer->indexMapping().size(); ++i)
blockIndeces[i] = i+1;
SparseBlockMatrix<ScalarMatrix> H(blockIndeces.get(), blockIndeces.get(), _optimizer->indexMapping().size(), _optimizer->indexMapping().size());
// building the structure, diagonal for each active vertex
for (size_t i = 0; i < _optimizer->indexMapping().size(); ++i) {
OptimizableGraph::Vertex* v = _optimizer->indexMapping()[i];
int poseIdx = v->hessianIndex();
ScalarMatrix* m = H.block(poseIdx, poseIdx, true);
m->setZero();
}
HyperGraph::VertexSet fixedSet;
// off diagonal for each edge
for (SparseOptimizer::EdgeContainer::const_iterator it = _optimizer->activeEdges().begin(); it != _optimizer->activeEdges().end(); ++it) {
# ifndef NDEBUG
EdgeSE2* e = dynamic_cast<EdgeSE2*>(*it);
assert(e && "Active edges contain non-odometry edge"); //
# else
EdgeSE2* e = static_cast<EdgeSE2*>(*it);
# endif
OptimizableGraph::Vertex* from = static_cast<OptimizableGraph::Vertex*>(e->vertices()[0]);
OptimizableGraph::Vertex* to = static_cast<OptimizableGraph::Vertex*>(e->vertices()[1]);
int ind1 = from->hessianIndex();
int ind2 = to->hessianIndex();
if (ind1 == -1 || ind2 == -1) {
if (ind1 == -1) fixedSet.insert(from); // collect the fixed vertices
if (ind2 == -1) fixedSet.insert(to);
continue;
}
bool transposedBlock = ind1 > ind2;
if (transposedBlock){ // make sure, we allocate the upper triangle block
std::swap(ind1, ind2);
}
ScalarMatrix* m = H.block(ind1, ind2, true);
m->setZero();
}
// walk along the Minimal Spanning Tree to compute the guess for the robot orientation
assert(fixedSet.size() == 1);
VertexSE2* root = static_cast<VertexSE2*>(*fixedSet.begin());
VectorXD thetaGuess;
thetaGuess.setZero(_optimizer->indexMapping().size());
UniformCostFunction uniformCost;
HyperDijkstra hyperDijkstra(_optimizer);
hyperDijkstra.shortestPaths(root, &uniformCost);
HyperDijkstra::computeTree(hyperDijkstra.adjacencyMap());
ThetaTreeAction thetaTreeAction(thetaGuess.data());
HyperDijkstra::visitAdjacencyMap(hyperDijkstra.adjacencyMap(), &thetaTreeAction);
// construct for the orientation
for (SparseOptimizer::EdgeContainer::const_iterator it = _optimizer->activeEdges().begin(); it != _optimizer->activeEdges().end(); ++it) {
EdgeSE2* e = static_cast<EdgeSE2*>(*it);
VertexSE2* from = static_cast<VertexSE2*>(e->vertices()[0]);
VertexSE2* to = static_cast<VertexSE2*>(e->vertices()[1]);
double omega = e->information()(2,2);
double fromThetaGuess = from->hessianIndex() < 0 ? 0. : thetaGuess[from->hessianIndex()];
double toThetaGuess = to->hessianIndex() < 0 ? 0. : thetaGuess[to->hessianIndex()];
double error = normalize_theta(-e->measurement().rotation().angle() + toThetaGuess - fromThetaGuess);
bool fromNotFixed = !(from->fixed());
bool toNotFixed = !(to->fixed());
if (fromNotFixed || toNotFixed) {
double omega_r = - omega * error;
if (fromNotFixed) {
b(from->hessianIndex()) -= omega_r;
(*H.block(from->hessianIndex(), from->hessianIndex()))(0,0) += omega;
if (toNotFixed) {
if (from->hessianIndex() > to->hessianIndex())
(*H.block(to->hessianIndex(), from->hessianIndex()))(0,0) -= omega;
else
(*H.block(from->hessianIndex(), to->hessianIndex()))(0,0) -= omega;
}
}
if (toNotFixed ) {
b(to->hessianIndex()) += omega_r;
(*H.block(to->hessianIndex(), to->hessianIndex()))(0,0) += omega;
}
}
}
//.........这里部分代码省略.........
示例7: main
int main()
{
std::random_device rd;
std::mt19937_64 rng(rd());
const int sawtooth = 1;
const int do_rand = 2;
const int stagger = 3;
const int plateau = 4;
const int shuffle = 5;
for (size_t n : {100, 1023, 1024, 1025, (2 << 16) - 1, 2 << 16, (2 << 16) + 1}) {
std::cerr << "\nSize: " << n << ": ";
for (size_t m = 1; m < 2 * n; m *= 2) {
std::cerr << m;
for (auto dist : {sawtooth, do_rand, stagger, plateau, shuffle}) {
std::cerr << ".";
std::vector<int64_t> x(n);
size_t i = 0, j = 0, k = 1;
switch (dist) {
case sawtooth:
for (; i < n; i++) {
x[i] = i % m;
}
break;
case do_rand:
for (; i < n; i++) {
x[i] = rng() % m;
}
break;
case stagger:
for (; i < n; i++) {
x[i] = (i * m + i) % n;
}
break;
case plateau:
for (; i < n; i++) {
x[i] = std::min(i, m);
}
break;
case shuffle:
for (; i < n; i++) {
x[i] = rng() % m ? (j += 2) : (k += 2);
}
break;
}
Ioss::qsort(x); // Copy of x
assert(verify_sorted(x));
std::reverse(x.begin(), x.end()); // Reversed
Ioss::qsort(x);
assert(verify_sorted(x));
std::reverse(&x[0], &x[n / 2]); // Front half reversed
Ioss::qsort(x);
assert(verify_sorted(x));
std::reverse(&x[n / 2], &x[n]); // Back half reversed
Ioss::qsort(x);
assert(verify_sorted(x));
Ioss::qsort(x); // Already sorted
assert(verify_sorted(x));
for (size_t p = 0; p < n; p++) {
x[p] += p % 5;
}
Ioss::qsort(x); // Dithered
assert(verify_sorted(x));
}
}
}
std::cerr << "\nDone\n";
}
示例8: lod_cn_travelling_wave
// NB : matrix is passed in Column-Major storage.
void
lod_cn_travelling_wave(double* const inout_matrix,
const int space_nb_x,
const int space_nb_y,
const double final_time,
const double tau,
const double eps)
{
double h_x = 1./((double)space_nb_x-1.), h_y = 1./((double)space_nb_y-1.);
Eigen::VectorXd x_border, y_border, x(space_nb_x), y(space_nb_y);
Eigen::MatrixXd values, after_x, after_y, after_reaction;
Eigen::SparseMatrix<double> operator_x, operator_y, laplace_x, unit_matrix_x, laplace_y, unit_matrix_y;
// Boundaries.
x_border.setLinSpaced(space_nb_x, 0., 1.);
y_border.setLinSpaced(space_nb_y, 0., 1.);
// Initial values.
initial_values(values, x_border, y_border, eps);
// Operators initialization;
laplace_operator_1d(laplace_x, space_nb_x);
identity_operator(unit_matrix_x, space_nb_x);
laplace_operator_1d(laplace_y, space_nb_y);
identity_operator(unit_matrix_y, space_nb_y);
space_operator(operator_x, laplace_x, (tau*eps)/(h_x*h_x), unit_matrix_x);
space_operator(operator_y, laplace_y, (tau*eps)/(h_y*h_y), unit_matrix_y);
#ifdef DEBUG_LOD_CN
debug_print("init values", values, 5, 5);
debug_print("laplace x", laplace_x, 5, 5);
debug_print("I x", unit_matrix_x, 5, 5);
debug_print("laplace y", laplace_y, 5, 5);
debug_print("I y", unit_matrix_y, 5, 5);
debug_print("Op x", operator_x, 5, 5);
debug_print("Op y", operator_y, 5, 5);
#endif
double time = 0.;
const double tcoeff = 1.;
while (time < final_time)
{
// Step in x direction.
// NB. Operators x and y are hermitian, so that we can commute them.
// Apply an operator in x direction.
#ifdef DEBUG_LOD_CN
debug_print("values", values, 5, 5);
#endif
after_x = values*operator_x;
bc_x(y, y_border, time, 0., eps);
after_x.col(0) = y*tcoeff;
bc_x(y, y_border, time, 1., eps);
after_x.col(space_nb_x-1) = y*tcoeff;
#ifdef DEBUG_LOD_CN
debug_print("after_x", after_x, 5, 5);
#endif
// Apply an operator in y direction.
after_y = operator_y*values;
bc_y(x, x_border, time, 0., eps);
after_y.row(0) = x.transpose()*tcoeff;
bc_y(x, x_border, time, 1., eps);
after_y.row(space_nb_y-1) = x.transpose()*tcoeff;
#ifdef DEBUG_LOD_CN
debug_print("after_y", after_y, 5, 5);
#endif
// Apply the reaction operator.
auto transform = ::boost::bind(reaction_operator, _1, tau/eps);
after_reaction = after_y+after_y.unaryExpr(transform);
#ifdef DEBUG_LOD_CN
debug_print("after_reaction", after_reaction, 5, 5);
#endif
// Time advance.
time += tau;
// Second application of an operator in y direction.
after_y = operator_y*after_reaction;
bc_y(x, x_border, time, 0., eps);
after_y.row(0) = x.transpose()*tcoeff;
bc_y(x, x_border, time, 1., eps);
after_y.row(space_nb_y-1) = x.transpose()*tcoeff;
#ifdef DEBUG_LOD_CN
debug_print("after_y", after_y, 5, 5);
#endif
// Second application of an operator in x direction.
values = after_y*operator_x;
bc_x(y, y_border, time, 0., eps);
values.col(0) = y*tcoeff;
bc_x(y, y_border, time, 1., eps);
values.col(space_nb_x-1) = y*tcoeff;
}
// Copy to the return value.
memcpy(inout_matrix, values.data(), space_nb_x*space_nb_y*sizeof(double));
}
示例9: add
void add(int u, int v, int cost, int cap) {
edge x(v, int(ed[v].size()), cost, cap);
edge y(u, int(ed[u].size()), -cost, 0);
ed[u].push_back(x);
ed[v].push_back(y);
}
示例10: fl_clip_box
void console_widget_t::draw()
{
if (console == NULL) {
int x_, y_, w_, h_;
fl_clip_box(x(),y(),w(),h(), x_, y_, w_, h_);
fl_color(FL_BLACK);
fl_rectf(x_, y_, w_, h_);
return;
}
fl_font(font_name, font_size);
int x_, y_, w_, h_, cx, cy;
fl_clip_box(x(), y(), w(), h(), x_, y_, w_, h_);
cx = x();
cy = y();
cx -= (fit_x - w()) / 2;
cy -= (fit_y - h()) / 2;
x_ -= cx;
y_ -= cy;
int x1 = x_ / letter_x;
int x2 = (x_ + w_) / letter_x + 1;
int y1 = y_ / letter_y;
int y2 = (y_ + h_) / letter_y + 1;
int yi = 0;
if (x_ < 0) {
fl_color(FL_BLACK);
fl_rectf(x(), y(), -x_, h_);
x1 = 0;
cx += x1 * letter_x;
}
if (y_ < 0) {
fl_color(FL_BLACK);
fl_rectf(cx, y(), fit_x, -y_);
}
if (x_ + w_ > fit_x) {
fl_color(FL_BLACK);
fl_rectf(cx + fit_x, y(), x_ + w_ - fit_x, h_);
x2 = console->config.x;
}
if (y_ + h_ > fit_y) {
fl_color(FL_BLACK);
fl_rectf(cx, cy + fit_y,
fit_x, y_ + h_ - fit_y);
}
fl_push_clip(x(), y(), w(), h());
for (yi = y1; yi < y2; yi++) {
if (yi < 0)
continue;
if (yi >= console->config.y)
break;
co_console_cell_t* row_start = &console->screen[(yi+scroll_lines) * console->config.x];
co_console_cell_t* cell;
co_console_cell_t* start;
co_console_cell_t* end;
char text_buff[0x100];
start = row_start + x1;
end = row_start + x2;
cell = start;
if (end > cell_limit) {
// co_debug("BUG: end=%p limit=%p row=%p start=%p x1=%d x2=%d y1=%d y2=%d",
// end, limit, row_start, start, x1, x2, y1, y2);
end = cell_limit; // Hack: Fix the overrun!
}
while (cell < end) {
while (cell < end && start->attr == cell->attr &&
cell - start < (int)sizeof(text_buff)) {
text_buff[cell - start] = cell->ch;
cell++;
}
FL_RGB_COLOR((start->attr >> 4) & 0xf);
fl_rectf(cx + letter_x * (start - row_start),
cy + letter_y * (yi),
(cell - start) * letter_x,
letter_y);
FL_RGB_COLOR((start->attr) & 0xf);
fl_draw(text_buff, cell - start,
cx + letter_x * (start - row_start),
cy + letter_y * (yi + 1) - fl_descent());
//.........这里部分代码省略.........
示例11: visualOverflowRect
void RenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
// An empty viewport disables rendering.
if (pixelSnappedBorderBoxRect().isEmpty())
return;
// Don't paint, if the context explicitely disabled it.
if (paintInfo.context->paintingDisabled())
return;
Page* page = 0;
if (Frame* frame = this->frame())
page = frame->page();
// Don't paint if we don't have kids, except if we have filters we should paint those.
if (!firstChild()) {
SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this);
if (!resources || !resources->filter()) {
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantUnpaintedObject(this, visualOverflowRect());
return;
}
}
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantRepaintedObject(this, visualOverflowRect());
// Make a copy of the PaintInfo because applyTransform will modify the damage rect.
PaintInfo childPaintInfo(paintInfo);
childPaintInfo.context->save();
// Apply initial viewport clip - not affected by overflow handling
childPaintInfo.context->clip(pixelSnappedIntRect(overflowClipRect(paintOffset, paintInfo.renderRegion)));
// Convert from container offsets (html renderers) to a relative transform (svg renderers).
// Transform from our paint container's coordinate system to our local coords.
IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset);
childPaintInfo.applyTransform(AffineTransform::translation(adjustedPaintOffset.x() - x(), adjustedPaintOffset.y() - y()) * localToParentTransform());
SVGRenderingContext renderingContext;
bool continueRendering = true;
if (childPaintInfo.phase == PaintPhaseForeground) {
renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
continueRendering = renderingContext.isRenderingPrepared();
}
if (continueRendering)
RenderBox::paint(childPaintInfo, LayoutPoint());
childPaintInfo.context->restore();
}
示例12: qMakePair
void QQuickParticleEmitter::burst(int num)
{
m_burstQueue << qMakePair(num, QPointF(x(), y()));
}
示例13: foo
void foo() {
X x(1); // { dg-error "incomplete type" }
bar(x); // { dg-error "3:'bar' was not declared" }
}
示例14: updateClock
void CommercialGraphic::showClock() {
clockStatus = SHOW_CLOCK;
updateClock();
if (show)
scene()->update(x() + CLOCK_X, y(), CLOCK_WIDTH, GRAPHIC_HEIGHT);
}
示例15: foo
int foo ()
{
std::decimal::decimal64 x(0);
bar (x);
}