当前位置: 首页>>代码示例>>C++>>正文


C++ typenameSpMat::pos方法代码示例

本文整理汇总了C++中typenameSpMat::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ typenameSpMat::pos方法的具体用法?C++ typenameSpMat::pos怎么用?C++ typenameSpMat::pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typenameSpMat的用法示例。


在下文中一共展示了typenameSpMat::pos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stream_state

inline
void
arma_ostream::print_dense(std::ostream& o, const SpMat<eT>& m, const bool modify)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  const uword m_n_rows = m.n_rows;
  const uword m_n_cols = m.n_cols;
    
  if(m.n_nonzero > 0)
    {
    const std::streamsize cell_width = modify ? modify_stream<eT>(o, m.begin(), m.n_nonzero) : o.width();
    
    typename SpMat<eT>::const_iterator begin = m.begin();
    
    if(m_n_cols > 0)
      {
      if(cell_width > 0)
        {
        // An efficient row_iterator would make this simpler and faster
        for(uword row=0; row < m_n_rows; ++row)
          {
          for(uword col=0; col < m_n_cols; ++col)
            {
            // the cell width appears to be reset after each element is printed,
            // hence we need to restore it
            o.width(cell_width);
            eT val = eT(0);
            for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m.n_nonzero; ++it)
              {
              if(it.row() == row && it.col() == col)
                {
                val = *it;
                break;
                }
              }
            arma_ostream::print_elem(o,eT(val), modify);
            }

          o << '\n';
          }
        }
      else
        {
        // An efficient row_iterator would make this simpler and faster
        for(uword row=0; row < m_n_rows; ++row)
          {
          for(uword col=0; col < m_n_cols; ++col)
            {
            eT val = eT(0);
            for(typename SpMat<eT>::const_iterator it = begin; it.pos() < m.n_nonzero; ++it)
              {
              if(it.row() == row && it.col() == col)
                {
                val = *it;
                break;
                }
              }
            arma_ostream::print_elem(o,eT(val), modify);
            o << ' ';
            }

          o << '\n';
          }
        }
      }
    }
  else
    {
    if(m.n_elem == 0)
      {
      o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n";
      }
    else
      {
      eT tmp[1];
      tmp[0] = eT(0);
      
      const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, &tmp[0], 1) : o.width();
      
      for(uword row=0; row < m_n_rows; ++row)
        {
        for(uword col=0; col < m_n_cols; ++col)
          {
          o.width(cell_width);
          
          arma_ostream::print_elem_zero<eT>(o, modify);
          
          o << ' ';
          }
        
        o << '\n';
        }
      }
    }
  
  o.flush();
  stream_state.restore(o);
//.........这里部分代码省略.........
开发者ID:DASLaboratories,项目名称:Armadillo,代码行数:101,代码来源:arma_ostream_meat.hpp

示例2: eT

inline
std::streamsize
arma_ostream::modify_stream(std::ostream& o, typename SpMat<eT>::const_iterator begin, const uword n_elem, const typename arma_not_cx<eT>::result* junk)
  {
  arma_extra_debug_sigprint();
  arma_ignore(junk);

  o.unsetf(ios::showbase);
  o.unsetf(ios::uppercase);
  o.unsetf(ios::showpos);

  o.fill(' ');

  std::streamsize cell_width;

  bool use_layout_B  = false;
  bool use_layout_C  = false;

  for(typename SpMat<eT>::const_iterator it = begin; it.pos() < n_elem; ++it)
    {
    const eT val = *it;

    if(
      val >= eT(+100) ||
      ( (is_signed<eT>::value == true) && (val <= eT(-100)) ) ||
      ( (is_non_integral<eT>::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) ||
      ( (is_non_integral<eT>::value == true) && (is_signed<eT>::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) )
      )
      {
      use_layout_C = true;
      break;
      }

    if(
      (val >= eT(+10)) || ( (is_signed<eT>::value == true) && (val <= eT(-10)) )
      )
      {
      use_layout_B = true;
      }
    }

  if(use_layout_C == true)
    {
    o.setf(ios::scientific);
    o.setf(ios::right);
    o.unsetf(ios::fixed);
    o.precision(4);
    cell_width = 13;
    }
  else
  if(use_layout_B == true)
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 10;
    }
  else
    {
    o.unsetf(ios::scientific);
    o.setf(ios::right);
    o.setf(ios::fixed);
    o.precision(4);
    cell_width = 9;
    }
  
  return cell_width;
  }
开发者ID:DASLaboratories,项目名称:Armadillo,代码行数:69,代码来源:arma_ostream_meat.hpp


注:本文中的typenameSpMat::pos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。