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


C++ mat::is_empty方法代码示例

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


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

示例1: Evaluate

void RNN<
LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction
>::Gradient(const arma::mat& /* unused */,
            const size_t i,
            arma::mat& gradient)
{
  if (gradient.is_empty())
  {
    gradient = arma::zeros<arma::mat>(parameter.n_rows, parameter.n_cols);
  }
  else
  {
    gradient.zeros();
  }

  Evaluate(parameter, i, false);

  arma::mat currentGradient = arma::mat(gradient.n_rows, gradient.n_cols);
  NetworkGradients(currentGradient, network);

  const arma::mat input = arma::mat(predictors.colptr(i), predictors.n_rows,
      1, false, true);

  // Iterate through the input sequence and perform the feed backward pass.
  for (seqNum = seqLen - 1; seqNum >= 0; seqNum--)
  {
    // Load the network activation for the upcoming backward pass.
    LoadActivations(input.rows(seqNum * inputSize, (seqNum + 1) *
        inputSize - 1), network);

    // Perform the backward pass.
    if (seqOutput)
    {
      arma::mat seqError = error.unsafe_col(seqNum);
      Backward(seqError, network);
    }
    else
    {
      Backward(error, network);
    }

    // Link the parameters and update the gradients.
    LinkParameter(network);
    UpdateGradients<>(network);

    // Update the overall gradient.
    gradient += currentGradient;

    if (seqNum == 0) break;
  }
}
开发者ID:AmesianX,项目名称:mlpack,代码行数:51,代码来源:rnn_impl.hpp

示例2: new_interior_indices

std::vector<int> HighOrderMeshGenerator::
insertNewNodes(const unique_element_ptr& el,
	       const arma::mat& newelnodes,
	       const arma::mat& parametric_coords,
	       int order){

  const int type = el->getElementType();

  const NodeIndexer* ni_old = 
    index_factory->getNodeIndexer(type,el->getOrder());

  const NodeIndexer* ni_new = 
    index_factory->getNodeIndexer(type,order);
  
  std::vector<int> newnode_indices(ni_new->Ndof(),-1);
  const std::vector<indtype>& corner_new = ni_new->getCornerNodes();
  
  const gind* old_nodes = el->getNodes();
  const std::vector<indtype>& corner_old = ni_old->getCornerNodes();
  
  for(int i = 0; i < el->numCornerNodes(); i++){
    //std::cout << "corner node: " << corner_new[i] << " " << 
    //  corner_old[i] << std::endl;
    newnode_indices[corner_new[i]] = old_nodes[corner_old[i]];
  }
 


    //std::cout << el->getDim() << std::endl;
  for(int ch = 0; ch < el->NumChildren(); ch++){
    const MEl* child_old = el->getChild(ch);
    if(el->getDim() > 1) assert(child_old);
    if(child_old){
      //int child_dim = child_old->getDim();
      auto child_it = elmap[el->getDim()-1].find(child_old);
      assert(child_it != elmap[el->getDim()-1].end());
   
      const MEl* child_new = child_it->second;
      const gind* child_nodes = child_new->getNodes();
      int orient = el->getChildOrientation(ch);
      
      const std::vector<indtype>& child_node_indices = 
	ni_new->getChildNodes(ch);

      const NodeIndexer* ni_child =
	index_factory->getNodeIndexer(child_new->getElementType(),
				      child_new->getOrder());

      const std::vector<indtype>& orient_indices = 
	ni_child->getOrientedNodes(orient);
      assert(child_node_indices.size() == child_new->NumNodes());
      for(int nd = 0; nd < child_new->NumNodes(); nd++){
	newnode_indices[child_node_indices[nd]] = 
	  child_nodes[orient_indices[nd]];
      }
    }
  } // end child loop

  
  // delete the old interior nodes from map
  
  const std::vector<indtype>& old_interior_indices = ni_old->getInteriorNodes();
  for(int i = 0; i < old_interior_indices.size(); i++){
    meshcurr->getNodesNC().erase(old_nodes[old_interior_indices[i]]);
  }
  

  // insert new nodes into node map
  //std::cout << "ni_new type: " << ni_new->getType() << std::endl;
  //arma::uvec new_interior_indices;
  //std::cout << "el type: " << el->getElementType() << std::endl;
  arma::uvec new_interior_indices(ni_new->getInteriorNodes());
  //std::cout << "h3.1" << std::endl;
  //std::cout << new_interior_indices << std::endl;
  //std::cout << newelnodes << std::endl;
  arma::mat new_interior_nodes = newelnodes.cols(new_interior_indices);
  //std::cout << "h3.2" << std::endl;
  //std::cout << new_interior_indices << std::endl;
  //std::cout << parametric_coords << std::endl;
  arma::mat new_interior_parametric_coords;
  if(!parametric_coords.is_empty()){
    new_interior_parametric_coords = 
      parametric_coords.cols(new_interior_indices);
  }

  //std::cout << "h4" << std::endl;

  nodeFactory* node_factory = nodeFactory::Instance();

  int node_type = 3;
  if(el->hasGeoEntity()) node_type = el->getGeoType()+1;
     
  //std::cout << new_interior_nodes << std::endl;

  if(el->getElementType() == 1){
    //std::cout << el->getGeoType() << std::endl;
    //if(!el->hasGeoEntity()) std::cout << "Line does not have a geo entity!" << std::endl;
  }
  for(int i = 0; i < new_interior_indices.size(); i++){
    double uv[2];
//.........这里部分代码省略.........
开发者ID:Nasrollah,项目名称:MeshOpt,代码行数:101,代码来源:HighOrderMeshGenerator.cpp


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