Boost multi_array library

Boost multi_array library

本文关键字:library array multi Boost      更新时间:2023-10-16

我需要将一些vba代码转换为c++,问题是算法非常特殊,它使用矩阵高达15维,因此我决定使用boost multi_array。现在我的问题是,在VBA中,你可以在运行时改变尺寸,我想知道我是否也可以在boost multi_array中做到这一点。

欢呼

您可以在运行时更改每个维度的范围(大小),但不能更改变量的维度数:

typedef boost::multi_array<double, 3> array_type;
// Create a 2x4x5 array
array_type array3(boost::extents[2][4][5]);
// Reshape (no copy) - The total number of elements must remain the same
boost::array<array_type::index, 3> new_dims{{5, 4, 2}};
array3.reshape(new_dims);
// Resize, keeping currently stored elements by copying them
array3.resize(boost::extents[8][10][5]);
// Create a new array
array3 = array_type(boost::extents[7][6][8]);

由于维度数是boost::multi_array的模板参数,所以不能在运行时更改。