本文介绍了使用CWiseNullaryOp扩展本征:无法重现示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试在Eigen文档的上重现第二个示例,但无法编译我的最小程序。我正在使用Eigen 3.3〜beta1-2。

I am trying to reproduce the second example on this page of the Eigen documentation, but cannot compile my minimal program. I am using Eigen 3.3~beta1-2.

在使用以下参数运行g ++时 -std = c ++ 11 -Wall -pipe- O3-快速数学-有趣的安全数学优化-march = native -mtune = native -pedantic -Wno-unused-variable -I / usr / local / include / eigen3 -I / usr / include / eigen3 -c example.cpp ,出现此错误:

When running g++ with the following arguments -std=c++11 -Wall -pipe -O3 -ffast-math -funsafe-math-optimizations -march=native -mtune=native -pedantic -Wno-unused-variable -I/usr/local/include/eigen3 -I/usr/include/eigen3 -c example.cpp, I get this error:

example.cpp:8:41 ("Eigen::MatrixXi B = indexing(A, ri, ci)" in program below)
/usr/include/eigen3/Eigen/src/Core/CoreEvaluators.h:348:27: error: no match for call to '(const indexing_functor<Eigen::Matrix<int, -1, -1>, Eigen::Array<int, 3, 1>, Eigen::Array<int, -1, 1> >) (Eigen::Index&)
      return m_functor(index);

我的最小程序包含以下内容(基本上是从文档中的示例复制并粘贴):

My minimal program consists of the following (essentially copy and pasted from the example in the documentation):

example.h

#include <iostream>
#include <stdio.h>
#include <Eigen/Core>

using namespace Eigen;

template<class ArgType, class RowIndexType, class ColIndexType>
class indexing_functor {
  const ArgType &m_arg;
  const RowIndexType &m_rowIndices;
  const ColIndexType &m_colIndices;
public:
  typedef Matrix<typename ArgType::Scalar,
                 RowIndexType::SizeAtCompileTime,
                 ColIndexType::SizeAtCompileTime,
                 ArgType::Flags&RowMajorBit?RowMajor:ColMajor,
                 RowIndexType::MaxSizeAtCompileTime,
                 ColIndexType::MaxSizeAtCompileTime> MatrixType;
  indexing_functor(const ArgType& arg, const RowIndexType& row_indices, const ColIndexType& col_indices)
    : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices)
  {}
  const typename ArgType::Scalar& operator() (Index row, Index col) const {
    return m_arg(m_rowIndices[row], m_colIndices[col]);
  }
};

template <class ArgType, class RowIndexType, class ColIndexType>
CwiseNullaryOp<indexing_functor<ArgType,RowIndexType,ColIndexType>, typename indexing_functor<ArgType,RowIndexType,ColIndexType>::MatrixType>
indexing(const Eigen::MatrixBase<ArgType>& arg, const RowIndexType& row_indices, const ColIndexType& col_indices)
{
  typedef indexing_functor<ArgType,RowIndexType,ColIndexType> Func;
  typedef typename Func::MatrixType MatrixType;
  return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices));
}

example.cpp

#include "example.h"

int main()
{
  Eigen::MatrixXi A = Eigen::MatrixXi::Random(4,4);
  Array3i ri(1,2,1);
  ArrayXi ci(6); ci << 3,2,1,0,0,2;
  Eigen::MatrixXi B = indexing(A, ri, ci);
  std::cout << "A =" << std::endl;
  std::cout << A << std::endl << std::endl;
  std::cout << "A([" << ri.transpose() << "], [" << ci.transpose() << "]) =" << std::endl;
  std::cout << B << std::endl;
}

我缺少关于模板在C ++中如何工作的基本知识吗?

Am I missing something fundamental about how templates work in C++?

推荐答案

我确定必须具有重大变化,或者在某种程度上缺乏对此扩展程序的支持。使用最新的标头时,该程序可以运行。

I've determined that the Ubuntu release for Eigen 3.3~beta1-2 must have a breaking change, or lack support for this extension in some way. The program works when using the latest headers.

这篇关于使用CWiseNullaryOp扩展本征:无法重现示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:55