关键词不能为空

当前您在: 主页 > 英语 >

TNT(template numerical toolkit)使用详解

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-13 18:06
tags:

-

2021年2月13日发(作者:kust)


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


设计的精妙之处吧


.


按文件来说


,


并附上使用实例


:


Tnt_i_refvec.h


作用


:


主要是提供底层的引用计数的实现


,


不推荐直接使用它


.


如果要改变值


,


请先拷贝一次


,


以免你将其他引用的数 组改变



成员变量


:


data:


保存的底层数据



ref_count_:


引用的次数



成员函数


:








i_refvec():


默认构造函 数


,


产生一个空数组



explicit


i_refvec(int


n);


产生一个长度为


n


的 数组


,


但是数据


没有初始化

< p>



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 & operator=(const i_refvec &V);


赋值


拷贝构造函数









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;


返回引用的数目


,


如果使


用外部数据就返回


-1,

< p>
如果是空数组就返回


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 vec1,vec2(4),vec3(arr);


cout<


输出的是


3


}










tnt_marix.h




:




< p>








,









,< /p>




Array2D(

< br>见后


)


所代替


.


其中我修改了他的代码


,


这儿用到的


std::vector


代替了源码


中的

< p>
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)



/ /


拷贝指针的数据到矩阵中


,


大小



M,N






void set(const T& val)



//


将矩阵的所有元素赋值为


val


void destroy()



//


清空数据






公共


:


类型定义

://



C++


标准库

< p>
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 &A)


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)//


同上


,


模板特化



~Matrix()


Matrix& newsize(int M, int N)//


改变矩阵的大小

,


数据已


清空





Matrix& operator=(const Matrix &B)//


赋值构造



Matrix& operator=(const T& scalar)//


将矩阵的所有值改



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//


返回对 角线的元素


,


返回值为


矩阵

< p>





Matrix upper_triangular() const;//


未实现





Matrix lower_triangular() const;


std::ostream&


operator<<(std::ostream


&s,


const


Matrix &A)




std::istream&


operator>>(std::istream


&s,


Matrix


&A)//


输入输出





Matrix


&


mult(Matrix&


C,


const


Matrix



&A,


const Matrix &B)//





inline Matrix mult(const Matrix



&A, const Matrix


&B)



nline


Matrix


operator*(const


Matrix



&A,


const


Matrix &B)



inline


std::vector


mult(const


Matrix



&A,


const


std::vector &b)



inline std::vector operator*(const Matrix



&A, const


std::vector &b)





inline Matrix mult(const T& s, const Matrix &A)


inline Matrix mult(const Matrix &A, const T& s)


inline Matrix& mult_eq(const T& s, Matrix &A)//


此处


源程序中有错误


,


请自行改正


.A+=B



inline Matrix& mult_eq(Matrix &A, const T&a)

-


-


-


-


-


-


-


-



本文更新与2021-02-13 18:06,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/651821.html

TNT(template numerical toolkit)使用详解的相关文章