//距陣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;
}