DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> C++ 的 MTL 庫 示例(整理 by RobinKin from DevonIT)
C++ 的 MTL 庫 示例(整理 by RobinKin from DevonIT)
編輯:AJAX詳解     

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

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved