您的位置:首页 > 编程语言 > C语言/C++

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

2005-02-25 12:13 876 查看
//距阵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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: