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 :: qualie(shopshape(),other.shape() this-> num_dimensions(),this-> shape())'失败。P>
我不知道为什么?
我知道我只能使用矢量,但是出于争论,请说我想拥有一系列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
的指针存储在您的代码中,这也可以节省很多副本。
- 检查输入 std::array 指针数据是否等于某个常量数组
- 基于 std::array 的多维数组
- std::array与C样式数组用于连续内存
- 具有静态 std::array 的神经网络比使用动态 C 数组的神经网络慢
- 不要声明 C 样式数组,而是使用 std::array<>
- 为什么我不能将 C 样式数组复制到 std::array?
- 创建 2D 数组类:如何访问 2D 数组类(如 array[x][y))中的元素
- 尝试使用 Array 类的模板构造整数数组时,错误:为什么数组类型"int [5]"不可分配,
- 为什么span的数组和std::array构造函数与其容器构造函数不同
- 键入 trait 以获取 std::array 或 C 样式数组的元素类型
- 原始数组和 std::array 在 clang++ 和 VC++ 上的不同迭代器行为
- 使用 std::array vs 数组传递对象数组
- 我无法将'2D array whit bool'转换为"空 2D 数组布尔值"(用于生命游戏)
- 为什么 C 数组比 std::array 快得多?
- 为什么在使用堆叠 std::array 声明多维数组时需要"双括号"?
- 使用索引数组订购 ArrayFire Array 的最佳方式
- NAPI AsyncWorker:将指针数组转换为NAPI::array,而不使用大的for
- 从std::array获取对原始数组的引用
- 获取 std::array 底层数组内存大小的最简单方法?
- 数组中的值之和返回内存地址,除非sizeof(array)/2