本文整理汇总了C++中x2函数的典型用法代码示例。如果您正苦于以下问题:C++ x2函数的具体用法?C++ x2怎么用?C++ x2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了x2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEUCHOS_UNIT_TEST
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( WuBasis, wu_basis_order_2 )
{
typedef DataTransferKit::WuBasis<2> BasisType;
typedef DataTransferKit::RadialBasisPolicy<BasisType> BP;
int dim = 3;
Teuchos::Array<double> x1(dim, 0.5);
Teuchos::Array<double> x2(dim, 0.75);
double radius_1 = 1.0;
Teuchos::RCP<BasisType> basis_1 = BP::create();
double dist = DataTransferKit::EuclideanDistance<3>::distance(
x1.getRawPtr(), x2.getRawPtr() );
double basis_value = BP::evaluateValue( *basis_1, radius_1, dist );
double basis_grad = BP::evaluateGradient( *basis_1, radius_1, dist );
double x = 0.0;
for ( int i = 0; i < dim; ++i )
{
x += (x2[i]-x1[i])*(x2[i]-x1[i]);
}
x = std::sqrt(x);
double test_value = (1.0-x)*(1.0-x)*(1.0-x)*(1.0-x)*(1.0-x) *
( 5.0*x*x*x*x+25.0*x*x*x+48.0*x*x+40.0*x+8.0 );
double test_grad = -9.0*(x-1.0)*(x-1.0)*(x-1.0)*(x-1.0)*x *
( 5.0*x*x*x+20.0*x*x+29.0*x+16.0 );
TEST_EQUALITY( test_value, basis_value );
TEST_FLOATING_EQUALITY( test_grad, basis_grad, epsilon );
double radius_2 = 0.1;
BasisType basis_2;
basis_value = BP::evaluateValue( basis_2, radius_2, dist );
basis_grad = BP::evaluateGradient( basis_2, radius_2, dist );
TEST_EQUALITY( 0.0, basis_value );
TEST_EQUALITY( 0.0, basis_grad );
}
示例2: probability_x_less_than_y
double probability_x_less_than_y(const std::valarray<double>& x, const std::valarray<double>& y)
{
vector<double> x2(x.size());
for(int i=0;i<x2.size();i++)
x2[i] = x[i];
sort(x2.begin(),x2.end());
vector<double> y2(y.size());
for(int i=0;i<y2.size();i++)
y2[i] = y[i];
sort(y2.begin(),y2.end());
valarray<double> FX(y.size());
int dx=0;
for(int dy=0;dy<FX.size();dy++) {
while((dx<x2.size()) and (x2[dx]<y2[dy]))
dx++;
FX[dy] = double(dx)/x2.size();
}
return FX.sum()/FX.size();
}
示例3: luaX_loadstring
LUALIB_API int luaX_loadstring(lua_State* L, LPCTSTR code, LPCTSTR name)
{
CString x1(code);
int sz = x1.GetLength();
int bs = WideCharToMultiByte(CP_THREAD_ACP, 0, x1, sz + 1, NULL, 0, NULL, NULL);
char* b1 = new char[bs];
int rs = WideCharToMultiByte(CP_THREAD_ACP, 0, x1, sz + 1, b1, bs, NULL, NULL);
CString x2(name);
x2 = CString("=String-") + x2;
sz = x2.GetLength();
bs = WideCharToMultiByte(CP_THREAD_ACP, 0, x2, sz + 1, NULL, 0, NULL, NULL);
char* b2 = new char[bs];
WideCharToMultiByte(CP_THREAD_ACP, 0, x2, sz + 1, b2, bs, NULL, NULL);
int r = luaL_loadbuffer(L, b1, rs - 1, b2);
delete b1;
delete b2;
return r;
}
示例4: DrawVisibility
void DrawVisibility(QPainter *p,pigalePaint *paint)
{TopologicalGraph G(paint->GCP);
Prop<Tpoint> P1(G.Set(tedge()),PROP_DRAW_POINT_1);
Prop<Tpoint> P2(G.Set(tedge()),PROP_DRAW_POINT_2);
Prop<int> x1(G.Set(tvertex()),PROP_DRAW_INT_1);
Prop<int> x2(G.Set(tvertex()),PROP_DRAW_INT_2);
Prop<int> y(G.Set(tvertex()),PROP_DRAW_INT_5);
Prop<short> ecolor(G.Set(tedge()),PROP_COLOR);
Prop<short> vcolor(G.Set(tvertex()),PROP_COLOR);
double alpha=0.35;
p->setFont(QFont("sans",Min((int)(1.8*alpha * Min(paint->xscale,paint->yscale) + .5),13)));
Tpoint a,b;
for(tvertex v=1;v<=G.nv();v++)
paint->DrawText(p,x1[v]-alpha,y[v]+alpha, x2[v]-x1[v]+2*alpha,2*alpha,v,vcolor[v]);
for (tedge e = 1;e <= G.ne();e++)
{a.x() = P1[e].x(); a.y() = P1[e].y() + alpha;
b.x() = P1[e].x(); b.y() = P2[e].y() - alpha;
paint->DrawSeg(p,a,b,ecolor[e]);
}
}
示例5: main
main()
{
Punct x1(10, 10), x2(100, 200);
Dreptunghi d1(x1, x2), d2(10, 20, 14, 50);
clrscr();
d1.List();
getch();
cout<<'\n';
d2.List();
getch();
cout<<'\n';
if (d1 == d2)
cout<<"d1 = d2";
else
cout<<"d1 != d2";
getch();
cout<<'\n';
cout<<d1.Lung_lat1()<<' '<<d1.Lung_lat2();
getch();
cout<<'\n';
cout<<d2.Lung_lat1()<<' '<<d2.Lung_lat2();
getch();
cout<<'\n';
cout<<"Perimetrul d1: "<<d1.Perimetru();
getch();
cout<<'\n';
cout<<"Perimetrul d2: "<<d2.Perimetru();
getch();
cout<<'\n';
cout<<"d1, colt stanga sus : "<<d1.Colt_st_sus();
getch();
cout<<'\n';
cout<<"d1, colt dreapta jos : "<<d1.Colt_dr_jos();
getch();
cout<<'\n';
return 0;
}
示例6: run
void run() {
/**
* note: this test will deadlock if the code breaks
*/
#if defined(__linux__) || defined(__APPLE__)
// create
pthread_rwlock_t lk;
verify(pthread_rwlock_init(&lk, 0) == 0);
// read lock
verify(pthread_rwlock_rdlock(&lk) == 0);
AtomicUInt32 x1(0);
stdx::thread t1(stdx::bind(worker1, &lk, &x1));
while (!x1.load())
;
verify(x1.load() == 1);
sleepmillis(500);
verify(x1.load() == 1);
AtomicUInt32 x2(0);
stdx::thread t2(stdx::bind(worker2, &lk, &x2));
t2.join();
verify(x2.load() == 1);
pthread_rwlock_unlock(&lk);
for (int i = 0; i < 2000; i++) {
if (x1.load() == 2)
break;
sleepmillis(1);
}
verify(x1.load() == 2);
t1.join();
#endif
}
示例7: testCosineTransform
double testCosineTransform (long n) {
try {
autoNUMvector<double> x (1, n);
autoNUMvector<double> y (1, n);
autoNUMvector<double> x2 (1, n);
autoNUMmatrix<double> cosinesTable (NUMcosinesTable (n), 1, 1);
for (long i = 1 ; i <= n; i++) {
x[i] = NUMrandomUniform (0, 70);
}
NUMcosineTransform (x.peek(), y.peek(), n, cosinesTable.peek());
NUMinverseCosineTransform (y.peek(), x2.peek(), n, cosinesTable.peek());
double delta = 0;
for (long i =1 ; i <= n; i++) {
double dif = x[i] - x2[i];
delta += dif * dif;
}
delta = sqrt (delta);
return delta;
} catch (MelderError) {
Melder_throw ("Test cosine transform error");
}
}
示例8: TEUCHOS_UNIT_TEST
//---------------------------------------------------------------------------//
// Tests.
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( WendlandBasis, dim_1_order_0 )
{
typedef DataTransferKit::WendlandBasis<0> BasisType;
typedef DataTransferKit::RadialBasisPolicy<BasisType> BP;
int dim = 1;
Teuchos::Array<double> x1(dim, 0.5);
Teuchos::Array<double> x2(dim, 0.75);
double radius_1 = 1.0;
Teuchos::RCP<BasisType> basis_1 = BP::create( radius_1 );
double dist = DataTransferKit::EuclideanDistance<1>::distance(
x1.getRawPtr(), x2.getRawPtr() );
double basis_value = BP::evaluateValue( *basis_1, dist );
double basis_grad = BP::evaluateGradient( *basis_1, dist );
double x = 0.0;
for ( int i = 0; i < dim; ++i )
{
x += (x2[i]-x1[i])*(x2[i]-x1[i]);
}
x = std::sqrt(x);
double test_value = (1.0-x)*(1.0-x);
double test_grad = 2.0*x-2.0;
TEST_EQUALITY( test_value, basis_value );
TEST_EQUALITY( test_grad, basis_grad );
double radius_2 = 0.1;
BasisType basis_2( radius_2 );
basis_value = BP::evaluateValue( basis_2, dist );
basis_grad = BP::evaluateGradient( basis_2, dist );
TEST_EQUALITY( 0.0, basis_value );
TEST_EQUALITY( 0.0, basis_grad );
}
示例9: interpolate
// Interpolates between the click points
static void interpolate (const dataVec& dataIn, dataVec& dataOut)
{
const size_t nSteps = 10;
const size_t interpolatedSize = (dataIn.size() - 1) * nSteps;
dataOut.resize(interpolatedSize);
std::vector<double> x(dataIn.size()), y(dataIn.size());
std::transform(begin(dataIn), end(dataIn), begin(x), [](lk::trackDatum d){ return std::get<1>(d).x; });
std::transform(begin(dataIn), end(dataIn), begin(y), [](lk::trackDatum d){ return std::get<1>(d).y; });
std::vector<size_t> frameIndices(interpolatedSize);
std::iota(begin(frameIndices), end(frameIndices), 0);
std::vector<double> x2(interpolatedSize), y2(interpolatedSize);
interpolation::cubic(begin(x), end(x), begin(x2), nSteps);
interpolation::cubic(begin(y), end(y), begin(y2), nSteps);
for (size_t i = 0; i < interpolatedSize; i++)
{
dataOut[i] = lk::trackDatum(frameIndices[i], cv::Point2d(x2[i], y2[i]));
}
}
示例10: createMeshLaplacianLM
boost::shared_ptr<Mesh<Simplex<2> > >
createMeshLaplacianLM()
{
typedef Mesh<Simplex<2> > mesh_type;
double meshSize = option("gmsh.hsize").as<double>();
GeoTool::Node x1(-2,-1);
GeoTool::Node x2(2,1);
GeoTool::Rectangle R( meshSize ,"OMEGA",x1,x2);
//R.setMarker(_type="line",_name="Paroi",_marker3=true);
R.setMarker(_type="line",_name="gamma",_markerAll=true);
R.setMarker(_type="surface",_name="Omega",_markerAll=true);
GeoTool::Node x3(0,0); //center
GeoTool::Node x4(1);//majorRadiusParam
GeoTool::Node x5(0.7);//minorRadiusParam
GeoTool::Node x6(0.1);//penautRadiusParam
GeoTool::Peanut P( meshSize ,"OMEGA2",x3,x4,x5,x6);
P.setMarker(_type="line",_name="peanut",_markerAll=true);
P.setMarker(_type="surface",_name="Omega2",_markerAll=true);
auto mesh = (R-P).createMesh(_mesh=new mesh_type,_name="mymesh.msh");
return mesh;
}
示例11: cos
Foliage::Fixed Foliage::FastMath::cos(const Foliage::Fixed x)
{
if (x < Sint16(0))
{
return cos(x.opposite());
}
if (x > F_TWOPI)
{
return cos(x - F_TWOPI);
}
if (x > F_PI)
{
return cos(x - F_PI).opposite();
}
if (x > F_PI_2)
{
return cos(F_PI - x).opposite();
}
Fixed x2(x);
x2 *= F_2000_OVER_PI;
Sint16 i = Sint16(x2);
return Foliage::FastMath::cos_t[i];
}
示例12: main
int main(int argc, char *argv[]) {
// Los vectores en C++ son escencialmente arreglos en C con una interfaz
// más conveniente. Donde sea que se pueda usar arreglos, se puede usar
// vectores. Cuando se necesita la dirección de memoria de un arreglo, hay
// que usar la dirección del primer elemento del vector: &x[0]. x por sí
// solo no sirve ya que es un objeto que encapsula al verdadero arreglo.
std::vector<float> x1;
x1.reserve(N);
x1.resize(N);
// copiar datos del archivo de entrada al vector
std::ifstream input_file(data_file_name, std::ios::binary | std::ios::in);
if (!input_file) {
std::cerr << "No se pudo abrir el archivo " << data_file_name << std::endl;
std::exit(-1);
}
input_file.read((char *) &x1[0], N * sizeof(float));
input_file.close();
// crear una copia del vector, de modo de tener
// uno para mapear en la GPU y otro en la CPU
std::vector<float> x2(x1);
// mapear x1 en la CPU y x2 en la GPU
cpu_map(x1);
gpu_map(&x2[0], x2.size());
// verificar que los resultados son prácticamente iguales
float squared_diff_norm = 0.0;
# define SQUARED(x) ((x) * (x))
# pragma omp parallel reduction(+: squared_diff_norm)
for (unsigned i = 0; i < N; ++i)
squared_diff_norm += SQUARED(x1[i] - x2[i]);
std::cout << "Norma de la diferencia: " << std::sqrt(squared_diff_norm) << std::endl;
}
示例13: x1
/// return the index of the MHM domain of a fracture
int TPZFracSet::MHMDomain(TPZFracture &frac)
{
TPZManVector<REAL,3> x1(3), x2(3), xmid(3);
fNodeVec[frac.fNodes[0]].GetCoordinates(x1);
fNodeVec[frac.fNodes[1]].GetCoordinates(x2);
std::pair<uint32_t,uint32_t> key0 = NodeKey(frac.fNodes[0]);
std::pair<uint32_t,uint32_t> key1 = NodeKey(frac.fNodes[1]);
if(key0.first == key1.first && key0.first%fMHMSpacingInt[0] == 0)
{
return -1;
}
if(key0.second == key1.second && key0.second%fMHMSpacingInt[1] == 0)
{
return -1;
}
for (int i=0; i<3; i++) {
xmid[i] = (x1[i]+x2[i])*0.5-fLowLeft[i];
}
int numfacex = (fTopRight[0]-fLowLeft[0])/fMHMSpacing[0];
int numx = (xmid[0])/fMHMSpacing[0];
int numy = (xmid[1])/fMHMSpacing[1];
return numy*numfacex+numx;
}
示例14: fevec5
int fevec5(Epetra_Comm& Comm, bool verbose)
{
int NumElements = 4;
Epetra_Map Map(NumElements, 0, Comm);
Epetra_FEVector x1(Map);
x1.PutScalar (0);
// let all processors set global entry 0 to 1
const int GID = 0;
const double value = 1;
x1.ReplaceGlobalValues(1, &GID, &value);
x1.GlobalAssemble (Insert);
if (Comm.MyPID()==0)
std::cout << "Entry " << GID << " after construct & set: "
<< x1[0][0] << std::endl;
// copy vector
Epetra_FEVector x2 (x1);
x2.PutScalar(0);
// re-apply 1 to the vector, but only on the
// owning processor. should be enough to set
// the value (as non-local data in x1 should
// have been eliminated after calling
// GlobalAssemble).
if (Comm.MyPID()==0)
x2.ReplaceGlobalValues(1, &GID, &value);
x2.GlobalAssemble (Insert);
if (Comm.MyPID()==0)
std::cout << "Entry " << GID << " after copy & set: "
<< x2[0][0] << std::endl;
return 0;
}
示例15: TEST
TEST(StanAgradRevInternal, precomp_vv_vari) {
double value, gradient1, gradient2;
AVAR x1(2), x2(3);
AVAR y;
value = 1;
gradient1 = 4;
gradient2 = 5;
AVEC vars = createAVEC(x1, x2);
EXPECT_NO_THROW(y
= stan::math::var(new stan::math::precomp_vv_vari(value,
x1.vi_, x2.vi_, gradient1, gradient2)));
EXPECT_FLOAT_EQ(value, y.val());
VEC g;
EXPECT_NO_THROW(y.grad(vars, g));
ASSERT_EQ(2U, g.size());
EXPECT_FLOAT_EQ(gradient1, g[0]);
EXPECT_FLOAT_EQ(gradient2, g[1]);
stan::math::recover_memory();
}