// Solving by Robinkin
#include "mtl / matrix.h" #include "mtl / tinalg_vec.h" #include "mtl / utils.h" #include
/ * Sample Output:
Partitioning vectors // vector division [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,] split in Half [0, 1, 2, 3, 4,] [5, 6, 7, 8, 9,] Split Into Thirds [0, 1, 2,] [3, 4, 5, 6,] [7, 8, 9,] Partitioning Matrice // Matrix 4X4 [[0, 1, 2, 3 ], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]]]
Divided into a 2X2 sub-matrix (2 column two) split INTO FOUR Submatricestop Mat: 2x22x2 [[0, 1], [4, 5]] 2x2 [[2, 3], [6, 7] 2X2 [[8, 9], [12, 13]] 2X2 [[10, 11], [14, 15]] divided into 2x2 sub-matrix Split Into Six Submau SUBMATRICSTOP MAT: 3X2 (line 3, column 2) 1x2 [[ 0, 1]] 1x2 [[2, 3]] 2X2 [[4, 5], [8, 9]] 2X2 [[6, 7], [10, 11]] 1x2 [[12, 13]] 1x2 [[14,15]]]
* /
INTMAIN () {Using Namespace MTL;
/ * Partitioning product * / std :: cout << "partitioning vectors" << std :: endl << std :: end1; const INT n = 10; int DX [N]; INT I, J;
For (i = 0; i TYPEDEF EXTERNAL_VEC VEC X (DX, N); Print_Vector (x); Std :: cout << "split in hald" << std :: endl; pVEC XP1 (2); // is divided into two subDivide (5, x, xp1); // Each child vector 5 elements Print_Partitioned_Vector (XP1) ; Std :: cout << "split Into thirds" << std :: end1; pVEC XP2 (3); // divided 3 int splits [] = {3,7}; partition (array_to_vec (splits), x, xp2 ); Print_partitioned_vector (xp2); / * Partitioning Matrices * / std :: cout << std :: endl; std :: cout << "partitioning matrice" << std :: endl << std :: endl; TypedEf Matrix Typedef Matrix Print_all_matrix (a); Std :: cout << "split INTO FOUR SUBMATERES" << std :: endl; pmatrix ap1 (2, 2); // 2X2 sub-matrix Subdivide (2, 2, a, ap1); print_partitioned_matrix (ap1); Std :: cout << "split inTo Six Submatrics" << std :: endl; INT row_splits [] = {1, 3}; // According to 1,3, Int colly_splits [] = {2}; PMAtrix AP2 (3, 2); // 3x2 sub-matrix partition (array_to_vec (row_splits), array_to_VEC (col_splits), A, AP2); Print_Partitioned_Matrix (AP2); Return 0;}