[英]Boost multi_array library
I need to convert some vba code to c++, the problem is that the algorithm is very particular, it uses matrices up to 15 dimensions, for this reason I decided to use boost multi_array. 我需要将一些vba代码转换为c ++,问题是该算法非常特殊,它使用的矩阵最大为15维,因此我决定使用boost multi_array。 Now my problem is that in VBA you can change the dimensions at runtime and I am wondering if I can do it in boost multi_array as well.
现在我的问题是,在VBA中,您可以在运行时更改尺寸,我想知道是否也可以在boost multi_array中进行更改。
cheers 干杯
You can change the extent (size) of each dimension at runtime, but not the number of dimensions of a variable: 您可以在运行时更改每个维的范围(大小),但不能更改变量的维数:
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]);
Since the number of dimensions is a template parameter of boost::multi_array
, you cannot change it at runtime. 由于维数是
boost::multi_array
的模板参数,您不能在运行时更改它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.