使用一个特征类型内提升图

Using a Eigen type inside boost graph

本文关键字:类型 特征 一个      更新时间:2023-10-16

我有一些特征对齐问题时,添加一个顶点到以下图:

#include <boost/graph/adjacency_list.hpp>
#include <Eigen/Eigen>
struct Vertex
{
   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
   Eigen::Affine3d T; // Here is the Fixed-size vectorizable Eigen object
};

struct aligned_listS { };
namespace boost 
{
  template <class ValueType>
  struct container_gen<aligned_listS, ValueType> 
  {
    typedef std::list<ValueType, Eigen::aligned_allocator<ValueType> > type;
  };
}
typedef boost::adjacency_list< boost::listS, aligned_listS, boost::directedS, Vertex> MyGraph;
int main(int, char*[])
{
   Vertex v;
   MyGraph g;
   boost::add_vertex(v, g);
   return 0;
}

在运行时,我有以下错误消息:

 /usr/local/include/eigen3/Eigen/src/Core/DenseStorage.h:56: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 16>::plain_array() [with T = double, int Size = 16, int MatrixOrArrayOptions = 0]: Assertion `(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.

似乎aligned_listS模板参数没有设置在合适的位置,或者我对齐的分配器没有很好地定义。所以我正在寻找一些关于如何使这个对齐的分配器正常工作的提示。

如果有帮助的话,下面是完整的gdb回溯:

#0  0xb7fdf1b2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0xb7d401df in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0xb7d43825 in __GI_abort () at abort.c:91
#3  0xb7d39085 in __assert_fail_base (fmt=0xb7e76c38 "%s%s%s:%u: %s%sAssertion `%s' failed.n%n", 
    assertion=0x804b324 "(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"", file=0x804b2ec "/usr/local/include/eigen3/Eigen/src/Core/DenseStorage.h", 
    line=56, 
    function=0x804b5e0 "Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 16>::plain_array() [with T = double, int Size = 16, int MatrixOrArrayOptions = 0]") at assert.c:94
#4  0xb7d39137 in __GI___assert_fail (
    assertion=0x804b324 "(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"", file=0x804b2ec "/usr/local/include/eigen3/Eigen/src/Core/DenseStorage.h", 
    line=56, 
    function=0x804b5e0 "Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 16>::plain_array() [with T = double, int Size = 16, int MatrixOrArrayOptions = 0]") at assert.c:103
#5  0x08049f1c in Eigen::internal::plain_array<double, 16, 0, 16>::plain_array() ()
#6  0x080499f1 in Eigen::DenseStorage<double, 16, 4, 4, 0>::DenseStorage() ()
#7  0x0804935a in Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 4, 0, 4, 4> >::PlainObjectBase() ()
#8  0x08048ec7 in Eigen::Matrix<double, 4, 4, 0, 4, 4>::Matrix() ()
#9  0x08049d71 in Eigen::Transform<double, 3, 2, 0>::Transform(Eigen::Transform<double, 3, 2, 0> const&) ()
#10 0x080496c0 in Vertex::Vertex(Vertex const&) ()
#11 0x080496e9 in boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config::seq_stored_vertex::seq_stored_vertex(Vertex const&) ()
#12 0x080491cc in boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config::stored_vertex::stored_vertex(Vertex const&) ()
#13 0x08048df3 in boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config::vertex_descriptor boost::add_vertex<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config, boost::directed_graph_helper<boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config> >(boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config::vertex_property_type const&, boost::adj_list_impl<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config, boost::directed_graph_helper<boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, aligned_listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>, aligned_listS, boost::listS, boost::directedS, Vertex, boost::no_property, boost::no_property, boost::listS>::config> >&) ()
#14 0x080489be in main ()

一种解决方法是使用以下图形定义:

typedef boost::adjacency_list< boost::listS, boost::listS, boost::directedS, boost::shared_ptr<Vertex> > MyGraph;

在这种情况下,这段代码不会生成断言。

   boost::shared_ptr<Vertex> ptr(new Vertex(v));
   boost::add_vertex(ptr, g);

在这种情况下,Eigen宏似乎可以完成任务。然而,我仍然不明白为什么第一个代码没有运行。使用指针更像是一个补丁而不是解决方案…