• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ vector_type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Multiply

  Multiply( const matrix_type & A ,
            const size_type nrow ,
            const size_type ncol ,
            const vector_type & x ,
            const vector_type & y )
  {
    CudaSparseSingleton & s = CudaSparseSingleton::singleton();
    const scalar_type alpha = 1 , beta = 0 ;

    cusparseStatus_t status =
      cusparseScsrmv( s.handle ,
                      CUSPARSE_OPERATION_NON_TRANSPOSE ,
                      nrow , ncol , A.coefficients.dimension_0() ,
                      &alpha ,
                      s.descra ,
                      A.coefficients.ptr_on_device() ,
                      A.graph.row_map.ptr_on_device() ,
                      A.graph.entries.ptr_on_device() ,
                      x.ptr_on_device() ,
                      &beta ,
                      y.ptr_on_device() );

    if ( CUSPARSE_STATUS_SUCCESS != status ) {
      throw std::runtime_error( std::string("ERROR - cusparseDcsrmv " ) );
    }
  }
开发者ID:ProgramFan,项目名称:kokkos,代码行数:26,代码来源:SparseLinearSystem.hpp


示例2: compareRank1

bool compareRank1(const vector_type& y,
                          const vector_type& y_exp,
                          const scalar_type rel_tol,
                          const scalar_type abs_tol,
                          Teuchos::FancyOStream& out)
{
  typedef typename vector_type::size_type size_type;
  typename vector_type::HostMirror hy = Kokkos::create_mirror_view(y);
  typename vector_type::HostMirror hy_exp = Kokkos::create_mirror_view(y_exp);
  Kokkos::deep_copy(hy, y);
  Kokkos::deep_copy(hy_exp, y_exp);

  size_type num_rows = y.dimension_0();
  bool success = true;
  for (size_type i=0; i<num_rows; ++i) {
    for (size_type j=0; j<y.sacado_size(); ++j) {
      scalar_type diff = std::abs( hy(i).fastAccessCoeff(j) - hy_exp(i).fastAccessCoeff(j) );
      scalar_type tol = rel_tol*std::abs(hy_exp(i).fastAccessCoeff(j)) + abs_tol;
      bool s = diff < tol;
      out << "y_expected(" << i << ").coeff(" << j << ") - "
          << "y(" << i << ").coeff(" << j << ") = " << hy_exp(i).fastAccessCoeff(j)
          << " - " << hy(i).fastAccessCoeff(j) << " == "
          << diff << " < " << tol << " : ";
      if (s)
        out << "passed";
      else
        out << "failed";
      out << std::endl;
      success = success && s;
    }
  }
  return success;
}
开发者ID:,项目名称:,代码行数:33,代码来源:


示例3: apply

  static void apply( const matrix_type & A ,
                     const vector_type & x ,
                     const vector_type & y )
  {
    CudaSparseSingleton & s = CudaSparseSingleton::singleton();
    const double alpha = 1 , beta = 0 ;
    const int n = A.graph.row_map.dimension_0() - 1 ;
    const int nz = A.graph.entries.dimension_0();

    cusparseStatus_t status =
      cusparseDcsrmv( s.handle ,
                      CUSPARSE_OPERATION_NON_TRANSPOSE ,
                      n , n , nz ,
                      &alpha ,
                      s.descra ,
                      A.values.ptr_on_device() ,
                      A.graph.row_map.ptr_on_device() ,
                      A.graph.entries.ptr_on_device() ,
                      x.ptr_on_device() ,
                      &beta ,
                      y.ptr_on_device() );

    if ( CUSPARSE_STATUS_SUCCESS != status ) {
      throw std::runtime_error( std::string("ERROR - cusparseDcsrmv " ) );
    }
  }
开发者ID:gitter-badger,项目名称:quinoa,代码行数:26,代码来源:Stokhos_Cuda_CrsMatrix.hpp


示例4: prod

 void prod( sparse_matrix_type const& A,
            vector_type const& x,
            vector_type& b ) const
 {
     int ierr = 0;
     petsc_sparse_matrix_type const& _A = dynamic_cast<petsc_sparse_matrix_type const&>( A );
     petsc_vector_type const& _x = dynamic_cast<petsc_vector_type const&>( x );
     petsc_vector_type const& _b = dynamic_cast<petsc_vector_type const&>( b );
     if ( _A.mapCol().worldComm().globalSize() == x.map().worldComm().globalSize() )
     {
         //std::cout << "BackendPetsc::prod STANDART"<< std::endl;
         ierr = MatMult( _A.mat(), _x.vec(), _b.vec() );
         CHKERRABORT( _A.comm().globalComm(),ierr );
     }
     else
     {
         //std::cout << "BackendPetsc::prod with convert"<< std::endl;
         auto x_convert = petscMPI_vector_type(_A.mapColPtr());
         x_convert.duplicateFromOtherPartition(x);
         x_convert.close();
         ierr = MatMult( _A.mat(), x_convert.vec(), _b.vec() );
         CHKERRABORT( _A.comm().globalComm(),ierr );
     }
     b.close();
 }
开发者ID:TrojanXu,项目名称:feelpp,代码行数:25,代码来源:backendpetsc.hpp


示例5: checksum

unsigned_type checksum(vector_type& input)
{
    unsigned_type sum = 0;
    for (vector_type::const_iterator i = input.begin(); i != input.end(); ++i)
        sum += (unsigned_type)((*i).m_key);
    return sum;
}
开发者ID:RobertoMalatesta,项目名称:stxxl,代码行数:7,代码来源:test_parallel_sort.cpp


示例6: sumIntoGlobalValue

    /*!
     * \brief Sum a value into existing value at the global row index. The
     * global index must exist on process.
     */
    static void sumIntoGlobalValue( vector_type& vector,
    				    global_ordinal_type global_row,
    				    const scalar_type& value )
    {
	MCLS_REQUIRE( vector.getMap()->isNodeGlobalElement( global_row ) );
	vector.sumIntoGlobalValue( global_row, value );
    }
开发者ID:sslattery,项目名称:MCLS,代码行数:11,代码来源:MCLS_TpetraVectorAdapter.hpp


示例7: sumIntoLocalValue

    /*!
     * \brief Sum a value into existing value at the local row index. The
     * local index must exist on process.
     */
    static void sumIntoLocalValue( vector_type& vector,
    				   local_ordinal_type local_row,
    				   const scalar_type& value )
    {
	MCLS_REQUIRE( vector.getMap()->isNodeLocalElement( local_row ) );
	vector.sumIntoLocalValue( local_row, value );
    }
开发者ID:sslattery,项目名称:MCLS,代码行数:11,代码来源:MCLS_TpetraVectorAdapter.hpp


示例8: simulate

	public: vector_type simulate(vector_type const& u, vector_type const& e, real_type na_value = real_type(0)) const
	{
		namespace ublas = ::boost::numeric::ublas;
		namespace ublasx = ::boost::numeric::ublasx;

		size_type n_obs = u.size();
		size_type n_e = e.size();

		DCS_ASSERT(
			n_obs == n_e,
			throw ::std::logic_error("Size of Input Data and Noise Data does not match.")
		);

		size_type n_a = ublasx::size(a_); // # of output channels
		size_type n_b = ublasx::size(b_); // # of input channels
		size_type k_min = 0;
		size_type k_max = n_obs - ::std::min(static_cast<size_type>(d_*ts_), n_obs);

		vector_type y(n_obs, na_value);

//		for (size_type k = 0; k < k_min; ++k)
//		{
//			y(k) = e_var_*e(k);
//		}
		for (size_type k = k_min; k < k_max; ++k)
		{
			y(k) = 0;

			if (n_a > 0 && k > 0)
			{
				size_type nn_a = ::std::min(n_a, k);

				y(k) -=	ublas::inner_prod(
						//a_,
						ublas::subrange(a_, 0, nn_a),
						//::dcs::math::la::subslice(y, k-1, -1, n_a)
						ublas::subslice(y, k-1, -1, nn_a)
					);
			}

			if (n_b > 0)
			{
				size_type nn_b = ::std::min(n_b, k+1);

				y(k) += ublas::inner_prod(
						//b_,
						ublas::subrange(b_, 0, nn_b),
						//::dcs::math::la::subslice(u, k, -1, n_b)
						ublas::subslice(u, k, -1, nn_b)
					);
			}

			y(k) += e_var_*e(k);
		}

		return y;
	}
开发者ID:sguazt,项目名称:dcsxx-sysid,代码行数:57,代码来源:darx_siso.hpp


示例9: find_id

 typename vector_type::const_iterator find_id(const TId id) const noexcept {
     const element_type element {
         id,
         osmium::index::empty_value<TValue>()
     };
     return std::lower_bound(m_vector.begin(), m_vector.end(), element, [](const element_type& a, const element_type& b) {
         return a.first < b.first;
     });
 }
开发者ID:alex85k,项目名称:osm2pgsql,代码行数:9,代码来源:vector_map.hpp


示例10: Reflector

matrix_type Reflector(const vector_type& x)
{
    using namespace boost::numeric::ublas;

    matrix_type F(x.size(), x.size());

    Reflector<matrix_type, vector_type>(x, F);

    return F;
}
开发者ID:mobiusklein,项目名称:mzR,代码行数:10,代码来源:qr.hpp


示例11: setBounds

    void setBounds( vector_type const& __lb, vector_type const& __up )
    {
        GST_SMART_ASSERT( __lb.size() == __up.size() )( __lb )( __up )( "inconsistent bounds definition" );
        M_lb = __lb;
        M_ub = __up;
        M_lb_ub = __up - __lb;

        GST_SMART_ASSERT( *std::min_element( M_lb_ub.begin(), M_lb_ub.end() ) >= 0 )
        ( M_lb )( M_ub )( "lower and upper bounds are not properly defined" );
    }
开发者ID:TrojanXu,项目名称:feelpp,代码行数:10,代码来源:dirscalingmatrix.hpp


示例12: decorated_tuple

    decorated_tuple(cow_pointer_type d, const vector_type& v)
        : super(tuple_impl_info::statically_typed)
        , m_decorated(std::move(d)), m_mapping(v) {
#       ifdef CPPA_DEBUG
        const cow_pointer_type& ptr = m_decorated; // prevent detaching
#       endif
        CPPA_REQUIRE(ptr->size() >= sizeof...(ElementTypes));
        CPPA_REQUIRE(v.size() == sizeof...(ElementTypes));
        CPPA_REQUIRE(*(std::max_element(v.begin(), v.end())) < ptr->size());
    }
开发者ID:alepharchives,项目名称:libcppa,代码行数:10,代码来源:decorated_tuple.hpp


示例13: test_vector_magnitude

/**
 * @test Test MaRC::Vector magnitude (norm) calculation.
 */
bool test_vector_magnitude()
{
    using vector_type = MaRC::Vector<int, 3>;
    vector_type const v{ 3, 4, 5 };

    double const mag =
        std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);

    return MaRC::almost_equal(v.magnitude(), mag, ulps);
}
开发者ID:ossama-othman,项目名称:MaRC,代码行数:13,代码来源:Vector_Test.cpp


示例14: rhsVectorPtr

// ===================================================
// Methods
// ===================================================
Int
SolverAztecOO::solve ( vector_type& solution, const vector_type& rhs )
{
    M_solver.SetLHS ( &solution.epetraVector() );
    // The Solver from Aztecoo takes a non const (because of rescaling?)
    // We should be careful if you use scaling
    Epetra_FEVector* rhsVectorPtr ( const_cast<Epetra_FEVector*> (&rhs.epetraVector() ) );
    M_solver.SetRHS ( rhsVectorPtr );

    Int  maxiter (M_maxIter);
    Real mytol  (M_tolerance);
    Int status;

    if ( isPreconditionerSet() && M_preconditioner->preconditionerType().compare ("AztecOO") )
    {
        M_solver.SetPrecOperator (M_preconditioner->preconditioner() );
    }

    status = M_solver.Iterate (maxiter, mytol);

#ifdef HAVE_LIFEV_DEBUG
    M_displayer->comm()->Barrier();
    M_displayer->leaderPrint ( "  o-  Number of iterations = ", M_solver.NumIters() );
    M_displayer->leaderPrint ( "  o-  Norm of the true residual = ", M_solver.TrueResidual() );
    M_displayer->leaderPrint ( "  o-  Norm of the true ratio    = ",  M_solver.ScaledResidual() );
#endif

    /* try to solve again (reason may be:
      -2 "Aztec status AZ_breakdown: numerical breakdown"
      -3 "Aztec status AZ_loss: loss of precision"
      -4 "Aztec status AZ_ill_cond: GMRES hessenberg ill-conditioned"
    */
    if ( status <= -2 )
    {
        maxiter     = M_maxIter;
        mytol       = M_tolerance;
        Int oldIter = M_solver.NumIters();
        status      = M_solver.Iterate (maxiter, mytol);

#ifdef HAVE_LIFEV_DEBUG
        M_displayer->comm()->Barrier();
        M_displayer->leaderPrint ( "  o-  Second run: number of iterations = ", M_solver.NumIters() );
        M_displayer->leaderPrint ( "  o-  Norm of the true residual = ",  M_solver.TrueResidual() );
        M_displayer->leaderPrint ( "  o-  Norm of the true ratio    = ",  M_solver.ScaledResidual() );
#endif
        return ( M_solver.NumIters() + oldIter );
    }

    return ( M_solver.NumIters() );
}
开发者ID:chknipp,项目名称:lifev,代码行数:53,代码来源:SolverAztecOO.cpp


示例15: Ax

Real
SolverAztecOO::computeResidual ( vector_type& solution, vector_type& rhs )
{
    vector_type Ax ( solution.map() );
    vector_type res ( rhs );

    M_solver.GetUserMatrix()->Apply ( solution.epetraVector(), Ax.epetraVector() );

    res.epetraVector().Update ( 1, Ax.epetraVector(), -1 );

    Real residual;

    res.norm2 ( &residual );

    return residual;
}
开发者ID:chknipp,项目名称:lifev,代码行数:16,代码来源:SolverAztecOO.cpp


示例16: tic

int
PreconditionerBlockMS<space_type>::applyInverse ( const vector_type& X, vector_type& Y ) const
{
    tic();
    U = X;
    U.close();
    *M_uin = U.template element<0>();
    M_uin->close();
    *M_pin = U.template element<1>();
    M_pin->close();

    // Solve eq (12)
    // solve here eq 15 : Pm v = c
    backend(_name=M_prefix_11)->solve(_matrix=M_11,
                                      _rhs=M_uin,
                                      _solution=M_uout
                                     ) ;
    M_uout->close();

    // solve here eq 16
    backend(_name=M_prefix_22)->solve(_matrix=M_L,
                                      _rhs=M_pin,
                                      _solution=M_pout
                                     );
    M_pout->close();

    U.template element<0>() = *M_uout;
    U.template element<1>() = *M_pout;
    U.close();
    Y=U;
    Y.close();
    toc("[PreconditionerBlockMS] applyInverse update solution",FLAGS_v>0);
    return 0;
}
开发者ID:MarieHouillon,项目名称:feelpp,代码行数:34,代码来源:preconditionerblockms.hpp


示例17: uniform_signal_generator

	public: uniform_signal_generator(vector_type const& u_min, vector_type const& u_max, random_generator_type& rng)
	: rng_(rng),
	  ub_( ::std::numeric_limits<value_type>::infinity()),
	  lb_(-::std::numeric_limits<value_type>::infinity())
	{
		// pre: size(u_min) == size(u_max)
		DCS_ASSERT(u_min.size() == u_max.size(),
				   DCS_EXCEPTION_THROW(::std::invalid_argument,
									   "Size of min and max vectors does not match"));

		::std::size_t n(u_min.size());
		for (::std::size_t i = 0; i < n; ++i)
		{
			distrs_.push_back(uniform_distribution_type(u_min[i], u_max[i]));
		}
	}
开发者ID:sguazt,项目名称:dcsxx-testbed,代码行数:16,代码来源:uniform_signal_generator.hpp


示例18: deepCopy

    /*!
     * \brief Create a deep copy of the provided vector and return a
     * reference-counted pointer.
     */
    static Teuchos::RCP<vector_type> deepCopy( const vector_type& vector )
    {
	Teuchos::RCP<vector_type> vector_copy = clone( vector );
	Teuchos::ArrayRCP<Scalar> copy_view = vector_copy->getDataNonConst();
	copy_view.deepCopy( vector.getData()() );
	return vector_copy;
    }
开发者ID:sslattery,项目名称:MCLS,代码行数:11,代码来源:MCLS_TpetraVectorAdapter.hpp


示例19: apply

  static void apply( const value_type&   alpha ,
		     const vector_type & x ,
		     const value_type &  beta ,
                     const vector_type & y )
  {
    const size_t row_count = x.dimension_0() ;
    parallel_for( row_count , Update(alpha,x,beta,y) );
  }
开发者ID:00liujj,项目名称:trilinos,代码行数:8,代码来源:Kokkos_Multiply.hpp


示例20: recv

  void recv( const vector_type & v )
  {
    const size_t recv_msg_count = m_recv_request.size();
    const std::pair<unsigned,unsigned> recv_range( m_map.count_owned , m_map.count_owned + m_map.count_receive );

    const vector_type vrecv = subview<vector_type>( v , recv_range );

    // Wait for receives and verify:

    for ( size_t i = 0 ; i < recv_msg_count ; ++i ) {
      MPI_Status recv_status ;
      int recv_which = 0 ;
      int recv_size  = 0 ;

      MPI_Waitany( recv_msg_count , & m_recv_request[0] , & recv_which , & recv_status );

      const int recv_proc = recv_status.MPI_SOURCE ;

      MPI_Get_count( & recv_status , MPI_BYTE , & recv_size );

      // Verify message properly received:

      const int  expected_proc = m_map.host_recv(recv_which,0);
      const int  expected_size = m_map.host_recv(recv_which,1) *
                                 m_chunk * sizeof(scalar_type);

      if ( ( expected_proc != recv_proc ) ||
           ( expected_size != recv_size ) ) {
        std::ostringstream msg ;
        msg << "MatrixMultiply communication error:"
            << " P" << comm::rank( m_map.machine )
            << " received from P" << recv_proc
            << " size "     << recv_size
            << " expected " << expected_size
            << " from P"    << expected_proc ;
        throw std::runtime_error( msg.str() );
      }
    }

    // Copy received data to device memory.

    Impl::DeepCopy<typename Device::memory_space,HostSpace>( vrecv.ptr_on_device() ,
                                                             m_host_recv_buffer.ptr_on_device() ,
                                                             m_map.count_receive * m_chunk * sizeof(scalar_type) );
  }
开发者ID:00liujj,项目名称:trilinos,代码行数:45,代码来源:TestSparseLinearSystem.hpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ vector_vec3d类代码示例发布时间:2022-05-31
下一篇:
C++ vector_t类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap