繁体   English   中英

C ++:如何使用boost :: multi_array数组

[英]C++:How to have an array of boost::multi_array

嗨,我有一些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 :: equal(other.shape(),other.shape()+ this-> num_dimensions(),this-> shape())'失败。

而且我不知道为什么?

我知道我可以只使用向量,但是为了论证,可以说我想拥有一个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指针,这也将节省大量副本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM