1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //blocking a vector(partitioning) inline vxd::t v_block(vxd::t _v, int endIdx, int startIdx = 0 ){ return _v.segment(startIdx,endIdx); } //slicing and redicing axpy algorithm inline vxd::t v_axpy(double alpha, vxd::t _x, vxd::t _y){ vxd::t v_(_x.rows()); v_.setZero(); vxd::t xTop = _x.segment(0,0); vxd::t xBot = _x.segment(0,_x.rows()); vxd::t yTop = _y.segment(0,0); vxd::t yBot = _y.segment(0,_y.rows()); int idx = 0; while(xTop.rows() < _x.rows()){ v_[idx++] = alpha * _x[idx] + _y[idx]; xTop = _x.segment( 0, idx ); xBot = _x.segment(idx, _x.rows() - idx ); yTop = _y.segment( 0, idx ); yBot = _y.segment(idx, _y.rows() - idx ); co(xTop, "xTop"); co(xBot, "xBot"); co(yTop, "yTop"); co(yBot, "yBot"); } return v_; } vxd::t v(3); vxd::t v2(3); v << 1, 2, 3; v2 << 2, 2, 2; co(v_axpy(2, v, v2)); | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | result : xTop = 1 xBot = 2 3 yTop = 2 yBot = 2 2 xTop = 1 2 xBot = 3 yTop = 2 2 yBot = 2 xTop = 1 2 3 xBot = yTop = 2 2 2 yBot = output = 4 6 8 | cs |
'Linear Algebra' 카테고리의 다른 글
[Eigen] Day 6. Quadrants slicing and redicing with identity matrix (0) | 2019.05.28 |
---|---|
[Eigen] reviewing linear algebra day5. zero matrix with slicing and redicing (0) | 2019.05.27 |
[Eigen] 복습 3일차, Linear combination algorithm (0) | 2019.05.25 |
[Eigen] 복습 2일차 (0) | 2019.05.22 |
[Eigen] 아이겐을 사용한 선형대수 복습 1일차 (0) | 2019.05.21 |