【问题标题】:Boost multi_array library提升多数组库
【发布时间】:2016-06-30 12:15:49
【问题描述】:

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

干杯

【问题讨论】:

  • 您可以在运行时更改维度的扩展,但不能更改它们的数字。

标签: c++ boost


【解决方案1】:

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

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的模板参数,所以不能在运行时更改。

【讨论】:

    猜你喜欢
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 2017-06-30
    相关资源
    最近更新 更多