-
TNT(template numerical
toolkit)
使用详解
目录
前记
:
..................................................
..................................................
.............................................
1
Tnt_i_refvec.h
..................................................
..................................................
...............................
2
成员变量
:.................................................
..................................................
...............................
2
成员函数
:.................................................
..................................................
...............................
2
例子
:
..................................................
..................................................
.....................................
3
tnt_marix.h....
..................................................
..................................................
................................
5
作用
:
..................................................
..................................................
.....................................
5
成员变量
:.................................................
..................................................
...............................
5
成员函数
:.................................................
..................................................
...............................
5
例子
:
..................................................
..................................................
...................................
1
0
tnt_array1d.h
..................................................
..................................................
..............................
1
0
作用
:
..................................................
..................................................
...................................
1
0
成员变量
:................................................
..................................................
..............................
1
0
成员函数
:
.
.....................................
..................................................
................................
1
1
例子
:
..................................................
..................................................
...................................
1
2
tnt_array2d.h
..................................................
..................................................
..............................
1
3
作用
:
..................................................
..................................................
...................................
1
3
成员变量
:................................................
..................................................
..............................
1
3
成员函数
:................................................
..................................................
..............................
1
3
例子
:
..................................................
..................................................
...................................
1
5
其他
:
..................................................
..................................................
...........................................
1
5
下载地址
:
/tnt/
前记
:
由于网上没有关于
TNT(template
numerical toolkit)-----
数学模
板库
的中文资料
,
所以我决定写一个帮助手册
,
也算是自己再
重新感悟一下
TNT
设计的精妙之处吧
.
按文件来说
p>
,
并附上使用实例
:
Tnt_i_refvec.h
作用
:
主要是提供底层的引用计数的实现
,
不推荐直接使用它
.
如果要改变值
,
请先拷贝一次
,
以免你将其他引用的数
组改变
成员变量
:
data:
保存的底层数据
ref_count_:
引用的次数
成员函数
:
i_refvec():
默认构造函
数
,
产生一个空数组
explicit
i_refvec(int
n);
产生一个长度为
n
的
数组
,
但是数据
没有初始化
inline
i_refvec(T*
data);
产生一个数组指向数据指针
,
不产
生
引用计数
数
inline
T*
begin();
返回数组的数据的开始位置
inline
i_refvec(const i_refvec &v);
拷贝构造函数
,
有引用计
inline
const T* begin() const;
inline
T& operator[](int i);
返回第
i
个数据
,
数据是
0
基的
,
即从
0
开始
inline const T&
operator[](int i) const;
inline
i_refvec
赋值
拷贝构造函数
void copy_(T*
p, const T* q, const T* e);
将
[q,e)
复
制到
[p,e]
void set_(T* p,
const T* b, const T* e);
本文件并
未实现它
???
inline
int
ref_count()
const;
返回引用的数目
,
p>
如果使
用外部数据就返回
-1,
如果是空数组就返回
0
否则返回实际的引用数目
,
inline
int
is_null()
const;
判断是否为空
,1(0),
可以改写为
bool
型
,true(false)
一
~i_refvec();
inline
void
destroy();
清空此数组的数据
,
引用计数减
例子
:
#include
#include
项目应包含
TNT
头文件目录
using
namespace std;
using namespace TNT;
void testrefvec()
{
}
int main()
{
getchar();
cout<<
测试成功
!
return 0;
testrefvec();
double arr[]={1 ,2,3,4};
i_refvec
cout<
输出的是
3
}
tnt_marix.h
作
用
:
产
生
一
个
通
常
的
矩
阵
类
,
没
有
采
用
引
用
计
数
,<
/p>
它
被
Array2D(
< br>见后
)
所代替
.
其中我修改了他的代码
,
这儿用到的
std::vector
代替了源码
中的
Vector,
因为标准库中已有此类
,
无需自己在实现
成员变量
:
int m_;
//
行数
int n_;
//
列数
int
mn_;
//
总的大小
T* v_;
//
数据的物理存储
T** row_;
//
指向每一行的头指针
T* vm1_
//
以一为基的数据
T**
rowm1_;
//
以一为基
,
指向每
一行的头指针
,
这两个
数据完全没必要
,
但影响不大
成员函数
:
私有
:
void
initialize(int
M,
int
N)
//
< br>初始化矩阵为
M,N,
但不产生
具体数据
void copy(const T*
v)
/
/
拷贝指针的数据到矩阵中
,
大小
p>
为
M,N
void set(const
T& val)
//
将矩阵的所有元素赋值为
val
void destroy()
//
清空数据
公共
:
类型定义
://
与
C++
标准库
STL
兼容
typedef int
size_type;
typedef
T
value_type;
typedef
T
element_type;
typedef
T*
pointer;
typedef
T*
iterator;
typedef
T&
reference;
typedef const
T*
const_iterator;
typedef const
T&
const_reference;
函数
:
int lbound()
const //
返回下界
operator T**() //
转化为指针的指针
,
即二维数组
operator const T**() const
int size()
const //
返回矩阵的总的大小
MN
Matrix()
//
构造函数
Matrix(const Matrix
Matrix(int M, int N, const T& value =
T(0))
//
此处可以直接
写
T()
Matrix(int M, int N, const T*
v)//
将一维数组转化为矩阵
Matrix(int M, int N, const char *s)//
p>
同上
,
模板特化
~Matrix()
Matrix
改变矩阵的大小
,
数据已
清空
Matrix
赋值构造
Matrix
将矩阵的所有值改
为
scalar
int dim(int d)
const //
返回第
d
维的大小<
/p>
int num_rows() const {
return m_; } //
返回行数
int num_cols() const { return n_;
}//
返回列数
inline T* operator[](int i) //
返回第
i+1
个数据
inline const T*
operator[](int i) const
inline
reference operator()(int i)//
返回第
i
个数据
inline
const_reference operator()(int i) const
inline reference operator()(int i, int
j)
inline const_reference operator()
(int i, int j) const
std::vector
diag()
const//
返回对
角线的元素
,
返回值为
矩阵
Matrix
未实现
Matrix
std::ostream&
operator<<(std::ostream
&s,
const
Matrix
std::istream&
operator>>(std::istream
&s,
Matrix
&A)//
输入输出
Matrix
&
mult(Matrix
C,
const
Matrix
&A,
const Matrix
乘
inline Matrix
&A, const Matrix
&B)
nline
Matrix
operator*(const
Matrix
&A,
const
Matrix
inline
std::vector
mult(const
Matrix
&A,
const
std::vector
inline std::vector
&A, const
std::vector
inline Matrix
inline Matrix
inline Matrix
此处
源程序中有错误
,
请自行改正
.A+=B
inline Matrix
-
-
-
-
-
-
-
-
-
上一篇:114款Windows流氓杀软完整名单
下一篇:词根解析记忆