提升multi_array库

时间:2016-06-30 12:15:49

标签: c++ boost

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

欢呼声

1 个答案:

答案 0 :(得分:0)

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

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的模板参数,因此无法在运行时更改它。