C++ 的 MTL 库 示例(整理 by RobinKin from DevonIT)

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

//距阵copy 和 转置

// -*- c++ -*-

//

// $COPYRIGHT$

//

//===========================================================================

#include <iostream>

using namespace std;

#include <mtl/matrix.h>

#include <mtl/mtl.h>

#include <mtl/utils.h>

#include <mtl/linalg_vec.h>

/*

Transpose matrix A into matrix B using mtl::copy.

(We could use the mtl::transpose(A,B) function,

but then this wouldn't be an example about mtl::copy)

Sample Output

3x3

[

[1,4,7],

[2,5,8],

[3,6,9]

]

3x3

[

[1,2,3],

[4,5,6],

[7,8,9]

]

*/

using namespace mtl;

typedef matrix< double, rectangle<>,

dense<>, column_major>::type Matrix;

/* An external matrix - uses memory from some "outside" source, and

just makes that memory look like an MTL Matrix */

typedef matrix< double, rectangle<>,

dense<external>, column_major>::type EMatrix;

int

main()

{

int i;

const int N = 3;

double da[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

EMatrix A(da, N, N);

Matrix B(N, N);

print_all_matrix(A);

// Copy the columns of A into the rows of B

for (i = 0; i < N; ++i)

copy(A[i], rows(B)[i]); // rows(B) creates a row-oriented view of B

print_all_matrix(B);

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航