
if (0 == degenerate_dimension){ Slice slice = @R_301_5983@_array[boost::indices[slice_index][range()][range()]];}else if (1 == degenerate_dimension){ Slice slice = @R_301_5983@_array[boost::indices[range()][slice_index][range()]];}else if (2 == degenerate_dimension){ Slice slice = @R_301_5983@_array[boost::indices[range()][range()][slice_index]];} 有没有更美丽的方式构建index_gen对象?
这样的事情
var slicer;for(int i = 0; i < 3; ++i) { if (degenerate_dimension == i) slicer = boost::indices[slice_index]; else slicer = boost::indices[range()];}Slice slice = @R_301_5983@_array[slicer]; 似乎每个后续调用boost :: indices :: operator []根据维度(即先前的调用次数)返回不同的类型,所以没有办法使用可以容纳临时的index_gen对象的单个变量.
解决方法 请试试看. Сode有一个缺点 – 它指的是在boost :: detail :: multi_array命名空间中声明的ranges_数组变量.#include <boost/multi_array.hpp> typedef boost::multi_array<double,3> array_type; typedef boost::multi_array_types::index_gen::gen_type<2,3>::type index_gen_type; typedef boost::multi_array_types::index_range range; index_gen_type func(int degenerate_dimension,int slice_index) { index_gen_type slicer; int i; for(int i = 0; i < 3; ++i) { if (degenerate_dimension == i) slicer.ranges_[i] = range(slice_index); else slicer.ranges_[i] = range(); } return slicer; } int main(int argc,char **argv) { array_type myarray(boost::extents[3][3][3]); array_type::array_vIEw<2>::type myvIEw = myarray[ func(2,1) ]; return 0; } 总结 以上是内存溢出为你收集整理的c – 如何在运行时指定boost multi_array的简并维?全部内容,希望文章能够帮你解决c – 如何在运行时指定boost multi_array的简并维?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)