###### MTL 矩阵划分示例

//整理　by　RobinKin

#include "mtl/matrix.h"
#include "mtl/linalg_vec.h"
#include "mtl/utils.h"
#include <list>

/*
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]
]

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]
]

*/

int
main()
{
using namespace mtl;

/* Partitioning Vectors */
std::cout << "Partitioning Vectors" << std::endl << std::endl;
const int N = 10;
int dx[N];
int i, j;

for (i = 0; i < N; ++i)
dx[i] = i;

typedef external_vec<int> Vec;
typedef dense1D<Vec::subrange_type> PVec;

Vec x(dx, N);
print_vector(x);

std::cout << "split in half" << std::endl;
PVec xp1(2); //分成两个
subdivide(5, x, xp1);//每个子向量5个元素
print_partitioned_vector(xp1);

std::cout << "split into thirds" << std::endl;
PVec xp2(3);//分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 Matrices" << std::endl << std::endl;

typedef matrix<int, rectangle<>, dense<>, row_major>::type Matrix;

typedef matrix<Matrix::submatrix_type,
rectangle<>, 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 };//按照1，3 划分行
int col_splits[] = { 2 };
PMatrix Ap2(3,2);//3x2的子矩阵
partition(array_to_vec(row_splits),
array_to_vec(col_splits),
A, Ap2);
print_partitioned_matrix(Ap2);

return 0;
}

#### MTL 矩阵逆阵 解线性方程

2005-03-04 13:42:00

#### 介绍矩阵计算库MTL

2012-12-01 11:37:35

#### 给MTL库添加求行列式值

2011-03-04 15:35:00

#### VS2008下的MTL

2009年10月30日 167KB 下载

#### OBJ材质文件MTL格式分析

2011-08-22 10:58:09

#### MTL矩阵模板库

2014年07月28日 1.36MB 下载

#### pcd，obj，mtl文件格式解析

2017-06-14 15:26:33

#### 可达性矩阵的级别划分问题

2010年05月08日 6KB 下载

#### 摄影测量后方交会程序

2013年04月16日 77KB 下载

#### MTL 解下三角带状矩阵线形方程

2005-03-09 10:11:00

MTL 矩阵划分示例