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


C++ tensor_type类代码示例

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


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

示例1: backward

    void Min::backward(const tensor_type& data_input, const tensor_type& gradient_output)
    {
      gradient_input.resizeLike(data_input);
      gradient_input.setZero();
      
      if (dimension) {
	for (int row = 0; row != data_input.rows(); ++ row)
	  gradient_input.row(row)[indices[row]] = gradient_output.col(0)[row];
      } else {
	for (int col = 0; col != data_input.cols(); ++ col)
	  gradient_input.col(col)[indices[col]] = gradient_output.col(0)[col];
      }
    }
开发者ID:hitochan777,项目名称:cicada,代码行数:13,代码来源:min.cpp

示例2: apply

    static void apply( const tensor_type & tensor ,
                       const MatrixValue * const a ,
                       const VectorValue * const x ,
                       VectorValue * const y )
    {

        const size_type nDim = tensor.dimension();

        // Loop over i
        for ( size_type i = 0; i < nDim; ++i) {
            VectorValue ytmp = 0;

            // Loop over k for this i
            const size_type nk = tensor.num_k(i);
            const size_type kBeg = tensor.k_begin(i);
            const size_type kEnd = kBeg + nk;
            for (size_type kEntry = kBeg; kEntry < kEnd; ++kEntry) {
                const size_type k = tensor.k_coord(kEntry);
                const MatrixValue ak = a[k];
                const VectorValue xk = x[k];

                // Loop over j for this i,k
                const size_type nj = tensor.num_j(kEntry);
                const size_type jBeg = tensor.j_begin(kEntry);
                const size_type jEnd = jBeg + nj;
                for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
                    const size_type j = tensor.j_coord(jEntry);
                    ytmp += tensor.value(jEntry) * ( a[j] * xk + ak * x[j] );
                }
            }

            y[i] += ytmp ;
        }
    }
开发者ID:,项目名称:,代码行数:34,代码来源:

示例3: apply

  KOKKOS_INLINE_FUNCTION
  static void apply( const tensor_type & tensor ,
                     const MatrixValue * const a ,
                     const VectorValue * const x ,
                           VectorValue * const y )
  {
    const size_type nk = tensor.num_k();

    // Loop over k
    for ( size_type k = 0; k < nk; ++k) {
      const MatrixValue ak = a[k];
      const VectorValue xk = x[k];

      // Loop over j for this k
      const size_type nj = tensor.num_j(k);
      const size_type jBeg = tensor.j_begin(k);
      const size_type jEnd = jBeg + nj;
      for (size_type jEntry = jBeg; jEntry < jEnd; ++jEntry) {
        const size_type j = tensor.j_coord(jEntry);
        VectorValue tmp = a[j] * xk + ak * x[j];

        // Loop over i for this k,j
        const size_type ni = tensor.num_i(jEntry);
        const size_type iBeg = tensor.i_begin(jEntry);
        const size_type iEnd = iBeg + ni;
        for (size_type iEntry = iBeg; iEntry < iEnd; ++iEntry) {
          const size_type i = tensor.i_coord(iEntry);
          y[i] += tensor.value(iEntry) * tmp;
        }
      }
    }
  }
开发者ID:agrippa,项目名称:Trilinos,代码行数:32,代码来源:Stokhos_FlatSparse3Tensor_kji.hpp

示例4: fill_from_file

void fill_from_file(tensor_type& tens, const std::string& str)
{
   std::ifstream ifs(str);
   for(int k = 0 ; k < tens.extent<2>(); ++k)
      for(int j = 0 ; j < tens.extent<1>(); ++j)
         for(int i = 0 ; i < tens.extent<0>(); ++i)
      {
         ifs >> tens.at(i,j,k);
      }
}
开发者ID:IanHG,项目名称:tensor_code_generator.spirit,代码行数:10,代码来源:main_libmda.cpp

示例5: operator

 void operator ()(const tensor_type &delta, const tensor_type &x, tensor_type &x_gradient) {
   CHECK_EQ(x.order(), delta.order());
   // TODO(robertsdionne): Support arbitrary tensor order with an n-dimensional iterator.
   for (auto i = 0; i < x.shape().at(0); ++i) {
     for (auto j = 0; j < x.shape().at(1); ++j) {
       x_gradient.set({i, j}, delta.at({i, j}) * (x.at({i, j}) > F(0)));
     }
   }
 }
开发者ID:robertsdionne,项目名称:sacred,代码行数:9,代码来源:rectified_linear_gradient.hpp

示例6: forward

    void SoftMax::forward(const tensor_type& data_input)
    {
      // use of redux for computing logsum...
      
      const double infty = - std::numeric_limits<double>::infinity();
      
      double logsum = infty;
      for (difference_type i = 0; i != data_input.rows(); ++ i) {
	const double value = data_input.col(0)[i];
	
	if (logsum == infty)
	  logsum = value;
	else if (value > infty) {
	  if (logsum >= value)
	    logsum = logsum + utils::mathop::log1p(std::exp(value - logsum));
	  else
	    logsum = value  + utils::mathop::log1p(std::exp(logsum - value));
	}
      }
      
      data_output = (data_input.array() - logsum).exp();
    }
开发者ID:hitochan777,项目名称:cicada,代码行数:22,代码来源:softmax.cpp

示例7: print

void print(const tensor_type& tens, const std::string& str)
{
   std::ofstream of(str);
   of << std::showpos;
   using limit_type = std::numeric_limits<typename tensor_type::value_type>;
   of << std::scientific;
   of << std::setprecision(limit_type::max_digits10);
   for(int k = 0 ; k < tens.extent<2>(); ++k)
      for(int j = 0 ; j < tens.extent<1>(); ++j)
         for(int i = 0 ; i < tens.extent<0>(); ++i)
      {
         of << tens.at(i,j,k) << std::endl;
      }
}
开发者ID:IanHG,项目名称:tensor_code_generator.spirit,代码行数:14,代码来源:main_libmda.cpp

示例8: operator

 void operator ()(const tensor_type &x, tensor_type &y) {
   using std::max;
   CHECK_EQ(x.order(), y.order());
   // TODO(robertsdionne): Support arbitrary tensor order with an n-dimensional iterator.
   for (auto i = 0; i < x.shape().at(0); ++i) {
     for (auto j = 0; j < x.shape().at(1); ++j) {
       y.set({i, j}, max(F(0), x.at({i, j})));
     }
   }
 }
开发者ID:robertsdionne,项目名称:sacred,代码行数:10,代码来源:rectified_linear.hpp

示例9: forward

    void Min::forward(const tensor_type& data_input)
    {
      if (dimension) {
	// select row and compute column-min
	data_output.resize(data_input.rows(), 1);
	indices.resize(data_input.rows());
	
	for (size_type row = 0; row != data_input.rows(); ++ row) {
	  int col_min = 0;
	  data_output.col(0)[row] = data_input.row(row).minCoeff(&col_min);
	  indices[row] = col_min;
	}
      } else {
	// select column and compute row-min!
	data_output.resize(data_input.cols(), 1);
	indices.resize(data_input.cols());
	
	for (size_type col = 0; col != data_input.cols(); ++ col) {
	  int row_min = 0;
	  data_output.col(0)[col] = data_input.col(col).minCoeff(&row_min);
	  indices[col] = row_min;
	}
      }
    }
开发者ID:hitochan777,项目名称:cicada,代码行数:24,代码来源:min.cpp

示例10: matrix_size

 static size_type matrix_size( const tensor_type & tensor )
 {
     return tensor.dimension();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:

示例11: vector_size

 KOKKOS_INLINE_FUNCTION
 static size_type vector_size( const tensor_type & tensor )
 { return tensor.dimension(); }
开发者ID:agrippa,项目名称:Trilinos,代码行数:3,代码来源:Stokhos_FlatSparse3Tensor_kji.hpp

示例12: forward

 void Exp::forward(const tensor_type& data_input)
 {
   data_output = data_input.array().exp();
 }
开发者ID:hitochan777,项目名称:cicada,代码行数:4,代码来源:exp.cpp

示例13: backward

 void Exp::backward(const tensor_type& data_input, const tensor_type& gradient_output)
 {
   gradient_input.array() = gradient_output.array() * data_output.array();
 }
开发者ID:hitochan777,项目名称:cicada,代码行数:4,代码来源:exp.cpp

示例14: backward

 void Log::backward(const tensor_type& data_input, const tensor_type& gradient_output)
 {
   gradient_input = data_input.array() / gradient_output.array();
 }
开发者ID:hitochan777,项目名称:cicada,代码行数:4,代码来源:log.cpp

示例15: vector_size

 static size_type vector_size( const tensor_type & tensor )
 {
     return tensor.dimension();
 }
开发者ID:,项目名称:,代码行数:4,代码来源:


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