本文整理汇总了C++中SmartPtr::ElementWiseReciprocal方法的典型用法代码示例。如果您正苦于以下问题:C++ SmartPtr::ElementWiseReciprocal方法的具体用法?C++ SmartPtr::ElementWiseReciprocal怎么用?C++ SmartPtr::ElementWiseReciprocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmartPtr
的用法示例。
在下文中一共展示了SmartPtr::ElementWiseReciprocal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConstPtr
SmartPtr<const Vector> AugRestoSystemSolver::Sigma_tilde_n_c_inv(
const SmartPtr<const Vector>& sigma_n_c,
Number delta_x,
const Vector& any_vec_in_c)
{
DBG_START_METH("AugRestoSystemSolver::Sigma_tilde_n_c_inv",dbg_verbosity);
SmartPtr<Vector> retVec;
if (IsValid(sigma_n_c) || delta_x != 0.0) {
std::vector<const TaggedObject*> deps(1);
std::vector<Number> scalar_deps(1);
deps[0] = GetRawPtr(sigma_n_c);
scalar_deps[0] = delta_x;
if (!sigma_tilde_n_c_inv_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
DBG_PRINT((1,"Not found in cache\n"));
retVec = any_vec_in_c.MakeNew();
if (IsValid(sigma_n_c)) {
if (delta_x != 0.) {
retVec->Copy(*sigma_n_c);
retVec->AddScalar(delta_x);
retVec->ElementWiseReciprocal();
}
else {
// Given a "homogenous vector" implementation (such as in
// DenseVector) the following should be more efficient
retVec->Set(1.);
retVec->ElementWiseDivide(*sigma_n_c);
}
}
else {
retVec->Set(1./delta_x);
}
sigma_tilde_n_c_inv_cache_.AddCachedResult(retVec, deps, scalar_deps);
}
}
return ConstPtr(retVec);
}
示例2: DetermineScalingParametersImpl
void GradientScaling::DetermineScalingParametersImpl(
const SmartPtr<const VectorSpace> x_space,
const SmartPtr<const VectorSpace> p_space,
const SmartPtr<const VectorSpace> c_space,
const SmartPtr<const VectorSpace> d_space,
const SmartPtr<const MatrixSpace> jac_c_space,
const SmartPtr<const MatrixSpace> jac_d_space,
const SmartPtr<const SymMatrixSpace> h_space,
const Matrix& Px_L, const Vector& x_L,
const Matrix& Px_U, const Vector& x_U,
Number& df,
SmartPtr<Vector>& dx,
SmartPtr<Vector>& dc,
SmartPtr<Vector>& dd)
{
DBG_ASSERT(IsValid(nlp_));
SmartPtr<Vector> x = x_space->MakeNew();
SmartPtr<Vector> p = p_space->MakeNew();
if (!nlp_->GetStartingPoint(GetRawPtr(x), true,
GetRawPtr(p), true,
NULL, false,
NULL, false,
NULL, false,
NULL, false)) {
THROW_EXCEPTION(FAILED_INITIALIZATION,
"Error getting initial point from NLP in GradientScaling.\n");
}
//
// Calculate grad_f scaling
//
SmartPtr<Vector> grad_f = x_space->MakeNew();
if (nlp_->Eval_grad_f(*x, *p, *grad_f)) {
double max_grad_f = grad_f->Amax();
df = 1.;
if (scaling_obj_target_gradient_ == 0.) {
if (max_grad_f > scaling_max_gradient_) {
df = scaling_max_gradient_ / max_grad_f;
}
}
else {
if (max_grad_f == 0.) {
Jnlst().Printf(J_WARNING, J_INITIALIZATION,
"Gradient of objective function is zero at starting point. Cannot determine scaling factor based on scaling_obj_target_gradient option.\n");
}
else {
df = scaling_obj_target_gradient_ / max_grad_f;
}
}
df = Max(df, scaling_min_value_);
Jnlst().Printf(J_DETAILED, J_INITIALIZATION,
"Scaling parameter for objective function = %e\n", df);
}
else {
Jnlst().Printf(J_WARNING, J_INITIALIZATION,
"Error evaluating objective gradient at user provided starting point.\n No scaling factor for objective function computed!\n");
df = 1.;
}
//
// No x scaling
//
dx = NULL;
dc = NULL;
if (c_space->Dim()>0) {
//
// Calculate c scaling
//
SmartPtr<Matrix> jac_c = jac_c_space->MakeNew();
if (nlp_->Eval_jac_c(*x, *p, *jac_c)) {
dc = c_space->MakeNew();
const double dbl_min = std::numeric_limits<double>::min();
dc->Set(dbl_min);
jac_c->ComputeRowAMax(*dc, false);
Number arow_max = dc->Amax();
if (scaling_constr_target_gradient_<=0.) {
if (arow_max > scaling_max_gradient_) {
dc->ElementWiseReciprocal();
dc->Scal(scaling_max_gradient_);
SmartPtr<Vector> dummy = dc->MakeNew();
dummy->Set(1.);
dc->ElementWiseMin(*dummy);
}
else {
dc = NULL;
}
}
else {
dc->Set(scaling_constr_target_gradient_/arow_max);
}
if (IsValid(dc) && scaling_min_value_ > 0.) {
SmartPtr<Vector> tmp = dc->MakeNew();
tmp->Set(scaling_min_value_);
dc->ElementWiseMax(*tmp);
}
}
else {
Jnlst().Printf(J_WARNING, J_INITIALIZATION,
"Error evaluating Jacobian of equality constraints at user provided starting point.\n No scaling factors for equality constraints computed!\n");
//.........这里部分代码省略.........