gpt4 book ai didi

c++ - 在提升图中使用特征类型

转载 作者:太空狗 更新时间:2023-10-29 21:45:57 24 4
gpt4 key购买 nike

在向下图添加顶点时,我遇到了一些 Eigen 对齐问题:

#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 宏似乎可以胜任。但是,我仍然不明白为什么第一个代码没有运行。使用指针与其说是解决方案,不如说是补丁...

关于c++ - 在提升图中使用特征类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16429524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com