C :如何拥有一个boost :: multi_array数组

C++:How to have an array of boost::multi_array

本文关键字:array 数组 multi 有一个 何拥 boost      更新时间:2023-10-16

嗨,我有一些boost :: multi_array定义如下:

typedef boost::multi_array<double, 3> region_prior_integral_image

我试图创建一个region_prior_integral_image的数组,如以下内容:

unordered_map<string, int> filename_to_hash_key_map = get_filename_to_hash_key_map();
unordered_map<string, region_prior_integral_image> filename_to_region_prior_map = get_region_prior_integral_images();
region_prior_integral_image* image_cache = new region_prior_integral_image[5];
for(unordered_map<string, int>::iterator it = filename_to_hash_key_map.begin(); it != filename_to_hash_key_map.end(); it++){
    image_cache[it->second] = filename_to_region_prior_map[it->first];
}

但是,该程序终止以下内容: SemanticTextonForest: /home/aly/libs/boost_1_51_0/stage/include/boost/multi_array/multi_array_ref.hpp:488: boost::multi_array_ref<T, NumDims>& boost::multi_array_ref<T, NumDims>::operator=(const ConstMultiArray&) [with ConstMultiArray = boost::multi_array<double, 3ul>, T = double, long unsigned int NumDims = 3ul, boost::multi_array_ref<T, NumDims> = boost::multi_array_ref<double, 3ul>]: Assertion std :: qualie(shopshape(),other.shape() this-> num_dimensions(),this-> shape())'失败。P>

我不知道为什么?

我知道我只能使用矢量,但是出于争论,请说我想拥有一系列region_prior_integral_images

谢谢

假设我们有两个region_prior_integral_image实例:A和B。如果要将B分配给A,例如A = B;AB的形状必须相等。错误消息说,在您的代码image_cache[it->second] = filename_to_region_prior_map[it->first];中,两个数组的形状不同。

您如何在filename_to_region_prior_map中创建数组?我想您使用此构造函数来指定形状:multi_array<double,3> B(boost::extents[i][j][k])。因此它们的形状为[i][j][k]。但是,当您创建image_cache时,会调用默认构造函数。所以两个形状不匹配。

我的看法是将region_prior_integral_image的指针存储在您的代码中,这也可以节省很多副本。