[英]C++:How to have an array of boost::multi_array
Hi I have a few boost::multi_array defined as below: 嗨,我有一些boost :: multi_array定义如下:
typedef boost::multi_array<double, 3> region_prior_integral_image
I am trying to create an array of region_prior_integral_image
like the following: 我正在尝试创建一个
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];
}
However the program is terminating with the following: 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())' failed.` 但是,该程序以以下内容终止:
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())'失败。
And I have no idea why? 而且我不知道为什么?
I know I could just use a vector, but for arguments sake lets say I wanted to have an array of region_prior_integral_images 我知道我可以只使用向量,但是为了论证,可以说我想拥有一个region_prior_integral_images数组
Thanks 谢谢
Let's say we have two region_prior_integral_image
instances: A and B. If you want to assign B to A, like A = B;
假设我们有两个
region_prior_integral_image
实例:A和B。如果要将B分配给A,例如A = B;
, the shapes of A
and B
must be equal. ,
A
和B
的形状必须相等。 The error message is saying that, in your code image_cache[it->second] = filename_to_region_prior_map[it->first];
错误消息表明,在您的代码中
image_cache[it->second] = filename_to_region_prior_map[it->first];
, the two arrays are of different shapes. ,这两个数组的形状不同。
How do you created the arrays in filename_to_region_prior_map
? 如何在
filename_to_region_prior_map
创建数组? I guess you used this constructor to specify the shapes: multi_array<double,3> B(boost::extents[i][j][k])
. 我猜您使用此构造函数指定了形状:
multi_array<double,3> B(boost::extents[i][j][k])
。 Hence their shape is [i][j][k]
. 因此,它们的形状为
[i][j][k]
。 But when you create the image_cache
, the default constructor is invoked. 但是,当您创建
image_cache
,将调用默认构造函数。 So the two shapes mismatch. 因此,这两个形状不匹配。
My opinion is to store pointers of region_prior_integral_image
in your code, which will save a lot of copy as well. 我的意见是在代码中存储
region_prior_integral_image
指针,这也将节省大量副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.