//整理 by robinkin
#include "mtl/matrix.h"
#include "mtl/linalg_vec.h"
#include "mtl/utils.h"
#include
/*sample output:
partitioning vectors
//向量劃分
[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 matrices
//矩陣劃分
4x4[
[0,1,2,3],
[4,5,6,7],
[8,9,10,11],
[12,13,14,15]
]劃分成 2x2的 子矩陣(行2個 ,列兩個)
split into four submatrices
top mat: 2x2
2x2[
[0,1],
[4,5]
]2x2
[[2,3],
[6,7]
]2x2
[[8,9],
[12,13]
]2x2
[[10,11],
[14,15]
]劃分成 2x2的 子矩陣
split into six submatrics
top mat: 3x2 (行3 ,列2)
1x2[
[0,1]
]1x2
[[2,3]
]2x2
[[4,5],
[8,9]
]2x2
[[6,7],
[10,11]
]1x2
[[12,13]
]1x2
[[14,15]]*/
intmain()
;partition(array_to_vec(splits), x, xp2);
print_partitioned_vector(xp2);
/* partitioning matrices */
std::cout << std::endl;
std::cout << "partitioning matrices" << std::endl << std::endl;
typedef matrix, dense<>, row_major>::type matrix;
typedef matrix, dense<>, row_major>::type pmatrix;
const int m = 4;
matrix a(m, m);
for (i = 0; i < m; ++i)
for (j = 0; j < m; ++j)
a(i,j) = i * m + j;
print_all_matrix(a);
std::cout << "split into four submatrices" << std::endl;
pmatrix ap1(2,2);//2x2個子矩陣
subdivide(2, 2, a, ap1);
print_partitioned_matrix(ap1);
std::cout << "split into six submatrics" << std::endl;
int row_splits = ;//按照1,3 劃分行
int col_splits = ;
pmatrix ap2(3,2);//3x2的子矩陣
partition(array_to_vec(row_splits),
array_to_vec(col_splits),
a, ap2);
print_partitioned_matrix(ap2);
return 0;
}