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;
}
// -*- 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;
}
相关文章推荐
- C++ MTL 矩阵 行交换 示例 (整理 by RobinKin from DevonIT)
- 整理android逆向工程师技能表 by非虫from看雪
- C++新风格的强制类型转换(by Morphy, from csdn community)
- python调用c/c++方式示例(修改整理)
- Calling Fortran functions from C++ by means of shared libraries
- How to use an Outlook Object Model from Visual C++ by using a #import statement
- GitHub 通告:整理了一个 C 和 C++ 开源库的清单(含示例代码)
- boost 检查(测试)库 示例 (RobinKin 整理)
- c++开源库rapidxml介绍与示例
- <From C++ To C#> 我们先定义一些局部变量
- 面试笔试整理2:c++常问问题
- c++中对目录的操作示例
- C#调用C++的COM组件简单示例
- Calling C and C++ from IDL (二)——变量传递
- C++ How To Program整理(11)
- Learning C++ by Creating Games With UE4(15.05.21)(Chapter 11-4)Monster
- C++的一些简单示例(4)
- 【LeetCode算法练习(C++)】Remove Duplicates from Sorted Array
- Qt(C++)调用工业相机Basler的SDK简单使用示例
- c++ 类型转换整理一:static_cas t和 reinterpret_cast