gather_scatter.cc
来自「MTL C++ Numeric Library」· CC 代码 · 共 71 行
CC
71 行
#include "mtl/matrix.h"#include "mtl/mtl.h"#include "mtl/utils.h"#include "mtl/dense1D.h"#include "mtl/compressed1D.h"#include "mtl/sparse1D.h"/*Sample Outputusing compressed1Dvector before[2,2,2,2,2,2,2,2,2,]vector before[2,2,4,2,2,4,2,4,2,]using sparse1Dvector before[2,2,2,2,2,2,2,2,2,]vector before[2,2,4,2,2,4,2,4,2,]*/template <class DenseVec, class SparseVec>//beginvoid do_gather_scatter(DenseVec& d, SparseVec& c) { using namespace mtl; //end std::cout << "vector before" <<std::endl; print_vector(d); //begin c[2] = 0; c[5] = 0; c[7] = 0; gather(d,c); scale(c,2.0); scatter(c,d); //end std::cout << "vector after" <<std::endl; print_vector(d); //being}//endint main (){ using namespace mtl; //begin typedef dense1D<double> denseVec; typedef compressed1D<double> compVec; denseVec d(9,2); compVec c; //end std::cout << "using compressed1D" <<std::endl; //begin do_gather_scatter(d, c); //end typedef std::set< entry1<double> > RepType; typedef sparse1D< RepType > sparseVec; sparseVec s; mtl::set_value(d, 2); std::cout << "using sparse1D" << std::endl; do_gather_scatter(d, s);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?