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


C++ MatrixT::handle2方法代码示例

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


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

示例1: diff

NumericT diff(std::vector<std::map<IndexT, NumericT> > const & stl_A,
              MatrixT & vcl_A)
{
  viennacl::switch_memory_context(vcl_A, viennacl::context(viennacl::MAIN_MEMORY));

  NumericT error = NumericT(-1.0);

  NumericT     const * vcl_A_elements   = viennacl::linalg::host_based::detail::extract_raw_pointer<NumericT>(vcl_A.handle());
  unsigned int const * vcl_A_row_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(vcl_A.handle1());
  unsigned int const * vcl_A_col_buffer = viennacl::linalg::host_based::detail::extract_raw_pointer<unsigned int>(vcl_A.handle2());


  /* Simultaneously compare the sparsity patterns of both matrices against each other. */

  unsigned int const * vcl_A_current_col_ptr = vcl_A_col_buffer;
  NumericT     const * vcl_A_current_val_ptr = vcl_A_elements;

  for (std::size_t row = 0; row < stl_A.size(); ++row)
  {
    if (vcl_A_current_col_ptr != vcl_A_col_buffer + vcl_A_row_buffer[row])
    {
      std::cerr << "Sparsity pattern mismatch detected: Start of row out of sync!" << std::endl;
      std::cerr << " STL row: " << row << std::endl;
      std::cerr << " ViennaCL col ptr is: " << vcl_A_current_col_ptr << std::endl;
      std::cerr << " ViennaCL col ptr should: " << vcl_A_col_buffer + vcl_A_row_buffer[row] << std::endl;
      std::cerr << " ViennaCL col ptr value: " << *vcl_A_current_col_ptr << std::endl;
      return NumericT(1.0);
    }

    //std::cout << "Row " << row_it.index1() << ": " << std::endl;
    for (typename std::map<IndexT, NumericT>::const_iterator col_it = stl_A[row].begin();
          col_it != stl_A[row].end();
          ++col_it, ++vcl_A_current_col_ptr, ++vcl_A_current_val_ptr)
    {
      if (col_it->first != std::size_t(*vcl_A_current_col_ptr))
      {
        std::cerr << "Sparsity pattern mismatch detected!" << std::endl;
        std::cerr << " STL row: " << row << std::endl;
        std::cerr << " STL col: " << col_it->first << std::endl;
        std::cerr << " ViennaCL row entries: " << vcl_A_row_buffer[row] << ", " << vcl_A_row_buffer[row + 1] << std::endl;
        std::cerr << " ViennaCL entry in row: " << vcl_A_current_col_ptr - (vcl_A_col_buffer + vcl_A_row_buffer[row]) << std::endl;
        std::cerr << " ViennaCL col: " << *vcl_A_current_col_ptr << std::endl;
        return NumericT(1.0);
      }

      // compute relative error (we know for sure that the uBLAS matrix only carries nonzero entries:
      NumericT current_error = std::fabs(col_it->second - *vcl_A_current_val_ptr) / std::max(std::fabs(col_it->second), std::fabs(*vcl_A_current_val_ptr));

      if (current_error > 0.1)
      {
        std::cerr << "Value mismatch detected!" << std::endl;
        std::cerr << " STL row: " << row << std::endl;
        std::cerr << " STL col: " << col_it->first << std::endl;
        std::cerr << " STL value: " << col_it->second << std::endl;
        std::cerr << " ViennaCL value: " << *vcl_A_current_val_ptr << std::endl;
        return NumericT(1.0);
      }

      if (current_error > error)
        error = current_error;
    }
  }

  return error;
}
开发者ID:Rombur,项目名称:viennacl-dev,代码行数:65,代码来源:sparse_prod.cpp


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