[英]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;
, A
和B
的形狀必須相等。 錯誤消息表明,在您的代碼中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.