本文整理汇总了C++中std::ostream::copyfmt方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::copyfmt方法的具体用法?C++ ostream::copyfmt怎么用?C++ ostream::copyfmt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostream
的用法示例。
在下文中一共展示了ostream::copyfmt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_node
void write_node(const tree_type & tree,
const typename tree_type::iterator & node_iter,
std::ostream& out) const {
bool is_leaf = node_iter.is_leaf();
if (!is_leaf) {
out << "(";
int ch_count = 0;
for (auto chi = tree.children_begin(node_iter);
chi != tree.children_end(node_iter);
++chi, ++ch_count) {
if (ch_count > 0) {
out << ",";
if (!this->compact_spaces_) {
out << " ";
}
}
this->write_node(tree, chi, out);
}
out << ")";
}
if (this->node_value_label_getter_ && (is_leaf || !this->suppress_internal_node_labels_)) {
out << this->node_value_label_getter_(*node_iter);
}
if (this->node_value_edge_length_getter_ && !this->suppress_edge_lengths_) {
out << ":" << std::fixed << std::setprecision(this->edge_length_precision_) << this->node_value_edge_length_getter_(*node_iter);
out.copyfmt(std::ios(NULL)); // restore state
}
}
示例2: i
static
void
add_gvcf_filters(const gvcf_options& opt,
const cdmap_t& chrom_depth,
std::ostream& os) {
using namespace VCF_FILTERS;
write_vcf_filter(os,get_label(IndelConflict),"Locus is in region with conflicting indel calls");
write_vcf_filter(os,get_label(SiteConflict),"Site genotype conflicts with proximal indel call. This is typically a heterozygous SNV call made inside of a heterozygous deletion");
if (opt.is_min_gqx) {
std::ostringstream oss;
oss << "Locus GQX is less than " << opt.min_gqx << " or not present";
write_vcf_filter(os,get_label(LowGQX),oss.str().c_str());
}
if (opt.is_max_base_filt) {
std::ostringstream oss;
oss << "The fraction of basecalls filtered out at a site is greater than " << opt.max_base_filt;
write_vcf_filter(os,get_label(HighBaseFilt),oss.str().c_str());
}
if (opt.is_max_snv_sb) {
std::ostringstream oss;
oss << "SNV strand bias value (SNVSB) exceeds " << opt.max_snv_sb;
write_vcf_filter(os,get_label(HighSNVSB),oss.str().c_str());
}
if (opt.is_max_snv_hpol) {
std::ostringstream oss;
oss << "SNV contextual homopolymer length (SNVHPOL) exceeds " << opt.max_snv_hpol;
write_vcf_filter(os,get_label(HighSNVHPOL),oss.str().c_str());
}
if (opt.is_max_ref_rep) {
std::ostringstream oss;
oss << "Locus contains an indel allele occurring in a homopolymer or dinucleotide track with a reference repeat greater than " << opt.max_ref_rep;
write_vcf_filter(os,get_label(HighRefRep),oss.str().c_str());
}
if (opt.is_max_depth_factor && (! chrom_depth.empty())) {
std::ostringstream oss;
oss << "Locus depth is greater than " << opt.max_depth_factor << "x the mean chromosome depth";
write_vcf_filter(os,get_label(HighDepth),oss.str().c_str());
std::ofstream tmp_os;
tmp_os.copyfmt(os);
os << std::fixed << std::setprecision(2);
cdmap_t::const_iterator i(chrom_depth.begin()), i_end(chrom_depth.end());
for (; i!=i_end; ++i) {
const std::string& chrom(i->first);
const double max_depth(opt.max_depth_factor*i->second);
os << "##MaxDepth_" << chrom << '=' << max_depth << "\n";
}
os.copyfmt(tmp_os);
}
}
示例3: init
//
// Generate hex dump of a "payload"
//
static const void dumpPayload(std::ostream &os, const SerfPayload &p)
{
int count = 0;
std::ios init(NULL);
init.copyfmt(os);
os << std::hex << std::setfill('0') << std::setw(2);
SerfPayload::const_iterator i = p.begin();
for (; i != p.end(); ++i, ++count) {
if (count && (count % 8) == 0) os << "\n ";
os << "0x" << (static_cast<int>(*i) & 0xff) << " ";
}
os.copyfmt(init);
os << std::endl;
}
示例4: hsymCheck
std::vector<Real> Objective<Real>::checkHessSym( const Vector<Real> &x,
const Vector<Real> &hv,
const Vector<Real> &v,
const Vector<Real> &w,
const bool printToStream,
std::ostream & outStream ) {
Real tol = std::sqrt(ROL_EPSILON);
// Compute (Hessian at x) times (vector v).
Teuchos::RCP<Vector<Real> > h = hv.clone();
this->hessVec(*h, v, x, tol);
Real wHv = w.dot(h->dual());
this->hessVec(*h, w, x, tol);
Real vHw = v.dot(h->dual());
std::vector<Real> hsymCheck(3, 0);
hsymCheck[0] = wHv;
hsymCheck[1] = vHw;
hsymCheck[2] = std::abs(vHw-wHv);
// Save the format state of the original outStream.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(outStream);
if (printToStream) {
outStream << std::right
<< std::setw(20) << "<w, H(x)v>"
<< std::setw(20) << "<v, H(x)w>"
<< std::setw(20) << "abs error"
<< "\n";
outStream << std::scientific << std::setprecision(11) << std::right
<< std::setw(20) << hsymCheck[0]
<< std::setw(20) << hsymCheck[1]
<< std::setw(20) << hsymCheck[2]
<< "\n";
}
// Reset format state of outStream.
outStream.copyfmt(oldFormatState);
return hsymCheck;
} // checkHessSym
示例5: print
void SockAddress::print(std::ostream &out) const
{
if(m_Type == V4)
out << (int)m_Data[0] << '.' << (int)m_Data[1] << '.'
<< (int)m_Data[2] << '.' << (int)m_Data[3];
else /* m_Type == V6 */
{
std::ios state(NULL);
state.copyfmt(out);
out << std::hex << std::uppercase;
out << '[' << (int)m_Data[0];
for(int i = 1; i < 16; ++i)
out << ':' << (int)m_Data[i];
out << ']';
out.copyfmt(state);
}
}
示例6: tmp
std::vector<std::vector<Real> > Objective<Real>::checkHessVec( const Vector<Real> &x,
const Vector<Real> &hv,
const Vector<Real> &v,
const std::vector<Real> &steps,
const bool printToStream,
std::ostream & outStream,
const int order ) {
TEUCHOS_TEST_FOR_EXCEPTION( order<1 || order>4, std::invalid_argument,
"Error: finite difference order must be 1,2,3, or 4" );
using Finite_Difference_Arrays::shifts;
using Finite_Difference_Arrays::weights;
Real tol = std::sqrt(ROL_EPSILON);
int numSteps = steps.size();
int numVals = 4;
std::vector<Real> tmp(numVals);
std::vector<std::vector<Real> > hvCheck(numSteps, tmp);
// Save the format state of the original outStream.
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(outStream);
// Compute gradient at x.
Teuchos::RCP<Vector<Real> > g = hv.clone();
this->update(x);
this->gradient(*g, x, tol);
// Compute (Hessian at x) times (vector v).
Teuchos::RCP<Vector<Real> > Hv = hv.clone();
this->hessVec(*Hv, v, x, tol);
Real normHv = Hv->norm();
// Temporary vectors.
Teuchos::RCP<Vector<Real> > gdif = hv.clone();
Teuchos::RCP<Vector<Real> > gnew = hv.clone();
Teuchos::RCP<Vector<Real> > xnew = x.clone();
for (int i=0; i<numSteps; i++) {
Real eta = steps[i];
// Evaluate objective value at x+eta*d.
xnew->set(x);
gdif->set(*g);
gdif->scale(weights[order-1][0]);
for(int j=0; j<order; ++j) {
// Evaluate at x <- x+eta*c_i*d.
xnew->axpy(eta*shifts[order-1][j], v);
// Only evaluate at shifts where the weight is nonzero
if( weights[order-1][j+1] != 0 ) {
this->update(*xnew);
this->gradient(*gnew, *xnew, tol);
gdif->axpy(weights[order-1][j+1],*gnew);
}
}
gdif->scale(1.0/eta);
// Compute norms of hessvec, finite-difference hessvec, and error.
hvCheck[i][0] = eta;
hvCheck[i][1] = normHv;
hvCheck[i][2] = gdif->norm();
gdif->axpy(-1.0, *Hv);
hvCheck[i][3] = gdif->norm();
if (printToStream) {
if (i==0) {
outStream << std::right
<< std::setw(20) << "Step size"
<< std::setw(20) << "norm(Hess*vec)"
<< std::setw(20) << "norm(FD approx)"
<< std::setw(20) << "norm(abs error)"
<< "\n";
}
outStream << std::scientific << std::setprecision(11) << std::right
<< std::setw(20) << hvCheck[i][0]
<< std::setw(20) << hvCheck[i][1]
<< std::setw(20) << hvCheck[i][2]
<< std::setw(20) << hvCheck[i][3]
<< "\n";
}
}
// Reset format state of outStream.
outStream.copyfmt(oldFormatState);
return hvCheck;
} // checkHessVec
示例7: RiskMeasureInfo
//.........这里部分代码省略.........
riskString[i] == "Log-Quantile Quadrangle" ||
riskString[i] == "Mean-Variance Quadrangle" ||
riskString[i] == "Quantile-Based Quadrangle" ||
riskString[i] == "Smoothed Worst-Case Quadrangle" ||
riskString[i] == "Truncated Mean Quadrangle" ) {
nStatistic += 1;
lower.push_back(ROL_NINF<Real>());
upper.push_back(ROL_INF<Real>());
}
else if ( riskString[i] == "Quantile-Radius Quadrangle" ) {
nStatistic += 2;
lower.push_back(ROL_NINF<Real>()); lower.push_back(ROL_NINF<Real>());
upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
}
else if ( riskString[i] == "Coherent Exponential Utility" ||
riskString[i] == "KL Divergence" ) {
nStatistic += 1;
isBoundActivated = true;
lower.push_back(zero);
upper.push_back(ROL_INF<Real>());
}
else if ( riskString[i] == "Chi-Squared Divergence" ) {
nStatistic += 2;
isBoundActivated = true;
lower.push_back(zero); lower.push_back(ROL_NINF<Real>());
upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
}
else if ( riskString[i] == "Mixed-Quantile Quadrangle" ) {
Teuchos::ParameterList &MQlist = list.sublist("Mixed-Quantile Quadrangle");
Teuchos::Array<Real> prob
= Teuchos::getArrayFromStringParameter<Real>(MQlist,"Probability Array");
nStatistic += prob.size();
for (typename Teuchos::Array<Real>::size_type j = 0; j < prob.size(); ++j) {
lower.push_back(ROL_NINF<Real>());
upper.push_back(ROL_INF<Real>());
}
}
else if ( riskString[i] == "Super Quantile Quadrangle" ||
riskString[i] == "Chebyshev-Kusuoka" ||
riskString[i] == "Spectral Risk" ) {
Teuchos::ParameterList &SQlist = list.sublist(riskString[i]);
int nSQQstat = SQlist.get("Number of Quadrature Points",5);
nStatistic += nSQQstat;
for (int j = 0; j < nSQQstat; ++j) {
lower.push_back(ROL_NINF<Real>());
upper.push_back(ROL_INF<Real>());
}
}
else if ( riskString[i] == "Exponential Utility" ||
riskString[i] == "Mean Plus Deviation From Target" ||
riskString[i] == "Mean Plus Deviation" ||
riskString[i] == "Mean Plus Variance From Target" ||
riskString[i] == "Mean Plus Variance" ) {
nStatistic += 0;
}
else {
TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
">>> (ROL::RiskMeasureInfo): Invalid risk measure " << riskString[i] << "!");
}
}
}
else {
TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
">>> (ROL::RiskMeasureInfo): Invalid risk measure " << name << "!");
}
// Print Information
if ( printToStream ) {
Teuchos::oblackholestream oldFormatState;
oldFormatState.copyfmt(outStream);
outStream << std::endl;
outStream << std::scientific << std::setprecision(6);
outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
outStream << " RISK MEASURE INFORMATION" << std::endl;
outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
outStream << " NAME" << std::endl;
outStream << " " << name << std::endl;
outStream << " NUMBER OF STATISTICS" << std::endl;
outStream << " " << nStatistic << std::endl;
outStream << " ARE BOUNDS ACTIVATED" << std::endl;
outStream << " " << (isBoundActivated ? "TRUE" : "FALSE") << std::endl;
if ( isBoundActivated ) {
outStream << " STATISTIC LOWER BOUNDS" << std::endl;
for (int i = 0; i < nStatistic-1; ++i) {
outStream << " " << lower[i] << std::endl;
}
outStream << " " << lower[nStatistic-1] << std::endl;
outStream << " STATISTIC UPPER BOUNDS" << std::endl;
for (int i = 0; i < nStatistic-1; ++i) {
outStream << " " << upper[i] << std::endl;
}
outStream << " " << upper[nStatistic-1] << std::endl;
}
outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
outStream << std::endl;
outStream.copyfmt(oldFormatState);
}
}