本文整理汇总了C++中PVector::axpy方法的典型用法代码示例。如果您正苦于以下问题:C++ PVector::axpy方法的具体用法?C++ PVector::axpy怎么用?C++ PVector::axpy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PVector
的用法示例。
在下文中一共展示了PVector::axpy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
using Teuchos::RCP;
using Teuchos::rcp;
typedef std::vector<RealT> vector;
typedef ROL::StdVector<RealT> StdVector;
typedef Teuchos::RCP<ROL::Vector<RealT> > PVector;
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
// This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
int iprint = argc - 1;
Teuchos::RCP<std::ostream> outStream;
Teuchos::oblackholestream bhs; // outputs nothing
if (iprint > 0)
outStream = Teuchos::rcp(&std::cout, false);
else
outStream = Teuchos::rcp(&bhs, false);
// Save the format state of the original std::cout.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(std::cout);
int errorFlag = 0;
// Specify interval on which to generate uniform random numbers.
RealT left = 0.1, right = 1.1;
// *** Test body.
try {
int dim = 1;
RCP<vector> x_rcp = rcp( new vector(dim,0.0) );
RCP<vector> y_rcp = rcp( new vector(dim,0.0) );
RCP<vector> v_rcp = rcp( new vector(dim,0.0) );
RCP<vector> d_rcp = rcp( new vector(dim,0.0) );
RCP<vector> gx_rcp = rcp( new vector(dim,0.0) );
RCP<vector> gy_rcp = rcp( new vector(dim,0.0) );
RCP<vector> hv_rcp = rcp( new vector(dim,0.0) );
for( int i=0; i<dim; ++i ) {
(*x_rcp)[i] = 2+( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
(*d_rcp)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
(*v_rcp)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
}
StdVector x( x_rcp);
StdVector y( y_rcp);
StdVector v( v_rcp);
StdVector d( d_rcp);
StdVector gx(gx_rcp);
StdVector gy(gy_rcp);
StdVector hv(hv_rcp);
// Fixed difference step size
RealT delta = 1.e-7;
y.set(x); // y = x
y.axpy(delta,d); // y = x+delta*d
ROL::LogBarrierObjective<RealT> obj;
// Do step size sweep
obj.checkGradient(x, d, true, *outStream);
*outStream << "\n";
obj.checkHessVec(x, v, true, *outStream);
*outStream << "\n";
RealT tol = 0;
// Compute objective at x and y
RealT fx = obj.value(x,tol);
RealT fy = obj.value(y,tol);
// Compute gradient at x and y
obj.gradient(gx,x,tol);
obj.gradient(gy,y,tol);
// Compute action of Hessian on v at x
obj.hessVec(hv,v,x,tol);
// FD gradient error
RealT graderr = (fy - fx)/delta - gx.dot(d);
// FD Hessian error
PVector dg = gx.clone();
dg->set(gy);
dg->axpy(-1.0,gx);
RealT hesserr = ( dg->dot(v) )/delta - hv.dot(d);
if( std::abs(graderr) > 1e-8 ) {
++errorFlag;
}
if( std::abs(hesserr) > 1e-8 ) {
//.........这里部分代码省略.........